@rimbu/deep 0.8.2 → 0.9.2
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 +26 -15
- package/dist/main/index.js +8 -1
- package/dist/main/index.js.map +1 -1
- package/dist/main/internal.js +6 -6
- package/dist/main/internal.js.map +1 -1
- package/dist/main/match.js +12 -4
- package/dist/main/match.js.map +1 -1
- package/dist/main/patch.js +7 -3
- package/dist/main/patch.js.map +1 -1
- package/dist/main/path.js +11 -5
- package/dist/main/path.js.map +1 -1
- package/dist/main/tuple.js +21 -1
- package/dist/main/tuple.js.map +1 -1
- package/dist/module/index.js +7 -0
- package/dist/module/index.js.map +1 -1
- package/dist/module/match.js +8 -0
- package/dist/module/match.js.map +1 -1
- package/dist/module/patch.js +4 -0
- package/dist/module/patch.js.map +1 -1
- package/dist/module/path.js +6 -0
- package/dist/module/path.js.map +1 -1
- package/dist/module/tuple.js +20 -0
- package/dist/module/tuple.js.map +1 -1
- package/dist/types/index.d.ts +7 -0
- package/dist/types/match.d.ts +8 -0
- package/dist/types/patch.d.ts +4 -0
- package/dist/types/path.d.ts +10 -0
- package/dist/types/tuple.d.ts +20 -0
- package/package.json +8 -6
- package/src/index.ts +8 -0
- package/src/match.ts +8 -0
- package/src/patch.ts +4 -0
- package/src/path.ts +10 -0
- package/src/tuple.ts +20 -0
package/dist/module/path.js
CHANGED
|
@@ -8,10 +8,12 @@ export var Path;
|
|
|
8
8
|
* @param source - the object to select in
|
|
9
9
|
* @param path - the path into the object
|
|
10
10
|
* @example
|
|
11
|
+
* ```ts
|
|
11
12
|
* console.log(Path.getValue({ a: { b: { c: 5 } } }), 'a.b')
|
|
12
13
|
* // => { c: 5 }
|
|
13
14
|
* console.log(Path.getValue({ a: { b: { c: 5 } } }), 'a.b.c')
|
|
14
15
|
* // => 5
|
|
16
|
+
* ```
|
|
15
17
|
*/
|
|
16
18
|
function getValue(source, path) {
|
|
17
19
|
const items = path.split('.');
|
|
@@ -28,7 +30,9 @@ export var Path;
|
|
|
28
30
|
* @param path - the path in the object to update
|
|
29
31
|
* @param value - the new value to set at the given position
|
|
30
32
|
* @example
|
|
33
|
+
* ```ts
|
|
31
34
|
* console.log(Path.setValue({ a: { b: { c: 5 } } }))
|
|
35
|
+
* ```
|
|
32
36
|
*/
|
|
33
37
|
function setValue(source, path, value) {
|
|
34
38
|
const items = path.split('.');
|
|
@@ -53,8 +57,10 @@ export var Path;
|
|
|
53
57
|
* @param path - the path in the object to update
|
|
54
58
|
* @param patches - one or more patches to update the value at the given path
|
|
55
59
|
* @example
|
|
60
|
+
* ```ts
|
|
56
61
|
* console.log(Path.setValue({ a: { b: { c: 5 } } }, 'a.b.c', 8)
|
|
57
62
|
* // => { a: { b: { c: 8 } } }
|
|
63
|
+
* ```
|
|
58
64
|
*/
|
|
59
65
|
function patchValue(source, path, ...patches) {
|
|
60
66
|
const value = Path.getValue(source, path);
|
package/dist/module/path.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,EAAS,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,EAAS,MAAM,YAAY,CAAC;AAcnD,MAAM,KAAW,IAAI,CAiHpB;AAjHD,WAAiB,IAAI;IAwBnB;;;;;;;;;;;;;OAaG;IACH,SAAgB,QAAQ,CACtB,MAAS,EACT,IAAO;QAEP,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE9B,IAAI,MAAM,GAAQ,MAAM,CAAC;QAEzB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;SACvB;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAbe,aAAQ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ple.js
CHANGED
|
@@ -5,8 +5,10 @@ export var Tuple;
|
|
|
5
5
|
* Convenience method to type Tuple types
|
|
6
6
|
* @param values - the values of the tuple
|
|
7
7
|
* @example
|
|
8
|
+
* ```ts
|
|
8
9
|
* const t = Tuple.of(1, 'a', true)
|
|
9
10
|
* // type of t => Tuple<[number, string, boolean]>
|
|
11
|
+
* ```
|
|
10
12
|
*/
|
|
11
13
|
function of(...values) {
|
|
12
14
|
return values;
|
|
@@ -17,9 +19,11 @@ export var Tuple;
|
|
|
17
19
|
* @param tuple - the tuple to get the item from
|
|
18
20
|
* @param index - the index in of the tuple element
|
|
19
21
|
* @example
|
|
22
|
+
* ```ts
|
|
20
23
|
* const t = Tuple.of(1, 'a', true)
|
|
21
24
|
* console.log(Tuple.getIndex(t, 1))
|
|
22
25
|
* // => 'a'
|
|
26
|
+
* ```
|
|
23
27
|
*/
|
|
24
28
|
function getIndex(tuple, index) {
|
|
25
29
|
return tuple[index];
|
|
@@ -29,9 +33,11 @@ export var Tuple;
|
|
|
29
33
|
* Returns the first element of a Tuple.
|
|
30
34
|
* @param tuple - the source tuple
|
|
31
35
|
* @example
|
|
36
|
+
* ```ts
|
|
32
37
|
* const t = Tuple.of(1, 'a', true)
|
|
33
38
|
* console.log(Tuple.first(t))
|
|
34
39
|
* // => 1
|
|
40
|
+
* ```
|
|
35
41
|
*/
|
|
36
42
|
function first(tuple) {
|
|
37
43
|
return tuple[0];
|
|
@@ -41,9 +47,11 @@ export var Tuple;
|
|
|
41
47
|
* Returns the second element of a Tuple.
|
|
42
48
|
* @param tuple - the source tuple
|
|
43
49
|
* @example
|
|
50
|
+
* ```ts
|
|
44
51
|
* const t = Tuple.of(1, 'a', true)
|
|
45
52
|
* console.log(Tuple.second(t))
|
|
46
53
|
* // => 'a'
|
|
54
|
+
* ```
|
|
47
55
|
*/
|
|
48
56
|
function second(tuple) {
|
|
49
57
|
return tuple[1];
|
|
@@ -53,9 +61,11 @@ export var Tuple;
|
|
|
53
61
|
* Returns the last element of a Tuple.
|
|
54
62
|
* @param tuple - the source tuple
|
|
55
63
|
* @example
|
|
64
|
+
* ```ts
|
|
56
65
|
* const t = Tuple.of(1, 'a', true)
|
|
57
66
|
* console.log(Tuple.last(t))
|
|
58
67
|
* // => true
|
|
68
|
+
* ```
|
|
59
69
|
*/
|
|
60
70
|
function last(tuple) {
|
|
61
71
|
return tuple[tuple.length - 1];
|
|
@@ -68,9 +78,11 @@ export var Tuple;
|
|
|
68
78
|
* @param index - the index in the tuple
|
|
69
79
|
* @param updater - the updater for the value
|
|
70
80
|
* @example
|
|
81
|
+
* ```ts
|
|
71
82
|
* const t = Tuple.of(1, 'a', true)
|
|
72
83
|
* console.log(Tuple.updateAt(t, 1, 'b'))
|
|
73
84
|
* // => [1, 'b', true]
|
|
85
|
+
* ```
|
|
74
86
|
*/
|
|
75
87
|
function updateAt(tuple, index, updater) {
|
|
76
88
|
return Arr.update(tuple, index, updater);
|
|
@@ -81,9 +93,11 @@ export var Tuple;
|
|
|
81
93
|
* @param tuple - the source tuple
|
|
82
94
|
* @param values - the values to append
|
|
83
95
|
* @example
|
|
96
|
+
* ```ts
|
|
84
97
|
* const t = Tuple.of(1, 'a')
|
|
85
98
|
* console.log(Tuple.append(t, true, 5))
|
|
86
99
|
* // => [1, 'a', true, 5]
|
|
100
|
+
* ```
|
|
87
101
|
*/
|
|
88
102
|
function append(tuple, ...values) {
|
|
89
103
|
return [...tuple, ...values];
|
|
@@ -95,10 +109,12 @@ export var Tuple;
|
|
|
95
109
|
* @param tuple1 - the first Tuple
|
|
96
110
|
* @param tuple2 - the second Tuple
|
|
97
111
|
* @example
|
|
112
|
+
* ```ts
|
|
98
113
|
* const t1 = Tuple.of(1, 'a')
|
|
99
114
|
* const t2 = Tuple.of(true, 5)
|
|
100
115
|
* console.log(Tuple.concat(t1, t2))
|
|
101
116
|
* // => [1, 'a', true, 5]
|
|
117
|
+
* ```
|
|
102
118
|
*/
|
|
103
119
|
function concat(tuple1, tuple2) {
|
|
104
120
|
return tuple1.concat(tuple2);
|
|
@@ -108,9 +124,11 @@ export var Tuple;
|
|
|
108
124
|
* Returns a Tuple containing all but the last element of the given `tuple`.
|
|
109
125
|
* @param tuple - the source tuple
|
|
110
126
|
* @example
|
|
127
|
+
* ```ts
|
|
111
128
|
* const t = Tuple.of(1, 'a', true)
|
|
112
129
|
* console.log(Tuple.init(t))
|
|
113
130
|
* // => [1, 'a']
|
|
131
|
+
* ```
|
|
114
132
|
*/
|
|
115
133
|
function init(tuple) {
|
|
116
134
|
return Arr.init(tuple);
|
|
@@ -120,9 +138,11 @@ export var Tuple;
|
|
|
120
138
|
* Returns a Tuple containing all but the first element of the given `tuple`.
|
|
121
139
|
* @param tuple - the source tuple
|
|
122
140
|
* @example
|
|
141
|
+
* ```ts
|
|
123
142
|
* const t = Tuple.of(1, 'a', true)
|
|
124
143
|
* console.log(Tuple.tail(t))
|
|
125
144
|
* // => ['a', true]
|
|
145
|
+
* ```
|
|
126
146
|
*/
|
|
127
147
|
function tail(tuple) {
|
|
128
148
|
return Arr.tail(tuple);
|
package/dist/module/tuple.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../src/tuple.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAQlC,MAAM,KAAW,KAAK,
|
|
1
|
+
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../src/tuple.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAQlC,MAAM,KAAW,KAAK,CAgLrB;AAhLD,WAAiB,KAAK;IAWpB;;;;;;;;OAQG;IACH,SAAgB,EAAE,CAAiC,GAAG,MAAS;QAC7D,OAAO,MAAa,CAAC;IACvB,CAAC;IAFe,QAAE,KAEjB,CAAA;IAED;;;;;;;;;;OAUG;IACH,SAAgB,QAAQ,CACtB,KAAQ,EACR,KAAQ;QAER,O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AAI,CAAC,KAAK,CAAQ,CAAC;IAChC,CAAC;IAJe,UAAI,OAInB,CAAA;AACH,CAAC,EAhLgB,KAAK,KAAL,KAAK,QAgLrB"}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/match.d.ts
CHANGED
|
@@ -47,8 +47,10 @@ export declare namespace Match {
|
|
|
47
47
|
* @param value - the value to match
|
|
48
48
|
* @param matchers - one or more `Match` objects
|
|
49
49
|
* @example
|
|
50
|
+
* ```ts
|
|
50
51
|
* matchAll({ g: { h: 'abc' }})({ g: { h: 'a' }}) => false
|
|
51
52
|
* matchAll({ g: { h: 'abc' }})({ g: { h: v => v.length > 1 }}) => true
|
|
53
|
+
* ```
|
|
52
54
|
*/
|
|
53
55
|
function all<T>(value: T): (...matchers: Match.Multi<T>) => boolean;
|
|
54
56
|
/**
|
|
@@ -57,8 +59,10 @@ export declare namespace Match {
|
|
|
57
59
|
* @param value - the value to match
|
|
58
60
|
* @param matchers - one or more `Match` objects
|
|
59
61
|
* @example
|
|
62
|
+
* ```ts
|
|
60
63
|
* matchAny({ g: { h: 'abc' }})({ g: { h: 'a' }}, { g: { h: v => v.length < 2 }}) => false
|
|
61
64
|
* matchAny({ g: { h: 'abc' }})({ g: { h: 'a' }}, { g: { h: v => v.length > 1 }}) => true
|
|
65
|
+
* ```
|
|
62
66
|
*/
|
|
63
67
|
function any<T>(value: T): (...matchers: Match.Multi<T>) => boolean;
|
|
64
68
|
/**
|
|
@@ -68,6 +72,7 @@ export declare namespace Match {
|
|
|
68
72
|
* @typeparam T2 - the type to use for the Match, should be equal to T
|
|
69
73
|
* @param matches - at least one Match instance to perform on a given `value`
|
|
70
74
|
* @example
|
|
75
|
+
* ```ts
|
|
71
76
|
* type Person = { name: string, age: number }
|
|
72
77
|
* const m = Match.createAll<Person>({ age: v => v > 20 }, { name: v => v.length > 2 })
|
|
73
78
|
*
|
|
@@ -77,6 +82,7 @@ export declare namespace Match {
|
|
|
77
82
|
* // => true
|
|
78
83
|
* console.log(m({ name: 'a', age: 20 }))
|
|
79
84
|
* // => false
|
|
85
|
+
* ```
|
|
80
86
|
*/
|
|
81
87
|
function createAll<T, T2 extends T = T>(...matches: Match.Multi<T2>): (value: T) => boolean;
|
|
82
88
|
/**
|
|
@@ -86,6 +92,7 @@ export declare namespace Match {
|
|
|
86
92
|
* @typeparam T2 - the type to use for the Match, should be equal to T
|
|
87
93
|
* @param matches - at least one Match instance to perform on a given `value`
|
|
88
94
|
* @example
|
|
95
|
+
* ```ts
|
|
89
96
|
* type Person = { name: string, age: number }
|
|
90
97
|
* const m = Match.createAny<Person>({ age: v => v > 20 }, { name: v => v.length > 2 })
|
|
91
98
|
*
|
|
@@ -97,6 +104,7 @@ export declare namespace Match {
|
|
|
97
104
|
* // => true
|
|
98
105
|
* console.log(m({ name: 'a', age: 10 }))
|
|
99
106
|
* // => false
|
|
107
|
+
* ```
|
|
100
108
|
*/
|
|
101
109
|
function createAny<T, T2 extends T = T>(...matches: Match.Multi<T2>): (value: T) => boolean;
|
|
102
110
|
}
|
package/dist/types/patch.d.ts
CHANGED
|
@@ -15,12 +15,14 @@ declare type PatchHelper<T, P, R> = T extends Literal.Obj ? Patch.PatchObj<T, P,
|
|
|
15
15
|
* @param value - the value to update
|
|
16
16
|
* @param patches - one or more `Patch` objects indicating modifications to the value
|
|
17
17
|
* @example
|
|
18
|
+
* ```ts
|
|
18
19
|
* patch({ g: { h: 5 }})({ g: { h: 6 }}) // => { g: { h: 6 }}
|
|
19
20
|
* patch({ g: { h: 5 }})({ g: { h: v => v + 1 }}) // => { g: { h: 6 }}
|
|
20
21
|
* patch({ g: { h: 5 }})({ g: { h: 1 }}, { g: { h: v => v + 1 }})
|
|
21
22
|
* // => { g: { h: 2 }}
|
|
22
23
|
* patch({ a: 1, b: 3 })({ a: (v, p) => v * p.b, (v, p) => v + p.a })
|
|
23
24
|
* // => { a: 3, b: 4 }
|
|
25
|
+
* ```
|
|
24
26
|
*/
|
|
25
27
|
export declare function patch<T>(value: T): (...patches: Patch.Multi<T>) => T;
|
|
26
28
|
export declare namespace Patch {
|
|
@@ -66,9 +68,11 @@ export declare namespace Patch {
|
|
|
66
68
|
* @typeparam T2 - the type the Patch is done for, should be equal to T
|
|
67
69
|
* @param patches - the patches to apply to a given object
|
|
68
70
|
* @example
|
|
71
|
+
* ```ts
|
|
69
72
|
* const r = Patch.create<{ a: number, b: number }>({ b: v => v + 1 })({ a: 1, b: 2})
|
|
70
73
|
* console.log(r)
|
|
71
74
|
* // => { a: 1, b: 3 }
|
|
75
|
+
* ```
|
|
72
76
|
*/
|
|
73
77
|
function create<T, T2 extends T = T>(...patches: Patch.Multi<T2>): (value: T) => T;
|
|
74
78
|
}
|
package/dist/types/path.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import { Literal, Patch } from './internal';
|
|
|
3
3
|
* A string representing a path into an (nested) object of type T.
|
|
4
4
|
* @typeparam T - the object type to select in
|
|
5
5
|
* @example
|
|
6
|
+
* ```ts
|
|
6
7
|
* const p: Path<{ a: { b: { c : 5 }}}> = 'a.b'
|
|
8
|
+
* ```
|
|
7
9
|
*/
|
|
8
10
|
export declare type Path<T> = T extends Literal.Obj ? {
|
|
9
11
|
[K in string & keyof T]: `${K}` | `${K}.${Path<T[K]>}`;
|
|
@@ -14,8 +16,10 @@ export declare namespace Path {
|
|
|
14
16
|
* @typeparam T - the object type to select in
|
|
15
17
|
* @typeparam P - a Path in object type T
|
|
16
18
|
* @example
|
|
19
|
+
* ```ts
|
|
17
20
|
* let r!: Path.Result<{ a: { b: { c: number } } }, 'a.b'>;
|
|
18
21
|
* // => type of r: { c: number }
|
|
22
|
+
* ```
|
|
19
23
|
*/
|
|
20
24
|
type Result<T, P extends Path<T> = Path<T>> = T extends Record<string, unknown> ? P extends `${infer Head}.${infer Rest}` ? Head extends keyof T ? Path.Result<T[Head], Rest & Path<T[Head]>> : never : P extends `${infer K}` ? T[K] : never : never;
|
|
21
25
|
/**
|
|
@@ -25,10 +29,12 @@ export declare namespace Path {
|
|
|
25
29
|
* @param source - the object to select in
|
|
26
30
|
* @param path - the path into the object
|
|
27
31
|
* @example
|
|
32
|
+
* ```ts
|
|
28
33
|
* console.log(Path.getValue({ a: { b: { c: 5 } } }), 'a.b')
|
|
29
34
|
* // => { c: 5 }
|
|
30
35
|
* console.log(Path.getValue({ a: { b: { c: 5 } } }), 'a.b.c')
|
|
31
36
|
* // => 5
|
|
37
|
+
* ```
|
|
32
38
|
*/
|
|
33
39
|
function getValue<T, P extends Path<T> = Path<T>>(source: T, path: P): Path.Result<T, P>;
|
|
34
40
|
/**
|
|
@@ -37,7 +43,9 @@ export declare namespace Path {
|
|
|
37
43
|
* @param path - the path in the object to update
|
|
38
44
|
* @param value - the new value to set at the given position
|
|
39
45
|
* @example
|
|
46
|
+
* ```ts
|
|
40
47
|
* console.log(Path.setValue({ a: { b: { c: 5 } } }))
|
|
48
|
+
* ```
|
|
41
49
|
*/
|
|
42
50
|
function setValue<T, P extends Path<T> = Path<T>>(source: T, path: P, value: Path.Result<T, P>): T;
|
|
43
51
|
/**
|
|
@@ -47,8 +55,10 @@ export declare namespace Path {
|
|
|
47
55
|
* @param path - the path in the object to update
|
|
48
56
|
* @param patches - one or more patches to update the value at the given path
|
|
49
57
|
* @example
|
|
58
|
+
* ```ts
|
|
50
59
|
* console.log(Path.setValue({ a: { b: { c: 5 } } }, 'a.b.c', 8)
|
|
51
60
|
* // => { a: { b: { c: 8 } } }
|
|
61
|
+
* ```
|
|
52
62
|
*/
|
|
53
63
|
function patchValue<T, P extends Path<T> = Path<T>>(source: T, path: P, ...patches: Patch.Multi<Path.Result<T, P>>): T;
|
|
54
64
|
}
|
package/dist/types/tuple.d.ts
CHANGED
|
@@ -16,8 +16,10 @@ export declare namespace Tuple {
|
|
|
16
16
|
* Convenience method to type Tuple types
|
|
17
17
|
* @param values - the values of the tuple
|
|
18
18
|
* @example
|
|
19
|
+
* ```ts
|
|
19
20
|
* const t = Tuple.of(1, 'a', true)
|
|
20
21
|
* // type of t => Tuple<[number, string, boolean]>
|
|
22
|
+
* ```
|
|
21
23
|
*/
|
|
22
24
|
function of<T extends Tuple.NonEmptySource>(...values: T): Tuple<T>;
|
|
23
25
|
/**
|
|
@@ -25,36 +27,44 @@ export declare namespace Tuple {
|
|
|
25
27
|
* @param tuple - the tuple to get the item from
|
|
26
28
|
* @param index - the index in of the tuple element
|
|
27
29
|
* @example
|
|
30
|
+
* ```ts
|
|
28
31
|
* const t = Tuple.of(1, 'a', true)
|
|
29
32
|
* console.log(Tuple.getIndex(t, 1))
|
|
30
33
|
* // => 'a'
|
|
34
|
+
* ```
|
|
31
35
|
*/
|
|
32
36
|
function getIndex<T extends Tuple.Source, K extends keyof T = keyof T>(tuple: T, index: K): T[K];
|
|
33
37
|
/**
|
|
34
38
|
* Returns the first element of a Tuple.
|
|
35
39
|
* @param tuple - the source tuple
|
|
36
40
|
* @example
|
|
41
|
+
* ```ts
|
|
37
42
|
* const t = Tuple.of(1, 'a', true)
|
|
38
43
|
* console.log(Tuple.first(t))
|
|
39
44
|
* // => 1
|
|
45
|
+
* ```
|
|
40
46
|
*/
|
|
41
47
|
function first<T extends Tuple.Source>(tuple: T): T[0];
|
|
42
48
|
/**
|
|
43
49
|
* Returns the second element of a Tuple.
|
|
44
50
|
* @param tuple - the source tuple
|
|
45
51
|
* @example
|
|
52
|
+
* ```ts
|
|
46
53
|
* const t = Tuple.of(1, 'a', true)
|
|
47
54
|
* console.log(Tuple.second(t))
|
|
48
55
|
* // => 'a'
|
|
56
|
+
* ```
|
|
49
57
|
*/
|
|
50
58
|
function second<T extends Tuple.Source>(tuple: T): T[1];
|
|
51
59
|
/**
|
|
52
60
|
* Returns the last element of a Tuple.
|
|
53
61
|
* @param tuple - the source tuple
|
|
54
62
|
* @example
|
|
63
|
+
* ```ts
|
|
55
64
|
* const t = Tuple.of(1, 'a', true)
|
|
56
65
|
* console.log(Tuple.last(t))
|
|
57
66
|
* // => true
|
|
67
|
+
* ```
|
|
58
68
|
*/
|
|
59
69
|
function last<T extends readonly unknown[], R>(tuple: readonly [...T, R]): R;
|
|
60
70
|
/**
|
|
@@ -64,9 +74,11 @@ export declare namespace Tuple {
|
|
|
64
74
|
* @param index - the index in the tuple
|
|
65
75
|
* @param updater - the updater for the value
|
|
66
76
|
* @example
|
|
77
|
+
* ```ts
|
|
67
78
|
* const t = Tuple.of(1, 'a', true)
|
|
68
79
|
* console.log(Tuple.updateAt(t, 1, 'b'))
|
|
69
80
|
* // => [1, 'b', true]
|
|
81
|
+
* ```
|
|
70
82
|
*/
|
|
71
83
|
function updateAt<T extends Tuple.Source, K extends keyof T = keyof T>(tuple: T, index: K, updater: Update<T[K]>): T;
|
|
72
84
|
/**
|
|
@@ -74,9 +86,11 @@ export declare namespace Tuple {
|
|
|
74
86
|
* @param tuple - the source tuple
|
|
75
87
|
* @param values - the values to append
|
|
76
88
|
* @example
|
|
89
|
+
* ```ts
|
|
77
90
|
* const t = Tuple.of(1, 'a')
|
|
78
91
|
* console.log(Tuple.append(t, true, 5))
|
|
79
92
|
* // => [1, 'a', true, 5]
|
|
93
|
+
* ```
|
|
80
94
|
*/
|
|
81
95
|
function append<T extends Tuple.Source, V extends readonly [unknown, ...unknown[]]>(tuple: T, ...values: V): readonly [...T, ...V];
|
|
82
96
|
/**
|
|
@@ -85,28 +99,34 @@ export declare namespace Tuple {
|
|
|
85
99
|
* @param tuple1 - the first Tuple
|
|
86
100
|
* @param tuple2 - the second Tuple
|
|
87
101
|
* @example
|
|
102
|
+
* ```ts
|
|
88
103
|
* const t1 = Tuple.of(1, 'a')
|
|
89
104
|
* const t2 = Tuple.of(true, 5)
|
|
90
105
|
* console.log(Tuple.concat(t1, t2))
|
|
91
106
|
* // => [1, 'a', true, 5]
|
|
107
|
+
* ```
|
|
92
108
|
*/
|
|
93
109
|
function concat<T1 extends Tuple.Source, T2 extends Tuple.Source>(tuple1: T1, tuple2: T2): readonly [...T1, ...T2];
|
|
94
110
|
/**
|
|
95
111
|
* Returns a Tuple containing all but the last element of the given `tuple`.
|
|
96
112
|
* @param tuple - the source tuple
|
|
97
113
|
* @example
|
|
114
|
+
* ```ts
|
|
98
115
|
* const t = Tuple.of(1, 'a', true)
|
|
99
116
|
* console.log(Tuple.init(t))
|
|
100
117
|
* // => [1, 'a']
|
|
118
|
+
* ```
|
|
101
119
|
*/
|
|
102
120
|
function init<T extends readonly unknown[]>(tuple: readonly [...T, unknown]): Readonly<T>;
|
|
103
121
|
/**
|
|
104
122
|
* Returns a Tuple containing all but the first element of the given `tuple`.
|
|
105
123
|
* @param tuple - the source tuple
|
|
106
124
|
* @example
|
|
125
|
+
* ```ts
|
|
107
126
|
* const t = Tuple.of(1, 'a', true)
|
|
108
127
|
* console.log(Tuple.tail(t))
|
|
109
128
|
* // => ['a', true]
|
|
129
|
+
* ```
|
|
110
130
|
*/
|
|
111
131
|
function tail<T extends readonly [...unknown[]]>(tuple: readonly [unknown, ...T]): Readonly<T>;
|
|
112
132
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rimbu/deep",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "Tools to use handle plain JS objects as immutable objects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"immutable",
|
|
@@ -40,12 +40,13 @@
|
|
|
40
40
|
],
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "yarn clean && yarn bundle",
|
|
43
|
-
"build:deno": "rimraf deno_dist ../../deno_dist/deep && denoify &&
|
|
43
|
+
"build:deno": "rimraf deno_dist ../../deno_dist/deep && denoify && mv deno_dist ../../deno_dist/deep",
|
|
44
44
|
"bundle": "yarn bundle:main && yarn bundle:module && yarn bundle:types",
|
|
45
45
|
"bundle:main": "tsc --p tsconfig.main.json",
|
|
46
46
|
"bundle:module": "tsc --p tsconfig.module.json",
|
|
47
47
|
"bundle:types": "tsc --p tsconfig.types.json",
|
|
48
48
|
"clean": "rimraf dist",
|
|
49
|
+
"extract-api": "api-extractor run --local --verbose --config config/api-extractor.main.json",
|
|
49
50
|
"format": "yarn format:base --write",
|
|
50
51
|
"format:base": "prettier \"{!CHANGELOG.md}|**/**/*.{ts,tsx,js,json,md}\"",
|
|
51
52
|
"format:check": "yarn format:base --check",
|
|
@@ -56,15 +57,16 @@
|
|
|
56
57
|
},
|
|
57
58
|
"sideEffects": false,
|
|
58
59
|
"dependencies": {
|
|
59
|
-
"@rimbu/base": "^0.
|
|
60
|
-
"@rimbu/common": "^0.
|
|
61
|
-
"tslib": "^2.
|
|
60
|
+
"@rimbu/base": "^0.8.2",
|
|
61
|
+
"@rimbu/common": "^0.9.2",
|
|
62
|
+
"tslib": "^2.4.0"
|
|
62
63
|
},
|
|
63
64
|
"publishConfig": {
|
|
64
65
|
"access": "public"
|
|
65
66
|
},
|
|
66
67
|
"denoify": {
|
|
68
|
+
"index": "src/index.ts",
|
|
67
69
|
"replacer": "../../config/denoify-rimbu-replacer.js"
|
|
68
70
|
},
|
|
69
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "33dd7ca935f19f513586834a2ce1b1f886352ae7"
|
|
70
72
|
}
|
package/src/index.ts
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* The `@rimbu/deep` package provides utilities to patch and match plain JavaScript objects..<br/>
|
|
5
|
+
* <br/>
|
|
6
|
+
* See the [Rimbu docs Deep overview page](/docs/deep/overview) for more information.
|
|
7
|
+
*/
|
|
8
|
+
|
|
1
9
|
export * from './internal';
|
package/src/match.ts
CHANGED
|
@@ -69,8 +69,10 @@ export namespace Match {
|
|
|
69
69
|
* @param value - the value to match
|
|
70
70
|
* @param matchers - one or more `Match` objects
|
|
71
71
|
* @example
|
|
72
|
+
* ```ts
|
|
72
73
|
* matchAll({ g: { h: 'abc' }})({ g: { h: 'a' }}) => false
|
|
73
74
|
* matchAll({ g: { h: 'abc' }})({ g: { h: v => v.length > 1 }}) => true
|
|
75
|
+
* ```
|
|
74
76
|
*/
|
|
75
77
|
export function all<T>(value: T): (...matchers: Match.Multi<T>) => boolean {
|
|
76
78
|
return (...matchers): boolean => {
|
|
@@ -90,8 +92,10 @@ export namespace Match {
|
|
|
90
92
|
* @param value - the value to match
|
|
91
93
|
* @param matchers - one or more `Match` objects
|
|
92
94
|
* @example
|
|
95
|
+
* ```ts
|
|
93
96
|
* matchAny({ g: { h: 'abc' }})({ g: { h: 'a' }}, { g: { h: v => v.length < 2 }}) => false
|
|
94
97
|
* matchAny({ g: { h: 'abc' }})({ g: { h: 'a' }}, { g: { h: v => v.length > 1 }}) => true
|
|
98
|
+
* ```
|
|
95
99
|
*/
|
|
96
100
|
export function any<T>(value: T): (...matchers: Match.Multi<T>) => boolean {
|
|
97
101
|
return (...matchers): boolean => {
|
|
@@ -112,6 +116,7 @@ export namespace Match {
|
|
|
112
116
|
* @typeparam T2 - the type to use for the Match, should be equal to T
|
|
113
117
|
* @param matches - at least one Match instance to perform on a given `value`
|
|
114
118
|
* @example
|
|
119
|
+
* ```ts
|
|
115
120
|
* type Person = { name: string, age: number }
|
|
116
121
|
* const m = Match.createAll<Person>({ age: v => v > 20 }, { name: v => v.length > 2 })
|
|
117
122
|
*
|
|
@@ -121,6 +126,7 @@ export namespace Match {
|
|
|
121
126
|
* // => true
|
|
122
127
|
* console.log(m({ name: 'a', age: 20 }))
|
|
123
128
|
* // => false
|
|
129
|
+
* ```
|
|
124
130
|
*/
|
|
125
131
|
export function createAll<T, T2 extends T = T>(
|
|
126
132
|
...matches: Match.Multi<T2>
|
|
@@ -135,6 +141,7 @@ export namespace Match {
|
|
|
135
141
|
* @typeparam T2 - the type to use for the Match, should be equal to T
|
|
136
142
|
* @param matches - at least one Match instance to perform on a given `value`
|
|
137
143
|
* @example
|
|
144
|
+
* ```ts
|
|
138
145
|
* type Person = { name: string, age: number }
|
|
139
146
|
* const m = Match.createAny<Person>({ age: v => v > 20 }, { name: v => v.length > 2 })
|
|
140
147
|
*
|
|
@@ -146,6 +153,7 @@ export namespace Match {
|
|
|
146
153
|
* // => true
|
|
147
154
|
* console.log(m({ name: 'a', age: 10 }))
|
|
148
155
|
* // => false
|
|
156
|
+
* ```
|
|
149
157
|
*/
|
|
150
158
|
export function createAny<T, T2 extends T = T>(
|
|
151
159
|
...matches: Match.Multi<T2>
|
package/src/patch.ts
CHANGED
|
@@ -23,12 +23,14 @@ type PatchHelper<T, P, R> = T extends Literal.Obj
|
|
|
23
23
|
* @param value - the value to update
|
|
24
24
|
* @param patches - one or more `Patch` objects indicating modifications to the value
|
|
25
25
|
* @example
|
|
26
|
+
* ```ts
|
|
26
27
|
* patch({ g: { h: 5 }})({ g: { h: 6 }}) // => { g: { h: 6 }}
|
|
27
28
|
* patch({ g: { h: 5 }})({ g: { h: v => v + 1 }}) // => { g: { h: 6 }}
|
|
28
29
|
* patch({ g: { h: 5 }})({ g: { h: 1 }}, { g: { h: v => v + 1 }})
|
|
29
30
|
* // => { g: { h: 2 }}
|
|
30
31
|
* patch({ a: 1, b: 3 })({ a: (v, p) => v * p.b, (v, p) => v + p.a })
|
|
31
32
|
* // => { a: 3, b: 4 }
|
|
33
|
+
* ```
|
|
32
34
|
*/
|
|
33
35
|
export function patch<T>(value: T): (...patches: Patch.Multi<T>) => T {
|
|
34
36
|
return function (...patches): T {
|
|
@@ -100,9 +102,11 @@ export namespace Patch {
|
|
|
100
102
|
* @typeparam T2 - the type the Patch is done for, should be equal to T
|
|
101
103
|
* @param patches - the patches to apply to a given object
|
|
102
104
|
* @example
|
|
105
|
+
* ```ts
|
|
103
106
|
* const r = Patch.create<{ a: number, b: number }>({ b: v => v + 1 })({ a: 1, b: 2})
|
|
104
107
|
* console.log(r)
|
|
105
108
|
* // => { a: 1, b: 3 }
|
|
109
|
+
* ```
|
|
106
110
|
*/
|
|
107
111
|
export function create<T, T2 extends T = T>(
|
|
108
112
|
...patches: Patch.Multi<T2>
|
package/src/path.ts
CHANGED
|
@@ -4,7 +4,9 @@ import { Literal, patch, Patch } from './internal';
|
|
|
4
4
|
* A string representing a path into an (nested) object of type T.
|
|
5
5
|
* @typeparam T - the object type to select in
|
|
6
6
|
* @example
|
|
7
|
+
* ```ts
|
|
7
8
|
* const p: Path<{ a: { b: { c : 5 }}}> = 'a.b'
|
|
9
|
+
* ```
|
|
8
10
|
*/
|
|
9
11
|
export type Path<T> = T extends Literal.Obj
|
|
10
12
|
? { [K in string & keyof T]: `${K}` | `${K}.${Path<T[K]>}` }[string & keyof T]
|
|
@@ -16,8 +18,10 @@ export namespace Path {
|
|
|
16
18
|
* @typeparam T - the object type to select in
|
|
17
19
|
* @typeparam P - a Path in object type T
|
|
18
20
|
* @example
|
|
21
|
+
* ```ts
|
|
19
22
|
* let r!: Path.Result<{ a: { b: { c: number } } }, 'a.b'>;
|
|
20
23
|
* // => type of r: { c: number }
|
|
24
|
+
* ```
|
|
21
25
|
*/
|
|
22
26
|
export type Result<T, P extends Path<T> = Path<T>> = T extends Record<
|
|
23
27
|
string,
|
|
@@ -39,10 +43,12 @@ export namespace Path {
|
|
|
39
43
|
* @param source - the object to select in
|
|
40
44
|
* @param path - the path into the object
|
|
41
45
|
* @example
|
|
46
|
+
* ```ts
|
|
42
47
|
* console.log(Path.getValue({ a: { b: { c: 5 } } }), 'a.b')
|
|
43
48
|
* // => { c: 5 }
|
|
44
49
|
* console.log(Path.getValue({ a: { b: { c: 5 } } }), 'a.b.c')
|
|
45
50
|
* // => 5
|
|
51
|
+
* ```
|
|
46
52
|
*/
|
|
47
53
|
export function getValue<T, P extends Path<T> = Path<T>>(
|
|
48
54
|
source: T,
|
|
@@ -65,7 +71,9 @@ export namespace Path {
|
|
|
65
71
|
* @param path - the path in the object to update
|
|
66
72
|
* @param value - the new value to set at the given position
|
|
67
73
|
* @example
|
|
74
|
+
* ```ts
|
|
68
75
|
* console.log(Path.setValue({ a: { b: { c: 5 } } }))
|
|
76
|
+
* ```
|
|
69
77
|
*/
|
|
70
78
|
export function setValue<T, P extends Path<T> = Path<T>>(
|
|
71
79
|
source: T,
|
|
@@ -100,8 +108,10 @@ export namespace Path {
|
|
|
100
108
|
* @param path - the path in the object to update
|
|
101
109
|
* @param patches - one or more patches to update the value at the given path
|
|
102
110
|
* @example
|
|
111
|
+
* ```ts
|
|
103
112
|
* console.log(Path.setValue({ a: { b: { c: 5 } } }, 'a.b.c', 8)
|
|
104
113
|
* // => { a: { b: { c: 8 } } }
|
|
114
|
+
* ```
|
|
105
115
|
*/
|
|
106
116
|
export function patchValue<T, P extends Path<T> = Path<T>>(
|
|
107
117
|
source: T,
|