angular2-data-table
Version:
angular2-data-table is a Angular2 component for presenting large and complex data.
36 lines • 1.25 kB
JavaScript
;
/**
* Converts strings from something to camel case
* http://stackoverflow.com/questions/10425287/convert-dash-separated-string-to-camelcase
* @param {string} str
* @return {string} camel case string
*/
function camelCase(str) {
// Replace special characters with a space
str = str.replace(/[^a-zA-Z0-9 ]/g, ' ');
// put a space before an uppercase letter
str = str.replace(/([a-z](?=[A-Z]))/g, '$1 ');
// Lower case first character and some other stuff
str = str.replace(/([^a-zA-Z0-9 ])|^[0-9]+/g, '').trim().toLowerCase();
// uppercase characters preceded by a space or number
str = str.replace(/([ 0-9]+)([a-zA-Z])/g, function (a, b, c) {
return b.trim() + c.toUpperCase();
});
return str;
}
exports.camelCase = camelCase;
/**
* Converts strings from camel case to words
* http://stackoverflow.com/questions/7225407/convert-camelcasetext-to-camel-case-text
*
* @export
* @param {any} str
* @returns string
*/
function deCamelCase(str) {
return str
.replace(/([A-Z])/g, function (match) { return (" " + match); })
.replace(/^./, function (match) { return match.toUpperCase(); });
}
exports.deCamelCase = deCamelCase;
//# sourceMappingURL=camel-case.js.map