@rimbu/common 2.0.1 → 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 +292 -66
- package/dist/bun/eq.mts +25 -4
- package/dist/bun/err.mts +7 -4
- package/dist/bun/index.mts +7 -1
- package/dist/cjs/eq.cjs +25 -4
- package/dist/cjs/eq.cjs.map +1 -1
- package/dist/cjs/eq.d.cts +25 -4
- package/dist/cjs/err.cjs +8 -5
- package/dist/cjs/err.cjs.map +1 -1
- package/dist/cjs/err.d.cts +6 -3
- package/dist/cjs/index.cjs +7 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +7 -1
- package/dist/cjs/optlazy.cjs +2 -3
- package/dist/cjs/optlazy.cjs.map +1 -1
- package/dist/cjs/traverse-state.cjs +1 -2
- package/dist/cjs/traverse-state.cjs.map +1 -1
- package/dist/cjs/update.cjs +1 -2
- package/dist/cjs/update.cjs.map +1 -1
- package/dist/esm/eq.d.mts +25 -4
- package/dist/esm/eq.mjs +25 -4
- package/dist/esm/eq.mjs.map +1 -1
- package/dist/esm/err.d.mts +6 -3
- package/dist/esm/err.mjs +6 -3
- package/dist/esm/err.mjs.map +1 -1
- package/dist/esm/index.d.mts +7 -1
- package/dist/esm/index.mjs +7 -1
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/eq.mts +25 -4
- package/src/err.mts +7 -4
- package/src/index.mts +7 -1
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 =
|
|
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 =
|
|
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
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ErrBase =
|
|
3
|
+
exports.ErrBase = void 0;
|
|
4
|
+
exports.Err = Err;
|
|
4
5
|
var tslib_1 = require("tslib");
|
|
5
6
|
/**
|
|
6
|
-
* Throws an `
|
|
7
|
+
* Throws an `ErrBase.ForcedError` error when called.
|
|
7
8
|
* @example
|
|
8
9
|
* ```ts
|
|
9
10
|
* const emptyMap = HashMap.empty<number, string>()
|
|
10
11
|
* emptyMap.get(5, Err);
|
|
11
|
-
* // throws:
|
|
12
|
+
* // throws: ErrBase.ForcedError(message: 'Err: Forced to throw error')
|
|
12
13
|
* ```
|
|
13
14
|
*/
|
|
14
15
|
function Err() {
|
|
15
16
|
return ErrBase.msg('Err: Forced to throw error')();
|
|
16
17
|
}
|
|
17
|
-
exports.Err = Err;
|
|
18
18
|
var ErrBase;
|
|
19
19
|
(function (ErrBase) {
|
|
20
20
|
/**
|
|
@@ -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:
|
|
55
|
+
* // throws: ErrBase.ForcedError(message: 'not found')
|
|
53
56
|
* ```
|
|
54
57
|
*/
|
|
55
58
|
function msg(message) {
|
package/dist/cjs/err.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"err.cjs","sourceRoot":"","sources":["../../_cjs_prepare/err.cts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/cjs/err.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Throws an `
|
|
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:
|
|
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:
|
|
32
|
+
* // throws: ErrBase.ForcedError(message: 'not found')
|
|
30
33
|
* ```
|
|
31
34
|
*/
|
|
32
35
|
function msg(message: string): () => never;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @packageDocumentation
|
|
4
4
|
*
|
|
5
|
-
* The `@rimbu/common` package provides
|
|
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");
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../_cjs_prepare/index.cts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../_cjs_prepare/index.cts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAEH,yDAA+B"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
*
|
|
4
|
-
* The `@rimbu/common` package provides
|
|
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/cjs/optlazy.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.OptLazy = OptLazy;
|
|
4
|
+
exports.OptLazyOr = OptLazyOr;
|
|
4
5
|
var tslib_1 = require("tslib");
|
|
5
6
|
/**
|
|
6
7
|
* Returns the value contained in an `OptLazy` instance of type T.
|
|
@@ -24,7 +25,6 @@ function OptLazy(optLazy) {
|
|
|
24
25
|
return optLazy.apply(void 0, tslib_1.__spreadArray([], tslib_1.__read(args), false));
|
|
25
26
|
return optLazy;
|
|
26
27
|
}
|
|
27
|
-
exports.OptLazy = OptLazy;
|
|
28
28
|
/**
|
|
29
29
|
* Returns the value contained in an `OptLazyOr` instance of type T, or the given
|
|
30
30
|
* `otherValue` if the lazy function returns it.
|
|
@@ -44,5 +44,4 @@ function OptLazyOr(optLazyOr, otherValue) {
|
|
|
44
44
|
return optLazyOr(otherValue);
|
|
45
45
|
return optLazyOr;
|
|
46
46
|
}
|
|
47
|
-
exports.OptLazyOr = OptLazyOr;
|
|
48
47
|
//# sourceMappingURL=optlazy.cjs.map
|
package/dist/cjs/optlazy.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optlazy.cjs","sourceRoot":"","sources":["../../_cjs_prepare/optlazy.cts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"optlazy.cjs","sourceRoot":"","sources":["../../_cjs_prepare/optlazy.cts"],"names":[],"mappings":";;AAoBA,0BAMC;AAwBD,8BAMC;;AAjDD;;;;;;;;;;;;GAYG;AACH,SAAgB,OAAO,CACrB,OAAsB;IACtB,cAAU;SAAV,UAAU,EAAV,qBAAU,EAAV,IAAU;QAAV,6BAAU;;IAEV,IAAI,OAAO,YAAY,QAAQ;QAAE,OAAO,OAAO,wDAAI,IAAI,WAAE;IACzD,OAAO,OAAO,CAAC;AACjB,CAAC;AAUD;;;;;;;;;;;;;GAaG;AACH,SAAgB,SAAS,CACvB,SAA0B,EAC1B,UAAa;IAEb,IAAI,SAAS,YAAY,QAAQ;QAAE,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC;IAChE,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TraverseState =
|
|
3
|
+
exports.TraverseState = TraverseState;
|
|
4
4
|
var TraverseStateImpl = /** @class */ (function () {
|
|
5
5
|
function TraverseStateImpl(startIndex) {
|
|
6
6
|
var _this = this;
|
|
@@ -29,5 +29,4 @@ function TraverseState(startIndex) {
|
|
|
29
29
|
if (startIndex === void 0) { startIndex = 0; }
|
|
30
30
|
return new TraverseStateImpl(startIndex);
|
|
31
31
|
}
|
|
32
|
-
exports.TraverseState = TraverseState;
|
|
33
32
|
//# sourceMappingURL=traverse-state.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverse-state.cjs","sourceRoot":"","sources":["../../_cjs_prepare/traverse-state.cts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"traverse-state.cjs","sourceRoot":"","sources":["../../_cjs_prepare/traverse-state.cts"],"names":[],"mappings":";;AAwDA,sCAEC;AA7BD;IAIE,2BAAqB,UAAkB;QAAvC,iBAEC;QAFoB,eAAU,GAAV,UAAU,CAAQ;QAFvC,WAAM,GAAG,KAAK,CAAC;QAUN,SAAI,GAAG;YACd,KAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC,CAAC;QATA,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC;IACjC,CAAC;IAED,qCAAS,GAAT;QACE,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC;IAC7B,CAAC;IAMD,iCAAK,GAAL;QACE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IACH,wBAAC;AAAD,CAAC,AApBD,IAoBC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,UAAc;IAAd,2BAAA,EAAA,cAAc;IAC1C,OAAO,IAAI,iBAAiB,CAAC,UAAU,CAAC,CAAC;AAC3C,CAAC"}
|
package/dist/cjs/update.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Update =
|
|
3
|
+
exports.Update = Update;
|
|
4
4
|
/**
|
|
5
5
|
* Returns the result of given `update` parameter, where it can either directly give a new value,
|
|
6
6
|
* or it is a function receiving the given `value`, and returns a new value.
|
|
@@ -20,5 +20,4 @@ function Update(value, update) {
|
|
|
20
20
|
}
|
|
21
21
|
return update;
|
|
22
22
|
}
|
|
23
|
-
exports.Update = Update;
|
|
24
23
|
//# sourceMappingURL=update.cjs.map
|
package/dist/cjs/update.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.cjs","sourceRoot":"","sources":["../../_cjs_prepare/update.cts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update.cjs","sourceRoot":"","sources":["../../_cjs_prepare/update.cts"],"names":[],"mappings":";;AAkBA,wBAKC;AAlBD;;;;;;;;;;;;GAYG;AACH,SAAgB,MAAM,CAAI,KAAQ,EAAE,MAAiB;IACnD,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QACjC,OAAQ,MAA0B,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
}
|
package/dist/esm/eq.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eq.mjs","sourceRoot":"","sources":["../../src/eq.mts"],"names":[],"mappings":"AAKA,MAAM,KAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"eq.mjs","sourceRoot":"","sources":["../../src/eq.mts"],"names":[],"mappings":"AAKA,MAAM,KAAW,EAAE,CAqalB;AAraD,WAAiB,EAAE;IACjB;;;;;;;;OAQG;IACH,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,CAAC;IAC/B,CAAC;IAZe,qBAAkB,qBAYjC,CAAA;IAED,MAAM,UAAU,GAAY,WAAW,CAAC,MAAM,CAAC,CAAC;IAChD,MAAM,aAAa,GAAY,WAAW,CAAC,SAAS,CAAC,CAAC;IACtD,MAAM,UAAU,GAAY,WAAW,CAAC,MAAM,CAAC,CAAC;IAEhD;;OAEG;IACH,SAAgB,SAAS;QACvB,OAAO,UAAU,CAAC;IACpB,CAAC;IAFe,YAAS,YAExB,CAAA;IAED;;;;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EAAE,CAAC,CAAC;IAE5C;;;;;;;;;;OAUG;IACH,SAAgB,SAAS;QACvB,OAAO,UAAU,CAAC;IACpB,CAAC;IAFe,YAAS,YAExB,CAAA;IAED;;;;;;;;;;;;;;OAcG;IACH,SAAgB,cAAc,CAC5B,KAAY,SAAS,EAAE;QAEvB,OAAO,CAAC,IAAqB,EAAE,IAAqB,EAAW,EAAE,CAC/D,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9C,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC;IANe,iBAAc,iBAM7B,CAAA;AACH,CAAC,EAragB,EAAE,KAAF,EAAE,QAqalB"}
|
package/dist/esm/err.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Throws an `
|
|
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:
|
|
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:
|
|
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 `
|
|
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:
|
|
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:
|
|
40
|
+
* // throws: ErrBase.ForcedError(message: 'not found')
|
|
38
41
|
* ```
|
|
39
42
|
*/
|
|
40
43
|
function msg(message) {
|
package/dist/esm/err.mjs.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
*
|
|
4
|
-
* The `@rimbu/common` package provides
|
|
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';
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
*
|
|
4
|
-
* The `@rimbu/common` package provides
|
|
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
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/index.mts"],"names":[],"mappings":"AAAA
|
|
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.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "Common types and objects used in many other Rimbu packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"common",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"types": "./dist/cjs/index.d.cts",
|
|
35
35
|
"exports": {
|
|
36
36
|
".": {
|
|
37
|
+
"bun": "./dist/bun/index.mts",
|
|
37
38
|
"import": {
|
|
38
39
|
"types": "./dist/esm/index.d.mts",
|
|
39
40
|
"default": "./dist/esm/index.mjs"
|
|
@@ -41,8 +42,7 @@
|
|
|
41
42
|
"require": {
|
|
42
43
|
"types": "./dist/cjs/index.d.cts",
|
|
43
44
|
"default": "./dist/cjs/index.cjs"
|
|
44
|
-
}
|
|
45
|
-
"bun": "./dist/bun/index.mts"
|
|
45
|
+
}
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
"files": [
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"bundle:deno-clean": "rimraf _deno_prepare",
|
|
66
66
|
"bundle:esm": "tsc --p tsconfig.esm.json",
|
|
67
67
|
"clean": "rimraf dist",
|
|
68
|
-
"extract-api": "
|
|
68
|
+
"extract-api": "tsx ../../config/api-extractor.ts config/api-extractor.main.json",
|
|
69
69
|
"format": "yarn format:base --write",
|
|
70
70
|
"format:base": "prettier \"{!CHANGELOG.md}|**/**/*.{ts,tsx,js,mts,mjs,json,md}\"",
|
|
71
71
|
"format:check": "yarn format:base --check",
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"dependencies": {
|
|
83
83
|
"tslib": "^2.6.2"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
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 =
|
|
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 =
|
|
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
|
}
|