Nodejs String Camel Case toCamelCase()

Here you can find the source of toCamelCase()

Method Source Code

String.prototype.toCamelCase = function() {
   words = this.split(' ')
   var upperCased = '';
   for (var i = 0; i < words.length; i++) {
      for (var y = 0; y < words[i].length; y++) {
         if (y == 0) {
            upperCased += words[i][y].toUpperCase();
         }//from w  w w .j  a  va2s .  c o  m
         else {
            upperCased += words[i][y];
         }
      }
      upperCased += ' ';   
   }   
   return upperCased;
}


var s = "i'm a test"
console.log(s.toCamelCase())

Related

  1. toCamelCase()
    String.prototype.toCamelCase = function () {
      return this.toString().toLowerCase().replace(/(-[a-z])/g, function ($1) {
        return $1.toUpperCase().replace('-', '');
      });
    };
    
  2. 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 + ''
    
  3. 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;
    ...
    
  4. 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;
    ...
    
  5. 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, '');
    };
    
  6. toCamelCase()
    String.prototype.toCamelCase = function () {
        return this.split(/\W+/g).map(function (w) {
            return w.substr(0, 1).toUpperCase() + w.substr(1); 
        }).join(' ');
    };
    
  7. toCamelCase()
    String.prototype.toCamelCase = function(){
        return this.replace(/(\_[a-z])/g, function($1){return $1.toUpperCase().replace('_','');});
    };
    
  8. toCamelCase()
    String.prototype.toCamelCase = function(){
      return this.replace(/[-_]([a-z])/g, function (g) { return g[1].toUpperCase(); });
    };
    
  9. toCamelCase()
    String.prototype.toCamelCase = function(){
      return this
             .toLowerCase()
             .replace(/(\s+[a-z])/g, 
                function($1) {
                  return $1.toUpperCase().replace(' ', '');
              );