ts-data-forge 6.4.0 → 6.5.0
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 +5 -3
- package/dist/array/impl/array-utils-element-access.d.mts +5 -5
- package/dist/array/impl/array-utils-element-access.mjs +4 -4
- package/dist/array/impl/array-utils-iterators.d.mts +1 -1
- package/dist/array/impl/array-utils-iterators.mjs +1 -1
- package/dist/array/impl/array-utils-modification.d.mts +4 -4
- package/dist/array/impl/array-utils-reducing-value.d.mts +5 -5
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +1 -0
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts +8 -8
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +3 -1
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +1 -1
- package/dist/array/impl/array-utils-size.mjs +1 -1
- package/dist/array/impl/array-utils-slice-clamped.d.mts +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts +3 -3
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +7 -7
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +22 -12
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/collections/imap.d.mts +19 -16
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +1 -1
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +2 -2
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +1 -1
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +1 -0
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/entry-point.mjs +1 -0
- package/dist/entry-point.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts +1 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +6 -5
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-zip.d.mts +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +1 -1
- package/dist/functional/result/impl/result-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-result.d.mts +1 -1
- package/dist/functional/result/impl/result-is-result.mjs +1 -1
- package/dist/functional/result/impl/result-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +1 -0
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +1 -0
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
- package/dist/guard/has-key.d.mts +3 -1
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +6 -2
- package/dist/guard/has-key.mjs.map +1 -1
- package/dist/guard/is-non-null-object.d.mts.map +1 -1
- package/dist/guard/is-non-null-object.mjs +3 -1
- package/dist/guard/is-non-null-object.mjs.map +1 -1
- package/dist/guard/is-record.d.mts +2 -2
- package/dist/guard/is-record.mjs +2 -2
- package/dist/guard/is-type.d.mts +15 -15
- package/dist/guard/is-type.mjs +15 -15
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +3 -1
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/json/json.d.mts +3 -3
- package/dist/json/json.mjs +4 -3
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +2 -2
- package/dist/number/branded-types/positive-safe-int.mjs +1 -1
- package/dist/number/branded-types/safe-int.mjs +2 -2
- package/dist/number/branded-types/safe-uint.mjs +1 -1
- package/dist/number/num.mjs +1 -1
- package/dist/object/object.d.mts +8 -8
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +7 -6
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/fast-deep-equal.d.mts +8 -0
- package/dist/others/fast-deep-equal.d.mts.map +1 -0
- package/dist/others/fast-deep-equal.mjs +72 -0
- package/dist/others/fast-deep-equal.mjs.map +1 -0
- package/dist/others/index.d.mts +1 -0
- package/dist/others/index.d.mts.map +1 -1
- package/dist/others/index.mjs +1 -0
- package/dist/others/index.mjs.map +1 -1
- package/package.json +22 -17
- package/src/array/impl/array-utils-creation.test.mts +13 -10
- package/src/array/impl/array-utils-element-access.mts +5 -5
- package/src/array/impl/array-utils-element-access.test.mts +5 -5
- package/src/array/impl/array-utils-iterators.mts +1 -1
- package/src/array/impl/array-utils-iterators.test.mts +6 -6
- package/src/array/impl/array-utils-modification.mts +4 -4
- package/src/array/impl/array-utils-modification.test.mts +12 -12
- package/src/array/impl/array-utils-overload-type-error.test.mts +1 -1
- package/src/array/impl/array-utils-reducing-value.mts +6 -5
- package/src/array/impl/array-utils-reducing-value.test.mts +9 -9
- package/src/array/impl/array-utils-search.mts +8 -8
- package/src/array/impl/array-utils-search.test.mts +35 -35
- package/src/array/impl/array-utils-set-op.mts +1 -0
- package/src/array/impl/array-utils-set-op.test.mts +2 -2
- package/src/array/impl/array-utils-size.mts +1 -1
- package/src/array/impl/array-utils-size.test.mts +1 -1
- package/src/array/impl/array-utils-slice-clamped.mts +1 -1
- package/src/array/impl/array-utils-slice-clamped.test.mts +5 -5
- package/src/array/impl/array-utils-slicing.mts +3 -3
- package/src/array/impl/array-utils-slicing.test.mts +5 -5
- package/src/array/impl/array-utils-transformation.mts +1 -1
- package/src/array/impl/array-utils-transformation.test.mts +53 -53
- package/src/array/impl/array-utils-validation.mts +18 -10
- package/src/array/impl/array-utils-validation.test.mts +34 -29
- package/src/array/impl/array.test.mts +1 -1
- package/src/collections/imap-mapped.test.mts +9 -9
- package/src/collections/imap.mts +20 -17
- package/src/collections/imap.test.mts +6 -6
- package/src/collections/iset-mapped.mts +7 -6
- package/src/collections/iset-mapped.test.mts +6 -6
- package/src/collections/iset.mts +6 -5
- package/src/collections/queue.test.mts +2 -1
- package/src/collections/stack.test.mts +3 -3
- package/src/functional/optional/impl/optional-is-optional.mts +6 -6
- package/src/functional/optional/impl/optional-some.mts +5 -4
- package/src/functional/optional/impl/optional-zip.mts +1 -1
- package/src/functional/result/impl/result-err.mts +5 -4
- package/src/functional/result/impl/result-is-result.mts +1 -1
- package/src/functional/result/impl/result-ok.mts +5 -4
- package/src/functional/result.test.mts +2 -2
- package/src/functional/ternary-result/impl/ternary-result-err.mts +5 -4
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-ok.mts +5 -4
- package/src/functional/ternary-result/impl/ternary-result-warn.mts +6 -5
- package/src/guard/has-key.mts +6 -2
- package/src/guard/is-error.test.mts +1 -1
- package/src/guard/is-non-empty-string.test.mts +1 -1
- package/src/guard/is-non-null-object.mts +1 -0
- package/src/guard/is-non-null-object.test.mts +4 -3
- package/src/guard/is-primitive.test.mts +1 -1
- package/src/guard/is-record.mts +2 -2
- package/src/guard/is-record.test.mts +2 -2
- package/src/guard/is-type.mts +15 -15
- package/src/guard/is-type.test.mts +2 -2
- package/src/guard/key-is-in.mts +3 -1
- package/src/json/json.mts +4 -3
- package/src/json/json.test.mts +20 -19
- package/src/number/branded-types/non-zero-safe-int.mts +2 -2
- package/src/number/branded-types/positive-safe-int.mts +1 -1
- package/src/number/branded-types/safe-int.mts +2 -2
- package/src/number/branded-types/safe-uint.mts +1 -1
- package/src/number/num.mts +1 -1
- package/src/object/object.mts +9 -8
- package/src/object/object.test.mts +12 -7
- package/src/others/cast-mutable.test.mts +3 -3
- package/src/others/cast-readonly.test.mts +8 -5
- package/src/others/fast-deep-equal.mts +98 -0
- package/src/others/fast-deep-equal.test.mts +769 -0
- package/src/others/index.mts +1 -0
- package/src/others/map-nullable.test.mts +8 -8
- package/src/others/memoize-function.test.mts +20 -8
- package/src/others/unknown-to-string.test.mts +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.mjs","sources":["../../src/object/object.mts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;AAOG;AACG,IAAW;AAAjB,CAAA,UAAiB,GAAG,EAAA;AAClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCG;IACU,GAAA,CAAA,SAAS,GAAG,CACv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
|
2
|
+
* The fastest deep equal with ES6 Map, Set and Typed arrays support.
|
|
3
|
+
* Checks equality of Date and RegExp objects by value.
|
|
4
|
+
*
|
|
5
|
+
* Forked from https://github.com/epoberezkin/fast-deep-equal/blob/v3.1.3/src/index.jst
|
|
6
|
+
*/
|
|
7
|
+
export declare const fastDeepEqual: <T>(a: T, b: T) => boolean;
|
|
8
|
+
//# sourceMappingURL=fast-deep-equal.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fast-deep-equal.d.mts","sourceRoot":"","sources":["../../src/others/fast-deep-equal.mts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAAG,GAAG,CAAC,EAAE,GAAG,CAAC,KAAG,OAqF9C,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { isMap, isSet, isTypedArray, isRegExp } from '@sindresorhus/is';
|
|
2
|
+
import { hasKey } from '../guard/has-key.mjs';
|
|
3
|
+
import { isRecord } from '../guard/is-record.mjs';
|
|
4
|
+
|
|
5
|
+
/* eslint-disable ts-data-forge/prefer-arr-is-array-of-length */
|
|
6
|
+
/* eslint-disable ts-data-forge/prefer-arr-is-array */
|
|
7
|
+
/**
|
|
8
|
+
* The fastest deep equal with ES6 Map, Set and Typed arrays support.
|
|
9
|
+
* Checks equality of Date and RegExp objects by value.
|
|
10
|
+
*
|
|
11
|
+
* Forked from https://github.com/epoberezkin/fast-deep-equal/blob/v3.1.3/src/index.jst
|
|
12
|
+
*/
|
|
13
|
+
const fastDeepEqual = (a, b) => {
|
|
14
|
+
if (a === b) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (typeof a !== typeof b) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (isRecord(a)) {
|
|
21
|
+
if (!isRecord(b)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (a.constructor !== b.constructor) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(a)) {
|
|
28
|
+
return (Array.isArray(b) &&
|
|
29
|
+
a.length === b.length &&
|
|
30
|
+
a.every((ai, index) => fastDeepEqual(ai, b[index])));
|
|
31
|
+
}
|
|
32
|
+
if (isMap(a)) {
|
|
33
|
+
return (isMap(b) &&
|
|
34
|
+
a.size === b.size &&
|
|
35
|
+
Array.from(a.entries()).every(([key, value]) => b.has(key) && fastDeepEqual(value, b.get(key))));
|
|
36
|
+
}
|
|
37
|
+
if (isSet(a)) {
|
|
38
|
+
return (isSet(b) &&
|
|
39
|
+
a.size === b.size &&
|
|
40
|
+
Array.from(a.entries()).every(([value]) => b.has(value)));
|
|
41
|
+
}
|
|
42
|
+
if (isTypedArray(a)) {
|
|
43
|
+
return (isTypedArray(b) &&
|
|
44
|
+
a.length === b.length &&
|
|
45
|
+
a.every((value, index) => value === b[index]));
|
|
46
|
+
}
|
|
47
|
+
if (isRegExp(a)) {
|
|
48
|
+
return isRegExp(b) && a.source === b.source && a.flags === b.flags;
|
|
49
|
+
}
|
|
50
|
+
if (a.valueOf !== Object.prototype.valueOf) {
|
|
51
|
+
return a.valueOf() === b.valueOf();
|
|
52
|
+
}
|
|
53
|
+
if (a.toString !== Object.prototype.toString) {
|
|
54
|
+
return a.toString() === b.toString();
|
|
55
|
+
}
|
|
56
|
+
const aKeys = Object.keys(a);
|
|
57
|
+
const bKeys = Object.keys(b);
|
|
58
|
+
return (aKeys.length === bKeys.length &&
|
|
59
|
+
aKeys.every((key) => hasKey(b, key) &&
|
|
60
|
+
// React-specific: avoid traversing React elements' _owner.
|
|
61
|
+
// _owner contains circular references
|
|
62
|
+
// and is not needed when comparing the actual elements (and not their owners)
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
64
|
+
!(key === '_owner' && a['$$typeof']) &&
|
|
65
|
+
fastDeepEqual(a[key], b[key])));
|
|
66
|
+
}
|
|
67
|
+
// true if both NaN, false otherwise
|
|
68
|
+
return Number.isNaN(a) && Number.isNaN(b);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export { fastDeepEqual };
|
|
72
|
+
//# sourceMappingURL=fast-deep-equal.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fast-deep-equal.mjs","sources":["../../src/others/fast-deep-equal.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA;AACA;AAKA;;;;;AAKG;MACU,aAAa,GAAG,CAAK,CAAI,EAAE,CAAI,KAAa;AACvD,IAAA,IAAI,CAAC,KAAK,CAAC,EAAE;AACX,QAAA,OAAO,IAAI;IACb;AAEA,IAAA,IAAI,OAAO,CAAC,KAAK,OAAO,CAAC,EAAE;AACzB,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE;AACf,QAAA,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;AAChB,YAAA,OAAO,KAAK;QACd;QAEA,IAAI,CAAC,CAAC,WAAW,KAAK,CAAC,CAAC,WAAW,EAAE;AACnC,YAAA,OAAO,KAAK;QACd;AAEA,QAAA,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;AACpB,YAAA,QACE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AAChB,gBAAA,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;gBACrB,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,KAAK,KAAK,aAAa,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QAEvD;AAEA,QAAA,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;AACZ,YAAA,QACE,KAAK,CAAC,CAAC,CAAC;AACR,gBAAA,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI;AACjB,gBAAA,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,KAAK,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,GAAsB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAE/C,MAAM,KAAK,GAAsB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AAE/C,QAAA,QACE,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;AAC7B,YAAA,KAAK,CAAC,KAAK,CACT,CAAC,GAAG,KACF,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC;;;;;gBAKd,EAAE,GAAG,KAAK,QAAQ,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC;AACpC,gBAAA,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAChC;IAEL;;AAGA,IAAA,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3C;;;;"}
|
package/dist/others/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './cast-mutable.mjs';
|
|
2
2
|
export * from './cast-readonly.mjs';
|
|
3
3
|
export * from './debounce-function.mjs';
|
|
4
|
+
export * from './fast-deep-equal.mjs';
|
|
4
5
|
export * from './if-then.mjs';
|
|
5
6
|
export * from './map-nullable.mjs';
|
|
6
7
|
export * from './memoize-function.mjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/others/index.mts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/others/index.mts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC"}
|
package/dist/others/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { castDeepMutable, castMutable } from './cast-mutable.mjs';
|
|
2
2
|
export { castDeepReadonly, castReadonly } from './cast-readonly.mjs';
|
|
3
3
|
export { debounce } from './debounce-function.mjs';
|
|
4
|
+
export { fastDeepEqual } from './fast-deep-equal.mjs';
|
|
4
5
|
export { ifThen } from './if-then.mjs';
|
|
5
6
|
export { mapNullable } from './map-nullable.mjs';
|
|
6
7
|
export { memoizeFunction } from './memoize-function.mjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-data-forge",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -41,8 +41,12 @@
|
|
|
41
41
|
"check-all": "tsx ./scripts/cmd/check-all.mts",
|
|
42
42
|
"clean": "pnpm run /clean:.*/",
|
|
43
43
|
"clean:logs": "npx rimraf ./*.log",
|
|
44
|
-
"codemod": "run-s codemod:
|
|
45
|
-
"codemod:
|
|
44
|
+
"codemod": "run-s codemod:uncommitted:as-const fmt codemod:uncommitted:readonly fmt",
|
|
45
|
+
"codemod:full": "run-s codemod:full:as-const fmt codemod:full:readonly fmt",
|
|
46
|
+
"codemod:full:as-const": "append-as-const '{src,scripts,samples,test}/**/*.{mts,tsx}'",
|
|
47
|
+
"codemod:full:readonly": "convert-to-readonly '{src,scripts,samples,test}/**/*.{mts,tsx}'",
|
|
48
|
+
"codemod:uncommitted:as-const": "append-as-const --uncommitted '{src,scripts,samples,test}/**/*.{mts,tsx}'",
|
|
49
|
+
"codemod:uncommitted:readonly": "convert-to-readonly --uncommitted '{src,scripts,samples,test}/**/*.{mts,tsx}'",
|
|
46
50
|
"cspell": "cspell \"**\" --gitignore --gitignore-root ./ --no-progress",
|
|
47
51
|
"doc": "tsx ./scripts/cmd/gen-docs.mts",
|
|
48
52
|
"doc:embed": "tsx ./scripts/cmd/embed-examples.mts",
|
|
@@ -92,32 +96,33 @@
|
|
|
92
96
|
"@semantic-release/commit-analyzer": "13.0.1",
|
|
93
97
|
"@semantic-release/exec": "7.1.0",
|
|
94
98
|
"@semantic-release/git": "10.0.1",
|
|
95
|
-
"@semantic-release/github": "12.0.
|
|
99
|
+
"@semantic-release/github": "12.0.3",
|
|
96
100
|
"@semantic-release/npm": "13.1.3",
|
|
97
101
|
"@semantic-release/release-notes-generator": "14.1.0",
|
|
98
|
-
"@types/node": "25.0
|
|
99
|
-
"@types/react": "19.2.
|
|
100
|
-
"@vitest/browser-playwright": "4.0.
|
|
101
|
-
"@vitest/coverage-v8": "4.0.
|
|
102
|
-
"@vitest/ui": "4.0.
|
|
102
|
+
"@types/node": "25.2.0",
|
|
103
|
+
"@types/react": "19.2.13",
|
|
104
|
+
"@vitest/browser-playwright": "4.0.18",
|
|
105
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
106
|
+
"@vitest/ui": "4.0.18",
|
|
103
107
|
"conventional-changelog-conventionalcommits": "9.1.0",
|
|
104
|
-
"cspell": "9.6.
|
|
108
|
+
"cspell": "9.6.4",
|
|
105
109
|
"dedent": "^1.7.1",
|
|
106
110
|
"eslint": "9.39.2",
|
|
107
|
-
"eslint-config-typed": "4.6.
|
|
108
|
-
"github-settings-as-code": "1.
|
|
111
|
+
"eslint-config-typed": "4.6.2",
|
|
112
|
+
"github-settings-as-code": "1.1.2",
|
|
109
113
|
"immer": "11.1.3",
|
|
110
114
|
"jiti": "2.6.1",
|
|
111
115
|
"markdownlint": "0.40.0",
|
|
112
116
|
"markdownlint-cli2": "0.20.0",
|
|
113
117
|
"npm-run-all2": "8.0.4",
|
|
114
|
-
"playwright": "1.58.
|
|
118
|
+
"playwright": "1.58.1",
|
|
115
119
|
"prettier": "3.8.1",
|
|
116
120
|
"prettier-plugin-organize-imports": "4.3.0",
|
|
117
121
|
"prettier-plugin-packagejson": "3.0.0",
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"
|
|
122
|
+
"react": "^19.2.4",
|
|
123
|
+
"rollup": "4.57.1",
|
|
124
|
+
"semantic-release": "25.0.3",
|
|
125
|
+
"ts-codemod-lib": "^2.0.3",
|
|
121
126
|
"ts-repo-utils": "8.1.0",
|
|
122
127
|
"tslib": "2.8.1",
|
|
123
128
|
"tsx": "4.21.0",
|
|
@@ -125,7 +130,7 @@
|
|
|
125
130
|
"typedoc-github-theme": "0.3.1",
|
|
126
131
|
"typescript": "5.9.3",
|
|
127
132
|
"vite": "7.3.1",
|
|
128
|
-
"vitest": "4.0.
|
|
133
|
+
"vitest": "4.0.18"
|
|
129
134
|
},
|
|
130
135
|
"peerDependencies": {
|
|
131
136
|
"typescript": ">=4.8"
|
|
@@ -137,14 +137,15 @@ describe('Arr creations', () => {
|
|
|
137
137
|
});
|
|
138
138
|
|
|
139
139
|
test('fixed length with object (shallow copy)', () => {
|
|
140
|
-
const obj = { id: 1 };
|
|
140
|
+
const obj = { id: 1 } as const;
|
|
141
141
|
|
|
142
142
|
const result = create(2, obj);
|
|
143
143
|
|
|
144
144
|
// transformer-ignore-next-line
|
|
145
|
-
expectType<
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
expectType<
|
|
146
|
+
typeof result,
|
|
147
|
+
readonly [Readonly<{ id: 1 }>, Readonly<{ id: 1 }>]
|
|
148
|
+
>('~=');
|
|
148
149
|
|
|
149
150
|
assert.deepStrictEqual(result, [obj, obj]);
|
|
150
151
|
|
|
@@ -182,7 +183,7 @@ describe('Arr creations', () => {
|
|
|
182
183
|
});
|
|
183
184
|
|
|
184
185
|
test('should create array with object values', () => {
|
|
185
|
-
const obj = { a: 1 };
|
|
186
|
+
const obj = { a: 1 } as const;
|
|
186
187
|
|
|
187
188
|
const result = create(2, obj);
|
|
188
189
|
|
|
@@ -222,16 +223,19 @@ describe('Arr creations', () => {
|
|
|
222
223
|
});
|
|
223
224
|
|
|
224
225
|
test('should create a shallow copy of an array of objects', () => {
|
|
225
|
-
const obj1 = { id: 1 };
|
|
226
|
+
const obj1 = { id: 1 } as const;
|
|
226
227
|
|
|
227
|
-
const obj2 = { id: 2 };
|
|
228
|
+
const obj2 = { id: 2 } as const;
|
|
228
229
|
|
|
229
230
|
const original = [obj1, obj2] as const;
|
|
230
231
|
|
|
231
232
|
const copied = copy(original);
|
|
232
233
|
|
|
233
234
|
// transformer-ignore-next-line
|
|
234
|
-
expectType<
|
|
235
|
+
expectType<
|
|
236
|
+
typeof copied,
|
|
237
|
+
readonly [Readonly<{ id: 1 }>, Readonly<{ id: 2 }>]
|
|
238
|
+
>('=');
|
|
235
239
|
|
|
236
240
|
assert.deepStrictEqual(copied, original);
|
|
237
241
|
|
|
@@ -766,8 +770,7 @@ describe('Arr creations', () => {
|
|
|
766
770
|
|
|
767
771
|
test('should handle async generator with delays', async () => {
|
|
768
772
|
const result = await generateAsync<number>(async function* () {
|
|
769
|
-
|
|
770
|
-
for (let i = 0; i < 3; i++) {
|
|
773
|
+
for (const i of range(0, 3)) {
|
|
771
774
|
// eslint-disable-next-line no-await-in-loop
|
|
772
775
|
await new Promise<void>((resolve) => {
|
|
773
776
|
setTimeout(resolve, 0);
|
|
@@ -6,7 +6,7 @@ import { Optional, pipe } from '../../functional/index.mjs';
|
|
|
6
6
|
* @example
|
|
7
7
|
*
|
|
8
8
|
* ```ts
|
|
9
|
-
* const letters: readonly string[] = ['a', 'b', 'c'];
|
|
9
|
+
* const letters: readonly string[] = ['a', 'b', 'c'] as const;
|
|
10
10
|
*
|
|
11
11
|
* const two = Arr.at(letters, 1);
|
|
12
12
|
*
|
|
@@ -64,9 +64,9 @@ export function at<E>(
|
|
|
64
64
|
* @example
|
|
65
65
|
*
|
|
66
66
|
* ```ts
|
|
67
|
-
* const users = [{ id: 1 }, { id: 2 }];
|
|
67
|
+
* const users = [{ id: 1 }, { id: 2 }] as const;
|
|
68
68
|
*
|
|
69
|
-
* const empty: readonly Readonly<{ id: number }>[] = [];
|
|
69
|
+
* const empty: readonly Readonly<{ id: number }>[] = [] as const;
|
|
70
70
|
*
|
|
71
71
|
* const first = Arr.head(users);
|
|
72
72
|
*
|
|
@@ -95,9 +95,9 @@ export const head = <const Ar extends readonly unknown[]>(
|
|
|
95
95
|
* @example
|
|
96
96
|
*
|
|
97
97
|
* ```ts
|
|
98
|
-
* const queue = ['first', 'second'];
|
|
98
|
+
* const queue = ['first', 'second'] as const;
|
|
99
99
|
*
|
|
100
|
-
* const emptyQueue: readonly string[] = [];
|
|
100
|
+
* const emptyQueue: readonly string[] = [] as const;
|
|
101
101
|
*
|
|
102
102
|
* const lastValue = Arr.last(queue);
|
|
103
103
|
*
|
|
@@ -6,7 +6,7 @@ import { at, head, last } from './array-utils-element-access.mjs';
|
|
|
6
6
|
describe('Arr element access', () => {
|
|
7
7
|
describe(at, () => {
|
|
8
8
|
test('should handle very large positive indices', () => {
|
|
9
|
-
const array = [1, 2, 3];
|
|
9
|
+
const array = [1, 2, 3] as readonly number[];
|
|
10
10
|
|
|
11
11
|
const result = at(array, asUint32(1000));
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ describe('Arr element access', () => {
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
test('should handle very large negative indices', () => {
|
|
17
|
-
const array = [1, 2, 3];
|
|
17
|
+
const array = [1, 2, 3] as readonly number[];
|
|
18
18
|
|
|
19
19
|
const result = at(array, asInt32(-1000));
|
|
20
20
|
|
|
@@ -22,7 +22,7 @@ describe('Arr element access', () => {
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
test('should work with valid indices', () => {
|
|
25
|
-
const array = [10, 20, 30];
|
|
25
|
+
const array = [10, 20, 30] as const;
|
|
26
26
|
|
|
27
27
|
const result = at(array, 1);
|
|
28
28
|
|
|
@@ -62,7 +62,7 @@ describe('Arr element access', () => {
|
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
test('case 2', () => {
|
|
65
|
-
const xs: MutableNonEmptyArray<number> = [1, 2, 3];
|
|
65
|
+
const xs: MutableNonEmptyArray<number> = [1, 2, 3] as const;
|
|
66
66
|
|
|
67
67
|
const h = head(xs);
|
|
68
68
|
|
|
@@ -132,7 +132,7 @@ describe('Arr element access', () => {
|
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
test('case 2', () => {
|
|
135
|
-
const xs: MutableNonEmptyArray<number> = [1, 2, 3];
|
|
135
|
+
const xs: MutableNonEmptyArray<number> = [1, 2, 3] as const;
|
|
136
136
|
|
|
137
137
|
const l = last(xs);
|
|
138
138
|
|
|
@@ -4,7 +4,7 @@ import { entries, indices, values } from './array-utils-iterators.mjs';
|
|
|
4
4
|
|
|
5
5
|
describe(entries, () => {
|
|
6
6
|
test('should return array of index-value pairs', () => {
|
|
7
|
-
const fruits = ['apple', 'banana', 'cherry'];
|
|
7
|
+
const fruits = ['apple', 'banana', 'cherry'] as const;
|
|
8
8
|
|
|
9
9
|
const es = Array.from(entries(fruits));
|
|
10
10
|
|
|
@@ -31,7 +31,7 @@ describe(entries, () => {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
test('should work with empty array', () => {
|
|
34
|
-
const empty: readonly string[] = [];
|
|
34
|
+
const empty: readonly string[] = [] as const;
|
|
35
35
|
|
|
36
36
|
const es = Array.from(entries(empty));
|
|
37
37
|
|
|
@@ -56,7 +56,7 @@ describe(entries, () => {
|
|
|
56
56
|
|
|
57
57
|
describe(values, () => {
|
|
58
58
|
test('should return copy of array values', () => {
|
|
59
|
-
const numbers = [1, 2, 3];
|
|
59
|
+
const numbers = [1, 2, 3] as const;
|
|
60
60
|
|
|
61
61
|
const vs = Array.from(values(numbers));
|
|
62
62
|
|
|
@@ -77,7 +77,7 @@ describe(values, () => {
|
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
test('should work with empty array', () => {
|
|
80
|
-
const empty: readonly number[] = [];
|
|
80
|
+
const empty: readonly number[] = [] as const;
|
|
81
81
|
|
|
82
82
|
const vs = Array.from(values(empty));
|
|
83
83
|
|
|
@@ -98,7 +98,7 @@ describe(values, () => {
|
|
|
98
98
|
|
|
99
99
|
describe(indices, () => {
|
|
100
100
|
test('should return array of indices', () => {
|
|
101
|
-
const fruits = ['apple', 'banana', 'cherry'];
|
|
101
|
+
const fruits = ['apple', 'banana', 'cherry'] as const;
|
|
102
102
|
|
|
103
103
|
const ks = Array.from(indices(fruits));
|
|
104
104
|
|
|
@@ -117,7 +117,7 @@ describe(indices, () => {
|
|
|
117
117
|
});
|
|
118
118
|
|
|
119
119
|
test('should work with empty array', () => {
|
|
120
|
-
const empty: readonly string[] = [];
|
|
120
|
+
const empty: readonly string[] = [] as const;
|
|
121
121
|
|
|
122
122
|
const ks = Array.from(indices(empty));
|
|
123
123
|
|
|
@@ -8,7 +8,7 @@ import { copy, create } from './array-utils-creation.mjs';
|
|
|
8
8
|
* @example
|
|
9
9
|
*
|
|
10
10
|
* ```ts
|
|
11
|
-
* const scores: readonly number[] = [10, 20, 30];
|
|
11
|
+
* const scores: readonly number[] = [10, 20, 30] as const;
|
|
12
12
|
*
|
|
13
13
|
* const updated = Arr.set(scores, 1, 25);
|
|
14
14
|
*
|
|
@@ -63,7 +63,7 @@ export function set<E, const V = E>(
|
|
|
63
63
|
* @example
|
|
64
64
|
*
|
|
65
65
|
* ```ts
|
|
66
|
-
* const temperatures: readonly number[] = [20, 21, 22];
|
|
66
|
+
* const temperatures: readonly number[] = [20, 21, 22] as const;
|
|
67
67
|
*
|
|
68
68
|
* const increased = Arr.toUpdated(temperatures, 1, (value) => value + 5);
|
|
69
69
|
*
|
|
@@ -341,7 +341,7 @@ export function toUnshifted<Ar extends readonly unknown[], const V>(
|
|
|
341
341
|
* @example
|
|
342
342
|
*
|
|
343
343
|
* ```ts
|
|
344
|
-
* const base = [1, 2, 3];
|
|
344
|
+
* const base = [1, 2, 3] as const;
|
|
345
345
|
*
|
|
346
346
|
* const filled = Arr.toFilled(base, 0);
|
|
347
347
|
*
|
|
@@ -396,7 +396,7 @@ export function toFilled<E>(
|
|
|
396
396
|
* @example
|
|
397
397
|
*
|
|
398
398
|
* ```ts
|
|
399
|
-
* const base = [0, 1, 2, 3, 4];
|
|
399
|
+
* const base = [0, 1, 2, 3, 4] as const;
|
|
400
400
|
*
|
|
401
401
|
* const filledMiddle = Arr.toRangeFilled(base, 9, [1, 4]);
|
|
402
402
|
*
|
|
@@ -104,7 +104,7 @@ describe('Arr modifications', () => {
|
|
|
104
104
|
});
|
|
105
105
|
|
|
106
106
|
test('case 4 (number[])', () => {
|
|
107
|
-
const xs: readonly number[] = [1, 2, 3];
|
|
107
|
+
const xs: readonly number[] = [1, 2, 3] as const;
|
|
108
108
|
|
|
109
109
|
const result = toRemoved(xs, 5);
|
|
110
110
|
|
|
@@ -134,7 +134,7 @@ describe('Arr modifications', () => {
|
|
|
134
134
|
});
|
|
135
135
|
|
|
136
136
|
test('case 2', () => {
|
|
137
|
-
const xs: readonly number[] = [1, 2, 3];
|
|
137
|
+
const xs: readonly number[] = [1, 2, 3] as const;
|
|
138
138
|
|
|
139
139
|
const result = toPushed(xs, 4 as const);
|
|
140
140
|
|
|
@@ -164,7 +164,7 @@ describe('Arr modifications', () => {
|
|
|
164
164
|
});
|
|
165
165
|
|
|
166
166
|
test('case 2', () => {
|
|
167
|
-
const xs: readonly number[] = [1, 2, 3];
|
|
167
|
+
const xs: readonly number[] = [1, 2, 3] as const;
|
|
168
168
|
|
|
169
169
|
const result = toUnshifted(xs, 4 as const);
|
|
170
170
|
|
|
@@ -184,7 +184,7 @@ describe('Arr modifications', () => {
|
|
|
184
184
|
|
|
185
185
|
describe(toFilled, () => {
|
|
186
186
|
test('should fill entire array with value', () => {
|
|
187
|
-
const arr = [1, 2, 3, 4, 5];
|
|
187
|
+
const arr = [1, 2, 3, 4, 5] as const;
|
|
188
188
|
|
|
189
189
|
const result = toFilled(arr, 0);
|
|
190
190
|
|
|
@@ -194,7 +194,7 @@ describe('Arr modifications', () => {
|
|
|
194
194
|
test('should work with curried version', () => {
|
|
195
195
|
const fillWithZero = toFilled(0);
|
|
196
196
|
|
|
197
|
-
const arr = [1, 2, 3];
|
|
197
|
+
const arr = [1, 2, 3] as const;
|
|
198
198
|
|
|
199
199
|
const result = fillWithZero(arr);
|
|
200
200
|
|
|
@@ -204,7 +204,7 @@ describe('Arr modifications', () => {
|
|
|
204
204
|
|
|
205
205
|
describe(toRangeFilled, () => {
|
|
206
206
|
test('should fill array with range', () => {
|
|
207
|
-
const arr = [1, 2, 3, 4, 5];
|
|
207
|
+
const arr = [1, 2, 3, 4, 5] as const;
|
|
208
208
|
|
|
209
209
|
const result = toRangeFilled(arr, 0, [1, 4]);
|
|
210
210
|
|
|
@@ -212,7 +212,7 @@ describe('Arr modifications', () => {
|
|
|
212
212
|
});
|
|
213
213
|
|
|
214
214
|
test('should fill with range starting from 0', () => {
|
|
215
|
-
const arr = [1, 2, 3, 4, 5];
|
|
215
|
+
const arr = [1, 2, 3, 4, 5] as const;
|
|
216
216
|
|
|
217
217
|
const result = toRangeFilled(arr, 9, [0, 3]);
|
|
218
218
|
|
|
@@ -220,7 +220,7 @@ describe('Arr modifications', () => {
|
|
|
220
220
|
});
|
|
221
221
|
|
|
222
222
|
test('should handle empty range', () => {
|
|
223
|
-
const arr = [1, 2, 3];
|
|
223
|
+
const arr = [1, 2, 3] as const;
|
|
224
224
|
|
|
225
225
|
const result = toRangeFilled(arr, 0, [2, 2]);
|
|
226
226
|
|
|
@@ -228,7 +228,7 @@ describe('Arr modifications', () => {
|
|
|
228
228
|
});
|
|
229
229
|
|
|
230
230
|
test('should clamp range to array bounds', () => {
|
|
231
|
-
const arr = [1, 2, 3];
|
|
231
|
+
const arr = [1, 2, 3] as readonly number[];
|
|
232
232
|
|
|
233
233
|
const result = toRangeFilled(arr, 0, [1, 10]);
|
|
234
234
|
|
|
@@ -236,7 +236,7 @@ describe('Arr modifications', () => {
|
|
|
236
236
|
});
|
|
237
237
|
|
|
238
238
|
test('should handle negative start (clamped to 0)', () => {
|
|
239
|
-
const arr = [1, 2, 3];
|
|
239
|
+
const arr = [1, 2, 3] as readonly number[];
|
|
240
240
|
|
|
241
241
|
const result = toRangeFilled(arr, 9, [-5, 2]);
|
|
242
242
|
|
|
@@ -252,14 +252,14 @@ describe('Arr modifications', () => {
|
|
|
252
252
|
});
|
|
253
253
|
|
|
254
254
|
test('A non-integer starting value should result in a type error', () => {
|
|
255
|
-
const arr = [1, 2, 3];
|
|
255
|
+
const arr = [1, 2, 3] as const;
|
|
256
256
|
|
|
257
257
|
// @ts-expect-error start must be an integer
|
|
258
258
|
assert.deepStrictEqual(toRangeFilled(arr, 0, [1.5, 3]), [1, 0, 0]);
|
|
259
259
|
});
|
|
260
260
|
|
|
261
261
|
test('A non-integer ending value should result in a type error', () => {
|
|
262
|
-
const arr = [1, 2, 3];
|
|
262
|
+
const arr = [1, 2, 3] as const;
|
|
263
263
|
|
|
264
264
|
// @ts-expect-error end must be an integer
|
|
265
265
|
assert.deepStrictEqual(toRangeFilled(arr, 0, [1, 2.5]), [1, 0, 3]);
|
|
@@ -148,7 +148,7 @@ describe('Array overloaded functions - type error validation', () => {
|
|
|
148
148
|
const invalidArgs: readonly [readonly string[], (x: string) => number] = [
|
|
149
149
|
['a'],
|
|
150
150
|
(x) => x.length,
|
|
151
|
-
];
|
|
151
|
+
] as const;
|
|
152
152
|
|
|
153
153
|
// @ts-expect-error - Wrong types in tuple for spread
|
|
154
154
|
findIndex(...invalidArgs);
|
|
@@ -14,7 +14,7 @@ import { isNonEmpty } from './array-utils-validation.mjs';
|
|
|
14
14
|
* ```ts
|
|
15
15
|
* const values = [5, 3, 9] as const;
|
|
16
16
|
*
|
|
17
|
-
* const empty: readonly number[] = [];
|
|
17
|
+
* const empty: readonly number[] = [] as const;
|
|
18
18
|
*
|
|
19
19
|
* const smallest = Arr.min(values);
|
|
20
20
|
*
|
|
@@ -64,7 +64,7 @@ export function min<E extends number>(
|
|
|
64
64
|
* @example
|
|
65
65
|
*
|
|
66
66
|
* ```ts
|
|
67
|
-
* const values = [5, 3, 9];
|
|
67
|
+
* const values = [5, 3, 9] as const;
|
|
68
68
|
*
|
|
69
69
|
* const largest = Arr.max(values);
|
|
70
70
|
*
|
|
@@ -155,7 +155,7 @@ export function minBy<E, V>(
|
|
|
155
155
|
* { id: 'a', stars: 10 },
|
|
156
156
|
* { id: 'b', stars: 30 },
|
|
157
157
|
* { id: 'c', stars: 20 },
|
|
158
|
-
* ];
|
|
158
|
+
* ] as const;
|
|
159
159
|
*
|
|
160
160
|
* const mostStars = Arr.maxBy(projects, (project) => project.stars);
|
|
161
161
|
*
|
|
@@ -318,7 +318,7 @@ export function countBy<E, G extends MapSetKeyType>(
|
|
|
318
318
|
* @example
|
|
319
319
|
*
|
|
320
320
|
* ```ts
|
|
321
|
-
* const words = ['Ada', 'Lovelace'];
|
|
321
|
+
* const words = ['Ada', 'Lovelace'] as const;
|
|
322
322
|
*
|
|
323
323
|
* const totalLength = Arr.foldl(words, (acc, word) => acc + word.length, 0);
|
|
324
324
|
*
|
|
@@ -395,7 +395,7 @@ export function foldl<E, P>(
|
|
|
395
395
|
* @example
|
|
396
396
|
*
|
|
397
397
|
* ```ts
|
|
398
|
-
* const numbers = [1, 2, 3];
|
|
398
|
+
* const numbers = [1, 2, 3] as const;
|
|
399
399
|
*
|
|
400
400
|
* const subtractRight = Arr.foldr(numbers, (acc, value) => acc - value, 0);
|
|
401
401
|
*
|
|
@@ -496,6 +496,7 @@ export function sum(array: readonly Int[]): Int;
|
|
|
496
496
|
export function sum(array: readonly number[]): number;
|
|
497
497
|
|
|
498
498
|
export function sum(array: readonly number[]): number {
|
|
499
|
+
// eslint-disable-next-line ts-data-forge/prefer-arr-sum
|
|
499
500
|
return array.reduce((prev, curr) => prev + curr, 0);
|
|
500
501
|
}
|
|
501
502
|
|