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

32 lines (30 loc) 1.02 kB
'use strict'; // 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; } exports.capitalize = capitalize; exports.capitalizeWords = capitalizeWords; exports.convertCamelToNormalCapitalized = convertCamelToNormalCapitalized; //# sourceMappingURL=capitalize.cjs.map //# sourceMappingURL=capitalize.cjs.map