xml2customjs
Version:
Library to custom convert an XML into a Javascript object or JSON
30 lines • 967 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toCamelCase = void 0;
/**
* This function converts a prop name in pascal, camel, snake, kebab or separated by :
* into camel case version
* @param param
* @returns string
*/
function toCamelCase(param) {
const text = '' + param;
const hasSymbolSeparators = /[-_:]/.test(text);
const isAllUpperOrLower = /^([a-z]+|[A-Z]+)$/.test(text);
if (hasSymbolSeparators) {
const arr = text.split(/[-_:]/);
const mappedArr = arr.map((val, index) => {
if (index == 0) {
return val.toLowerCase();
}
return val[0].toUpperCase() + val.slice(1).toLowerCase();
});
return mappedArr.join('');
}
if (isAllUpperOrLower) {
return text.toLowerCase();
}
return text[0].toLowerCase() + text.slice(1);
}
exports.toCamelCase = toCamelCase;
//# sourceMappingURL=to-camelcase.js.map