UNPKG

@n3okill/utils

Version:
18 lines 699 B
import { toString } from "./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 */ export function titleCase(name, ucwords = true) { let str = 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