Nodejs String Camel Case toCamelCase()

Here you can find the source of toCamelCase()

Method Source Code

/**//from   w w  w .  j ava  2s .  c  o  m
 * Converts a hyphenated string to camel case
 *    ex: 'my-module' returns 'myModule'
 */
String.prototype.toCamelCase = function () {
  return this.toString().toLowerCase().replace(/(-[a-z])/g, function ($1) {
    return $1.toUpperCase().replace('-', '');
  });
};

Related

  1. toCamel()
    String.prototype.toCamel = function(){
        var re = /(\b[a-z](?!\s))/g;
        return this.toLowerCase().replace(re, function(x){
            return x.toUpperCase();
        });
    };
    function addClass(el, className) {
        if (el.classList)
            el.classList.add(className)
    ...
    
  2. toCamel()
    String.prototype.toCamel = function(){
        return this.replace(/(\-[a-z])/g, function($1){return $1.toUpperCase().replace('-','');});
    };
    String.prototype.toUnderscore = function(){
        return this.replace(/([A-Z])/g, function($1){return "_"+$1.toLowerCase();});
    };
    
  3. toCamel()
    String.prototype.toCamel = function(){
      return this.replace(/([\-_][a-z])/g, function($1){return $1.toUpperCase().replace(/[-_]/,'');});
    };
    
  4. toCamelCase()
    String.prototype.toCamelCase = function () {
      return this.valueOf().replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
    
  5. toCamelCase()
    String.prototype.toCamelCase = function(){
        return this
            .toLowerCase()
            .replace( /\W+/g, ' ' )
            .replace( / (.)/g, function($1) { return $1.toUpperCase(); })
            .replace( / /g, '' );
    
  6. toCamelCase()
    String.prototype.toCamelCase = function () {
      const regex = new RegExp(/(?:_|-)(.)/g)
      if (regex.test(this)) {
        return this.toLowerCase().replace(regex, (match, group1) => {
          return group1.toUpperCase()
        })
      return this + ''
    
  7. toCamelCase()
    String.prototype.toCamelCase = function () {
        return this
            .replace(/\s(.)/g, function ($1) { return $1.toUpperCase(); })
            .replace(/\s/g, '')
            .replace(/^(.)/, function ($1) { return $1.toLowerCase(); });
    function enumString(e,value) 
        for (var k in e) if (e[k] == value) return k;
    ...
    
  8. toCamelCase()
    String.prototype.toCamelCase = function () {
      return this.replace(/^\s+|\s+$/g, '')
        .toLowerCase()
        .replace(/([\s\-\_][a-z0-9])/g, function ($1) {
          return $1.replace(/\s/, '').toUpperCase();
        })
        .replace(/\W/g, '');
    };
    export default String.prototype.toCamelCase;
    ...
    
  9. toCamelCase()
    String.prototype.toCamelCase = function () {
      return this.replace(/^\s+|\s+$/g, '').toLowerCase().replace(/([\s\-\_][a-z0-9])/g, function ($1) {
        return $1.replace(/\s/, '').toUpperCase();
      }).replace(/\W/g, '');
    };