Nodejs String Camel Case toCamelCase(delimiter)

Here you can find the source of toCamelCase(delimiter)

Method Source Code

"use strict";//from   w w  w. ja v a  2  s .  c  o  m
var toCamelCase = function (string) {
    if (string.substr(0, 2) !== string.substr(0, 2).toUpperCase()) {
        return string.substr(0, 1).toLowerCase() + string.substr(1);
    }
    else {
        return string;
    }
};
String.prototype.toCamelCase = function (delimiter) {
    if (typeof delimiter === "string" && delimiter.length > 0) {
        var parts = this.split(delimiter);
        return parts.map(function (part, index) {
            if (index === 0) {
                return toCamelCase(part);
            }
            else {
                return part.substr(0, 1).toUpperCase() + part.substr(1);
            }
        }).join("");
    }
    return toCamelCase(this);
};
module.exports = function (string, delimiter) {
    return String.prototype.toCamelCase.apply(string, delimiter);
};
//# sourceMappingURL=toCamelCase.js.map

Related

  1. toCamelCase()
    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();
          else {
    ...
    
  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, ($1) => {
                return $1.toUpperCase().replace('-','');
              });
    };
    
  4. toCamelCase()
    String.prototype.toCamelCase = function() {
      var str = this.toLowerCase();
      var modified = '';
      var mark = false;
      for (var i = 0; i < str.length; i++) {
        if (str[i] === '_') {
          mark = true;
          continue;
        if (mark) {
          if (modified.length > 0) {
            modified += str[i].toUpperCase();
          } else {
            modified = str[i];
          mark = false;
        } else {
          modified += str[i];
      return modified;
    };
    
  5. toCamelCase()
    String.prototype.toCamelCase = function() {
      return this.replace(/[- ](\w)/g, function(match) {
        return match[1].toUpperCase();
      });
    
  6. toCamelCasej()
    String.prototype.toCamelCase  = jCube.String.toCamelCase  = function () {
      return this.replace( /-\D|-\d/g, function(s){ return s.charAt(1).toUpperCase()}).replace( /\s\D|\s\d/g, function(s){ return s.charAt(1).toUpperCase()});
    
  7. toLittleCamelCase()
    String.prototype.toLittleCamelCase = function () {
      var sourceStr = this.toString();
      var str = '';
      var strArr = sourceStr.split('-');
      strArr.forEach(function (el) {
        str = str + el.firstUppserCase();
      })
      str = str.firstLowerCase();
      return str;
    ...
    
  8. to_camelCase()
    String.prototype.to_camelCase = String.prototype.to_camelCase || function(){
        var split = this.split('_').filter(Boolean);
        var len = split.length;
        var camelCaseString = '';
        for (var i=0;i<len;i++) {
            if(i===0){
                camelCaseString = camelCaseString + split[i].toLowerCase();
            else{
    ...
    
  9. unCamelCase()
    String.prototype.unCamelCase = function(){
      return this
        .replace(/([a-z])([A-Z])/g, '$1 $2')
        .replace(/\b([A-Z]+)([A-Z])([a-z])/, '$1 $2$3')
        .replace(/^./, function(str){ return str.toUpperCase(); })