Nodejs String Camel Case toCamelCase()

Here you can find the source of toCamelCase()

Method Source Code

String.prototype.toCamelCase = function() {
    var parts = this.split('-'),
        rtr = "",
        part;//from w w  w . j a v a  2  s  .c  o  m
    for (var i = 0; i < parts.length; i++) {
        part = parts[i];
        rtr += (i === 0) ? part.toLowerCase() : part[0].toUpperCase()+part.slice(1).toLowerCase();
    }
    return rtr;
};

Related

  1. toCamelCase()
    String.prototype.toCamelCase = function () {
        return this.split(/\W+/g).map(function (w) {
            return w.substr(0, 1).toUpperCase() + w.substr(1); 
        }).join(' ');
    };
    
  2. toCamelCase()
    String.prototype.toCamelCase = function(){
        return this.replace(/(\_[a-z])/g, function($1){return $1.toUpperCase().replace('_','');});
    };
    
  3. toCamelCase()
    String.prototype.toCamelCase = function(){
      return this.replace(/[-_]([a-z])/g, function (g) { return g[1].toUpperCase(); });
    };
    
  4. toCamelCase()
    String.prototype.toCamelCase = function(){
      return this
             .toLowerCase()
             .replace(/(\s+[a-z])/g, 
                function($1) {
                  return $1.toUpperCase().replace(' ', '');
              );
    
  5. toCamelCase()
    String.prototype.toCamelCase = function () {
        return this.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function (match, index) {
            if (+match === 0) return ""; 
            return index == 0 ? match.toLowerCase() : match.toUpperCase();
        });
    };
    
  6. toCamelCase()
    String.prototype.toCamelCase = function() {
      return this.replace(/-([a-z])/g, function (m, w) {
        return w.toUpperCase();
      });
    
  7. toCamelCase()
    String.prototype.toCamelCase = function() {
      return this.replace(/(^|\s)[a-z]/g, function (x) { return x.toUpperCase() });
    
  8. toCamelCase()
    String.prototype.toCamelCase = function() {
        return this.toLowerCase()
            .replace(/[-_]+/g, ' ')
            .replace(/[^\w\s]/g, '')
            .replace(/ (.)/g, function($1) {
                return $1.toUpperCase();
            })
            .replace(/ /g, '');
    };
    ...
    
  9. toCamelCase()
    String.prototype.toCamelCase = function () {
        return this.charAt(0).toLowerCase() + this.slice(1);
    };