@rimbu/common 2.0.0 → 2.0.2
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 +42 -42
- package/dist/bun/err.mts +1 -1
- package/dist/cjs/async-optlazy.cjs +60 -42
- package/dist/cjs/async-optlazy.cjs.map +1 -0
- package/dist/cjs/async-optlazy.d.cts +46 -0
- package/dist/cjs/collect.cjs +9 -31
- package/dist/cjs/collect.cjs.map +1 -0
- package/dist/cjs/collect.d.cts +29 -0
- package/dist/cjs/comp.cjs +518 -707
- package/dist/cjs/comp.cjs.map +1 -0
- package/dist/cjs/comp.d.cts +239 -0
- package/dist/cjs/eq.cjs +375 -203
- package/dist/cjs/eq.cjs.map +1 -0
- package/dist/cjs/err.cjs +57 -50
- package/dist/cjs/err.cjs.map +1 -0
- package/dist/cjs/index-range.cjs +105 -109
- package/dist/cjs/index-range.cjs.map +1 -0
- package/dist/cjs/index-range.d.cts +42 -0
- package/dist/cjs/index.cjs +9 -797
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +6 -0
- package/dist/cjs/internal.cjs +14 -797
- package/dist/cjs/internal.cjs.map +1 -0
- package/dist/cjs/internal.d.cts +11 -0
- package/dist/cjs/optlazy.cjs +43 -37
- package/dist/cjs/optlazy.cjs.map +1 -0
- package/dist/cjs/range.cjs +35 -49
- package/dist/cjs/range.cjs.map +1 -0
- package/dist/cjs/traverse-state.cjs +29 -46
- package/dist/cjs/traverse-state.cjs.map +1 -0
- package/dist/cjs/types.cjs +2 -17
- package/dist/cjs/types.cjs.map +1 -0
- package/dist/cjs/update.cjs +20 -32
- package/dist/cjs/update.cjs.map +1 -0
- package/dist/esm/eq.d.mts +196 -0
- package/dist/esm/err.d.mts +33 -0
- package/dist/esm/optlazy.d.mts +42 -0
- package/dist/esm/range.d.mts +35 -0
- package/dist/esm/traverse-state.d.mts +33 -0
- package/dist/esm/types.d.mts +31 -0
- package/dist/esm/update.d.mts +18 -0
- package/package.json +19 -12
- package/src/err.mts +1 -1
- /package/dist/{types/eq.d.mts → cjs/eq.d.cts} +0 -0
- /package/dist/{types/err.d.mts → cjs/err.d.cts} +0 -0
- /package/dist/{types/optlazy.d.mts → cjs/optlazy.d.cts} +0 -0
- /package/dist/{types/range.d.mts → cjs/range.d.cts} +0 -0
- /package/dist/{types/traverse-state.d.mts → cjs/traverse-state.d.cts} +0 -0
- /package/dist/{types/types.d.mts → cjs/types.d.cts} +0 -0
- /package/dist/{types/update.d.mts → cjs/update.d.cts} +0 -0
- /package/dist/{types → esm}/async-optlazy.d.mts +0 -0
- /package/dist/{types → esm}/collect.d.mts +0 -0
- /package/dist/{types → esm}/comp.d.mts +0 -0
- /package/dist/{types → esm}/index-range.d.mts +0 -0
- /package/dist/{types → esm}/index.d.mts +0 -0
- /package/dist/{types → esm}/internal.d.mts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.cjs","sourceRoot":"","sources":["../../_cjs_prepare/internal.cts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,qDAA2B;AAC3B,mDAAyB;AACzB,oDAA0B;AAC1B,4DAAkC;AAClC,wDAA8B;AAC9B,sDAA4B;AAC5B,+DAAqC;AACrC,sDAA4B;AAC5B,uDAA6B;AAC7B,8DAAoC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './collect.cjs';
|
|
2
|
+
export * from './comp.cjs';
|
|
3
|
+
export * from './eq.cjs';
|
|
4
|
+
export * from './err.cjs';
|
|
5
|
+
export * from './index-range.cjs';
|
|
6
|
+
export * from './optlazy.cjs';
|
|
7
|
+
export * from './range.cjs';
|
|
8
|
+
export * from './traverse-state.cjs';
|
|
9
|
+
export * from './types.cjs';
|
|
10
|
+
export * from './update.cjs';
|
|
11
|
+
export * from './async-optlazy.cjs';
|
package/dist/cjs/optlazy.cjs
CHANGED
|
@@ -1,41 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
function OptLazy(optLazy, ...args) {
|
|
28
|
-
if (optLazy instanceof Function)
|
|
29
|
-
return optLazy(...args);
|
|
30
|
-
return optLazy;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OptLazy = OptLazy;
|
|
4
|
+
exports.OptLazyOr = OptLazyOr;
|
|
5
|
+
var tslib_1 = require("tslib");
|
|
6
|
+
/**
|
|
7
|
+
* Returns the value contained in an `OptLazy` instance of type T.
|
|
8
|
+
* @param optLazy - the `OptLazy` value of type T
|
|
9
|
+
* @param args - when needed, the extra arguments to pass to the lazy invocation
|
|
10
|
+
* @typeparam T - the value type
|
|
11
|
+
* @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* OptLazy(1) // => 1
|
|
15
|
+
* OptLazy(() => 1) // => 1
|
|
16
|
+
* OptLazy(() => () => 1) // => () => 1
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function OptLazy(optLazy) {
|
|
20
|
+
var args = [];
|
|
21
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
22
|
+
args[_i - 1] = arguments[_i];
|
|
23
|
+
}
|
|
24
|
+
if (optLazy instanceof Function)
|
|
25
|
+
return optLazy.apply(void 0, tslib_1.__spreadArray([], tslib_1.__read(args), false));
|
|
26
|
+
return optLazy;
|
|
31
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns the value contained in an `OptLazyOr` instance of type T, or the given
|
|
30
|
+
* `otherValue` if the lazy function returns it.
|
|
31
|
+
* @param optLazyOr - a value or a function returning a value or otherwise the received value
|
|
32
|
+
* @param otherValue - the value to return if the optLazyOr does not return its own value
|
|
33
|
+
* @typeparam T - the value type
|
|
34
|
+
* @typeparam O - the default value type
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* OptLazyOr(1, 'a') // => 1
|
|
38
|
+
* OptLazyOr(() => 1, 'a') // => 1
|
|
39
|
+
* OptLazyOr((none) => none, 'a') // => 'a'
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
32
42
|
function OptLazyOr(optLazyOr, otherValue) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
43
|
+
if (optLazyOr instanceof Function)
|
|
44
|
+
return optLazyOr(otherValue);
|
|
45
|
+
return optLazyOr;
|
|
36
46
|
}
|
|
37
|
-
|
|
38
|
-
0 && (module.exports = {
|
|
39
|
-
OptLazy,
|
|
40
|
-
OptLazyOr
|
|
41
|
-
});
|
|
47
|
+
//# sourceMappingURL=optlazy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/dist/cjs/range.cjs
CHANGED
|
@@ -1,52 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/range.mts
|
|
21
|
-
var range_exports = {};
|
|
22
|
-
__export(range_exports, {
|
|
23
|
-
Range: () => Range
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(range_exports);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Range = void 0;
|
|
26
4
|
var Range;
|
|
27
|
-
((
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
5
|
+
(function (Range) {
|
|
6
|
+
/**
|
|
7
|
+
* Simplifies a given `range` `Range` input for easier processing, by returning optional
|
|
8
|
+
* start and end ranges including whether they are inclusive or exclusive
|
|
9
|
+
* @param range - the `Range` to use
|
|
10
|
+
*/
|
|
11
|
+
function getNormalizedRange(range) {
|
|
12
|
+
var start = undefined;
|
|
13
|
+
var end = undefined;
|
|
14
|
+
if ("start" in range && undefined !== range.start) {
|
|
15
|
+
if (Array.isArray(range.start) &&
|
|
16
|
+
range.start.length === 2 &&
|
|
17
|
+
typeof range.start[1] === 'boolean') {
|
|
18
|
+
start = range.start;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
start = [range.start, true];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if ("end" in range && undefined !== range.end) {
|
|
25
|
+
if (Array.isArray(range.end) &&
|
|
26
|
+
range.end.length === 2 &&
|
|
27
|
+
typeof range.end[1] === 'boolean') {
|
|
28
|
+
end = range.end;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
end = [range.end, true];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return { start: start, end: end };
|
|
37
35
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
} else {
|
|
42
|
-
end = [range.end, true];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return { start, end };
|
|
46
|
-
}
|
|
47
|
-
Range2.getNormalizedRange = getNormalizedRange;
|
|
48
|
-
})(Range || (Range = {}));
|
|
49
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
-
0 && (module.exports = {
|
|
51
|
-
Range
|
|
52
|
-
});
|
|
36
|
+
Range.getNormalizedRange = getNormalizedRange;
|
|
37
|
+
})(Range || (exports.Range = Range = {}));
|
|
38
|
+
//# sourceMappingURL=range.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range.cjs","sourceRoot":"","sources":["../../_cjs_prepare/range.cts"],"names":[],"mappings":";;;AAmBA,IAAiB,KAAK,CAsCrB;AAtCD,WAAiB,KAAK;IACpB;;;;OAIG;IACH,SAAgB,kBAAkB,CAAI,KAAe;QAInD,IAAI,KAAK,GAA6B,SAAS,CAAC;QAChD,IAAI,GAAG,GAA6B,SAAS,CAAC;QAE9C,IAAI,OAAO,IAAI,KAAK,IAAI,SAAS,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC;YAClD,IACE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;gBAC1B,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;gBACxB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,EACnC,CAAC;gBACD,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YACtB,CAAC;iBAAM,CAAC;gBACN,KAAK,GAAG,CAAC,KAAK,CAAC,KAAU,EAAE,IAAI,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;QACD,IAAI,KAAK,IAAI,KAAK,IAAI,SAAS,KAAK,KAAK,CAAC,GAAG,EAAE,CAAC;YAC9C,IACE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC;gBACxB,KAAK,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC;gBACtB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,EACjC,CAAC;gBACD,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;YAClB,CAAC;iBAAM,CAAC;gBACN,GAAG,GAAG,CAAC,KAAK,CAAC,GAAQ,EAAE,IAAI,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QAED,OAAO,EAAE,KAAK,OAAA,EAAE,GAAG,KAAA,EAAE,CAAC;IACxB,CAAC;IA/Be,wBAAkB,qBA+BjC,CAAA;AACH,CAAC,EAtCgB,KAAK,qBAAL,KAAK,QAsCrB"}
|
|
@@ -1,49 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/traverse-state.mts
|
|
21
|
-
var traverse_state_exports = {};
|
|
22
|
-
__export(traverse_state_exports, {
|
|
23
|
-
TraverseState: () => TraverseState
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(traverse_state_exports);
|
|
26
|
-
var TraverseStateImpl = class {
|
|
27
|
-
constructor(startIndex) {
|
|
28
|
-
this.startIndex = startIndex;
|
|
29
|
-
this.halted = false;
|
|
30
|
-
this.halt = () => {
|
|
31
|
-
this.halted = true;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TraverseState = TraverseState;
|
|
4
|
+
var TraverseStateImpl = /** @class */ (function () {
|
|
5
|
+
function TraverseStateImpl(startIndex) {
|
|
6
|
+
var _this = this;
|
|
7
|
+
this.startIndex = startIndex;
|
|
8
|
+
this.halted = false;
|
|
9
|
+
this.halt = function () {
|
|
10
|
+
_this.halted = true;
|
|
11
|
+
};
|
|
12
|
+
this.currentIndex = startIndex;
|
|
13
|
+
}
|
|
14
|
+
TraverseStateImpl.prototype.nextIndex = function () {
|
|
15
|
+
return this.currentIndex++;
|
|
32
16
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
17
|
+
TraverseStateImpl.prototype.reset = function () {
|
|
18
|
+
this.currentIndex = this.startIndex;
|
|
19
|
+
this.halted = false;
|
|
20
|
+
};
|
|
21
|
+
return TraverseStateImpl;
|
|
22
|
+
}());
|
|
23
|
+
/**
|
|
24
|
+
* Returns a new `TraverseState` instance, using optionally given `startIndex` as a start
|
|
25
|
+
* index value.
|
|
26
|
+
* @param startIndex - (default: 0) the start index to use
|
|
27
|
+
*/
|
|
28
|
+
function TraverseState(startIndex) {
|
|
29
|
+
if (startIndex === void 0) { startIndex = 0; }
|
|
30
|
+
return new TraverseStateImpl(startIndex);
|
|
45
31
|
}
|
|
46
|
-
|
|
47
|
-
0 && (module.exports = {
|
|
48
|
-
TraverseState
|
|
49
|
-
});
|
|
32
|
+
//# sourceMappingURL=traverse-state.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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/types.cjs
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
|
|
16
|
-
// src/types.mts
|
|
17
|
-
var types_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(types_exports);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../_cjs_prepare/types.cts"],"names":[],"mappings":""}
|
package/dist/cjs/update.cjs
CHANGED
|
@@ -1,35 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/update.mts
|
|
21
|
-
var update_exports = {};
|
|
22
|
-
__export(update_exports, {
|
|
23
|
-
Update: () => Update
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(update_exports);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Update = Update;
|
|
4
|
+
/**
|
|
5
|
+
* Returns the result of given `update` parameter, where it can either directly give a new value,
|
|
6
|
+
* or it is a function receiving the given `value`, and returns a new value.
|
|
7
|
+
* @param value - the current value
|
|
8
|
+
* @param update - an `Update` value, either a new value or a function receiving the old value
|
|
9
|
+
* and returning a new one.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* Update(1, 2) // => 2
|
|
13
|
+
* Update(1, () => 10) // => 10
|
|
14
|
+
* Update(1, v => v + 1) // => 2
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
26
17
|
function Update(value, update) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
if (typeof update === 'function') {
|
|
19
|
+
return update(value);
|
|
20
|
+
}
|
|
21
|
+
return update;
|
|
31
22
|
}
|
|
32
|
-
|
|
33
|
-
0 && (module.exports = {
|
|
34
|
-
Update
|
|
35
|
-
});
|
|
23
|
+
//# sourceMappingURL=update.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function returning true if given `v1` and `v2` should be considered equal.
|
|
3
|
+
*/
|
|
4
|
+
export type Eq<T> = (v1: T, v2: T) => boolean;
|
|
5
|
+
export declare namespace Eq {
|
|
6
|
+
function convertAnyToString(value: any): string;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the default Eq instance, which is the Eq.anyDeepEq() instance.
|
|
9
|
+
*/
|
|
10
|
+
function defaultEq(): Eq<any>;
|
|
11
|
+
/**
|
|
12
|
+
* An Eq instance that uses `Object.is` to determine if two objects are equal.
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const eq = Eq.objectIs
|
|
16
|
+
* console.log(eq(5, 5))
|
|
17
|
+
* // => true
|
|
18
|
+
* console.log(eq(5, 'a'))
|
|
19
|
+
* // => false
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
const objectIs: Eq<any>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns an Eq instance for objects that have a `valueOf` method. It returns true if the `.valueOf` values of both given objects are equal.
|
|
25
|
+
* @typeparam T - the object type containing a valueOf function of type V
|
|
26
|
+
* @typeparam V - the valueOf result type
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const eq = Eq.valueOfEq()
|
|
30
|
+
* console.log(eq(new Number(5), new Number(5)))
|
|
31
|
+
* // => true
|
|
32
|
+
* console.log(eq(new Number(5), new Number(3)))
|
|
33
|
+
* // => false
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
function valueOfEq<T extends {
|
|
37
|
+
valueOf(): V;
|
|
38
|
+
}, V>(): Eq<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Returns an Eq instance that compares Date objects according to their `valueOf` value.
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const eq = Eq.dateEq()
|
|
44
|
+
* console.log(eq(new Date(2020, 1, 1), new Date(2020, 1, 1))
|
|
45
|
+
* // => true
|
|
46
|
+
* console.log(eq(new Date(2020, 1, 1), new Date(2020, 2, 1))
|
|
47
|
+
* // => false
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
function dateEq(): Eq<Date>;
|
|
51
|
+
/**
|
|
52
|
+
* Returns an Eq instance that compares Iterables by comparing their elements with the given `itemEq` Eq instance.
|
|
53
|
+
* @typeparam T - the Iterable element type
|
|
54
|
+
* @param itemEq - (optional) the Eq instance to use to compare the Iterable's elements
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const eq = Eq.iterableEq();
|
|
58
|
+
* console.log(eq([1, 2, 3], [1, 2, 3])
|
|
59
|
+
* // => true
|
|
60
|
+
* console.log(eq([1, 2, 3], [1, 3, 2])
|
|
61
|
+
* // => false
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
function iterableEq<T>(itemEq?: Eq<T>): Eq<Iterable<T>>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns an Eq instance that checks equality of objects containing property values of type V by iteratively
|
|
67
|
+
* applying given `valueEq` to each of the object's property values.
|
|
68
|
+
* @typeparam - the object property value type
|
|
69
|
+
* @param valueEq - (optional) the Eq instance to use to compare property values
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const eq = Eq.objectEq()
|
|
73
|
+
* console.log(eq({ a: 1, b: { c: 2 }}, { b: { c: 2 }, a: 1 }))
|
|
74
|
+
* // => true
|
|
75
|
+
* console.log(eq({ a: 1, b: { c: 2 }}, { a: 1, b: { c: 3 }}))
|
|
76
|
+
* // => false
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
function objectEq<V = any>(valueEq?: Eq<V>): Eq<Record<any, V>>;
|
|
80
|
+
/**
|
|
81
|
+
* Returns an Eq instance that checks equality of any values. For composed values (objects and iterables)
|
|
82
|
+
* it will compare with Object.is.
|
|
83
|
+
* @typeparam T - the value type
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const eq = anyFlatEq()
|
|
87
|
+
* console.log(eq(1, 'a'))
|
|
88
|
+
* // => false
|
|
89
|
+
* console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
|
|
90
|
+
* // => false
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
function anyFlatEq<T = any>(): Eq<T>;
|
|
94
|
+
/**
|
|
95
|
+
* Returns an Eq instance that checks equality of any values. For composed values (objects and iterables)
|
|
96
|
+
* it will enter 1 level, and if again compound values are found, they are compared
|
|
97
|
+
* with Object.is.
|
|
98
|
+
* @typeparam T - the value type
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* const eq = anyFlatEq()
|
|
102
|
+
* console.log(eq(1, 'a'))
|
|
103
|
+
* // => false
|
|
104
|
+
* console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
|
|
105
|
+
* // => true
|
|
106
|
+
* console.log(eq([{ a: 1, b: 2 }], [{ b: 2, a: 1 }]))
|
|
107
|
+
* // => false
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
function anyShallowEq<T = any>(): Eq<T>;
|
|
111
|
+
/**
|
|
112
|
+
* Returns an Eq instance that checks equality of any values. For composed values (objects and iterables)
|
|
113
|
+
* it will recursively compare the contained values.
|
|
114
|
+
* @note may have poor performance for deeply nested types and large arrays, and objects with circular structures
|
|
115
|
+
* may cause infinite loops
|
|
116
|
+
* @typeparam T - the value type
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const eq = anyFlatEq()
|
|
120
|
+
* console.log(eq(1, 'a'))
|
|
121
|
+
* // => false
|
|
122
|
+
* console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
|
|
123
|
+
* // => true
|
|
124
|
+
* console.log(eq([{ a: 1, b: 2 }], [{ b: 2, a: 1 }]))
|
|
125
|
+
* // => false
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
function anyDeepEq<T = any>(): Eq<T>;
|
|
129
|
+
/**
|
|
130
|
+
* Returns an Eq instance that considers strings equal taking the given or default locale into account.
|
|
131
|
+
* @param locales - (optional) a locale or list of locales
|
|
132
|
+
* @param options - (optional) see String.localeCompare for details
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* const eq = Eq.createStringCollatorEq()
|
|
136
|
+
* console.log(eq('a', 'a'))
|
|
137
|
+
* // => true
|
|
138
|
+
* console.log(eq('abc', 'aBc'))
|
|
139
|
+
* // => false
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
function createStringCollatorEq(...args: ConstructorParameters<typeof Intl.Collator>): Eq<string>;
|
|
143
|
+
/**
|
|
144
|
+
* Returns an Eq instance that considers strings equal regardless of their case.
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* const eq = Eq.stringCaseInsentitiveEq()
|
|
148
|
+
* console.log(eq('aB', 'Ab'))
|
|
149
|
+
* // => true
|
|
150
|
+
* console.log(eq('aBc', 'abB'))
|
|
151
|
+
* // => false
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
function stringCaseInsentitiveEq(): Eq<string>;
|
|
155
|
+
/**
|
|
156
|
+
* Returns an Eq instance that considers strings equal when all their charcodes are equal.
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* const eq = Eq.stringCharCodeEq()
|
|
160
|
+
* console.log(eq('a', 'a'))
|
|
161
|
+
* // => true
|
|
162
|
+
* console.log(eq('abc', 'aBc'))
|
|
163
|
+
* // => false
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
function stringCharCodeEq(): Eq<string>;
|
|
167
|
+
function anyToStringEq(): Eq<any>;
|
|
168
|
+
/**
|
|
169
|
+
* Returns an Eq instance that considers values equal their JSON.stringify values are equal.
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* const eq = Eq.anyJsonEq()
|
|
173
|
+
* console.log(eq({ a: 1, b: 2 }, { a: 1, b: 2 }))
|
|
174
|
+
* // => true
|
|
175
|
+
* console.log(eq({ a: 1, b: 2 }, { b: 2, a: 1 }))
|
|
176
|
+
* // => false
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
function anyJsonEq(): Eq<any>;
|
|
180
|
+
/**
|
|
181
|
+
* Returns an `Eq` instance for tuples that considers two tuples [A, B] and [C, D] equal if [A, B] equals [C, D],
|
|
182
|
+
* or if [A, B] equals [D, C]
|
|
183
|
+
* @param eq - (optional) an alternative `Eq` instance to use for the values in the tuple
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* const eq = Eq.tupleSymmetric()
|
|
187
|
+
* console.log(eq([1, 2], [1, 2]))
|
|
188
|
+
* // => true
|
|
189
|
+
* console.log(eq([1, 2], [2, 1]))
|
|
190
|
+
* // => true
|
|
191
|
+
* console.log(eq([1, 3], [2, 1]))
|
|
192
|
+
* // => false
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
function tupleSymmetric<T>(eq?: Eq<T>): Eq<readonly [T, T]>;
|
|
196
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throws an `Err.ForcedError` error when called.
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* const emptyMap = HashMap.empty<number, string>()
|
|
6
|
+
* emptyMap.get(5, Err);
|
|
7
|
+
* // throws: Err.CustomError(message: 'Err: forced to throw error')
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare function Err(): never;
|
|
11
|
+
export declare namespace ErrBase {
|
|
12
|
+
/**
|
|
13
|
+
* A custom error instance.
|
|
14
|
+
*/
|
|
15
|
+
abstract class CustomError {
|
|
16
|
+
readonly message: string;
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
get name(): string;
|
|
19
|
+
}
|
|
20
|
+
class ForcedError extends CustomError {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns a function that, when called, throws an `Err.ForcedError` with the given `message` string.
|
|
24
|
+
* @param message - the message to put in the `Err.ForcedError` instance.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const emptyMap = HashMap.empty<number, string>()
|
|
28
|
+
* emptyMap.get(5, ErrBase.msg('not found'));
|
|
29
|
+
* // throws: Err.CustomError(message: 'not found')
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function msg(message: string): () => never;
|
|
33
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A potentially lazy value of type T.
|
|
3
|
+
* @typeparam T - the value type
|
|
4
|
+
* @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
|
|
5
|
+
*/
|
|
6
|
+
export type OptLazy<T, A extends any[] = []> = T | ((...args: A) => T);
|
|
7
|
+
/**
|
|
8
|
+
* Returns the value contained in an `OptLazy` instance of type T.
|
|
9
|
+
* @param optLazy - the `OptLazy` value of type T
|
|
10
|
+
* @param args - when needed, the extra arguments to pass to the lazy invocation
|
|
11
|
+
* @typeparam T - the value type
|
|
12
|
+
* @typeparam A - (default: []) types of the argument array that can be passed in the lazy case
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* OptLazy(1) // => 1
|
|
16
|
+
* OptLazy(() => 1) // => 1
|
|
17
|
+
* OptLazy(() => () => 1) // => () => 1
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function OptLazy<T, A extends any[] = []>(optLazy: OptLazy<T, A>, ...args: A): T;
|
|
21
|
+
/**
|
|
22
|
+
* A potentially lazy value that, in case of a lazy function, received a default value
|
|
23
|
+
* that it can return.
|
|
24
|
+
* @typeparam T - the value type
|
|
25
|
+
* @typeparam O - the default value type
|
|
26
|
+
*/
|
|
27
|
+
export type OptLazyOr<T, O> = T | ((none: O) => T | O);
|
|
28
|
+
/**
|
|
29
|
+
* Returns the value contained in an `OptLazyOr` instance of type T, or the given
|
|
30
|
+
* `otherValue` if the lazy function returns it.
|
|
31
|
+
* @param optLazyOr - a value or a function returning a value or otherwise the received value
|
|
32
|
+
* @param otherValue - the value to return if the optLazyOr does not return its own value
|
|
33
|
+
* @typeparam T - the value type
|
|
34
|
+
* @typeparam O - the default value type
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* OptLazyOr(1, 'a') // => 1
|
|
38
|
+
* OptLazyOr(() => 1, 'a') // => 1
|
|
39
|
+
* OptLazyOr((none) => none, 'a') // => 'a'
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function OptLazyOr<T, O>(optLazyOr: OptLazyOr<T, O>, otherValue: O): T | O;
|