UNPKG

typedash

Version:

modern, type-safe collection of utility functions

22 lines (21 loc) 712 B
//#region src/functions/kebabCase/kebabCase.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 * kebabCase('fooBar') // 'foo-bar' * kebabCase('foo bar') // 'foo-bar' * kebabCase('foo-bar') // 'foo-bar' * kebabCase('fooBar42') // 'foo-bar42' * ``` */ function kebabCase(string) { if (!/[a-z]+/i.test(string)) return string; return string.match(KEBAB_REGEX)?.map((x) => x.toLowerCase()).join("-"); } const KEBAB_REGEX = /[A-Z]{2,}(?=[A-Z][a-z]+\d*|\b)|[A-Z]?[a-z]+\d*|[A-Z]|\d+/g; //#endregion export { kebabCase as t }; //# sourceMappingURL=kebabCase-WtX4Ri98.js.map