@ls-stack/utils 3.30.0 → 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/_media/modules.md +2 -0
- package/docs/modules.md +2 -0
- package/docs/stringUtils/README.md +88 -4
- package/docs/typeUtils/-internal-.md +99 -0
- package/docs/typeUtils/README.md +177 -0
- package/docs/typeUtils.typesTest.md +7 -0
- package/docs/typingUtils.md +36 -12
- 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/typeUtils.cjs +18 -0
- package/lib/typeUtils.d.cts +39 -0
- package/lib/typeUtils.d.ts +39 -0
- package/lib/typeUtils.js +0 -0
- package/lib/typingUtils.d.cts +6 -0
- package/lib/typingUtils.d.ts +6 -0
- package/lib/yamlStringify.js +2 -2
- package/package.json +9 -1
- package/lib/chunk-4REIIZQY.js +0 -40
package/docs/_media/modules.md
CHANGED
|
@@ -47,6 +47,8 @@
|
|
|
47
47
|
- [timers](timers.md)
|
|
48
48
|
- [tsResult](tsResult/README.md)
|
|
49
49
|
- [typeGuards](typeGuards.md)
|
|
50
|
+
- [typeUtils](typeUtils/README.md)
|
|
51
|
+
- [typeUtils.typesTest](typeUtils.typesTest.md)
|
|
50
52
|
- [typingFnUtils](typingFnUtils/README.md)
|
|
51
53
|
- [typingTestUtils](typingTestUtils.md)
|
|
52
54
|
- [typingUtils](typingUtils.md)
|
package/docs/modules.md
CHANGED
|
@@ -47,6 +47,8 @@
|
|
|
47
47
|
- [timers](timers.md)
|
|
48
48
|
- [tsResult](tsResult/README.md)
|
|
49
49
|
- [typeGuards](typeGuards.md)
|
|
50
|
+
- [typeUtils](typeUtils/README.md)
|
|
51
|
+
- [typeUtils.typesTest](typeUtils.typesTest.md)
|
|
50
52
|
- [typingFnUtils](typingFnUtils/README.md)
|
|
51
53
|
- [typingTestUtils](typingTestUtils.md)
|
|
52
54
|
- [typingUtils](typingUtils.md)
|
|
@@ -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,99 @@
|
|
|
1
|
+
[**@ls-stack/utils**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@ls-stack/utils](../modules.md) / [typeUtils](README.md) / \<internal\>
|
|
6
|
+
|
|
7
|
+
# \<internal\>
|
|
8
|
+
|
|
9
|
+
## Type Aliases
|
|
10
|
+
|
|
11
|
+
### BuildArrayPath\<BasePath\>
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
type BuildArrayPath<BasePath> = BasePath extends "$" ? "[*]" : `${BasePath}[*]`;
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Defined in: [packages/utils/src/typeUtils.ts:62](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeUtils.ts#L62)
|
|
18
|
+
|
|
19
|
+
#### Type Parameters
|
|
20
|
+
|
|
21
|
+
##### BasePath
|
|
22
|
+
|
|
23
|
+
`BasePath` *extends* `string`
|
|
24
|
+
|
|
25
|
+
***
|
|
26
|
+
|
|
27
|
+
### BuildPath\<BasePath, Key\>
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
type BuildPath<BasePath, Key> = BasePath extends "$" ? Key extends string | number ? `${Key}` : never : Key extends string | number ? `${BasePath}.${Key}` : never;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Defined in: [packages/utils/src/typeUtils.ts:54](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeUtils.ts#L54)
|
|
34
|
+
|
|
35
|
+
#### Type Parameters
|
|
36
|
+
|
|
37
|
+
##### BasePath
|
|
38
|
+
|
|
39
|
+
`BasePath` *extends* `string`
|
|
40
|
+
|
|
41
|
+
##### Key
|
|
42
|
+
|
|
43
|
+
`Key` *extends* `PropertyKey`
|
|
44
|
+
|
|
45
|
+
***
|
|
46
|
+
|
|
47
|
+
### DeepReplaceValueImpl\<T, ReplaceType, NewType, SkipPaths, SkipType, Path\>
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
type DeepReplaceValueImpl<T, ReplaceType, NewType, SkipPaths, SkipType, Path> = SkipPaths extends string ? PathMatches<Path, SkipPaths> extends true ? T : T extends ReplaceType ? T extends SkipType ? T : NewType : T extends readonly infer U[] ? DeepReplaceValueImpl<U, ReplaceType, NewType, SkipPaths, SkipType, BuildArrayPath<Path>>[] : T extends SkipType ? T : T extends Record<string, any> ? { [K in keyof T]: DeepReplaceValueImpl<T[K], ReplaceType, NewType, SkipPaths, SkipType, BuildPath<Path, K>> } : T : T extends ReplaceType ? T extends SkipType ? T : NewType : T extends readonly infer U[] ? DeepReplaceValueImpl<U, ReplaceType, NewType, SkipPaths, SkipType, BuildArrayPath<Path>>[] : T extends SkipType ? T : T extends Record<string, any> ? { [K in keyof T]: DeepReplaceValueImpl<T[K], ReplaceType, NewType, SkipPaths, SkipType, BuildPath<Path, K>> } : T;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Defined in: [packages/utils/src/typeUtils.ts:65](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeUtils.ts#L65)
|
|
54
|
+
|
|
55
|
+
#### Type Parameters
|
|
56
|
+
|
|
57
|
+
##### T
|
|
58
|
+
|
|
59
|
+
`T`
|
|
60
|
+
|
|
61
|
+
##### ReplaceType
|
|
62
|
+
|
|
63
|
+
`ReplaceType`
|
|
64
|
+
|
|
65
|
+
##### NewType
|
|
66
|
+
|
|
67
|
+
`NewType`
|
|
68
|
+
|
|
69
|
+
##### SkipPaths
|
|
70
|
+
|
|
71
|
+
`SkipPaths` *extends* `string` \| `undefined`
|
|
72
|
+
|
|
73
|
+
##### SkipType
|
|
74
|
+
|
|
75
|
+
`SkipType`
|
|
76
|
+
|
|
77
|
+
##### Path
|
|
78
|
+
|
|
79
|
+
`Path` *extends* `string` = `"$"`
|
|
80
|
+
|
|
81
|
+
***
|
|
82
|
+
|
|
83
|
+
### PathMatches\<CurrentPath, SkipPaths\>
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
type PathMatches<CurrentPath, SkipPaths> = true extends SkipPaths extends any ? CurrentPath extends SkipPaths ? true : SkipPaths extends `${infer Prefix}[*]${infer Suffix}` ? CurrentPath extends `${Prefix}[${string}]${Suffix}` ? true : false : false : false ? true : false;
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Defined in: [packages/utils/src/typeUtils.ts:40](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeUtils.ts#L40)
|
|
90
|
+
|
|
91
|
+
#### Type Parameters
|
|
92
|
+
|
|
93
|
+
##### CurrentPath
|
|
94
|
+
|
|
95
|
+
`CurrentPath` *extends* `string`
|
|
96
|
+
|
|
97
|
+
##### SkipPaths
|
|
98
|
+
|
|
99
|
+
`SkipPaths` *extends* `string`
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
[**@ls-stack/utils**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@ls-stack/utils](../modules.md) / typeUtils
|
|
6
|
+
|
|
7
|
+
# typeUtils
|
|
8
|
+
|
|
9
|
+
## Modules
|
|
10
|
+
|
|
11
|
+
- [\<internal\>](-internal-.md)
|
|
12
|
+
|
|
13
|
+
## Type Aliases
|
|
14
|
+
|
|
15
|
+
### DeepPrettify\<T\>
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
type DeepPrettify<T> = { [K in keyof T]: T[K] extends Record<string, unknown> ? DeepPrettify<T[K]> : T[K] } & object;
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Defined in: [packages/utils/src/typeUtils.ts:25](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeUtils.ts#L25)
|
|
22
|
+
|
|
23
|
+
#### Type Parameters
|
|
24
|
+
|
|
25
|
+
##### T
|
|
26
|
+
|
|
27
|
+
`T`
|
|
28
|
+
|
|
29
|
+
***
|
|
30
|
+
|
|
31
|
+
### DeepReplaceValue\<T, ReplaceType, NewType, SkipPaths, SkipTypes\>
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
type DeepReplaceValue<T, ReplaceType, NewType, SkipPaths, SkipTypes> = DeepReplaceValueImpl<T, ReplaceType, NewType, SkipPaths, SkipTypes>;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Defined in: [packages/utils/src/typeUtils.ts:141](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeUtils.ts#L141)
|
|
38
|
+
|
|
39
|
+
Replaces all values that extends `ReplaceType` with `NewType` in a deeply nested object or array.
|
|
40
|
+
|
|
41
|
+
#### Type Parameters
|
|
42
|
+
|
|
43
|
+
##### T
|
|
44
|
+
|
|
45
|
+
`T`
|
|
46
|
+
|
|
47
|
+
The object or array to replace values in.
|
|
48
|
+
|
|
49
|
+
##### ReplaceType
|
|
50
|
+
|
|
51
|
+
`ReplaceType`
|
|
52
|
+
|
|
53
|
+
The type to replace.
|
|
54
|
+
|
|
55
|
+
##### NewType
|
|
56
|
+
|
|
57
|
+
`NewType`
|
|
58
|
+
|
|
59
|
+
The new type to replace with.
|
|
60
|
+
|
|
61
|
+
##### SkipPaths
|
|
62
|
+
|
|
63
|
+
`SkipPaths` *extends* `string` \| `undefined` = `undefined`
|
|
64
|
+
|
|
65
|
+
The paths to skip in transverse. e.g. 'a.b.c' | 'array[*].b'
|
|
66
|
+
|
|
67
|
+
##### SkipTypes
|
|
68
|
+
|
|
69
|
+
`SkipTypes` = [`DefaultSkipTransverseDeepReplace`](#defaultskiptransversedeepreplace)
|
|
70
|
+
|
|
71
|
+
The types to skip in transverse and replace.
|
|
72
|
+
|
|
73
|
+
***
|
|
74
|
+
|
|
75
|
+
### DefaultSkipTransverseDeepReplace
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
type DefaultSkipTransverseDeepReplace =
|
|
79
|
+
| Date
|
|
80
|
+
| RegExp
|
|
81
|
+
| (...args) => any
|
|
82
|
+
| Error
|
|
83
|
+
| Set<any>
|
|
84
|
+
| Map<any, any>
|
|
85
|
+
| WeakSet<any>
|
|
86
|
+
| WeakMap<any, any>;
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Defined in: [packages/utils/src/typeUtils.ts:30](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeUtils.ts#L30)
|
|
90
|
+
|
|
91
|
+
***
|
|
92
|
+
|
|
93
|
+
### IsAny\<T\>
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
type IsAny<T> = unknown extends T ? [keyof T] extends [never] ? false : true : false;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Defined in: [packages/utils/src/typeUtils.ts:14](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeUtils.ts#L14)
|
|
100
|
+
|
|
101
|
+
#### Type Parameters
|
|
102
|
+
|
|
103
|
+
##### T
|
|
104
|
+
|
|
105
|
+
`T`
|
|
106
|
+
|
|
107
|
+
***
|
|
108
|
+
|
|
109
|
+
### NonPartial\<T\>
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
type NonPartial<T> = { [K in keyof Required<T>]: T[K] };
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Defined in: [packages/utils/src/typeUtils.ts:5](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeUtils.ts#L5)
|
|
116
|
+
|
|
117
|
+
#### Type Parameters
|
|
118
|
+
|
|
119
|
+
##### T
|
|
120
|
+
|
|
121
|
+
`T`
|
|
122
|
+
|
|
123
|
+
***
|
|
124
|
+
|
|
125
|
+
### ObjKeysWithValuesOfType\<Obj, ValueType\>
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
type ObjKeysWithValuesOfType<Obj, ValueType> = { [K in keyof Obj]: Obj[K] extends ValueType ? K : never }[keyof Obj];
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Defined in: [packages/utils/src/typeUtils.ts:7](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeUtils.ts#L7)
|
|
132
|
+
|
|
133
|
+
#### Type Parameters
|
|
134
|
+
|
|
135
|
+
##### Obj
|
|
136
|
+
|
|
137
|
+
`Obj` *extends* `Record`\<`PropertyKey`, `unknown`\>
|
|
138
|
+
|
|
139
|
+
##### ValueType
|
|
140
|
+
|
|
141
|
+
`ValueType`
|
|
142
|
+
|
|
143
|
+
***
|
|
144
|
+
|
|
145
|
+
### PartialRecord\<K, T\>
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
type PartialRecord<K, T> = { [P in K]?: T };
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Defined in: [packages/utils/src/typeUtils.ts:1](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeUtils.ts#L1)
|
|
152
|
+
|
|
153
|
+
#### Type Parameters
|
|
154
|
+
|
|
155
|
+
##### K
|
|
156
|
+
|
|
157
|
+
`K` *extends* keyof `any`
|
|
158
|
+
|
|
159
|
+
##### T
|
|
160
|
+
|
|
161
|
+
`T`
|
|
162
|
+
|
|
163
|
+
***
|
|
164
|
+
|
|
165
|
+
### Prettify\<T\>
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
type Prettify<T> = { [P in keyof T]: T[P] } & object;
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Defined in: [packages/utils/src/typeUtils.ts:21](https://github.com/lucasols/utils/blob/main/packages/utils/src/typeUtils.ts#L21)
|
|
172
|
+
|
|
173
|
+
#### Type Parameters
|
|
174
|
+
|
|
175
|
+
##### T
|
|
176
|
+
|
|
177
|
+
`T` *extends* `Record`\<`string`, `unknown`\>
|
package/docs/typingUtils.md
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
|
|
9
9
|
## Type Aliases
|
|
10
10
|
|
|
11
|
-
### DeepPrettify\<T
|
|
11
|
+
### ~~DeepPrettify\<T\>~~
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
14
|
type DeepPrettify<T> = { [K in keyof T]: T[K] extends Record<string, unknown> ? DeepPrettify<T[K]> : T[K] } & object;
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
Defined in: [packages/utils/src/typingUtils.ts:
|
|
17
|
+
Defined in: [packages/utils/src/typingUtils.ts:31](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingUtils.ts#L31)
|
|
18
18
|
|
|
19
19
|
#### Type Parameters
|
|
20
20
|
|
|
@@ -22,15 +22,19 @@ Defined in: [packages/utils/src/typingUtils.ts:25](https://github.com/lucasols/u
|
|
|
22
22
|
|
|
23
23
|
`T`
|
|
24
24
|
|
|
25
|
+
#### Deprecated
|
|
26
|
+
|
|
27
|
+
Use `DeepPrettify` from `@ls-stack/utils/typeUtils` instead
|
|
28
|
+
|
|
25
29
|
***
|
|
26
30
|
|
|
27
|
-
### IsAny\<T
|
|
31
|
+
### ~~IsAny\<T\>~~
|
|
28
32
|
|
|
29
33
|
```ts
|
|
30
34
|
type IsAny<T> = unknown extends T ? [keyof T] extends [never] ? false : true : false;
|
|
31
35
|
```
|
|
32
36
|
|
|
33
|
-
Defined in: [packages/utils/src/typingUtils.ts:
|
|
37
|
+
Defined in: [packages/utils/src/typingUtils.ts:18](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingUtils.ts#L18)
|
|
34
38
|
|
|
35
39
|
#### Type Parameters
|
|
36
40
|
|
|
@@ -38,15 +42,19 @@ Defined in: [packages/utils/src/typingUtils.ts:14](https://github.com/lucasols/u
|
|
|
38
42
|
|
|
39
43
|
`T`
|
|
40
44
|
|
|
45
|
+
#### Deprecated
|
|
46
|
+
|
|
47
|
+
Use `IsAny` from `@ls-stack/utils/typeUtils` instead
|
|
48
|
+
|
|
41
49
|
***
|
|
42
50
|
|
|
43
|
-
### NonPartial\<T
|
|
51
|
+
### ~~NonPartial\<T\>~~
|
|
44
52
|
|
|
45
53
|
```ts
|
|
46
54
|
type NonPartial<T> = { [K in keyof Required<T>]: T[K] };
|
|
47
55
|
```
|
|
48
56
|
|
|
49
|
-
Defined in: [packages/utils/src/typingUtils.ts:
|
|
57
|
+
Defined in: [packages/utils/src/typingUtils.ts:7](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingUtils.ts#L7)
|
|
50
58
|
|
|
51
59
|
#### Type Parameters
|
|
52
60
|
|
|
@@ -54,15 +62,19 @@ Defined in: [packages/utils/src/typingUtils.ts:5](https://github.com/lucasols/ut
|
|
|
54
62
|
|
|
55
63
|
`T`
|
|
56
64
|
|
|
65
|
+
#### Deprecated
|
|
66
|
+
|
|
67
|
+
Use `NonPartial` from `@ls-stack/utils/typeUtils` instead
|
|
68
|
+
|
|
57
69
|
***
|
|
58
70
|
|
|
59
|
-
### ObjKeysWithValuesOfType\<Obj, ValueType
|
|
71
|
+
### ~~ObjKeysWithValuesOfType\<Obj, ValueType\>~~
|
|
60
72
|
|
|
61
73
|
```ts
|
|
62
74
|
type ObjKeysWithValuesOfType<Obj, ValueType> = { [K in keyof Obj]: Obj[K] extends ValueType ? K : never }[keyof Obj];
|
|
63
75
|
```
|
|
64
76
|
|
|
65
|
-
Defined in: [packages/utils/src/typingUtils.ts:
|
|
77
|
+
Defined in: [packages/utils/src/typingUtils.ts:10](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingUtils.ts#L10)
|
|
66
78
|
|
|
67
79
|
#### Type Parameters
|
|
68
80
|
|
|
@@ -74,15 +86,19 @@ Defined in: [packages/utils/src/typingUtils.ts:7](https://github.com/lucasols/ut
|
|
|
74
86
|
|
|
75
87
|
`ValueType`
|
|
76
88
|
|
|
89
|
+
#### Deprecated
|
|
90
|
+
|
|
91
|
+
Use `ObjKeysWithValuesOfType` from `@ls-stack/utils/typeUtils` instead
|
|
92
|
+
|
|
77
93
|
***
|
|
78
94
|
|
|
79
|
-
### PartialRecord\<K, T
|
|
95
|
+
### ~~PartialRecord\<K, T\>~~
|
|
80
96
|
|
|
81
97
|
```ts
|
|
82
98
|
type PartialRecord<K, T> = { [P in K]?: T };
|
|
83
99
|
```
|
|
84
100
|
|
|
85
|
-
Defined in: [packages/utils/src/typingUtils.ts:
|
|
101
|
+
Defined in: [packages/utils/src/typingUtils.ts:2](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingUtils.ts#L2)
|
|
86
102
|
|
|
87
103
|
#### Type Parameters
|
|
88
104
|
|
|
@@ -94,18 +110,26 @@ Defined in: [packages/utils/src/typingUtils.ts:1](https://github.com/lucasols/ut
|
|
|
94
110
|
|
|
95
111
|
`T`
|
|
96
112
|
|
|
113
|
+
#### Deprecated
|
|
114
|
+
|
|
115
|
+
Use `PartialRecord` from `@ls-stack/utils/typeUtils` instead
|
|
116
|
+
|
|
97
117
|
***
|
|
98
118
|
|
|
99
|
-
### Prettify\<T
|
|
119
|
+
### ~~Prettify\<T\>~~
|
|
100
120
|
|
|
101
121
|
```ts
|
|
102
122
|
type Prettify<T> = { [P in keyof T]: T[P] } & object;
|
|
103
123
|
```
|
|
104
124
|
|
|
105
|
-
Defined in: [packages/utils/src/typingUtils.ts:
|
|
125
|
+
Defined in: [packages/utils/src/typingUtils.ts:26](https://github.com/lucasols/utils/blob/main/packages/utils/src/typingUtils.ts#L26)
|
|
106
126
|
|
|
107
127
|
#### Type Parameters
|
|
108
128
|
|
|
109
129
|
##### T
|
|
110
130
|
|
|
111
131
|
`T` *extends* `Record`\<`string`, `unknown`\>
|
|
132
|
+
|
|
133
|
+
#### Deprecated
|
|
134
|
+
|
|
135
|
+
Use `DeepPrettify` from `@ls-stack/utils/typeUtils` instead
|
|
@@ -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
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/typeUtils.ts
|
|
17
|
+
var typeUtils_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(typeUtils_exports);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
type PartialRecord<K extends keyof any, T> = {
|
|
2
|
+
[P in K]?: T;
|
|
3
|
+
};
|
|
4
|
+
type NonPartial<T> = {
|
|
5
|
+
[K in keyof Required<T>]: T[K];
|
|
6
|
+
};
|
|
7
|
+
type ObjKeysWithValuesOfType<Obj extends Record<PropertyKey, unknown>, ValueType> = {
|
|
8
|
+
[K in keyof Obj]: Obj[K] extends ValueType ? K : never;
|
|
9
|
+
}[keyof Obj];
|
|
10
|
+
type IsAny<T> = unknown extends T ? [
|
|
11
|
+
keyof T
|
|
12
|
+
] extends [never] ? false : true : false;
|
|
13
|
+
type Prettify<T extends Record<string, unknown>> = {
|
|
14
|
+
[P in keyof T]: T[P];
|
|
15
|
+
} & {};
|
|
16
|
+
type DeepPrettify<T> = {
|
|
17
|
+
[K in keyof T]: T[K] extends Record<string, unknown> ? DeepPrettify<T[K]> : T[K];
|
|
18
|
+
} & {};
|
|
19
|
+
type DefaultSkipTransverseDeepReplace = Date | RegExp | ((...args: any[]) => any) | Error | Set<any> | Map<any, any> | WeakSet<any> | WeakMap<any, any>;
|
|
20
|
+
type PathMatches<CurrentPath extends string, SkipPaths extends string> = true extends (SkipPaths extends any ? CurrentPath extends SkipPaths ? true : SkipPaths extends `${infer Prefix}[*]${infer Suffix}` ? CurrentPath extends `${Prefix}[${string}]${Suffix}` ? true : false : false : false) ? true : false;
|
|
21
|
+
type BuildPath<BasePath extends string, Key extends PropertyKey> = BasePath extends '$' ? Key extends string | number ? `${Key}` : never : Key extends string | number ? `${BasePath}.${Key}` : never;
|
|
22
|
+
type BuildArrayPath<BasePath extends string> = BasePath extends '$' ? '[*]' : `${BasePath}[*]`;
|
|
23
|
+
type DeepReplaceValueImpl<T, ReplaceType, NewType, SkipPaths extends string | undefined, SkipType, Path extends string = '$'> = SkipPaths extends string ? PathMatches<Path, SkipPaths> extends true ? T : T extends ReplaceType ? T extends SkipType ? T : NewType : T extends readonly (infer U)[] ? Array<DeepReplaceValueImpl<U, ReplaceType, NewType, SkipPaths, SkipType, BuildArrayPath<Path>>> : T extends SkipType ? T : T extends Record<string, any> ? {
|
|
24
|
+
[K in keyof T]: DeepReplaceValueImpl<T[K], ReplaceType, NewType, SkipPaths, SkipType, BuildPath<Path, K>>;
|
|
25
|
+
} : T : T extends ReplaceType ? T extends SkipType ? T : NewType : T extends readonly (infer U)[] ? Array<DeepReplaceValueImpl<U, ReplaceType, NewType, SkipPaths, SkipType, BuildArrayPath<Path>>> : T extends SkipType ? T : T extends Record<string, any> ? {
|
|
26
|
+
[K in keyof T]: DeepReplaceValueImpl<T[K], ReplaceType, NewType, SkipPaths, SkipType, BuildPath<Path, K>>;
|
|
27
|
+
} : T;
|
|
28
|
+
/**
|
|
29
|
+
* Replaces all values that extends `ReplaceType` with `NewType` in a deeply nested object or array.
|
|
30
|
+
*
|
|
31
|
+
* @template T - The object or array to replace values in.
|
|
32
|
+
* @template ReplaceType - The type to replace.
|
|
33
|
+
* @template NewType - The new type to replace with.
|
|
34
|
+
* @template SkipPaths - The paths to skip in transverse. e.g. 'a.b.c' | 'array[*].b'
|
|
35
|
+
* @template SkipTypes - The types to skip in transverse and replace.
|
|
36
|
+
*/
|
|
37
|
+
type DeepReplaceValue<T, ReplaceType, NewType, SkipPaths extends string | undefined = undefined, SkipTypes = DefaultSkipTransverseDeepReplace> = DeepReplaceValueImpl<T, ReplaceType, NewType, SkipPaths, SkipTypes>;
|
|
38
|
+
|
|
39
|
+
export type { DeepPrettify, DeepReplaceValue, DefaultSkipTransverseDeepReplace, IsAny, NonPartial, ObjKeysWithValuesOfType, PartialRecord, Prettify };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
type PartialRecord<K extends keyof any, T> = {
|
|
2
|
+
[P in K]?: T;
|
|
3
|
+
};
|
|
4
|
+
type NonPartial<T> = {
|
|
5
|
+
[K in keyof Required<T>]: T[K];
|
|
6
|
+
};
|
|
7
|
+
type ObjKeysWithValuesOfType<Obj extends Record<PropertyKey, unknown>, ValueType> = {
|
|
8
|
+
[K in keyof Obj]: Obj[K] extends ValueType ? K : never;
|
|
9
|
+
}[keyof Obj];
|
|
10
|
+
type IsAny<T> = unknown extends T ? [
|
|
11
|
+
keyof T
|
|
12
|
+
] extends [never] ? false : true : false;
|
|
13
|
+
type Prettify<T extends Record<string, unknown>> = {
|
|
14
|
+
[P in keyof T]: T[P];
|
|
15
|
+
} & {};
|
|
16
|
+
type DeepPrettify<T> = {
|
|
17
|
+
[K in keyof T]: T[K] extends Record<string, unknown> ? DeepPrettify<T[K]> : T[K];
|
|
18
|
+
} & {};
|
|
19
|
+
type DefaultSkipTransverseDeepReplace = Date | RegExp | ((...args: any[]) => any) | Error | Set<any> | Map<any, any> | WeakSet<any> | WeakMap<any, any>;
|
|
20
|
+
type PathMatches<CurrentPath extends string, SkipPaths extends string> = true extends (SkipPaths extends any ? CurrentPath extends SkipPaths ? true : SkipPaths extends `${infer Prefix}[*]${infer Suffix}` ? CurrentPath extends `${Prefix}[${string}]${Suffix}` ? true : false : false : false) ? true : false;
|
|
21
|
+
type BuildPath<BasePath extends string, Key extends PropertyKey> = BasePath extends '$' ? Key extends string | number ? `${Key}` : never : Key extends string | number ? `${BasePath}.${Key}` : never;
|
|
22
|
+
type BuildArrayPath<BasePath extends string> = BasePath extends '$' ? '[*]' : `${BasePath}[*]`;
|
|
23
|
+
type DeepReplaceValueImpl<T, ReplaceType, NewType, SkipPaths extends string | undefined, SkipType, Path extends string = '$'> = SkipPaths extends string ? PathMatches<Path, SkipPaths> extends true ? T : T extends ReplaceType ? T extends SkipType ? T : NewType : T extends readonly (infer U)[] ? Array<DeepReplaceValueImpl<U, ReplaceType, NewType, SkipPaths, SkipType, BuildArrayPath<Path>>> : T extends SkipType ? T : T extends Record<string, any> ? {
|
|
24
|
+
[K in keyof T]: DeepReplaceValueImpl<T[K], ReplaceType, NewType, SkipPaths, SkipType, BuildPath<Path, K>>;
|
|
25
|
+
} : T : T extends ReplaceType ? T extends SkipType ? T : NewType : T extends readonly (infer U)[] ? Array<DeepReplaceValueImpl<U, ReplaceType, NewType, SkipPaths, SkipType, BuildArrayPath<Path>>> : T extends SkipType ? T : T extends Record<string, any> ? {
|
|
26
|
+
[K in keyof T]: DeepReplaceValueImpl<T[K], ReplaceType, NewType, SkipPaths, SkipType, BuildPath<Path, K>>;
|
|
27
|
+
} : T;
|
|
28
|
+
/**
|
|
29
|
+
* Replaces all values that extends `ReplaceType` with `NewType` in a deeply nested object or array.
|
|
30
|
+
*
|
|
31
|
+
* @template T - The object or array to replace values in.
|
|
32
|
+
* @template ReplaceType - The type to replace.
|
|
33
|
+
* @template NewType - The new type to replace with.
|
|
34
|
+
* @template SkipPaths - The paths to skip in transverse. e.g. 'a.b.c' | 'array[*].b'
|
|
35
|
+
* @template SkipTypes - The types to skip in transverse and replace.
|
|
36
|
+
*/
|
|
37
|
+
type DeepReplaceValue<T, ReplaceType, NewType, SkipPaths extends string | undefined = undefined, SkipTypes = DefaultSkipTransverseDeepReplace> = DeepReplaceValueImpl<T, ReplaceType, NewType, SkipPaths, SkipTypes>;
|
|
38
|
+
|
|
39
|
+
export type { DeepPrettify, DeepReplaceValue, DefaultSkipTransverseDeepReplace, IsAny, NonPartial, ObjKeysWithValuesOfType, PartialRecord, Prettify };
|
package/lib/typeUtils.js
ADDED
|
File without changes
|
package/lib/typingUtils.d.cts
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
|
+
/** @deprecated Use `PartialRecord` from `@ls-stack/utils/typeUtils` instead */
|
|
1
2
|
type PartialRecord<K extends keyof any, T> = {
|
|
2
3
|
[P in K]?: T;
|
|
3
4
|
};
|
|
5
|
+
/** @deprecated Use `NonPartial` from `@ls-stack/utils/typeUtils` instead */
|
|
4
6
|
type NonPartial<T> = {
|
|
5
7
|
[K in keyof Required<T>]: T[K];
|
|
6
8
|
};
|
|
9
|
+
/** @deprecated Use `ObjKeysWithValuesOfType` from `@ls-stack/utils/typeUtils` instead */
|
|
7
10
|
type ObjKeysWithValuesOfType<Obj extends Record<PropertyKey, unknown>, ValueType> = {
|
|
8
11
|
[K in keyof Obj]: Obj[K] extends ValueType ? K : never;
|
|
9
12
|
}[keyof Obj];
|
|
13
|
+
/** @deprecated Use `IsAny` from `@ls-stack/utils/typeUtils` instead */
|
|
10
14
|
type IsAny<T> = unknown extends T ? [
|
|
11
15
|
keyof T
|
|
12
16
|
] extends [never] ? false : true : false;
|
|
17
|
+
/** @deprecated Use `DeepPrettify` from `@ls-stack/utils/typeUtils` instead */
|
|
13
18
|
type Prettify<T extends Record<string, unknown>> = {
|
|
14
19
|
[P in keyof T]: T[P];
|
|
15
20
|
} & {};
|
|
21
|
+
/** @deprecated Use `DeepPrettify` from `@ls-stack/utils/typeUtils` instead */
|
|
16
22
|
type DeepPrettify<T> = {
|
|
17
23
|
[K in keyof T]: T[K] extends Record<string, unknown> ? DeepPrettify<T[K]> : T[K];
|
|
18
24
|
} & {};
|
package/lib/typingUtils.d.ts
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
|
+
/** @deprecated Use `PartialRecord` from `@ls-stack/utils/typeUtils` instead */
|
|
1
2
|
type PartialRecord<K extends keyof any, T> = {
|
|
2
3
|
[P in K]?: T;
|
|
3
4
|
};
|
|
5
|
+
/** @deprecated Use `NonPartial` from `@ls-stack/utils/typeUtils` instead */
|
|
4
6
|
type NonPartial<T> = {
|
|
5
7
|
[K in keyof Required<T>]: T[K];
|
|
6
8
|
};
|
|
9
|
+
/** @deprecated Use `ObjKeysWithValuesOfType` from `@ls-stack/utils/typeUtils` instead */
|
|
7
10
|
type ObjKeysWithValuesOfType<Obj extends Record<PropertyKey, unknown>, ValueType> = {
|
|
8
11
|
[K in keyof Obj]: Obj[K] extends ValueType ? K : never;
|
|
9
12
|
}[keyof Obj];
|
|
13
|
+
/** @deprecated Use `IsAny` from `@ls-stack/utils/typeUtils` instead */
|
|
10
14
|
type IsAny<T> = unknown extends T ? [
|
|
11
15
|
keyof T
|
|
12
16
|
] extends [never] ? false : true : false;
|
|
17
|
+
/** @deprecated Use `DeepPrettify` from `@ls-stack/utils/typeUtils` instead */
|
|
13
18
|
type Prettify<T extends Record<string, unknown>> = {
|
|
14
19
|
[P in keyof T]: T[P];
|
|
15
20
|
} & {};
|
|
21
|
+
/** @deprecated Use `DeepPrettify` from `@ls-stack/utils/typeUtils` instead */
|
|
16
22
|
type DeepPrettify<T> = {
|
|
17
23
|
[K in keyof T]: T[K] extends Record<string, unknown> ? DeepPrettify<T[K]> : T[K];
|
|
18
24
|
} & {};
|
package/lib/yamlStringify.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ls-stack/utils",
|
|
3
3
|
"description": "Universal TypeScript utilities for browser and Node.js",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.31.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib",
|
|
@@ -184,6 +184,14 @@
|
|
|
184
184
|
"import": "./lib/typeGuards.js",
|
|
185
185
|
"require": "./lib/typeGuards.cjs"
|
|
186
186
|
},
|
|
187
|
+
"./typeUtils": {
|
|
188
|
+
"import": "./lib/typeUtils.js",
|
|
189
|
+
"require": "./lib/typeUtils.cjs"
|
|
190
|
+
},
|
|
191
|
+
"./typeUtils.typesTest": {
|
|
192
|
+
"import": "./lib/typeUtils.typesTest.js",
|
|
193
|
+
"require": "./lib/typeUtils.typesTest.cjs"
|
|
194
|
+
},
|
|
187
195
|
"./typingFnUtils": {
|
|
188
196
|
"import": "./lib/typingFnUtils.js",
|
|
189
197
|
"require": "./lib/typingFnUtils.cjs"
|
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
|
-
};
|