@ls-stack/utils 3.30.1 → 3.31.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.
- package/docs/stringUtils/README.md +88 -4
- package/lib/chunk-3LZQMZAS.js +57 -0
- package/lib/{chunk-QLD7KG5I.js → chunk-IY3KYH32.js} +1 -1
- package/lib/concurrentCalls.js +1 -1
- package/lib/stringUtils.cjs +27 -6
- package/lib/stringUtils.d.cts +6 -2
- package/lib/stringUtils.d.ts +6 -2
- package/lib/stringUtils.js +9 -1
- package/lib/testUtils.js +2 -2
- package/lib/yamlStringify.js +2 -2
- package/package.json +1 -1
- package/lib/chunk-4REIIZQY.js +0 -40
|
@@ -76,13 +76,93 @@ joinStrings('a', addBString ? 'b' : null, 'c') // 'ac' if addBString is false, '
|
|
|
76
76
|
|
|
77
77
|
***
|
|
78
78
|
|
|
79
|
+
### convertToCamelCase()
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
function convertToCamelCase(str): string;
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Defined in: [packages/utils/src/stringUtils.ts:72](https://github.com/lucasols/utils/blob/main/packages/utils/src/stringUtils.ts#L72)
|
|
86
|
+
|
|
87
|
+
#### Parameters
|
|
88
|
+
|
|
89
|
+
##### str
|
|
90
|
+
|
|
91
|
+
`string`
|
|
92
|
+
|
|
93
|
+
#### Returns
|
|
94
|
+
|
|
95
|
+
`string`
|
|
96
|
+
|
|
97
|
+
***
|
|
98
|
+
|
|
99
|
+
### convertToPascalCase()
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
function convertToPascalCase(str): string;
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Defined in: [packages/utils/src/stringUtils.ts:65](https://github.com/lucasols/utils/blob/main/packages/utils/src/stringUtils.ts#L65)
|
|
106
|
+
|
|
107
|
+
#### Parameters
|
|
108
|
+
|
|
109
|
+
##### str
|
|
110
|
+
|
|
111
|
+
`string`
|
|
112
|
+
|
|
113
|
+
#### Returns
|
|
114
|
+
|
|
115
|
+
`string`
|
|
116
|
+
|
|
117
|
+
***
|
|
118
|
+
|
|
119
|
+
### convertToSentenceCase()
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
function convertToSentenceCase(str): string;
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Defined in: [packages/utils/src/stringUtils.ts:77](https://github.com/lucasols/utils/blob/main/packages/utils/src/stringUtils.ts#L77)
|
|
126
|
+
|
|
127
|
+
#### Parameters
|
|
128
|
+
|
|
129
|
+
##### str
|
|
130
|
+
|
|
131
|
+
`string`
|
|
132
|
+
|
|
133
|
+
#### Returns
|
|
134
|
+
|
|
135
|
+
`string`
|
|
136
|
+
|
|
137
|
+
***
|
|
138
|
+
|
|
79
139
|
### convertToSnakeCase()
|
|
80
140
|
|
|
81
141
|
```ts
|
|
82
142
|
function convertToSnakeCase(str): string;
|
|
83
143
|
```
|
|
84
144
|
|
|
85
|
-
Defined in: [packages/utils/src/stringUtils.ts:
|
|
145
|
+
Defined in: [packages/utils/src/stringUtils.ts:54](https://github.com/lucasols/utils/blob/main/packages/utils/src/stringUtils.ts#L54)
|
|
146
|
+
|
|
147
|
+
#### Parameters
|
|
148
|
+
|
|
149
|
+
##### str
|
|
150
|
+
|
|
151
|
+
`string`
|
|
152
|
+
|
|
153
|
+
#### Returns
|
|
154
|
+
|
|
155
|
+
`string`
|
|
156
|
+
|
|
157
|
+
***
|
|
158
|
+
|
|
159
|
+
### convertToTitleCase()
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
function convertToTitleCase(str): string;
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Defined in: [packages/utils/src/stringUtils.ts:85](https://github.com/lucasols/utils/blob/main/packages/utils/src/stringUtils.ts#L85)
|
|
86
166
|
|
|
87
167
|
#### Parameters
|
|
88
168
|
|
|
@@ -99,7 +179,7 @@ Defined in: [packages/utils/src/stringUtils.ts:47](https://github.com/lucasols/u
|
|
|
99
179
|
### formatNum()
|
|
100
180
|
|
|
101
181
|
```ts
|
|
102
|
-
function formatNum(num): string;
|
|
182
|
+
function formatNum(num, maxDecimalsOrOptions): string;
|
|
103
183
|
```
|
|
104
184
|
|
|
105
185
|
Defined in: [packages/utils/src/stringUtils.ts:36](https://github.com/lucasols/utils/blob/main/packages/utils/src/stringUtils.ts#L36)
|
|
@@ -110,6 +190,10 @@ Defined in: [packages/utils/src/stringUtils.ts:36](https://github.com/lucasols/u
|
|
|
110
190
|
|
|
111
191
|
`number`
|
|
112
192
|
|
|
193
|
+
##### maxDecimalsOrOptions
|
|
194
|
+
|
|
195
|
+
`number` | `NumberFormatOptions`
|
|
196
|
+
|
|
113
197
|
#### Returns
|
|
114
198
|
|
|
115
199
|
`string`
|
|
@@ -122,7 +206,7 @@ Defined in: [packages/utils/src/stringUtils.ts:36](https://github.com/lucasols/u
|
|
|
122
206
|
function isSnakeCase(str): boolean;
|
|
123
207
|
```
|
|
124
208
|
|
|
125
|
-
Defined in: [packages/utils/src/stringUtils.ts:
|
|
209
|
+
Defined in: [packages/utils/src/stringUtils.ts:50](https://github.com/lucasols/utils/blob/main/packages/utils/src/stringUtils.ts#L50)
|
|
126
210
|
|
|
127
211
|
#### Parameters
|
|
128
212
|
|
|
@@ -145,7 +229,7 @@ function truncateString(
|
|
|
145
229
|
ellipsis): string;
|
|
146
230
|
```
|
|
147
231
|
|
|
148
|
-
Defined in: [packages/utils/src/stringUtils.ts:
|
|
232
|
+
Defined in: [packages/utils/src/stringUtils.ts:92](https://github.com/lucasols/utils/blob/main/packages/utils/src/stringUtils.ts#L92)
|
|
149
233
|
|
|
150
234
|
#### Parameters
|
|
151
235
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/stringUtils.ts
|
|
2
|
+
function concatStrings(...args) {
|
|
3
|
+
const strings = [];
|
|
4
|
+
for (let i = 0; i < args.length; i++) {
|
|
5
|
+
const arg = args[i];
|
|
6
|
+
if (!arg) continue;
|
|
7
|
+
if (Array.isArray(arg)) {
|
|
8
|
+
strings.push(concatStrings(...arg));
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
strings.push(arg);
|
|
12
|
+
}
|
|
13
|
+
return strings.join("");
|
|
14
|
+
}
|
|
15
|
+
var joinStrings = concatStrings;
|
|
16
|
+
function formatNum(num, maxDecimalsOrOptions = 2) {
|
|
17
|
+
const options = typeof maxDecimalsOrOptions === "number" ? {
|
|
18
|
+
maximumFractionDigits: maxDecimalsOrOptions
|
|
19
|
+
} : maxDecimalsOrOptions;
|
|
20
|
+
return num.toLocaleString("en-US", options);
|
|
21
|
+
}
|
|
22
|
+
function isSnakeCase(str) {
|
|
23
|
+
return /^[a-z0-9_]+$/.test(str);
|
|
24
|
+
}
|
|
25
|
+
function convertToSnakeCase(str) {
|
|
26
|
+
return str.replace(/[\s\-.]+/g, "_").replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/[^a-z0-9_]/g, "").replace(/^_+|_+$/g, "").replace(/_+/g, "_");
|
|
27
|
+
}
|
|
28
|
+
function convertToPascalCase(str) {
|
|
29
|
+
return str.split(/[\s_-]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
30
|
+
}
|
|
31
|
+
function convertToCamelCase(str) {
|
|
32
|
+
const pascalCase = convertToPascalCase(str);
|
|
33
|
+
return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
|
|
34
|
+
}
|
|
35
|
+
function convertToSentenceCase(str) {
|
|
36
|
+
return str.split(/[\s_-]+/).map((word) => word.toLowerCase()).join(" ").replace(/^\w/, (char) => char.toUpperCase());
|
|
37
|
+
}
|
|
38
|
+
function convertToTitleCase(str) {
|
|
39
|
+
return str.split(/[\s_-]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
40
|
+
}
|
|
41
|
+
function truncateString(str, length, ellipsis = "\u2026") {
|
|
42
|
+
if (str.length <= length) return str;
|
|
43
|
+
return str.slice(0, length - 1) + ellipsis;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
concatStrings,
|
|
48
|
+
joinStrings,
|
|
49
|
+
formatNum,
|
|
50
|
+
isSnakeCase,
|
|
51
|
+
convertToSnakeCase,
|
|
52
|
+
convertToPascalCase,
|
|
53
|
+
convertToCamelCase,
|
|
54
|
+
convertToSentenceCase,
|
|
55
|
+
convertToTitleCase,
|
|
56
|
+
truncateString
|
|
57
|
+
};
|
package/lib/concurrentCalls.js
CHANGED
package/lib/stringUtils.cjs
CHANGED
|
@@ -21,7 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var stringUtils_exports = {};
|
|
22
22
|
__export(stringUtils_exports, {
|
|
23
23
|
concatStrings: () => concatStrings,
|
|
24
|
+
convertToCamelCase: () => convertToCamelCase,
|
|
25
|
+
convertToPascalCase: () => convertToPascalCase,
|
|
26
|
+
convertToSentenceCase: () => convertToSentenceCase,
|
|
24
27
|
convertToSnakeCase: () => convertToSnakeCase,
|
|
28
|
+
convertToTitleCase: () => convertToTitleCase,
|
|
25
29
|
formatNum: () => formatNum,
|
|
26
30
|
isSnakeCase: () => isSnakeCase,
|
|
27
31
|
joinStrings: () => joinStrings,
|
|
@@ -42,17 +46,30 @@ function concatStrings(...args) {
|
|
|
42
46
|
return strings.join("");
|
|
43
47
|
}
|
|
44
48
|
var joinStrings = concatStrings;
|
|
45
|
-
function formatNum(num) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
function formatNum(num, maxDecimalsOrOptions = 2) {
|
|
50
|
+
const options = typeof maxDecimalsOrOptions === "number" ? {
|
|
51
|
+
maximumFractionDigits: maxDecimalsOrOptions
|
|
52
|
+
} : maxDecimalsOrOptions;
|
|
53
|
+
return num.toLocaleString("en-US", options);
|
|
50
54
|
}
|
|
51
55
|
function isSnakeCase(str) {
|
|
52
56
|
return /^[a-z0-9_]+$/.test(str);
|
|
53
57
|
}
|
|
54
58
|
function convertToSnakeCase(str) {
|
|
55
|
-
return str.replace(/([A-Z])/g, "
|
|
59
|
+
return str.replace(/[\s\-.]+/g, "_").replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/[^a-z0-9_]/g, "").replace(/^_+|_+$/g, "").replace(/_+/g, "_");
|
|
60
|
+
}
|
|
61
|
+
function convertToPascalCase(str) {
|
|
62
|
+
return str.split(/[\s_-]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
|
|
63
|
+
}
|
|
64
|
+
function convertToCamelCase(str) {
|
|
65
|
+
const pascalCase = convertToPascalCase(str);
|
|
66
|
+
return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
|
|
67
|
+
}
|
|
68
|
+
function convertToSentenceCase(str) {
|
|
69
|
+
return str.split(/[\s_-]+/).map((word) => word.toLowerCase()).join(" ").replace(/^\w/, (char) => char.toUpperCase());
|
|
70
|
+
}
|
|
71
|
+
function convertToTitleCase(str) {
|
|
72
|
+
return str.split(/[\s_-]+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
56
73
|
}
|
|
57
74
|
function truncateString(str, length, ellipsis = "\u2026") {
|
|
58
75
|
if (str.length <= length) return str;
|
|
@@ -61,7 +78,11 @@ function truncateString(str, length, ellipsis = "\u2026") {
|
|
|
61
78
|
// Annotate the CommonJS export names for ESM import in node:
|
|
62
79
|
0 && (module.exports = {
|
|
63
80
|
concatStrings,
|
|
81
|
+
convertToCamelCase,
|
|
82
|
+
convertToPascalCase,
|
|
83
|
+
convertToSentenceCase,
|
|
64
84
|
convertToSnakeCase,
|
|
85
|
+
convertToTitleCase,
|
|
65
86
|
formatNum,
|
|
66
87
|
isSnakeCase,
|
|
67
88
|
joinStrings,
|
package/lib/stringUtils.d.cts
CHANGED
|
@@ -13,9 +13,13 @@ declare function concatStrings(...args: (Arg | Arg[])[]): string;
|
|
|
13
13
|
* @deprecated Use {@link concatStrings} instead
|
|
14
14
|
*/
|
|
15
15
|
declare const joinStrings: typeof concatStrings;
|
|
16
|
-
declare function formatNum(num: number): string;
|
|
16
|
+
declare function formatNum(num: number, maxDecimalsOrOptions?: number | Intl.NumberFormatOptions): string;
|
|
17
17
|
declare function isSnakeCase(str: string): boolean;
|
|
18
18
|
declare function convertToSnakeCase(str: string): string;
|
|
19
|
+
declare function convertToPascalCase(str: string): string;
|
|
20
|
+
declare function convertToCamelCase(str: string): string;
|
|
21
|
+
declare function convertToSentenceCase(str: string): string;
|
|
22
|
+
declare function convertToTitleCase(str: string): string;
|
|
19
23
|
declare function truncateString(str: string, length: number, ellipsis?: string): string;
|
|
20
24
|
|
|
21
|
-
export { concatStrings, convertToSnakeCase, formatNum, isSnakeCase, joinStrings, truncateString };
|
|
25
|
+
export { concatStrings, convertToCamelCase, convertToPascalCase, convertToSentenceCase, convertToSnakeCase, convertToTitleCase, formatNum, isSnakeCase, joinStrings, truncateString };
|
package/lib/stringUtils.d.ts
CHANGED
|
@@ -13,9 +13,13 @@ declare function concatStrings(...args: (Arg | Arg[])[]): string;
|
|
|
13
13
|
* @deprecated Use {@link concatStrings} instead
|
|
14
14
|
*/
|
|
15
15
|
declare const joinStrings: typeof concatStrings;
|
|
16
|
-
declare function formatNum(num: number): string;
|
|
16
|
+
declare function formatNum(num: number, maxDecimalsOrOptions?: number | Intl.NumberFormatOptions): string;
|
|
17
17
|
declare function isSnakeCase(str: string): boolean;
|
|
18
18
|
declare function convertToSnakeCase(str: string): string;
|
|
19
|
+
declare function convertToPascalCase(str: string): string;
|
|
20
|
+
declare function convertToCamelCase(str: string): string;
|
|
21
|
+
declare function convertToSentenceCase(str: string): string;
|
|
22
|
+
declare function convertToTitleCase(str: string): string;
|
|
19
23
|
declare function truncateString(str: string, length: number, ellipsis?: string): string;
|
|
20
24
|
|
|
21
|
-
export { concatStrings, convertToSnakeCase, formatNum, isSnakeCase, joinStrings, truncateString };
|
|
25
|
+
export { concatStrings, convertToCamelCase, convertToPascalCase, convertToSentenceCase, convertToSnakeCase, convertToTitleCase, formatNum, isSnakeCase, joinStrings, truncateString };
|
package/lib/stringUtils.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
concatStrings,
|
|
3
|
+
convertToCamelCase,
|
|
4
|
+
convertToPascalCase,
|
|
5
|
+
convertToSentenceCase,
|
|
3
6
|
convertToSnakeCase,
|
|
7
|
+
convertToTitleCase,
|
|
4
8
|
formatNum,
|
|
5
9
|
isSnakeCase,
|
|
6
10
|
joinStrings,
|
|
7
11
|
truncateString
|
|
8
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-3LZQMZAS.js";
|
|
9
13
|
export {
|
|
10
14
|
concatStrings,
|
|
15
|
+
convertToCamelCase,
|
|
16
|
+
convertToPascalCase,
|
|
17
|
+
convertToSentenceCase,
|
|
11
18
|
convertToSnakeCase,
|
|
19
|
+
convertToTitleCase,
|
|
12
20
|
formatNum,
|
|
13
21
|
isSnakeCase,
|
|
14
22
|
joinStrings,
|
package/lib/testUtils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
yamlStringify
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IY3KYH32.js";
|
|
4
4
|
import {
|
|
5
5
|
omit,
|
|
6
6
|
pick
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
import {
|
|
19
19
|
clampMin
|
|
20
20
|
} from "./chunk-HTCYUMDR.js";
|
|
21
|
-
import "./chunk-
|
|
21
|
+
import "./chunk-3LZQMZAS.js";
|
|
22
22
|
import {
|
|
23
23
|
arrayWithPrevAndIndex,
|
|
24
24
|
filterAndMap
|
package/lib/yamlStringify.js
CHANGED
package/package.json
CHANGED
package/lib/chunk-4REIIZQY.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// src/stringUtils.ts
|
|
2
|
-
function concatStrings(...args) {
|
|
3
|
-
const strings = [];
|
|
4
|
-
for (let i = 0; i < args.length; i++) {
|
|
5
|
-
const arg = args[i];
|
|
6
|
-
if (!arg) continue;
|
|
7
|
-
if (Array.isArray(arg)) {
|
|
8
|
-
strings.push(concatStrings(...arg));
|
|
9
|
-
continue;
|
|
10
|
-
}
|
|
11
|
-
strings.push(arg);
|
|
12
|
-
}
|
|
13
|
-
return strings.join("");
|
|
14
|
-
}
|
|
15
|
-
var joinStrings = concatStrings;
|
|
16
|
-
function formatNum(num) {
|
|
17
|
-
return num.toLocaleString("en-US", {
|
|
18
|
-
minimumFractionDigits: 2,
|
|
19
|
-
maximumFractionDigits: 2
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
function isSnakeCase(str) {
|
|
23
|
-
return /^[a-z0-9_]+$/.test(str);
|
|
24
|
-
}
|
|
25
|
-
function convertToSnakeCase(str) {
|
|
26
|
-
return str.replace(/([A-Z])/g, "_$1").replace(/[^a-z0-9_]/g, "").toLowerCase();
|
|
27
|
-
}
|
|
28
|
-
function truncateString(str, length, ellipsis = "\u2026") {
|
|
29
|
-
if (str.length <= length) return str;
|
|
30
|
-
return str.slice(0, length - 1) + ellipsis;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
concatStrings,
|
|
35
|
-
joinStrings,
|
|
36
|
-
formatNum,
|
|
37
|
-
isSnakeCase,
|
|
38
|
-
convertToSnakeCase,
|
|
39
|
-
truncateString
|
|
40
|
-
};
|