nhb-toolbox 2.3.3 → 2.3.5
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.
- package/dist/string/constants.d.ts +2 -0
- package/dist/string/constants.d.ts.map +1 -0
- package/dist/string/constants.js +130 -0
- package/dist/string/convert.d.ts +22 -4
- package/dist/string/convert.d.ts.map +1 -1
- package/dist/string/convert.js +57 -6
- package/dist/string/types.d.ts +2 -0
- package/dist/string/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/string/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,EAAE,MAAM,EAiIpB,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOWERCASE = void 0;
|
|
4
|
+
exports.LOWERCASE = [
|
|
5
|
+
// Conjunctions
|
|
6
|
+
'and',
|
|
7
|
+
'but',
|
|
8
|
+
'or',
|
|
9
|
+
'nor',
|
|
10
|
+
'for',
|
|
11
|
+
'so',
|
|
12
|
+
'yet',
|
|
13
|
+
'after',
|
|
14
|
+
'although',
|
|
15
|
+
'as',
|
|
16
|
+
'because',
|
|
17
|
+
'before',
|
|
18
|
+
'even',
|
|
19
|
+
'if',
|
|
20
|
+
'once',
|
|
21
|
+
'since',
|
|
22
|
+
'than',
|
|
23
|
+
'that',
|
|
24
|
+
'though',
|
|
25
|
+
'unless',
|
|
26
|
+
'until',
|
|
27
|
+
'when',
|
|
28
|
+
'whenever',
|
|
29
|
+
'where',
|
|
30
|
+
'whereas',
|
|
31
|
+
'wherever',
|
|
32
|
+
'whether',
|
|
33
|
+
'while',
|
|
34
|
+
// Prepositions
|
|
35
|
+
'about',
|
|
36
|
+
'above',
|
|
37
|
+
'across',
|
|
38
|
+
'after',
|
|
39
|
+
'against',
|
|
40
|
+
'along',
|
|
41
|
+
'among',
|
|
42
|
+
'around',
|
|
43
|
+
'as',
|
|
44
|
+
'at',
|
|
45
|
+
'before',
|
|
46
|
+
'behind',
|
|
47
|
+
'below',
|
|
48
|
+
'beneath',
|
|
49
|
+
'beside',
|
|
50
|
+
'between',
|
|
51
|
+
'beyond',
|
|
52
|
+
'but',
|
|
53
|
+
'by',
|
|
54
|
+
'concerning',
|
|
55
|
+
'considering',
|
|
56
|
+
'despite',
|
|
57
|
+
'down',
|
|
58
|
+
'during',
|
|
59
|
+
'except',
|
|
60
|
+
'following',
|
|
61
|
+
'for',
|
|
62
|
+
'from',
|
|
63
|
+
'in',
|
|
64
|
+
'inside',
|
|
65
|
+
'into',
|
|
66
|
+
'like',
|
|
67
|
+
'minus',
|
|
68
|
+
'near',
|
|
69
|
+
'of',
|
|
70
|
+
'off',
|
|
71
|
+
'on',
|
|
72
|
+
'onto',
|
|
73
|
+
'opposite',
|
|
74
|
+
'out',
|
|
75
|
+
'outside',
|
|
76
|
+
'over',
|
|
77
|
+
'past',
|
|
78
|
+
'per',
|
|
79
|
+
'plus',
|
|
80
|
+
'regarding',
|
|
81
|
+
'round',
|
|
82
|
+
'save',
|
|
83
|
+
'since',
|
|
84
|
+
'than',
|
|
85
|
+
'through',
|
|
86
|
+
'throughout',
|
|
87
|
+
'till',
|
|
88
|
+
'to',
|
|
89
|
+
'toward',
|
|
90
|
+
'towards',
|
|
91
|
+
'under',
|
|
92
|
+
'underneath',
|
|
93
|
+
'unlike',
|
|
94
|
+
'until',
|
|
95
|
+
'up',
|
|
96
|
+
'upon',
|
|
97
|
+
'versus',
|
|
98
|
+
'via',
|
|
99
|
+
'with',
|
|
100
|
+
'within',
|
|
101
|
+
'without',
|
|
102
|
+
// Articles
|
|
103
|
+
'a',
|
|
104
|
+
'an',
|
|
105
|
+
'the',
|
|
106
|
+
// Auxiliary Verbs
|
|
107
|
+
'am',
|
|
108
|
+
'are',
|
|
109
|
+
'be',
|
|
110
|
+
'been',
|
|
111
|
+
'being',
|
|
112
|
+
'can',
|
|
113
|
+
'could',
|
|
114
|
+
'do',
|
|
115
|
+
'does',
|
|
116
|
+
'did',
|
|
117
|
+
'had',
|
|
118
|
+
'has',
|
|
119
|
+
'have',
|
|
120
|
+
'is',
|
|
121
|
+
'may',
|
|
122
|
+
'might',
|
|
123
|
+
'must',
|
|
124
|
+
'shall',
|
|
125
|
+
'should',
|
|
126
|
+
'was',
|
|
127
|
+
'were',
|
|
128
|
+
'will',
|
|
129
|
+
'would',
|
|
130
|
+
];
|
package/dist/string/convert.d.ts
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
|
+
import type { CaseFormat } from './types';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* Converts a string to a specified case format such as `camelCase`, `snake_case`, `kebab-case`, `PascalCase`, `Title Case`, `lowercase`, or `UPPERCASE`.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
5
|
+
* This function handles non-alphanumeric characters (e.g., spaces, hyphens, underscores, dots, slashes) as word delimiters. For `Title Case`, prepositions, articles, conjunctions, and auxiliary verbs are not capitalized unless they appear at the start of the title.
|
|
6
|
+
* You can also convert the string to `lowercase` or `UPPERCASE`, but it's recommended to use default string methods like `string.toLowerCase()` and `string.toUpperCase()` for these cases.
|
|
7
|
+
*
|
|
8
|
+
* @param string The input string to be converted. The string should have words separated by non-alphanumeric characters (e.g., spaces, hyphens, underscores, etc.).
|
|
9
|
+
* @param format The format to convert the string to. The available formats are:
|
|
10
|
+
* - `'camelCase'`: Converts to camelCase (e.g., `myVariableName`).
|
|
11
|
+
* - `'snake_case'`: Converts to snake_case (e.g., `my_variable_name`).
|
|
12
|
+
* - `'kebab-case'`: Converts to kebab-case (e.g., `my-variable-name`).
|
|
13
|
+
* - `'PascalCase'`: Converts to PascalCase (e.g., `MyVariableName`).
|
|
14
|
+
* - `'Title Case'`: Converts to Title Case (e.g., `My Variable Name`), where certain words like `prepositions, articles, conjunctions and auxiliary verbs` are not capitalized unless at the start.
|
|
15
|
+
* - `'lowercase'`: Converts the string to all lowercase characters.
|
|
16
|
+
* - `'UPPERCASE'`: Converts the string to all uppercase characters.
|
|
6
17
|
* @returns The formatted string in the specified case format.
|
|
18
|
+
* @example
|
|
19
|
+
* convertStringCase('my-example_string', 'camelCase'); // returns 'myExampleString'
|
|
20
|
+
* convertStringCase('my-example_string', 'snake_case'); // returns 'my_example_string'
|
|
21
|
+
* convertStringCase('my-example_string', 'kebab-case'); // returns 'my-example-string'
|
|
22
|
+
* convertStringCase('my example string', 'Title Case'); // returns 'My Example String'
|
|
23
|
+
* convertStringCase('my example string', 'lowercase'); // returns 'my example string'
|
|
24
|
+
* convertStringCase('my example string', 'UPPERCASE'); // returns 'MY EXAMPLE STRING'
|
|
7
25
|
*/
|
|
8
|
-
export declare function convertStringCase(string: string, format:
|
|
26
|
+
export declare function convertStringCase(string: string, format: CaseFormat): string;
|
|
9
27
|
/**
|
|
10
28
|
* Replaces all occurrences of a string or pattern in the given input string.
|
|
11
29
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/string/convert.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../../src/string/convert.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,CA6E5E;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,UACvB,MAAM,QACP,MAAM,GAAG,MAAM,WACZ,MAAM,KACb,MAgBF,CAAC"}
|
package/dist/string/convert.js
CHANGED
|
@@ -1,28 +1,79 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replaceAllInString = void 0;
|
|
4
|
+
exports.convertStringCase = convertStringCase;
|
|
5
|
+
const constants_1 = require("./constants");
|
|
2
6
|
/**
|
|
3
|
-
*
|
|
7
|
+
* Converts a string to a specified case format such as `camelCase`, `snake_case`, `kebab-case`, `PascalCase`, `Title Case`, `lowercase`, or `UPPERCASE`.
|
|
8
|
+
*
|
|
9
|
+
* This function handles non-alphanumeric characters (e.g., spaces, hyphens, underscores, dots, slashes) as word delimiters. For `Title Case`, prepositions, articles, conjunctions, and auxiliary verbs are not capitalized unless they appear at the start of the title.
|
|
10
|
+
* You can also convert the string to `lowercase` or `UPPERCASE`, but it's recommended to use default string methods like `string.toLowerCase()` and `string.toUpperCase()` for these cases.
|
|
4
11
|
*
|
|
5
|
-
* @param string
|
|
6
|
-
* @param format
|
|
12
|
+
* @param string The input string to be converted. The string should have words separated by non-alphanumeric characters (e.g., spaces, hyphens, underscores, etc.).
|
|
13
|
+
* @param format The format to convert the string to. The available formats are:
|
|
14
|
+
* - `'camelCase'`: Converts to camelCase (e.g., `myVariableName`).
|
|
15
|
+
* - `'snake_case'`: Converts to snake_case (e.g., `my_variable_name`).
|
|
16
|
+
* - `'kebab-case'`: Converts to kebab-case (e.g., `my-variable-name`).
|
|
17
|
+
* - `'PascalCase'`: Converts to PascalCase (e.g., `MyVariableName`).
|
|
18
|
+
* - `'Title Case'`: Converts to Title Case (e.g., `My Variable Name`), where certain words like `prepositions, articles, conjunctions and auxiliary verbs` are not capitalized unless at the start.
|
|
19
|
+
* - `'lowercase'`: Converts the string to all lowercase characters.
|
|
20
|
+
* - `'UPPERCASE'`: Converts the string to all uppercase characters.
|
|
7
21
|
* @returns The formatted string in the specified case format.
|
|
22
|
+
* @example
|
|
23
|
+
* convertStringCase('my-example_string', 'camelCase'); // returns 'myExampleString'
|
|
24
|
+
* convertStringCase('my-example_string', 'snake_case'); // returns 'my_example_string'
|
|
25
|
+
* convertStringCase('my-example_string', 'kebab-case'); // returns 'my-example-string'
|
|
26
|
+
* convertStringCase('my example string', 'Title Case'); // returns 'My Example String'
|
|
27
|
+
* convertStringCase('my example string', 'lowercase'); // returns 'my example string'
|
|
28
|
+
* convertStringCase('my example string', 'UPPERCASE'); // returns 'MY EXAMPLE STRING'
|
|
8
29
|
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.replaceAllInString = void 0;
|
|
11
|
-
exports.convertStringCase = convertStringCase;
|
|
12
30
|
function convertStringCase(string, format) {
|
|
13
31
|
if (!string || typeof string !== 'string')
|
|
14
32
|
return '';
|
|
33
|
+
const start = string.match(/^[^\d\w\s]+/)?.[0] || '';
|
|
34
|
+
const end = string.match(/[^\d\w\s]+$/)?.[0] || '';
|
|
35
|
+
const core = string.replace(/^[^\d\w\s]+|[^\w\s]+$/g, '').trim();
|
|
36
|
+
const titleCase = core
|
|
37
|
+
.split(/\s+/g)
|
|
38
|
+
.map((part) => {
|
|
39
|
+
const startSymbol = part.match(/^[^\d\w\s]+/)?.[0] || ''; // Capture leading symbols
|
|
40
|
+
const endSymbol = part.match(/[^\d\w\s]+$/)?.[0] || ''; // Capture trailing symbols
|
|
41
|
+
const coreWord = part.replace(/^[^\d\w\s]+|[^\d\w\s]+$/g, ''); // Remove them for processing
|
|
42
|
+
if (constants_1.LOWERCASE.includes(coreWord.toLowerCase())) {
|
|
43
|
+
return startSymbol + coreWord.toLowerCase() + endSymbol;
|
|
44
|
+
}
|
|
45
|
+
return (startSymbol +
|
|
46
|
+
coreWord.charAt(0).toUpperCase() +
|
|
47
|
+
coreWord.slice(1) +
|
|
48
|
+
endSymbol);
|
|
49
|
+
})
|
|
50
|
+
.join(' ');
|
|
15
51
|
const formattedString = string.replace(/[^a-zA-Z0-9]+(.)?/g, (_, chr) => (chr ? chr.toUpperCase() : ''));
|
|
16
52
|
if (!formattedString)
|
|
17
53
|
return '';
|
|
18
54
|
switch (format) {
|
|
19
55
|
case 'camelCase':
|
|
56
|
+
// return formattedString.replace(/[A-Z]/g, (letter, index) =>
|
|
57
|
+
// index === 0 ? letter.toUpperCase() : letter.toLowerCase(),
|
|
58
|
+
// );
|
|
20
59
|
return (formattedString.charAt(0).toLowerCase() +
|
|
21
60
|
formattedString.slice(1));
|
|
22
61
|
case 'snake_case':
|
|
23
62
|
return formattedString.replace(/[A-Z]/g, (letter, index) => index === 0 ? letter.toLowerCase() : `_${letter.toLowerCase()}`);
|
|
24
63
|
case 'kebab-case':
|
|
25
64
|
return formattedString.replace(/[A-Z]/g, (letter, index) => index === 0 ? letter.toLowerCase() : `-${letter.toLowerCase()}`);
|
|
65
|
+
case 'PascalCase':
|
|
66
|
+
return (formattedString.charAt(0).toUpperCase() +
|
|
67
|
+
formattedString.slice(1));
|
|
68
|
+
case 'Title Case':
|
|
69
|
+
return (start +
|
|
70
|
+
titleCase.charAt(0).toUpperCase() +
|
|
71
|
+
titleCase.slice(1) +
|
|
72
|
+
end);
|
|
73
|
+
case 'lowercase':
|
|
74
|
+
return start + core.toLowerCase() + end;
|
|
75
|
+
case 'UPPERCASE':
|
|
76
|
+
return start + core.toUpperCase() + end;
|
|
26
77
|
default:
|
|
27
78
|
return formattedString;
|
|
28
79
|
}
|
package/dist/string/types.d.ts
CHANGED
|
@@ -33,5 +33,7 @@ export interface AnagramOptions {
|
|
|
33
33
|
/** Whether to lookup in the dictionary. Default is `false`. */
|
|
34
34
|
validWords?: boolean;
|
|
35
35
|
}
|
|
36
|
+
/** - Case formats for converting a string */
|
|
37
|
+
export type CaseFormat = 'camelCase' | 'snake_case' | 'kebab-case' | 'PascalCase' | 'Title Case' | 'UPPERCASE' | 'lowercase';
|
|
36
38
|
export {};
|
|
37
39
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/string/types.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,MAAM,WAAW,iBAAiB;IACjC,iGAAiG;IACj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