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
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { ErrTypeTagName, WarnTypeTagName, OkTypeTagName } from './tag.mjs';
|
|
2
2
|
|
|
3
|
-
/** @internal Returns the human readable variant label for the given tag. */
|
|
4
3
|
const variantName = (tag) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
switch (tag) {
|
|
5
|
+
case OkTypeTagName:
|
|
6
|
+
return "Ok";
|
|
7
|
+
case WarnTypeTagName:
|
|
8
|
+
return "Warn";
|
|
9
|
+
case ErrTypeTagName:
|
|
10
|
+
return "Err";
|
|
11
|
+
}
|
|
13
12
|
};
|
|
14
13
|
|
|
15
14
|
export { variantName };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variant-name.mjs","sources":["../../../../src/functional/ternary-result/impl/variant-name.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"variant-name.mjs","sources":["../../../../src/functional/ternary-result/impl/variant-name.mts"],"sourcesContent":["import { type UnknownTernaryResult } from '../ternary-result.mjs';\nimport { ErrTypeTagName, OkTypeTagName, WarnTypeTagName } from './tag.mjs';\n\n/** @internal Returns the human readable variant label for the given tag. */\nexport const variantName = (\n tag: UnknownTernaryResult['$$tag'],\n): 'Ok' | 'Warn' | 'Err' => {\n switch (tag) {\n case OkTypeTagName:\n return 'Ok';\n\n case WarnTypeTagName:\n return 'Warn';\n\n case ErrTypeTagName:\n return 'Err';\n }\n};\n"],"names":[],"mappings":";;AAIO,MAAM,WAAA,GAAc,CACzB,GAAA,KAC0B;AAC1B,EAAA,QAAQ,GAAA;AAAK,IACX,KAAK,aAAA;AACH,MAAA,OAAO,IAAA;AAAA,IAET,KAAK,eAAA;AACH,MAAA,OAAO,MAAA;AAAA,IAET,KAAK,cAAA;AACH,MAAA,OAAO,KAAA;AAAA;AAEb;;;;"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type BoundedLengthArray, type FixedLengthArray, type MaxLengthArray, type MinLengthArray, type SupportedLength } from 'ts-type-forge';
|
|
2
|
+
/**
|
|
3
|
+
* Casts an array to `FixedLengthArray<Length, E>` after checking that it has
|
|
4
|
+
* exactly `length` elements.
|
|
5
|
+
*
|
|
6
|
+
* Use this instead of writing `xs as unknown as FixedLengthArray<N, E>`: the
|
|
7
|
+
* length is verified at runtime, and the original array type (e.g. tuple
|
|
8
|
+
* types) is preserved via intersection, so the result also benefits from the
|
|
9
|
+
* structural tuple prefix (in-range indexed access without `undefined` under
|
|
10
|
+
* `noUncheckedIndexedAccess`).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const rgb = asFixedLengthArray([255, 128, 0], 3);
|
|
16
|
+
*
|
|
17
|
+
* const atMost5: MaxLengthArray<5, number> = rgb; // OK (3 <= 5)
|
|
18
|
+
* const red: number = rgb[0]; // OK — no `undefined`
|
|
19
|
+
*
|
|
20
|
+
* // asFixedLengthArray([255, 128], 3); // throws TypeError
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @template Xs - The input array type (tuple types are preserved).
|
|
24
|
+
* @template Length - The exact number of elements.
|
|
25
|
+
* @param xs - The array to cast.
|
|
26
|
+
* @param length - The exact number of elements.
|
|
27
|
+
* @returns `xs` typed as `FixedLengthArray<Length, Xs[number]> & Xs`.
|
|
28
|
+
* @throws {TypeError} If `xs.length !== length`.
|
|
29
|
+
*/
|
|
30
|
+
export declare const asFixedLengthArray: <Xs extends readonly unknown[], Length extends SupportedLength>(xs: Xs, length: Length) => FixedLengthArray<Length, Xs[number]> & Xs;
|
|
31
|
+
/**
|
|
32
|
+
* Casts an array to `MinLengthArray<MinLength, E>` after checking that it has
|
|
33
|
+
* at least `minLength` elements.
|
|
34
|
+
*
|
|
35
|
+
* Use this instead of writing `xs as unknown as MinLengthArray<N, E>`: the
|
|
36
|
+
* length is verified at runtime, and the original array type (e.g. tuple
|
|
37
|
+
* types) is preserved via intersection, so the result also benefits from the
|
|
38
|
+
* structural tuple prefix (indexed access below `min(N, 10)` without
|
|
39
|
+
* `undefined` under `noUncheckedIndexedAccess`).
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* const history = asMinLengthArray([0, 1, 2, 3], 3);
|
|
45
|
+
*
|
|
46
|
+
* const nonEmpty: MinLengthArray<1, number> = history; // OK (3 >= 1)
|
|
47
|
+
* const first: number = history[0]; // OK — no `undefined`
|
|
48
|
+
*
|
|
49
|
+
* // asMinLengthArray([0], 3); // throws TypeError
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @template Xs - The input array type (tuple types are preserved).
|
|
53
|
+
* @template MinLength - The minimum number of elements (inclusive).
|
|
54
|
+
* @param xs - The array to cast.
|
|
55
|
+
* @param minLength - The minimum number of elements (inclusive).
|
|
56
|
+
* @returns `xs` typed as `MinLengthArray<MinLength, Xs[number]> & Xs`.
|
|
57
|
+
* @throws {TypeError} If `xs.length < minLength`.
|
|
58
|
+
*/
|
|
59
|
+
export declare const asMinLengthArray: <Xs extends readonly unknown[], MinLength extends SupportedLength>(xs: Xs, minLength: MinLength) => MinLengthArray<MinLength, Xs[number]> & Xs;
|
|
60
|
+
/**
|
|
61
|
+
* Casts an array to `MaxLengthArray<MaxLength, E>` after checking that it has
|
|
62
|
+
* at most `maxLength` elements.
|
|
63
|
+
*
|
|
64
|
+
* Use this instead of writing `xs as unknown as MaxLengthArray<N, E>`: the
|
|
65
|
+
* length is verified at runtime, and the original array type (e.g. tuple
|
|
66
|
+
* types) is preserved via intersection.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* const tags = asMaxLengthArray(['a', 'b', 'c'], 8);
|
|
72
|
+
*
|
|
73
|
+
* const relaxed: MaxLengthArray<16, string> = tags; // OK (8 <= 16)
|
|
74
|
+
*
|
|
75
|
+
* // asMaxLengthArray(['a', 'b', 'c'], 2); // throws TypeError
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @template Xs - The input array type (tuple types are preserved).
|
|
79
|
+
* @template MaxLength - The maximum number of elements (inclusive).
|
|
80
|
+
* @param xs - The array to cast.
|
|
81
|
+
* @param maxLength - The maximum number of elements (inclusive).
|
|
82
|
+
* @returns `xs` typed as `MaxLengthArray<MaxLength, Xs[number]> & Xs`.
|
|
83
|
+
* @throws {TypeError} If `xs.length > maxLength`.
|
|
84
|
+
*/
|
|
85
|
+
export declare const asMaxLengthArray: <Xs extends readonly unknown[], MaxLength extends SupportedLength>(xs: Xs, maxLength: MaxLength) => MaxLengthArray<MaxLength, Xs[number]> & Xs;
|
|
86
|
+
/**
|
|
87
|
+
* Casts an array to `BoundedLengthArray<MinLength, MaxLength, E>` after
|
|
88
|
+
* checking that its length is within the inclusive range
|
|
89
|
+
* `[minLength, maxLength]`.
|
|
90
|
+
*
|
|
91
|
+
* Use this instead of writing
|
|
92
|
+
* `xs as unknown as BoundedLengthArray<Min, Max, E>`: the length is verified
|
|
93
|
+
* at runtime, and the original array type (e.g. tuple types) is preserved via
|
|
94
|
+
* intersection.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
*
|
|
98
|
+
* ```ts
|
|
99
|
+
* const selection = asBoundedLengthArray([1, 2, 3], 1, 5);
|
|
100
|
+
*
|
|
101
|
+
* const relaxed: BoundedLengthArray<0, 100, number> = selection; // OK
|
|
102
|
+
*
|
|
103
|
+
* // asBoundedLengthArray([], 1, 5); // throws TypeError
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @template Xs - The input array type (tuple types are preserved).
|
|
107
|
+
* @template MinLength - The minimum number of elements (inclusive).
|
|
108
|
+
* @template MaxLength - The maximum number of elements (inclusive).
|
|
109
|
+
* @param xs - The array to cast.
|
|
110
|
+
* @param minLength - The minimum number of elements (inclusive).
|
|
111
|
+
* @param maxLength - The maximum number of elements (inclusive).
|
|
112
|
+
* @returns `xs` typed as
|
|
113
|
+
* `BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs`.
|
|
114
|
+
* @throws {TypeError} If `xs.length < minLength || xs.length > maxLength`.
|
|
115
|
+
*/
|
|
116
|
+
export declare const asBoundedLengthArray: <Xs extends readonly unknown[], MinLength extends SupportedLength, MaxLength extends SupportedLength>(xs: Xs, minLength: MinLength, maxLength: MaxLength) => BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs;
|
|
117
|
+
//# sourceMappingURL=as-length-bounded-array.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"as-length-bounded-array.d.mts","sourceRoot":"","sources":["../../src/guard/as-length-bounded-array.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAQvB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,kBAAkB,GAC7B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,MAAM,SAAS,eAAe,MAE1B,EAAE,UACE,MAAM,KACb,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAQzC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,gBAAgB,GAC3B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,SAAS,SAAS,eAAe,MAE7B,EAAE,aACK,SAAS,KACnB,cAAc,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAQ1C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,gBAAgB,GAC3B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,SAAS,SAAS,eAAe,MAE7B,EAAE,aACK,SAAS,KACnB,cAAc,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAQ1C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,oBAAoB,GAC/B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,SAAS,SAAS,eAAe,EACjC,SAAS,SAAS,eAAe,MAE7B,EAAE,aACK,SAAS,aACT,SAAS,KACnB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAQzD,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { isBoundedLengthArray, isFixedLengthArray, isMaxLengthArray, isMinLengthArray } from './is-length-bounded-array.mjs';
|
|
2
|
+
|
|
3
|
+
const asFixedLengthArray = (xs, length) => {
|
|
4
|
+
if (!isFixedLengthArray(xs, length)) {
|
|
5
|
+
throw new TypeError(
|
|
6
|
+
`Expected an array of length ${length}, got an array of length ${xs.length}`
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
return xs;
|
|
10
|
+
};
|
|
11
|
+
const asMinLengthArray = (xs, minLength) => {
|
|
12
|
+
if (!isMinLengthArray(xs, minLength)) {
|
|
13
|
+
throw new TypeError(
|
|
14
|
+
`Expected an array of length >= ${minLength}, got an array of length ${xs.length}`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
return xs;
|
|
18
|
+
};
|
|
19
|
+
const asMaxLengthArray = (xs, maxLength) => {
|
|
20
|
+
if (!isMaxLengthArray(xs, maxLength)) {
|
|
21
|
+
throw new TypeError(
|
|
22
|
+
`Expected an array of length <= ${maxLength}, got an array of length ${xs.length}`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return xs;
|
|
26
|
+
};
|
|
27
|
+
const asBoundedLengthArray = (xs, minLength, maxLength) => {
|
|
28
|
+
if (!isBoundedLengthArray(xs, minLength, maxLength)) {
|
|
29
|
+
throw new TypeError(
|
|
30
|
+
`Expected an array of length in [${minLength}, ${maxLength}], got an array of length ${xs.length}`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return xs;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { asBoundedLengthArray, asFixedLengthArray, asMaxLengthArray, asMinLengthArray };
|
|
37
|
+
//# sourceMappingURL=as-length-bounded-array.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"as-length-bounded-array.mjs","sources":["../../src/guard/as-length-bounded-array.mts"],"sourcesContent":["import {\n type BoundedLengthArray,\n type FixedLengthArray,\n type MaxLengthArray,\n type MinLengthArray,\n type SupportedLength,\n} from 'ts-type-forge';\nimport {\n isBoundedLengthArray,\n isFixedLengthArray,\n isMaxLengthArray,\n isMinLengthArray,\n} from './is-length-bounded-array.mjs';\n\n/**\n * Casts an array to `FixedLengthArray<Length, E>` after checking that it has\n * exactly `length` elements.\n *\n * Use this instead of writing `xs as unknown as FixedLengthArray<N, E>`: the\n * length is verified at runtime, and the original array type (e.g. tuple\n * types) is preserved via intersection, so the result also benefits from the\n * structural tuple prefix (in-range indexed access without `undefined` under\n * `noUncheckedIndexedAccess`).\n *\n * @example\n *\n * ```ts\n * const rgb = asFixedLengthArray([255, 128, 0], 3);\n *\n * const atMost5: MaxLengthArray<5, number> = rgb; // OK (3 <= 5)\n * const red: number = rgb[0]; // OK — no `undefined`\n *\n * // asFixedLengthArray([255, 128], 3); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @template Length - The exact number of elements.\n * @param xs - The array to cast.\n * @param length - The exact number of elements.\n * @returns `xs` typed as `FixedLengthArray<Length, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length !== length`.\n */\nexport const asFixedLengthArray = <\n Xs extends readonly unknown[],\n Length extends SupportedLength,\n>(\n xs: Xs,\n length: Length,\n): FixedLengthArray<Length, Xs[number]> & Xs => {\n if (!isFixedLengthArray(xs, length)) {\n throw new TypeError(\n `Expected an array of length ${length}, got an array of length ${xs.length}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `MinLengthArray<MinLength, E>` after checking that it has\n * at least `minLength` elements.\n *\n * Use this instead of writing `xs as unknown as MinLengthArray<N, E>`: the\n * length is verified at runtime, and the original array type (e.g. tuple\n * types) is preserved via intersection, so the result also benefits from the\n * structural tuple prefix (indexed access below `min(N, 10)` without\n * `undefined` under `noUncheckedIndexedAccess`).\n *\n * @example\n *\n * ```ts\n * const history = asMinLengthArray([0, 1, 2, 3], 3);\n *\n * const nonEmpty: MinLengthArray<1, number> = history; // OK (3 >= 1)\n * const first: number = history[0]; // OK — no `undefined`\n *\n * // asMinLengthArray([0], 3); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @template MinLength - The minimum number of elements (inclusive).\n * @param xs - The array to cast.\n * @param minLength - The minimum number of elements (inclusive).\n * @returns `xs` typed as `MinLengthArray<MinLength, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length < minLength`.\n */\nexport const asMinLengthArray = <\n Xs extends readonly unknown[],\n MinLength extends SupportedLength,\n>(\n xs: Xs,\n minLength: MinLength,\n): MinLengthArray<MinLength, Xs[number]> & Xs => {\n if (!isMinLengthArray(xs, minLength)) {\n throw new TypeError(\n `Expected an array of length >= ${minLength}, got an array of length ${xs.length}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `MaxLengthArray<MaxLength, E>` after checking that it has\n * at most `maxLength` elements.\n *\n * Use this instead of writing `xs as unknown as MaxLengthArray<N, E>`: the\n * length is verified at runtime, and the original array type (e.g. tuple\n * types) is preserved via intersection.\n *\n * @example\n *\n * ```ts\n * const tags = asMaxLengthArray(['a', 'b', 'c'], 8);\n *\n * const relaxed: MaxLengthArray<16, string> = tags; // OK (8 <= 16)\n *\n * // asMaxLengthArray(['a', 'b', 'c'], 2); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @template MaxLength - The maximum number of elements (inclusive).\n * @param xs - The array to cast.\n * @param maxLength - The maximum number of elements (inclusive).\n * @returns `xs` typed as `MaxLengthArray<MaxLength, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length > maxLength`.\n */\nexport const asMaxLengthArray = <\n Xs extends readonly unknown[],\n MaxLength extends SupportedLength,\n>(\n xs: Xs,\n maxLength: MaxLength,\n): MaxLengthArray<MaxLength, Xs[number]> & Xs => {\n if (!isMaxLengthArray(xs, maxLength)) {\n throw new TypeError(\n `Expected an array of length <= ${maxLength}, got an array of length ${xs.length}`,\n );\n }\n\n return xs;\n};\n\n/**\n * Casts an array to `BoundedLengthArray<MinLength, MaxLength, E>` after\n * checking that its length is within the inclusive range\n * `[minLength, maxLength]`.\n *\n * Use this instead of writing\n * `xs as unknown as BoundedLengthArray<Min, Max, E>`: the length is verified\n * at runtime, and the original array type (e.g. tuple types) is preserved via\n * intersection.\n *\n * @example\n *\n * ```ts\n * const selection = asBoundedLengthArray([1, 2, 3], 1, 5);\n *\n * const relaxed: BoundedLengthArray<0, 100, number> = selection; // OK\n *\n * // asBoundedLengthArray([], 1, 5); // throws TypeError\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @template MinLength - The minimum number of elements (inclusive).\n * @template MaxLength - The maximum number of elements (inclusive).\n * @param xs - The array to cast.\n * @param minLength - The minimum number of elements (inclusive).\n * @param maxLength - The maximum number of elements (inclusive).\n * @returns `xs` typed as\n * `BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs`.\n * @throws {TypeError} If `xs.length < minLength || xs.length > maxLength`.\n */\nexport const asBoundedLengthArray = <\n Xs extends readonly unknown[],\n MinLength extends SupportedLength,\n MaxLength extends SupportedLength,\n>(\n xs: Xs,\n minLength: MinLength,\n maxLength: MaxLength,\n): BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs => {\n if (!isBoundedLengthArray(xs, minLength, maxLength)) {\n throw new TypeError(\n `Expected an array of length in [${minLength}, ${maxLength}], got an array of length ${xs.length}`,\n );\n }\n\n return xs;\n};\n"],"names":[],"mappings":";;AA0CO,MAAM,kBAAA,GAAqB,CAIhC,EAAA,EACA,MAAA,KAC8C;AAC9C,EAAA,IAAI,CAAC,kBAAA,CAAmB,EAAA,EAAI,MAAM,CAAA,EAAG;AACnC,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,CAAA,4BAAA,EAA+B,MAAM,CAAA,yBAAA,EAA4B,EAAA,CAAG,MAAM,CAAA;AAAA,KAC5E;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT;AA8BO,MAAM,gBAAA,GAAmB,CAI9B,EAAA,EACA,SAAA,KAC+C;AAC/C,EAAA,IAAI,CAAC,gBAAA,CAAiB,EAAA,EAAI,SAAS,CAAA,EAAG;AACpC,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,CAAA,+BAAA,EAAkC,SAAS,CAAA,yBAAA,EAA4B,EAAA,CAAG,MAAM,CAAA;AAAA,KAClF;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT;AA2BO,MAAM,gBAAA,GAAmB,CAI9B,EAAA,EACA,SAAA,KAC+C;AAC/C,EAAA,IAAI,CAAC,gBAAA,CAAiB,EAAA,EAAI,SAAS,CAAA,EAAG;AACpC,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,CAAA,+BAAA,EAAkC,SAAS,CAAA,yBAAA,EAA4B,EAAA,CAAG,MAAM,CAAA;AAAA,KAClF;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT;AAgCO,MAAM,oBAAA,GAAuB,CAKlC,EAAA,EACA,SAAA,EACA,SAAA,KAC8D;AAC9D,EAAA,IAAI,CAAC,oBAAA,CAAqB,EAAA,EAAI,SAAA,EAAW,SAAS,CAAA,EAAG;AACnD,IAAA,MAAM,IAAI,SAAA;AAAA,MACR,mCAAmC,SAAS,CAAA,EAAA,EAAK,SAAS,CAAA,0BAAA,EAA6B,GAAG,MAAM,CAAA;AAAA,KAClG;AAAA,EACF;AAEA,EAAA,OAAO,EAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has-key.d.mts","sourceRoot":"","sources":["../../src/guard/has-key.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,MAAM,GACjB,KAAK,CAAC,CAAC,SAAS,aAAa,EAC7B,KAAK,CAAC,CAAC,SAAS,WAAW,
|
|
1
|
+
{"version":3,"file":"has-key.d.mts","sourceRoot":"","sources":["../../src/guard/has-key.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,MAAM,GACjB,KAAK,CAAC,CAAC,SAAS,aAAa,EAC7B,KAAK,CAAC,CAAC,SAAS,WAAW,OAEtB,CAAC,OACD,CAAC,KACL,GAAG,IAAI,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAA4B,CAAC;AAE5D;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,CAC1B,CAAC,SAAS,aAAa,EACvB,CAAC,SAAS,WAAW,IACnB,CAAC,SAAS,CAAC,GACX,CAAC,SAAS,MAAM,CAAC,GACf,MAAM,SAAS,MAAM,CAAC,GACpB,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GACjC,MAAM,SAAS,MAAM,CAAC,GACpB,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GACjC,MAAM,SAAS,MAAM,CAAC,GACpB,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GACjC,CAAC,GACP,KAAK,GACP,KAAK,CAAC"}
|
package/dist/guard/has-key.mjs
CHANGED
|
@@ -1,44 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type guard function that checks if an object has a specific key as its own
|
|
3
|
-
* property.
|
|
4
|
-
*
|
|
5
|
-
* This function uses `Object.hasOwn()` to check if the given object has the
|
|
6
|
-
* specified key as its own property (not inherited). It acts as a type guard
|
|
7
|
-
* that narrows the type of the object to guarantee the key exists, enabling
|
|
8
|
-
* type-safe property access.
|
|
9
|
-
*
|
|
10
|
-
* **Type Narrowing Behavior:**
|
|
11
|
-
*
|
|
12
|
-
* - When the guard returns `true`, TypeScript narrows the object type to include
|
|
13
|
-
* the checked key
|
|
14
|
-
* - For union types, only union members that contain the key are preserved
|
|
15
|
-
* - The key's value type is preserved from the original object type when possible
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
*
|
|
19
|
-
* ```ts
|
|
20
|
-
* const maybeUser: Readonly<{ id?: number; name?: string }> = {
|
|
21
|
-
* id: 42,
|
|
22
|
-
* } as const;
|
|
23
|
-
*
|
|
24
|
-
* if (hasKey(maybeUser, 'id')) {
|
|
25
|
-
* // `maybeUser` is now known to have an `id` property.
|
|
26
|
-
* assert.isTrue(maybeUser.id === 42);
|
|
27
|
-
* } else {
|
|
28
|
-
* assert.fail();
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @template R - The type of the input object, must extend UnknownRecord
|
|
33
|
-
* @template K - The type of the key to check for, must extend PropertyKey
|
|
34
|
-
* (string | number | symbol)
|
|
35
|
-
* @param obj - The object to check for the presence of the key
|
|
36
|
-
* @param key - The key to check for in the object
|
|
37
|
-
* @returns `true` if the object has the specified key as its own property,
|
|
38
|
-
* `false` otherwise. When `true`, TypeScript narrows the object type to
|
|
39
|
-
* guarantee the key exists.
|
|
40
|
-
* @see {@link keyIsIn} - Similar function that narrows the key type instead of the object type
|
|
41
|
-
*/
|
|
42
1
|
const hasKey = (obj, key) => Object.hasOwn(obj, key);
|
|
43
2
|
|
|
44
3
|
export { hasKey };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has-key.mjs","sources":["../../src/guard/has-key.mts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"has-key.mjs","sources":["../../src/guard/has-key.mts"],"sourcesContent":["import { type ReadonlyRecord, type UnknownRecord } from 'ts-type-forge';\n\n/**\n * Type guard function that checks if an object has a specific key as its own\n * property.\n *\n * This function uses `Object.hasOwn()` to check if the given object has the\n * specified key as its own property (not inherited). It acts as a type guard\n * that narrows the type of the object to guarantee the key exists, enabling\n * type-safe property access.\n *\n * **Type Narrowing Behavior:**\n *\n * - When the guard returns `true`, TypeScript narrows the object type to include\n * the checked key\n * - For union types, only union members that contain the key are preserved\n * - The key's value type is preserved from the original object type when possible\n *\n * @example\n *\n * ```ts\n * const maybeUser: Readonly<{ id?: number; name?: string }> = {\n * id: 42,\n * } as const;\n *\n * if (hasKey(maybeUser, 'id')) {\n * // `maybeUser` is now known to have an `id` property.\n * assert.isTrue(maybeUser.id === 42);\n * } else {\n * assert.fail();\n * }\n * ```\n *\n * @template R - The type of the input object, must extend UnknownRecord\n * @template K - The type of the key to check for, must extend PropertyKey\n * (string | number | symbol)\n * @param obj - The object to check for the presence of the key\n * @param key - The key to check for in the object\n * @returns `true` if the object has the specified key as its own property,\n * `false` otherwise. When `true`, TypeScript narrows the object type to\n * guarantee the key exists.\n * @see {@link keyIsIn} - Similar function that narrows the key type instead of the object type\n */\nexport const hasKey = <\n const R extends UnknownRecord,\n const K extends PropertyKey,\n>(\n obj: R,\n key: K,\n): obj is HasKeyReturnType<R, K> => Object.hasOwn(obj, key);\n\n/**\n * @internal\n * When R is a union type (including the case with only one element), if any element in the union\n * contains K as a key, returns a type that narrows the union to only those elements that contain K as a key.\n * If none of the elements in the union contain K as a key, returns `ReadonlyRecord<K, unknown>`.\n * The result is made readonly.\n */\nexport type HasKeyReturnType<\n R extends UnknownRecord,\n K extends PropertyKey,\n> = R extends R // union distribution\n ? K extends keyof R\n ? string extends keyof R\n ? ReadonlyRecord<K, R[keyof R]> & R\n : number extends keyof R\n ? ReadonlyRecord<K, R[keyof R]> & R\n : symbol extends keyof R\n ? ReadonlyRecord<K, R[keyof R]> & R\n : R\n : never // omit union member that does not have key K\n : never; // dummy case for union distribution\n"],"names":[],"mappings":"AA2CO,MAAM,SAAS,CAIpB,GAAA,EACA,QACkC,MAAA,CAAO,MAAA,CAAO,KAAK,GAAG;;;;"}
|
package/dist/guard/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/guard/index.mts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/guard/index.mts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,eAAe,CAAC;AAC9B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC"}
|
package/dist/guard/index.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { asBoundedLengthArray, asFixedLengthArray, asMaxLengthArray, asMinLengthArray } from './as-length-bounded-array.mjs';
|
|
1
2
|
export { hasKey } from './has-key.mjs';
|
|
3
|
+
export { isBoundedLengthArray, isFixedLengthArray, isMaxLengthArray, isMinLengthArray } from './is-length-bounded-array.mjs';
|
|
2
4
|
export { isBoundedLengthString, isFixedLengthString, isMaxLengthString, isMinLengthString } from './is-length-bounded-string.mjs';
|
|
3
5
|
export { isNonEmptyString } from './is-non-empty-string.mjs';
|
|
4
6
|
export { isNonNullObject } from './is-non-null-object.mjs';
|
package/dist/guard/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { type BoundedLengthArray, type FixedLengthArray, type MaxLengthArray, type MinLengthArray, type SupportedLength } from 'ts-type-forge';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard that checks if an array has at least `minLength` elements.
|
|
4
|
+
*
|
|
5
|
+
* **Type Narrowing Behavior:**
|
|
6
|
+
*
|
|
7
|
+
* - Narrows the input to `MinLengthArray<MinLength, E>` while preserving the
|
|
8
|
+
* original array type (e.g. tuple types) via intersection.
|
|
9
|
+
* - The length constraint lives only in the brand, so this stays cheap for the
|
|
10
|
+
* type checker even when the element type is large — unlike
|
|
11
|
+
* `isMinLengthTuple`, which narrows to a structural tuple type.
|
|
12
|
+
* - The result participates in the length-constraint subtyping relation: for
|
|
13
|
+
* example, a value narrowed to `MinLengthArray<3, E>` is assignable to
|
|
14
|
+
* `MinLengthArray<1, E>`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* const input: readonly number[] = [0, 1, 2, 3];
|
|
20
|
+
*
|
|
21
|
+
* assert.isTrue(isMinLengthArray(input, 3));
|
|
22
|
+
*
|
|
23
|
+
* assert.isFalse(isMinLengthArray([0], 3));
|
|
24
|
+
*
|
|
25
|
+
* if (isMinLengthArray(input, 3)) {
|
|
26
|
+
* const history: MinLengthArray<3, number> = input;
|
|
27
|
+
*
|
|
28
|
+
* const nonEmpty: MinLengthArray<1, number> = input; // OK (3 >= 1)
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @template Xs - The input array type (tuple types are preserved).
|
|
33
|
+
* @template MinLength - The minimum number of elements (inclusive).
|
|
34
|
+
* @param xs - The array to check.
|
|
35
|
+
* @param minLength - The minimum number of elements (inclusive).
|
|
36
|
+
* @returns `true` if `xs.length >= minLength`, `false` otherwise. When `true`,
|
|
37
|
+
* TypeScript narrows `xs` to `MinLengthArray<MinLength, Xs[number]> & Xs`.
|
|
38
|
+
*/
|
|
39
|
+
export declare const isMinLengthArray: <Xs extends readonly unknown[], MinLength extends SupportedLength>(xs: Xs, minLength: MinLength) => xs is MinLengthArray<MinLength, Xs[number]> & Xs;
|
|
40
|
+
/**
|
|
41
|
+
* Type guard that checks if an array has at most `maxLength` elements.
|
|
42
|
+
*
|
|
43
|
+
* **Type Narrowing Behavior:**
|
|
44
|
+
*
|
|
45
|
+
* - Narrows the input to `MaxLengthArray<MaxLength, E>` while preserving the
|
|
46
|
+
* original array type (e.g. tuple types) via intersection.
|
|
47
|
+
* - The length constraint lives only in the brand, so this stays cheap for the
|
|
48
|
+
* type checker even when the element type is large — unlike
|
|
49
|
+
* `isMaxLengthTuple`, which narrows to a union of tuple types.
|
|
50
|
+
* - The result participates in the length-constraint subtyping relation: for
|
|
51
|
+
* example, a value narrowed to `MaxLengthArray<8, E>` is assignable to
|
|
52
|
+
* `MaxLengthArray<16, E>`.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* const input: readonly string[] = ['a', 'b', 'c'];
|
|
58
|
+
*
|
|
59
|
+
* assert.isTrue(isMaxLengthArray(input, 8));
|
|
60
|
+
*
|
|
61
|
+
* assert.isFalse(isMaxLengthArray(input, 2));
|
|
62
|
+
*
|
|
63
|
+
* if (isMaxLengthArray(input, 8)) {
|
|
64
|
+
* const tags: MaxLengthArray<8, string> = input;
|
|
65
|
+
*
|
|
66
|
+
* const relaxed: MaxLengthArray<16, string> = input; // OK (8 <= 16)
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @template Xs - The input array type (tuple types are preserved).
|
|
71
|
+
* @template MaxLength - The maximum number of elements (inclusive).
|
|
72
|
+
* @param xs - The array to check.
|
|
73
|
+
* @param maxLength - The maximum number of elements (inclusive).
|
|
74
|
+
* @returns `true` if `xs.length <= maxLength`, `false` otherwise. When `true`,
|
|
75
|
+
* TypeScript narrows `xs` to `MaxLengthArray<MaxLength, Xs[number]> & Xs`.
|
|
76
|
+
*/
|
|
77
|
+
export declare const isMaxLengthArray: <Xs extends readonly unknown[], MaxLength extends SupportedLength>(xs: Xs, maxLength: MaxLength) => xs is MaxLengthArray<MaxLength, Xs[number]> & Xs;
|
|
78
|
+
/**
|
|
79
|
+
* Type guard that checks if an array's length is within the inclusive range
|
|
80
|
+
* `[minLength, maxLength]`.
|
|
81
|
+
*
|
|
82
|
+
* **Type Narrowing Behavior:**
|
|
83
|
+
*
|
|
84
|
+
* - Narrows the input to `BoundedLengthArray<MinLength, MaxLength, E>` while
|
|
85
|
+
* preserving the original array type (e.g. tuple types) via intersection.
|
|
86
|
+
* - Since `BoundedLengthArray` is the intersection of `MinLengthArray` and
|
|
87
|
+
* `MaxLengthArray`, the narrowed value is assignable to both, and both
|
|
88
|
+
* bounds can be weakened independently.
|
|
89
|
+
* - The length constraint lives only in the brand, so this stays cheap for the
|
|
90
|
+
* type checker even when the element type is large — unlike
|
|
91
|
+
* `isBoundedLengthTuple`, which narrows to a union of tuple types.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
*
|
|
95
|
+
* ```ts
|
|
96
|
+
* const input: readonly number[] = [1, 2, 3];
|
|
97
|
+
*
|
|
98
|
+
* assert.isTrue(isBoundedLengthArray(input, 1, 5));
|
|
99
|
+
*
|
|
100
|
+
* assert.isFalse(isBoundedLengthArray([], 1, 5));
|
|
101
|
+
*
|
|
102
|
+
* if (isBoundedLengthArray(input, 1, 5)) {
|
|
103
|
+
* const selection: BoundedLengthArray<1, 5, number> = input;
|
|
104
|
+
*
|
|
105
|
+
* const relaxed: BoundedLengthArray<0, 100, number> = input; // OK ([1, 5] ⊆ [0, 100])
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @template Xs - The input array type (tuple types are preserved).
|
|
110
|
+
* @template MinLength - The minimum number of elements (inclusive).
|
|
111
|
+
* @template MaxLength - The maximum number of elements (inclusive).
|
|
112
|
+
* @param xs - The array to check.
|
|
113
|
+
* @param minLength - The minimum number of elements (inclusive).
|
|
114
|
+
* @param maxLength - The maximum number of elements (inclusive).
|
|
115
|
+
* @returns `true` if `minLength <= xs.length && xs.length <= maxLength`,
|
|
116
|
+
* `false` otherwise. When `true`, TypeScript narrows `xs` to
|
|
117
|
+
* `BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs`.
|
|
118
|
+
*/
|
|
119
|
+
export declare const isBoundedLengthArray: <Xs extends readonly unknown[], MinLength extends SupportedLength, MaxLength extends SupportedLength>(xs: Xs, minLength: MinLength, maxLength: MaxLength) => xs is BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs;
|
|
120
|
+
/**
|
|
121
|
+
* Type guard that checks if an array has exactly `length` elements.
|
|
122
|
+
*
|
|
123
|
+
* **Type Narrowing Behavior:**
|
|
124
|
+
*
|
|
125
|
+
* - Narrows the input to `FixedLengthArray<Length, E>` while preserving the
|
|
126
|
+
* original array type (e.g. tuple types) via intersection.
|
|
127
|
+
* - Since `FixedLengthArray<Length, E>` is defined as
|
|
128
|
+
* `BoundedLengthArray<Length, Length, E>`, the narrowed value is assignable
|
|
129
|
+
* to any `MinLengthArray<N, E>` with `N <= Length` and any
|
|
130
|
+
* `MaxLengthArray<N, E>` with `N >= Length`.
|
|
131
|
+
* - The length constraint lives only in the brand, so this stays cheap for the
|
|
132
|
+
* type checker even when the element type is large — unlike
|
|
133
|
+
* `isFixedLengthTuple`, which narrows to a structural tuple type.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
*
|
|
137
|
+
* ```ts
|
|
138
|
+
* const input: readonly number[] = [255, 128, 0];
|
|
139
|
+
*
|
|
140
|
+
* assert.isTrue(isFixedLengthArray(input, 3));
|
|
141
|
+
*
|
|
142
|
+
* assert.isFalse(isFixedLengthArray(input, 4));
|
|
143
|
+
*
|
|
144
|
+
* if (isFixedLengthArray(input, 3)) {
|
|
145
|
+
* const rgb: FixedLengthArray<3, number> = input;
|
|
146
|
+
*
|
|
147
|
+
* const atMost5: MaxLengthArray<5, number> = input; // OK (3 <= 5)
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @template Xs - The input array type (tuple types are preserved).
|
|
152
|
+
* @template Length - The exact number of elements.
|
|
153
|
+
* @param xs - The array to check.
|
|
154
|
+
* @param length - The exact number of elements.
|
|
155
|
+
* @returns `true` if `xs.length === length`, `false` otherwise. When `true`,
|
|
156
|
+
* TypeScript narrows `xs` to `FixedLengthArray<Length, Xs[number]> & Xs`.
|
|
157
|
+
*/
|
|
158
|
+
export declare const isFixedLengthArray: <Xs extends readonly unknown[], Length extends SupportedLength>(xs: Xs, length: Length) => xs is FixedLengthArray<Length, Xs[number]> & Xs;
|
|
159
|
+
//# sourceMappingURL=is-length-bounded-array.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-length-bounded-array.d.mts","sourceRoot":"","sources":["../../src/guard/is-length-bounded-array.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,gBAAgB,GAC3B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,SAAS,SAAS,eAAe,MAE7B,EAAE,aACK,SAAS,KACnB,EAAE,IAAI,cAAc,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAA4B,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,gBAAgB,GAC3B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,SAAS,SAAS,eAAe,MAE7B,EAAE,aACK,SAAS,KACnB,EAAE,IAAI,cAAc,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAA4B,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,oBAAoB,GAC/B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,SAAS,SAAS,eAAe,EACjC,SAAS,SAAS,eAAe,MAE7B,EAAE,aACK,SAAS,aACT,SAAS,KACnB,EAAE,IAAI,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EACd,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,kBAAkB,GAC7B,EAAE,SAAS,SAAS,OAAO,EAAE,EAC7B,MAAM,SAAS,eAAe,MAE1B,EAAE,UACE,MAAM,KACb,EAAE,IAAI,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAA0B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const isMinLengthArray = (xs, minLength) => xs.length >= minLength;
|
|
2
|
+
const isMaxLengthArray = (xs, maxLength) => xs.length <= maxLength;
|
|
3
|
+
const isBoundedLengthArray = (xs, minLength, maxLength) => xs.length >= minLength && xs.length <= maxLength;
|
|
4
|
+
const isFixedLengthArray = (xs, length) => xs.length === length;
|
|
5
|
+
|
|
6
|
+
export { isBoundedLengthArray, isFixedLengthArray, isMaxLengthArray, isMinLengthArray };
|
|
7
|
+
//# sourceMappingURL=is-length-bounded-array.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-length-bounded-array.mjs","sources":["../../src/guard/is-length-bounded-array.mts"],"sourcesContent":["import {\n type BoundedLengthArray,\n type FixedLengthArray,\n type MaxLengthArray,\n type MinLengthArray,\n type SupportedLength,\n} from 'ts-type-forge';\n\n/**\n * Type guard that checks if an array has at least `minLength` elements.\n *\n * **Type Narrowing Behavior:**\n *\n * - Narrows the input to `MinLengthArray<MinLength, E>` while preserving the\n * original array type (e.g. tuple types) via intersection.\n * - The length constraint lives only in the brand, so this stays cheap for the\n * type checker even when the element type is large — unlike\n * `isMinLengthTuple`, which narrows to a structural tuple type.\n * - The result participates in the length-constraint subtyping relation: for\n * example, a value narrowed to `MinLengthArray<3, E>` is assignable to\n * `MinLengthArray<1, E>`.\n *\n * @example\n *\n * ```ts\n * const input: readonly number[] = [0, 1, 2, 3];\n *\n * assert.isTrue(isMinLengthArray(input, 3));\n *\n * assert.isFalse(isMinLengthArray([0], 3));\n *\n * if (isMinLengthArray(input, 3)) {\n * const history: MinLengthArray<3, number> = input;\n *\n * const nonEmpty: MinLengthArray<1, number> = input; // OK (3 >= 1)\n * }\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @template MinLength - The minimum number of elements (inclusive).\n * @param xs - The array to check.\n * @param minLength - The minimum number of elements (inclusive).\n * @returns `true` if `xs.length >= minLength`, `false` otherwise. When `true`,\n * TypeScript narrows `xs` to `MinLengthArray<MinLength, Xs[number]> & Xs`.\n */\nexport const isMinLengthArray = <\n Xs extends readonly unknown[],\n MinLength extends SupportedLength,\n>(\n xs: Xs,\n minLength: MinLength,\n): xs is MinLengthArray<MinLength, Xs[number]> & Xs => xs.length >= minLength;\n\n/**\n * Type guard that checks if an array has at most `maxLength` elements.\n *\n * **Type Narrowing Behavior:**\n *\n * - Narrows the input to `MaxLengthArray<MaxLength, E>` while preserving the\n * original array type (e.g. tuple types) via intersection.\n * - The length constraint lives only in the brand, so this stays cheap for the\n * type checker even when the element type is large — unlike\n * `isMaxLengthTuple`, which narrows to a union of tuple types.\n * - The result participates in the length-constraint subtyping relation: for\n * example, a value narrowed to `MaxLengthArray<8, E>` is assignable to\n * `MaxLengthArray<16, E>`.\n *\n * @example\n *\n * ```ts\n * const input: readonly string[] = ['a', 'b', 'c'];\n *\n * assert.isTrue(isMaxLengthArray(input, 8));\n *\n * assert.isFalse(isMaxLengthArray(input, 2));\n *\n * if (isMaxLengthArray(input, 8)) {\n * const tags: MaxLengthArray<8, string> = input;\n *\n * const relaxed: MaxLengthArray<16, string> = input; // OK (8 <= 16)\n * }\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @template MaxLength - The maximum number of elements (inclusive).\n * @param xs - The array to check.\n * @param maxLength - The maximum number of elements (inclusive).\n * @returns `true` if `xs.length <= maxLength`, `false` otherwise. When `true`,\n * TypeScript narrows `xs` to `MaxLengthArray<MaxLength, Xs[number]> & Xs`.\n */\nexport const isMaxLengthArray = <\n Xs extends readonly unknown[],\n MaxLength extends SupportedLength,\n>(\n xs: Xs,\n maxLength: MaxLength,\n): xs is MaxLengthArray<MaxLength, Xs[number]> & Xs => xs.length <= maxLength;\n\n/**\n * Type guard that checks if an array's length is within the inclusive range\n * `[minLength, maxLength]`.\n *\n * **Type Narrowing Behavior:**\n *\n * - Narrows the input to `BoundedLengthArray<MinLength, MaxLength, E>` while\n * preserving the original array type (e.g. tuple types) via intersection.\n * - Since `BoundedLengthArray` is the intersection of `MinLengthArray` and\n * `MaxLengthArray`, the narrowed value is assignable to both, and both\n * bounds can be weakened independently.\n * - The length constraint lives only in the brand, so this stays cheap for the\n * type checker even when the element type is large — unlike\n * `isBoundedLengthTuple`, which narrows to a union of tuple types.\n *\n * @example\n *\n * ```ts\n * const input: readonly number[] = [1, 2, 3];\n *\n * assert.isTrue(isBoundedLengthArray(input, 1, 5));\n *\n * assert.isFalse(isBoundedLengthArray([], 1, 5));\n *\n * if (isBoundedLengthArray(input, 1, 5)) {\n * const selection: BoundedLengthArray<1, 5, number> = input;\n *\n * const relaxed: BoundedLengthArray<0, 100, number> = input; // OK ([1, 5] ⊆ [0, 100])\n * }\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @template MinLength - The minimum number of elements (inclusive).\n * @template MaxLength - The maximum number of elements (inclusive).\n * @param xs - The array to check.\n * @param minLength - The minimum number of elements (inclusive).\n * @param maxLength - The maximum number of elements (inclusive).\n * @returns `true` if `minLength <= xs.length && xs.length <= maxLength`,\n * `false` otherwise. When `true`, TypeScript narrows `xs` to\n * `BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs`.\n */\nexport const isBoundedLengthArray = <\n Xs extends readonly unknown[],\n MinLength extends SupportedLength,\n MaxLength extends SupportedLength,\n>(\n xs: Xs,\n minLength: MinLength,\n maxLength: MaxLength,\n): xs is BoundedLengthArray<MinLength, MaxLength, Xs[number]> & Xs =>\n xs.length >= minLength && xs.length <= maxLength;\n\n/**\n * Type guard that checks if an array has exactly `length` elements.\n *\n * **Type Narrowing Behavior:**\n *\n * - Narrows the input to `FixedLengthArray<Length, E>` while preserving the\n * original array type (e.g. tuple types) via intersection.\n * - Since `FixedLengthArray<Length, E>` is defined as\n * `BoundedLengthArray<Length, Length, E>`, the narrowed value is assignable\n * to any `MinLengthArray<N, E>` with `N <= Length` and any\n * `MaxLengthArray<N, E>` with `N >= Length`.\n * - The length constraint lives only in the brand, so this stays cheap for the\n * type checker even when the element type is large — unlike\n * `isFixedLengthTuple`, which narrows to a structural tuple type.\n *\n * @example\n *\n * ```ts\n * const input: readonly number[] = [255, 128, 0];\n *\n * assert.isTrue(isFixedLengthArray(input, 3));\n *\n * assert.isFalse(isFixedLengthArray(input, 4));\n *\n * if (isFixedLengthArray(input, 3)) {\n * const rgb: FixedLengthArray<3, number> = input;\n *\n * const atMost5: MaxLengthArray<5, number> = input; // OK (3 <= 5)\n * }\n * ```\n *\n * @template Xs - The input array type (tuple types are preserved).\n * @template Length - The exact number of elements.\n * @param xs - The array to check.\n * @param length - The exact number of elements.\n * @returns `true` if `xs.length === length`, `false` otherwise. When `true`,\n * TypeScript narrows `xs` to `FixedLengthArray<Length, Xs[number]> & Xs`.\n */\nexport const isFixedLengthArray = <\n Xs extends readonly unknown[],\n Length extends SupportedLength,\n>(\n xs: Xs,\n length: Length,\n): xs is FixedLengthArray<Length, Xs[number]> & Xs => xs.length === length;\n"],"names":[],"mappings":"AA6CO,MAAM,gBAAA,GAAmB,CAI9B,EAAA,EACA,SAAA,KACqD,GAAG,MAAA,IAAU;AAuC7D,MAAM,gBAAA,GAAmB,CAI9B,EAAA,EACA,SAAA,KACqD,GAAG,MAAA,IAAU;AA2C7D,MAAM,oBAAA,GAAuB,CAKlC,EAAA,EACA,SAAA,EACA,cAEA,EAAA,CAAG,MAAA,IAAU,SAAA,IAAa,EAAA,CAAG,MAAA,IAAU;AAwClC,MAAM,kBAAA,GAAqB,CAIhC,EAAA,EACA,MAAA,KACoD,GAAG,MAAA,KAAW;;;;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type BoundedLengthString, type FixedLengthString, type MaxLengthString, type MinLengthString } from 'ts-type-forge';
|
|
2
|
-
import { type SizeType } from '../types.mjs';
|
|
1
|
+
import { type BoundedLengthString, type FixedLengthString, type MaxLengthString, type MinLengthString, type SupportedLength } from 'ts-type-forge';
|
|
3
2
|
/**
|
|
4
3
|
* Type guard that checks if a string has at least `minLength` characters.
|
|
5
4
|
*
|
|
@@ -38,7 +37,7 @@ import { type SizeType } from '../types.mjs';
|
|
|
38
37
|
* @returns `true` if `s.length >= minLength`, `false` otherwise. When `true`,
|
|
39
38
|
* TypeScript narrows `s` to `MinLengthString<MinLength> & S`.
|
|
40
39
|
*/
|
|
41
|
-
export declare const isMinLengthString: <S extends string, MinLength extends
|
|
40
|
+
export declare const isMinLengthString: <S extends string, MinLength extends SupportedLength>(s: S, minLength: MinLength) => s is MinLengthString<MinLength> & S;
|
|
42
41
|
/**
|
|
43
42
|
* Type guard that checks if a string has at most `maxLength` characters.
|
|
44
43
|
*
|
|
@@ -77,7 +76,7 @@ export declare const isMinLengthString: <S extends string, MinLength extends Siz
|
|
|
77
76
|
* @returns `true` if `s.length <= maxLength`, `false` otherwise. When `true`,
|
|
78
77
|
* TypeScript narrows `s` to `MaxLengthString<MaxLength> & S`.
|
|
79
78
|
*/
|
|
80
|
-
export declare const isMaxLengthString: <S extends string, MaxLength extends
|
|
79
|
+
export declare const isMaxLengthString: <S extends string, MaxLength extends SupportedLength>(s: S, maxLength: MaxLength) => s is MaxLengthString<MaxLength> & S;
|
|
81
80
|
/**
|
|
82
81
|
* Type guard that checks if a string's length is within the inclusive range
|
|
83
82
|
* `[minLength, maxLength]`.
|
|
@@ -120,7 +119,7 @@ export declare const isMaxLengthString: <S extends string, MaxLength extends Siz
|
|
|
120
119
|
* otherwise. When `true`, TypeScript narrows `s` to
|
|
121
120
|
* `BoundedLengthString<MinLength, MaxLength> & S`.
|
|
122
121
|
*/
|
|
123
|
-
export declare const isBoundedLengthString: <S extends string, MinLength extends
|
|
122
|
+
export declare const isBoundedLengthString: <S extends string, MinLength extends SupportedLength, MaxLength extends SupportedLength>(s: S, minLength: MinLength, maxLength: MaxLength) => s is BoundedLengthString<MinLength, MaxLength> & S;
|
|
124
123
|
/**
|
|
125
124
|
* Type guard that checks if a string has exactly `length` characters.
|
|
126
125
|
*
|
|
@@ -160,5 +159,5 @@ export declare const isBoundedLengthString: <S extends string, MinLength extends
|
|
|
160
159
|
* @returns `true` if `s.length === length`, `false` otherwise. When `true`,
|
|
161
160
|
* TypeScript narrows `s` to `FixedLengthString<Length> & S`.
|
|
162
161
|
*/
|
|
163
|
-
export declare const isFixedLengthString: <S extends string, Length extends
|
|
162
|
+
export declare const isFixedLengthString: <S extends string, Length extends SupportedLength>(s: S, length: Length) => s is FixedLengthString<Length> & S;
|
|
164
163
|
//# sourceMappingURL=is-length-bounded-string.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-length-bounded-string.d.mts","sourceRoot":"","sources":["../../src/guard/is-length-bounded-string.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"is-length-bounded-string.d.mts","sourceRoot":"","sources":["../../src/guard/is-length-bounded-string.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,iBAAiB,GAC5B,CAAC,SAAS,MAAM,EAChB,SAAS,SAAS,eAAe,KAE9B,CAAC,aACO,SAAS,KACnB,CAAC,IAAI,eAAe,CAAC,SAAS,CAAC,GAAG,CAA0B,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,iBAAiB,GAC5B,CAAC,SAAS,MAAM,EAChB,SAAS,SAAS,eAAe,KAE9B,CAAC,aACO,SAAS,KACnB,CAAC,IAAI,eAAe,CAAC,SAAS,CAAC,GAAG,CAA0B,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,qBAAqB,GAChC,CAAC,SAAS,MAAM,EAChB,SAAS,SAAS,eAAe,EACjC,SAAS,SAAS,eAAe,KAE9B,CAAC,aACO,SAAS,aACT,SAAS,KACnB,CAAC,IAAI,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,CACJ,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,mBAAmB,GAC9B,CAAC,SAAS,MAAM,EAChB,MAAM,SAAS,eAAe,KAE3B,CAAC,UACI,MAAM,KACb,CAAC,IAAI,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAwB,CAAC"}
|