ts-data-forge 9.0.0 → 9.0.1
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/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.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 +1 -1
- 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.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +18 -169
- package/dist/array/impl/array-utils-validation.mjs.map +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/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/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/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/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 +8 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-creation.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-creation.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,IAAI,EACT,KAAK,GAAG,EACR,KAAK,aAAa,EAClB,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EAChC,KAAK,cAAc,EACnB,KAAK,OAAO,EACZ,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,KAAK,GAAG,EACR,KAAK,SAAS,EACf,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,QAAQ,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"array-utils-creation.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-creation.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK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SAAS,SAAS,EAC5D,KAAK,EAAE,CAAC,EACR,GAAG,EAAE,CAAC,EACN,IAAI,CAAC,EAAE,CAAC,GACP,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEnB,wBAAgB,KAAK,CACnB,KAAK,EAAE,oBAAoB,EAC3B,GAAG,EAAE,oBAAoB,EACzB,IAAI,CAAC,EAAE,2BAA2B,GACjC,SAAS,QAAQ,EAAE,CAAC;AAEvB,wBAAgB,KAAK,CACnB,KAAK,EAAE,mBAAmB,EAC1B,GAAG,EAAE,mBAAmB,EACxB,IAAI,CAAC,EAAE,0BAA0B,GAChC,SAAS,OAAO,EAAE,CAAC"}
|
|
@@ -1,121 +1,26 @@
|
|
|
1
1
|
import { range as range$1 } from '../../iterator/range.mjs';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* assert.deepStrictEqual(threeZeros, [0, 0, 0]);
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
const zeros = (len) =>
|
|
19
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
20
|
-
Array.from({ length: len }, () => 0);
|
|
21
|
-
/**
|
|
22
|
-
* Creates a sequence of consecutive integers from 0 to `len-1`.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* const emptySeq = Arr.seq(0);
|
|
28
|
-
*
|
|
29
|
-
* const firstFive = Arr.seq(5);
|
|
30
|
-
*
|
|
31
|
-
* assert.deepStrictEqual(emptySeq, []);
|
|
32
|
-
*
|
|
33
|
-
* assert.deepStrictEqual(firstFive, [0, 1, 2, 3, 4]);
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
const seq = (len) =>
|
|
37
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
38
|
-
Array.from({ length: len }, (_, i) => i);
|
|
39
|
-
/**
|
|
40
|
-
* Creates a new array of the specified length, filled with the initial value.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
*
|
|
44
|
-
* ```ts
|
|
45
|
-
* const threeOnes = Arr.create(3, 1);
|
|
46
|
-
*
|
|
47
|
-
* const emptyStrings = Arr.create(0, 'Ada');
|
|
48
|
-
*
|
|
49
|
-
* assert.deepStrictEqual(threeOnes, [1, 1, 1]);
|
|
50
|
-
*
|
|
51
|
-
* assert.deepStrictEqual(emptyStrings, []);
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
const create = (len, init) =>
|
|
55
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
56
|
-
Array.from({ length: Math.max(0, len) }, () => init);
|
|
57
|
-
/**
|
|
58
|
-
* Alias for `create`.
|
|
59
|
-
*
|
|
60
|
-
* @see {@link create}
|
|
61
|
-
*/
|
|
3
|
+
const zeros = (len) => (
|
|
4
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
5
|
+
Array.from({ length: len }, () => 0)
|
|
6
|
+
);
|
|
7
|
+
const seq = (len) => (
|
|
8
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
9
|
+
Array.from({ length: len }, (_, i) => i)
|
|
10
|
+
);
|
|
11
|
+
const create = (len, init) => (
|
|
12
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
13
|
+
Array.from({ length: Math.max(0, len) }, () => init)
|
|
14
|
+
);
|
|
62
15
|
const newArray = create;
|
|
63
|
-
/**
|
|
64
|
-
* Generates an array from a generator function.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
*
|
|
68
|
-
* ```ts
|
|
69
|
-
* const numbers = Arr.generate(function* () {
|
|
70
|
-
* yield 1;
|
|
71
|
-
*
|
|
72
|
-
* yield 2;
|
|
73
|
-
*
|
|
74
|
-
* yield 3;
|
|
75
|
-
* });
|
|
76
|
-
*
|
|
77
|
-
* assert.deepStrictEqual(numbers, [1, 2, 3]);
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
16
|
const generate = (generatorFn) => Array.from(generatorFn());
|
|
81
|
-
/**
|
|
82
|
-
* Generates an array from an async generator function.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
*
|
|
86
|
-
* ```ts
|
|
87
|
-
* const values = await Arr.generateAsync(async function* () {
|
|
88
|
-
* yield 'Ada';
|
|
89
|
-
*
|
|
90
|
-
* await Promise.resolve();
|
|
91
|
-
*
|
|
92
|
-
* yield 'Lovelace';
|
|
93
|
-
* });
|
|
94
|
-
*
|
|
95
|
-
* assert.deepStrictEqual(values, ['Ada', 'Lovelace']);
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
17
|
const generateAsync = (generatorFn) => Array.fromAsync(generatorFn());
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*
|
|
104
|
-
* ```ts
|
|
105
|
-
* const original = [{ id: 1 }, { id: 2 }] as const;
|
|
106
|
-
*
|
|
107
|
-
* const cloned = Arr.copy(original);
|
|
108
|
-
*
|
|
109
|
-
* assert.deepStrictEqual(cloned, original);
|
|
110
|
-
*
|
|
111
|
-
* assert.notStrictEqual(cloned, original);
|
|
112
|
-
* ```
|
|
113
|
-
*/
|
|
114
|
-
const copy = (array) =>
|
|
115
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
116
|
-
array.slice();
|
|
18
|
+
const copy = (array) => (
|
|
19
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
20
|
+
array.slice()
|
|
21
|
+
);
|
|
117
22
|
function range(start, end, step = 1) {
|
|
118
|
-
|
|
23
|
+
return Array.from(range$1(start, end, step));
|
|
119
24
|
}
|
|
120
25
|
|
|
121
26
|
export { copy, create, generate, generateAsync, newArray, range, seq, zeros };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-creation.mjs","sources":["../../../src/array/impl/array-utils-creation.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"array-utils-creation.mjs","sources":["../../../src/array/impl/array-utils-creation.mts"],"sourcesContent":["import {\n type ArrayOfLength,\n type BoolOr,\n type Index,\n type IsUnion,\n type List,\n type Min,\n type NonEmptyArray,\n type NonZeroSafeIntWithSmallInt,\n type PositiveSafeIntWithSmallInt,\n type RelaxedExclude,\n type SafeInt,\n type SafeIntWithSmallInt,\n type SafeUint,\n type SafeUintWithSmallInt,\n type Seq,\n type SmallUint,\n} from 'ts-type-forge';\nimport { expectType } from '../../expect-type.mjs';\nimport { range as rangeIterator } from '../../iterator/index.mjs';\nimport { type SizeType } from '../../types.mjs';\n\n/**\n * Creates an array of zeros with the specified length.\n *\n * @example\n *\n * ```ts\n * const emptyZeros = Arr.zeros(0);\n *\n * const threeZeros = Arr.zeros(3);\n *\n * assert.deepStrictEqual(emptyZeros, []);\n *\n * assert.deepStrictEqual(threeZeros, [0, 0, 0]);\n * ```\n */\nexport const zeros = <N extends SizeType.ArgArr>(\n len: N,\n): N extends SmallUint\n ? ArrayOfLength<N, 0>\n : N extends SizeType.ArgArrPositive\n ? NonEmptyArray<0>\n : readonly 0[] =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Array.from({ length: len }, () => 0) as never;\n\n/**\n * Creates a sequence of consecutive integers from 0 to `len-1`.\n *\n * @example\n *\n * ```ts\n * const emptySeq = Arr.seq(0);\n *\n * const firstFive = Arr.seq(5);\n *\n * assert.deepStrictEqual(emptySeq, []);\n *\n * assert.deepStrictEqual(firstFive, [0, 1, 2, 3, 4]);\n * ```\n */\nexport const seq = <N extends SizeType.ArgArr>(\n len: N,\n): N extends SmallUint\n ? Seq<N>\n : N extends SizeType.ArgArrPositive\n ? NonEmptyArray<SizeType.Arr>\n : readonly SizeType.Arr[] =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Array.from({ length: len }, (_, i) => i) as never;\n\n/**\n * Creates a new array of the specified length, filled with the initial value.\n *\n * @example\n *\n * ```ts\n * const threeOnes = Arr.create(3, 1);\n *\n * const emptyStrings = Arr.create(0, 'Ada');\n *\n * assert.deepStrictEqual(threeOnes, [1, 1, 1]);\n *\n * assert.deepStrictEqual(emptyStrings, []);\n * ```\n */\nexport const create = <N extends SizeType.ArgArr, const V>(\n len: N,\n init: V,\n): N extends SmallUint\n ? ArrayOfLength<N, V>\n : N extends SizeType.ArgArrPositive\n ? NonEmptyArray<V>\n : readonly V[] =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Array.from({ length: Math.max(0, len) }, () => init) as never;\n\n/**\n * Alias for `create`.\n *\n * @see {@link create}\n */\nexport const newArray = create;\n\n/**\n * Generates an array from a generator function.\n *\n * @example\n *\n * ```ts\n * const numbers = Arr.generate(function* () {\n * yield 1;\n *\n * yield 2;\n *\n * yield 3;\n * });\n *\n * assert.deepStrictEqual(numbers, [1, 2, 3]);\n * ```\n */\nexport const generate = <T,>(\n generatorFn: () => Generator<T, void, unknown>,\n): readonly T[] => Array.from(generatorFn());\n\n/**\n * Generates an array from an async generator function.\n *\n * @example\n *\n * ```ts\n * const values = await Arr.generateAsync(async function* () {\n * yield 'Ada';\n *\n * await Promise.resolve();\n *\n * yield 'Lovelace';\n * });\n *\n * assert.deepStrictEqual(values, ['Ada', 'Lovelace']);\n * ```\n */\nexport const generateAsync = <T,>(\n generatorFn: () => AsyncGenerator<T, void, unknown>,\n): Promise<readonly T[]> => Array.fromAsync(generatorFn());\n\n/**\n * Creates a shallow copy of an array.\n *\n * @example\n *\n * ```ts\n * const original = [{ id: 1 }, { id: 2 }] as const;\n *\n * const cloned = Arr.copy(original);\n *\n * assert.deepStrictEqual(cloned, original);\n *\n * assert.notStrictEqual(cloned, original);\n * ```\n */\nexport const copy = <const Ar extends readonly unknown[]>(array: Ar): Ar =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n array.slice() as unknown as Ar;\n\ntype LT = Readonly<{ [N in SmallUint]: Index<N> }>;\n\ntype RangeList<S extends SmallUint, E extends SmallUint> =\n BoolOr<IsUnion<S>, IsUnion<E>> extends true\n ? readonly RelaxedExclude<LT[E], LT[Min<S>]>[] // Avoid incorrect type calculation for unions with Seq\n : List.Skip<S, Seq<E>>;\n\nexpectType<RangeList<1, 5>, readonly [1, 2, 3, 4]>('=');\n\nexpectType<RangeList<1, 2>, readonly [1]>('=');\n\nexpectType<RangeList<1, 1>, readonly []>('=');\n\nexpectType<RangeList<1, 1 | 3>, readonly (1 | 2)[]>('=');\n\nexpectType<RangeList<1 | 3, 3 | 5>, readonly (1 | 2 | 3 | 4)[]>('=');\n\nexpectType<RangeList<1 | 2 | 3, 5 | 6 | 7>, readonly (1 | 2 | 3 | 4 | 5 | 6)[]>(\n '=',\n);\n\nexpectType<RangeList<5, 1>, readonly []>('=');\n\n/**\n * Creates an array of numbers within a specified range with optional step.\n *\n * @example\n *\n * ```ts\n * const ascending = Arr.range(asUint32(1), asUint32(5));\n *\n * const empty = Arr.range(asUint32(2), asUint32(2));\n *\n * assert.deepStrictEqual(ascending, [1, 2, 3, 4]);\n *\n * assert.deepStrictEqual(empty, []);\n * ```\n */\nexport function range<S extends SmallUint, E extends SmallUint>(\n start: S,\n end: E,\n step?: 1,\n): RangeList<S, E>;\n\nexport function range(\n start: SafeUintWithSmallInt,\n end: SafeUintWithSmallInt,\n step?: PositiveSafeIntWithSmallInt,\n): readonly SafeUint[];\n\nexport function range(\n start: SafeIntWithSmallInt,\n end: SafeIntWithSmallInt,\n step?: NonZeroSafeIntWithSmallInt,\n): readonly SafeInt[];\n\nexport function range(\n start: SafeIntWithSmallInt,\n end: SafeIntWithSmallInt,\n step: NonZeroSafeIntWithSmallInt = 1,\n): readonly SafeInt[] {\n return Array.from(rangeIterator(start, end, step));\n}\n"],"names":["rangeIterator"],"mappings":";;AAqCO,MAAM,QAAQ,CACnB,GAAA;AAAA;AAAA,EAOA,MAAM,IAAA,CAAK,EAAE,QAAQ,GAAA,EAAI,EAAG,MAAM,CAAC;AAAA;AAiB9B,MAAM,MAAM,CACjB,GAAA;AAAA;AAAA,EAOA,KAAA,CAAM,KAAK,EAAE,MAAA,EAAQ,KAAI,EAAG,CAAC,CAAA,EAAG,CAAA,KAAM,CAAC;AAAA;MAiB5B,MAAA,GAAS,CACpB,GAAA,EACA,IAAA;AAAA;AAAA,EAOA,KAAA,CAAM,IAAA,CAAK,EAAE,MAAA,EAAQ,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,GAAG,CAAA,EAAE,EAAG,MAAM,IAAI;AAAA;AAO9C,MAAM,QAAA,GAAW;AAmBjB,MAAM,WAAW,CACtB,WAAA,KACiB,KAAA,CAAM,IAAA,CAAK,aAAa;AAmBpC,MAAM,gBAAgB,CAC3B,WAAA,KAC0B,KAAA,CAAM,SAAA,CAAU,aAAa;AAiBlD,MAAM,OAAO,CAAsC,KAAA;AAAA;AAAA,EAExD,MAAM,KAAA;AAAM;AA0DP,SAAS,KAAA,CACd,KAAA,EACA,GAAA,EACA,IAAA,GAAmC,CAAA,EACf;AACpB,EAAA,OAAO,MAAM,IAAA,CAAKA,OAAA,CAAc,KAAA,EAAO,GAAA,EAAK,IAAI,CAAC,CAAA;AACnD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-element-access.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-element-access.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAQ,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EACL,KAAK,yBAAyB,EAC9B,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,IAAI,EACV,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,EAAE,CAAC,KAAK,CAAC,EAAE,S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|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const [index] = args;
|
|
17
|
-
return (array) => at(array, index);
|
|
18
|
-
}
|
|
7
|
+
switch (args.length) {
|
|
8
|
+
case 2: {
|
|
9
|
+
const [array, index$1] = args;
|
|
10
|
+
return pipe(index$1 < 0 ? array.length + index$1 : index$1).map(
|
|
11
|
+
(normalizedIndex) => normalizedIndex < 0 || normalizedIndex >= array.length ? none : (
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
13
|
+
some(array[normalizedIndex])
|
|
14
|
+
)
|
|
15
|
+
).value;
|
|
19
16
|
}
|
|
17
|
+
case 1: {
|
|
18
|
+
const [index] = args;
|
|
19
|
+
return (array) => at(array, index);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* const empty: readonly Readonly<{ id: number }>[] = [] as const;
|
|
30
|
-
*
|
|
31
|
-
* const first = Arr.head(users);
|
|
32
|
-
*
|
|
33
|
-
* const none = Arr.head(empty);
|
|
34
|
-
*
|
|
35
|
-
* assert.deepStrictEqual(first, Optional.some({ id: 1 }));
|
|
36
|
-
*
|
|
37
|
-
* assert.deepStrictEqual(none, Optional.none);
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
const head = (array) =>
|
|
41
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
42
|
-
(array.length === 0 ? none : some(array.at(0)));
|
|
43
|
-
/**
|
|
44
|
-
* Returns the last element of an array as an Optional.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
*
|
|
48
|
-
* ```ts
|
|
49
|
-
* const queue = ['first', 'second'] as const;
|
|
50
|
-
*
|
|
51
|
-
* const emptyQueue: readonly string[] = [] as const;
|
|
52
|
-
*
|
|
53
|
-
* const lastValue = Arr.last(queue);
|
|
54
|
-
*
|
|
55
|
-
* const none = Arr.last(emptyQueue);
|
|
56
|
-
*
|
|
57
|
-
* assert.deepStrictEqual(lastValue, Optional.some('second'));
|
|
58
|
-
*
|
|
59
|
-
* assert.deepStrictEqual(none, Optional.none);
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
const last = (array) =>
|
|
63
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
64
|
-
(array.length === 0 ? none : some(array.at(-1)));
|
|
65
|
-
/**
|
|
66
|
-
* Alias for `head`.
|
|
67
|
-
*
|
|
68
|
-
* @see {@link head}
|
|
69
|
-
*/
|
|
23
|
+
const head = (array) => (
|
|
24
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
25
|
+
array.length === 0 ? none : some(array.at(0))
|
|
26
|
+
);
|
|
27
|
+
const last = (array) => (
|
|
28
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
29
|
+
array.length === 0 ? none : some(array.at(-1))
|
|
30
|
+
);
|
|
70
31
|
const first = head;
|
|
71
32
|
|
|
72
33
|
export { at, first, head, last };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-element-access.mjs","sources":["../../../src/array/impl/array-utils-element-access.mts"],"sourcesContent":[null],"names":["index","Optional.none","Optional.some"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"array-utils-element-access.mjs","sources":["../../../src/array/impl/array-utils-element-access.mts"],"sourcesContent":["import { type NonEmptyArray } from 'ts-type-forge';\nimport { Optional, pipe } from '../../functional/index.mjs';\nimport {\n type ArgArrayIndexWithNegative,\n type None,\n type SizeType,\n type Some,\n} from '../../types.mjs';\n\n/**\n * Safely retrieves an element at a given index from an array, returning an Optional.\n *\n * @example\n *\n * ```ts\n * const letters: readonly string[] = ['a', 'b', 'c'] as const;\n *\n * const two = Arr.at(letters, 1);\n *\n * const last = Arr.at(-1)(letters);\n *\n * const missing = Arr.at(letters, 5);\n *\n * assert.deepStrictEqual(two, Optional.some('b'));\n *\n * assert.deepStrictEqual(last, Optional.some('c'));\n *\n * assert.deepStrictEqual(missing, Optional.none);\n * ```\n */\nexport function at<const Ar extends readonly unknown[]>(\n array: Ar,\n index: ArgArrayIndexWithNegative<Ar>,\n): Optional<Ar[number]>;\n\n// Curried version\n\nexport function at(\n index: SizeType.ArgArrWithNegative,\n): <E>(array: readonly E[]) => Optional<E>;\n\nexport function at<E>(\n ...args:\n | readonly [array: readonly E[], index: SizeType.ArgArrWithNegative]\n | readonly [index: SizeType.ArgArrWithNegative]\n): Optional<E> | ((array: readonly E[]) => Optional<E>) {\n switch (args.length) {\n case 2: {\n const [array, index] = args;\n\n return pipe(index < 0 ? array.length + index : index).map(\n (normalizedIndex) =>\n normalizedIndex < 0 || normalizedIndex >= array.length\n ? Optional.none\n : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n Optional.some(array[normalizedIndex]!),\n ).value;\n }\n\n case 1: {\n const [index] = args;\n\n return (array) => at(array, index);\n }\n }\n}\n\n/**\n * Returns the first element of an array as an Optional.\n *\n * @example\n *\n * ```ts\n * const users = [{ id: 1 }, { id: 2 }] as const;\n *\n * const empty: readonly Readonly<{ id: number }>[] = [] as const;\n *\n * const first = Arr.head(users);\n *\n * const none = Arr.head(empty);\n *\n * assert.deepStrictEqual(first, Optional.some({ id: 1 }));\n *\n * assert.deepStrictEqual(none, Optional.none);\n * ```\n */\nexport const head = <const Ar extends readonly unknown[]>(\n array: Ar,\n): Ar extends readonly []\n ? None\n : Ar extends readonly [infer E, ...unknown[]]\n ? Some<E>\n : Ar extends NonEmptyArray<infer E>\n ? Some<E>\n : Optional<Ar[number]> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (array.length === 0 ? Optional.none : Optional.some(array.at(0))) as never;\n\n/**\n * Returns the last element of an array as an Optional.\n *\n * @example\n *\n * ```ts\n * const queue = ['first', 'second'] as const;\n *\n * const emptyQueue: readonly string[] = [] as const;\n *\n * const lastValue = Arr.last(queue);\n *\n * const none = Arr.last(emptyQueue);\n *\n * assert.deepStrictEqual(lastValue, Optional.some('second'));\n *\n * assert.deepStrictEqual(none, Optional.none);\n * ```\n */\nexport const last = <const Ar extends readonly unknown[]>(\n array: Ar,\n): Ar extends readonly []\n ? None\n : Ar extends readonly [...unknown[], infer E]\n ? Some<E>\n : Ar extends NonEmptyArray<infer E>\n ? Some<E>\n : Optional<Ar[number]> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (array.length === 0 ? Optional.none : Optional.some(array.at(-1))) as never;\n\n/**\n * Alias for `head`.\n *\n * @see {@link head}\n */\nexport const first = head;\n"],"names":["index","Optional.none","Optional.some"],"mappings":";;;;;AAyCO,SAAS,MACX,IAAA,EAGmD;AACtD,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAOA,OAAK,CAAA,GAAI,IAAA;AAEvB,MAAA,OAAO,KAAKA,OAAA,GAAQ,CAAA,GAAI,MAAM,MAAA,GAASA,OAAA,GAAQA,OAAK,CAAA,CAAE,GAAA;AAAA,QACpD,CAAC,eAAA,KACC,eAAA,GAAkB,KAAK,eAAA,IAAmB,KAAA,CAAM,SAC5CC,IAAS;AAAA;AAAA,UAETC,IAAS,CAAK,KAAA,CAAM,eAAe,CAAE;AAAA;AAAA,OAC7C,CAAE,KAAA;AAAA,IACJ;AAAA,IAEA,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAK,CAAA,GAAI,IAAA;AAEhB,MAAA,OAAO,CAAC,KAAA,KAAU,EAAA,CAAG,KAAA,EAAO,KAAK,CAAA;AAAA,IACnC;AAAA;AAEJ;AAqBO,MAAM,OAAO,CAClB,KAAA;AAAA;AAAA,EASC,KAAA,CAAM,MAAA,KAAW,CAAA,GAAID,IAAS,GAAOC,IAAS,CAAK,KAAA,CAAM,EAAA,CAAG,CAAC,CAAC;AAAA;AAqB1D,MAAM,OAAO,CAClB,KAAA;AAAA;AAAA,EASC,KAAA,CAAM,MAAA,KAAW,CAAA,GAAID,IAAS,GAAOC,IAAS,CAAK,KAAA,CAAM,EAAA,CAAG,EAAE,CAAC;AAAA;AAO3D,MAAM,KAAA,GAAQ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-iterators.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-iterators.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,OAAO,GAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"array-utils-iterators.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-iterators.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,OAAO,GAAc,CAAC,SAC1B,SAAS,CAAC,EAAE,KAClB,aAAa,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,CAI1C,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,MAAM,GAAc,CAAC,SAAS,SAAS,CAAC,EAAE,KAAG,aAAa,CAAC,CAAC,CAIxE,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,GAAc,CAAC,SAC1B,SAAS,CAAC,EAAE,KAClB,aAAa,CAAC,QAAQ,CAAC,GAAG,CAI5B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,IAAI,GAbiB,CAAC,SAC1B,SAAS,CAAC,EAAE,KAClB,aAAa,CAAC,QAAQ,CAAC,GAAG,CAWF,CAAC"}
|
|
@@ -35,75 +35,21 @@ import '../../number/enum/uint8.mjs';
|
|
|
35
35
|
import '../../number/num.mjs';
|
|
36
36
|
import '../../number/refined-number-utils.mjs';
|
|
37
37
|
|
|
38
|
-
/**
|
|
39
|
-
* Returns an iterator of `[index, value]` pairs for an array.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
*
|
|
43
|
-
* ```ts
|
|
44
|
-
* const tags = ['alpha', 'beta', 'gamma'] as const;
|
|
45
|
-
*
|
|
46
|
-
* const entryList = Array.from(
|
|
47
|
-
* Arr.entries(tags),
|
|
48
|
-
* ([index, tag]) => [Number(index), tag] as const,
|
|
49
|
-
* );
|
|
50
|
-
*
|
|
51
|
-
* assert.deepStrictEqual(
|
|
52
|
-
* entryList,
|
|
53
|
-
* Array.from([
|
|
54
|
-
* [0, 'alpha'],
|
|
55
|
-
* [1, 'beta'],
|
|
56
|
-
* [2, 'gamma'],
|
|
57
|
-
* ]),
|
|
58
|
-
* );
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
38
|
const entries = function* (array) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
39
|
+
for (const [index, value] of array.entries()) {
|
|
40
|
+
yield [asUint32(index), value];
|
|
41
|
+
}
|
|
65
42
|
};
|
|
66
|
-
/**
|
|
67
|
-
* Returns an iterator of values for an array.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
*
|
|
71
|
-
* ```ts
|
|
72
|
-
* const players = ['Ada', 'Grace', 'Alan'] as readonly string[];
|
|
73
|
-
*
|
|
74
|
-
* const valueList = Array.from(Arr.values(players));
|
|
75
|
-
*
|
|
76
|
-
* assert.deepStrictEqual(valueList, players);
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
43
|
const values = function* (array) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
44
|
+
for (const value of array) {
|
|
45
|
+
yield value;
|
|
46
|
+
}
|
|
83
47
|
};
|
|
84
|
-
/**
|
|
85
|
-
* Returns an iterator of indices for an array.
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
*
|
|
89
|
-
* ```ts
|
|
90
|
-
* const items = ['zero', 'one', 'two'] as const;
|
|
91
|
-
*
|
|
92
|
-
* const indexList = Array.from(Arr.indices(items));
|
|
93
|
-
*
|
|
94
|
-
* assert.deepStrictEqual(indexList, [0, 1, 2]);
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
48
|
const indices = function* (array) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
49
|
+
for (const key of array.keys()) {
|
|
50
|
+
yield asUint32(key);
|
|
51
|
+
}
|
|
101
52
|
};
|
|
102
|
-
/**
|
|
103
|
-
* Alias for `indices`.
|
|
104
|
-
*
|
|
105
|
-
* @see {@link indices}
|
|
106
|
-
*/
|
|
107
53
|
const keys = indices;
|
|
108
54
|
|
|
109
55
|
export { entries, indices, keys, values };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-iterators.mjs","sources":["../../../src/array/impl/array-utils-iterators.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"array-utils-iterators.mjs","sources":["../../../src/array/impl/array-utils-iterators.mts"],"sourcesContent":["import { asUint32 } from '../../number/index.mjs';\nimport { type SizeType } from '../../types.mjs';\n\n/**\n * Returns an iterator of `[index, value]` pairs for an array.\n *\n * @example\n *\n * ```ts\n * const tags = ['alpha', 'beta', 'gamma'] as const;\n *\n * const entryList = Array.from(\n * Arr.entries(tags),\n * ([index, tag]) => [Number(index), tag] as const,\n * );\n *\n * assert.deepStrictEqual(\n * entryList,\n * Array.from([\n * [0, 'alpha'],\n * [1, 'beta'],\n * [2, 'gamma'],\n * ]),\n * );\n * ```\n */\nexport const entries = function* <E>(\n array: readonly E[],\n): ArrayIterator<readonly [SizeType.Arr, E]> {\n for (const [index, value] of array.entries()) {\n yield [asUint32(index), value] as const;\n }\n};\n\n/**\n * Returns an iterator of values for an array.\n *\n * @example\n *\n * ```ts\n * const players = ['Ada', 'Grace', 'Alan'] as readonly string[];\n *\n * const valueList = Array.from(Arr.values(players));\n *\n * assert.deepStrictEqual(valueList, players);\n * ```\n */\nexport const values = function* <E>(array: readonly E[]): ArrayIterator<E> {\n for (const value of array) {\n yield value;\n }\n};\n\n/**\n * Returns an iterator of indices for an array.\n *\n * @example\n *\n * ```ts\n * const items = ['zero', 'one', 'two'] as const;\n *\n * const indexList = Array.from(Arr.indices(items));\n *\n * assert.deepStrictEqual(indexList, [0, 1, 2]);\n * ```\n */\nexport const indices = function* <E>(\n array: readonly E[],\n): ArrayIterator<SizeType.Arr> {\n for (const key of array.keys()) {\n yield asUint32(key);\n }\n};\n\n/**\n * Alias for `indices`.\n *\n * @see {@link indices}\n */\nexport const keys = indices;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BO,MAAM,OAAA,GAAU,WACrB,KAAA,EAC2C;AAC3C,EAAA,KAAA,MAAW,CAAC,KAAA,EAAO,KAAK,CAAA,IAAK,KAAA,CAAM,SAAQ,EAAG;AAC5C,IAAA,MAAM,CAAC,QAAA,CAAS,KAAK,CAAA,EAAG,KAAK,CAAA;AAAA,EAC/B;AACF;AAeO,MAAM,MAAA,GAAS,WAAc,KAAA,EAAuC;AACzE,EAAA,KAAA,MAAW,SAAS,KAAA,EAAO;AACzB,IAAA,MAAM,KAAA;AAAA,EACR;AACF;AAeO,MAAM,OAAA,GAAU,WACrB,KAAA,EAC6B;AAC7B,EAAA,KAAA,MAAW,GAAA,IAAO,KAAA,CAAM,IAAA,EAAK,EAAG;AAC9B,IAAA,MAAM,SAAS,GAAG,CAAA;AAAA,EACpB;AACF;AAOO,MAAM,IAAA,GAAO;;;;"}
|
|
@@ -39,106 +39,106 @@ import '@sindresorhus/is';
|
|
|
39
39
|
import { create, copy } from './array-utils-creation.mjs';
|
|
40
40
|
|
|
41
41
|
function set(...args) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
case 2: {
|
|
48
|
-
const [index, newValue] = args;
|
|
49
|
-
return (array) => set(array, index, newValue);
|
|
50
|
-
}
|
|
42
|
+
switch (args.length) {
|
|
43
|
+
case 3: {
|
|
44
|
+
const [array, index, newValue] = args;
|
|
45
|
+
return array.with(index, newValue);
|
|
51
46
|
}
|
|
47
|
+
case 2: {
|
|
48
|
+
const [index, newValue] = args;
|
|
49
|
+
return (array) => set(array, index, newValue);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
52
|
}
|
|
53
53
|
function toUpdated(...args) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return (array) => toUpdated(array, index, updater);
|
|
63
|
-
}
|
|
54
|
+
switch (args.length) {
|
|
55
|
+
case 3: {
|
|
56
|
+
const [array, index, updater] = args;
|
|
57
|
+
return array.with(index, updater(array[index]));
|
|
58
|
+
}
|
|
59
|
+
case 2: {
|
|
60
|
+
const [index, updater] = args;
|
|
61
|
+
return (array) => toUpdated(array, index, updater);
|
|
64
62
|
}
|
|
63
|
+
}
|
|
65
64
|
}
|
|
66
65
|
function toInserted(...args) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return (array) => toInserted(array, index, newValue);
|
|
76
|
-
}
|
|
66
|
+
switch (args.length) {
|
|
67
|
+
case 3: {
|
|
68
|
+
const [array, index, newValue] = args;
|
|
69
|
+
return array.toSpliced(
|
|
70
|
+
index,
|
|
71
|
+
0,
|
|
72
|
+
newValue
|
|
73
|
+
);
|
|
77
74
|
}
|
|
75
|
+
case 2: {
|
|
76
|
+
const [index, newValue] = args;
|
|
77
|
+
return (array) => toInserted(array, index, newValue);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
78
80
|
}
|
|
79
81
|
function toRemoved(...args) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
82
|
+
switch (args.length) {
|
|
83
|
+
case 2: {
|
|
84
|
+
const [array, index] = args;
|
|
85
|
+
return array.toSpliced(index, 1);
|
|
86
|
+
}
|
|
87
|
+
case 1: {
|
|
88
|
+
const [index] = args;
|
|
89
|
+
return (array) => toRemoved(array, index);
|
|
89
90
|
}
|
|
91
|
+
}
|
|
90
92
|
}
|
|
91
93
|
function toPushed(...args) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return array.toSpliced(array.length, 0, newValue);
|
|
97
|
-
}
|
|
98
|
-
case 1: {
|
|
99
|
-
const [newValue] = args;
|
|
100
|
-
return (array) => toPushed(array, newValue);
|
|
101
|
-
}
|
|
94
|
+
switch (args.length) {
|
|
95
|
+
case 2: {
|
|
96
|
+
const [array, newValue] = args;
|
|
97
|
+
return array.toSpliced(array.length, 0, newValue);
|
|
102
98
|
}
|
|
99
|
+
case 1: {
|
|
100
|
+
const [newValue] = args;
|
|
101
|
+
return (array) => toPushed(array, newValue);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
103
104
|
}
|
|
104
105
|
function toUnshifted(...args) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return (array) => toUnshifted(array, newValue);
|
|
114
|
-
}
|
|
106
|
+
switch (args.length) {
|
|
107
|
+
case 2: {
|
|
108
|
+
const [array, newValue] = args;
|
|
109
|
+
return array.toSpliced(0, 0, newValue);
|
|
110
|
+
}
|
|
111
|
+
case 1: {
|
|
112
|
+
const [newValue] = args;
|
|
113
|
+
return (array) => toUnshifted(array, newValue);
|
|
115
114
|
}
|
|
115
|
+
}
|
|
116
116
|
}
|
|
117
117
|
function toFilled(...args) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
case 1: {
|
|
124
|
-
const [value] = args;
|
|
125
|
-
return (array) => toFilled(array, value);
|
|
126
|
-
}
|
|
118
|
+
switch (args.length) {
|
|
119
|
+
case 2: {
|
|
120
|
+
const [array, value] = args;
|
|
121
|
+
return create(asPositiveUint32(array.length), value);
|
|
127
122
|
}
|
|
123
|
+
case 1: {
|
|
124
|
+
const [value] = args;
|
|
125
|
+
return (array) => toFilled(array, value);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
128
|
}
|
|
129
129
|
function toRangeFilled(...args) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
130
|
+
switch (args.length) {
|
|
131
|
+
case 3: {
|
|
132
|
+
const [array, value, [start, end]] = args;
|
|
133
|
+
const mut_cp = castMutable(copy(array));
|
|
134
|
+
mut_cp.fill(value, start, end);
|
|
135
|
+
return mut_cp;
|
|
136
|
+
}
|
|
137
|
+
case 2: {
|
|
138
|
+
const [value, fillRange] = args;
|
|
139
|
+
return (array) => toRangeFilled(array, value, fillRange);
|
|
141
140
|
}
|
|
141
|
+
}
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
export { set, toFilled, toInserted, toPushed, toRangeFilled, toRemoved, toUnshifted, toUpdated };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-modification.mjs","sources":["../../../src/array/impl/array-utils-modification.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDM,SAAU,GAAG,CACjB,GAAG,IAE+C,EAAA;AAElD,IAAA,QAAQ,IAAI,CAAC,MAAM;QACjB,KAAK,CAAC,EAAE;YACN,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAI;YAErC,OAAQ,KAA4B,CAAC,IAAI,CAAC,KAAK,EAA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M,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,IAAI;YAE3B,OAAO,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC;QACtD;QAEA,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI;YAEpB,OAAO,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;QAC1C;;AAEJ;AA+CM,SAAU,aAAa,CAC3B,GAAG,IAeE,EAAA;AAEL,IAAA,QAAQ,IAAI,CAAC,MAAM;QACjB,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI;YAEzC,MAAM,MAAM,GAAc,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAElD,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC;AAE9B,YAAA,OAAO,MAAM;QACf;QAEA,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,GAAG,IAAI;AAE/B,YAAA,OAAO,CAAC,KAAK,KAAK,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC;QAC1D;;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"array-utils-modification.mjs","sources":["../../../src/array/impl/array-utils-modification.mts"],"sourcesContent":["import {\n type ArrayOfLength,\n type Increment,\n type IsFixedLengthList,\n type NonEmptyArray,\n} from 'ts-type-forge';\nimport { asPositiveUint32 } from '../../number/index.mjs';\nimport { castMutable } from '../../others/index.mjs';\nimport {\n type ArgArrayIndex,\n type ArgArrayIndexWithNegative,\n type SizeType,\n} from '../../types.mjs';\nimport { copy, create } from './array-utils-creation.mjs';\n\n/**\n * Returns a new array with an element at the specified index replaced.\n *\n * @example\n *\n * ```ts\n * const scores: readonly number[] = [10, 20, 30] as const;\n *\n * const updated = Arr.set(scores, 1, 25);\n *\n * assert.deepStrictEqual(updated, [10, 25, 30]);\n * ```\n */\nexport function set<const Ar extends readonly unknown[], const V = Ar[number]>(\n array: Ar,\n index: ArgArrayIndex<Ar>,\n newValue: V,\n): IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\n// curried version\nexport function set<const V>(\n index: SizeType.ArgArr,\n newValue: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\nexport function set<E, const V = E>(\n ...args:\n | readonly [array: readonly E[], index: SizeType.ArgArr, newValue: V]\n | readonly [index: SizeType.ArgArr, newValue: V]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3: {\n const [array, index, newValue] = args;\n\n return (array as readonly (E | V)[]).with(index, newValue);\n }\n\n case 2: {\n const [index, newValue] = args;\n\n return (array) => set(array, index, newValue);\n }\n }\n}\n\n/**\n * Returns a new array with an element at the specified index updated by applying a function.\n *\n * @example\n *\n * ```ts\n * const temperatures: readonly number[] = [20, 21, 22] as const;\n *\n * const increased = Arr.toUpdated(temperatures, 1, (value) => value + 5);\n *\n * const incrementLast = Arr.toUpdated<number>(\n * 2,\n * (value) => value + 1,\n * )(temperatures);\n *\n * assert.deepStrictEqual(increased, [20, 26, 22]);\n *\n * assert.deepStrictEqual(incrementLast, [20, 21, 23]);\n * ```\n */\nexport function toUpdated<\n const Ar extends readonly unknown[],\n const V = Ar[number],\n>(\n array: Ar,\n index: ArgArrayIndex<Ar>,\n updater: (prev: Ar[number]) => V,\n): IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\n// curried version\nexport function toUpdated<E, const V = E>(\n index: SizeType.ArgArr,\n updater: (prev: E) => V,\n): <const Ar extends readonly E[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? Readonly<{ [K in keyof Ar]: Ar[K] | V }>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<Ar[number] | V>\n : readonly (Ar[number] | V)[];\n\nexport function toUpdated<E, V = E>(\n ...args:\n | readonly [\n array: readonly E[],\n index: SizeType.ArgArr,\n updater: (prev: E) => V,\n ]\n | readonly [index: SizeType.ArgArr, updater: (prev: E) => V]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3: {\n const [array, index, updater] = args;\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return (array as readonly (E | V)[]).with(index, updater(array[index]!));\n }\n\n case 2: {\n const [index, updater] = args;\n\n return (array) => toUpdated(array, index, updater);\n }\n }\n}\n\n/**\n * Returns a new array with a value inserted at the specified index.\n *\n * @example\n *\n * ```ts\n * const numbers = [1, 2, 4] as const;\n *\n * const withThree = Arr.toInserted(numbers, 2, 3);\n *\n * const appendFive = Arr.toInserted(3, 5)(numbers);\n *\n * assert.deepStrictEqual(withThree, [1, 2, 3, 4]);\n *\n * assert.deepStrictEqual(appendFive, [1, 2, 4, 5]);\n * ```\n */\nexport function toInserted<\n const Ar extends readonly unknown[],\n const V = Ar[number],\n>(\n array: Ar,\n index: ArgArrayIndexWithNegative<Ar>,\n newValue: V,\n): IsFixedLengthList<Ar> extends true\n ? ArrayOfLength<CastToNumber<Increment<Ar['length']>>, Ar[number] | V>\n : NonEmptyArray<Ar[number] | V>;\n\n// curried version\nexport function toInserted<const V>(\n index: SizeType.ArgArrWithNegative,\n newValue: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? ArrayOfLength<CastToNumber<Increment<Ar['length']>>, Ar[number] | V>\n : NonEmptyArray<Ar[number] | V>;\n\nexport function toInserted<E, const V = E>(\n ...args:\n | readonly [\n array: readonly E[],\n index: SizeType.ArgArrWithNegative,\n newValue: V,\n ]\n | readonly [index: SizeType.ArgArrWithNegative, newValue: V]\n): NonEmptyArray<E | V> | ((array: readonly E[]) => NonEmptyArray<E | V>) {\n switch (args.length) {\n case 3: {\n const [array, index, newValue] = args;\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return (array as readonly (E | V)[]).toSpliced(\n index,\n 0,\n newValue,\n ) as unknown as NonEmptyArray<E | V>;\n }\n\n case 2: {\n const [index, newValue] = args;\n\n return (array) => toInserted(array, index, newValue);\n }\n }\n}\n\ntype CastToNumber<T> = T extends number ? T : never;\n\n/**\n * Returns a new array with the element at the specified index removed.\n *\n * @example\n *\n * ```ts\n * const letters = ['a', 'b', 'c', 'd'] as const;\n *\n * const withoutSecond = Arr.toRemoved(letters, 1);\n *\n * const withoutFirstCurried = Arr.toRemoved(0)(letters);\n *\n * assert.deepStrictEqual(withoutSecond, ['a', 'c', 'd']);\n *\n * assert.deepStrictEqual(withoutFirstCurried, ['b', 'c', 'd']);\n * ```\n */\nexport function toRemoved<const Ar extends readonly unknown[]>(\n array: Ar,\n index: ArgArrayIndexWithNegative<Ar>,\n): readonly Ar[number][];\n\nexport function toRemoved(\n index: SizeType.ArgArrWithNegative,\n): <E>(array: readonly E[]) => readonly E[];\n\nexport function toRemoved<E>(\n ...args:\n | readonly [array: readonly E[], index: SizeType.ArgArrWithNegative]\n | readonly [index: SizeType.ArgArrWithNegative]\n): readonly E[] | ((array: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2: {\n const [array, index] = args;\n\n return array.toSpliced(index, 1);\n }\n\n case 1: {\n const [index] = args;\n\n return (array) => toRemoved(array, index);\n }\n }\n}\n\n/**\n * Returns a new array with a value appended to the end.\n *\n * @example\n *\n * ```ts\n * const base = [1, 2] as const;\n *\n * const appended = Arr.toPushed(base, 3);\n *\n * const appendedCurried = Arr.toPushed(4)(base);\n *\n * assert.deepStrictEqual(appended, [1, 2, 3]);\n *\n * assert.deepStrictEqual(appendedCurried, [1, 2, 4]);\n * ```\n */\nexport function toPushed<const Ar extends readonly unknown[], const V>(\n array: Ar,\n newValue: V,\n): readonly [...Ar, V];\n\nexport function toPushed<const V>(\n newValue: V,\n): <const Ar extends readonly unknown[]>(array: Ar) => readonly [...Ar, V];\n\nexport function toPushed<const Ar extends readonly unknown[], const V>(\n ...args: readonly [array: Ar, newValue: V] | readonly [newValue: V]\n): readonly [...Ar, V] | ((array: Ar) => readonly [...Ar, V]) {\n switch (args.length) {\n case 2: {\n const [array, newValue] = args;\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return array.toSpliced(array.length, 0, newValue) as unknown as readonly [\n ...Ar,\n V,\n ];\n }\n\n case 1: {\n const [newValue] = args;\n\n return (array) => toPushed(array, newValue);\n }\n }\n}\n\n/**\n * Returns a new array with a value prepended to the beginning.\n *\n * @example\n *\n * ```ts\n * const base = [2, 3] as const;\n *\n * const prefixed = Arr.toUnshifted(base, 1);\n *\n * const prefixedCurried = Arr.toUnshifted(0)(base);\n *\n * assert.deepStrictEqual(prefixed, [1, 2, 3]);\n *\n * assert.deepStrictEqual(prefixedCurried, [0, 2, 3]);\n * ```\n */\nexport function toUnshifted<const Ar extends readonly unknown[], const V>(\n array: Ar,\n newValue: V,\n): readonly [V, ...Ar];\n\nexport function toUnshifted<const V>(\n newValue: V,\n): <const Ar extends readonly unknown[]>(array: Ar) => readonly [V, ...Ar];\n\nexport function toUnshifted<Ar extends readonly unknown[], const V>(\n ...args: readonly [array: Ar, newValue: V] | readonly [newValue: V]\n): readonly [V, ...Ar] | ((array: Ar) => readonly [V, ...Ar]) {\n switch (args.length) {\n case 2: {\n const [array, newValue] = args;\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return array.toSpliced(0, 0, newValue) as unknown as readonly [V, ...Ar];\n }\n\n case 1: {\n const [newValue] = args;\n\n return (array) => toUnshifted(array, newValue);\n }\n }\n}\n\n/**\n * Returns a new array with all elements replaced by the specified value.\n *\n * @example\n *\n * ```ts\n * const base = [1, 2, 3] as const;\n *\n * const filled = Arr.toFilled(base, 0);\n *\n * const filledCurried = Arr.toFilled('x')(base);\n *\n * assert.deepStrictEqual(filled, [0, 0, 0]);\n *\n * assert.deepStrictEqual(filledCurried, ['x', 'x', 'x']);\n * ```\n */\nexport function toFilled<const Ar extends readonly unknown[], const V>(\n array: Ar,\n value: V,\n): IsFixedLengthList<Ar> extends true\n ? ArrayOfLength<Ar['length'], V>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<V>\n : readonly V[];\n\n// curried version\nexport function toFilled<const V>(\n value: V,\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? ArrayOfLength<Ar['length'], V>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<V>\n : readonly V[];\n\nexport function toFilled<E>(\n ...args: readonly [array: readonly E[], value: E] | readonly [value: E]\n): readonly E[] | ((array: readonly E[]) => readonly E[]) {\n switch (args.length) {\n case 2: {\n const [array, value] = args;\n\n return create(asPositiveUint32(array.length), value);\n }\n\n case 1: {\n const [value] = args;\n\n return (array) => toFilled(array, value);\n }\n }\n}\n\n/**\n * Returns a new array with elements in the specified range replaced by the specified value.\n *\n * @example\n *\n * ```ts\n * const base = [0, 1, 2, 3, 4] as const;\n *\n * const filledMiddle = Arr.toRangeFilled(base, 9, [1, 4]);\n *\n * const filledPrefix = Arr.toRangeFilled(8, [0, 2])(base);\n *\n * assert.deepStrictEqual(filledMiddle, [0, 9, 9, 9, 4]);\n *\n * assert.deepStrictEqual(filledPrefix, [8, 8, 2, 3, 4]);\n * ```\n */\nexport function toRangeFilled<const Ar extends readonly unknown[], const V>(\n array: Ar,\n value: V,\n fillRange: readonly [\n start: ArgArrayIndexWithNegative<Ar>,\n end: ArgArrayIndexWithNegative<Ar>,\n ],\n): IsFixedLengthList<Ar> extends true\n ? ArrayOfLength<Ar['length'], V | Ar[number]>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<V | Ar[number]>\n : readonly (V | Ar[number])[];\n\n// curried version\nexport function toRangeFilled<const V>(\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n): <const Ar extends readonly unknown[]>(\n array: Ar,\n) => IsFixedLengthList<Ar> extends true\n ? ArrayOfLength<Ar['length'], V | Ar[number]>\n : Ar extends NonEmptyArray<unknown>\n ? NonEmptyArray<V | Ar[number]>\n : readonly (V | Ar[number])[];\n\nexport function toRangeFilled<E, const V>(\n ...args:\n | readonly [\n array: readonly E[],\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n ]\n | readonly [\n value: V,\n fillRange: readonly [\n start: SizeType.ArgArrWithNegative,\n end: SizeType.ArgArrWithNegative,\n ],\n ]\n): readonly (E | V)[] | ((array: readonly E[]) => readonly (E | V)[]) {\n switch (args.length) {\n case 3: {\n const [array, value, [start, end]] = args;\n\n const mut_cp: (E | V)[] = castMutable(copy(array));\n\n mut_cp.fill(value, start, end);\n\n return mut_cp;\n }\n\n case 2: {\n const [value, fillRange] = args;\n\n return (array) => toRangeFilled(array, value, fillRange);\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDO,SAAS,OACX,IAAA,EAGiE;AACpE,EAAA,QAAQ,KAAK,MAAA;AAAQ,IACnB,KAAK,CAAA,EAAG;AACN,MAAA,MAAM,CAAC,KAAA,EAAO,KAAA,EAAO,QAAQ,CAAA,GAAI,IAAA;AAEjC,MAAA,OAAQ,KAAA,CAA6B,IAAA,CAAK,KAAA,EAAO,QAAQ,CAAA;AAAA,IAC3D;AAAA,I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