@rimbu/deep 0.8.0 → 0.9.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/dist/main/index.js +7 -0
- package/dist/main/index.js.map +1 -1
- package/dist/main/match.js +8 -0
- package/dist/main/match.js.map +1 -1
- package/dist/main/patch.js +4 -0
- package/dist/main/patch.js.map +1 -1
- package/dist/main/path.js +6 -0
- package/dist/main/path.js.map +1 -1
- package/dist/main/tuple.js +20 -0
- 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/main/index.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*
|
|
5
|
+
* The `@rimbu/deep` package provides utilities to patch and match plain JavaScript objects..<br/>
|
|
6
|
+
* <br/>
|
|
7
|
+
* See the [Rimbu docs Deep overview page](/docs/deep/overview) for more information.
|
|
8
|
+
*/
|
|
2
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
10
|
var tslib_1 = require("tslib");
|
|
4
11
|
(0, tslib_1.__exportStar)(require("./internal"), exports);
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,0DAA2B"}
|
package/dist/main/match.js
CHANGED
|
@@ -12,8 +12,10 @@ var Match;
|
|
|
12
12
|
* @param value - the value to match
|
|
13
13
|
* @param matchers - one or more `Match` objects
|
|
14
14
|
* @example
|
|
15
|
+
* ```ts
|
|
15
16
|
* matchAll({ g: { h: 'abc' }})({ g: { h: 'a' }}) => false
|
|
16
17
|
* matchAll({ g: { h: 'abc' }})({ g: { h: v => v.length > 1 }}) => true
|
|
18
|
+
* ```
|
|
17
19
|
*/
|
|
18
20
|
function all(value) {
|
|
19
21
|
return function () {
|
|
@@ -47,8 +49,10 @@ var Match;
|
|
|
47
49
|
* @param value - the value to match
|
|
48
50
|
* @param matchers - one or more `Match` objects
|
|
49
51
|
* @example
|
|
52
|
+
* ```ts
|
|
50
53
|
* matchAny({ g: { h: 'abc' }})({ g: { h: 'a' }}, { g: { h: v => v.length < 2 }}) => false
|
|
51
54
|
* matchAny({ g: { h: 'abc' }})({ g: { h: 'a' }}, { g: { h: v => v.length > 1 }}) => true
|
|
55
|
+
* ```
|
|
52
56
|
*/
|
|
53
57
|
function any(value) {
|
|
54
58
|
return function () {
|
|
@@ -83,6 +87,7 @@ var Match;
|
|
|
83
87
|
* @typeparam T2 - the type to use for the Match, should be equal to T
|
|
84
88
|
* @param matches - at least one Match instance to perform on a given `value`
|
|
85
89
|
* @example
|
|
90
|
+
* ```ts
|
|
86
91
|
* type Person = { name: string, age: number }
|
|
87
92
|
* const m = Match.createAll<Person>({ age: v => v > 20 }, { name: v => v.length > 2 })
|
|
88
93
|
*
|
|
@@ -92,6 +97,7 @@ var Match;
|
|
|
92
97
|
* // => true
|
|
93
98
|
* console.log(m({ name: 'a', age: 20 }))
|
|
94
99
|
* // => false
|
|
100
|
+
* ```
|
|
95
101
|
*/
|
|
96
102
|
function createAll() {
|
|
97
103
|
var matches = [];
|
|
@@ -108,6 +114,7 @@ var Match;
|
|
|
108
114
|
* @typeparam T2 - the type to use for the Match, should be equal to T
|
|
109
115
|
* @param matches - at least one Match instance to perform on a given `value`
|
|
110
116
|
* @example
|
|
117
|
+
* ```ts
|
|
111
118
|
* type Person = { name: string, age: number }
|
|
112
119
|
* const m = Match.createAny<Person>({ age: v => v > 20 }, { name: v => v.length > 2 })
|
|
113
120
|
*
|
|
@@ -119,6 +126,7 @@ var Match;
|
|
|
119
126
|
* // => true
|
|
120
127
|
* console.log(m({ name: 'a', age: 10 }))
|
|
121
128
|
* // => false
|
|
129
|
+
* ```
|
|
122
130
|
*/
|
|
123
131
|
function createAny() {
|
|
124
132
|
var matches = [];
|
package/dist/main/match.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../src/match.ts"],"names":[],"mappings":";;;;AAAA,oCAAyC;AAEzC,uCAAgD;AAgBhD,IAAiB,KAAK,
|
|
1
|
+
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../src/match.ts"],"names":[],"mappings":";;;;AAAA,oCAAyC;AAEzC,uCAAgD;AAgBhD,IAAiB,KAAK,CAgJrB;AAhJD,WAAiB,KAAK;IA+CpB;;;;;;;;;;OAUG;IACH,SAAgB,GAAG,CAAI,KAAQ;QAC7B,OAAO;;YAAC,kBAAW;iBAAX,UAAW,EAAX,qBAAW,EAAX,IAAW;gBAAX,6BAAW;;;gBACjB,KAAsB,IAAA,aAAA,sBAAA,QAAQ,CAAA,kCAAA,wDAAE;oBAA3B,IAAM,OAAO,qBAAA;oBAChB,IAAI,CAAC,WAAW,CAAgB,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE;wBAC7D,OAAO,KAAK,CAAC;qBACd;iBACF;;;;;;;;;YAED,OAAO,IAAI,CAAC;QACd,CAAC,CAAC;IACJ,CAAC;IAV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;QAED,IAAM,MAAM,GAAG,WAAW,CACvB,KAAa,CAAC,GAAG,CAAC,EACnB,QAAQ,EACR,KAAK,EACL,IAAI,CACL,CAAC;QACF,IAAI,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;KAC3B;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/main/patch.js
CHANGED
|
@@ -11,12 +11,14 @@ var internal_1 = require("./internal");
|
|
|
11
11
|
* @param value - the value to update
|
|
12
12
|
* @param patches - one or more `Patch` objects indicating modifications to the value
|
|
13
13
|
* @example
|
|
14
|
+
* ```ts
|
|
14
15
|
* patch({ g: { h: 5 }})({ g: { h: 6 }}) // => { g: { h: 6 }}
|
|
15
16
|
* patch({ g: { h: 5 }})({ g: { h: v => v + 1 }}) // => { g: { h: 6 }}
|
|
16
17
|
* patch({ g: { h: 5 }})({ g: { h: 1 }}, { g: { h: v => v + 1 }})
|
|
17
18
|
* // => { g: { h: 2 }}
|
|
18
19
|
* patch({ a: 1, b: 3 })({ a: (v, p) => v * p.b, (v, p) => v + p.a })
|
|
19
20
|
* // => { a: 3, b: 4 }
|
|
21
|
+
* ```
|
|
20
22
|
*/
|
|
21
23
|
function patch(value) {
|
|
22
24
|
return function () {
|
|
@@ -53,9 +55,11 @@ var Patch;
|
|
|
53
55
|
* @typeparam T2 - the type the Patch is done for, should be equal to T
|
|
54
56
|
* @param patches - the patches to apply to a given object
|
|
55
57
|
* @example
|
|
58
|
+
* ```ts
|
|
56
59
|
* const r = Patch.create<{ a: number, b: number }>({ b: v => v + 1 })({ a: 1, b: 2})
|
|
57
60
|
* console.log(r)
|
|
58
61
|
* // => { a: 1, b: 3 }
|
|
62
|
+
* ```
|
|
59
63
|
*/
|
|
60
64
|
function create() {
|
|
61
65
|
var patches = [];
|
package/dist/main/patch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/patch.ts"],"names":[],"mappings":";;;;AAAA,oCAAyC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AAE,WAAW,CAAC,EAAE;gBACpC,IAAI,SAAS,KAAK,MAAM,EAAE;oBACxB,MAAM,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC;iBACtB;gBACD,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;aACrB;SACF;QAED,OAAO,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,GAAG,CAAQ,CAAC;KAC/B;IAED,IAAM,KAAK,GAAQ,YAAY,CAAC,CAAC,CAAE,mDAAK,KAAa,SAAS,CAAC,CAAC,2BAAM,KAAK,CAAE,CAAC;IAC9E,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,KAAK,IAAM,GAAG,IAAI,OAAc,EAAE;QAChC,IAAM,QAAQ,GAAI,OAAe,CAAC,GAAG,CAAC,CAAC;QAEvC,IAAI,CAAC,CAAC,GAAG,IAAI,KAAK,CAAC,IAAI,OAAO,QAAQ,KAAK,UAAU;YAAE,SAAS;QAEhE,IAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QAE5B,IAAI,SAAS,KAAK,QAAQ,EAAE;YAC1B,iBAAU,CAAC,sBAAsB,CAC/B,gHAAgH,CACjH,CAAC;SACH;QAED,IAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,EAAE,QAAe,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAErE,IAAI,QAAQ,KAAK,QAAQ,EAAE;YACzB,OAAO,GAAG,IAAI,CAAC;YACf,KAAK,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;SACvB;KACF;IAED,IAAI,OAAO;QAAE,OAAO,KAAK,CAAC;IAE1B,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/main/path.js
CHANGED
|
@@ -12,10 +12,12 @@ var Path;
|
|
|
12
12
|
* @param source - the object to select in
|
|
13
13
|
* @param path - the path into the object
|
|
14
14
|
* @example
|
|
15
|
+
* ```ts
|
|
15
16
|
* console.log(Path.getValue({ a: { b: { c: 5 } } }), 'a.b')
|
|
16
17
|
* // => { c: 5 }
|
|
17
18
|
* console.log(Path.getValue({ a: { b: { c: 5 } } }), 'a.b.c')
|
|
18
19
|
* // => 5
|
|
20
|
+
* ```
|
|
19
21
|
*/
|
|
20
22
|
function getValue(source, path) {
|
|
21
23
|
var e_1, _a;
|
|
@@ -43,7 +45,9 @@ var Path;
|
|
|
43
45
|
* @param path - the path in the object to update
|
|
44
46
|
* @param value - the new value to set at the given position
|
|
45
47
|
* @example
|
|
48
|
+
* ```ts
|
|
46
49
|
* console.log(Path.setValue({ a: { b: { c: 5 } } }))
|
|
50
|
+
* ```
|
|
47
51
|
*/
|
|
48
52
|
function setValue(source, path, value) {
|
|
49
53
|
var e_2, _a;
|
|
@@ -79,8 +83,10 @@ var Path;
|
|
|
79
83
|
* @param path - the path in the object to update
|
|
80
84
|
* @param patches - one or more patches to update the value at the given path
|
|
81
85
|
* @example
|
|
86
|
+
* ```ts
|
|
82
87
|
* console.log(Path.setValue({ a: { b: { c: 5 } } }, 'a.b.c', 8)
|
|
83
88
|
* // => { a: { b: { c: 8 } } }
|
|
89
|
+
* ```
|
|
84
90
|
*/
|
|
85
91
|
function patchValue(source, path) {
|
|
86
92
|
var patches = [];
|
package/dist/main/path.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/path.ts"],"names":[],"mappings":";;;;AAAA,uCAAmD;
|
|
1
|
+
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/path.ts"],"names":[],"mappings":";;;;AAAA,uCAAmD;AAcnD,IAAiB,IAAI,CAiHpB;AAjHD,WAAiB,IAAI;IAwBnB;;;;;;;;;;;;;OAaG;IACH,SAAgB,QAAQ,CACtB,MAAS,EACT,IAAO;;QAEP,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE9B,IAAI,MAAM,GAAQ,MAAM,CAAC;;YAEzB,KAAmB,IAAA,UAAA,sBAAA,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AAC,CAAC;QAE1C,IAAI,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC;YAAE,OAAO,MAAM,CAAC;QAE9C,OAAO,IAAI,CAAC,QAAQ,CAAW,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IACzD,CAAC;IAXe,eAAU,aAWzB,CAAA;AACH,CAAC,EAjHgB,IAAI,GAAJ,YAAI,KAAJ,YAAI,QAiHpB"}
|
package/dist/main/tuple.js
CHANGED
|
@@ -9,8 +9,10 @@ var Tuple;
|
|
|
9
9
|
* Convenience method to type Tuple types
|
|
10
10
|
* @param values - the values of the tuple
|
|
11
11
|
* @example
|
|
12
|
+
* ```ts
|
|
12
13
|
* const t = Tuple.of(1, 'a', true)
|
|
13
14
|
* // type of t => Tuple<[number, string, boolean]>
|
|
15
|
+
* ```
|
|
14
16
|
*/
|
|
15
17
|
function of() {
|
|
16
18
|
var values = [];
|
|
@@ -25,9 +27,11 @@ var 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(tuple, index) {
|
|
33
37
|
return tuple[index];
|
|
@@ -37,9 +41,11 @@ var Tuple;
|
|
|
37
41
|
* Returns the first element of a Tuple.
|
|
38
42
|
* @param tuple - the source tuple
|
|
39
43
|
* @example
|
|
44
|
+
* ```ts
|
|
40
45
|
* const t = Tuple.of(1, 'a', true)
|
|
41
46
|
* console.log(Tuple.first(t))
|
|
42
47
|
* // => 1
|
|
48
|
+
* ```
|
|
43
49
|
*/
|
|
44
50
|
function first(tuple) {
|
|
45
51
|
return tuple[0];
|
|
@@ -49,9 +55,11 @@ var Tuple;
|
|
|
49
55
|
* Returns the second element of a Tuple.
|
|
50
56
|
* @param tuple - the source tuple
|
|
51
57
|
* @example
|
|
58
|
+
* ```ts
|
|
52
59
|
* const t = Tuple.of(1, 'a', true)
|
|
53
60
|
* console.log(Tuple.second(t))
|
|
54
61
|
* // => 'a'
|
|
62
|
+
* ```
|
|
55
63
|
*/
|
|
56
64
|
function second(tuple) {
|
|
57
65
|
return tuple[1];
|
|
@@ -61,9 +69,11 @@ var Tuple;
|
|
|
61
69
|
* Returns the last element of a Tuple.
|
|
62
70
|
* @param tuple - the source tuple
|
|
63
71
|
* @example
|
|
72
|
+
* ```ts
|
|
64
73
|
* const t = Tuple.of(1, 'a', true)
|
|
65
74
|
* console.log(Tuple.last(t))
|
|
66
75
|
* // => true
|
|
76
|
+
* ```
|
|
67
77
|
*/
|
|
68
78
|
function last(tuple) {
|
|
69
79
|
return tuple[tuple.length - 1];
|
|
@@ -76,9 +86,11 @@ var Tuple;
|
|
|
76
86
|
* @param index - the index in the tuple
|
|
77
87
|
* @param updater - the updater for the value
|
|
78
88
|
* @example
|
|
89
|
+
* ```ts
|
|
79
90
|
* const t = Tuple.of(1, 'a', true)
|
|
80
91
|
* console.log(Tuple.updateAt(t, 1, 'b'))
|
|
81
92
|
* // => [1, 'b', true]
|
|
93
|
+
* ```
|
|
82
94
|
*/
|
|
83
95
|
function updateAt(tuple, index, updater) {
|
|
84
96
|
return base_1.Arr.update(tuple, index, updater);
|
|
@@ -89,9 +101,11 @@ var Tuple;
|
|
|
89
101
|
* @param tuple - the source tuple
|
|
90
102
|
* @param values - the values to append
|
|
91
103
|
* @example
|
|
104
|
+
* ```ts
|
|
92
105
|
* const t = Tuple.of(1, 'a')
|
|
93
106
|
* console.log(Tuple.append(t, true, 5))
|
|
94
107
|
* // => [1, 'a', true, 5]
|
|
108
|
+
* ```
|
|
95
109
|
*/
|
|
96
110
|
function append(tuple) {
|
|
97
111
|
var values = [];
|
|
@@ -107,10 +121,12 @@ var Tuple;
|
|
|
107
121
|
* @param tuple1 - the first Tuple
|
|
108
122
|
* @param tuple2 - the second Tuple
|
|
109
123
|
* @example
|
|
124
|
+
* ```ts
|
|
110
125
|
* const t1 = Tuple.of(1, 'a')
|
|
111
126
|
* const t2 = Tuple.of(true, 5)
|
|
112
127
|
* console.log(Tuple.concat(t1, t2))
|
|
113
128
|
* // => [1, 'a', true, 5]
|
|
129
|
+
* ```
|
|
114
130
|
*/
|
|
115
131
|
function concat(tuple1, tuple2) {
|
|
116
132
|
return tuple1.concat(tuple2);
|
|
@@ -120,9 +136,11 @@ var Tuple;
|
|
|
120
136
|
* Returns a Tuple containing all but the last element of the given `tuple`.
|
|
121
137
|
* @param tuple - the source tuple
|
|
122
138
|
* @example
|
|
139
|
+
* ```ts
|
|
123
140
|
* const t = Tuple.of(1, 'a', true)
|
|
124
141
|
* console.log(Tuple.init(t))
|
|
125
142
|
* // => [1, 'a']
|
|
143
|
+
* ```
|
|
126
144
|
*/
|
|
127
145
|
function init(tuple) {
|
|
128
146
|
return base_1.Arr.init(tuple);
|
|
@@ -132,9 +150,11 @@ var Tuple;
|
|
|
132
150
|
* Returns a Tuple containing all but the first element of the given `tuple`.
|
|
133
151
|
* @param tuple - the source tuple
|
|
134
152
|
* @example
|
|
153
|
+
* ```ts
|
|
135
154
|
* const t = Tuple.of(1, 'a', true)
|
|
136
155
|
* console.log(Tuple.tail(t))
|
|
137
156
|
* // => ['a', true]
|
|
157
|
+
* ```
|
|
138
158
|
*/
|
|
139
159
|
function tail(tuple) {
|
|
140
160
|
return base_1.Arr.tail(tuple);
|
package/dist/main/tuple.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../src/tuple.ts"],"names":[],"mappings":";;;;AAAA,oCAAkC;AAQlC,IAAiB,KAAK,
|
|
1
|
+
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../src/tuple.ts"],"names":[],"mappings":";;;;AAAA,oCAAkC;AAQlC,IAAiB,KAAK,CAgLrB;AA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CAAC,MAAM,CAAC,MAAM,CAAQ,CAAC;IACtC,CAAC;IALe,YAAM,SAKrB,CAAA;IAED;;;;;;;;;OASG;IACH,SAAgB,IAAI,CAClB,KAA+B;QAE/B,OAAO,UAAG,CAAC,IAAI,CAAC,KAAK,CAAQ,CAAC;IAChC,CAAC;IAJe,UAAI,OAInB,CAAA;IAED;;;;;;;;;OASG;IACH,SAAgB,IAAI,CAClB,KAA+B;QAE/B,OAAO,UAAG,CAAC,IAAI,CAAC,KAAK,CAAQ,CAAC;IAChC,CAAC;IAJe,UAAI,OAInB,CAAA;AACH,CAAC,EAhLgB,KAAK,GAAL,aAAK,KAAL,aAAK,QAgLrB"}
|
package/dist/module/index.js
CHANGED
|
@@ -1,2 +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
|
+
*/
|
|
1
8
|
export * from './internal';
|
|
2
9
|
//# sourceMappingURL=index.js.map
|
package/dist/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,YAAY,CAAC"}
|
package/dist/module/match.js
CHANGED
|
@@ -8,8 +8,10 @@ export var Match;
|
|
|
8
8
|
* @param value - the value to match
|
|
9
9
|
* @param matchers - one or more `Match` objects
|
|
10
10
|
* @example
|
|
11
|
+
* ```ts
|
|
11
12
|
* matchAll({ g: { h: 'abc' }})({ g: { h: 'a' }}) => false
|
|
12
13
|
* matchAll({ g: { h: 'abc' }})({ g: { h: v => v.length > 1 }}) => true
|
|
14
|
+
* ```
|
|
13
15
|
*/
|
|
14
16
|
function all(value) {
|
|
15
17
|
return (...matchers) => {
|
|
@@ -28,8 +30,10 @@ export var Match;
|
|
|
28
30
|
* @param value - the value to match
|
|
29
31
|
* @param matchers - one or more `Match` objects
|
|
30
32
|
* @example
|
|
33
|
+
* ```ts
|
|
31
34
|
* matchAny({ g: { h: 'abc' }})({ g: { h: 'a' }}, { g: { h: v => v.length < 2 }}) => false
|
|
32
35
|
* matchAny({ g: { h: 'abc' }})({ g: { h: 'a' }}, { g: { h: v => v.length > 1 }}) => true
|
|
36
|
+
* ```
|
|
33
37
|
*/
|
|
34
38
|
function any(value) {
|
|
35
39
|
return (...matchers) => {
|
|
@@ -49,6 +53,7 @@ export var Match;
|
|
|
49
53
|
* @typeparam T2 - the type to use for the Match, should be equal to T
|
|
50
54
|
* @param matches - at least one Match instance to perform on a given `value`
|
|
51
55
|
* @example
|
|
56
|
+
* ```ts
|
|
52
57
|
* type Person = { name: string, age: number }
|
|
53
58
|
* const m = Match.createAll<Person>({ age: v => v > 20 }, { name: v => v.length > 2 })
|
|
54
59
|
*
|
|
@@ -58,6 +63,7 @@ export var Match;
|
|
|
58
63
|
* // => true
|
|
59
64
|
* console.log(m({ name: 'a', age: 20 }))
|
|
60
65
|
* // => false
|
|
66
|
+
* ```
|
|
61
67
|
*/
|
|
62
68
|
function createAll(...matches) {
|
|
63
69
|
return (value) => Match.all(value)(...matches);
|
|
@@ -70,6 +76,7 @@ export var Match;
|
|
|
70
76
|
* @typeparam T2 - the type to use for the Match, should be equal to T
|
|
71
77
|
* @param matches - at least one Match instance to perform on a given `value`
|
|
72
78
|
* @example
|
|
79
|
+
* ```ts
|
|
73
80
|
* type Person = { name: string, age: number }
|
|
74
81
|
* const m = Match.createAny<Person>({ age: v => v > 20 }, { name: v => v.length > 2 })
|
|
75
82
|
*
|
|
@@ -81,6 +88,7 @@ export var Match;
|
|
|
81
88
|
* // => true
|
|
82
89
|
* console.log(m({ name: 'a', age: 10 }))
|
|
83
90
|
* // => false
|
|
91
|
+
* ```
|
|
84
92
|
*/
|
|
85
93
|
function createAny(...matches) {
|
|
86
94
|
return (value) => Match.any(value)(...matches);
|
package/dist/module/match.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../src/match.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAa,OAAO,EAAE,MAAM,YAAY,CAAC;AAgBhD,MAAM,KAAW,KAAK,
|
|
1
|
+
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../src/match.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAa,OAAO,EAAE,MAAM,YAAY,CAAC;AAgBhD,MAAM,KAAW,KAAK,CAgJrB;AAhJD,WAAiB,KAAK;IA+CpB;;;;;;;;;;OAUG;IACH,SAAgB,GAAG,CAAI,KAAQ;QAC7B,OAAO,CAAC,GAAG,QAAQ,EAAW,EAAE;YAC9B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;gBAC9B,IAAI,CAAC,WAAW,CAAgB,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE;oBAC7D,OAAO,KAAK,CAAC;iBACd;aACF;YAED,OAAO,IAAI,CAAC;QACd,CAAC,CAAC;IACJ,CAAC;IAVe,SAAG,MAUlB,CAAA;IAED;;;;;;;;;;OAUG;IACH,SAAgB,GAAG,CAAI,KAAQ;QAC7B,OAAO,CAAC,GAAG,QAAQ,EAAW,EAAE;YAC9B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;gBAC9B,IAAI,WAAW,CAAgB,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE;oBAC5D,OAAO,IAAI,CAAC;iBACb;aACF;YAED,OAAO,KAAK,CAAC;QACf,CAAC,CA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AAE,UAAU,CAAC,sBAAsB,EAAE,CAAC;IAErE,IAAI,IAAI,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAEnC,IAAI,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;QAC9B,OAAO,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,KAAK,CAAC;KAC5C;IAED,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAE1C,wBAAwB;IACxB,IAAI,CAAC,YAAY,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE;QAClD,OAAQ,OAAe,KAAK,KAAK,CAAC;KACnC;IAED,KAAK,MAAM,GAAG,IAAI,OAAc,EAAE;QAChC,IAAI,CAAC,CAAC,GAAG,IAAI,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAElC,MAAM,QAAQ,GAAI,OAAe,CAAC,GAAG,CAAC,CAAC;QAEvC,IAAI,SAAS,KAAK,QAAQ,EAAE;YAC1B,UAAU,CAAC,sBAAsB,CAC/B,gHAAgH,CACjH,CAAC;SACH;QAED,MAAM,MAAM,GAAG,WAAW,CACvB,KAAa,CAAC,GAAG,CAAC,EACnB,QAAQ,EACR,KAAK,EACL,IAAI,CACL,CAAC;QACF,IAAI,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;KAC3B;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/module/patch.js
CHANGED
|
@@ -7,12 +7,14 @@ import { Literal } from './internal';
|
|
|
7
7
|
* @param value - the value to update
|
|
8
8
|
* @param patches - one or more `Patch` objects indicating modifications to the value
|
|
9
9
|
* @example
|
|
10
|
+
* ```ts
|
|
10
11
|
* patch({ g: { h: 5 }})({ g: { h: 6 }}) // => { g: { h: 6 }}
|
|
11
12
|
* patch({ g: { h: 5 }})({ g: { h: v => v + 1 }}) // => { g: { h: 6 }}
|
|
12
13
|
* patch({ g: { h: 5 }})({ g: { h: 1 }}, { g: { h: v => v + 1 }})
|
|
13
14
|
* // => { g: { h: 2 }}
|
|
14
15
|
* patch({ a: 1, b: 3 })({ a: (v, p) => v * p.b, (v, p) => v + p.a })
|
|
15
16
|
* // => { a: 3, b: 4 }
|
|
17
|
+
* ```
|
|
16
18
|
*/
|
|
17
19
|
export function patch(value) {
|
|
18
20
|
return function (...patches) {
|
|
@@ -33,9 +35,11 @@ export var Patch;
|
|
|
33
35
|
* @typeparam T2 - the type the Patch is done for, should be equal to T
|
|
34
36
|
* @param patches - the patches to apply to a given object
|
|
35
37
|
* @example
|
|
38
|
+
* ```ts
|
|
36
39
|
* const r = Patch.create<{ a: number, b: number }>({ b: v => v + 1 })({ a: 1, b: 2})
|
|
37
40
|
* console.log(r)
|
|
38
41
|
* // => { a: 1, b: 3 }
|
|
42
|
+
* ```
|
|
39
43
|
*/
|
|
40
44
|
function create(...patches) {
|
|
41
45
|
return (value) => patch(value)(...patches);
|
package/dist/module/patch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAgBrC
|
|
1
|
+
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAgBrC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,KAAK,CAAI,KAAQ;IAC/B,OAAO,UAAU,GAAG,OAAO;QACzB,IAAI,MAAM,GAAG,KAAK,CAAC;QAEnB,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;YACvB,MAAM,GAAG,WAAW,CAClB,MAAa,EACb,CAAQ,EACR,MAAa,EACb,MAAa,CACd,CAAC;SACH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AK,UAAU;YAAE,SAAS;QAEhE,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QAE5B,IAAI,SAAS,KAAK,QAAQ,EAAE;YAC1B,UAAU,CAAC,sBAAsB,CAC/B,gHAAgH,CACjH,CAAC;SACH;QAED,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,EAAE,QAAe,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAErE,IAAI,QAAQ,KAAK,QAAQ,EAAE;YACzB,OAAO,GAAG,IAAI,CAAC;YACf,KAAK,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;SACvB;KACF;IAED,IAAI,OAAO;QAAE,OAAO,KAAK,CAAC;IAE1B,OAAO,KAAK,CAAC;AACf,CAAC"}
|
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,WAavB,CAAA;IAED;;;;;;;;;OASG;IACH,SAAgB,QAAQ,CACtB,MAAS,EACT,IAAO,EACP,KAAwB;QAExB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9B,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,EAAG,CAAC;QAE1B,MAAM,MAAM,qBAAQ,MAAM,CAAE,CAAC;QAE7B,IAAI,OAAO,GAAQ,MAAM,CAAC;QAE1B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,OAAO,CAAC,IAAI,CAAC,qBAAQ,OAAO,CAAC,IAAI,CAAC,CAAE,CAAC;YACrC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;SACzB;QAED,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAE/B,IAAI,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC;YAAE,OAAO,MAAM,CAAC;QAE9C,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAEtB,OAAO,MAAM,CAAC;IAChB,CAAC;IAxBe,aAAQ,WAwBvB,CAAA;IAED;;;;;;;;;;;OAWG;IACH,SAAgB,UAAU,CACxB,MAAS,EACT,IAAO,EACP,GAAG,OAAuC;QAE1C,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC1C,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC;QAE1C,IAAI,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC;YAAE,OAAO,MAAM,CAAC;QAE9C,OAAO,IAAI,CAAC,QAAQ,CAAW,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IACzD,CAAC;IAXe,eAAU,aAWzB,CAAA;AACH,CAAC,EAjHgB,IAAI,KAAJ,IAAI,QAiHpB"}
|
package/dist/module/tuple.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,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IALe,cAAQ,WAKvB,CAAA;IAED;;;;;;;;;OASG;IACH,SAAgB,KAAK,CAAyB,KAAQ;QACpD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAFe,WAAK,QAEpB,CAAA;IAED;;;;;;;;;OASG;IACH,SAAgB,MAAM,CAAyB,KAAQ;QACrD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAFe,YAAM,SAErB,CAAA;IAED;;;;;;;;;OASG;IACH,SAAgB,IAAI,CAClB,KAAyB;QAEzB,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAQ,CAAC;IACxC,CAAC;IAJe,UAAI,OAInB,CAAA;IAED;;;;;;;;;;;;OAYG;IACH,SAAgB,QAAQ,CACtB,KAAQ,EACR,KAAQ,EACR,OAAqB;QAErB,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,KAAe,EAAE,OAAO,CAAM,CAAC;IAC1D,CAAC;IANe,cAAQ,WAMvB,CAAA;IAED;;;;;;;;;;OAUG;IACH,SAAgB,MAAM,CAGpB,KAAQ,EAAE,GAAG,MAAS;QACtB,OAAO,CAAC,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC,CAAC;IAC/B,CAAC;IALe,YAAM,SAKrB,CAAA;IAED;;;;;;;;;;;;OAYG;IACH,SAAgB,MAAM,CACpB,MAAU,EACV,MAAU;QAEV,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAQ,CAAC;IACtC,CAAC;IALe,YAAM,SAKrB,CAAA;IAED;;;;;;;;;OASG;IACH,SAAgB,IAAI,CAClB,KAA+B;QAE/B,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,CAAQ,CAAC;IAChC,CAAC;IAJe,UAAI,OAInB,CAAA;IAED;;;;;;;;;OASG;IACH,SAAgB,IAAI,CAClB,KAA+B;QAE/B,OAAO,GAAG,CAAC,IAAI,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.0",
|
|
4
4
|
"description": "Tools to use handle plain JS objects as immutable objects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"immutable",
|
|
@@ -40,14 +40,15 @@
|
|
|
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
|
-
"format:base": "prettier \"{!CHANGELOG.md}
|
|
51
|
+
"format:base": "prettier \"{!CHANGELOG.md}|**/**/*.{ts,tsx,js,json,md}\"",
|
|
51
52
|
"format:check": "yarn format:base --check",
|
|
52
53
|
"lint": "eslint src",
|
|
53
54
|
"test": "jest",
|
|
@@ -56,15 +57,16 @@
|
|
|
56
57
|
},
|
|
57
58
|
"sideEffects": false,
|
|
58
59
|
"dependencies": {
|
|
59
|
-
"@rimbu/base": "^0.
|
|
60
|
-
"@rimbu/common": "^0.
|
|
60
|
+
"@rimbu/base": "^0.8.0",
|
|
61
|
+
"@rimbu/common": "^0.9.0",
|
|
61
62
|
"tslib": "^2.3.1"
|
|
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": "7c60bf40f3479524fa9d603a75b33f914d2feb28"
|
|
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,
|
package/src/tuple.ts
CHANGED
|
@@ -21,8 +21,10 @@ export namespace Tuple {
|
|
|
21
21
|
* Convenience method to type Tuple types
|
|
22
22
|
* @param values - the values of the tuple
|
|
23
23
|
* @example
|
|
24
|
+
* ```ts
|
|
24
25
|
* const t = Tuple.of(1, 'a', true)
|
|
25
26
|
* // type of t => Tuple<[number, string, boolean]>
|
|
27
|
+
* ```
|
|
26
28
|
*/
|
|
27
29
|
export function of<T extends Tuple.NonEmptySource>(...values: T): Tuple<T> {
|
|
28
30
|
return values as any;
|
|
@@ -33,9 +35,11 @@ export namespace Tuple {
|
|
|
33
35
|
* @param tuple - the tuple to get the item from
|
|
34
36
|
* @param index - the index in of the tuple element
|
|
35
37
|
* @example
|
|
38
|
+
* ```ts
|
|
36
39
|
* const t = Tuple.of(1, 'a', true)
|
|
37
40
|
* console.log(Tuple.getIndex(t, 1))
|
|
38
41
|
* // => 'a'
|
|
42
|
+
* ```
|
|
39
43
|
*/
|
|
40
44
|
export function getIndex<T extends Tuple.Source, K extends keyof T = keyof T>(
|
|
41
45
|
tuple: T,
|
|
@@ -48,9 +52,11 @@ export namespace Tuple {
|
|
|
48
52
|
* Returns the first element of a Tuple.
|
|
49
53
|
* @param tuple - the source tuple
|
|
50
54
|
* @example
|
|
55
|
+
* ```ts
|
|
51
56
|
* const t = Tuple.of(1, 'a', true)
|
|
52
57
|
* console.log(Tuple.first(t))
|
|
53
58
|
* // => 1
|
|
59
|
+
* ```
|
|
54
60
|
*/
|
|
55
61
|
export function first<T extends Tuple.Source>(tuple: T): T[0] {
|
|
56
62
|
return tuple[0];
|
|
@@ -60,9 +66,11 @@ export namespace Tuple {
|
|
|
60
66
|
* Returns the second element of a Tuple.
|
|
61
67
|
* @param tuple - the source tuple
|
|
62
68
|
* @example
|
|
69
|
+
* ```ts
|
|
63
70
|
* const t = Tuple.of(1, 'a', true)
|
|
64
71
|
* console.log(Tuple.second(t))
|
|
65
72
|
* // => 'a'
|
|
73
|
+
* ```
|
|
66
74
|
*/
|
|
67
75
|
export function second<T extends Tuple.Source>(tuple: T): T[1] {
|
|
68
76
|
return tuple[1];
|
|
@@ -72,9 +80,11 @@ export namespace Tuple {
|
|
|
72
80
|
* Returns the last element of a Tuple.
|
|
73
81
|
* @param tuple - the source tuple
|
|
74
82
|
* @example
|
|
83
|
+
* ```ts
|
|
75
84
|
* const t = Tuple.of(1, 'a', true)
|
|
76
85
|
* console.log(Tuple.last(t))
|
|
77
86
|
* // => true
|
|
87
|
+
* ```
|
|
78
88
|
*/
|
|
79
89
|
export function last<T extends readonly unknown[], R>(
|
|
80
90
|
tuple: readonly [...T, R]
|
|
@@ -89,9 +99,11 @@ export namespace Tuple {
|
|
|
89
99
|
* @param index - the index in the tuple
|
|
90
100
|
* @param updater - the updater for the value
|
|
91
101
|
* @example
|
|
102
|
+
* ```ts
|
|
92
103
|
* const t = Tuple.of(1, 'a', true)
|
|
93
104
|
* console.log(Tuple.updateAt(t, 1, 'b'))
|
|
94
105
|
* // => [1, 'b', true]
|
|
106
|
+
* ```
|
|
95
107
|
*/
|
|
96
108
|
export function updateAt<T extends Tuple.Source, K extends keyof T = keyof T>(
|
|
97
109
|
tuple: T,
|
|
@@ -106,9 +118,11 @@ export namespace Tuple {
|
|
|
106
118
|
* @param tuple - the source tuple
|
|
107
119
|
* @param values - the values to append
|
|
108
120
|
* @example
|
|
121
|
+
* ```ts
|
|
109
122
|
* const t = Tuple.of(1, 'a')
|
|
110
123
|
* console.log(Tuple.append(t, true, 5))
|
|
111
124
|
* // => [1, 'a', true, 5]
|
|
125
|
+
* ```
|
|
112
126
|
*/
|
|
113
127
|
export function append<
|
|
114
128
|
T extends Tuple.Source,
|
|
@@ -123,10 +137,12 @@ export namespace Tuple {
|
|
|
123
137
|
* @param tuple1 - the first Tuple
|
|
124
138
|
* @param tuple2 - the second Tuple
|
|
125
139
|
* @example
|
|
140
|
+
* ```ts
|
|
126
141
|
* const t1 = Tuple.of(1, 'a')
|
|
127
142
|
* const t2 = Tuple.of(true, 5)
|
|
128
143
|
* console.log(Tuple.concat(t1, t2))
|
|
129
144
|
* // => [1, 'a', true, 5]
|
|
145
|
+
* ```
|
|
130
146
|
*/
|
|
131
147
|
export function concat<T1 extends Tuple.Source, T2 extends Tuple.Source>(
|
|
132
148
|
tuple1: T1,
|
|
@@ -139,9 +155,11 @@ export namespace Tuple {
|
|
|
139
155
|
* Returns a Tuple containing all but the last element of the given `tuple`.
|
|
140
156
|
* @param tuple - the source tuple
|
|
141
157
|
* @example
|
|
158
|
+
* ```ts
|
|
142
159
|
* const t = Tuple.of(1, 'a', true)
|
|
143
160
|
* console.log(Tuple.init(t))
|
|
144
161
|
* // => [1, 'a']
|
|
162
|
+
* ```
|
|
145
163
|
*/
|
|
146
164
|
export function init<T extends readonly unknown[]>(
|
|
147
165
|
tuple: readonly [...T, unknown]
|
|
@@ -153,9 +171,11 @@ export namespace Tuple {
|
|
|
153
171
|
* Returns a Tuple containing all but the first element of the given `tuple`.
|
|
154
172
|
* @param tuple - the source tuple
|
|
155
173
|
* @example
|
|
174
|
+
* ```ts
|
|
156
175
|
* const t = Tuple.of(1, 'a', true)
|
|
157
176
|
* console.log(Tuple.tail(t))
|
|
158
177
|
* // => ['a', true]
|
|
178
|
+
* ```
|
|
159
179
|
*/
|
|
160
180
|
export function tail<T extends readonly [...unknown[]]>(
|
|
161
181
|
tuple: readonly [unknown, ...T]
|