@full-pack/string-pack
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -94,3 +94,3 @@ /** | ||
* - Provide `false` or an empty string (`''`) for no separator. | ||
* - Provide `true` for a space (' ') as the separator. | ||
* - Provide `true` for a space (`' '`) as the separator. | ||
* @param {string[]} strings - The array of strings to merge. | ||
@@ -110,6 +110,27 @@ * @returns {string} The merged string. | ||
* - Provide `false` or an empty string (`''`) for no separator. | ||
* - Provide `true` for a space (' ') as the separator. | ||
* - Provide `true` for a space (`' '`) as the separator. | ||
*/ | ||
declare function merge(sep: string | boolean, ...strings: string[]): string; | ||
declare function merge(sep: string | boolean, ...strings: string[] | string[][]): string; | ||
export { compare, looseCompare, merge, padBidirectional, padEnd, padStart }; | ||
/** | ||
* Capitalizes the first letter of a word in a string. | ||
* @param {string} str - The input string. | ||
* @returns {string} The string with the first letter capitalized. | ||
* @example | ||
* capitalizeInitial('hello'); // 'Hello' | ||
* capitalizeInitial(':> hello'); // ':> Hello' | ||
*/ | ||
declare function capitalizeInitial(str: string): string; | ||
/** | ||
* Capitalizes the first letter of each word in a given string. | ||
* @param {string} str - The input string containing words to be capitalized. | ||
* @returns {string} Returns the input string with the first letter of each word capitalized. | ||
* @example | ||
* capitalizeWords('hello world'); | ||
* // 'Hello World' | ||
* capitalizeWords('Sphinx of black quartz:-judge my vow'); | ||
* // 'Sphinx Of Black Quartz:-Judge My Vow' | ||
*/ | ||
declare function capitalizeWords(str: string): string; | ||
export { capitalizeInitial, capitalizeWords, compare, looseCompare, merge, padBidirectional, padEnd, padStart }; |
@@ -23,2 +23,4 @@ "use strict"; | ||
__export(src_exports, { | ||
capitalizeInitial: () => capitalizeInitial, | ||
capitalizeWords: () => capitalizeWords, | ||
compare: () => compare, | ||
@@ -93,2 +95,3 @@ looseCompare: () => looseCompare, | ||
function merge(sep, ...strings) { | ||
strings = strings.flat(); | ||
for (let i = 0, val = ""; i < strings.length; i++) { | ||
@@ -104,4 +107,14 @@ if (strings.length - 1 === i) | ||
} | ||
// src/case.ts | ||
function capitalizeInitial(str) { | ||
return str.replace(/\b\w/, (char) => char.toUpperCase()); | ||
} | ||
function capitalizeWords(str) { | ||
return str.replace(/\b\w/g, (char) => char.toUpperCase()); | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
capitalizeInitial, | ||
capitalizeWords, | ||
compare, | ||
@@ -108,0 +121,0 @@ looseCompare, |
{ | ||
"name": "@full-pack/string-pack", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A lightweight and versatile String Utility Package for Node.js & Browser.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -23,9 +23,9 @@ # @full-pack/string-pack | ||
* [looseCompare](#loosecompare) | ||
* [capitalizeInitial](#capitalizeinitial) | ||
* [capitalizeWords](#capitalizewords) | ||
(Coming Soon) | ||
* [remove](#) | ||
* [looseRemove](#) | ||
* [caseConversion](#) | ||
* [regionMatch](#) | ||
* [looseRegionMatch](#) | ||
* [caseCoversion](#) | ||
* And Much More. | ||
@@ -116,2 +116,18 @@ * [Build](#build) | ||
### capitalizeInitial | ||
Capitalizes the first letter of a word in a string. | ||
```js | ||
capitalizeInitial('hello'); // 'Hello' | ||
capitalizeInitial(':> hello'); // ':> Hello' | ||
``` | ||
### capitalizeWords | ||
Capitalizes the first letter of each word in a given string. | ||
```js | ||
capitalizeWords('hello world'); // 'Hello World' | ||
capitalizeWords('Sphinx of black quartz:-judge my vow'); // 'Sphinx Of Black Quartz:-Judge My Vow' | ||
``` | ||
## Build | ||
@@ -118,0 +134,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39898
334
138