@rimbu/deep 2.0.1 → 2.0.3
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/README.md +295 -60
- package/dist/bun/deep.mts +8 -8
- package/dist/bun/match.mts +29 -27
- package/dist/bun/patch.mts +11 -10
- package/dist/bun/path.mts +98 -100
- package/dist/bun/protected.mts +18 -17
- package/dist/bun/selector.mts +22 -20
- package/dist/bun/tuple.mts +6 -2
- package/dist/cjs/deep.cjs +18 -18
- package/dist/cjs/deep.cjs.map +1 -1
- package/dist/cjs/deep.d.cts +6 -6
- package/dist/cjs/match.cjs +2 -3
- package/dist/cjs/match.cjs.map +1 -1
- package/dist/cjs/match.d.cts +2 -2
- package/dist/cjs/patch.cjs +2 -3
- package/dist/cjs/patch.cjs.map +1 -1
- package/dist/cjs/patch.d.cts +1 -1
- package/dist/cjs/path.cjs +5 -5
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/path.d.cts +8 -6
- package/dist/cjs/selector.cjs +1 -2
- package/dist/cjs/selector.cjs.map +1 -1
- package/dist/cjs/tuple.cjs +1 -1
- package/dist/cjs/tuple.cjs.map +1 -1
- package/dist/cjs/tuple.d.cts +5 -1
- package/dist/esm/deep.d.mts +6 -6
- package/dist/esm/deep.mjs +6 -6
- package/dist/esm/match.d.mts +2 -2
- package/dist/esm/match.mjs +1 -1
- package/dist/esm/match.mjs.map +1 -1
- package/dist/esm/patch.d.mts +1 -1
- package/dist/esm/patch.mjs +1 -1
- package/dist/esm/patch.mjs.map +1 -1
- package/dist/esm/path.d.mts +8 -6
- package/dist/esm/path.mjs +2 -2
- package/dist/esm/path.mjs.map +1 -1
- package/dist/esm/selector.mjs.map +1 -1
- package/dist/esm/tuple.d.mts +5 -1
- package/dist/esm/tuple.mjs +1 -1
- package/dist/esm/tuple.mjs.map +1 -1
- package/package.json +7 -7
- package/src/deep.mts +8 -8
- package/src/match.mts +29 -27
- package/src/patch.mts +11 -10
- package/src/path.mts +98 -100
- package/src/protected.mts +18 -17
- package/src/selector.mts +22 -20
- package/src/tuple.mts +6 -2
package/dist/bun/path.mts
CHANGED
|
@@ -36,7 +36,7 @@ export namespace Path {
|
|
|
36
36
|
T,
|
|
37
37
|
Write extends boolean,
|
|
38
38
|
Maybe extends boolean,
|
|
39
|
-
First extends boolean = false
|
|
39
|
+
First extends boolean = false,
|
|
40
40
|
> = `${IsAnyFunc<T> extends true
|
|
41
41
|
? // functions can not be further decomposed
|
|
42
42
|
''
|
|
@@ -54,47 +54,44 @@ export namespace Path {
|
|
|
54
54
|
T,
|
|
55
55
|
Write extends boolean,
|
|
56
56
|
Maybe extends boolean,
|
|
57
|
-
First extends boolean
|
|
58
|
-
> =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
First extends boolean,
|
|
58
|
+
> =
|
|
59
|
+
Path.Internal.IsOptional<T> extends true
|
|
60
|
+
? // the value T may be null or undefined, check whether further chaining is allowed
|
|
61
|
+
Write extends false
|
|
62
|
+
? // path is not used to write to, so optional chaining is allowed
|
|
63
|
+
Path.Internal.Generic<Exclude<T, undefined | null>, Write, true>
|
|
64
|
+
: // path can be written to, no optional chaining allowed
|
|
65
|
+
never
|
|
66
|
+
: // determine separator, and continue with non-optional value
|
|
67
|
+
`${Path.Internal.Separator<
|
|
68
|
+
First,
|
|
69
|
+
Maybe,
|
|
70
|
+
IsArray<T>
|
|
71
|
+
>}${Path.Internal.NonOptional<T, Write, Maybe>}`;
|
|
71
72
|
|
|
72
73
|
/**
|
|
73
74
|
* Determines the allowed paths into a non-optional value of type `T`.
|
|
74
75
|
* @typeparam T - the source type
|
|
75
76
|
* @typeparam Write - if true the path should be writable (no optional chaining)
|
|
76
77
|
* @typeparam Maybe - if true the value at the current path is optional
|
|
77
|
-
* @typeparam First - if true this is the root call
|
|
78
78
|
*/
|
|
79
|
-
export type NonOptional<
|
|
80
|
-
T
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
Path.Internal.Obj<T, Write, Maybe>
|
|
96
|
-
: // no match
|
|
97
|
-
never;
|
|
79
|
+
export type NonOptional<T, Write extends boolean, Maybe extends boolean> =
|
|
80
|
+
Tuple.IsTuple<T> extends true
|
|
81
|
+
? // determine allowed paths for tuple
|
|
82
|
+
Path.Internal.Tup<T, Write, Maybe>
|
|
83
|
+
: T extends readonly any[]
|
|
84
|
+
? // determine allowed paths for array
|
|
85
|
+
Write extends false
|
|
86
|
+
? // path is not writable so arrays are allowed
|
|
87
|
+
Path.Internal.Arr<T>
|
|
88
|
+
: // path is writable, no arrays allowed
|
|
89
|
+
never
|
|
90
|
+
: IsPlainObj<T> extends true
|
|
91
|
+
? // determine allowed paths for object
|
|
92
|
+
Path.Internal.Obj<T, Write, Maybe>
|
|
93
|
+
: // no match
|
|
94
|
+
never;
|
|
98
95
|
|
|
99
96
|
/**
|
|
100
97
|
* Determines the allowed paths for a tuple. Since tuples have fixed types, they do not
|
|
@@ -104,11 +101,7 @@ export namespace Path {
|
|
|
104
101
|
* @typeparam Maybe - if true the value at the current path is optional
|
|
105
102
|
*/
|
|
106
103
|
export type Tup<T, Write extends boolean, Maybe extends boolean> = {
|
|
107
|
-
[K in Tuple.KeysOf<T>]: `[${K}]${Path.Internal.Generic<
|
|
108
|
-
T[K],
|
|
109
|
-
Write,
|
|
110
|
-
Maybe
|
|
111
|
-
>}`;
|
|
104
|
+
[K in Tuple.KeysOf<T>]: `[${K}]${Path.Internal.Generic<T[K], Write, Maybe>}`;
|
|
112
105
|
}[Tuple.KeysOf<T>];
|
|
113
106
|
|
|
114
107
|
/**
|
|
@@ -135,7 +128,7 @@ export namespace Path {
|
|
|
135
128
|
}[keyof T];
|
|
136
129
|
|
|
137
130
|
/**
|
|
138
|
-
* Determines the allowed path part
|
|
131
|
+
* Determines the allowed path part separator based on the input types.
|
|
139
132
|
* @typeparam First - if true, this is the first call
|
|
140
133
|
* @typeparam Maybe - if true, the value is optional
|
|
141
134
|
* @typeparam IsArray - if true, the value is an array
|
|
@@ -143,7 +136,7 @@ export namespace Path {
|
|
|
143
136
|
export type Separator<
|
|
144
137
|
First extends boolean,
|
|
145
138
|
Maybe extends boolean,
|
|
146
|
-
IsArray extends boolean
|
|
139
|
+
IsArray extends boolean,
|
|
147
140
|
> = Maybe extends true
|
|
148
141
|
? First extends true
|
|
149
142
|
? // first optional value cannot have separator
|
|
@@ -151,13 +144,13 @@ export namespace Path {
|
|
|
151
144
|
: // non-first optional value must have separator
|
|
152
145
|
'?.'
|
|
153
146
|
: First extends true
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
147
|
+
? // first non-optional value has empty separator
|
|
148
|
+
''
|
|
149
|
+
: IsArray extends true
|
|
150
|
+
? // array selectors do not have separator
|
|
151
|
+
''
|
|
152
|
+
: // normal separator
|
|
153
|
+
'.';
|
|
161
154
|
|
|
162
155
|
/**
|
|
163
156
|
* Determines whether the given type `T` is optional, that is, whether it can be null or undefined.
|
|
@@ -169,10 +162,10 @@ export namespace Path {
|
|
|
169
162
|
? // is optional
|
|
170
163
|
True
|
|
171
164
|
: null extends T
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
165
|
+
? // is optional
|
|
166
|
+
True
|
|
167
|
+
: // not optional
|
|
168
|
+
False;
|
|
176
169
|
|
|
177
170
|
/**
|
|
178
171
|
* Returns type `T` if `Maybe` is false, `T | undefined` otherwise.
|
|
@@ -185,12 +178,12 @@ export namespace Path {
|
|
|
185
178
|
|
|
186
179
|
/**
|
|
187
180
|
* Utility type to only add non-empty string types to a string array.
|
|
188
|
-
* @
|
|
181
|
+
* @typeparam A - the input string array
|
|
189
182
|
* @typeparam T - the string value to optionally add
|
|
190
183
|
*/
|
|
191
184
|
export type AppendIfNotEmpty<
|
|
192
185
|
A extends string[],
|
|
193
|
-
T extends string
|
|
186
|
+
T extends string,
|
|
194
187
|
> = T extends ''
|
|
195
188
|
? // empty string, do not add
|
|
196
189
|
A
|
|
@@ -224,23 +217,23 @@ export namespace Path {
|
|
|
224
217
|
export type For<
|
|
225
218
|
T,
|
|
226
219
|
Tokens,
|
|
227
|
-
Maybe extends boolean = Path.Internal.IsOptional<T
|
|
220
|
+
Maybe extends boolean = Path.Internal.IsOptional<T>,
|
|
228
221
|
> = Tokens extends []
|
|
229
222
|
? // no more token
|
|
230
223
|
Path.Internal.MaybeValue<T, Maybe>
|
|
231
224
|
: Path.Internal.IsOptional<T> extends true
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
225
|
+
? // T can be null or undefined, so continue with Maybe set to true
|
|
226
|
+
Path.Result.For<Exclude<T, undefined | null>, Tokens, Maybe>
|
|
227
|
+
: Tokens extends ['?.', infer Key, ...infer Rest]
|
|
228
|
+
? // optional chaining, process first part and set Maybe to true
|
|
229
|
+
Path.Result.For<Path.Result.Part<T, Key, Maybe>, Rest, true>
|
|
230
|
+
: Tokens extends ['.', infer Key, ...infer Rest]
|
|
231
|
+
? // normal chaining, process first part and continue
|
|
232
|
+
Path.Result.For<Path.Result.Part<T, Key, false>, Rest, Maybe>
|
|
233
|
+
: Tokens extends [infer Key, ...infer Rest]
|
|
234
|
+
? // process first part, and continue
|
|
235
|
+
Path.Result.For<Path.Result.Part<T, Key, false>, Rest, Maybe>
|
|
236
|
+
: never;
|
|
244
237
|
|
|
245
238
|
/**
|
|
246
239
|
* Determines the result of getting the property/index `K` from type `T`, taking into
|
|
@@ -249,15 +242,16 @@ export namespace Path {
|
|
|
249
242
|
* @typeparam K - the key to get from the source type
|
|
250
243
|
* @typeparam Maybe - if true indicates that the path may be undefined
|
|
251
244
|
*/
|
|
252
|
-
export type Part<T, K, Maybe extends boolean> =
|
|
253
|
-
|
|
254
|
-
// for
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
245
|
+
export type Part<T, K, Maybe extends boolean> =
|
|
246
|
+
IsArray<T> extends true
|
|
247
|
+
? // for arrays, Maybe needs to be set to true to force optional chaining
|
|
248
|
+
// for tuples, Maybe should be false
|
|
249
|
+
Path.Internal.MaybeValue<
|
|
250
|
+
T[K & keyof T],
|
|
251
|
+
Tuple.IsTuple<T> extends true ? Maybe : true
|
|
252
|
+
>
|
|
253
|
+
: // Return the type at the given key, and take `Maybe` into account
|
|
254
|
+
Path.Internal.MaybeValue<T[K & keyof T], Maybe>;
|
|
261
255
|
|
|
262
256
|
/**
|
|
263
257
|
* Converts a path string into separate tokens in a string array.
|
|
@@ -268,31 +262,35 @@ export namespace Path {
|
|
|
268
262
|
export type Tokenize<
|
|
269
263
|
P extends string,
|
|
270
264
|
Token extends string = '',
|
|
271
|
-
Res extends string[] = []
|
|
265
|
+
Res extends string[] = [],
|
|
272
266
|
> = P extends ''
|
|
273
267
|
? // no more input to process, return result
|
|
274
268
|
Path.Internal.AppendIfNotEmpty<Res, Token>
|
|
275
269
|
: P extends `[${infer Index}]${infer Rest}`
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
270
|
+
? // input is an array selector, append index to tokens. Continue with new token
|
|
271
|
+
Tokenize<
|
|
272
|
+
Rest,
|
|
273
|
+
'',
|
|
274
|
+
[...Path.Internal.AppendIfNotEmpty<Res, Token>, Index]
|
|
275
|
+
>
|
|
276
|
+
: P extends `?.${infer Rest}`
|
|
277
|
+
? // optional chaining, append to tokens. Continue with new token
|
|
278
|
+
Tokenize<
|
|
279
|
+
Rest,
|
|
280
|
+
'',
|
|
281
|
+
[...Path.Internal.AppendIfNotEmpty<Res, Token>, '?.']
|
|
282
|
+
>
|
|
283
|
+
: P extends `.${infer Rest}`
|
|
284
|
+
? // normal chaining, append to tokens. Continue with new token
|
|
285
|
+
Tokenize<
|
|
286
|
+
Rest,
|
|
287
|
+
'',
|
|
288
|
+
[...Path.Internal.AppendIfNotEmpty<Res, Token>, '.']
|
|
289
|
+
>
|
|
290
|
+
: P extends `${infer First}${infer Rest}`
|
|
291
|
+
? // process next character
|
|
292
|
+
Tokenize<Rest, `${Token}${First}`, Res>
|
|
293
|
+
: never;
|
|
296
294
|
}
|
|
297
295
|
|
|
298
296
|
/**
|
|
@@ -327,9 +325,9 @@ export namespace Path {
|
|
|
327
325
|
* ```ts
|
|
328
326
|
* const value = { a: { b: { c: [{ d: 5 }, { d: 6 }] } } }
|
|
329
327
|
* Deep.getAt(value, 'a.b');
|
|
330
|
-
* // => { c: 5 }
|
|
328
|
+
* // => { c: [{ d: 5 }, { d: 6 }] }
|
|
331
329
|
* Deep.getAt(value, 'a.b.c');
|
|
332
|
-
* // => [{ d: 5 }, { d:
|
|
330
|
+
* // => [{ d: 5 }, { d: 6 }]
|
|
333
331
|
* Deep.getAt(value, 'a.b.c[1]');
|
|
334
332
|
* // => { d: 6 }
|
|
335
333
|
* Deep.getAt(value, 'a.b.c[1]?.d');
|
package/dist/bun/protected.mts
CHANGED
|
@@ -11,20 +11,21 @@ import type { IsAny, IsPlainObj } from '@rimbu/base';
|
|
|
11
11
|
* - Any other type will not be mapped
|
|
12
12
|
* @typeparam T - the input type
|
|
13
13
|
*/
|
|
14
|
-
export type Protected<T> =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
14
|
+
export type Protected<T> =
|
|
15
|
+
IsAny<T> extends true
|
|
16
|
+
? // to prevent infinite recursion, any will be any
|
|
17
|
+
T
|
|
18
|
+
: T extends readonly any[] & infer A
|
|
19
|
+
? // convert all keys to readonly and all values to `Protected`
|
|
20
|
+
{ readonly [K in keyof A]: Protected<A[K]> }
|
|
21
|
+
: T extends Map<infer K, infer V>
|
|
22
|
+
? ReadonlyMap<Protected<K>, Protected<V>>
|
|
23
|
+
: T extends Set<infer E>
|
|
24
|
+
? ReadonlySet<Protected<E>>
|
|
25
|
+
: T extends Promise<infer E>
|
|
26
|
+
? Promise<Protected<E>>
|
|
27
|
+
: IsPlainObj<T> extends true
|
|
28
|
+
? // convert all keys to readonly and all values to `Protected`
|
|
29
|
+
{ readonly [K in keyof T]: Protected<T[K]> }
|
|
30
|
+
: // nothing to do, just return `T`
|
|
31
|
+
T;
|
package/dist/bun/selector.mts
CHANGED
|
@@ -22,32 +22,34 @@ export namespace Selector {
|
|
|
22
22
|
* Type defining the shape of allowed selectors, used to improve compiler checking.
|
|
23
23
|
* @typeparam SL - the selector type
|
|
24
24
|
*/
|
|
25
|
-
export type Shape<SL> =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
export type Shape<SL> =
|
|
26
|
+
IsAnyFunc<SL> extends true
|
|
27
|
+
? // functions are allowed, type provided by `Selector`
|
|
28
|
+
SL
|
|
29
|
+
: IsArray<SL> extends true
|
|
30
|
+
? // ensure tuple type is preserved
|
|
31
|
+
readonly [...(SL extends readonly unknown[] ? SL : never)]
|
|
32
|
+
: SL extends { readonly [key: string | number | symbol]: unknown }
|
|
33
|
+
? // ensure all object properties satisfy `Shape`
|
|
34
|
+
{ readonly [K in keyof SL]: Selector.Shape<SL[K]> }
|
|
35
|
+
: // nothing to check
|
|
36
|
+
SL;
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
39
|
* Type defining the result type of applying the SL selector type to the T value type.
|
|
39
40
|
* @typeparam T - the source value type
|
|
40
41
|
* @typeparam SL - the selector type
|
|
41
42
|
*/
|
|
42
|
-
export type Result<T, SL> =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
export type Result<T, SL> =
|
|
44
|
+
Selector<T> extends SL
|
|
45
|
+
? never
|
|
46
|
+
: SL extends (...args: any[]) => infer R
|
|
47
|
+
? R
|
|
48
|
+
: SL extends string
|
|
49
|
+
? Path.Result<T, SL>
|
|
50
|
+
: {
|
|
51
|
+
readonly [K in keyof SL]: Selector.Result<T, SL[K]>;
|
|
52
|
+
};
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
/**
|
package/dist/bun/tuple.mts
CHANGED
|
@@ -17,6 +17,10 @@ export namespace Tuple {
|
|
|
17
17
|
*/
|
|
18
18
|
export type Source = readonly unknown[];
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Determines whether the given type `T` is a tuple type.
|
|
22
|
+
* @typeparam T - the input type
|
|
23
|
+
*/
|
|
20
24
|
export type IsTuple<T> = T extends { length: infer L }
|
|
21
25
|
? 0 extends L
|
|
22
26
|
? false
|
|
@@ -43,7 +47,7 @@ export namespace Tuple {
|
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
/**
|
|
46
|
-
* Returns the item at the given `index` in the
|
|
50
|
+
* Returns the item at the given `index` in the given `tuple`.
|
|
47
51
|
* @param tuple - the tuple to get the item from
|
|
48
52
|
* @param index - the index in of the tuple element
|
|
49
53
|
* @example
|
|
@@ -138,7 +142,7 @@ export namespace Tuple {
|
|
|
138
142
|
*/
|
|
139
143
|
export function append<
|
|
140
144
|
T extends Tuple.Source,
|
|
141
|
-
V extends readonly [unknown, ...unknown[]]
|
|
145
|
+
V extends readonly [unknown, ...unknown[]],
|
|
142
146
|
>(tuple: T, ...values: V): readonly [...T, ...V] {
|
|
143
147
|
return [...tuple, ...values];
|
|
144
148
|
}
|
package/dist/cjs/deep.cjs
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.select = exports.patchAt = exports.getAt = exports.patch = exports.match = void 0;
|
|
4
|
+
exports.protect = protect;
|
|
5
|
+
exports.getAtWith = getAtWith;
|
|
6
|
+
exports.patchWith = patchWith;
|
|
7
|
+
exports.patchAtWith = patchAtWith;
|
|
8
|
+
exports.matchWith = matchWith;
|
|
9
|
+
exports.matchAt = matchAt;
|
|
10
|
+
exports.matchAtWith = matchAtWith;
|
|
11
|
+
exports.selectWith = selectWith;
|
|
12
|
+
exports.selectAt = selectAt;
|
|
13
|
+
exports.selectAtWith = selectAtWith;
|
|
14
|
+
exports.withType = withType;
|
|
4
15
|
var internal_cjs_1 = require("./internal.cjs");
|
|
5
16
|
var match_cjs_1 = require("./match.cjs");
|
|
6
17
|
Object.defineProperty(exports, "match", { enumerable: true, get: function () { return match_cjs_1.match; } });
|
|
@@ -29,7 +40,6 @@ Object.defineProperty(exports, "select", { enumerable: true, get: function () {
|
|
|
29
40
|
function protect(source) {
|
|
30
41
|
return source;
|
|
31
42
|
}
|
|
32
|
-
exports.protect = protect;
|
|
33
43
|
/**
|
|
34
44
|
* Returns a function that gets the value at the given string `path` inside an object.
|
|
35
45
|
* @typeparam T - the input value type
|
|
@@ -46,7 +56,6 @@ exports.protect = protect;
|
|
|
46
56
|
function getAtWith(path) {
|
|
47
57
|
return function (source) { return internal_cjs_1.Deep.getAt(source, path); };
|
|
48
58
|
}
|
|
49
|
-
exports.getAtWith = getAtWith;
|
|
50
59
|
/**
|
|
51
60
|
* Returns a function that patches a given `source` with the given `patchItems`.
|
|
52
61
|
* @typeparam T - the patch value type
|
|
@@ -64,7 +73,6 @@ exports.getAtWith = getAtWith;
|
|
|
64
73
|
function patchWith(patchItem) {
|
|
65
74
|
return function (source) { return internal_cjs_1.Deep.patch(source, patchItem); };
|
|
66
75
|
}
|
|
67
|
-
exports.patchWith = patchWith;
|
|
68
76
|
/**
|
|
69
77
|
* Returns a function that patches a given `value` with the given `patchItems` at the given `path`.
|
|
70
78
|
* @typeparam T - the patch value type
|
|
@@ -84,12 +92,11 @@ exports.patchWith = patchWith;
|
|
|
84
92
|
function patchAtWith(path, patchItem) {
|
|
85
93
|
return function (source) { return internal_cjs_1.Deep.patchAt(source, path, patchItem); };
|
|
86
94
|
}
|
|
87
|
-
exports.patchAtWith = patchAtWith;
|
|
88
95
|
/**
|
|
89
96
|
* Returns a function that matches a given `value` with the given `matcher`.
|
|
90
|
-
* @typeparam T - the
|
|
97
|
+
* @typeparam T - the input value type
|
|
91
98
|
* @param matcher - a matcher object that matches input values.
|
|
92
|
-
* @param source - the value to
|
|
99
|
+
* @param source - the value to match (parameter of the returned function).
|
|
93
100
|
* @example
|
|
94
101
|
* ```ts
|
|
95
102
|
* const items = [{ a: 1, b: 'a' }, { a: 2, b: 'b' }];
|
|
@@ -100,7 +107,6 @@ exports.patchAtWith = patchAtWith;
|
|
|
100
107
|
function matchWith(matcher) {
|
|
101
108
|
return function (source) { return internal_cjs_1.Deep.match(source, matcher); };
|
|
102
109
|
}
|
|
103
|
-
exports.matchWith = matchWith;
|
|
104
110
|
/**
|
|
105
111
|
* Returns true if the given `value` object matches the given `matcher` at the given `path`, false otherwise.
|
|
106
112
|
* @typeparam T - the input value type
|
|
@@ -118,10 +124,9 @@ exports.matchWith = matchWith;
|
|
|
118
124
|
function matchAt(source, path, matcher) {
|
|
119
125
|
return internal_cjs_1.Deep.match(internal_cjs_1.Deep.getAt(source, path), matcher);
|
|
120
126
|
}
|
|
121
|
-
exports.matchAt = matchAt;
|
|
122
127
|
/**
|
|
123
128
|
* Returns a function that matches a given `value` with the given `matcher` at the given string `path`.
|
|
124
|
-
* @typeparam T - the
|
|
129
|
+
* @typeparam T - the input value type
|
|
125
130
|
* @typeparam P - the string literal path type in the object
|
|
126
131
|
* @typeparam TE - utility type
|
|
127
132
|
* @param path - the string path in the object
|
|
@@ -137,10 +142,9 @@ exports.matchAt = matchAt;
|
|
|
137
142
|
function matchAtWith(path, matcher) {
|
|
138
143
|
return function (source) { return internal_cjs_1.Deep.matchAt(source, path, matcher); };
|
|
139
144
|
}
|
|
140
|
-
exports.matchAtWith = matchAtWith;
|
|
141
145
|
/**
|
|
142
146
|
* Returns a function that selects a certain shape from a given `value` with the given `selector`.
|
|
143
|
-
* @typeparam T - the
|
|
147
|
+
* @typeparam T - the input value type
|
|
144
148
|
* @typeparam SL - the selector shape type
|
|
145
149
|
* @param selector - a shape indicating the selection from the source values
|
|
146
150
|
* @param source - the value to use the given `selector` on.
|
|
@@ -154,10 +158,9 @@ exports.matchAtWith = matchAtWith;
|
|
|
154
158
|
function selectWith(selector) {
|
|
155
159
|
return function (source) { return internal_cjs_1.Deep.select(source, selector); };
|
|
156
160
|
}
|
|
157
|
-
exports.selectWith = selectWith;
|
|
158
161
|
/**
|
|
159
162
|
* Returns the result of applying the given `selector` shape to the given `source` value.
|
|
160
|
-
* @typeparam T - the
|
|
163
|
+
* @typeparam T - the input value type
|
|
161
164
|
* @typeparam P - the string literal path type in the object
|
|
162
165
|
* @typeparam SL - the selector shape type
|
|
163
166
|
* @param source - the source value to select from
|
|
@@ -173,10 +176,9 @@ exports.selectWith = selectWith;
|
|
|
173
176
|
function selectAt(source, path, selector) {
|
|
174
177
|
return internal_cjs_1.Deep.select(internal_cjs_1.Deep.getAt(source, path), selector);
|
|
175
178
|
}
|
|
176
|
-
exports.selectAt = selectAt;
|
|
177
179
|
/**
|
|
178
180
|
* Returns a function that selects a certain shape from a given `value` with the given `selector` at the given string `path`.
|
|
179
|
-
* @typeparam T - the
|
|
181
|
+
* @typeparam T - the input value type
|
|
180
182
|
* @typeparam P - the string literal path type in the object
|
|
181
183
|
* @typeparam SL - the selector shape type
|
|
182
184
|
* @param path - the string path in the object
|
|
@@ -191,7 +193,6 @@ exports.selectAt = selectAt;
|
|
|
191
193
|
function selectAtWith(path, selector) {
|
|
192
194
|
return function (source) { return internal_cjs_1.Deep.selectAt(source, path, selector); };
|
|
193
195
|
}
|
|
194
|
-
exports.selectAtWith = selectAtWith;
|
|
195
196
|
/**
|
|
196
197
|
* Returns a curried API with a known target type. This can be useful for using the methods in
|
|
197
198
|
* contexts where the target type can be inferred from the usage.
|
|
@@ -207,5 +208,4 @@ exports.selectAtWith = selectAtWith;
|
|
|
207
208
|
function withType() {
|
|
208
209
|
return internal_cjs_1.Deep;
|
|
209
210
|
}
|
|
210
|
-
exports.withType = withType;
|
|
211
211
|
//# sourceMappingURL=deep.cjs.map
|
package/dist/cjs/deep.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep.cjs","sourceRoot":"","sources":["../../_cjs_prepare/deep.cts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"deep.cjs","sourceRoot":"","sources":["../../_cjs_prepare/deep.cts"],"names":[],"mappings":";;;AAwBA,0BAEC;AAeD,8BAIC;AAgBD,8BAIC;AAkBD,kCAKC;AAcD,8BAEC;AAgBD,0BAMC;AAiBD,kCAKC;AAeD,gCAIC;AAiBD,4BAUC;AAgBD,oCASC;AA8ID,4BAEC;AA1WD,+CAAsC;AAEtC,yCAAgD;AAAvC,kGAAA,KAAK,OAAA;AACd,yCAAgD;AAAvC,kGAAA,KAAK,OAAA;AACd,uCAAuD;AAA9C,iGAAA,KAAK,OAAA;AAAE,mGAAA,OAAO,OAAA;AAEvB,+CAAuD;AAA9C,sGAAA,MAAM,OAAA;AAEf;;;;;;;;;;;;;;GAcG;AACH,SAAgB,OAAO,CAAI,MAAS;IAClC,OAAO,MAAsB,CAAC;AAChC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,SAAS,CACvB,IAAO;IAEP,OAAO,UAAC,MAAM,IAAK,OAAA,mBAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,EAAxB,CAAwB,CAAC;AAC9C,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,SAAS,CACvB,SAAwB;IAExB,OAAO,UAAC,MAAM,IAAK,OAAA,mBAAI,CAAC,KAAK,CAAC,MAAM,EAAE,SAAgB,CAAC,EAApC,CAAoC,CAAC;AAC1D,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,WAAW,CACzB,IAAO,EACP,SAAwD;IAExD,OAAO,UAAC,MAAM,IAAK,OAAA,mBAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,SAAgB,CAAC,EAA5C,CAA4C,CAAC;AAClE,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,SAAS,CAAI,OAAiB;IAC5C,OAAO,UAAC,MAAM,IAAK,OAAA,mBAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,EAA3B,CAA2B,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,OAAO,CACrB,MAAS,EACT,IAAO,EACP,OAAiC;IAEjC,OAAO,mBAAI,CAAC,KAAK,CAAC,mBAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,WAAW,CACzB,IAAO,EACP,OAAsC;IAEtC,OAAO,UAAC,MAAM,IAAK,OAAA,mBAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,OAAc,CAAC,EAA1C,CAA0C,CAAC;AAChE,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,UAAU,CACxB,QAA4B;IAE5B,OAAO,UAAC,MAAM,IAAK,OAAA,mBAAI,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,EAA7B,CAA6B,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,QAAQ,CAKtB,MAAS,EACT,IAAO,EACP,QAA4B;IAE5B,OAAO,mBAAI,CAAC,MAAM,CAAC,mBAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAC;AACzD,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,YAAY,CAK1B,IAAO,EACP,QAA4B;IAE5B,OAAO,UAAC,MAAM,IAAK,OAAA,mBAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,EAArC,CAAqC,CAAC;AAC3D,CAAC;AAkID;;;;;;;;;;;GAWG;AACH,SAAgB,QAAQ;IACtB,OAAO,mBAAI,CAAC;AACd,CAAC"}
|
package/dist/cjs/deep.d.cts
CHANGED
|
@@ -68,9 +68,9 @@ export declare function patchWith<T, TE extends T = T, TT = T>(patchItem: Patch<
|
|
|
68
68
|
export declare function patchAtWith<T, P extends Path.Set<T>, TE extends T = T, TT = T>(path: P, patchItem: Patch<Path.Result<TE, P>, Path.Result<TT, P>>): (source: T) => T;
|
|
69
69
|
/**
|
|
70
70
|
* Returns a function that matches a given `value` with the given `matcher`.
|
|
71
|
-
* @typeparam T - the
|
|
71
|
+
* @typeparam T - the input value type
|
|
72
72
|
* @param matcher - a matcher object that matches input values.
|
|
73
|
-
* @param source - the value to
|
|
73
|
+
* @param source - the value to match (parameter of the returned function).
|
|
74
74
|
* @example
|
|
75
75
|
* ```ts
|
|
76
76
|
* const items = [{ a: 1, b: 'a' }, { a: 2, b: 'b' }];
|
|
@@ -96,7 +96,7 @@ export declare function matchWith<T>(matcher: Match<T>): (source: T) => boolean;
|
|
|
96
96
|
export declare function matchAt<T, P extends Path.Get<T>>(source: T, path: P, matcher: Match<Path.Result<T, P>>): boolean;
|
|
97
97
|
/**
|
|
98
98
|
* Returns a function that matches a given `value` with the given `matcher` at the given string `path`.
|
|
99
|
-
* @typeparam T - the
|
|
99
|
+
* @typeparam T - the input value type
|
|
100
100
|
* @typeparam P - the string literal path type in the object
|
|
101
101
|
* @typeparam TE - utility type
|
|
102
102
|
* @param path - the string path in the object
|
|
@@ -112,7 +112,7 @@ export declare function matchAt<T, P extends Path.Get<T>>(source: T, path: P, ma
|
|
|
112
112
|
export declare function matchAtWith<T, P extends Path.Get<T>, TE extends T = T>(path: P, matcher: Match<Path.Result<T & TE, P>>): (source: T) => boolean;
|
|
113
113
|
/**
|
|
114
114
|
* Returns a function that selects a certain shape from a given `value` with the given `selector`.
|
|
115
|
-
* @typeparam T - the
|
|
115
|
+
* @typeparam T - the input value type
|
|
116
116
|
* @typeparam SL - the selector shape type
|
|
117
117
|
* @param selector - a shape indicating the selection from the source values
|
|
118
118
|
* @param source - the value to use the given `selector` on.
|
|
@@ -126,7 +126,7 @@ export declare function matchAtWith<T, P extends Path.Get<T>, TE extends T = T>(
|
|
|
126
126
|
export declare function selectWith<T, SL extends Selector<T>>(selector: Selector.Shape<SL>): (source: T) => Selector.Result<T, SL>;
|
|
127
127
|
/**
|
|
128
128
|
* Returns the result of applying the given `selector` shape to the given `source` value.
|
|
129
|
-
* @typeparam T - the
|
|
129
|
+
* @typeparam T - the input value type
|
|
130
130
|
* @typeparam P - the string literal path type in the object
|
|
131
131
|
* @typeparam SL - the selector shape type
|
|
132
132
|
* @param source - the source value to select from
|
|
@@ -142,7 +142,7 @@ export declare function selectWith<T, SL extends Selector<T>>(selector: Selector
|
|
|
142
142
|
export declare function selectAt<T, P extends Path.Get<T>, SL extends Selector<Path.Result<T, P>>>(source: T, path: P, selector: Selector.Shape<SL>): Selector.Result<Path.Result<T, P>, SL>;
|
|
143
143
|
/**
|
|
144
144
|
* Returns a function that selects a certain shape from a given `value` with the given `selector` at the given string `path`.
|
|
145
|
-
* @typeparam T - the
|
|
145
|
+
* @typeparam T - the input value type
|
|
146
146
|
* @typeparam P - the string literal path type in the object
|
|
147
147
|
* @typeparam SL - the selector shape type
|
|
148
148
|
* @param path - the string path in the object
|
package/dist/cjs/match.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.match =
|
|
3
|
+
exports.match = match;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var base_1 = require("@rimbu/base");
|
|
6
6
|
/**
|
|
@@ -17,7 +17,7 @@ var base_1 = require("@rimbu/base");
|
|
|
17
17
|
* match(input, { a: 2 }) // => false
|
|
18
18
|
* match(input, { a: (v) => v > 10 }) // => false
|
|
19
19
|
* match(input, { b: { c: true }}) // => true
|
|
20
|
-
* match(input,
|
|
20
|
+
* match(input, ['every', { a: (v) => v > 0 }, { b: { c: true } }]) // => true
|
|
21
21
|
* match(input, { b: { c: (v, parent, root) => v && parent.d.length > 0 && root.a > 0 } })
|
|
22
22
|
* // => true
|
|
23
23
|
* ```
|
|
@@ -25,7 +25,6 @@ var base_1 = require("@rimbu/base");
|
|
|
25
25
|
function match(source, matcher, failureLog) {
|
|
26
26
|
return matchEntry(source, source, source, matcher, failureLog);
|
|
27
27
|
}
|
|
28
|
-
exports.match = match;
|
|
29
28
|
/**
|
|
30
29
|
* Match a generic match entry against the given source.
|
|
31
30
|
*/
|