typedash
Version:
modern, type-safe collection of utility functions
28 lines (26 loc) • 894 B
JavaScript
const require_capitalize = require('./capitalize-BDqzNm3J.cjs');
//#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) => require_capitalize.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
Object.defineProperty(exports, 'startCase', {
enumerable: true,
get: function () {
return startCase;
}
});
//# sourceMappingURL=startCase-DMTQunoR.cjs.map