@rimbu/common 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,122 +1,348 @@
1
1
  <p align="center">
2
- <img src="https://github.com/rimbu-org/rimbu/raw/main/assets/rimbu_logo.svg" />
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
- [![npm version](https://badge.fury.io/js/@rimbu%2Fcommon.svg)](https://www.npmjs.com/package/@rimbu/common) [![Deno](https://shield.deno.dev/x/rimbu)](http://deno.land/x/rimbu)
5
+ <div align="center">
6
6
 
7
- ![Licence](https://img.shields.io/github/license/rimbu-org/rimbu)
7
+ [![npm version](https://badge.fury.io/js/@rimbu%2Fcommon.svg)](https://www.npmjs.com/package/@rimbu/common)
8
+ ![License](https://img.shields.io/github/license/rimbu-org/rimbu)
9
+ ![Types Included](https://img.shields.io/badge/TypeScript-ready-blue)
10
+ ![Node](https://img.shields.io/badge/Node-18+-6DA55F?logo=node.js&logoColor=white)
11
+ ![Deno](https://shield.deno.dev/x/rimbu)
12
+ ![Bun](https://img.shields.io/badge/Bun-%23000000.svg)
13
+ ![ESM + CJS](https://img.shields.io/badge/modules-ESM%20%2B%20CJS-informational)
8
14
 
9
- # @rimbu/common
15
+ </div>
10
16
 
11
- Welcome to `@rimbu/common`! This package exports essential types and utilities that are widely used across various Rimbu packages. It provides a robust foundation for building efficient and reliable applications.
17
+ # `@rimbu/common`
12
18
 
13
- ### Overview of most important Exported Types:
19
+ **Shared utility types and helpers for the Rimbu ecosystem.**
14
20
 
15
- | Name | Description |
16
- | --------------- | ----------------------------------------------------------------------------------------------------- |
17
- | `CollectFun` | Types and values used in various `collect` methods within collections. |
18
- | `Comp` | Interface and default implementations of comparison functions for ordering/sorting values. |
19
- | `Eq` | Interface and default implementations of equality functions for checking value equality. |
20
- | `Err` | Functions to easily create error-throwing behavior as fallback values. |
21
- | `FastIterable` | An `Iterable` implementation that offers better performance than standard iterables. |
22
- | `IndexRange` | Utilities for selecting index ranges in indexed collections. |
23
- | `OptLazy` | A utility to provide values that can optionally be lazy. |
24
- | `Range` | Utility types to specify ranges for comparable types. |
25
- | `Reducer` | An API to create reusable logic pieces that process data streams, which can be processed in parallel. |
26
- | `TraverseState` | A utility for loops to maintain traversal state. |
27
- | `Update` | A standard way to update a value. |
21
+ `@rimbu/common` provides the low-level **building blocks** used throughout Rimbu:
28
22
 
29
- ### Documentation
23
+ - **Equality & comparison** helpers (`Eq`, `Comp`) for consistent value semantics.
24
+ - **Range & index utilities** (`Range`, `IndexRange`) for working with slices and windows.
25
+ - **Lazy values & updates** (`OptLazy`, `OptLazyOr`, `AsyncOptLazy`, `Update`) for ergonomic APIs.
26
+ - **Traversal helpers** (`CollectFun`, `TraverseState`) for efficient collection operations.
27
+ - **Type-level utilities** (`SuperOf`, `SubOf`, `RelatedTo`, `ArrayNonEmpty`, `StringNonEmpty`, `ToJSON`) for stronger TypeScript modelling.
30
28
 
31
- For complete documentation, please visit the [Rimbu Docs](https://rimbu.org), or directly explore the [Rimbu Common API Docs](https://rimbu.org/api/rimbu/common).
29
+ Use this package directly in your own code, or consume it indirectly when using other Rimbu packages.
32
30
 
33
- ### Try It Out
31
+ ---
34
32
 
35
- Experience `@rimbu/common` in action! [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) on CodeSandBox.
33
+ ## Table of Contents
36
34
 
37
- ## Installation
35
+ 1. [Why `@rimbu/common`?](#why-rimbucommon)
36
+ 2. [Feature Highlights](#feature-highlights)
37
+ 3. [Quick Start](#quick-start)
38
+ 4. [Core Concepts & Types](#core-concepts--types)
39
+ 5. [Working with Equality & Comparison](#working-with-equality--comparison)
40
+ 6. [Lazy Values, Updates & Async](#lazy-values-updates--async)
41
+ 7. [Ranges & Indices](#ranges--indices)
42
+ 8. [Type Utilities](#type-utilities)
43
+ 9. [Installation](#installation)
44
+ 10. [Ecosystem & Links](#ecosystem--links)
45
+ 11. [Contributing](#contributing)
46
+ 12. [License](#license)
38
47
 
39
- ### Compabitity
48
+ ---
40
49
 
41
- - [`Node` ![NodeJS](https://img.shields.io/badge/node.js-6DA55F?logo=node.js&logoColor=white)](https://nodejs.org)
42
- - [`Deno` ![Deno JS](https://img.shields.io/badge/deno%20js-000000?logo=deno&logoColor=white)](https://deno.com/runtime)
43
- - [`Bun` ![Bun](https://img.shields.io/badge/Bun-%23000000.svg?logoColor=white)](https://bun.sh/)
44
- - `Web` ![HTML5](https://img.shields.io/badge/html5-%23E34F26.svg?logoColor=white)
50
+ ## Why `@rimbu/common`?
45
51
 
46
- ### Package Managers
52
+ Many Rimbu collections (and your own APIs) need **consistent behaviour** for:
47
53
 
48
- **Yarn:**
54
+ - Comparing values (e.g. custom sort orders, structural vs reference equality).
55
+ - Handling optional or deferred values (lazy evaluation, async computations).
56
+ - Working with index or value ranges in a uniform way.
57
+ - Expressing richer type relationships in TypeScript.
49
58
 
50
- ```sh
51
- yarn add @rimbu/common
59
+ Instead of re‑implementing these patterns, `@rimbu/common` provides:
60
+
61
+ - **Well-tested primitives** shared across all Rimbu packages.
62
+ - **Reusable utilities** you can depend on directly in your own libraries and apps.
63
+ - **Type-safe building blocks** that integrate smoothly with the rest of the Rimbu ecosystem.
64
+
65
+ ---
66
+
67
+ ## Feature Highlights
68
+
69
+ - **Pluggable equality & comparison** – `Eq` and `Comp` instances for primitives, objects, iterables, JSON, case-insensitive strings, and more.
70
+ - **Lazy & async helpers** – `OptLazy`, `OptLazyOr`, `AsyncOptLazy`, `MaybePromise` to keep APIs flexible without sacrificing clarity.
71
+ - **Declarative ranges** – `Range<T>` and `IndexRange` to describe open/closed and offset-based ranges in a single, typed shape.
72
+ - **Traversal utilities** – `CollectFun` and `TraverseState` for customizable, short‑circuitable traversals.
73
+ - **Type-level helpers** – utilities like `ArrayNonEmpty`, `StringNonEmpty`, and `ToJSON` to express invariants and serializable shapes.
74
+
75
+ ---
76
+
77
+ ## Quick Start
78
+
79
+ ```ts
80
+ import { Eq, Comp, OptLazy, Update } from '@rimbu/common';
81
+
82
+ // Equality: deep structural comparison
83
+ const eq = Eq.anyDeepEq<Record<string, unknown>>();
84
+ console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }));
85
+ // => true
86
+
87
+ // Comparison: natural number ordering
88
+ const numComp = Comp.numberComp();
89
+ console.log(numComp.compare(3, 5) < 0);
90
+ // => true
91
+
92
+ // Lazy values: compute only when needed
93
+ const lazyValue = OptLazy(() => 1 + 2);
94
+ console.log(lazyValue); // 3
95
+
96
+ // Updates: accept either a value or an updater function
97
+ const next = Update(1, v => v + 1);
98
+ console.log(next); // 2
52
99
  ```
53
100
 
54
- **npm:**
101
+ Try Rimbu (including `@rimbu/common`) live in the browser using the
102
+ [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).
55
103
 
56
- ```sh
57
- npm install @rimbu/common
104
+ ---
105
+
106
+ ## Core Concepts & Types
107
+
108
+ ### Exported Types & Utilities
109
+
110
+ | Name | Description |
111
+ | ------------------ | --------------------------------------------------------------------------------------------------- |
112
+ | `CollectFun` | Types used by `collect`-style functions to map/filter in a single pass with skip & halt support. |
113
+ | `AsyncCollectFun` | Asynchronous version of `CollectFun`, returning `MaybePromise` of a collected value or skip token. |
114
+ | `Comp` | Interface and implementations for comparing values (ordering / sorting). |
115
+ | `Eq` | Interface and implementations for checking value equality. |
116
+ | `Err`, `ErrBase` | Helpers to throw consistent custom errors from fallback handlers. |
117
+ | `IndexRange` | Range specification for numeric indices (e.g. slicing arrays or collections). |
118
+ | `Range<T>` | Range specification for ordered values of type `T`. |
119
+ | `OptLazy` | A value or a function returning a value (lazy). |
120
+ | `OptLazyOr` | Like `OptLazy`, but can return a provided default value instead. |
121
+ | `AsyncOptLazy` | Potentially lazy and/or async values built on `OptLazy` + `MaybePromise`. |
122
+ | `MaybePromise<T>` | A value of type `T` or a `Promise<T>`. |
123
+ | `TraverseState` | Object to track progress & early termination in traversals. |
124
+ | `Update` | Value or updater function used to derive a new value from the old one. |
125
+ | `SuperOf`, `SubOf` | Type utilities for expressing upper/lower bounds between types. |
126
+ | `RelatedTo` | Type utility accepting related types where one extends the other. |
127
+ | `ArrayNonEmpty` | Tuple type representing non-empty arrays. |
128
+ | `StringNonEmpty` | Type representing non-empty string types. |
129
+ | `ToJSON` | Helper interface for JSON-serializable wrapper objects. |
130
+
131
+ See the full [Common API reference](https://rimbu.org/api/rimbu/common) for all members and overloads.
132
+
133
+ ---
134
+
135
+ ## Working with Equality & Comparison
136
+
137
+ ### Equality with `Eq`
138
+
139
+ ```ts
140
+ import { Eq } from '@rimbu/common';
141
+
142
+ // Deep structural equality
143
+ const deepEq = Eq.anyDeepEq<Record<string, unknown>>();
144
+ console.log(deepEq({ a: 1, b: 2 }, { b: 2, a: 1 }));
145
+ // => true
146
+
147
+ // Shallow equality: one level into objects / iterables
148
+ const shallowEq = Eq.anyShallowEq<Record<string, unknown>>();
149
+ console.log(shallowEq({ a: 1, b: 2 }, { b: 2, a: 1 }));
150
+ // => true
151
+
152
+ // Flat equality: composed values compared using Object.is
153
+ const flatEq = Eq.anyFlatEq<Record<string, unknown>>();
154
+ console.log(flatEq({ a: 1, b: 2 }, { b: 2, a: 1 }));
155
+ // => false
156
+
157
+ // Case-insensitive string equality
158
+ const ci = Eq.stringCaseInsentitiveEq();
159
+ console.log(ci('AbC', 'aBc'));
160
+ // => true
58
161
  ```
59
162
 
60
- **Bun:**
163
+ ### Comparison with `Comp`
61
164
 
62
- ```sh
63
- bun add @rimbu/common
165
+ ```ts
166
+ import { Comp } from '@rimbu/common';
167
+
168
+ // Numbers: natural ordering with special handling for NaN and infinities
169
+ const numberComp = Comp.numberComp();
170
+ numberComp.compare(3, 5); // < 0
171
+
172
+ // Strings: locale-aware comparison
173
+ const stringComp = Comp.stringComp('en');
174
+ stringComp.compare('a', 'b'); // < 0
175
+
176
+ // Deep comparison of arbitrary values
177
+ const anyDeepComp = Comp.anyDeepComp<unknown>();
178
+ anyDeepComp.compare({ a: 1 }, { a: 1 }); // 0
179
+
180
+ // Convert a comparison into an equality function
181
+ const objectEq = Comp.toEq(Comp.objectComp());
182
+ console.log(objectEq({ a: 1, b: 2 }, { b: 2, a: 1 }));
183
+ // => true
64
184
  ```
65
185
 
66
- ### Deno Setup
186
+ ---
67
187
 
68
- Create or edit `import_map.json` in your project root:
188
+ ## Lazy Values, Updates & Async
69
189
 
70
- ```json
71
- {
72
- "imports": {
73
- "@rimbu/": "https://deno.land/x/rimbu@x.y.z/"
74
- }
75
- }
190
+ ### `OptLazy` and `OptLazyOr`
191
+
192
+ ```ts
193
+ import { OptLazy, OptLazyOr } from '@rimbu/common';
194
+
195
+ // Eager or lazy values
196
+ OptLazy(1); // => 1
197
+ OptLazy(() => 1); // => 1
198
+
199
+ // With a default "other" value
200
+ OptLazyOr(1, 'a'); // => 1
201
+ OptLazyOr(() => 1, 'a'); // => 1
202
+ OptLazyOr(none => none, 'a'); // => 'a'
76
203
  ```
77
204
 
78
- _Replace `x.y.z` with the desired version._
205
+ ### `Update`
206
+
207
+ ```ts
208
+ import { Update } from '@rimbu/common';
209
+
210
+ Update(1, 2); // => 2
211
+ Update(1, () => 10); // => 10
212
+ Update(1, v => v + 1); // => 2
213
+ ```
79
214
 
80
- In this way you can use relative imports from Rimbu in your code, like so:
215
+ ### `AsyncOptLazy` and `MaybePromise`
81
216
 
82
217
  ```ts
83
- import { List } from '@rimbu/core/mod.ts';
84
- import { HashMap } from '@rimbu/hashed/mod.ts';
218
+ import { AsyncOptLazy } from '@rimbu/common';
219
+
220
+ // Get a value or promised value
221
+ await AsyncOptLazy.toPromise(1); // Promise(1)
222
+ await AsyncOptLazy.toPromise(() => 1); // Promise(1)
223
+ await AsyncOptLazy.toPromise(async () => 1); // Promise(1)
224
+ await AsyncOptLazy.toPromise(Promise.resolve(1)); // Promise(1)
85
225
  ```
86
226
 
87
- Note that for sub-packages, due to conversion limitations it is needed to import the `index.ts` instead of `mod.ts`, like so:
227
+ ---
228
+
229
+ ## Ranges & Indices
230
+
231
+ ### `Range<T>`
88
232
 
89
233
  ```ts
90
- import { HashMap } from '@rimbu/hashed/map/index.ts';
234
+ import { Range } from '@rimbu/common';
235
+
236
+ // Inclusive start, exclusive end
237
+ const r1: Range<number> = { start: [0, true], end: [10, false] };
238
+
239
+ // Only end (inclusive by default)
240
+ const r2: Range<number> = { end: 5 };
241
+
242
+ // Normalize for easier handling
243
+ const normalized = Range.getNormalizedRange(r1);
244
+ // => { start: [0, true], end: [10, false] }
91
245
  ```
92
246
 
93
- To run your script (let's assume the entry point is in `src/main.ts`):
247
+ ### `IndexRange`
94
248
 
95
- `deno run --import-map import_map.json src/main.ts`
249
+ ```ts
250
+ import { IndexRange } from '@rimbu/common';
251
+
252
+ const ir: IndexRange = { start: [0, true], amount: 3 };
253
+
254
+ // Extract concrete indices for a given length
255
+ IndexRange.getIndicesFor(ir, 10); // [0, 2]
256
+ ```
257
+
258
+ ---
96
259
 
97
- ## Usage
260
+ ## Type Utilities
98
261
 
99
262
  ```ts
100
- import { Eq } from '@rimbu/common';
263
+ import type {
264
+ SuperOf,
265
+ SubOf,
266
+ RelatedTo,
267
+ ArrayNonEmpty,
268
+ StringNonEmpty,
269
+ ToJSON,
270
+ } from '@rimbu/common';
271
+
272
+ type A = SuperOf<string, 'a' | 'b'>; // string
273
+ type B = SubOf<'a' | 'b', string>; // 'a' | 'b'
274
+ type R = RelatedTo<'a', string>; // 'a' | string
275
+
276
+ type NonEmptyNumbers = ArrayNonEmpty<number>; // [number, ...number[]]
277
+ type NonEmptyString = StringNonEmpty<'a' | ''>; // 'a'
278
+
279
+ interface UserJSON extends ToJSON<{ id: number }, 'User'> {}
280
+ ```
101
281
 
102
- console.log(Eq.stringCaseInsentitive()('abc', 'AbC'));
103
- // => true
282
+ ---
283
+
284
+ ## Installation
285
+
286
+ ### Node / Bun / npm / Yarn
287
+
288
+ ```sh
289
+ npm install @rimbu/common
290
+ # or
291
+ yarn add @rimbu/common
292
+ # or
293
+ bun add @rimbu/common
104
294
  ```
105
295
 
106
- ## Author
296
+ ### Deno (import map)
297
+
298
+ ```jsonc
299
+ {
300
+ "imports": {
301
+ "@rimbu/": "https://deno.land/x/rimbu@<version>/"
302
+ }
303
+ }
304
+ ```
107
305
 
108
- Created and maintained by [Arvid Nicolaas](https://github.com/vitoke).
306
+ Then:
109
307
 
110
- ## Contributing
308
+ ```ts
309
+ import { Eq } from '@rimbu/common/mod.ts';
310
+ ```
311
+
312
+ ### Browser / ESM
313
+
314
+ `@rimbu/common` ships both **ESM** and **CJS** builds. Use it with any modern bundler
315
+ (Vite, Webpack, esbuild, Bun, etc.) or directly in Node ESM projects.
316
+
317
+ ---
318
+
319
+ ## Ecosystem & Links
320
+
321
+ - Part of the broader **Rimbu** collection ecosystem – interoperates with `@rimbu/collection-types`,
322
+ `@rimbu/hashed`, `@rimbu/ordered`, `@rimbu/stream`, and more.
323
+ - Main documentation: [rimbu.org](https://rimbu.org)
324
+ - Package docs: [Common docs](https://rimbu.org/docs/common/overview)
325
+ - API reference: [Common API](https://rimbu.org/api/rimbu/common)
111
326
 
112
- We welcome contributions! Please read our [Contributing guide](https://github.com/rimbu-org/rimbu/blob/main/CONTRIBUTING.md).
327
+ ---
113
328
 
114
- ## Contributors
329
+ ## Contributing
330
+
331
+ We welcome contributions! See the
332
+ [Contributing guide](https://github.com/rimbu-org/rimbu/blob/main/CONTRIBUTING.md) for details.
115
333
 
116
- <img src = "https://contrib.rocks/image?repo=rimbu-org/rimbu"/>
334
+ <img src="https://contrib.rocks/image?repo=rimbu-org/rimbu" alt="Contributors" />
117
335
 
118
336
  _Made with [contributors-img](https://contrib.rocks)._
119
337
 
338
+ ---
339
+
120
340
  ## License
121
341
 
122
- This project is licensed under the MIT License. See the [LICENSE](./LICENSE) for details.
342
+ MIT © Rimbu contributors. See [LICENSE](./LICENSE) for details.
343
+
344
+ ---
345
+
346
+ ## Attributions
347
+
348
+ Created and maintained by [Arvid Nicolaas](https://github.com/vitoke). Logo © Rimbu.
package/dist/bun/eq.mts CHANGED
@@ -4,6 +4,15 @@
4
4
  export type Eq<T> = (v1: T, v2: T) => boolean;
5
5
 
6
6
  export namespace Eq {
7
+ /**
8
+ * Converts any given `value` to a string representation that is stable for equality
9
+ * and ordering comparisons.
10
+ *
11
+ * For primitive values and objects with a custom `toString` implementation, it uses
12
+ * `String(value)`. For plain objects with the default `Object.prototype.toString`
13
+ * implementation, it uses `JSON.stringify(value)` instead.
14
+ * @param value - the value to convert
15
+ */
7
16
  export function convertAnyToString(value: any): string {
8
17
  if (
9
18
  typeof value !== 'object' ||
@@ -146,7 +155,7 @@ export namespace Eq {
146
155
  /**
147
156
  * Returns an Eq instance that checks equality of objects containing property values of type V by iteratively
148
157
  * applying given `valueEq` to each of the object's property values.
149
- * @typeparam - the object property value type
158
+ * @typeparam V - the object property value type
150
159
  * @param valueEq - (optional) the Eq instance to use to compare property values
151
160
  * @example
152
161
  * ```ts
@@ -228,7 +237,7 @@ export namespace Eq {
228
237
  * @typeparam T - the value type
229
238
  * @example
230
239
  * ```ts
231
- * const eq = anyFlatEq()
240
+ * const eq = Eq.anyFlatEq()
232
241
  * console.log(eq(1, 'a'))
233
242
  * // => false
234
243
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -246,7 +255,7 @@ export namespace Eq {
246
255
  * @typeparam T - the value type
247
256
  * @example
248
257
  * ```ts
249
- * const eq = anyFlatEq()
258
+ * const eq = Eq.anyShallowEq()
250
259
  * console.log(eq(1, 'a'))
251
260
  * // => false
252
261
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -267,7 +276,7 @@ export namespace Eq {
267
276
  * @typeparam T - the value type
268
277
  * @example
269
278
  * ```ts
270
- * const eq = anyFlatEq()
279
+ * const eq = Eq.anyDeepEq()
271
280
  * console.log(eq(1, 'a'))
272
281
  * // => false
273
282
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -359,6 +368,18 @@ export namespace Eq {
359
368
  const _anyToStringEq: Eq<any> = (v1, v2) =>
360
369
  convertAnyToString(v1) === convertAnyToString(v2);
361
370
 
371
+ /**
372
+ * Returns an Eq instance that considers two values equal when their string
373
+ * representations, as returned by `Eq.convertAnyToString`, are equal.
374
+ * @example
375
+ * ```ts
376
+ * const eq = Eq.anyToStringEq()
377
+ * console.log(eq({ a: 1 }, { a: 1 }))
378
+ * // => true
379
+ * console.log(eq({ a: 1 }, { a: 2 }))
380
+ * // => false
381
+ * ```
382
+ */
362
383
  export function anyToStringEq(): Eq<any> {
363
384
  return _anyToStringEq;
364
385
  }
package/dist/bun/err.mts CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Throws an `Err.ForcedError` error when called.
2
+ * Throws an `ErrBase.ForcedError` error when called.
3
3
  * @example
4
4
  * ```ts
5
5
  * const emptyMap = HashMap.empty<number, string>()
6
6
  * emptyMap.get(5, Err);
7
- * // throws: Err.CustomError(message: 'Err: forced to throw error')
7
+ * // throws: ErrBase.ForcedError(message: 'Err: Forced to throw error')
8
8
  * ```
9
9
  */
10
10
  export function Err(): never {
@@ -23,6 +23,9 @@ export namespace ErrBase {
23
23
  }
24
24
  }
25
25
 
26
+ /**
27
+ * Error type that is thrown by `Err` and the functions returned by `ErrBase.msg`.
28
+ */
26
29
  export class ForcedError extends CustomError {}
27
30
 
28
31
  /**
@@ -32,7 +35,7 @@ export namespace ErrBase {
32
35
  * ```ts
33
36
  * const emptyMap = HashMap.empty<number, string>()
34
37
  * emptyMap.get(5, ErrBase.msg('not found'));
35
- * // throws: Err.CustomError(message: 'not found')
38
+ * // throws: ErrBase.ForcedError(message: 'not found')
36
39
  * ```
37
40
  */
38
41
  export function msg(message: string): () => never {
@@ -1,7 +1,13 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * The `@rimbu/common` package provides many commonly used types and utilities that can also be of use to Rimbu users.<br/>
4
+ * The `@rimbu/common` package provides shared equality and comparison helpers, range and index
5
+ * utilities, lazy and async value helpers, traversal utilities, and rich type‑level helpers used
6
+ * throughout the Rimbu ecosystem.<br/>
7
+ * Use it when you need well‑tested primitives like `Eq`, `Comp`, `Range`, `OptLazy`, `AsyncOptLazy`,
8
+ * or advanced type utilities in your own code, or when building on top of other Rimbu packages.<br/>
9
+ * See the [Common docs](https://rimbu.org/docs/common/overview) and
10
+ * [API reference](https://rimbu.org/api/rimbu/common) for more information.
5
11
  */
6
12
 
7
13
  export * from './internal.mts';
package/dist/cjs/eq.cjs CHANGED
@@ -4,6 +4,15 @@ exports.Eq = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var Eq;
6
6
  (function (Eq) {
7
+ /**
8
+ * Converts any given `value` to a string representation that is stable for equality
9
+ * and ordering comparisons.
10
+ *
11
+ * For primitive values and objects with a custom `toString` implementation, it uses
12
+ * `String(value)`. For plain objects with the default `Object.prototype.toString`
13
+ * implementation, it uses `JSON.stringify(value)` instead.
14
+ * @param value - the value to convert
15
+ */
7
16
  function convertAnyToString(value) {
8
17
  if (typeof value !== 'object' ||
9
18
  null === value ||
@@ -135,7 +144,7 @@ var Eq;
135
144
  /**
136
145
  * Returns an Eq instance that checks equality of objects containing property values of type V by iteratively
137
146
  * applying given `valueEq` to each of the object's property values.
138
- * @typeparam - the object property value type
147
+ * @typeparam V - the object property value type
139
148
  * @param valueEq - (optional) the Eq instance to use to compare property values
140
149
  * @example
141
150
  * ```ts
@@ -206,7 +215,7 @@ var Eq;
206
215
  * @typeparam T - the value type
207
216
  * @example
208
217
  * ```ts
209
- * const eq = anyFlatEq()
218
+ * const eq = Eq.anyFlatEq()
210
219
  * console.log(eq(1, 'a'))
211
220
  * // => false
212
221
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -224,7 +233,7 @@ var Eq;
224
233
  * @typeparam T - the value type
225
234
  * @example
226
235
  * ```ts
227
- * const eq = anyFlatEq()
236
+ * const eq = Eq.anyShallowEq()
228
237
  * console.log(eq(1, 'a'))
229
238
  * // => false
230
239
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -245,7 +254,7 @@ var Eq;
245
254
  * @typeparam T - the value type
246
255
  * @example
247
256
  * ```ts
248
- * const eq = anyFlatEq()
257
+ * const eq = Eq.anyDeepEq()
249
258
  * console.log(eq(1, 'a'))
250
259
  * // => false
251
260
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -333,6 +342,18 @@ var Eq;
333
342
  var _anyToStringEq = function (v1, v2) {
334
343
  return convertAnyToString(v1) === convertAnyToString(v2);
335
344
  };
345
+ /**
346
+ * Returns an Eq instance that considers two values equal when their string
347
+ * representations, as returned by `Eq.convertAnyToString`, are equal.
348
+ * @example
349
+ * ```ts
350
+ * const eq = Eq.anyToStringEq()
351
+ * console.log(eq({ a: 1 }, { a: 1 }))
352
+ * // => true
353
+ * console.log(eq({ a: 1 }, { a: 2 }))
354
+ * // => false
355
+ * ```
356
+ */
336
357
  function anyToStringEq() {
337
358
  return _anyToStringEq;
338
359
  }
@@ -1 +1 @@
1
- {"version":3,"file":"eq.cjs","sourceRoot":"","sources":["../../_cjs_prepare/eq.cts"],"names":[],"mappings":";;;;AAKA,IAAiB,EAAE,CAgZlB;AAhZD,WAAiB,EAAE;IACjB,SAAgB,kBAAkB,CAAC,KAAU;QAC3C,IACE,OAAO,KAAK,KAAK,QAAQ;YACzB,IAAI,KAAK,KAAK;YACd,CAAC,CAAC,UAAU,IAAI,KAAK,CAAC;YACtB,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU;YACpC,KAAK,CAAC,QAAQ,KAAK,MAAM,CAAC,SAAS,CAAC,QAAQ,EAC5C,CAAC;YACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QAED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AC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAD9C,CAC8C,CAAC;IACnD,CAAC;IANe,iBAAc,iBAM7B,CAAA;AACH,CAAC,EAragB,EAAE,kBAAF,EAAE,QAqalB"}
package/dist/cjs/eq.d.cts CHANGED
@@ -3,6 +3,15 @@
3
3
  */
4
4
  export type Eq<T> = (v1: T, v2: T) => boolean;
5
5
  export declare namespace Eq {
6
+ /**
7
+ * Converts any given `value` to a string representation that is stable for equality
8
+ * and ordering comparisons.
9
+ *
10
+ * For primitive values and objects with a custom `toString` implementation, it uses
11
+ * `String(value)`. For plain objects with the default `Object.prototype.toString`
12
+ * implementation, it uses `JSON.stringify(value)` instead.
13
+ * @param value - the value to convert
14
+ */
6
15
  function convertAnyToString(value: any): string;
7
16
  /**
8
17
  * Returns the default Eq instance, which is the Eq.anyDeepEq() instance.
@@ -65,7 +74,7 @@ export declare namespace Eq {
65
74
  /**
66
75
  * Returns an Eq instance that checks equality of objects containing property values of type V by iteratively
67
76
  * applying given `valueEq` to each of the object's property values.
68
- * @typeparam - the object property value type
77
+ * @typeparam V - the object property value type
69
78
  * @param valueEq - (optional) the Eq instance to use to compare property values
70
79
  * @example
71
80
  * ```ts
@@ -83,7 +92,7 @@ export declare namespace Eq {
83
92
  * @typeparam T - the value type
84
93
  * @example
85
94
  * ```ts
86
- * const eq = anyFlatEq()
95
+ * const eq = Eq.anyFlatEq()
87
96
  * console.log(eq(1, 'a'))
88
97
  * // => false
89
98
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -98,7 +107,7 @@ export declare namespace Eq {
98
107
  * @typeparam T - the value type
99
108
  * @example
100
109
  * ```ts
101
- * const eq = anyFlatEq()
110
+ * const eq = Eq.anyShallowEq()
102
111
  * console.log(eq(1, 'a'))
103
112
  * // => false
104
113
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -116,7 +125,7 @@ export declare namespace Eq {
116
125
  * @typeparam T - the value type
117
126
  * @example
118
127
  * ```ts
119
- * const eq = anyFlatEq()
128
+ * const eq = Eq.anyDeepEq()
120
129
  * console.log(eq(1, 'a'))
121
130
  * // => false
122
131
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -164,6 +173,18 @@ export declare namespace Eq {
164
173
  * ```
165
174
  */
166
175
  function stringCharCodeEq(): Eq<string>;
176
+ /**
177
+ * Returns an Eq instance that considers two values equal when their string
178
+ * representations, as returned by `Eq.convertAnyToString`, are equal.
179
+ * @example
180
+ * ```ts
181
+ * const eq = Eq.anyToStringEq()
182
+ * console.log(eq({ a: 1 }, { a: 1 }))
183
+ * // => true
184
+ * console.log(eq({ a: 1 }, { a: 2 }))
185
+ * // => false
186
+ * ```
187
+ */
167
188
  function anyToStringEq(): Eq<any>;
168
189
  /**
169
190
  * Returns an Eq instance that considers values equal their JSON.stringify values are equal.
package/dist/cjs/err.cjs CHANGED
@@ -4,12 +4,12 @@ exports.ErrBase = void 0;
4
4
  exports.Err = Err;
5
5
  var tslib_1 = require("tslib");
6
6
  /**
7
- * Throws an `Err.ForcedError` error when called.
7
+ * Throws an `ErrBase.ForcedError` error when called.
8
8
  * @example
9
9
  * ```ts
10
10
  * const emptyMap = HashMap.empty<number, string>()
11
11
  * emptyMap.get(5, Err);
12
- * // throws: Err.CustomError(message: 'Err: forced to throw error')
12
+ * // throws: ErrBase.ForcedError(message: 'Err: Forced to throw error')
13
13
  * ```
14
14
  */
15
15
  function Err() {
@@ -34,6 +34,9 @@ var ErrBase;
34
34
  return CustomError;
35
35
  }());
36
36
  ErrBase.CustomError = CustomError;
37
+ /**
38
+ * Error type that is thrown by `Err` and the functions returned by `ErrBase.msg`.
39
+ */
37
40
  var ForcedError = /** @class */ (function (_super) {
38
41
  tslib_1.__extends(ForcedError, _super);
39
42
  function ForcedError() {
@@ -49,7 +52,7 @@ var ErrBase;
49
52
  * ```ts
50
53
  * const emptyMap = HashMap.empty<number, string>()
51
54
  * emptyMap.get(5, ErrBase.msg('not found'));
52
- * // throws: Err.CustomError(message: 'not found')
55
+ * // throws: ErrBase.ForcedError(message: 'not found')
53
56
  * ```
54
57
  */
55
58
  function msg(message) {
@@ -1 +1 @@
1
- {"version":3,"file":"err.cjs","sourceRoot":"","sources":["../../_cjs_prepare/err.cts"],"names":[],"mappings":";;;AASA,kBAEC;;AAXD;;;;;;;;GAQG;AACH,SAAgB,GAAG;IACjB,OAAO,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,EAAE,CAAC;AACrD,CAAC;AAED,IAAiB,OAAO,CA6BvB;AA7BD,WAAiB,OAAO;IACtB;;OAEG;IACH;QACE,qBAAqB,OAAe;YAAf,YAAO,GAAP,OAAO,CAAQ;QAAG,CAAC;QAExC,sBAAI,6BAAI;iBAAR;gBACE,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;YAC/B,CAAC;;;WAAA;QACH,kBAAC;IAAD,CAAC,AAND,IAMC;IANqB,mBAAW,cAMhC,CAAA;IAED;QAAiC,uCAAW;QAA5C;;QAA8C,CAAC;QAAD,kBAAC;IAAD,CAAC,AAA/C,CAAiC,WAAW,GAAG;IAAlC,mBAAW,cAAuB,CAAA;IAE/C;;;;;;;;;OASG;IACH,SAAgB,GAAG,CAAC,OAAe;QACjC,OAAO;YACL,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACzC,CAAC,CAAC;IACJ,CAAC;IAJe,WAAG,MAIlB,CAAA;AACH,CAAC,EA7BgB,OAAO,uBAAP,OAAO,QA6BvB"}
1
+ {"version":3,"file":"err.cjs","sourceRoot":"","sources":["../../_cjs_prepare/err.cts"],"names":[],"mappings":";;;AASA,kBAEC;;AAXD;;;;;;;;GAQG;AACH,SAAgB,GAAG;IACjB,OAAO,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,EAAE,CAAC;AACrD,CAAC;AAED,IAAiB,OAAO,CAgCvB;AAhCD,WAAiB,OAAO;IACtB;;OAEG;IACH;QACE,qBAAqB,OAAe;YAAf,YAAO,GAAP,OAAO,CAAQ;QAAG,CAAC;QAExC,sBAAI,6BAAI;iBAAR;gBACE,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;YAC/B,CAAC;;;WAAA;QACH,kBAAC;IAAD,CAAC,AAND,IAMC;IANqB,mBAAW,cAMhC,CAAA;IAED;;OAEG;IACH;QAAiC,uCAAW;QAA5C;;QAA8C,CAAC;QAAD,kBAAC;IAAD,CAAC,AAA/C,CAAiC,WAAW,GAAG;IAAlC,mBAAW,cAAuB,CAAA;IAE/C;;;;;;;;;OASG;IACH,SAAgB,GAAG,CAAC,OAAe;QACjC,OAAO;YACL,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACzC,CAAC,CAAC;IACJ,CAAC;IAJe,WAAG,MAIlB,CAAA;AACH,CAAC,EAhCgB,OAAO,uBAAP,OAAO,QAgCvB"}
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Throws an `Err.ForcedError` error when called.
2
+ * Throws an `ErrBase.ForcedError` error when called.
3
3
  * @example
4
4
  * ```ts
5
5
  * const emptyMap = HashMap.empty<number, string>()
6
6
  * emptyMap.get(5, Err);
7
- * // throws: Err.CustomError(message: 'Err: forced to throw error')
7
+ * // throws: ErrBase.ForcedError(message: 'Err: Forced to throw error')
8
8
  * ```
9
9
  */
10
10
  export declare function Err(): never;
@@ -17,6 +17,9 @@ export declare namespace ErrBase {
17
17
  constructor(message: string);
18
18
  get name(): string;
19
19
  }
20
+ /**
21
+ * Error type that is thrown by `Err` and the functions returned by `ErrBase.msg`.
22
+ */
20
23
  class ForcedError extends CustomError {
21
24
  }
22
25
  /**
@@ -26,7 +29,7 @@ export declare namespace ErrBase {
26
29
  * ```ts
27
30
  * const emptyMap = HashMap.empty<number, string>()
28
31
  * emptyMap.get(5, ErrBase.msg('not found'));
29
- * // throws: Err.CustomError(message: 'not found')
32
+ * // throws: ErrBase.ForcedError(message: 'not found')
30
33
  * ```
31
34
  */
32
35
  function msg(message: string): () => never;
@@ -2,7 +2,13 @@
2
2
  /**
3
3
  * @packageDocumentation
4
4
  *
5
- * The `@rimbu/common` package provides many commonly used types and utilities that can also be of use to Rimbu users.<br/>
5
+ * The `@rimbu/common` package provides shared equality and comparison helpers, range and index
6
+ * utilities, lazy and async value helpers, traversal utilities, and rich type‑level helpers used
7
+ * throughout the Rimbu ecosystem.<br/>
8
+ * Use it when you need well‑tested primitives like `Eq`, `Comp`, `Range`, `OptLazy`, `AsyncOptLazy`,
9
+ * or advanced type utilities in your own code, or when building on top of other Rimbu packages.<br/>
10
+ * See the [Common docs](https://rimbu.org/docs/common/overview) and
11
+ * [API reference](https://rimbu.org/api/rimbu/common) for more information.
6
12
  */
7
13
  Object.defineProperty(exports, "__esModule", { value: true });
8
14
  var tslib_1 = require("tslib");
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../_cjs_prepare/index.cts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,yDAA+B"}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../_cjs_prepare/index.cts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAEH,yDAA+B"}
@@ -1,6 +1,12 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * The `@rimbu/common` package provides many commonly used types and utilities that can also be of use to Rimbu users.<br/>
4
+ * The `@rimbu/common` package provides shared equality and comparison helpers, range and index
5
+ * utilities, lazy and async value helpers, traversal utilities, and rich type‑level helpers used
6
+ * throughout the Rimbu ecosystem.<br/>
7
+ * Use it when you need well‑tested primitives like `Eq`, `Comp`, `Range`, `OptLazy`, `AsyncOptLazy`,
8
+ * or advanced type utilities in your own code, or when building on top of other Rimbu packages.<br/>
9
+ * See the [Common docs](https://rimbu.org/docs/common/overview) and
10
+ * [API reference](https://rimbu.org/api/rimbu/common) for more information.
5
11
  */
6
12
  export * from './internal.cjs';
package/dist/esm/eq.d.mts CHANGED
@@ -3,6 +3,15 @@
3
3
  */
4
4
  export type Eq<T> = (v1: T, v2: T) => boolean;
5
5
  export declare namespace Eq {
6
+ /**
7
+ * Converts any given `value` to a string representation that is stable for equality
8
+ * and ordering comparisons.
9
+ *
10
+ * For primitive values and objects with a custom `toString` implementation, it uses
11
+ * `String(value)`. For plain objects with the default `Object.prototype.toString`
12
+ * implementation, it uses `JSON.stringify(value)` instead.
13
+ * @param value - the value to convert
14
+ */
6
15
  function convertAnyToString(value: any): string;
7
16
  /**
8
17
  * Returns the default Eq instance, which is the Eq.anyDeepEq() instance.
@@ -65,7 +74,7 @@ export declare namespace Eq {
65
74
  /**
66
75
  * Returns an Eq instance that checks equality of objects containing property values of type V by iteratively
67
76
  * applying given `valueEq` to each of the object's property values.
68
- * @typeparam - the object property value type
77
+ * @typeparam V - the object property value type
69
78
  * @param valueEq - (optional) the Eq instance to use to compare property values
70
79
  * @example
71
80
  * ```ts
@@ -83,7 +92,7 @@ export declare namespace Eq {
83
92
  * @typeparam T - the value type
84
93
  * @example
85
94
  * ```ts
86
- * const eq = anyFlatEq()
95
+ * const eq = Eq.anyFlatEq()
87
96
  * console.log(eq(1, 'a'))
88
97
  * // => false
89
98
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -98,7 +107,7 @@ export declare namespace Eq {
98
107
  * @typeparam T - the value type
99
108
  * @example
100
109
  * ```ts
101
- * const eq = anyFlatEq()
110
+ * const eq = Eq.anyShallowEq()
102
111
  * console.log(eq(1, 'a'))
103
112
  * // => false
104
113
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -116,7 +125,7 @@ export declare namespace Eq {
116
125
  * @typeparam T - the value type
117
126
  * @example
118
127
  * ```ts
119
- * const eq = anyFlatEq()
128
+ * const eq = Eq.anyDeepEq()
120
129
  * console.log(eq(1, 'a'))
121
130
  * // => false
122
131
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -164,6 +173,18 @@ export declare namespace Eq {
164
173
  * ```
165
174
  */
166
175
  function stringCharCodeEq(): Eq<string>;
176
+ /**
177
+ * Returns an Eq instance that considers two values equal when their string
178
+ * representations, as returned by `Eq.convertAnyToString`, are equal.
179
+ * @example
180
+ * ```ts
181
+ * const eq = Eq.anyToStringEq()
182
+ * console.log(eq({ a: 1 }, { a: 1 }))
183
+ * // => true
184
+ * console.log(eq({ a: 1 }, { a: 2 }))
185
+ * // => false
186
+ * ```
187
+ */
167
188
  function anyToStringEq(): Eq<any>;
168
189
  /**
169
190
  * Returns an Eq instance that considers values equal their JSON.stringify values are equal.
package/dist/esm/eq.mjs CHANGED
@@ -1,5 +1,14 @@
1
1
  export var Eq;
2
2
  (function (Eq) {
3
+ /**
4
+ * Converts any given `value` to a string representation that is stable for equality
5
+ * and ordering comparisons.
6
+ *
7
+ * For primitive values and objects with a custom `toString` implementation, it uses
8
+ * `String(value)`. For plain objects with the default `Object.prototype.toString`
9
+ * implementation, it uses `JSON.stringify(value)` instead.
10
+ * @param value - the value to convert
11
+ */
3
12
  function convertAnyToString(value) {
4
13
  if (typeof value !== 'object' ||
5
14
  null === value ||
@@ -129,7 +138,7 @@ export var Eq;
129
138
  /**
130
139
  * Returns an Eq instance that checks equality of objects containing property values of type V by iteratively
131
140
  * applying given `valueEq` to each of the object's property values.
132
- * @typeparam - the object property value type
141
+ * @typeparam V - the object property value type
133
142
  * @param valueEq - (optional) the Eq instance to use to compare property values
134
143
  * @example
135
144
  * ```ts
@@ -200,7 +209,7 @@ export var Eq;
200
209
  * @typeparam T - the value type
201
210
  * @example
202
211
  * ```ts
203
- * const eq = anyFlatEq()
212
+ * const eq = Eq.anyFlatEq()
204
213
  * console.log(eq(1, 'a'))
205
214
  * // => false
206
215
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -218,7 +227,7 @@ export var Eq;
218
227
  * @typeparam T - the value type
219
228
  * @example
220
229
  * ```ts
221
- * const eq = anyFlatEq()
230
+ * const eq = Eq.anyShallowEq()
222
231
  * console.log(eq(1, 'a'))
223
232
  * // => false
224
233
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -239,7 +248,7 @@ export var Eq;
239
248
  * @typeparam T - the value type
240
249
  * @example
241
250
  * ```ts
242
- * const eq = anyFlatEq()
251
+ * const eq = Eq.anyDeepEq()
243
252
  * console.log(eq(1, 'a'))
244
253
  * // => false
245
254
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -319,6 +328,18 @@ export var Eq;
319
328
  }
320
329
  Eq.stringCharCodeEq = stringCharCodeEq;
321
330
  const _anyToStringEq = (v1, v2) => convertAnyToString(v1) === convertAnyToString(v2);
331
+ /**
332
+ * Returns an Eq instance that considers two values equal when their string
333
+ * representations, as returned by `Eq.convertAnyToString`, are equal.
334
+ * @example
335
+ * ```ts
336
+ * const eq = Eq.anyToStringEq()
337
+ * console.log(eq({ a: 1 }, { a: 1 }))
338
+ * // => true
339
+ * console.log(eq({ a: 1 }, { a: 2 }))
340
+ * // => false
341
+ * ```
342
+ */
322
343
  function anyToStringEq() {
323
344
  return _anyToStringEq;
324
345
  }
@@ -1 +1 @@
1
- {"version":3,"file":"eq.mjs","sourceRoot":"","sources":["../../src/eq.mts"],"names":[],"mappings":"AAKA,MAAM,KAAW,EAAE,CAgZlB;AAhZD,WAAiB,EAAE;IACjB,SAAgB,kBAAkB,CAAC,KAAU;QAC3C,IACE,OAAO,KAAK,KAAK,QAAQ;YACzB,IAAI,KAAK,KAAK;YACd,CAAC,CAAC,UAAU,IAAI,KAAK,CAAC;YACtB,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU;YACpC,KAAK,CAAC,QAAQ,KAAK,MAAM,CAAC,SAAS,CAAC,QAAQ,EAC5C,CAAC;YACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,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
- * Throws an `Err.ForcedError` error when called.
2
+ * Throws an `ErrBase.ForcedError` error when called.
3
3
  * @example
4
4
  * ```ts
5
5
  * const emptyMap = HashMap.empty<number, string>()
6
6
  * emptyMap.get(5, Err);
7
- * // throws: Err.CustomError(message: 'Err: forced to throw error')
7
+ * // throws: ErrBase.ForcedError(message: 'Err: Forced to throw error')
8
8
  * ```
9
9
  */
10
10
  export declare function Err(): never;
@@ -17,6 +17,9 @@ export declare namespace ErrBase {
17
17
  constructor(message: string);
18
18
  get name(): string;
19
19
  }
20
+ /**
21
+ * Error type that is thrown by `Err` and the functions returned by `ErrBase.msg`.
22
+ */
20
23
  class ForcedError extends CustomError {
21
24
  }
22
25
  /**
@@ -26,7 +29,7 @@ export declare namespace ErrBase {
26
29
  * ```ts
27
30
  * const emptyMap = HashMap.empty<number, string>()
28
31
  * emptyMap.get(5, ErrBase.msg('not found'));
29
- * // throws: Err.CustomError(message: 'not found')
32
+ * // throws: ErrBase.ForcedError(message: 'not found')
30
33
  * ```
31
34
  */
32
35
  function msg(message: string): () => never;
package/dist/esm/err.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Throws an `Err.ForcedError` error when called.
2
+ * Throws an `ErrBase.ForcedError` error when called.
3
3
  * @example
4
4
  * ```ts
5
5
  * const emptyMap = HashMap.empty<number, string>()
6
6
  * emptyMap.get(5, Err);
7
- * // throws: Err.CustomError(message: 'Err: forced to throw error')
7
+ * // throws: ErrBase.ForcedError(message: 'Err: Forced to throw error')
8
8
  * ```
9
9
  */
10
10
  export function Err() {
@@ -24,6 +24,9 @@ export var ErrBase;
24
24
  }
25
25
  }
26
26
  ErrBase.CustomError = CustomError;
27
+ /**
28
+ * Error type that is thrown by `Err` and the functions returned by `ErrBase.msg`.
29
+ */
27
30
  class ForcedError extends CustomError {
28
31
  }
29
32
  ErrBase.ForcedError = ForcedError;
@@ -34,7 +37,7 @@ export var ErrBase;
34
37
  * ```ts
35
38
  * const emptyMap = HashMap.empty<number, string>()
36
39
  * emptyMap.get(5, ErrBase.msg('not found'));
37
- * // throws: Err.CustomError(message: 'not found')
40
+ * // throws: ErrBase.ForcedError(message: 'not found')
38
41
  * ```
39
42
  */
40
43
  function msg(message) {
@@ -1 +1 @@
1
- {"version":3,"file":"err.mjs","sourceRoot":"","sources":["../../src/err.mts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,GAAG;IACjB,OAAO,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,EAAE,CAAC;AACrD,CAAC;AAED,MAAM,KAAW,OAAO,CA6BvB;AA7BD,WAAiB,OAAO;IACtB;;OAEG;IACH,MAAsB,WAAW;QAC/B,YAAqB,OAAe;YAAf,YAAO,GAAP,OAAO,CAAQ;QAAG,CAAC;QAExC,IAAI,IAAI;YACN,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAC/B,CAAC;KACF;IANqB,mBAAW,cAMhC,CAAA;IAED,MAAa,WAAY,SAAQ,WAAW;KAAG;IAAlC,mBAAW,cAAuB,CAAA;IAE/C;;;;;;;;;OASG;IACH,SAAgB,GAAG,CAAC,OAAe;QACjC,OAAO;YACL,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACzC,CAAC,CAAC;IACJ,CAAC;IAJe,WAAG,MAIlB,CAAA;AACH,CAAC,EA7BgB,OAAO,KAAP,OAAO,QA6BvB"}
1
+ {"version":3,"file":"err.mjs","sourceRoot":"","sources":["../../src/err.mts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,GAAG;IACjB,OAAO,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,EAAE,CAAC;AACrD,CAAC;AAED,MAAM,KAAW,OAAO,CAgCvB;AAhCD,WAAiB,OAAO;IACtB;;OAEG;IACH,MAAsB,WAAW;QAC/B,YAAqB,OAAe;YAAf,YAAO,GAAP,OAAO,CAAQ;QAAG,CAAC;QAExC,IAAI,IAAI;YACN,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAC/B,CAAC;KACF;IANqB,mBAAW,cAMhC,CAAA;IAED;;OAEG;IACH,MAAa,WAAY,SAAQ,WAAW;KAAG;IAAlC,mBAAW,cAAuB,CAAA;IAE/C;;;;;;;;;OASG;IACH,SAAgB,GAAG,CAAC,OAAe;QACjC,OAAO;YACL,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACzC,CAAC,CAAC;IACJ,CAAC;IAJe,WAAG,MAIlB,CAAA;AACH,CAAC,EAhCgB,OAAO,KAAP,OAAO,QAgCvB"}
@@ -1,6 +1,12 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * The `@rimbu/common` package provides many commonly used types and utilities that can also be of use to Rimbu users.<br/>
4
+ * The `@rimbu/common` package provides shared equality and comparison helpers, range and index
5
+ * utilities, lazy and async value helpers, traversal utilities, and rich type‑level helpers used
6
+ * throughout the Rimbu ecosystem.<br/>
7
+ * Use it when you need well‑tested primitives like `Eq`, `Comp`, `Range`, `OptLazy`, `AsyncOptLazy`,
8
+ * or advanced type utilities in your own code, or when building on top of other Rimbu packages.<br/>
9
+ * See the [Common docs](https://rimbu.org/docs/common/overview) and
10
+ * [API reference](https://rimbu.org/api/rimbu/common) for more information.
5
11
  */
6
12
  export * from './internal.mjs';
@@ -1,7 +1,13 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * The `@rimbu/common` package provides many commonly used types and utilities that can also be of use to Rimbu users.<br/>
4
+ * The `@rimbu/common` package provides shared equality and comparison helpers, range and index
5
+ * utilities, lazy and async value helpers, traversal utilities, and rich type‑level helpers used
6
+ * throughout the Rimbu ecosystem.<br/>
7
+ * Use it when you need well‑tested primitives like `Eq`, `Comp`, `Range`, `OptLazy`, `AsyncOptLazy`,
8
+ * or advanced type utilities in your own code, or when building on top of other Rimbu packages.<br/>
9
+ * See the [Common docs](https://rimbu.org/docs/common/overview) and
10
+ * [API reference](https://rimbu.org/api/rimbu/common) for more information.
5
11
  */
6
12
  export * from './internal.mjs';
7
13
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/index.mts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/index.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,cAAc,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimbu/common",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Common types and objects used in many other Rimbu packages",
5
5
  "keywords": [
6
6
  "common",
@@ -82,5 +82,5 @@
82
82
  "dependencies": {
83
83
  "tslib": "^2.6.2"
84
84
  },
85
- "gitHead": "f18ddf964507dbd10790da3cd4deef8f455a178e"
85
+ "gitHead": "1c35dbdd9ce13aeba818b41eb20bab1e826b3e16"
86
86
  }
package/src/eq.mts CHANGED
@@ -4,6 +4,15 @@
4
4
  export type Eq<T> = (v1: T, v2: T) => boolean;
5
5
 
6
6
  export namespace Eq {
7
+ /**
8
+ * Converts any given `value` to a string representation that is stable for equality
9
+ * and ordering comparisons.
10
+ *
11
+ * For primitive values and objects with a custom `toString` implementation, it uses
12
+ * `String(value)`. For plain objects with the default `Object.prototype.toString`
13
+ * implementation, it uses `JSON.stringify(value)` instead.
14
+ * @param value - the value to convert
15
+ */
7
16
  export function convertAnyToString(value: any): string {
8
17
  if (
9
18
  typeof value !== 'object' ||
@@ -146,7 +155,7 @@ export namespace Eq {
146
155
  /**
147
156
  * Returns an Eq instance that checks equality of objects containing property values of type V by iteratively
148
157
  * applying given `valueEq` to each of the object's property values.
149
- * @typeparam - the object property value type
158
+ * @typeparam V - the object property value type
150
159
  * @param valueEq - (optional) the Eq instance to use to compare property values
151
160
  * @example
152
161
  * ```ts
@@ -228,7 +237,7 @@ export namespace Eq {
228
237
  * @typeparam T - the value type
229
238
  * @example
230
239
  * ```ts
231
- * const eq = anyFlatEq()
240
+ * const eq = Eq.anyFlatEq()
232
241
  * console.log(eq(1, 'a'))
233
242
  * // => false
234
243
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -246,7 +255,7 @@ export namespace Eq {
246
255
  * @typeparam T - the value type
247
256
  * @example
248
257
  * ```ts
249
- * const eq = anyFlatEq()
258
+ * const eq = Eq.anyShallowEq()
250
259
  * console.log(eq(1, 'a'))
251
260
  * // => false
252
261
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -267,7 +276,7 @@ export namespace Eq {
267
276
  * @typeparam T - the value type
268
277
  * @example
269
278
  * ```ts
270
- * const eq = anyFlatEq()
279
+ * const eq = Eq.anyDeepEq()
271
280
  * console.log(eq(1, 'a'))
272
281
  * // => false
273
282
  * console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
@@ -359,6 +368,18 @@ export namespace Eq {
359
368
  const _anyToStringEq: Eq<any> = (v1, v2) =>
360
369
  convertAnyToString(v1) === convertAnyToString(v2);
361
370
 
371
+ /**
372
+ * Returns an Eq instance that considers two values equal when their string
373
+ * representations, as returned by `Eq.convertAnyToString`, are equal.
374
+ * @example
375
+ * ```ts
376
+ * const eq = Eq.anyToStringEq()
377
+ * console.log(eq({ a: 1 }, { a: 1 }))
378
+ * // => true
379
+ * console.log(eq({ a: 1 }, { a: 2 }))
380
+ * // => false
381
+ * ```
382
+ */
362
383
  export function anyToStringEq(): Eq<any> {
363
384
  return _anyToStringEq;
364
385
  }
package/src/err.mts CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Throws an `Err.ForcedError` error when called.
2
+ * Throws an `ErrBase.ForcedError` error when called.
3
3
  * @example
4
4
  * ```ts
5
5
  * const emptyMap = HashMap.empty<number, string>()
6
6
  * emptyMap.get(5, Err);
7
- * // throws: Err.CustomError(message: 'Err: forced to throw error')
7
+ * // throws: ErrBase.ForcedError(message: 'Err: Forced to throw error')
8
8
  * ```
9
9
  */
10
10
  export function Err(): never {
@@ -23,6 +23,9 @@ export namespace ErrBase {
23
23
  }
24
24
  }
25
25
 
26
+ /**
27
+ * Error type that is thrown by `Err` and the functions returned by `ErrBase.msg`.
28
+ */
26
29
  export class ForcedError extends CustomError {}
27
30
 
28
31
  /**
@@ -32,7 +35,7 @@ export namespace ErrBase {
32
35
  * ```ts
33
36
  * const emptyMap = HashMap.empty<number, string>()
34
37
  * emptyMap.get(5, ErrBase.msg('not found'));
35
- * // throws: Err.CustomError(message: 'not found')
38
+ * // throws: ErrBase.ForcedError(message: 'not found')
36
39
  * ```
37
40
  */
38
41
  export function msg(message: string): () => never {
package/src/index.mts CHANGED
@@ -1,7 +1,13 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * The `@rimbu/common` package provides many commonly used types and utilities that can also be of use to Rimbu users.<br/>
4
+ * The `@rimbu/common` package provides shared equality and comparison helpers, range and index
5
+ * utilities, lazy and async value helpers, traversal utilities, and rich type‑level helpers used
6
+ * throughout the Rimbu ecosystem.<br/>
7
+ * Use it when you need well‑tested primitives like `Eq`, `Comp`, `Range`, `OptLazy`, `AsyncOptLazy`,
8
+ * or advanced type utilities in your own code, or when building on top of other Rimbu packages.<br/>
9
+ * See the [Common docs](https://rimbu.org/docs/common/overview) and
10
+ * [API reference](https://rimbu.org/api/rimbu/common) for more information.
5
11
  */
6
12
 
7
13
  export * from './internal.mjs';