@newdash/newdash
Version:
javascript/typescript utility library
34 lines (33 loc) • 1.1 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.startCase = void 0;
const upperFirst_1 = __importDefault(require("./upperFirst"));
const words_1 = __importDefault(require("./words"));
/**
* Converts `string` to
* [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
*
* @since 3.1.0
* @category String
* @param s The string to convert.
* @returns {string} Returns the start cased string.
* @see camelCase, lowerCase, kebabCase, snakeCase, upperCase, upperFirst
* @example
*
* startCase('--foo-bar--')
* // => 'Foo Bar'
*
* startCase('fooBar')
* // => 'Foo Bar'
*
* startCase('__FOO_BAR__')
* // => 'FOO BAR'
*/
function startCase(s = "") {
return (0, words_1.default)(`${s}`.replace(/['\u2019]/g, "")).reduce((result, word, index) => (result + (index ? " " : "") + (0, upperFirst_1.default)(word)), "");
}
exports.startCase = startCase;
exports.default = startCase;