UNPKG

typedash

Version:

modern, type-safe collection of utility functions

23 lines (21 loc) 779 B
import { t as capitalize } from "./capitalize-C9a76pfn.js"; //#region src/functions/startCase/startCase.ts /** * Converts a string to start case (first letter of each word capitalized, joined by spaces). * @param string The input string to convert to start case. * @returns A new string converted to start case. * @example * ```ts * startCase('--foo-bar--') // 'Foo Bar' * startCase('fooBar') // 'Foo Bar' * startCase('__FOO_BAR__') // 'FOO BAR' * ``` */ function startCase(string) { if (!/[a-z]+/i.test(string)) return string; return string.match(WORDS_REGEX)?.map((word) => capitalize(word)).join(" "); } const WORDS_REGEX = /[A-Z]{2,}(?=[A-Z][a-z]+\d*|\b)|[A-Z]?[a-z]+\d*|[A-Z]+|\d+/g; //#endregion export { startCase as t }; //# sourceMappingURL=startCase-CK5TWWzn.js.map