Javascript String toCamel()

Description

Javascript String toCamel()


String.prototype.toCamel = function(){
  return this.replace(/(\-[a-z])/g, function($1){return $1.toUpperCase().replace('-','');});
};

Javascript String toCamel()

/**/*w  ww .  java 2s. c o m*/
 * http://stackoverflow.com/a/15829686
 */
String.prototype.toCamel = function(){
    return this.replace(/^([A-Z])|\s(\w)/g, function(match, p1, p2, offset) {
        if (p2) return p2.toUpperCase();
        return p1.toLowerCase();        
    });
};

Javascript String toCamel()

String.prototype.toCamel = function() {
  return this.replace(/(\_[a-z])/g, function($1){return $1.toUpperCase().replace('_','');});
};

Javascript String toCamel()

// Convert a string with spaces to Camel Case
String.prototype.toCamel = function(){
    return this.replace(/\s(.)/g, function(match, group1) {
        return group1.toUpperCase();
    });//w  ww.  j  a  v a2  s.  c om
};

Javascript String toCamel()

String.prototype.toCamel = function() {
  return this.toLowerCase().replace(/_(.)/g, function(match, group1) {
    return group1.toUpperCase();
  });/*from   w  w w  . j  a v a2  s.  c  o m*/
};

Javascript String toCamel()

String.prototype.toCamel = function(){
 return this.replace(/(\s[a-z])/g, function($){return $.toUpperCase().replace(/\s/g, '');});
};

Javascript String toCamel()

String.prototype.toCamel = function () {
    return this.toLowerCase().replace(/(_[a-z])/g, function ($1) {
        return $1.toUpperCase().replace('_', '');
    });//from   w  w  w .  ja  v  a2s .c o  m
};

Javascript String toCamel()

/**//from  w ww.  jav  a  2 s.  c  om
  * toCamel()
  * -------------------------
  * @desc: converts string to camel case format
  * @type: (string)
*/
String.prototype.toCamel = function(){
 return this.replace(/(\-[a-z])/g, function($1){return $1.toUpperCase().replace('-','');});
};



PreviousNext

Related