typedash
Version:
modern, type-safe collection of utility functions
29 lines (27 loc) • 903 B
JavaScript
const require_capitalize = require('./capitalize-BDqzNm3J.cjs');
//#region src/functions/camelCase/camelCase.ts
/**
* Changes the casing of a string to kebab case.
* @param string The input string to change the casing of.
* @returns A new string with the casing changed to kebab case.
* @example
* ```ts
* camelCase('fooBar') // 'fooFar'
* camelCase('foo bar') // 'fooBar'
* camelCase('foo-bar') // 'fooBar'
* camelCase('fooBar42') // 'fooBar42'
* ```
*/
function camelCase(string) {
if (!/[a-z]+/i.test(string)) return string;
return string.trim().split(wordsRegex).map((word, index) => index === 0 ? word.toLowerCase() : require_capitalize.capitalize(word)).join("");
}
const wordsRegex = /[\s_-]+|(?<=[a-z])(?=[A-Z])/;
//#endregion
Object.defineProperty(exports, 'camelCase', {
enumerable: true,
get: function () {
return camelCase;
}
});
//# sourceMappingURL=camelCase-zSjbdRoI.cjs.map