Here you can find the source of to_camelCase()
//converts string with underscores to camelCase. string is the same if the string doesn't contain underscores or only contains a leading underscore e.g. _hello 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(); }//from www . j a va2s .c o m else{ camelCaseString = camelCaseString + split[i].capitalize(); } } return camelCaseString; } //to map array-like objects such as collections- returns array with function applied function map_collection(collection, callback){ var len = collection.length; var newArray = []; for(var i=0; i<len;i++){ newArray.push(callback(collection[i])); } return newArray; } //returns cross browser compatible (back to i.e. 6) xml dom object from xml string var parseXML = (function(){ if (typeof window.DOMParser != "undefined") { return function(xmlStr) { return ( new window.DOMParser() ).parseFromString(xmlStr, "text/xml"); }; } else if (typeof window.ActiveXObject != "undefined" && new window.ActiveXObject("Microsoft.XMLDOM")) { return function(xmlStr) { var xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = "false"; xmlDoc.loadXML(xmlStr); return xmlDoc; }; } else { throw new Error("No XML parser found"); } })();
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; };
String.prototype.toCamelCase = function() { return this.replace(/[- ](\w)/g, function(match) { return match[1].toUpperCase(); });
"use strict"; 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 = 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()});
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; ...
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(); })
String.prototype.underscore_to_camel = function() { return this.replace(/_[a-z]/, function(m){ return m.substring(1).toUpperCase(); }) String.prototype.capitalize = function() { return this.replace(/^[a-z]/, function(m){ return m.toUpperCase(); }) String.prototype.repeat = function(num) { return new Array( num + 1 ).join( this );