UNPKG

@n3okill/utils

Version:
21 lines 819 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.titleCase = titleCase; const toString_1 = require("./toString"); /** * Converts a CamelCase name into space-separated words. * For example, 'PostTag' will be converted to 'Post Tag'. * @param name the string to be converted * @param ucwords whether to capitalize the first letter in each word * @return the resulting words */ function titleCase(name, ucwords = true) { let str = (0, toString_1.toString)(name); str = str.replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase(); return ucwords ? str.replace(/([ -_.]|^)(.)/g, function (allMatches, firstMatch, secondMatch) { return (firstMatch ? " " : "") + secondMatch.toUpperCase(); }) : str; } //# sourceMappingURL=titleCase.js.map