@rimbu/deep 0.9.1 → 0.10.1
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 +27 -16
- package/dist/main/index.js +12 -3
- package/dist/main/index.js.map +1 -1
- package/dist/main/internal.js +4 -6
- package/dist/main/internal.js.map +1 -1
- package/dist/main/match.js +197 -132
- package/dist/main/match.js.map +1 -1
- package/dist/main/patch.js +125 -106
- package/dist/main/patch.js.map +1 -1
- package/dist/main/path.js +16 -41
- package/dist/main/path.js.map +1 -1
- package/dist/main/protected.js +24 -0
- package/dist/main/protected.js.map +1 -0
- package/dist/main/tuple.js +1 -1
- package/dist/main/tuple.js.map +1 -1
- package/dist/module/index.js +3 -2
- package/dist/module/index.js.map +1 -1
- package/dist/module/internal.js +2 -4
- package/dist/module/internal.js.map +1 -1
- package/dist/module/match.js +180 -97
- package/dist/module/match.js.map +1 -1
- package/dist/module/patch.js +113 -87
- package/dist/module/patch.js.map +1 -1
- package/dist/module/path.js +15 -36
- package/dist/module/path.js.map +1 -1
- package/dist/module/protected.js +20 -0
- package/dist/module/protected.js.map +1 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/internal.d.ts +2 -4
- package/dist/types/match.d.ts +93 -80
- package/dist/types/patch.d.ts +64 -61
- package/dist/types/path.d.ts +9 -20
- package/dist/types/protected.d.ts +34 -0
- package/package.json +5 -5
- package/src/index.ts +12 -2
- package/src/internal.ts +3 -4
- package/src/match.ts +254 -163
- package/src/patch.ts +204 -147
- package/src/path.ts +20 -44
- package/src/protected.ts +46 -0
- package/dist/main/immutable.js +0 -12
- package/dist/main/immutable.js.map +0 -1
- package/dist/main/literal.js +0 -41
- package/dist/main/literal.js.map +0 -1
- package/dist/module/immutable.js +0 -8
- package/dist/module/immutable.js.map +0 -1
- package/dist/module/literal.js +0 -37
- package/dist/module/literal.js.map +0 -1
- package/dist/types/immutable.d.ts +0 -13
- package/dist/types/literal.d.ts +0 -48
- package/src/immutable.ts +0 -21
- package/src/literal.ts +0 -70
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
Offers tools to use handle plain JS objects as immutable objects. The [`Patch` object](https://rimbu.org/docs/deep/patch) allows convenient immutable modification of simple objects. The [`Match` object](https://rimbu.org/docs/deep/match) allows easy matching on plain objects. The [`Path` object](https://rimbu.org/docs/deep/path) allows easy querying of nested values. The [`Immutable` type](https://rimbu.org/docs/deep/immutable) makes it easy to create plain objects that that have compile-time protection against mutation. The [`Tuple` type](https://rimbu.org/docs/deep/tuple) is a utility to have similar functionality as `as const` but less strict.
|
|
8
8
|
|
|
9
|
-
For complete documentation please visit the [Immutable Objects overview](https://rimbu.org/docs/deep/overview) in the _[Rimbu Docs](https://rimbu.org)_.
|
|
9
|
+
For complete documentation please visit the [Immutable Objects overview](https://rimbu.org/docs/deep/overview) in the _[Rimbu Docs](https://rimbu.org)_, or directly see the _[Rimbu Deep API Docs](https://rimbu.org/api/rimbu/deep)_.
|
|
10
10
|
|
|
11
11
|
Or [Try Out Rimbu](https://codesandbox.io/s/github/vitoke/rimbu-sandbox/tree/main?previewwindow=console&view=split&editorsize=65&moduleview=1&module=/src/index.ts) in CodeSandBox.
|
|
12
12
|
|
|
@@ -26,29 +26,40 @@ or
|
|
|
26
26
|
|
|
27
27
|
### Deno
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
For Deno, the following approach is recommended:
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
> export * from 'https://deno.land/x/rimbu/deep/mod.ts';
|
|
33
|
-
> ```
|
|
31
|
+
In the root folder of your project, create or edit a file called `import_map.json` with the following contents (where you should replace `x.y.z` with the desired version of Rimbu):
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"imports": {
|
|
36
|
+
"@rimbu/": "https://deno.land/x/rimbu@x.y.z/"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Note: The trailing slashes are important!**
|
|
42
|
+
|
|
43
|
+
In this way you can use relative imports from Rimbu in your code, like so:
|
|
36
44
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
```ts
|
|
46
|
+
import { List } from '@rimbu/core/mod.ts';
|
|
47
|
+
import { HashMap } from '@rimbu/hashed/mod.ts';
|
|
48
|
+
```
|
|
40
49
|
|
|
41
|
-
|
|
50
|
+
Note that for sub-packages, due to conversion limitations it is needed to import the `index.ts` instead of `mod.ts`, like so:
|
|
42
51
|
|
|
43
52
|
```ts
|
|
44
|
-
import {
|
|
53
|
+
import { HashMap } from '@rimbu/hashed/map/index.ts';
|
|
45
54
|
```
|
|
46
55
|
|
|
47
|
-
|
|
56
|
+
To run your script (let's assume the entry point is in `src/main.ts`):
|
|
57
|
+
|
|
58
|
+
`deno run --import-map import_map.json src/main.ts`
|
|
48
59
|
|
|
49
|
-
|
|
60
|
+
Because Rimbu uses advanced types, this may slow down the type checking part when running your code. If you're able to rely on your code editor to provide type errors, you can skip the Deno type check using the `--no-check` flag:
|
|
50
61
|
|
|
51
|
-
|
|
62
|
+
`deno run --import-map import_map.json --no-check src/main.ts`
|
|
52
63
|
|
|
53
64
|
## Usage
|
|
54
65
|
|
|
@@ -73,11 +84,11 @@ console.log(
|
|
|
73
84
|
|
|
74
85
|
## Contributing
|
|
75
86
|
|
|
76
|
-
Feel very welcome to contribute to further improve Rimbu. Please read our [Contributing guide](
|
|
87
|
+
Feel very welcome to contribute to further improve Rimbu. Please read our [Contributing guide](https://github.com/rimbu-org/rimbu/blob/main/CONTRIBUTING.md).
|
|
77
88
|
|
|
78
89
|
## Contributors
|
|
79
90
|
|
|
80
|
-
<img src = "https://contrib.rocks/image?repo=
|
|
91
|
+
<img src = "https://contrib.rocks/image?repo=rimbu-org/rimbu"/>
|
|
81
92
|
|
|
82
93
|
Made with [contributors-img](https://contrib.rocks).
|
|
83
94
|
|
package/dist/main/index.js
CHANGED
|
@@ -2,11 +2,20 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @packageDocumentation
|
|
4
4
|
*
|
|
5
|
-
* The `@rimbu/deep` package provides utilities to patch and match plain JavaScript objects
|
|
5
|
+
* The `@rimbu/deep` package provides utilities to patch and match plain JavaScript objects.<br/>
|
|
6
6
|
* <br/>
|
|
7
7
|
* See the [Rimbu docs Deep overview page](/docs/deep/overview) for more information.
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
exports.Tuple = exports.Protected = exports.Path = exports.Match = exports.match = exports.Patch = exports.patchNested = exports.patch = void 0;
|
|
11
|
+
var internal_1 = require("./internal");
|
|
12
|
+
Object.defineProperty(exports, "patch", { enumerable: true, get: function () { return internal_1.patch; } });
|
|
13
|
+
Object.defineProperty(exports, "patchNested", { enumerable: true, get: function () { return internal_1.patchNested; } });
|
|
14
|
+
Object.defineProperty(exports, "Patch", { enumerable: true, get: function () { return internal_1.Patch; } });
|
|
15
|
+
Object.defineProperty(exports, "match", { enumerable: true, get: function () { return internal_1.match; } });
|
|
16
|
+
Object.defineProperty(exports, "Match", { enumerable: true, get: function () { return internal_1.Match; } });
|
|
17
|
+
Object.defineProperty(exports, "Path", { enumerable: true, get: function () { return internal_1.Path; } });
|
|
18
|
+
Object.defineProperty(exports, "Protected", { enumerable: true, get: function () { return internal_1.Protected; } });
|
|
19
|
+
var tuple_1 = require("./tuple");
|
|
20
|
+
Object.defineProperty(exports, "Tuple", { enumerable: true, get: function () { return tuple_1.Tuple; } });
|
|
12
21
|
//# sourceMappingURL=index.js.map
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,uCAQoB;AAPlB,iGAAA,KAAK,OAAA;AACL,uGAAA,WAAW,OAAA;AACX,iGAAA,KAAK,OAAA;AACL,iGAAA,KAAK,OAAA;AACL,iGAAA,KAAK,OAAA;AACL,gGAAA,IAAI,OAAA;AACJ,qGAAA,SAAS,OAAA;AAGX,iCAAgC;AAAvB,8FAAA,KAAK,OAAA"}
|
package/dist/main/internal.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
(0, tslib_1.__exportStar)(require("./path"), exports);
|
|
9
|
-
(0, tslib_1.__exportStar)(require("./patch"), exports);
|
|
4
|
+
tslib_1.__exportStar(require("./protected"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./match"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./patch"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./path"), exports);
|
|
10
8
|
//# sourceMappingURL=internal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAE5B,kDAAwB;AACxB,kDAAwB;AACxB,iDAAuB"}
|
package/dist/main/match.js
CHANGED
|
@@ -1,181 +1,246 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Match = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
3
|
+
exports.match = exports.Match = void 0;
|
|
5
4
|
var base_1 = require("@rimbu/base");
|
|
6
|
-
var internal_1 = require("./internal");
|
|
7
5
|
var Match;
|
|
8
6
|
(function (Match) {
|
|
9
7
|
/**
|
|
10
|
-
* Returns true if
|
|
11
|
-
* @typeparam T - the type of
|
|
12
|
-
* @
|
|
13
|
-
* @
|
|
8
|
+
* Returns a matcher that returns true if every given `matchItem` matches the given value.
|
|
9
|
+
* @typeparam T - the type of value to match
|
|
10
|
+
* @typeparam R - the root object type
|
|
11
|
+
* @typeparam Q - a utility type for the matcher
|
|
12
|
+
* @param matchItems - the match specifications to test
|
|
14
13
|
* @example
|
|
15
14
|
* ```ts
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* const input = { a: 1, b: { c: true, d: 'a' } }
|
|
16
|
+
* match(input, Match.every({ a: 1, { c: true } } )) // => true
|
|
17
|
+
* match(input, Match.every({ a: 1, { c: false } } )) // => false
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
for (var matchers_1 = (0, tslib_1.__values)(matchers), matchers_1_1 = matchers_1.next(); !matchers_1_1.done; matchers_1_1 = matchers_1.next()) {
|
|
29
|
-
var matcher = matchers_1_1.value;
|
|
30
|
-
if (!matchSingle(value, matcher, value, value)) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
36
|
-
finally {
|
|
37
|
-
try {
|
|
38
|
-
if (matchers_1_1 && !matchers_1_1.done && (_a = matchers_1.return)) _a.call(matchers_1);
|
|
39
|
-
}
|
|
40
|
-
finally { if (e_1) throw e_1.error; }
|
|
41
|
-
}
|
|
42
|
-
return true;
|
|
43
|
-
};
|
|
20
|
+
function every() {
|
|
21
|
+
var matchItems = [];
|
|
22
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
23
|
+
matchItems[_i] = arguments[_i];
|
|
24
|
+
}
|
|
25
|
+
return new Every(matchItems);
|
|
44
26
|
}
|
|
45
|
-
Match.
|
|
27
|
+
Match.every = every;
|
|
46
28
|
/**
|
|
47
|
-
* Returns true if
|
|
48
|
-
* @typeparam T - the type of
|
|
49
|
-
* @
|
|
50
|
-
* @
|
|
29
|
+
* Returns a matcher that returns true if at least one of given `matchItem` matches the given value.
|
|
30
|
+
* @typeparam T - the type of value to match
|
|
31
|
+
* @typeparam R - the root object type
|
|
32
|
+
* @typeparam Q - a utility type for the matcher
|
|
33
|
+
* @param matchItems - the match specifications to test
|
|
51
34
|
* @example
|
|
52
35
|
* ```ts
|
|
53
|
-
*
|
|
54
|
-
*
|
|
36
|
+
* const input = { a: 1, b: { c: true, d: 'a' } }
|
|
37
|
+
* match(input, Match.some({ a: 5, { c: true } } )) // => true
|
|
38
|
+
* match(input, Match.some({ a: 5, { c: false } } )) // => false
|
|
55
39
|
* ```
|
|
56
40
|
*/
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
for (var matchers_2 = (0, tslib_1.__values)(matchers), matchers_2_1 = matchers_2.next(); !matchers_2_1.done; matchers_2_1 = matchers_2.next()) {
|
|
66
|
-
var matcher = matchers_2_1.value;
|
|
67
|
-
if (matchSingle(value, matcher, value, value)) {
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
73
|
-
finally {
|
|
74
|
-
try {
|
|
75
|
-
if (matchers_2_1 && !matchers_2_1.done && (_a = matchers_2.return)) _a.call(matchers_2);
|
|
76
|
-
}
|
|
77
|
-
finally { if (e_2) throw e_2.error; }
|
|
78
|
-
}
|
|
79
|
-
return false;
|
|
80
|
-
};
|
|
41
|
+
function some() {
|
|
42
|
+
var matchItems = [];
|
|
43
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
44
|
+
matchItems[_i] = arguments[_i];
|
|
45
|
+
}
|
|
46
|
+
return new Some(matchItems);
|
|
81
47
|
}
|
|
82
|
-
Match.
|
|
48
|
+
Match.some = some;
|
|
83
49
|
/**
|
|
84
|
-
* Returns a
|
|
85
|
-
*
|
|
86
|
-
* @typeparam
|
|
87
|
-
* @typeparam
|
|
88
|
-
* @param
|
|
50
|
+
* Returns a matcher that returns true if none of given `matchItem` matches the given value.
|
|
51
|
+
* @typeparam T - the type of value to match
|
|
52
|
+
* @typeparam R - the root object type
|
|
53
|
+
* @typeparam Q - a utility type for the matcher
|
|
54
|
+
* @param matchItems - the match specifications to test
|
|
89
55
|
* @example
|
|
90
56
|
* ```ts
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* console.log(m({ name: 'abc', age: 10 }))
|
|
95
|
-
* // => false
|
|
96
|
-
* console.log(m({ name: 'abc', age: 20 }))
|
|
97
|
-
* // => true
|
|
98
|
-
* console.log(m({ name: 'a', age: 20 }))
|
|
99
|
-
* // => false
|
|
57
|
+
* const input = { a: 1, b: { c: true, d: 'a' } }
|
|
58
|
+
* match(input, Match.none({ a: 5, { c: true } } )) // => false
|
|
59
|
+
* match(input, Match.none({ a: 5, { c: false } } )) // => true
|
|
100
60
|
* ```
|
|
101
61
|
*/
|
|
102
|
-
function
|
|
103
|
-
var
|
|
62
|
+
function none() {
|
|
63
|
+
var matchItems = [];
|
|
104
64
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
105
|
-
|
|
65
|
+
matchItems[_i] = arguments[_i];
|
|
106
66
|
}
|
|
107
|
-
return
|
|
67
|
+
return new None(matchItems);
|
|
108
68
|
}
|
|
109
|
-
Match.
|
|
69
|
+
Match.none = none;
|
|
110
70
|
/**
|
|
111
|
-
* Returns a
|
|
112
|
-
*
|
|
113
|
-
* @typeparam
|
|
114
|
-
* @typeparam
|
|
115
|
-
* @param
|
|
71
|
+
* Returns a matcher that returns true if exactly one of given `matchItem` matches the given value.
|
|
72
|
+
* @typeparam T - the type of value to match
|
|
73
|
+
* @typeparam R - the root object type
|
|
74
|
+
* @typeparam Q - a utility type for the matcher
|
|
75
|
+
* @param matchItems - the match specifications to test
|
|
116
76
|
* @example
|
|
117
77
|
* ```ts
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* console.log(m({ name: 'abc', age: 10 }))
|
|
122
|
-
* // => true
|
|
123
|
-
* console.log(m({ name: 'abc', age: 20 }))
|
|
124
|
-
* // => true
|
|
125
|
-
* console.log(m({ name: 'a', age: 20 }))
|
|
126
|
-
* // => true
|
|
127
|
-
* console.log(m({ name: 'a', age: 10 }))
|
|
128
|
-
* // => false
|
|
78
|
+
* const input = { a: 1, b: { c: true, d: 'a' } }
|
|
79
|
+
* match(input, Match.single({ a: 1, { c: true } } )) // => false
|
|
80
|
+
* match(input, Match.single({ a: 1, { c: false } } )) // => true
|
|
129
81
|
* ```
|
|
130
82
|
*/
|
|
131
|
-
function
|
|
132
|
-
var
|
|
83
|
+
function single() {
|
|
84
|
+
var matchItems = [];
|
|
133
85
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
134
|
-
|
|
86
|
+
matchItems[_i] = arguments[_i];
|
|
135
87
|
}
|
|
136
|
-
return
|
|
88
|
+
return new Single(matchItems);
|
|
137
89
|
}
|
|
138
|
-
Match.
|
|
90
|
+
Match.single = single;
|
|
139
91
|
})(Match = exports.Match || (exports.Match = {}));
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
92
|
+
var Every = /** @class */ (function () {
|
|
93
|
+
function Every(matchItems) {
|
|
94
|
+
this.matchItems = matchItems;
|
|
95
|
+
}
|
|
96
|
+
return Every;
|
|
97
|
+
}());
|
|
98
|
+
var Some = /** @class */ (function () {
|
|
99
|
+
function Some(matchItems) {
|
|
100
|
+
this.matchItems = matchItems;
|
|
101
|
+
}
|
|
102
|
+
return Some;
|
|
103
|
+
}());
|
|
104
|
+
var None = /** @class */ (function () {
|
|
105
|
+
function None(matchItems) {
|
|
106
|
+
this.matchItems = matchItems;
|
|
107
|
+
}
|
|
108
|
+
return None;
|
|
109
|
+
}());
|
|
110
|
+
var Single = /** @class */ (function () {
|
|
111
|
+
function Single(matchItems) {
|
|
112
|
+
this.matchItems = matchItems;
|
|
143
113
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
114
|
+
return Single;
|
|
115
|
+
}());
|
|
116
|
+
/**
|
|
117
|
+
* Returns true if the given `value` object matches the given `matcher`, false otherwise.
|
|
118
|
+
* @typeparam T - the input value type
|
|
119
|
+
* @param value - the value to match (should be a plain object)
|
|
120
|
+
* @param matcher - a matcher object or a function taking the matcher API and returning a match object
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* const input = { a: 1, b: { c: true, d: 'a' } }
|
|
124
|
+
* match(input, { a: 1 }) // => true
|
|
125
|
+
* match(input, { a: 2 }) // => false
|
|
126
|
+
* match(input, { a: v => v > 10 }) // => false
|
|
127
|
+
* match(input, { b: { c: true }}) // => true
|
|
128
|
+
* match(input, ({ every }) => every({ a: v => v > 0 }, { b: { c: true } } )) // => true
|
|
129
|
+
* match(input, { b: { c: (v, parent, root) => v && parent.d.length > 0 && root.a > 0 } })
|
|
130
|
+
* // => true
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
function match(value, matcher) {
|
|
134
|
+
if (matcher instanceof Function) {
|
|
135
|
+
return matchOptions(value, value, matcher(Match));
|
|
136
|
+
}
|
|
137
|
+
return matchOptions(value, value, matcher);
|
|
138
|
+
}
|
|
139
|
+
exports.match = match;
|
|
140
|
+
function matchOptions(value, root, matcher) {
|
|
141
|
+
if (matcher instanceof Every) {
|
|
142
|
+
var i = -1;
|
|
143
|
+
var matchItems = matcher.matchItems;
|
|
144
|
+
var len = matchItems.length;
|
|
145
|
+
while (++i < len) {
|
|
146
|
+
if (!matchOptions(value, root, matchItems[i])) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
147
149
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
if (matcher instanceof Some) {
|
|
153
|
+
var i = -1;
|
|
154
|
+
var matchItems = matcher.matchItems;
|
|
155
|
+
var len = matchItems.length;
|
|
156
|
+
while (++i < len) {
|
|
157
|
+
if (matchOptions(value, root, matchItems[i])) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
150
160
|
}
|
|
151
|
-
return
|
|
161
|
+
return false;
|
|
152
162
|
}
|
|
153
|
-
if (
|
|
154
|
-
|
|
163
|
+
if (matcher instanceof None) {
|
|
164
|
+
var i = -1;
|
|
165
|
+
var matchItems = matcher.matchItems;
|
|
166
|
+
var len = matchItems.length;
|
|
167
|
+
while (++i < len) {
|
|
168
|
+
if (matchOptions(value, root, matchItems[i])) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return true;
|
|
155
173
|
}
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
174
|
+
if (matcher instanceof Single) {
|
|
175
|
+
var i = -1;
|
|
176
|
+
var matchItems = matcher.matchItems;
|
|
177
|
+
var len = matchItems.length;
|
|
178
|
+
var matched = false;
|
|
179
|
+
while (++i < len) {
|
|
180
|
+
if (matchOptions(value, root, matchItems[i])) {
|
|
181
|
+
if (matched) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
matched = true;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return matched;
|
|
188
|
+
}
|
|
189
|
+
if ((0, base_1.isPlainObj)(matcher)) {
|
|
190
|
+
return matchRecord(value, root, matcher);
|
|
162
191
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
192
|
+
return Object.is(value, matcher);
|
|
193
|
+
}
|
|
194
|
+
function matchRecord(value, root, matcher) {
|
|
195
|
+
if (!(0, base_1.isPlainObj)(matcher)) {
|
|
196
|
+
base_1.RimbuError.throwInvalidUsageError('match: to prevent accidental errors, match only supports plain objects as input.');
|
|
167
197
|
}
|
|
168
198
|
for (var key in matcher) {
|
|
169
199
|
if (!(key in value))
|
|
170
200
|
return false;
|
|
171
|
-
var
|
|
172
|
-
|
|
173
|
-
|
|
201
|
+
var matchValue = matcher[key];
|
|
202
|
+
var target = value[key];
|
|
203
|
+
if (matchValue instanceof Function) {
|
|
204
|
+
if (target instanceof Function && Object.is(target, matchValue)) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
var result = matchValue(target, value, root);
|
|
208
|
+
if (typeof result === 'boolean') {
|
|
209
|
+
if (result) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
if (!matchRecordItem(target, root, result)) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
if (!matchRecordItem(target, root, matchValue)) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
174
222
|
}
|
|
175
|
-
var result = matchSingle(value[key], matchKey, value, root);
|
|
176
|
-
if (!result)
|
|
177
|
-
return false;
|
|
178
223
|
}
|
|
179
224
|
return true;
|
|
180
225
|
}
|
|
226
|
+
function matchRecordItem(value, root, matcher) {
|
|
227
|
+
if ((0, base_1.isIterable)(matcher) && (0, base_1.isIterable)(value)) {
|
|
228
|
+
var it1 = value[Symbol.iterator]();
|
|
229
|
+
var it2 = matcher[Symbol.iterator]();
|
|
230
|
+
while (true) {
|
|
231
|
+
var v1 = it1.next();
|
|
232
|
+
var v2 = it2.next();
|
|
233
|
+
if (v1.done !== v2.done || v1.value !== v2.value) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
if (v1.done) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if ((0, base_1.isPlainObj)(value)) {
|
|
242
|
+
return matchOptions(value, root, matcher);
|
|
243
|
+
}
|
|
244
|
+
return Object.is(value, matcher);
|
|
245
|
+
}
|
|
181
246
|
//# sourceMappingURL=match.js.map
|
package/dist/main/match.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../src/match.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"match.js","sourceRoot":"","sources":["../../src/match.ts"],"names":[],"mappings":";;;AAAA,oCAMqB;AAUrB,IAAiB,KAAK,CAoHrB;AApHD,WAAiB,KAAK;IAuCpB;;;;;;;;;;;;OAYG;IACH,SAAgB,KAAK;QACnB,oBAAoC;aAApC,UAAoC,EAApC,qBAAoC,EAApC,IAAoC;YAApC,+BAAoC;;QAEpC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;IAC/B,CAAC;IAJe,WAAK,QAIpB,CAAA;IACD;;;;;;;;;;;;OAYG;IACH,SAAgB,IAAI;QAClB,oBAAoC;aAApC,UAAoC,EAApC,qBAAoC,EAApC,IAAoC;YAApC,+BAAoC;;QAEpC,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;IAJe,UAAI,OAInB,CAAA;IACD;;;;;;;;;;;;OAYG;IACH,SAAgB,IAAI;QAClB,oBAAoC;aAApC,UAAoC,EAApC,qBAAoC,EAApC,IAAoC;YAApC,+BAAoC;;QAEpC,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;IAJe,UAAI,OAInB,CAAA;IACD;;;;;;;;;;;;OAYG;IACH,SAAgB,MAAM;QACpB,oBAAoC;aAApC,UAAoC,EAApC,qBAAoC,EAApC,IAAoC;YAApC,+BAAoC;;QAEpC,OAAO,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC;IAJe,YAAM,SAIrB,CAAA;AAMH,CAAC,EApHgB,KAAK,GAAL,aAAK,KAAL,aAAK,QAoHrB;AAED;IACE,eAAqB,U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