nhb-toolbox 0.8.9 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,WACpB,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,WACpB,MAAM,YACJ,iBAAiB,KACzB,MA4CF,CAAC"}
|
package/dist/string/index.js
CHANGED
|
@@ -9,11 +9,7 @@ exports.capitalizeString = void 0;
|
|
|
9
9
|
* @param options Options to customize the capitalization.
|
|
10
10
|
* @returns Capitalized string.
|
|
11
11
|
*/
|
|
12
|
-
const capitalizeString = (string, options
|
|
13
|
-
capitalizeAll: false,
|
|
14
|
-
capitalizeEachFirst: false,
|
|
15
|
-
lowerCaseRest: true,
|
|
16
|
-
}) => {
|
|
12
|
+
const capitalizeString = (string, options) => {
|
|
17
13
|
if (typeof string !== 'string' || !string.trim())
|
|
18
14
|
return '';
|
|
19
15
|
if (!string)
|
|
@@ -21,7 +17,7 @@ const capitalizeString = (string, options = {
|
|
|
21
17
|
const trimmedString = string.trim();
|
|
22
18
|
if (!trimmedString)
|
|
23
19
|
return '';
|
|
24
|
-
const { capitalizeAll, capitalizeEachFirst, lowerCaseRest } = options;
|
|
20
|
+
const { capitalizeAll = false, capitalizeEachFirst = false, lowerCaseRest = true, } = options || {};
|
|
25
21
|
if (capitalizeAll) {
|
|
26
22
|
return trimmedString.toUpperCase();
|
|
27
23
|
}
|
|
@@ -34,10 +30,9 @@ const capitalizeString = (string, options = {
|
|
|
34
30
|
const matchArray = trimmedString.match(/^(\W*)(\w)(.*)$/);
|
|
35
31
|
if (matchArray && matchArray.length === 4) {
|
|
36
32
|
const [_, leadingSymbols, firstLetter, rest] = matchArray;
|
|
37
|
-
return
|
|
38
|
-
firstLetter
|
|
39
|
-
|
|
40
|
-
.concat(lowerCaseRest ? rest.toLowerCase() : rest));
|
|
33
|
+
return leadingSymbols
|
|
34
|
+
.concat(firstLetter.toUpperCase())
|
|
35
|
+
.concat(lowerCaseRest ? rest.toLowerCase() : rest);
|
|
41
36
|
}
|
|
42
37
|
return trimmedString
|
|
43
38
|
.charAt(0)
|
package/dist/string/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export interface CapitalizeOptions {
|
|
2
|
-
/** If true, capitalizes the first letter of each word (space separated). Defaults to `false
|
|
2
|
+
/** If true, capitalizes the first letter of each word (space separated). Defaults to `false`. */
|
|
3
3
|
capitalizeEachFirst?: boolean;
|
|
4
|
-
/** If true, ensures that the whole string is capitalized. Defaults to `false
|
|
4
|
+
/** If true, ensures that the whole string is capitalized. Defaults to `false`. */
|
|
5
5
|
capitalizeAll?: boolean;
|
|
6
|
-
/** If true, ensures that the rest of the string is lowercase. Defaults to `true
|
|
6
|
+
/** If true, ensures that the rest of the string is lowercase. Defaults to `true`. */
|
|
7
7
|
lowerCaseRest?: boolean;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/string/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IACjC,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/string/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IACjC,iGAAiG;IACjG,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,kFAAkF;IAClF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,qFAAqF;IACrF,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB"}
|
package/package.json
CHANGED