ts-data-forge 9.0.0 → 10.0.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 +1 -1
- package/dist/array/impl/array-utils-creation.d.mts +4 -4
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-creation.mjs +17 -112
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
- package/dist/array/impl/array-utils-element-access.mjs +22 -61
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-iterators.d.mts.map +1 -1
- package/dist/array/impl/array-utils-iterators.mjs +9 -63
- package/dist/array/impl/array-utils-iterators.mjs.map +1 -1
- package/dist/array/impl/array-utils-modification.d.mts +7 -7
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs +78 -78
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +95 -89
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.mjs +100 -92
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +31 -141
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts.map +1 -1
- package/dist/array/impl/array-utils-size.mjs +4 -8
- package/dist/array/impl/array-utils-size.mjs.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.mjs +11 -12
- package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs +44 -96
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +4 -4
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +150 -292
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +17 -17
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +23 -174
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/array/impl/index.mjs +1 -1
- package/dist/collections/imap-mapped.d.mts.map +1 -1
- package/dist/collections/imap-mapped.mjs +243 -330
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +190 -275
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +1 -1
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +222 -444
- 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 +158 -324
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.d.mts.map +1 -1
- package/dist/collections/queue.mjs +106 -178
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.d.mts.map +1 -1
- package/dist/collections/stack.mjs +95 -165
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/entry-point.mjs +2 -0
- package/dist/entry-point.mjs.map +1 -1
- package/dist/expect-type.d.mts +1 -1
- package/dist/expect-type.d.mts.map +1 -1
- package/dist/expect-type.mjs +1 -69
- package/dist/expect-type.mjs.map +1 -1
- package/dist/functional/match.mjs +9 -9
- package/dist/functional/match.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.mjs +13 -14
- package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-filter.mjs +14 -15
- package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-flat-map.mjs +10 -11
- package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-from-nullable.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-from-nullable.mjs +1 -25
- package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-none.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +0 -19
- package/dist/functional/optional/impl/optional-is-none.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +1 -23
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +0 -20
- package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-map.mjs +13 -14
- package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-none.mjs +0 -16
- package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-or-else.mjs +10 -11
- package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-some.mjs +2 -21
- package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.mjs +1 -27
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-or.mjs +9 -10
- package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +4 -32
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap.mjs +4 -4
- package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-zip.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +1 -35
- package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
- package/dist/functional/optional/impl/tag.mjs +2 -3
- package/dist/functional/optional/impl/tag.mjs.map +1 -1
- package/dist/functional/pipe.d.mts.map +1 -1
- package/dist/functional/pipe.mjs +9 -34
- package/dist/functional/pipe.mjs.map +1 -1
- package/dist/functional/result/impl/result-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-err.mjs +2 -27
- package/dist/functional/result/impl/result-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-expect-to-be.mjs +13 -15
- package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
- package/dist/functional/result/impl/result-flat-map.mjs +16 -16
- package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-fold.mjs +16 -16
- package/dist/functional/result/impl/result-fold.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-promise.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs +4 -31
- package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +8 -38
- package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-err.mjs +0 -19
- package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-ok.mjs +0 -19
- package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-result.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-result.mjs +1 -23
- package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
- package/dist/functional/result/impl/result-map-err.mjs +16 -16
- package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-map.mjs +16 -16
- package/dist/functional/result/impl/result-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-ok.mjs +2 -27
- package/dist/functional/result/impl/result-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-or-else.mjs +10 -12
- package/dist/functional/result/impl/result-or-else.mjs.map +1 -1
- package/dist/functional/result/impl/result-swap.d.mts.map +1 -1
- package/dist/functional/result/impl/result-swap.mjs +4 -22
- package/dist/functional/result/impl/result-swap.mjs.map +1 -1
- package/dist/functional/result/impl/result-to-optional.d.mts.map +1 -1
- package/dist/functional/result/impl/result-to-optional.mjs +0 -27
- package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.mjs +9 -11
- package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +13 -40
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.mjs +4 -32
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs +9 -11
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok.mjs +4 -4
- package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +4 -35
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-zip.d.mts.map +1 -1
- package/dist/functional/result/impl/result-zip.mjs +1 -34
- package/dist/functional/result/impl/result-zip.mjs.map +1 -1
- package/dist/functional/result/impl/tag.mjs +2 -3
- package/dist/functional/result/impl/tag.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/tag.mjs +3 -5
- package/dist/functional/ternary-result/impl/tag.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 +2 -15
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +13 -13
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +27 -26
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +21 -22
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +4 -20
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +7 -25
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +0 -17
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +0 -19
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +1 -25
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +0 -18
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +13 -15
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +18 -18
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs +21 -22
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +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 +2 -16
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +9 -9
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +4 -22
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +9 -9
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +12 -27
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +4 -19
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +9 -9
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +4 -5
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +15 -27
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +9 -9
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +10 -24
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +4 -19
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.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 +3 -19
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +14 -45
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/variant-name.d.mts +1 -1
- package/dist/functional/ternary-result/impl/variant-name.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/variant-name.mjs +8 -9
- package/dist/functional/ternary-result/impl/variant-name.mjs.map +1 -1
- package/dist/guard/as-length-bounded-array.d.mts +117 -0
- package/dist/guard/as-length-bounded-array.d.mts.map +1 -0
- package/dist/guard/as-length-bounded-array.mjs +37 -0
- package/dist/guard/as-length-bounded-array.mjs.map +1 -0
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +0 -41
- package/dist/guard/has-key.mjs.map +1 -1
- package/dist/guard/index.d.mts +2 -0
- package/dist/guard/index.d.mts.map +1 -1
- package/dist/guard/index.mjs +2 -0
- package/dist/guard/index.mjs.map +1 -1
- package/dist/guard/is-length-bounded-array.d.mts +159 -0
- package/dist/guard/is-length-bounded-array.d.mts.map +1 -0
- package/dist/guard/is-length-bounded-array.mjs +7 -0
- package/dist/guard/is-length-bounded-array.mjs.map +1 -0
- package/dist/guard/is-length-bounded-string.d.mts +5 -6
- package/dist/guard/is-length-bounded-string.d.mts.map +1 -1
- package/dist/guard/is-length-bounded-string.mjs +0 -157
- package/dist/guard/is-length-bounded-string.mjs.map +1 -1
- package/dist/guard/is-non-empty-string.d.mts +1 -1
- package/dist/guard/is-non-empty-string.d.mts.map +1 -1
- package/dist/guard/is-non-empty-string.mjs +1 -38
- package/dist/guard/is-non-empty-string.mjs.map +1 -1
- package/dist/guard/is-non-null-object.d.mts.map +1 -1
- package/dist/guard/is-non-null-object.mjs +1 -35
- package/dist/guard/is-non-null-object.mjs.map +1 -1
- package/dist/guard/is-primitive.d.mts.map +1 -1
- package/dist/guard/is-primitive.mjs +12 -43
- package/dist/guard/is-primitive.mjs.map +1 -1
- package/dist/guard/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +0 -86
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/is-type.d.mts.map +1 -1
- package/dist/guard/is-type.mjs +12 -399
- package/dist/guard/is-type.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +0 -40
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/iterator/range.mjs +16 -16
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +52 -340
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/finite-number.d.mts +3 -3
- package/dist/number/branded-types/finite-number.mjs +135 -154
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +4 -4
- package/dist/number/branded-types/int.mjs +205 -245
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.d.mts +15 -15
- package/dist/number/branded-types/int16.mjs +116 -123
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +11 -11
- package/dist/number/branded-types/int32.mjs +116 -123
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/negative-finite-number.d.mts +4 -4
- package/dist/number/branded-types/negative-finite-number.mjs +129 -144
- package/dist/number/branded-types/negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/negative-int.d.mts +5 -5
- package/dist/number/branded-types/negative-int.mjs +94 -113
- package/dist/number/branded-types/negative-int.mjs.map +1 -1
- package/dist/number/branded-types/negative-safe-int.d.mts +5 -5
- package/dist/number/branded-types/negative-safe-int.mjs +103 -124
- package/dist/number/branded-types/negative-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +5 -5
- package/dist/number/branded-types/non-negative-finite-number.mjs +136 -142
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +16 -16
- package/dist/number/branded-types/non-negative-int16.mjs +109 -118
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +12 -12
- package/dist/number/branded-types/non-negative-int32.mjs +110 -119
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-finite-number.d.mts +3 -3
- package/dist/number/branded-types/non-positive-finite-number.mjs +120 -124
- package/dist/number/branded-types/non-positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-int.d.mts +4 -4
- package/dist/number/branded-types/non-positive-int.mjs +167 -212
- package/dist/number/branded-types/non-positive-int.mjs.map +1 -1
- package/dist/number/branded-types/non-positive-safe-int.d.mts +4 -4
- package/dist/number/branded-types/non-positive-safe-int.mjs +95 -106
- package/dist/number/branded-types/non-positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +4 -4
- package/dist/number/branded-types/non-zero-finite-number.mjs +114 -123
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts +2 -2
- package/dist/number/branded-types/non-zero-int.mjs +72 -83
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +7 -7
- package/dist/number/branded-types/non-zero-int16.mjs +96 -107
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +5 -5
- package/dist/number/branded-types/non-zero-int32.mjs +97 -108
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +2 -2
- package/dist/number/branded-types/non-zero-safe-int.mjs +100 -111
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +8 -8
- package/dist/number/branded-types/non-zero-uint16.mjs +96 -107
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +6 -6
- package/dist/number/branded-types/non-zero-uint32.mjs +96 -107
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +8 -8
- package/dist/number/branded-types/positive-finite-number.mjs +139 -141
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +11 -11
- package/dist/number/branded-types/positive-int.mjs +228 -271
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +19 -19
- package/dist/number/branded-types/positive-int16.mjs +109 -118
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +15 -15
- package/dist/number/branded-types/positive-int32.mjs +109 -118
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +11 -11
- package/dist/number/branded-types/positive-safe-int.mjs +244 -275
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +17 -17
- package/dist/number/branded-types/positive-uint16.mjs +109 -118
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +13 -13
- package/dist/number/branded-types/positive-uint32.mjs +110 -119
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +4 -4
- package/dist/number/branded-types/safe-int.mjs +251 -292
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +8 -8
- package/dist/number/branded-types/safe-uint.mjs +111 -119
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +8 -8
- package/dist/number/branded-types/uint.mjs +198 -225
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +14 -14
- package/dist/number/branded-types/uint16.mjs +109 -119
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +10 -10
- package/dist/number/branded-types/uint32.mjs +110 -117
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.mjs +119 -145
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.mjs +107 -121
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/num.d.mts +2 -2
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +76 -537
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +1 -1
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +127 -263
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +107 -222
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/cast-mutable.d.mts.map +1 -1
- package/dist/others/cast-mutable.mjs +8 -37
- package/dist/others/cast-mutable.mjs.map +1 -1
- package/dist/others/cast-readonly.d.mts.map +1 -1
- package/dist/others/cast-readonly.mjs +8 -36
- package/dist/others/cast-readonly.mjs.map +1 -1
- package/dist/others/debounce-function.d.mts.map +1 -1
- package/dist/others/debounce-function.mjs +7 -16
- package/dist/others/debounce-function.mjs.map +1 -1
- package/dist/others/fast-deep-equal.d.mts.map +1 -1
- package/dist/others/fast-deep-equal.mjs +43 -59
- package/dist/others/fast-deep-equal.mjs.map +1 -1
- package/dist/others/if-then.d.mts.map +1 -1
- package/dist/others/if-then.mjs +0 -29
- package/dist/others/if-then.mjs.map +1 -1
- package/dist/others/map-nullable.mjs +9 -9
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/memoize-function.mjs +12 -12
- package/dist/others/memoize-function.mjs.map +1 -1
- package/dist/others/tuple.d.mts.map +1 -1
- package/dist/others/tuple.mjs +0 -50
- package/dist/others/tuple.mjs.map +1 -1
- package/dist/others/unknown-to-string.d.mts.map +1 -1
- package/dist/others/unknown-to-string.mjs +41 -88
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/promise/promise.d.mts.map +1 -1
- package/dist/promise/promise.mjs +4 -49
- package/dist/promise/promise.mjs.map +1 -1
- package/package.json +14 -13
- package/src/array/impl/array-utils-creation.mts +3 -3
- package/src/array/impl/array-utils-modification.mts +7 -7
- package/src/array/impl/array-utils-modification.test.mts +4 -4
- package/src/array/impl/array-utils-transformation.mts +4 -4
- package/src/array/impl/array-utils-transformation.test.mts +7 -7
- package/src/array/impl/array-utils-validation.mts +24 -24
- package/src/array/impl/array-utils-validation.test.mts +94 -92
- package/src/collections/queue.test.mts +1 -1
- package/src/guard/as-length-bounded-array.mts +190 -0
- package/src/guard/as-length-bounded-array.test.mts +118 -0
- package/src/guard/index.mts +2 -0
- package/src/guard/is-length-bounded-array.mts +195 -0
- package/src/guard/is-length-bounded-array.test.mts +169 -0
- package/src/guard/is-length-bounded-string.mts +6 -6
- package/src/object/object.test.mts +3 -3
|
@@ -42,352 +42,265 @@ import '../number/enum/uint8.mjs';
|
|
|
42
42
|
import '../number/num.mjs';
|
|
43
43
|
import '../number/refined-number-utils.mjs';
|
|
44
44
|
|
|
45
|
-
/** Provides utility functions for IMapMapped. */
|
|
46
45
|
var IMapMapped;
|
|
47
|
-
(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
* as keys by providing bidirectional transformation functions. The `toKey`
|
|
53
|
-
* function converts your custom key type to a primitive type that can be
|
|
54
|
-
* efficiently stored, while `fromKey` reconstructs the original key type for
|
|
55
|
-
* iteration and access.
|
|
56
|
-
*
|
|
57
|
-
* **Performance:** O(n) where n is the number of entries in the iterable.
|
|
58
|
-
*
|
|
59
|
-
* @template K The type of the custom keys.
|
|
60
|
-
* @template V The type of the values.
|
|
61
|
-
* @template KM The type of the mapped primitive keys.
|
|
62
|
-
* @example
|
|
63
|
-
*
|
|
64
|
-
* ```ts
|
|
65
|
-
* type Point = Readonly<{ x: number; y: number }>;
|
|
66
|
-
*
|
|
67
|
-
* const toKey = (p: Point) => JSON.stringify(p);
|
|
68
|
-
*
|
|
69
|
-
* // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
70
|
-
* const fromKey = (key: string) => JSON.parse(key) as Point;
|
|
71
|
-
*
|
|
72
|
-
* const map = IMapMapped.create<Point, string, string>(
|
|
73
|
-
* [
|
|
74
|
-
* [{ x: 0, y: 0 }, 'origin'],
|
|
75
|
-
* [{ x: 1, y: 0 }, 'right'],
|
|
76
|
-
* ],
|
|
77
|
-
* toKey,
|
|
78
|
-
* fromKey,
|
|
79
|
-
* );
|
|
80
|
-
*
|
|
81
|
-
* assert.isTrue(map.size === 2);
|
|
82
|
-
*
|
|
83
|
-
* assert.deepStrictEqual(map.get({ x: 0, y: 0 }), Optional.some('origin'));
|
|
84
|
-
* ```
|
|
85
|
-
*
|
|
86
|
-
* @param iterable An iterable of key-value pairs using the custom key type.
|
|
87
|
-
* @param toKey A function that converts a custom key `K` to a primitive key
|
|
88
|
-
* `KM`. This function must be deterministic and produce unique values for
|
|
89
|
-
* unique keys.
|
|
90
|
-
* @param fromKey A function that converts a primitive key `KM` back to the
|
|
91
|
-
* custom key `K`. This should be the inverse of `toKey`.
|
|
92
|
-
* @returns A new IMapMapped instance containing all entries from the
|
|
93
|
-
* iterable.
|
|
94
|
-
*/
|
|
95
|
-
IMapMapped.create = (iterable, toKey, fromKey) => new IMapMappedClass(iterable, toKey, fromKey);
|
|
96
|
-
/**
|
|
97
|
-
* Checks if two IMapMapped instances are structurally equal.
|
|
98
|
-
*
|
|
99
|
-
* Two IMapMapped instances are considered equal if they have the same size
|
|
100
|
-
* and contain exactly the same key-value pairs. The comparison is performed
|
|
101
|
-
* on the underlying mapped keys and values, so the transformation functions
|
|
102
|
-
* themselves don't need to be identical. Values are compared using
|
|
103
|
-
* JavaScript's `===` operator.
|
|
104
|
-
*
|
|
105
|
-
* **Performance:** O(n) where n is the size of the smaller map.
|
|
106
|
-
*
|
|
107
|
-
* @template K The type of the custom keys.
|
|
108
|
-
* @template V The type of the values.
|
|
109
|
-
* @template KM The type of the mapped primitive keys.
|
|
110
|
-
* @example
|
|
111
|
-
*
|
|
112
|
-
* ```ts
|
|
113
|
-
* type Point = Readonly<{ x: number; y: number }>;
|
|
114
|
-
*
|
|
115
|
-
* const toKey = (p: Point) => JSON.stringify(p);
|
|
116
|
-
*
|
|
117
|
-
* // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
118
|
-
* const fromKey = (key: string) => JSON.parse(key) as Point;
|
|
119
|
-
*
|
|
120
|
-
* const first = IMapMapped.create<Point, string, string>(
|
|
121
|
-
* [
|
|
122
|
-
* [{ x: 0, y: 0 }, 'origin'],
|
|
123
|
-
* [{ x: 1, y: 0 }, 'right'],
|
|
124
|
-
* ],
|
|
125
|
-
* toKey,
|
|
126
|
-
* fromKey,
|
|
127
|
-
* );
|
|
128
|
-
*
|
|
129
|
-
* const second = IMapMapped.create<Point, string, string>(
|
|
130
|
-
* [
|
|
131
|
-
* [{ x: 1, y: 0 }, 'right'],
|
|
132
|
-
* [{ x: 0, y: 0 }, 'origin'],
|
|
133
|
-
* ],
|
|
134
|
-
* toKey,
|
|
135
|
-
* fromKey,
|
|
136
|
-
* );
|
|
137
|
-
*
|
|
138
|
-
* const third = IMapMapped.create<Point, string, string>(
|
|
139
|
-
* [[{ x: 0, y: 0 }, 'different']],
|
|
140
|
-
* toKey,
|
|
141
|
-
* fromKey,
|
|
142
|
-
* );
|
|
143
|
-
*
|
|
144
|
-
* assert.isTrue(IMapMapped.equal(first, second));
|
|
145
|
-
*
|
|
146
|
-
* assert.isFalse(IMapMapped.equal(first, third));
|
|
147
|
-
* ```
|
|
148
|
-
*
|
|
149
|
-
* @param a The first IMapMapped instance to compare.
|
|
150
|
-
* @param b The second IMapMapped instance to compare.
|
|
151
|
-
* @returns `true` if the maps contain exactly the same key-value pairs,
|
|
152
|
-
* `false` otherwise.
|
|
153
|
-
*/
|
|
154
|
-
IMapMapped.equal = (a, b) => a.size === b.size &&
|
|
155
|
-
a.every((v, k) => pipe(b.get(k)).map((bv) => isSome(bv) && bv.value === v).value);
|
|
46
|
+
((IMapMapped2) => {
|
|
47
|
+
IMapMapped2.create = (iterable, toKey, fromKey) => new IMapMappedClass(iterable, toKey, fromKey);
|
|
48
|
+
IMapMapped2.equal = (a, b) => a.size === b.size && a.every(
|
|
49
|
+
(v, k) => pipe(b.get(k)).map((bv) => isSome(bv) && bv.value === v).value
|
|
50
|
+
);
|
|
156
51
|
})(IMapMapped || (IMapMapped = {}));
|
|
157
|
-
/**
|
|
158
|
-
* Internal class implementation for IMapMapped providing immutable map
|
|
159
|
-
* operations with key transformation.
|
|
160
|
-
*
|
|
161
|
-
* This class implements the IMapMapped interface by maintaining a JavaScript
|
|
162
|
-
* Map with primitive keys internally while exposing an API that works with
|
|
163
|
-
* custom key types. The transformation between custom and primitive keys is
|
|
164
|
-
* handled transparently through the provided `toKey` and `fromKey` functions.
|
|
165
|
-
*
|
|
166
|
-
* **Implementation Details:**
|
|
167
|
-
*
|
|
168
|
-
* - Uses ReadonlyMap<KM, V> internally where KM is the primitive key type
|
|
169
|
-
* - Stores transformation functions for bidirectional key conversion
|
|
170
|
-
* - Implements copy-on-write semantics for efficiency
|
|
171
|
-
* - Provides optional debug messaging for development
|
|
172
|
-
*
|
|
173
|
-
* @template K The type of the custom keys.
|
|
174
|
-
* @template V The type of the values.
|
|
175
|
-
* @template KM The type of the mapped primitive keys.
|
|
176
|
-
* @implements IMapMapped
|
|
177
|
-
* @implements Iterable
|
|
178
|
-
* @internal This class should not be used directly. Use IMapMapped.create() instead.
|
|
179
|
-
*/
|
|
180
52
|
class IMapMappedClass {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
53
|
+
#map;
|
|
54
|
+
#toKey;
|
|
55
|
+
#fromKey;
|
|
56
|
+
#showNotFoundMessage;
|
|
57
|
+
/**
|
|
58
|
+
* Constructs an IMapMappedClass instance with custom key transformation.
|
|
59
|
+
*
|
|
60
|
+
* @param iterable An iterable of key-value pairs using the custom key type K.
|
|
61
|
+
* @param toKey A function that converts a custom key K to a primitive key KM.
|
|
62
|
+
* Must be deterministic and produce unique values for unique keys.
|
|
63
|
+
* @param fromKey A function that converts a primitive key KM back to the
|
|
64
|
+
* custom key K. Should be the inverse of the toKey function.
|
|
65
|
+
* @param showNotFoundMessage Whether to log warning messages when operations
|
|
66
|
+
* are performed on non-existent keys. Useful for debugging. Defaults to
|
|
67
|
+
* false for production use.
|
|
68
|
+
* @internal Use IMapMapped.create() instead of calling this constructor directly.
|
|
69
|
+
*/
|
|
70
|
+
constructor(iterable, toKey, fromKey, showNotFoundMessage = false) {
|
|
71
|
+
this.#map = new Map(Array.from(iterable, ([k, v]) => [toKey(k), v]));
|
|
72
|
+
this.#toKey = toKey;
|
|
73
|
+
this.#fromKey = fromKey;
|
|
74
|
+
this.#showNotFoundMessage = showNotFoundMessage;
|
|
75
|
+
}
|
|
76
|
+
/** @inheritdoc */
|
|
77
|
+
get size() {
|
|
78
|
+
return asUint32(this.#map.size);
|
|
79
|
+
}
|
|
80
|
+
/** @inheritdoc */
|
|
81
|
+
has(key) {
|
|
82
|
+
return this.#map.has(this.#toKey(key));
|
|
83
|
+
}
|
|
84
|
+
/** @inheritdoc */
|
|
85
|
+
get(key) {
|
|
86
|
+
if (!this.has(key)) return none;
|
|
87
|
+
return some(this.#map.get(this.#toKey(key)));
|
|
88
|
+
}
|
|
89
|
+
/** @inheritdoc */
|
|
90
|
+
every(predicate) {
|
|
91
|
+
for (const [k, v] of this.entries()) {
|
|
92
|
+
if (!predicate(v, k)) return false;
|
|
203
93
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
/** @inheritdoc */
|
|
97
|
+
some(predicate) {
|
|
98
|
+
for (const [k, v] of this.entries()) {
|
|
99
|
+
if (predicate(v, k)) return true;
|
|
207
100
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
/** @inheritdoc */
|
|
104
|
+
delete(key) {
|
|
105
|
+
if (!this.has(key)) {
|
|
106
|
+
if (this.#showNotFoundMessage) {
|
|
107
|
+
console.warn(
|
|
108
|
+
`IMapMapped.delete: key not found: ${String(this.#toKey(key))}`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return this;
|
|
212
112
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
113
|
+
const keyMapped = this.#toKey(key);
|
|
114
|
+
return IMapMapped.create(
|
|
115
|
+
Array.from(this.#map).filter(([km]) => !Object.is(km, keyMapped)).map(([km, v]) => tp(this.#fromKey(km), v)),
|
|
116
|
+
this.#toKey,
|
|
117
|
+
this.#fromKey
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
/** @inheritdoc */
|
|
121
|
+
set(key, value) {
|
|
122
|
+
const curr = this.get(key);
|
|
123
|
+
if (isSome(curr) && value === curr.value) return this;
|
|
124
|
+
const keyMapped = this.#toKey(key);
|
|
125
|
+
if (!this.has(key)) {
|
|
126
|
+
return IMapMapped.create(
|
|
127
|
+
[...this.#map, tp(keyMapped, value)].map(
|
|
128
|
+
([km, v]) => tp(this.#fromKey(km), v)
|
|
129
|
+
),
|
|
130
|
+
this.#toKey,
|
|
131
|
+
this.#fromKey
|
|
132
|
+
);
|
|
219
133
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
134
|
+
return IMapMapped.create(
|
|
135
|
+
Array.from(
|
|
136
|
+
this.#map,
|
|
137
|
+
([km, v]) => tp(this.#fromKey(km), Object.is(km, keyMapped) ? value : v)
|
|
138
|
+
),
|
|
139
|
+
this.#toKey,
|
|
140
|
+
this.#fromKey
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
/** @inheritdoc */
|
|
144
|
+
update(key, updater) {
|
|
145
|
+
const curr = this.get(key);
|
|
146
|
+
if (isNone(curr)) {
|
|
147
|
+
if (this.#showNotFoundMessage) {
|
|
148
|
+
console.warn(
|
|
149
|
+
`IMapMapped.update: key not found: ${String(this.#toKey(key))}`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return this;
|
|
235
153
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
154
|
+
const keyMapped = this.#toKey(key);
|
|
155
|
+
return IMapMapped.create(
|
|
156
|
+
Array.from(
|
|
157
|
+
this.#map,
|
|
158
|
+
([km, v]) => tp(
|
|
159
|
+
this.#fromKey(km),
|
|
160
|
+
Object.is(km, keyMapped) ? updater(curr.value) : v
|
|
161
|
+
)
|
|
162
|
+
),
|
|
163
|
+
this.#toKey,
|
|
164
|
+
this.#fromKey
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
/** @inheritdoc */
|
|
168
|
+
withMutations(actions) {
|
|
169
|
+
const mut_result = new Map(this.#map);
|
|
170
|
+
const updateFn = (action) => {
|
|
171
|
+
const key = this.#toKey(action.key);
|
|
172
|
+
switch (action.type) {
|
|
173
|
+
case "delete":
|
|
174
|
+
mut_result.delete(key);
|
|
175
|
+
break;
|
|
176
|
+
case "set":
|
|
177
|
+
mut_result.set(key, action.value);
|
|
178
|
+
break;
|
|
179
|
+
case "update": {
|
|
180
|
+
const curr = mut_result.get(key);
|
|
181
|
+
if (!mut_result.has(key) || curr === void 0) {
|
|
239
182
|
if (this.#showNotFoundMessage) {
|
|
240
|
-
|
|
183
|
+
console.warn(
|
|
184
|
+
`IMapMapped.withMutations::update: key not found: ${String(key)}`
|
|
185
|
+
);
|
|
241
186
|
}
|
|
242
|
-
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
mut_result.set(key, action.updater(curr));
|
|
190
|
+
break;
|
|
243
191
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
/** @inheritdoc */
|
|
250
|
-
set(key, value) {
|
|
251
|
-
const curr = this.get(key);
|
|
252
|
-
if (isSome(curr) && value === curr.value)
|
|
253
|
-
return this;
|
|
254
|
-
const keyMapped = this.#toKey(key);
|
|
255
|
-
if (!this.has(key)) {
|
|
256
|
-
return IMapMapped.create([...this.#map, tp(keyMapped, value)].map(([km, v]) => tp(this.#fromKey(km), v)), this.#toKey, this.#fromKey);
|
|
257
|
-
}
|
|
258
|
-
return IMapMapped.create(Array.from(this.#map, ([km, v]) => tp(this.#fromKey(km), Object.is(km, keyMapped) ? value : v)), this.#toKey, this.#fromKey);
|
|
259
|
-
}
|
|
260
|
-
/** @inheritdoc */
|
|
261
|
-
update(key, updater) {
|
|
262
|
-
const curr = this.get(key);
|
|
263
|
-
if (isNone(curr)) {
|
|
264
|
-
if (this.#showNotFoundMessage) {
|
|
265
|
-
console.warn(`IMapMapped.update: key not found: ${String(this.#toKey(key))}`);
|
|
266
|
-
}
|
|
267
|
-
return this;
|
|
268
|
-
}
|
|
269
|
-
const keyMapped = this.#toKey(key);
|
|
270
|
-
return IMapMapped.create(Array.from(this.#map, ([km, v]) => tp(this.#fromKey(km), Object.is(km, keyMapped) ? updater(curr.value) : v)), this.#toKey, this.#fromKey);
|
|
271
|
-
}
|
|
272
|
-
/** @inheritdoc */
|
|
273
|
-
withMutations(actions) {
|
|
274
|
-
const mut_result = new Map(this.#map);
|
|
275
|
-
const updateFn = (action) => {
|
|
276
|
-
const key = this.#toKey(action.key);
|
|
277
|
-
switch (action.type) {
|
|
278
|
-
case 'delete':
|
|
279
|
-
mut_result.delete(key);
|
|
280
|
-
break;
|
|
281
|
-
case 'set':
|
|
282
|
-
mut_result.set(key, action.value);
|
|
283
|
-
break;
|
|
284
|
-
case 'update': {
|
|
285
|
-
const curr = mut_result.get(key);
|
|
286
|
-
if (!mut_result.has(key) || curr === undefined) {
|
|
287
|
-
if (this.#showNotFoundMessage) {
|
|
288
|
-
console.warn(`IMapMapped.withMutations::update: key not found: ${String(key)}`);
|
|
289
|
-
}
|
|
290
|
-
break;
|
|
291
|
-
}
|
|
292
|
-
mut_result.set(key, action.updater(curr));
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
for (const action of actions) {
|
|
298
|
-
updateFn(action);
|
|
299
|
-
}
|
|
300
|
-
return IMapMapped.create(Array.from(mut_result, ([k, v]) => [this.#fromKey(k), v]), this.#toKey, this.#fromKey);
|
|
301
|
-
}
|
|
302
|
-
/** @inheritdoc */
|
|
303
|
-
map(mapFn) {
|
|
304
|
-
return IMapMapped.create(this.toArray().map(([k, v]) => tp(k, mapFn(v, k))), this.#toKey, this.#fromKey);
|
|
305
|
-
}
|
|
306
|
-
/** @inheritdoc */
|
|
307
|
-
mapKeys(mapFn) {
|
|
308
|
-
return IMapMapped.create(this.toArray().map(([k, v]) => tp(mapFn(k), v)), this.#toKey, this.#fromKey);
|
|
309
|
-
}
|
|
310
|
-
/** @inheritdoc */
|
|
311
|
-
mapEntries(mapFn) {
|
|
312
|
-
return IMapMapped.create(this.toArray().map(mapFn), this.#toKey, this.#fromKey);
|
|
313
|
-
}
|
|
314
|
-
/** @inheritdoc */
|
|
315
|
-
forEach(callbackfn) {
|
|
316
|
-
for (const [km, value] of this.#map) {
|
|
317
|
-
callbackfn(value, this.#fromKey(km));
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* @example
|
|
322
|
-
*
|
|
323
|
-
* ```ts
|
|
324
|
-
* type Point = Readonly<{ x: number; y: number }>;
|
|
325
|
-
*
|
|
326
|
-
* const toKey = (p: Point) => JSON.stringify(p);
|
|
327
|
-
*
|
|
328
|
-
* // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
329
|
-
* const fromKey = (key: string) => JSON.parse(key) as Point;
|
|
330
|
-
*
|
|
331
|
-
* const map = IMapMapped.create<Point, string, string>(
|
|
332
|
-
* [
|
|
333
|
-
* [{ x: 0, y: 0 }, 'origin'],
|
|
334
|
-
* [{ x: 1, y: 0 }, 'right'],
|
|
335
|
-
* ],
|
|
336
|
-
* toKey,
|
|
337
|
-
* fromKey,
|
|
338
|
-
* );
|
|
339
|
-
*
|
|
340
|
-
* const collected = Array.from(map);
|
|
341
|
-
*
|
|
342
|
-
* assert.deepStrictEqual(collected, [
|
|
343
|
-
* [{ x: 0, y: 0 }, 'origin'],
|
|
344
|
-
* [{ x: 1, y: 0 }, 'right'],
|
|
345
|
-
* ]);
|
|
346
|
-
* ```
|
|
347
|
-
*
|
|
348
|
-
* @inheritdoc
|
|
349
|
-
*/
|
|
350
|
-
*[Symbol.iterator]() {
|
|
351
|
-
for (const e of this.entries()) {
|
|
352
|
-
yield e;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
/** @inheritdoc */
|
|
356
|
-
*keys() {
|
|
357
|
-
for (const km of this.#map.keys()) {
|
|
358
|
-
yield this.#fromKey(km);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
/** @inheritdoc */
|
|
362
|
-
values() {
|
|
363
|
-
return this.#map.values();
|
|
364
|
-
}
|
|
365
|
-
/** @inheritdoc */
|
|
366
|
-
*entries() {
|
|
367
|
-
for (const [km, v] of this.#map) {
|
|
368
|
-
yield [this.#fromKey(km), v];
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
/** @inheritdoc */
|
|
372
|
-
toKeysArray() {
|
|
373
|
-
return Array.from(this.keys());
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
for (const action of actions) {
|
|
195
|
+
updateFn(action);
|
|
374
196
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
197
|
+
return IMapMapped.create(
|
|
198
|
+
Array.from(mut_result, ([k, v]) => [this.#fromKey(k), v]),
|
|
199
|
+
this.#toKey,
|
|
200
|
+
this.#fromKey
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
/** @inheritdoc */
|
|
204
|
+
map(mapFn) {
|
|
205
|
+
return IMapMapped.create(
|
|
206
|
+
this.toArray().map(([k, v]) => tp(k, mapFn(v, k))),
|
|
207
|
+
this.#toKey,
|
|
208
|
+
this.#fromKey
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
/** @inheritdoc */
|
|
212
|
+
mapKeys(mapFn) {
|
|
213
|
+
return IMapMapped.create(
|
|
214
|
+
this.toArray().map(([k, v]) => tp(mapFn(k), v)),
|
|
215
|
+
this.#toKey,
|
|
216
|
+
this.#fromKey
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
/** @inheritdoc */
|
|
220
|
+
mapEntries(mapFn) {
|
|
221
|
+
return IMapMapped.create(
|
|
222
|
+
this.toArray().map(mapFn),
|
|
223
|
+
this.#toKey,
|
|
224
|
+
this.#fromKey
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
/** @inheritdoc */
|
|
228
|
+
forEach(callbackfn) {
|
|
229
|
+
for (const [km, value] of this.#map) {
|
|
230
|
+
callbackfn(value, this.#fromKey(km));
|
|
378
231
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* @example
|
|
235
|
+
*
|
|
236
|
+
* ```ts
|
|
237
|
+
* type Point = Readonly<{ x: number; y: number }>;
|
|
238
|
+
*
|
|
239
|
+
* const toKey = (p: Point) => JSON.stringify(p);
|
|
240
|
+
*
|
|
241
|
+
* // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
242
|
+
* const fromKey = (key: string) => JSON.parse(key) as Point;
|
|
243
|
+
*
|
|
244
|
+
* const map = IMapMapped.create<Point, string, string>(
|
|
245
|
+
* [
|
|
246
|
+
* [{ x: 0, y: 0 }, 'origin'],
|
|
247
|
+
* [{ x: 1, y: 0 }, 'right'],
|
|
248
|
+
* ],
|
|
249
|
+
* toKey,
|
|
250
|
+
* fromKey,
|
|
251
|
+
* );
|
|
252
|
+
*
|
|
253
|
+
* const collected = Array.from(map);
|
|
254
|
+
*
|
|
255
|
+
* assert.deepStrictEqual(collected, [
|
|
256
|
+
* [{ x: 0, y: 0 }, 'origin'],
|
|
257
|
+
* [{ x: 1, y: 0 }, 'right'],
|
|
258
|
+
* ]);
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* @inheritdoc
|
|
262
|
+
*/
|
|
263
|
+
*[Symbol.iterator]() {
|
|
264
|
+
for (const e of this.entries()) {
|
|
265
|
+
yield e;
|
|
382
266
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
267
|
+
}
|
|
268
|
+
/** @inheritdoc */
|
|
269
|
+
*keys() {
|
|
270
|
+
for (const km of this.#map.keys()) {
|
|
271
|
+
yield this.#fromKey(km);
|
|
386
272
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
273
|
+
}
|
|
274
|
+
/** @inheritdoc */
|
|
275
|
+
values() {
|
|
276
|
+
return this.#map.values();
|
|
277
|
+
}
|
|
278
|
+
/** @inheritdoc */
|
|
279
|
+
*entries() {
|
|
280
|
+
for (const [km, v] of this.#map) {
|
|
281
|
+
yield [this.#fromKey(km), v];
|
|
390
282
|
}
|
|
283
|
+
}
|
|
284
|
+
/** @inheritdoc */
|
|
285
|
+
toKeysArray() {
|
|
286
|
+
return Array.from(this.keys());
|
|
287
|
+
}
|
|
288
|
+
/** @inheritdoc */
|
|
289
|
+
toValuesArray() {
|
|
290
|
+
return Array.from(this.values());
|
|
291
|
+
}
|
|
292
|
+
/** @inheritdoc */
|
|
293
|
+
toEntriesArray() {
|
|
294
|
+
return Array.from(this.entries());
|
|
295
|
+
}
|
|
296
|
+
/** @inheritdoc */
|
|
297
|
+
toArray() {
|
|
298
|
+
return Array.from(this.entries());
|
|
299
|
+
}
|
|
300
|
+
/** @inheritdoc */
|
|
301
|
+
toRawMap() {
|
|
302
|
+
return this.#map;
|
|
303
|
+
}
|
|
391
304
|
}
|
|
392
305
|
|
|
393
306
|
export { IMapMapped };
|