UNPKG

advanced-js-kit

Version:

Modern TypeScript utility library with tree-shaking support - Array, String, Number, Network, Sleep, and JWT utilities for JavaScript and TypeScript projects

28 lines (27 loc) 925 B
// src/universal/string/capitalize.ts function capitalize(str) { if (typeof str !== "string") { throw new Error("Input must be a string"); } if (str.length === 0) { return str; } return str.charAt(0).toUpperCase() + str.slice(1); } function capitalizeWords(str) { if (typeof str !== "string") { throw new Error("Input must be a string"); } return str.replace(/\b\w/g, (char) => char.toUpperCase()); } function convertCamelToNormalCapitalized(camelCaseString) { const words = camelCaseString.replace(/([a-z])([A-Z])/g, "$1 $2").split(/[\s_]+/); const capitalizedWords = words.map( (word) => word.charAt(0).toUpperCase() + word.slice(1) ); const normalCapitalizedString = capitalizedWords.join(" "); return normalCapitalizedString; } export { capitalize, capitalizeWords, convertCamelToNormalCapitalized }; //# sourceMappingURL=capitalize.js.map //# sourceMappingURL=capitalize.js.map