Showing posts with label underbar. Show all posts
Showing posts with label underbar. Show all posts

Friday, January 17, 2014

[JAVASCRIPT/JQUERY] STRING FUNCTION CAMEL TO PASCAL UNDERBAR

Underscores CamelCased format string to uppercase, you can

Camel underscore uppercase string of the form, you can change the notation.

This code is required to JQUERY library.

$.camelToCapital=function(str){
 return str.replace(/([A-Z])/g,function(arg){
  return '_'+arg.toLowerCase();
 }).toUpperCase();
};

$.capitalToCamel=function(str){
 return str.toLowerCase().replace(/(\_[a-z])/g,function(arg){
  return arg.toUpperCase().replace('_','');
 });
};


$.camelToCapital("testAhndoori");
>> TEST_AHNDOORI

$.capitalToCamel("AHNDOORI_BLOGSPOT_KR");
>> kaudoBlogspotKr