@rimbu/deep 2.0.2 → 2.0.4
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 +283 -67
- package/dist/bun/deep.mts +6 -6
- package/dist/bun/match.mts +2 -2
- package/dist/bun/patch.mts +1 -1
- package/dist/bun/path.mts +4 -5
- package/dist/bun/tuple.mts +5 -1
- package/dist/cjs/deep.cjs +6 -6
- package/dist/cjs/deep.d.cts +6 -6
- package/dist/cjs/match.cjs +1 -1
- package/dist/cjs/match.d.cts +2 -2
- package/dist/cjs/patch.cjs +1 -1
- package/dist/cjs/patch.d.cts +1 -1
- package/dist/cjs/path.cjs +2 -2
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/path.d.cts +4 -5
- package/dist/cjs/tuple.cjs +1 -1
- package/dist/cjs/tuple.cjs.map +1 -1
- package/dist/cjs/tuple.d.cts +5 -1
- package/dist/esm/deep.d.mts +6 -6
- package/dist/esm/deep.mjs +6 -6
- package/dist/esm/match.d.mts +2 -2
- package/dist/esm/match.mjs +1 -1
- package/dist/esm/patch.d.mts +1 -1
- package/dist/esm/patch.mjs +1 -1
- package/dist/esm/path.d.mts +4 -5
- package/dist/esm/path.mjs +2 -2
- package/dist/esm/path.mjs.map +1 -1
- package/dist/esm/tuple.d.mts +5 -1
- package/dist/esm/tuple.mjs +1 -1
- package/dist/esm/tuple.mjs.map +1 -1
- package/package.json +5 -10
- package/src/deep.mts +6 -6
- package/src/match.mts +2 -2
- package/src/patch.mts +1 -1
- package/src/path.mts +4 -5
- package/src/tuple.mts +5 -1
package/README.md
CHANGED
|
@@ -1,122 +1,338 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
|
|
2
|
+
<img src="https://github.com/rimbu-org/rimbu/raw/main/assets/rimbu_logo.svg" height="96" alt="Rimbu Logo" />
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<div align="center">
|
|
6
6
|
|
|
7
|
-
](https://www.npmjs.com/package/@rimbu/deep)
|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
</div>
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
# `@rimbu/deep`
|
|
12
17
|
|
|
13
|
-
|
|
18
|
+
**Immutable, type-safe utilities for deeply patching, matching, and selecting from plain JavaScript objects.**
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- **Nested Value Querying**: Easily query nested values with the [`Path` object](https://rimbu.org/docs/deep/path).
|
|
18
|
-
- **Compile-Time Protection**: The [`Immutable` type](https://rimbu.org/docs/deep/immutable) helps create plain objects with compile-time protection against mutation.
|
|
19
|
-
- **Flexible Tuples**: The [`Tuple` type](https://rimbu.org/docs/deep/tuple) provides similar functionality to `as const` but with more flexibility.
|
|
20
|
+
`@rimbu/deep` gives you a set of composable tools – `Patch`, `Match`, `Path`, `Selector`, `Protected`, and `Tuple` –
|
|
21
|
+
to treat plain objects as if they were immutable, deeply typed data structures. You can:
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
- **Apply immutable updates** to nested structures using a flexible `Patch` notation.
|
|
24
|
+
- **Express rich match conditions** over objects and arrays using `Match`.
|
|
25
|
+
- **Access nested properties safely** using type‑checked string `Path`s.
|
|
26
|
+
- **Build typed projections** from objects using `Selector` shapes.
|
|
27
|
+
- **Protect values at compile time** from accidental mutation using `Protected`.
|
|
28
|
+
- **Work ergonomically with tuples** and fixed‑length arrays via `Tuple`.
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
Use it whenever you want the convenience of plain objects, but with **deep type safety**, **immutable semantics**, and
|
|
31
|
+
**refactor‑friendly string paths**.
|
|
24
32
|
|
|
25
|
-
|
|
33
|
+
---
|
|
26
34
|
|
|
27
|
-
|
|
35
|
+
## Table of Contents
|
|
28
36
|
|
|
29
|
-
|
|
37
|
+
1. [Why `@rimbu/deep`?](#why-rimbu-deep)
|
|
38
|
+
2. [Feature Highlights](#feature-highlights)
|
|
39
|
+
3. [Quick Start](#quick-start)
|
|
40
|
+
4. [Core Concepts & Types](#core-concepts--types)
|
|
41
|
+
5. [Deep API Helpers](#deep-api-helpers)
|
|
42
|
+
6. [Installation](#installation)
|
|
43
|
+
7. [Ecosystem & Further Reading](#ecosystem--further-reading)
|
|
44
|
+
8. [Contributing](#contributing)
|
|
45
|
+
9. [License](#license)
|
|
30
46
|
|
|
31
|
-
|
|
47
|
+
---
|
|
32
48
|
|
|
33
|
-
|
|
34
|
-
- [`Deno` ](https://deno.com/runtime)
|
|
35
|
-
- [`Bun` ](https://bun.sh/)
|
|
36
|
-
- `Web` 
|
|
49
|
+
## Why `@rimbu/deep`?
|
|
37
50
|
|
|
38
|
-
|
|
51
|
+
Plain objects are great, but they quickly become painful when:
|
|
39
52
|
|
|
40
|
-
**
|
|
53
|
+
- You need to **update nested fields immutably** (e.g. in Redux‑style state).
|
|
54
|
+
- You want **type‑safe string paths** like `'a.b.c[0]?.d'` instead of ad‑hoc helpers.
|
|
55
|
+
- You’d like to **pattern‑match** complex structures without a forest of `if`/`switch` checks.
|
|
56
|
+
- You want to **project and reshape data** (e.g. API responses) into well‑typed views.
|
|
41
57
|
|
|
42
|
-
|
|
43
|
-
|
|
58
|
+
`@rimbu/deep` focuses on:
|
|
59
|
+
|
|
60
|
+
- **Type‑driven paths and selectors** – `Path` and `Selector` are derived from your data types.
|
|
61
|
+
- **Immutable patching** – `Patch` lets you describe updates declaratively and apply them in one go.
|
|
62
|
+
- **Expressive matching** – `Match` supports nested objects, arrays, tuples, and compound predicates.
|
|
63
|
+
- **Compile‑time protection** – `Protected<T>` makes entire object graphs appear readonly to TypeScript.
|
|
64
|
+
|
|
65
|
+
If you find yourself writing a lot of manual cloning, deep property access, or matcher utilities, `@rimbu/deep` is a
|
|
66
|
+
drop‑in improvement.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Feature Highlights
|
|
71
|
+
|
|
72
|
+
- **Deep immutable patching** with `patch` and `patchAt`:
|
|
73
|
+
describe updates using nested objects/arrays and functions instead of manual cloning.
|
|
74
|
+
- **Typed string paths** with `Path.Get` and `Path.Set`:
|
|
75
|
+
only valid paths for your data type compile.
|
|
76
|
+
- **Structured matching** with `match`:
|
|
77
|
+
supports nested objects, tuple/array traversal, and compound matchers (`every`, `some`, `none`, `single`).
|
|
78
|
+
- **Selection & projection** with `select` and `Selector`:
|
|
79
|
+
derive new shapes from existing data using path strings, functions, or nested selector objects.
|
|
80
|
+
- **Compile‑time protection** with `Protected` and `protect`:
|
|
81
|
+
make values deeply readonly at the type level while still using the underlying runtime value.
|
|
82
|
+
- **Tuple helpers** with `Tuple`:
|
|
83
|
+
ergonomics around fixed‑length tuples (construction, indexing, updates, etc.).
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Quick Start
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { Deep } from '@rimbu/deep';
|
|
91
|
+
|
|
92
|
+
const input = { a: 1, b: { c: true, d: 'a' } } as const;
|
|
93
|
+
|
|
94
|
+
// Immutable deep patch
|
|
95
|
+
const updated = Deep.patch(input, [{ b: [{ c: (v) => !v }] }]);
|
|
96
|
+
// => { a: 1, b: { c: false, d: 'a' } }
|
|
97
|
+
|
|
98
|
+
// Type-safe nested get
|
|
99
|
+
const cValue = Deep.getAt(input, 'b.c'); // boolean
|
|
100
|
+
|
|
101
|
+
// Pattern matching
|
|
102
|
+
if (Deep.match(input, { b: { c: true } })) {
|
|
103
|
+
// ...
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Selection / projection
|
|
107
|
+
const projected = Deep.select(input, { flag: 'b.c', label: 'b.d' });
|
|
108
|
+
// projected: { flag: boolean; label: string }
|
|
44
109
|
```
|
|
45
110
|
|
|
46
|
-
|
|
111
|
+
Try Rimbu (including `@rimbu/deep`) live in the browser using the
|
|
112
|
+
[Rimbu Sandbox on CodeSandbox](https://codesandbox.io/s/github/vitoke/rimbu-sandbox/tree/main?previewwindow=console&view=split&editorsize=65&moduleview=1&module=/src/index.ts).
|
|
47
113
|
|
|
48
|
-
|
|
49
|
-
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Core Concepts & Types
|
|
117
|
+
|
|
118
|
+
### Exported Types & Namespaces
|
|
119
|
+
|
|
120
|
+
From `@rimbu/deep`’s main entrypoint you have access to:
|
|
121
|
+
|
|
122
|
+
| Name | Description |
|
|
123
|
+
| ------------------------------- | ------------------------------------------------------------------------------------------------------ |
|
|
124
|
+
| `Patch<T, C = T>` | Type describing allowed patch shapes for a value of type `T`. |
|
|
125
|
+
| `Match<T, C = Partial<T>>` | Type describing allowed matchers for values of type `T`. |
|
|
126
|
+
| `Path` | Namespace containing `Path.Get<T>`, `Path.Set<T>`, and `Path.Result<T, P>` utilities for string paths. |
|
|
127
|
+
| `Selector<T>` | Type describing allowed selector shapes for values of type `T`. |
|
|
128
|
+
| `Protected<T>` | Deeply readonly/“protected” view of `T` for compile‑time mutation safety. |
|
|
129
|
+
| `Tuple<T extends Tuple.Source>` | Tuple wrapper with helper types and functions under the `Tuple` namespace. |
|
|
130
|
+
| `Deep` | Convenience namespace exposing the main deep utilities (`patch`, `match`, `getAt`, `select`, etc.). |
|
|
131
|
+
|
|
132
|
+
See the [Deep overview docs](https://rimbu.org/docs/deep/overview) and
|
|
133
|
+
[API reference](https://rimbu.org/api/rimbu/deep) for the full surface.
|
|
134
|
+
|
|
135
|
+
### Patching with `patch` and `Patch`
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
import { Deep, type Patch } from '@rimbu/deep';
|
|
139
|
+
|
|
140
|
+
type State = {
|
|
141
|
+
count: number;
|
|
142
|
+
user?: { name: string; active: boolean };
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const state: State = { count: 1, user: { name: 'Ada', active: true } };
|
|
146
|
+
|
|
147
|
+
const patchItem: Patch<State> = [
|
|
148
|
+
{ count: (v) => v + 1 },
|
|
149
|
+
{ user: [{ active: false }] },
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
const next = Deep.patch(state, patchItem);
|
|
153
|
+
// => { count: 2, user: { name: 'Ada', active: false } }
|
|
50
154
|
```
|
|
51
155
|
|
|
52
|
-
|
|
156
|
+
Patches can be:
|
|
53
157
|
|
|
54
|
-
|
|
55
|
-
|
|
158
|
+
- Direct replacement values (`T`).
|
|
159
|
+
- Functions `(current, parent, root) => newValue`.
|
|
160
|
+
- Nested objects / arrays describing which fields or tuple indices to update.
|
|
161
|
+
|
|
162
|
+
### Matching with `match` and `Match`
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import { Deep, type Match } from '@rimbu/deep';
|
|
166
|
+
|
|
167
|
+
type Item = { id: number; tags: string[] };
|
|
168
|
+
|
|
169
|
+
const items: Item[] = [
|
|
170
|
+
{ id: 1, tags: ['a', 'b'] },
|
|
171
|
+
{ id: 2, tags: ['b'] },
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
const matcher: Match<Item> = {
|
|
175
|
+
tags: { someItem: (tag) => tag === 'a' },
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const result = items.filter((item) => Deep.match(item, matcher));
|
|
179
|
+
// => only items containing tag 'a'
|
|
56
180
|
```
|
|
57
181
|
|
|
58
|
-
|
|
182
|
+
`Match` supports:
|
|
59
183
|
|
|
60
|
-
|
|
184
|
+
- Plain object matchers (`{ a: 1, b: { c: true } }`).
|
|
185
|
+
- Function matchers `(value, parent, root) => boolean | matcher`.
|
|
186
|
+
- Array/tuple matchers and traversal helpers such as `someItem`, `everyItem`, `noneItem`, `singleItem`.
|
|
187
|
+
- Compound matchers like `['every', matcher1, matcher2]`.
|
|
61
188
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
189
|
+
### Paths with `Path.Get`, `Path.Set` and `getAt` / `patchAt`
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { Deep, type Path } from '@rimbu/deep';
|
|
193
|
+
|
|
194
|
+
type Model = { a: { b: { c: number }[] } };
|
|
195
|
+
const value: Model = { a: { b: { c: [5, 6] } } as any };
|
|
196
|
+
|
|
197
|
+
// Typed paths
|
|
198
|
+
const path: Path.Get<Model> = 'a.b.c[1]?.d'; // compile-time checked
|
|
199
|
+
|
|
200
|
+
// Reading
|
|
201
|
+
const result = Deep.getAt(value, 'a.b.c[0]'); // number | undefined
|
|
202
|
+
|
|
203
|
+
// Patching at a path
|
|
204
|
+
const updated = Deep.patchAt(value, 'a.b.c', (arr) => [...arr, 7]);
|
|
68
205
|
```
|
|
69
206
|
|
|
70
|
-
|
|
207
|
+
`Path.Result<T, P>` gives you the resulting type at a given path `P` in `T`.
|
|
71
208
|
|
|
72
|
-
|
|
209
|
+
### Selection with `Selector` and `select`
|
|
73
210
|
|
|
74
211
|
```ts
|
|
75
|
-
import {
|
|
76
|
-
|
|
212
|
+
import { Deep, type Selector } from '@rimbu/deep';
|
|
213
|
+
|
|
214
|
+
type Source = {
|
|
215
|
+
a: { b: number; c: string };
|
|
216
|
+
meta: { createdAt: string };
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const source: Source = {
|
|
220
|
+
a: { b: 1, c: 'x' },
|
|
221
|
+
meta: { createdAt: '2024-01-01' },
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const selector: Selector<Source> = {
|
|
225
|
+
value: 'a.b',
|
|
226
|
+
label: 'a.c',
|
|
227
|
+
created: 'meta.createdAt',
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const view = Deep.select(source, selector);
|
|
231
|
+
// view: { value: number; label: string; created: string }
|
|
77
232
|
```
|
|
78
233
|
|
|
79
|
-
|
|
234
|
+
Selectors can be:
|
|
235
|
+
|
|
236
|
+
- String paths.
|
|
237
|
+
- Functions `(value: Protected<T>) => any`.
|
|
238
|
+
- Arrays or objects composed of other selectors.
|
|
239
|
+
|
|
240
|
+
### Protection with `Protected` and `protect`
|
|
80
241
|
|
|
81
242
|
```ts
|
|
82
|
-
import {
|
|
243
|
+
import { Deep, type Protected } from '@rimbu/deep';
|
|
244
|
+
|
|
245
|
+
type Data = { a: { b: number[] } };
|
|
246
|
+
|
|
247
|
+
const data: Data = { a: { b: [1, 2] } };
|
|
248
|
+
const protectedData: Protected<Data> = Deep.protect(data);
|
|
249
|
+
|
|
250
|
+
// protectedData.a.b.push(3); // TypeScript error – `b` is readonly
|
|
83
251
|
```
|
|
84
252
|
|
|
85
|
-
|
|
253
|
+
`Protected<T>` is a **type‑level** construct: it does not freeze the value at runtime, but helps prevent
|
|
254
|
+
accidental mutations in your code.
|
|
86
255
|
|
|
87
|
-
|
|
256
|
+
---
|
|
88
257
|
|
|
89
|
-
##
|
|
258
|
+
## Deep API Helpers
|
|
259
|
+
|
|
260
|
+
All top‑level utilities are also available through the `Deep` namespace:
|
|
90
261
|
|
|
91
262
|
```ts
|
|
92
|
-
import {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
263
|
+
import { Deep } from '@rimbu/deep';
|
|
264
|
+
|
|
265
|
+
// Functional helpers
|
|
266
|
+
const incCount = Deep.patchWith<{ count: number }>([{ count: (v) => v + 1 }]);
|
|
267
|
+
const onlyActive = Deep.matchWith({ active: true });
|
|
268
|
+
const getName = Deep.getAtWith<{ user: { name: string } }>('user.name');
|
|
269
|
+
|
|
270
|
+
// Typed, curried API with withType
|
|
271
|
+
const s = { a: 1, b: { c: 'a', d: true } };
|
|
272
|
+
const api = Deep.withType<typeof s>();
|
|
273
|
+
|
|
274
|
+
const next = api.patchWith([{ b: [{ d: (v) => !v }] }])(s);
|
|
275
|
+
// => { a: 1, b: { c: 'a', d: false } }
|
|
104
276
|
```
|
|
105
277
|
|
|
106
|
-
|
|
278
|
+
The `Deep` namespace mirrors the main exports:
|
|
107
279
|
|
|
108
|
-
|
|
280
|
+
- `Deep.patch`, `Deep.patchAt`, `Deep.patchWith`, `Deep.patchAtWith`
|
|
281
|
+
- `Deep.match`, `Deep.matchAt`, `Deep.matchWith`, `Deep.matchAtWith`
|
|
282
|
+
- `Deep.getAt`, `Deep.getAtWith`
|
|
283
|
+
- `Deep.select`, `Deep.selectAt`, `Deep.selectWith`, `Deep.selectAtWith`
|
|
284
|
+
- `Deep.withType<T>()` for creating a typed, curried API.
|
|
109
285
|
|
|
110
|
-
|
|
286
|
+
---
|
|
111
287
|
|
|
112
|
-
|
|
288
|
+
## Installation
|
|
113
289
|
|
|
114
|
-
|
|
290
|
+
### Node / Bun / npm / Yarn
|
|
115
291
|
|
|
116
|
-
|
|
292
|
+
```sh
|
|
293
|
+
npm install @rimbu/deep
|
|
294
|
+
# or
|
|
295
|
+
yarn add @rimbu/deep
|
|
296
|
+
# or
|
|
297
|
+
bun add @rimbu/deep
|
|
298
|
+
# or
|
|
299
|
+
deno add npm:@rimbu/deep
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Then:
|
|
303
|
+
|
|
304
|
+
```ts
|
|
305
|
+
import { Deep } from '@rimbu/deep/mod.ts';
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Browser / ESM
|
|
309
|
+
|
|
310
|
+
`@rimbu/deep` ships both **ESM** and **CJS** builds. Use it with any modern bundler
|
|
311
|
+
(Vite, Webpack, esbuild, Bun, etc.) or directly in Node ESM projects.
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## Ecosystem & Further Reading
|
|
316
|
+
|
|
317
|
+
- Part of the broader **Rimbu** ecosystem – interoperates with `@rimbu/core`, `@rimbu/collection-types`,
|
|
318
|
+
and other collection packages.
|
|
319
|
+
- Ideal for modelling immutable application state, selectors, and matchers in complex domains.
|
|
320
|
+
- Learn more in the [Deep overview docs](https://rimbu.org/docs/deep/overview) and the
|
|
321
|
+
[Deep API reference](https://rimbu.org/api/rimbu/deep).
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
## Contributing
|
|
326
|
+
|
|
327
|
+
We welcome contributions! See the
|
|
328
|
+
[Contributing guide](https://github.com/rimbu-org/rimbu/blob/main/CONTRIBUTING.md) for details.
|
|
329
|
+
|
|
330
|
+
<img src="https://contrib.rocks/image?repo=rimbu-org/rimbu" alt="Contributors" />
|
|
117
331
|
|
|
118
332
|
_Made with [contributors-img](https://contrib.rocks)._
|
|
119
333
|
|
|
334
|
+
---
|
|
335
|
+
|
|
120
336
|
## License
|
|
121
337
|
|
|
122
|
-
|
|
338
|
+
MIT © Rimbu contributors. See [LICENSE](./LICENSE) for details.
|
package/dist/bun/deep.mts
CHANGED
|
@@ -90,9 +90,9 @@ export function patchAtWith<T, P extends Path.Set<T>, TE extends T = T, TT = T>(
|
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* Returns a function that matches a given `value` with the given `matcher`.
|
|
93
|
-
* @typeparam T - the
|
|
93
|
+
* @typeparam T - the input value type
|
|
94
94
|
* @param matcher - a matcher object that matches input values.
|
|
95
|
-
* @param source - the value to
|
|
95
|
+
* @param source - the value to match (parameter of the returned function).
|
|
96
96
|
* @example
|
|
97
97
|
* ```ts
|
|
98
98
|
* const items = [{ a: 1, b: 'a' }, { a: 2, b: 'b' }];
|
|
@@ -128,7 +128,7 @@ export function matchAt<T, P extends Path.Get<T>>(
|
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
130
|
* Returns a function that matches a given `value` with the given `matcher` at the given string `path`.
|
|
131
|
-
* @typeparam T - the
|
|
131
|
+
* @typeparam T - the input value type
|
|
132
132
|
* @typeparam P - the string literal path type in the object
|
|
133
133
|
* @typeparam TE - utility type
|
|
134
134
|
* @param path - the string path in the object
|
|
@@ -150,7 +150,7 @@ export function matchAtWith<T, P extends Path.Get<T>, TE extends T = T>(
|
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
152
|
* Returns a function that selects a certain shape from a given `value` with the given `selector`.
|
|
153
|
-
* @typeparam T - the
|
|
153
|
+
* @typeparam T - the input value type
|
|
154
154
|
* @typeparam SL - the selector shape type
|
|
155
155
|
* @param selector - a shape indicating the selection from the source values
|
|
156
156
|
* @param source - the value to use the given `selector` on.
|
|
@@ -169,7 +169,7 @@ export function selectWith<T, SL extends Selector<T>>(
|
|
|
169
169
|
|
|
170
170
|
/**
|
|
171
171
|
* Returns the result of applying the given `selector` shape to the given `source` value.
|
|
172
|
-
* @typeparam T - the
|
|
172
|
+
* @typeparam T - the input value type
|
|
173
173
|
* @typeparam P - the string literal path type in the object
|
|
174
174
|
* @typeparam SL - the selector shape type
|
|
175
175
|
* @param source - the source value to select from
|
|
@@ -196,7 +196,7 @@ export function selectAt<
|
|
|
196
196
|
|
|
197
197
|
/**
|
|
198
198
|
* Returns a function that selects a certain shape from a given `value` with the given `selector` at the given string `path`.
|
|
199
|
-
* @typeparam T - the
|
|
199
|
+
* @typeparam T - the input value type
|
|
200
200
|
* @typeparam P - the string literal path type in the object
|
|
201
201
|
* @typeparam SL - the selector shape type
|
|
202
202
|
* @param path - the string path in the object
|
package/dist/bun/match.mts
CHANGED
|
@@ -134,7 +134,7 @@ export namespace Match {
|
|
|
134
134
|
export type ArrayTraversalType = `${CompoundType}Item`;
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
|
-
*
|
|
137
|
+
* Compound matcher for objects, represented as an array starting with a compound type keyword.
|
|
138
138
|
* @typeparam T - the input value type
|
|
139
139
|
* @typeparam C - utility type
|
|
140
140
|
* @typeparam P - the parent type
|
|
@@ -194,7 +194,7 @@ export namespace Match {
|
|
|
194
194
|
* match(input, { a: 2 }) // => false
|
|
195
195
|
* match(input, { a: (v) => v > 10 }) // => false
|
|
196
196
|
* match(input, { b: { c: true }}) // => true
|
|
197
|
-
* match(input,
|
|
197
|
+
* match(input, ['every', { a: (v) => v > 0 }, { b: { c: true } }]) // => true
|
|
198
198
|
* match(input, { b: { c: (v, parent, root) => v && parent.d.length > 0 && root.a > 0 } })
|
|
199
199
|
* // => true
|
|
200
200
|
* ```
|
package/dist/bun/patch.mts
CHANGED
|
@@ -110,7 +110,7 @@ export namespace Patch {
|
|
|
110
110
|
* patch(input, [{ a: 2 }]) // => { a: 2, b: { c: true, d: 'a' } }
|
|
111
111
|
* patch(input, [{ b: [{ c: (v) => !v }] }] )
|
|
112
112
|
* // => { a: 1, b: { c: false, d: 'a' } }
|
|
113
|
-
* patch(input
|
|
113
|
+
* patch(input, [{ a: (v) => v + 1, b: [{ d: 'q' }] }] )
|
|
114
114
|
* // => { a: 2, b: { c: true, d: 'q' } }
|
|
115
115
|
* ```
|
|
116
116
|
*/
|
package/dist/bun/path.mts
CHANGED
|
@@ -75,7 +75,6 @@ export namespace Path {
|
|
|
75
75
|
* @typeparam T - the source type
|
|
76
76
|
* @typeparam Write - if true the path should be writable (no optional chaining)
|
|
77
77
|
* @typeparam Maybe - if true the value at the current path is optional
|
|
78
|
-
* @typeparam First - if true this is the root call
|
|
79
78
|
*/
|
|
80
79
|
export type NonOptional<T, Write extends boolean, Maybe extends boolean> =
|
|
81
80
|
Tuple.IsTuple<T> extends true
|
|
@@ -129,7 +128,7 @@ export namespace Path {
|
|
|
129
128
|
}[keyof T];
|
|
130
129
|
|
|
131
130
|
/**
|
|
132
|
-
* Determines the allowed path part
|
|
131
|
+
* Determines the allowed path part separator based on the input types.
|
|
133
132
|
* @typeparam First - if true, this is the first call
|
|
134
133
|
* @typeparam Maybe - if true, the value is optional
|
|
135
134
|
* @typeparam IsArray - if true, the value is an array
|
|
@@ -179,7 +178,7 @@ export namespace Path {
|
|
|
179
178
|
|
|
180
179
|
/**
|
|
181
180
|
* Utility type to only add non-empty string types to a string array.
|
|
182
|
-
* @
|
|
181
|
+
* @typeparam A - the input string array
|
|
183
182
|
* @typeparam T - the string value to optionally add
|
|
184
183
|
*/
|
|
185
184
|
export type AppendIfNotEmpty<
|
|
@@ -326,9 +325,9 @@ export namespace Path {
|
|
|
326
325
|
* ```ts
|
|
327
326
|
* const value = { a: { b: { c: [{ d: 5 }, { d: 6 }] } } }
|
|
328
327
|
* Deep.getAt(value, 'a.b');
|
|
329
|
-
* // => { c: 5 }
|
|
328
|
+
* // => { c: [{ d: 5 }, { d: 6 }] }
|
|
330
329
|
* Deep.getAt(value, 'a.b.c');
|
|
331
|
-
* // => [{ d: 5 }, { d:
|
|
330
|
+
* // => [{ d: 5 }, { d: 6 }]
|
|
332
331
|
* Deep.getAt(value, 'a.b.c[1]');
|
|
333
332
|
* // => { d: 6 }
|
|
334
333
|
* Deep.getAt(value, 'a.b.c[1]?.d');
|
package/dist/bun/tuple.mts
CHANGED
|
@@ -17,6 +17,10 @@ export namespace Tuple {
|
|
|
17
17
|
*/
|
|
18
18
|
export type Source = readonly unknown[];
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Determines whether the given type `T` is a tuple type.
|
|
22
|
+
* @typeparam T - the input type
|
|
23
|
+
*/
|
|
20
24
|
export type IsTuple<T> = T extends { length: infer L }
|
|
21
25
|
? 0 extends L
|
|
22
26
|
? false
|
|
@@ -43,7 +47,7 @@ export namespace Tuple {
|
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
/**
|
|
46
|
-
* Returns the item at the given `index` in the
|
|
50
|
+
* Returns the item at the given `index` in the given `tuple`.
|
|
47
51
|
* @param tuple - the tuple to get the item from
|
|
48
52
|
* @param index - the index in of the tuple element
|
|
49
53
|
* @example
|
package/dist/cjs/deep.cjs
CHANGED
|
@@ -94,9 +94,9 @@ function patchAtWith(path, patchItem) {
|
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* Returns a function that matches a given `value` with the given `matcher`.
|
|
97
|
-
* @typeparam T - the
|
|
97
|
+
* @typeparam T - the input value type
|
|
98
98
|
* @param matcher - a matcher object that matches input values.
|
|
99
|
-
* @param source - the value to
|
|
99
|
+
* @param source - the value to match (parameter of the returned function).
|
|
100
100
|
* @example
|
|
101
101
|
* ```ts
|
|
102
102
|
* const items = [{ a: 1, b: 'a' }, { a: 2, b: 'b' }];
|
|
@@ -126,7 +126,7 @@ function matchAt(source, path, matcher) {
|
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* Returns a function that matches a given `value` with the given `matcher` at the given string `path`.
|
|
129
|
-
* @typeparam T - the
|
|
129
|
+
* @typeparam T - the input value type
|
|
130
130
|
* @typeparam P - the string literal path type in the object
|
|
131
131
|
* @typeparam TE - utility type
|
|
132
132
|
* @param path - the string path in the object
|
|
@@ -144,7 +144,7 @@ function matchAtWith(path, matcher) {
|
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
146
146
|
* Returns a function that selects a certain shape from a given `value` with the given `selector`.
|
|
147
|
-
* @typeparam T - the
|
|
147
|
+
* @typeparam T - the input value type
|
|
148
148
|
* @typeparam SL - the selector shape type
|
|
149
149
|
* @param selector - a shape indicating the selection from the source values
|
|
150
150
|
* @param source - the value to use the given `selector` on.
|
|
@@ -160,7 +160,7 @@ function selectWith(selector) {
|
|
|
160
160
|
}
|
|
161
161
|
/**
|
|
162
162
|
* Returns the result of applying the given `selector` shape to the given `source` value.
|
|
163
|
-
* @typeparam T - the
|
|
163
|
+
* @typeparam T - the input value type
|
|
164
164
|
* @typeparam P - the string literal path type in the object
|
|
165
165
|
* @typeparam SL - the selector shape type
|
|
166
166
|
* @param source - the source value to select from
|
|
@@ -178,7 +178,7 @@ function selectAt(source, path, selector) {
|
|
|
178
178
|
}
|
|
179
179
|
/**
|
|
180
180
|
* Returns a function that selects a certain shape from a given `value` with the given `selector` at the given string `path`.
|
|
181
|
-
* @typeparam T - the
|
|
181
|
+
* @typeparam T - the input value type
|
|
182
182
|
* @typeparam P - the string literal path type in the object
|
|
183
183
|
* @typeparam SL - the selector shape type
|
|
184
184
|
* @param path - the string path in the object
|
package/dist/cjs/deep.d.cts
CHANGED
|
@@ -68,9 +68,9 @@ export declare function patchWith<T, TE extends T = T, TT = T>(patchItem: Patch<
|
|
|
68
68
|
export declare function patchAtWith<T, P extends Path.Set<T>, TE extends T = T, TT = T>(path: P, patchItem: Patch<Path.Result<TE, P>, Path.Result<TT, P>>): (source: T) => T;
|
|
69
69
|
/**
|
|
70
70
|
* Returns a function that matches a given `value` with the given `matcher`.
|
|
71
|
-
* @typeparam T - the
|
|
71
|
+
* @typeparam T - the input value type
|
|
72
72
|
* @param matcher - a matcher object that matches input values.
|
|
73
|
-
* @param source - the value to
|
|
73
|
+
* @param source - the value to match (parameter of the returned function).
|
|
74
74
|
* @example
|
|
75
75
|
* ```ts
|
|
76
76
|
* const items = [{ a: 1, b: 'a' }, { a: 2, b: 'b' }];
|
|
@@ -96,7 +96,7 @@ export declare function matchWith<T>(matcher: Match<T>): (source: T) => boolean;
|
|
|
96
96
|
export declare function matchAt<T, P extends Path.Get<T>>(source: T, path: P, matcher: Match<Path.Result<T, P>>): boolean;
|
|
97
97
|
/**
|
|
98
98
|
* Returns a function that matches a given `value` with the given `matcher` at the given string `path`.
|
|
99
|
-
* @typeparam T - the
|
|
99
|
+
* @typeparam T - the input value type
|
|
100
100
|
* @typeparam P - the string literal path type in the object
|
|
101
101
|
* @typeparam TE - utility type
|
|
102
102
|
* @param path - the string path in the object
|
|
@@ -112,7 +112,7 @@ export declare function matchAt<T, P extends Path.Get<T>>(source: T, path: P, ma
|
|
|
112
112
|
export declare function matchAtWith<T, P extends Path.Get<T>, TE extends T = T>(path: P, matcher: Match<Path.Result<T & TE, P>>): (source: T) => boolean;
|
|
113
113
|
/**
|
|
114
114
|
* Returns a function that selects a certain shape from a given `value` with the given `selector`.
|
|
115
|
-
* @typeparam T - the
|
|
115
|
+
* @typeparam T - the input value type
|
|
116
116
|
* @typeparam SL - the selector shape type
|
|
117
117
|
* @param selector - a shape indicating the selection from the source values
|
|
118
118
|
* @param source - the value to use the given `selector` on.
|
|
@@ -126,7 +126,7 @@ export declare function matchAtWith<T, P extends Path.Get<T>, TE extends T = T>(
|
|
|
126
126
|
export declare function selectWith<T, SL extends Selector<T>>(selector: Selector.Shape<SL>): (source: T) => Selector.Result<T, SL>;
|
|
127
127
|
/**
|
|
128
128
|
* Returns the result of applying the given `selector` shape to the given `source` value.
|
|
129
|
-
* @typeparam T - the
|
|
129
|
+
* @typeparam T - the input value type
|
|
130
130
|
* @typeparam P - the string literal path type in the object
|
|
131
131
|
* @typeparam SL - the selector shape type
|
|
132
132
|
* @param source - the source value to select from
|
|
@@ -142,7 +142,7 @@ export declare function selectWith<T, SL extends Selector<T>>(selector: Selector
|
|
|
142
142
|
export declare function selectAt<T, P extends Path.Get<T>, SL extends Selector<Path.Result<T, P>>>(source: T, path: P, selector: Selector.Shape<SL>): Selector.Result<Path.Result<T, P>, SL>;
|
|
143
143
|
/**
|
|
144
144
|
* Returns a function that selects a certain shape from a given `value` with the given `selector` at the given string `path`.
|
|
145
|
-
* @typeparam T - the
|
|
145
|
+
* @typeparam T - the input value type
|
|
146
146
|
* @typeparam P - the string literal path type in the object
|
|
147
147
|
* @typeparam SL - the selector shape type
|
|
148
148
|
* @param path - the string path in the object
|
package/dist/cjs/match.cjs
CHANGED
|
@@ -17,7 +17,7 @@ var base_1 = require("@rimbu/base");
|
|
|
17
17
|
* match(input, { a: 2 }) // => false
|
|
18
18
|
* match(input, { a: (v) => v > 10 }) // => false
|
|
19
19
|
* match(input, { b: { c: true }}) // => true
|
|
20
|
-
* match(input,
|
|
20
|
+
* match(input, ['every', { a: (v) => v > 0 }, { b: { c: true } }]) // => true
|
|
21
21
|
* match(input, { b: { c: (v, parent, root) => v && parent.d.length > 0 && root.a > 0 } })
|
|
22
22
|
* // => true
|
|
23
23
|
* ```
|
package/dist/cjs/match.d.cts
CHANGED
|
@@ -80,7 +80,7 @@ export declare namespace Match {
|
|
|
80
80
|
*/
|
|
81
81
|
type ArrayTraversalType = `${CompoundType}Item`;
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
83
|
+
* Compound matcher for objects, represented as an array starting with a compound type keyword.
|
|
84
84
|
* @typeparam T - the input value type
|
|
85
85
|
* @typeparam C - utility type
|
|
86
86
|
* @typeparam P - the parent type
|
|
@@ -132,7 +132,7 @@ export declare namespace Match {
|
|
|
132
132
|
* match(input, { a: 2 }) // => false
|
|
133
133
|
* match(input, { a: (v) => v > 10 }) // => false
|
|
134
134
|
* match(input, { b: { c: true }}) // => true
|
|
135
|
-
* match(input,
|
|
135
|
+
* match(input, ['every', { a: (v) => v > 0 }, { b: { c: true } }]) // => true
|
|
136
136
|
* match(input, { b: { c: (v, parent, root) => v && parent.d.length > 0 && root.a > 0 } })
|
|
137
137
|
* // => true
|
|
138
138
|
* ```
|
package/dist/cjs/patch.cjs
CHANGED
|
@@ -21,7 +21,7 @@ var base_1 = require("@rimbu/base");
|
|
|
21
21
|
* patch(input, [{ a: 2 }]) // => { a: 2, b: { c: true, d: 'a' } }
|
|
22
22
|
* patch(input, [{ b: [{ c: (v) => !v }] }] )
|
|
23
23
|
* // => { a: 1, b: { c: false, d: 'a' } }
|
|
24
|
-
* patch(input
|
|
24
|
+
* patch(input, [{ a: (v) => v + 1, b: [{ d: 'q' }] }] )
|
|
25
25
|
* // => { a: 2, b: { c: true, d: 'q' } }
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
package/dist/cjs/patch.d.cts
CHANGED
|
@@ -82,7 +82,7 @@ export declare namespace Patch {
|
|
|
82
82
|
* patch(input, [{ a: 2 }]) // => { a: 2, b: { c: true, d: 'a' } }
|
|
83
83
|
* patch(input, [{ b: [{ c: (v) => !v }] }] )
|
|
84
84
|
* // => { a: 1, b: { c: false, d: 'a' } }
|
|
85
|
-
* patch(input
|
|
85
|
+
* patch(input, [{ a: (v) => v + 1, b: [{ d: 'q' }] }] )
|
|
86
86
|
* // => { a: 2, b: { c: true, d: 'q' } }
|
|
87
87
|
* ```
|
|
88
88
|
*/
|
package/dist/cjs/path.cjs
CHANGED
|
@@ -33,9 +33,9 @@ var Path;
|
|
|
33
33
|
* ```ts
|
|
34
34
|
* const value = { a: { b: { c: [{ d: 5 }, { d: 6 }] } } }
|
|
35
35
|
* Deep.getAt(value, 'a.b');
|
|
36
|
-
* // => { c: 5 }
|
|
36
|
+
* // => { c: [{ d: 5 }, { d: 6 }] }
|
|
37
37
|
* Deep.getAt(value, 'a.b.c');
|
|
38
|
-
* // => [{ d: 5 }, { d:
|
|
38
|
+
* // => [{ d: 5 }, { d: 6 }]
|
|
39
39
|
* Deep.getAt(value, 'a.b.c[1]');
|
|
40
40
|
* // => { d: 6 }
|
|
41
41
|
* Deep.getAt(value, 'a.b.c[1]?.d');
|
package/dist/cjs/path.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.cjs","sourceRoot":"","sources":["../../_cjs_prepare/path.cts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"path.cjs","sourceRoot":"","sources":["../../_cjs_prepare/path.cts"],"names":[],"mappings":";;;AAgVA,sBA8BC;AAgBD,0BA6CC;;AA1aD,+CAAkD;AAGlD,IAAiB,IAAI,CAoTpB;AApTD,WAAiB,IAAI;IAmSnB;;OAEG;IACU,qBAAgB,GAAG,gBAAgB,CAAC;IAOjD;;;OAGG;IACH,SAAgB,WAAW,CAAC,IAAY;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC3C,CAAC;IAFe,gBAAW,cAE1B,CAAA;AACH,CAAC,EApTgB,IAAI,oBAAJ,IAAI,QAoTpB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,KAAK,CACnB,MAAS,EACT,IAAO;;IAEP,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QAChB,kDAAkD;QAClD,OAAO,MAAa,CAAC;IACvB,CAAC;IAED,IAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAErC,sCAAsC;IACtC,IAAI,MAAM,GAAG,MAAa,CAAC;;QAE3B,KAAmB,IAAA,UAAA,iBAAA,KAAK,CAAA,4BAAA,+CAAE,CAAC;YAAtB,IAAM,IAAI,kBAAA;YACb,IAAI,SAAS,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;gBACtD,0BAA0B;gBAC1B,SAAS;YACX,CAAC;YAED,IAAI,SAAS,KAAK,MAAM,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBAC5C,2FAA2F;gBAC3F,OAAO,SAAgB,CAAC;YAC1B,CAAC;YAED,sCAAsC;YACtC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;;;;;;;;;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,OAAO,CACrB,MAAS,EACT,IAAO,EACP,SAA0D;IAE1D,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QAChB,OAAO,mBAAI,CAAC,KAAK,CAAC,MAAM,EAAE,SAAgB,CAAC,CAAC;IAC9C,CAAC;IAED,IAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAErC,mDAAmD;IACnD,SAAS,eAAe,CAAC,KAAa,EAAE,MAAW;;QACjD,IAAI,KAAK,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;YAC3B,oDAAoD;YACpD,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAE1B,IAAI,SAAS,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;YACtC,6BAA6B;YAC7B,OAAO,eAAe,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;QAC5C,CAAC;QAED,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,kDAAkD;YAClD,OAAO,eAAe,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;QAC5C,CAAC;QAED,gGAAgG;QAChG,IAAM,MAAM;YACV,GAAC,IAAI,IAAG,eAAe,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;eACjD,CAAC;QAEF,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,wEAAwE;YACxE,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,mEAAmE;QACnE,OAAO,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,mBAAI,CAAC,KAAK,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
package/dist/cjs/path.d.cts
CHANGED
|
@@ -44,7 +44,6 @@ export declare namespace Path {
|
|
|
44
44
|
* @typeparam T - the source type
|
|
45
45
|
* @typeparam Write - if true the path should be writable (no optional chaining)
|
|
46
46
|
* @typeparam Maybe - if true the value at the current path is optional
|
|
47
|
-
* @typeparam First - if true this is the root call
|
|
48
47
|
*/
|
|
49
48
|
type NonOptional<T, Write extends boolean, Maybe extends boolean> = Tuple.IsTuple<T> extends true ? Path.Internal.Tup<T, Write, Maybe> : T extends readonly any[] ? Write extends false ? Path.Internal.Arr<T> : never : IsPlainObj<T> extends true ? Path.Internal.Obj<T, Write, Maybe> : never;
|
|
50
49
|
/**
|
|
@@ -72,7 +71,7 @@ export declare namespace Path {
|
|
|
72
71
|
[K in keyof T]: `${K & string}${Path.Internal.Generic<T[K], Write, Write extends true ? false : Path.Internal.IsOptional<T[K], true, Maybe>>}`;
|
|
73
72
|
}[keyof T];
|
|
74
73
|
/**
|
|
75
|
-
* Determines the allowed path part
|
|
74
|
+
* Determines the allowed path part separator based on the input types.
|
|
76
75
|
* @typeparam First - if true, this is the first call
|
|
77
76
|
* @typeparam Maybe - if true, the value is optional
|
|
78
77
|
* @typeparam IsArray - if true, the value is an array
|
|
@@ -93,7 +92,7 @@ export declare namespace Path {
|
|
|
93
92
|
type MaybeValue<T, Maybe extends boolean> = Maybe extends true ? T | undefined : T;
|
|
94
93
|
/**
|
|
95
94
|
* Utility type to only add non-empty string types to a string array.
|
|
96
|
-
* @
|
|
95
|
+
* @typeparam A - the input string array
|
|
97
96
|
* @typeparam T - the string value to optionally add
|
|
98
97
|
*/
|
|
99
98
|
type AppendIfNotEmpty<A extends string[], T extends string> = T extends '' ? A : [
|
|
@@ -172,9 +171,9 @@ export declare namespace Path {
|
|
|
172
171
|
* ```ts
|
|
173
172
|
* const value = { a: { b: { c: [{ d: 5 }, { d: 6 }] } } }
|
|
174
173
|
* Deep.getAt(value, 'a.b');
|
|
175
|
-
* // => { c: 5 }
|
|
174
|
+
* // => { c: [{ d: 5 }, { d: 6 }] }
|
|
176
175
|
* Deep.getAt(value, 'a.b.c');
|
|
177
|
-
* // => [{ d: 5 }, { d:
|
|
176
|
+
* // => [{ d: 5 }, { d: 6 }]
|
|
178
177
|
* Deep.getAt(value, 'a.b.c[1]');
|
|
179
178
|
* // => { d: 6 }
|
|
180
179
|
* Deep.getAt(value, 'a.b.c[1]?.d');
|
package/dist/cjs/tuple.cjs
CHANGED
|
@@ -23,7 +23,7 @@ var Tuple;
|
|
|
23
23
|
}
|
|
24
24
|
Tuple.of = of;
|
|
25
25
|
/**
|
|
26
|
-
* Returns the item at the given `index` in the
|
|
26
|
+
* Returns the item at the given `index` in the given `tuple`.
|
|
27
27
|
* @param tuple - the tuple to get the item from
|
|
28
28
|
* @param index - the index in of the tuple element
|
|
29
29
|
* @example
|
package/dist/cjs/tuple.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tuple.cjs","sourceRoot":"","sources":["../../_cjs_prepare/tuple.cts"],"names":[],"mappings":";;;;AAAA,oCAAkC;AAQlC,IAAiB,KAAK,
|
|
1
|
+
{"version":3,"file":"tuple.cjs","sourceRoot":"","sources":["../../_cjs_prepare/tuple.cts"],"names":[],"mappings":";;;;AAAA,oCAAkC;AAQlC,IAAiB,KAAK,CAgMrB;AAhMD,WAAiB,KAAK;IA2BpB;;;;;;;;OAQG;IACH,SAAgB,EAAE;QAAiC,gBAAY;aAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;YAAZ,2BAAY;;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,UAAG,CAAC,MAAM,CAAC,KAAK,EAAE,KAAe,EAAE,OAAO,CAAM,CAAC;IAC1D,CAAC;IANe,cAAQ,WAMvB,CAAA;IAED;;;;;;;;;;OAUG;IACH,SAAgB,MAAM,CAGpB,KAAQ;QAAE,gBAAY;aAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;YAAZ,+BAAY;;QACtB,sEAAW,KAAK,0BAAK,MAAM,UAAE;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,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,EAhMgB,KAAK,qBAAL,KAAK,QAgMrB"}
|
package/dist/cjs/tuple.d.cts
CHANGED
|
@@ -12,6 +12,10 @@ export declare namespace Tuple {
|
|
|
12
12
|
* A readonly array that can serve as a source for a Tuple.
|
|
13
13
|
*/
|
|
14
14
|
type Source = readonly unknown[];
|
|
15
|
+
/**
|
|
16
|
+
* Determines whether the given type `T` is a tuple type.
|
|
17
|
+
* @typeparam T - the input type
|
|
18
|
+
*/
|
|
15
19
|
type IsTuple<T> = T extends {
|
|
16
20
|
length: infer L;
|
|
17
21
|
} ? 0 extends L ? false : true : false;
|
|
@@ -33,7 +37,7 @@ export declare namespace Tuple {
|
|
|
33
37
|
*/
|
|
34
38
|
function of<T extends Tuple.NonEmptySource>(...values: T): Tuple<T>;
|
|
35
39
|
/**
|
|
36
|
-
* Returns the item at the given `index` in the
|
|
40
|
+
* Returns the item at the given `index` in the given `tuple`.
|
|
37
41
|
* @param tuple - the tuple to get the item from
|
|
38
42
|
* @param index - the index in of the tuple element
|
|
39
43
|
* @example
|
package/dist/esm/deep.d.mts
CHANGED
|
@@ -68,9 +68,9 @@ export declare function patchWith<T, TE extends T = T, TT = T>(patchItem: Patch<
|
|
|
68
68
|
export declare function patchAtWith<T, P extends Path.Set<T>, TE extends T = T, TT = T>(path: P, patchItem: Patch<Path.Result<TE, P>, Path.Result<TT, P>>): (source: T) => T;
|
|
69
69
|
/**
|
|
70
70
|
* Returns a function that matches a given `value` with the given `matcher`.
|
|
71
|
-
* @typeparam T - the
|
|
71
|
+
* @typeparam T - the input value type
|
|
72
72
|
* @param matcher - a matcher object that matches input values.
|
|
73
|
-
* @param source - the value to
|
|
73
|
+
* @param source - the value to match (parameter of the returned function).
|
|
74
74
|
* @example
|
|
75
75
|
* ```ts
|
|
76
76
|
* const items = [{ a: 1, b: 'a' }, { a: 2, b: 'b' }];
|
|
@@ -96,7 +96,7 @@ export declare function matchWith<T>(matcher: Match<T>): (source: T) => boolean;
|
|
|
96
96
|
export declare function matchAt<T, P extends Path.Get<T>>(source: T, path: P, matcher: Match<Path.Result<T, P>>): boolean;
|
|
97
97
|
/**
|
|
98
98
|
* Returns a function that matches a given `value` with the given `matcher` at the given string `path`.
|
|
99
|
-
* @typeparam T - the
|
|
99
|
+
* @typeparam T - the input value type
|
|
100
100
|
* @typeparam P - the string literal path type in the object
|
|
101
101
|
* @typeparam TE - utility type
|
|
102
102
|
* @param path - the string path in the object
|
|
@@ -112,7 +112,7 @@ export declare function matchAt<T, P extends Path.Get<T>>(source: T, path: P, ma
|
|
|
112
112
|
export declare function matchAtWith<T, P extends Path.Get<T>, TE extends T = T>(path: P, matcher: Match<Path.Result<T & TE, P>>): (source: T) => boolean;
|
|
113
113
|
/**
|
|
114
114
|
* Returns a function that selects a certain shape from a given `value` with the given `selector`.
|
|
115
|
-
* @typeparam T - the
|
|
115
|
+
* @typeparam T - the input value type
|
|
116
116
|
* @typeparam SL - the selector shape type
|
|
117
117
|
* @param selector - a shape indicating the selection from the source values
|
|
118
118
|
* @param source - the value to use the given `selector` on.
|
|
@@ -126,7 +126,7 @@ export declare function matchAtWith<T, P extends Path.Get<T>, TE extends T = T>(
|
|
|
126
126
|
export declare function selectWith<T, SL extends Selector<T>>(selector: Selector.Shape<SL>): (source: T) => Selector.Result<T, SL>;
|
|
127
127
|
/**
|
|
128
128
|
* Returns the result of applying the given `selector` shape to the given `source` value.
|
|
129
|
-
* @typeparam T - the
|
|
129
|
+
* @typeparam T - the input value type
|
|
130
130
|
* @typeparam P - the string literal path type in the object
|
|
131
131
|
* @typeparam SL - the selector shape type
|
|
132
132
|
* @param source - the source value to select from
|
|
@@ -142,7 +142,7 @@ export declare function selectWith<T, SL extends Selector<T>>(selector: Selector
|
|
|
142
142
|
export declare function selectAt<T, P extends Path.Get<T>, SL extends Selector<Path.Result<T, P>>>(source: T, path: P, selector: Selector.Shape<SL>): Selector.Result<Path.Result<T, P>, SL>;
|
|
143
143
|
/**
|
|
144
144
|
* Returns a function that selects a certain shape from a given `value` with the given `selector` at the given string `path`.
|
|
145
|
-
* @typeparam T - the
|
|
145
|
+
* @typeparam T - the input value type
|
|
146
146
|
* @typeparam P - the string literal path type in the object
|
|
147
147
|
* @typeparam SL - the selector shape type
|
|
148
148
|
* @param path - the string path in the object
|
package/dist/esm/deep.mjs
CHANGED
|
@@ -75,9 +75,9 @@ export function patchAtWith(path, patchItem) {
|
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* Returns a function that matches a given `value` with the given `matcher`.
|
|
78
|
-
* @typeparam T - the
|
|
78
|
+
* @typeparam T - the input value type
|
|
79
79
|
* @param matcher - a matcher object that matches input values.
|
|
80
|
-
* @param source - the value to
|
|
80
|
+
* @param source - the value to match (parameter of the returned function).
|
|
81
81
|
* @example
|
|
82
82
|
* ```ts
|
|
83
83
|
* const items = [{ a: 1, b: 'a' }, { a: 2, b: 'b' }];
|
|
@@ -107,7 +107,7 @@ export function matchAt(source, path, matcher) {
|
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Returns a function that matches a given `value` with the given `matcher` at the given string `path`.
|
|
110
|
-
* @typeparam T - the
|
|
110
|
+
* @typeparam T - the input value type
|
|
111
111
|
* @typeparam P - the string literal path type in the object
|
|
112
112
|
* @typeparam TE - utility type
|
|
113
113
|
* @param path - the string path in the object
|
|
@@ -125,7 +125,7 @@ export function matchAtWith(path, matcher) {
|
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
127
|
* Returns a function that selects a certain shape from a given `value` with the given `selector`.
|
|
128
|
-
* @typeparam T - the
|
|
128
|
+
* @typeparam T - the input value type
|
|
129
129
|
* @typeparam SL - the selector shape type
|
|
130
130
|
* @param selector - a shape indicating the selection from the source values
|
|
131
131
|
* @param source - the value to use the given `selector` on.
|
|
@@ -141,7 +141,7 @@ export function selectWith(selector) {
|
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
143
|
* Returns the result of applying the given `selector` shape to the given `source` value.
|
|
144
|
-
* @typeparam T - the
|
|
144
|
+
* @typeparam T - the input value type
|
|
145
145
|
* @typeparam P - the string literal path type in the object
|
|
146
146
|
* @typeparam SL - the selector shape type
|
|
147
147
|
* @param source - the source value to select from
|
|
@@ -159,7 +159,7 @@ export function selectAt(source, path, selector) {
|
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* Returns a function that selects a certain shape from a given `value` with the given `selector` at the given string `path`.
|
|
162
|
-
* @typeparam T - the
|
|
162
|
+
* @typeparam T - the input value type
|
|
163
163
|
* @typeparam P - the string literal path type in the object
|
|
164
164
|
* @typeparam SL - the selector shape type
|
|
165
165
|
* @param path - the string path in the object
|
package/dist/esm/match.d.mts
CHANGED
|
@@ -80,7 +80,7 @@ export declare namespace Match {
|
|
|
80
80
|
*/
|
|
81
81
|
type ArrayTraversalType = `${CompoundType}Item`;
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
83
|
+
* Compound matcher for objects, represented as an array starting with a compound type keyword.
|
|
84
84
|
* @typeparam T - the input value type
|
|
85
85
|
* @typeparam C - utility type
|
|
86
86
|
* @typeparam P - the parent type
|
|
@@ -132,7 +132,7 @@ export declare namespace Match {
|
|
|
132
132
|
* match(input, { a: 2 }) // => false
|
|
133
133
|
* match(input, { a: (v) => v > 10 }) // => false
|
|
134
134
|
* match(input, { b: { c: true }}) // => true
|
|
135
|
-
* match(input,
|
|
135
|
+
* match(input, ['every', { a: (v) => v > 0 }, { b: { c: true } }]) // => true
|
|
136
136
|
* match(input, { b: { c: (v, parent, root) => v && parent.d.length > 0 && root.a > 0 } })
|
|
137
137
|
* // => true
|
|
138
138
|
* ```
|
package/dist/esm/match.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { isPlainObj, } from '@rimbu/base';
|
|
|
13
13
|
* match(input, { a: 2 }) // => false
|
|
14
14
|
* match(input, { a: (v) => v > 10 }) // => false
|
|
15
15
|
* match(input, { b: { c: true }}) // => true
|
|
16
|
-
* match(input,
|
|
16
|
+
* match(input, ['every', { a: (v) => v > 0 }, { b: { c: true } }]) // => true
|
|
17
17
|
* match(input, { b: { c: (v, parent, root) => v && parent.d.length > 0 && root.a > 0 } })
|
|
18
18
|
* // => true
|
|
19
19
|
* ```
|
package/dist/esm/patch.d.mts
CHANGED
|
@@ -82,7 +82,7 @@ export declare namespace Patch {
|
|
|
82
82
|
* patch(input, [{ a: 2 }]) // => { a: 2, b: { c: true, d: 'a' } }
|
|
83
83
|
* patch(input, [{ b: [{ c: (v) => !v }] }] )
|
|
84
84
|
* // => { a: 1, b: { c: false, d: 'a' } }
|
|
85
|
-
* patch(input
|
|
85
|
+
* patch(input, [{ a: (v) => v + 1, b: [{ d: 'q' }] }] )
|
|
86
86
|
* // => { a: 2, b: { c: true, d: 'q' } }
|
|
87
87
|
* ```
|
|
88
88
|
*/
|
package/dist/esm/patch.mjs
CHANGED
|
@@ -17,7 +17,7 @@ import { isPlainObj, } from '@rimbu/base';
|
|
|
17
17
|
* patch(input, [{ a: 2 }]) // => { a: 2, b: { c: true, d: 'a' } }
|
|
18
18
|
* patch(input, [{ b: [{ c: (v) => !v }] }] )
|
|
19
19
|
* // => { a: 1, b: { c: false, d: 'a' } }
|
|
20
|
-
* patch(input
|
|
20
|
+
* patch(input, [{ a: (v) => v + 1, b: [{ d: 'q' }] }] )
|
|
21
21
|
* // => { a: 2, b: { c: true, d: 'q' } }
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
package/dist/esm/path.d.mts
CHANGED
|
@@ -44,7 +44,6 @@ export declare namespace Path {
|
|
|
44
44
|
* @typeparam T - the source type
|
|
45
45
|
* @typeparam Write - if true the path should be writable (no optional chaining)
|
|
46
46
|
* @typeparam Maybe - if true the value at the current path is optional
|
|
47
|
-
* @typeparam First - if true this is the root call
|
|
48
47
|
*/
|
|
49
48
|
type NonOptional<T, Write extends boolean, Maybe extends boolean> = Tuple.IsTuple<T> extends true ? Path.Internal.Tup<T, Write, Maybe> : T extends readonly any[] ? Write extends false ? Path.Internal.Arr<T> : never : IsPlainObj<T> extends true ? Path.Internal.Obj<T, Write, Maybe> : never;
|
|
50
49
|
/**
|
|
@@ -72,7 +71,7 @@ export declare namespace Path {
|
|
|
72
71
|
[K in keyof T]: `${K & string}${Path.Internal.Generic<T[K], Write, Write extends true ? false : Path.Internal.IsOptional<T[K], true, Maybe>>}`;
|
|
73
72
|
}[keyof T];
|
|
74
73
|
/**
|
|
75
|
-
* Determines the allowed path part
|
|
74
|
+
* Determines the allowed path part separator based on the input types.
|
|
76
75
|
* @typeparam First - if true, this is the first call
|
|
77
76
|
* @typeparam Maybe - if true, the value is optional
|
|
78
77
|
* @typeparam IsArray - if true, the value is an array
|
|
@@ -93,7 +92,7 @@ export declare namespace Path {
|
|
|
93
92
|
type MaybeValue<T, Maybe extends boolean> = Maybe extends true ? T | undefined : T;
|
|
94
93
|
/**
|
|
95
94
|
* Utility type to only add non-empty string types to a string array.
|
|
96
|
-
* @
|
|
95
|
+
* @typeparam A - the input string array
|
|
97
96
|
* @typeparam T - the string value to optionally add
|
|
98
97
|
*/
|
|
99
98
|
type AppendIfNotEmpty<A extends string[], T extends string> = T extends '' ? A : [
|
|
@@ -172,9 +171,9 @@ export declare namespace Path {
|
|
|
172
171
|
* ```ts
|
|
173
172
|
* const value = { a: { b: { c: [{ d: 5 }, { d: 6 }] } } }
|
|
174
173
|
* Deep.getAt(value, 'a.b');
|
|
175
|
-
* // => { c: 5 }
|
|
174
|
+
* // => { c: [{ d: 5 }, { d: 6 }] }
|
|
176
175
|
* Deep.getAt(value, 'a.b.c');
|
|
177
|
-
* // => [{ d: 5 }, { d:
|
|
176
|
+
* // => [{ d: 5 }, { d: 6 }]
|
|
178
177
|
* Deep.getAt(value, 'a.b.c[1]');
|
|
179
178
|
* // => { d: 6 }
|
|
180
179
|
* Deep.getAt(value, 'a.b.c[1]?.d');
|
package/dist/esm/path.mjs
CHANGED
|
@@ -27,9 +27,9 @@ export var Path;
|
|
|
27
27
|
* ```ts
|
|
28
28
|
* const value = { a: { b: { c: [{ d: 5 }, { d: 6 }] } } }
|
|
29
29
|
* Deep.getAt(value, 'a.b');
|
|
30
|
-
* // => { c: 5 }
|
|
30
|
+
* // => { c: [{ d: 5 }, { d: 6 }] }
|
|
31
31
|
* Deep.getAt(value, 'a.b.c');
|
|
32
|
-
* // => [{ d: 5 }, { d:
|
|
32
|
+
* // => [{ d: 5 }, { d: 6 }]
|
|
33
33
|
* Deep.getAt(value, 'a.b.c[1]');
|
|
34
34
|
* // => { d: 6 }
|
|
35
35
|
* Deep.getAt(value, 'a.b.c[1]?.d');
|
package/dist/esm/path.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.mjs","sourceRoot":"","sources":["../../src/path.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAc,MAAM,gBAAgB,CAAC;AAGlD,MAAM,KAAW,IAAI,
|
|
1
|
+
{"version":3,"file":"path.mjs","sourceRoot":"","sources":["../../src/path.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAc,MAAM,gBAAgB,CAAC;AAGlD,MAAM,KAAW,IAAI,CAoTpB;AApTD,WAAiB,IAAI;IAmSnB;;OAEG;IACU,qBAAgB,GAAG,gBAAgB,CAAC;IAOjD;;;OAGG;IACH,SAAgB,WAAW,CAAC,IAAY;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC3C,CAAC;IAFe,gBAAW,cAE1B,CAAA;AACH,CAAC,EApTgB,IAAI,KAAJ,IAAI,QAoTpB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,KAAK,CACnB,MAAS,EACT,IAAO;IAEP,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QAChB,kDAAkD;QAClD,OAAO,MAAa,CAAC;IACvB,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAErC,sCAAsC;IACtC,IAAI,MAAM,GAAG,MAAa,CAAC;IAE3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,SAAS,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACtD,0BAA0B;YAC1B,SAAS;QACX,CAAC;QAED,IAAI,SAAS,KAAK,MAAM,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;YAC5C,2FAA2F;YAC3F,OAAO,SAAgB,CAAC;QAC1B,CAAC;QAED,sCAAsC;QACtC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,OAAO,CACrB,MAAS,EACT,IAAO,EACP,SAA0D;IAE1D,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,SAAgB,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAErC,mDAAmD;IACnD,SAAS,eAAe,CAAC,KAAa,EAAE,MAAW;QACjD,IAAI,KAAK,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;YAC3B,oDAAoD;YACpD,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAE1B,IAAI,SAAS,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;YACtC,6BAA6B;YAC7B,OAAO,eAAe,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;QAC5C,CAAC;QAED,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,kDAAkD;YAClD,OAAO,eAAe,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;QAC5C,CAAC;QAED,gGAAgG;QAChG,MAAM,MAAM,GAAG;YACb,CAAC,IAAI,CAAC,EAAE,eAAe,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;SACjD,CAAC;QAEF,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,wEAAwE;YACxE,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,mEAAmE;QACnE,OAAO,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
package/dist/esm/tuple.d.mts
CHANGED
|
@@ -12,6 +12,10 @@ export declare namespace Tuple {
|
|
|
12
12
|
* A readonly array that can serve as a source for a Tuple.
|
|
13
13
|
*/
|
|
14
14
|
type Source = readonly unknown[];
|
|
15
|
+
/**
|
|
16
|
+
* Determines whether the given type `T` is a tuple type.
|
|
17
|
+
* @typeparam T - the input type
|
|
18
|
+
*/
|
|
15
19
|
type IsTuple<T> = T extends {
|
|
16
20
|
length: infer L;
|
|
17
21
|
} ? 0 extends L ? false : true : false;
|
|
@@ -33,7 +37,7 @@ export declare namespace Tuple {
|
|
|
33
37
|
*/
|
|
34
38
|
function of<T extends Tuple.NonEmptySource>(...values: T): Tuple<T>;
|
|
35
39
|
/**
|
|
36
|
-
* Returns the item at the given `index` in the
|
|
40
|
+
* Returns the item at the given `index` in the given `tuple`.
|
|
37
41
|
* @param tuple - the tuple to get the item from
|
|
38
42
|
* @param index - the index in of the tuple element
|
|
39
43
|
* @example
|
package/dist/esm/tuple.mjs
CHANGED
|
@@ -15,7 +15,7 @@ export var Tuple;
|
|
|
15
15
|
}
|
|
16
16
|
Tuple.of = of;
|
|
17
17
|
/**
|
|
18
|
-
* Returns the item at the given `index` in the
|
|
18
|
+
* Returns the item at the given `index` in the given `tuple`.
|
|
19
19
|
* @param tuple - the tuple to get the item from
|
|
20
20
|
* @param index - the index in of the tuple element
|
|
21
21
|
* @example
|
package/dist/esm/tuple.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tuple.mjs","sourceRoot":"","sources":["../../src/tuple.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAQlC,MAAM,KAAW,KAAK,
|
|
1
|
+
{"version":3,"file":"tuple.mjs","sourceRoot":"","sources":["../../src/tuple.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAQlC,MAAM,KAAW,KAAK,CAgMrB;AAhMD,WAAiB,KAAK;IA2BpB;;;;;;;;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,EAhMgB,KAAK,KAAL,KAAK,QAgMrB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rimbu/deep",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "Tools to use handle plain JS objects as immutable objects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"immutable",
|
|
@@ -53,17 +53,12 @@
|
|
|
53
53
|
],
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "yarn clean && yarn bundle",
|
|
56
|
-
"build:deno": "yarn bundle:deno-prepare && yarn bundle:deno-convert && yarn bundle:deno-move && yarn bundle:deno-clean",
|
|
57
56
|
"bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:bun",
|
|
58
57
|
"bundle:bun": "node ../../config/bunnify.mjs -mode bun",
|
|
59
58
|
"bundle:cjs": "yarn bundle:cjs-prepare && yarn bundle:cjs-build && yarn bundle:cjs-clean",
|
|
60
59
|
"bundle:cjs-prepare": "node ../../config/bunnify.mjs -mode cjs",
|
|
61
60
|
"bundle:cjs-build": "tsc -p tsconfig.cjs.json",
|
|
62
61
|
"bundle:cjs-clean": "rimraf _cjs_prepare",
|
|
63
|
-
"bundle:deno-prepare": "node ../../config/prepare-denoify.mjs",
|
|
64
|
-
"bundle:deno-convert": "denoify --src _deno_prepare/src",
|
|
65
|
-
"bundle:deno-move": "rimraf ../../deno_dist/deep && mv deno_dist ../../deno_dist/deep",
|
|
66
|
-
"bundle:deno-clean": "rimraf _deno_prepare",
|
|
67
62
|
"bundle:esm": "tsc --p tsconfig.esm.json",
|
|
68
63
|
"clean": "rimraf dist",
|
|
69
64
|
"extract-api": "tsx ../../config/api-extractor.ts config/api-extractor.main.json",
|
|
@@ -78,12 +73,12 @@
|
|
|
78
73
|
"typecheck": "tsc"
|
|
79
74
|
},
|
|
80
75
|
"dependencies": {
|
|
81
|
-
"@rimbu/base": "^2.0.
|
|
82
|
-
"@rimbu/common": "^2.0.
|
|
83
|
-
"tslib": "^2.
|
|
76
|
+
"@rimbu/base": "^2.0.4",
|
|
77
|
+
"@rimbu/common": "^2.0.4",
|
|
78
|
+
"tslib": "^2.8.1"
|
|
84
79
|
},
|
|
85
80
|
"publishConfig": {
|
|
86
81
|
"access": "public"
|
|
87
82
|
},
|
|
88
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "bc6bc82af86461c423ba459d6d9809efdd5ffd61"
|
|
89
84
|
}
|
package/src/deep.mts
CHANGED
|
@@ -90,9 +90,9 @@ export function patchAtWith<T, P extends Path.Set<T>, TE extends T = T, TT = T>(
|
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* Returns a function that matches a given `value` with the given `matcher`.
|
|
93
|
-
* @typeparam T - the
|
|
93
|
+
* @typeparam T - the input value type
|
|
94
94
|
* @param matcher - a matcher object that matches input values.
|
|
95
|
-
* @param source - the value to
|
|
95
|
+
* @param source - the value to match (parameter of the returned function).
|
|
96
96
|
* @example
|
|
97
97
|
* ```ts
|
|
98
98
|
* const items = [{ a: 1, b: 'a' }, { a: 2, b: 'b' }];
|
|
@@ -128,7 +128,7 @@ export function matchAt<T, P extends Path.Get<T>>(
|
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
130
|
* Returns a function that matches a given `value` with the given `matcher` at the given string `path`.
|
|
131
|
-
* @typeparam T - the
|
|
131
|
+
* @typeparam T - the input value type
|
|
132
132
|
* @typeparam P - the string literal path type in the object
|
|
133
133
|
* @typeparam TE - utility type
|
|
134
134
|
* @param path - the string path in the object
|
|
@@ -150,7 +150,7 @@ export function matchAtWith<T, P extends Path.Get<T>, TE extends T = T>(
|
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
152
|
* Returns a function that selects a certain shape from a given `value` with the given `selector`.
|
|
153
|
-
* @typeparam T - the
|
|
153
|
+
* @typeparam T - the input value type
|
|
154
154
|
* @typeparam SL - the selector shape type
|
|
155
155
|
* @param selector - a shape indicating the selection from the source values
|
|
156
156
|
* @param source - the value to use the given `selector` on.
|
|
@@ -169,7 +169,7 @@ export function selectWith<T, SL extends Selector<T>>(
|
|
|
169
169
|
|
|
170
170
|
/**
|
|
171
171
|
* Returns the result of applying the given `selector` shape to the given `source` value.
|
|
172
|
-
* @typeparam T - the
|
|
172
|
+
* @typeparam T - the input value type
|
|
173
173
|
* @typeparam P - the string literal path type in the object
|
|
174
174
|
* @typeparam SL - the selector shape type
|
|
175
175
|
* @param source - the source value to select from
|
|
@@ -196,7 +196,7 @@ export function selectAt<
|
|
|
196
196
|
|
|
197
197
|
/**
|
|
198
198
|
* Returns a function that selects a certain shape from a given `value` with the given `selector` at the given string `path`.
|
|
199
|
-
* @typeparam T - the
|
|
199
|
+
* @typeparam T - the input value type
|
|
200
200
|
* @typeparam P - the string literal path type in the object
|
|
201
201
|
* @typeparam SL - the selector shape type
|
|
202
202
|
* @param path - the string path in the object
|
package/src/match.mts
CHANGED
|
@@ -134,7 +134,7 @@ export namespace Match {
|
|
|
134
134
|
export type ArrayTraversalType = `${CompoundType}Item`;
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
|
-
*
|
|
137
|
+
* Compound matcher for objects, represented as an array starting with a compound type keyword.
|
|
138
138
|
* @typeparam T - the input value type
|
|
139
139
|
* @typeparam C - utility type
|
|
140
140
|
* @typeparam P - the parent type
|
|
@@ -194,7 +194,7 @@ export namespace Match {
|
|
|
194
194
|
* match(input, { a: 2 }) // => false
|
|
195
195
|
* match(input, { a: (v) => v > 10 }) // => false
|
|
196
196
|
* match(input, { b: { c: true }}) // => true
|
|
197
|
-
* match(input,
|
|
197
|
+
* match(input, ['every', { a: (v) => v > 0 }, { b: { c: true } }]) // => true
|
|
198
198
|
* match(input, { b: { c: (v, parent, root) => v && parent.d.length > 0 && root.a > 0 } })
|
|
199
199
|
* // => true
|
|
200
200
|
* ```
|
package/src/patch.mts
CHANGED
|
@@ -110,7 +110,7 @@ export namespace Patch {
|
|
|
110
110
|
* patch(input, [{ a: 2 }]) // => { a: 2, b: { c: true, d: 'a' } }
|
|
111
111
|
* patch(input, [{ b: [{ c: (v) => !v }] }] )
|
|
112
112
|
* // => { a: 1, b: { c: false, d: 'a' } }
|
|
113
|
-
* patch(input
|
|
113
|
+
* patch(input, [{ a: (v) => v + 1, b: [{ d: 'q' }] }] )
|
|
114
114
|
* // => { a: 2, b: { c: true, d: 'q' } }
|
|
115
115
|
* ```
|
|
116
116
|
*/
|
package/src/path.mts
CHANGED
|
@@ -75,7 +75,6 @@ export namespace Path {
|
|
|
75
75
|
* @typeparam T - the source type
|
|
76
76
|
* @typeparam Write - if true the path should be writable (no optional chaining)
|
|
77
77
|
* @typeparam Maybe - if true the value at the current path is optional
|
|
78
|
-
* @typeparam First - if true this is the root call
|
|
79
78
|
*/
|
|
80
79
|
export type NonOptional<T, Write extends boolean, Maybe extends boolean> =
|
|
81
80
|
Tuple.IsTuple<T> extends true
|
|
@@ -129,7 +128,7 @@ export namespace Path {
|
|
|
129
128
|
}[keyof T];
|
|
130
129
|
|
|
131
130
|
/**
|
|
132
|
-
* Determines the allowed path part
|
|
131
|
+
* Determines the allowed path part separator based on the input types.
|
|
133
132
|
* @typeparam First - if true, this is the first call
|
|
134
133
|
* @typeparam Maybe - if true, the value is optional
|
|
135
134
|
* @typeparam IsArray - if true, the value is an array
|
|
@@ -179,7 +178,7 @@ export namespace Path {
|
|
|
179
178
|
|
|
180
179
|
/**
|
|
181
180
|
* Utility type to only add non-empty string types to a string array.
|
|
182
|
-
* @
|
|
181
|
+
* @typeparam A - the input string array
|
|
183
182
|
* @typeparam T - the string value to optionally add
|
|
184
183
|
*/
|
|
185
184
|
export type AppendIfNotEmpty<
|
|
@@ -326,9 +325,9 @@ export namespace Path {
|
|
|
326
325
|
* ```ts
|
|
327
326
|
* const value = { a: { b: { c: [{ d: 5 }, { d: 6 }] } } }
|
|
328
327
|
* Deep.getAt(value, 'a.b');
|
|
329
|
-
* // => { c: 5 }
|
|
328
|
+
* // => { c: [{ d: 5 }, { d: 6 }] }
|
|
330
329
|
* Deep.getAt(value, 'a.b.c');
|
|
331
|
-
* // => [{ d: 5 }, { d:
|
|
330
|
+
* // => [{ d: 5 }, { d: 6 }]
|
|
332
331
|
* Deep.getAt(value, 'a.b.c[1]');
|
|
333
332
|
* // => { d: 6 }
|
|
334
333
|
* Deep.getAt(value, 'a.b.c[1]?.d');
|
package/src/tuple.mts
CHANGED
|
@@ -17,6 +17,10 @@ export namespace Tuple {
|
|
|
17
17
|
*/
|
|
18
18
|
export type Source = readonly unknown[];
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Determines whether the given type `T` is a tuple type.
|
|
22
|
+
* @typeparam T - the input type
|
|
23
|
+
*/
|
|
20
24
|
export type IsTuple<T> = T extends { length: infer L }
|
|
21
25
|
? 0 extends L
|
|
22
26
|
? false
|
|
@@ -43,7 +47,7 @@ export namespace Tuple {
|
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
/**
|
|
46
|
-
* Returns the item at the given `index` in the
|
|
50
|
+
* Returns the item at the given `index` in the given `tuple`.
|
|
47
51
|
* @param tuple - the tuple to get the item from
|
|
48
52
|
* @param index - the index in of the tuple element
|
|
49
53
|
* @example
|