typedash
Version:
modern, type-safe collection of utility functions
24 lines (22 loc) • 788 B
JavaScript
import { t as capitalize } from "./capitalize-C9a76pfn.js";
//#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() : capitalize(word)).join("");
}
const wordsRegex = /[\s_-]+|(?<=[a-z])(?=[A-Z])/;
//#endregion
export { camelCase as t };
//# sourceMappingURL=camelCase-7dj9ihzD.js.map