ts-data-forge 8.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/entry-point.mjs +1 -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/functional/ternary-result/ternary-result.d.mts.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/index.d.mts +1 -0
- package/dist/guard/index.d.mts.map +1 -1
- package/dist/guard/index.mjs +1 -0
- package/dist/guard/index.mjs.map +1 -1
- package/dist/guard/is-length-bounded-string.d.mts +164 -0
- package/dist/guard/is-length-bounded-string.d.mts.map +1 -0
- package/dist/guard/is-length-bounded-string.mjs +7 -0
- package/dist/guard/is-length-bounded-string.mjs.map +1 -0
- 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 +1 -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 +17 -16
- package/src/array/impl/array-utils-transformation.mts +1 -2
- package/src/array/impl/array-utils-transformation.test.mts +3 -36
- package/src/array/impl/array-utils-validation.test.mts +1 -3
- package/src/expect-type.mts +4 -5
- package/src/functional/ternary-result/ternary-result.mts +2 -6
- package/src/guard/index.mts +1 -0
- package/src/guard/is-length-bounded-string.mts +199 -0
- package/src/guard/is-length-bounded-string.test.mts +170 -0
- package/src/number/refined-number-utils.mts +1 -9
- package/src/object/object.mts +25 -23
package/dist/number/num.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"num.mjs","sources":["../../src/number/num.mts"],"sourcesContent":[null],"names":["Result.err","Result.ok"],"mappings":";;;;AA6BA;;;;;;;;;;;;;;AAcG;IACc;AAAjB,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AK,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,KAAK;AACxC,IAAA,CAAC;AAED;;;;;;;;;AASG;;AAEU,IAAA,GAAA,CAAA,UAAU,GAAG,CAAC,GAAW,KAAU,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAQ;AAE5E;;;;;;;;;AASG;AACU,IAAA,GAAA,CAAA,KAAK,GAAG,CACnB,KAAkC,KACL;AAC7B,QAAA,MAAM,SAAS,GAAG,EAAE,IAAI,KAAK;QAE7B,OAAO,CAAC,MAAc;;QAEpB,GAAA,CAAA,UAAU,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,SAAS;AAC9C,IAAA,CAAC;AAED;;;;;;;;;;AAUG;IACU,GAAA,CAAA,gBAAgB,GAAG,CAC9B,GAAM,KAEN,MAAM,CAAC,KAAK,CAAC,GAAG;AACd,UAAE;AACF;AACG,YAAA,GAAkC;AAEzC;;;;;;;;;;AAUG;AACU,IAAA,GAAA,CAAA,SAAS,GAAG,CAAsB,CAAI;;AAEjD,KAAC,CAAC,GAAG,CAAC,CAAiB;AAEzB;;;;;;;;;;AAUG;AACU,IAAA,GAAA,CAAA,SAAS,GAAG,CAA6B,CAAI;;AAExD,KAAC,CAAC,GAAG,CAAC,CAAiB;AAC3B,CAAC,EAtqBgB,GAAG,KAAH,GAAG,GAAA,EAAA,CAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"num.mjs","sources":["../../src/number/num.mts"],"sourcesContent":["import {\n type Decrement,\n type FiniteNumber,\n type Increment,\n type Index,\n type Int,\n type Min,\n type NaNType,\n type NegativeIndex,\n type NonNegativeNumber,\n type NonZeroNumber,\n type PositiveNumber,\n type PositiveSafeIntWithSmallInt,\n type RelaxedExclude,\n type SmallInt,\n type SmallUint,\n type UnknownBrand,\n} from 'ts-type-forge';\nimport { expectType } from '../expect-type.mjs';\nimport { Result } from '../functional/index.mjs';\nimport { type SmallPositiveInt } from '../types.mjs';\nimport {\n type AddResult,\n type DivIntResult,\n type DivResult,\n type MulResult,\n type SubResult,\n} from './num-arithmetic-types.mjs';\n\n/**\n * Namespace providing utility functions for number manipulation and validation.\n *\n * This namespace offers a comprehensive set of type-safe number utilities\n * including:\n *\n * - Type conversion and validation\n * - Type guards for numeric constraints (non-zero, non-negative, positive)\n * - Range checking and clamping operations\n * - Mathematical operations with type safety\n * - Rounding utilities\n *\n * Many functions in this namespace leverage TypeScript's type system to provide\n * compile-time guarantees about numeric constraints.\n */\nexport namespace Num {\n /**\n * Converts an unknown value to a number. Alias for the `Number` constructor.\n *\n * @example\n *\n * ```ts\n * const input = '123.45';\n *\n * const result = Num.from(input);\n *\n * assert.isTrue(result === 123.45);\n * ```\n *\n * @param n The value to convert.\n * @returns The numeric representation of `n`.\n */\n export const from: (n: unknown) => number = Number;\n\n /**\n * Safely parses a base-10 integer from a string, returning a {@link Result}\n * that is `Ok<Int>` for valid input and `Err<Error>` otherwise.\n *\n * This is a stricter alternative to both `parseInt` and `Number`:\n *\n * - Unlike `parseInt('12abc', 10)` (which returns `12`), trailing\n * non-numeric characters make the whole input invalid and yield `Err`.\n * - Unlike `Number('')` / `Number(' ')` (which return `0`), empty or\n * whitespace-only input yields `Err`.\n *\n * The empty-string case is rejected by delegating to `parseInt` (which\n * returns `NaN` there) rather than hard-coding a check, while the trailing-\n * garbage case is rejected via `Number`. Valid input is truncated toward\n * zero, so `'12.9'` becomes `12` and `'-3.5'` becomes `-3`.\n *\n * Only base 10 is supported. Use `Result.unwrapOk` (optionally with a\n * `?? Number.NaN` fallback) or `Result.unwrapOkOr` to get a plain number\n * back.\n *\n * @example\n *\n * ```ts\n * assert.strictEqual(\n * Result.unwrapOkOr(Num.safeParseInt('123'), Number.NaN),\n * 123,\n * );\n *\n * assert.strictEqual(\n * Result.unwrapOkOr(Num.safeParseInt('12.9'), Number.NaN),\n * 12,\n * );\n *\n * assert.strictEqual(\n * Result.unwrapOkOr(Num.safeParseInt('-12.9'), Number.NaN),\n * -12,\n * );\n *\n * assert.strictEqual(Number.parseInt('-12.9', 10), -12);\n *\n * // Native `parseInt` ignores trailing non-numeric characters\n *\n * assert.strictEqual(Number.parseInt('123abc', 10), 123);\n *\n * assert.isTrue(Number.isNaN(Number('123abc')));\n *\n * assert.isTrue(Result.isErr(Num.safeParseInt('123abc')));\n *\n * // Whitespace is not a valid integer, so we return an error instead of coercing to 0.\n *\n * assert.isTrue(Number.isNaN(Number.parseInt(' ', 10)));\n *\n * assert.strictEqual(Number(' '), 0); // Native `Number` coerces whitespace to 0\n *\n * assert.isTrue(Result.isErr(Num.safeParseInt('')));\n *\n * assert.strictEqual(Result.unwrapOk(Num.safeParseInt(' ')), undefined);\n * ```\n *\n * @param s The string to parse.\n * @returns `Result.ok(parsedInt)` for valid input, otherwise `Result.err`\n * wrapping an `Error` describing the invalid input.\n */\n export const safeParseInt = (s: string): Result<Int, Error> => {\n const viaNumber = Number(s);\n\n // `Number('')` / `Number(' ')` は 0 を返すが、`parseInt` は NaN を返す。\n // 末尾不正文字 ('12abc' 等) は `Number` 側が NaN にするので、両者が共に\n // 有効な場合のみ採用することで空文字・空白のみ・末尾不正をまとめて弾く。\n return Number.isNaN(viaNumber) || Number.isNaN(Number.parseInt(s, 10))\n ? Result.err(\n new Error(`safeParseInt: \"${s}\" is not a valid base-10 integer`),\n )\n : // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Result.ok(Math.trunc(viaNumber) as Int);\n };\n\n /**\n * Safely parses a finite floating-point number from a string, returning a\n * {@link Result} that is `Ok<FiniteNumber>` for valid input and `Err<Error>`\n * otherwise.\n *\n * This is a stricter alternative to both `parseFloat` and `Number`:\n *\n * - Unlike `parseFloat('12abc')` (which returns `12`), trailing non-numeric\n * characters make the whole input invalid and yield `Err`.\n * - Unlike `Number('')` / `Number(' ')` (which return `0`), empty or\n * whitespace-only input yields `Err`.\n * - Unlike `Number('Infinity')` (which returns `Infinity`), non-finite values\n * yield `Err`.\n *\n * The empty-string case is rejected by delegating to `parseFloat` (which\n * returns `NaN` there) rather than hard-coding a check, while the trailing-\n * garbage case is rejected via `Number`. Decimal values are preserved as-is,\n * so `'12.9'` stays `12.9`.\n *\n * Use `Result.unwrapOk` (optionally with a `?? Number.NaN` fallback) or\n * `Result.unwrapOkOr` to get a plain number back.\n *\n * @example\n *\n * ```ts\n * assert.strictEqual(\n * Result.unwrapOkOr(Num.safeParseFloat('12.9'), Number.NaN),\n * 12.9,\n * );\n *\n * assert.strictEqual(\n * Result.unwrapOkOr(Num.safeParseFloat('-3.5'), Number.NaN),\n * -3.5,\n * );\n *\n * assert.strictEqual(\n * Result.unwrapOkOr(Num.safeParseFloat('1e3'), Number.NaN),\n * 1000,\n * );\n *\n * // Native `parseFloat` ignores trailing non-numeric characters\n *\n * assert.strictEqual(Number.parseFloat('12px'), 12);\n *\n * assert.isTrue(Result.isErr(Num.safeParseFloat('12px')));\n *\n * // Whitespace is not a valid number, so we return an error instead of coercing to 0.\n *\n * assert.isTrue(Result.isErr(Num.safeParseFloat('')));\n *\n * assert.isTrue(Result.isErr(Num.safeParseFloat(' ')));\n *\n * // Infinity and NaN are not finite, so they are rejected.\n *\n * assert.isTrue(Result.isErr(Num.safeParseFloat('Infinity')));\n *\n * assert.isTrue(Result.isErr(Num.safeParseFloat('NaN')));\n * ```\n *\n * @param s The string to parse.\n * @returns `Result.ok(parsedFloat)` for valid finite input, otherwise\n * `Result.err` wrapping an `Error` describing the invalid input.\n */\n export const safeParseFloat = (s: string): Result<FiniteNumber, Error> => {\n const viaNumber = Number(s);\n\n // `Number('')` / `Number(' ')` は 0 を返すが、`parseFloat` は NaN を返す。\n // 末尾不正文字 ('12abc' 等) は `Number` 側が NaN にするので、両者が共に\n // 非 NaN かつ有限の場合のみ採用することで空文字・空白のみ・末尾不正・\n // Infinity をまとめて弾く。\n return Number.isNaN(viaNumber) ||\n !Number.isFinite(viaNumber) ||\n Number.isNaN(Number.parseFloat(s))\n ? Result.err(\n new Error(`safeParseFloat: \"${s}\" is not a valid finite number`),\n )\n : // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Result.ok(viaNumber as FiniteNumber);\n };\n\n /**\n * Type guard that checks if a number is non-zero.\n *\n * When this function returns `true`, TypeScript narrows the type to exclude\n * zero, providing compile-time safety for division operations and other\n * calculations that require non-zero values.\n *\n * @example\n *\n * ```ts\n * const value: number = 5;\n *\n * if (Num.isNonZero(value)) {\n * // Safe to divide now that we know value is non-zero\n * // eslint-disable-next-line total-functions/no-partial-division\n * const inverted = 1 / value;\n *\n * assert.isTrue(inverted === 0.2);\n * }\n *\n * assert.isFalse(Num.isNonZero(0));\n * ```\n *\n * @template N - The numeric literal type or number type to check\n * @param num - The number to check\n * @returns `true` if the number is not zero, `false` otherwise\n */\n export const isNonZero = <N extends number>(\n num: N,\n ): num is NonZeroNumber & RelaxedExclude<N, 0> => num !== 0;\n\n expectType<NonZeroNumber & RelaxedExclude<123, 0>, UnknownBrand>('<=');\n\n /**\n * Type guard that checks if a number is non-negative (greater than or equal\n * to zero).\n *\n * When this function returns `true`, TypeScript narrows the type to exclude\n * negative values, which is useful for operations that require non-negative\n * inputs like array indices or measurements.\n *\n * @example\n *\n * ```ts\n * const candidate = 10;\n *\n * if (Num.isNonNegative(candidate)) {\n * const index: number = candidate;\n *\n * assert.isTrue(index === 10);\n * }\n *\n * assert.isFalse(Num.isNonNegative(-1));\n * ```\n *\n * @template N - The numeric literal type or number type to check\n * @param num - The number to check\n * @returns `true` if the number is >= 0, `false` otherwise\n */\n export const isNonNegative = <N extends number>(\n num: N,\n ): num is NonNegativeNumber & RelaxedExclude<N, NegativeIndex<1024>> =>\n num >= 0;\n\n /**\n * Type guard that checks if a number is positive (greater than zero).\n *\n * When this function returns `true`, TypeScript narrows the type to exclude\n * zero and negative values. This is particularly useful for validating inputs\n * that must be strictly positive, such as dimensions, counts, or rates.\n *\n * @example\n *\n * ```ts\n * const amount = 42;\n *\n * if (Num.isPositive(amount)) {\n * assert.isTrue(amount > 0);\n * }\n *\n * assert.isFalse(Num.isPositive(0));\n * ```\n *\n * @template N - The numeric literal type or number type to check\n * @param num - The number to check\n * @returns `true` if the number is > 0, `false` otherwise\n */\n export const isPositive = <N extends number>(\n num: N,\n ): num is PositiveNumber & RelaxedExclude<N, NegativeIndex<1024> | 0> =>\n num > 0;\n\n /**\n * Creates a function that checks if a number `x` is within the range\n * `lowerBound <= x < upperBound`.\n *\n * @example\n *\n * ```ts\n * const isGrade = Num.isInRange(0, 100);\n *\n * assert.isTrue(isGrade(50));\n *\n * assert.isFalse(isGrade(100));\n * ```\n *\n * @param lowerBound The lower bound (inclusive).\n * @param upperBound The upper bound (exclusive).\n * @returns A function that takes a number `x` and returns `true` if `x` is in\n * the range, `false` otherwise.\n */\n export const isInRange =\n (lowerBound: number, upperBound: number) =>\n (x: number): boolean =>\n lowerBound <= x && x < upperBound;\n\n /**\n * Creates a function that checks if a number `x` is within the range\n * `lowerBound <= x <= upperBound`.\n *\n * @example\n *\n * ```ts\n * const isPercentage = Num.isInRangeInclusive(0, 100);\n *\n * assert.isTrue(isPercentage(100));\n *\n * assert.isFalse(isPercentage(-1));\n * ```\n *\n * @param lowerBound The lower bound (inclusive).\n * @param upperBound The upper bound (inclusive).\n * @returns A function that takes a number `x` and returns `true` if `x` is in\n * the range, `false` otherwise.\n */\n export const isInRangeInclusive =\n (lowerBound: number, upperBound: number) =>\n (x: number): boolean =>\n lowerBound <= x && x <= upperBound;\n\n /**\n * @template N - A SmallUint representing the exclusive upper bound\n * @internal\n * Helper type mapping each SmallUint N to the union of integers from 0 to N-1.\n * Used internally for type-safe range operations.\n *\n * For example:\n * - LT[3] = 0 | 1 | 2\n * - LT[5] = 0 | 1 | 2 | 3 | 4\n */\n type LT = Readonly<{ [N in SmallUint]: Index<N> }>;\n\n /**\n * @template N - A SmallUint representing the inclusive upper bound\n * @internal\n * Helper type mapping each SmallUint N to the union of integers from 0 to N (inclusive).\n * Used internally for type-safe range operations with inclusive upper bounds.\n *\n * For example:\n * - LEQ[3] = 0 | 1 | 2 | 3\n * - LEQ[5] = 0 | 1 | 2 | 3 | 4 | 5\n */\n type LEQ = Readonly<{ [N in SmallUint]: Index<N> | N }>;\n\n /**\n * Creates a type guard that checks if a number is an unsigned integer within\n * a specified range.\n *\n * This function returns a predicate that validates whether a number is:\n *\n * - A safe integer (no floating point)\n * - Within the range [lowerBound, upperBound)\n *\n * The returned type guard provides precise type narrowing when the bounds are\n * SmallUint literals, making it ideal for array index validation.\n *\n * @example\n *\n * ```ts\n * const indexGuard = Num.isUintInRange(0, 5);\n *\n * assert.isTrue(indexGuard(3));\n *\n * assert.isFalse(indexGuard(5));\n *\n * assert.isFalse(indexGuard(-1));\n * ```\n *\n * @template L - The lower bound as a SmallUint literal type\n * @template U - The upper bound as a SmallUint literal type\n * @param lowerBound - The minimum value (inclusive)\n * @param upperBound - The maximum value (exclusive)\n * @returns A type guard function that validates and narrows number types\n */\n export const isUintInRange =\n <L extends SmallUint, U extends SmallUint>(lowerBound: L, upperBound: U) =>\n (x: number): x is RelaxedExclude<LT[U], LT[Min<L>]> =>\n Number.isSafeInteger(x) && lowerBound <= x && x < upperBound;\n\n /**\n * Creates a type guard that checks if a number is an unsigned integer within\n * a specified inclusive range.\n *\n * This function returns a predicate that validates whether a number is:\n *\n * - A safe integer (no floating point)\n * - Within the range [lowerBound, upperBound] (both bounds inclusive)\n *\n * The returned type guard provides precise type narrowing when the bounds are\n * SmallUint literals, useful for validating scores, percentages, or other\n * bounded values.\n *\n * @example\n *\n * ```ts\n * const inclusiveGuard = Num.isUintInRangeInclusive(0, 5);\n *\n * assert.isTrue(inclusiveGuard(5));\n *\n * assert.isFalse(inclusiveGuard(6));\n * ```\n *\n * @template L - The lower bound as a SmallUint literal type\n * @template U - The upper bound as a SmallUint literal type\n * @param lowerBound - The minimum value (inclusive)\n * @param upperBound - The maximum value (inclusive)\n * @returns A type guard function that validates and narrows number types\n */\n export const isUintInRangeInclusive =\n <L extends SmallUint, U extends SmallUint>(lowerBound: L, upperBound: U) =>\n (x: number): x is RelaxedExclude<LEQ[U], LT[Min<L>]> =>\n Number.isSafeInteger(x) && lowerBound <= x && x <= upperBound;\n\n /**\n * Clamps a value within the given range. If the target value is invalid (not\n * finite), returns the lower bound.\n *\n * Provides two usage patterns for maximum flexibility:\n *\n * - **Direct usage**: Pass all three arguments to get the clamped value\n * immediately\n * - **Curried usage**: Pass bounds to get a reusable clamping function\n *\n * @example\n *\n * ```ts\n * assert.isTrue(Num.clamp(150, 0, 100) === 100);\n *\n * assert.isTrue(Num.clamp(-50, 0, 100) === 0);\n *\n * const clampToPercentage = Num.clamp(0, 100);\n *\n * assert.isTrue(clampToPercentage(75) === 75);\n *\n * assert.isTrue(clampToPercentage(150) === 100);\n * ```\n */\n export function clamp(\n target: number,\n lowerBound: number,\n upperBound: number,\n ): number;\n\n // Curried version\n export function clamp(\n lowerBound: number,\n upperBound: number,\n ): (target: number) => number;\n\n export function clamp(\n ...args:\n | readonly [target: number, lowerBound: number, upperBound: number]\n | readonly [lowerBound: number, upperBound: number]\n ): number | ((target: number) => number) {\n switch (args.length) {\n case 3: {\n const [target, lowerBound, upperBound] = args;\n\n return !Number.isFinite(target)\n ? lowerBound\n : Math.max(lowerBound, Math.min(upperBound, target));\n }\n\n case 2: {\n const [lowerBound, upperBound] = args;\n\n return (target: number): number =>\n clamp(target, lowerBound, upperBound);\n }\n }\n }\n\n /**\n * Adds two numbers, returning the tightest sound branded result type.\n *\n * The sign of the result is computed exactly (e.g. a non-negative plus a\n * non-negative is non-negative); the integer/finite level is preserved, with\n * `SafeInt` operands widening to `Int` because the sum may exceed the safe\n * range. No clamping is performed — for a result that stays inside a bounded\n * type, use that type's branded `add` instead.\n *\n * @param a - The first addend.\n * @param b - The second addend.\n * @returns `a + b`, typed as the tightest branded type guaranteed to contain\n * it.\n */\n export const add = <A extends number, B extends number>(\n a: A,\n b: B,\n ): AddResult<A, B> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (a + b) as AddResult<A, B>;\n\n /**\n * Subtracts `b` from `a`, returning the tightest sound branded result type.\n *\n * The sign is computed exactly; the level is preserved (with `SafeInt`\n * widening to `Int`). No clamping — for saturating subtraction that stays in a\n * bounded type (e.g. `Uint.sub` clamping at `0`), use that type's branded\n * `sub`.\n *\n * @param a - The minuend.\n * @param b - The subtrahend.\n * @returns `a - b`, typed as the tightest branded type guaranteed to contain\n * it.\n */\n export const sub = <A extends number, B extends number>(\n a: A,\n b: B,\n ): SubResult<A, B> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (a - b) as SubResult<A, B>;\n\n /**\n * Multiplies two numbers, returning the tightest sound branded result type.\n *\n * The sign follows the usual product rule (e.g. negative times negative is\n * positive); the level is preserved (with `SafeInt` widening to `Int`). No\n * clamping.\n *\n * @param a - The first factor.\n * @param b - The second factor.\n * @returns `a * b`, typed as the tightest branded type guaranteed to contain\n * it.\n */\n export const mul = <A extends number, B extends number>(\n a: A,\n b: B,\n ): MulResult<A, B> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (a * b) as MulResult<A, B>;\n\n /**\n * Performs type-safe exact division with a compile-time zero-check.\n *\n * The divisor must be typed as `NonZeroNumber` or a non-zero numeric literal.\n * The result sign follows the quotient rule; because exact division can be\n * fractional, the level is `finite` (or `number`).\n *\n * @param a - The dividend.\n * @param b - The divisor (must be non-zero, enforced by types).\n * @returns `a / b`, typed as the tightest branded type guaranteed to contain\n * it.\n */\n export const div = <\n A extends number,\n B extends NonZeroNumber | SmallInt<'!=0'>,\n >(\n a: A,\n b: B,\n ): DivResult<A, B> =>\n // eslint-disable-next-line total-functions/no-partial-division, total-functions/no-unsafe-type-assertion\n (a / b) as DivResult<A, B>;\n\n /**\n * Performs integer division using floor division.\n *\n * Computes `⌊a / b⌋` by flooring both operands before division and then\n * flooring the result. This ensures integer arithmetic semantics.\n *\n * Note: Unlike `div`, this function does not enforce non-zero divisor at\n * compile time. Division by zero returns `NaN`.\n *\n * @param a - The dividend\n * @param b - The divisor\n * @returns The integer quotient, or `NaN` if b is zero\n */\n export const divInt = <\n A extends number,\n B extends NonZeroNumber | SmallInt<'!=0'>,\n >(\n a: A,\n b: B,\n ): DivIntResult<A, B> => {\n // eslint-disable-next-line total-functions/no-partial-division\n const quotient = Math.floor(Math.floor(a) / Math.floor(b));\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n return quotient as DivIntResult<A, B>;\n };\n\n /**\n * Rounds a number to a specified number of decimal places.\n *\n * Uses the standard rounding algorithm (round half up) to round the number to\n * the given precision. The precision must be a positive safe integer.\n *\n * @param num - The number to round\n * @param precision - The number of decimal places (must be positive)\n * @returns The rounded number\n */\n export const roundAt = (\n num: number,\n precision: PositiveSafeIntWithSmallInt,\n ): number => {\n const digit = 10 ** precision;\n\n // eslint-disable-next-line total-functions/no-partial-division\n return Math.round(num * digit) / digit;\n };\n\n /**\n * Rounds a number to the nearest integer using bitwise operations.\n *\n * This function uses a bitwise OR trick for potentially faster rounding.\n * Note: This implementation rounds half up for positive numbers but may\n * behave differently for negative numbers compared to Math.round.\n *\n * @param num - The number to round\n * @returns The rounded integer as an Int branded type\n */\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n export const roundToInt = (num: number): Int => Math.trunc(num + 0.5) as Int;\n\n /**\n * Creates a reusable rounding function with a fixed precision.\n *\n * This is a curried version of roundAt that returns a function configured to\n * always round to the specified number of decimal places. Useful for creating\n * consistent rounding behavior across multiple values.\n *\n * @param digit - The number of decimal places for rounding\n * @returns A function that rounds numbers to the specified precision\n */\n export const round = (\n digit: PositiveSafeIntWithSmallInt,\n ): ((num: number) => number) => {\n const powAmount = 10 ** digit;\n\n return (target: number) =>\n // eslint-disable-next-line total-functions/no-partial-division\n roundToInt(powAmount * target) / powAmount;\n };\n\n /**\n * Converts NaN values to undefined while preserving all other numbers.\n *\n * This function is useful for handling potentially invalid numeric operations\n * in a type-safe way, converting NaN results to undefined for easier handling\n * with optional chaining or nullish coalescing.\n *\n * @template N - The numeric type (literal or number)\n * @param num - The number to check\n * @returns The original number if not NaN, otherwise undefined\n */\n export const mapNaN2Undefined = <N extends number>(\n num: N,\n ): RelaxedExclude<N, NaNType> | undefined =>\n Number.isNaN(num)\n ? undefined\n : // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (num as RelaxedExclude<N, NaNType>);\n\n /**\n * Type-safe increment operation for SmallUint values.\n *\n * Increments a SmallUint (0-40) by 1 with the result type computed at compile\n * time. This provides type-level arithmetic for small unsigned integers,\n * useful for type-safe counter operations.\n *\n * @template N - A SmallUint literal type (0-40)\n * @param n - The SmallUint value to increment\n * @returns The incremented value with type Increment<N>\n */\n export const increment = <N extends SmallUint>(n: N): Increment<N> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (n + 1) as Increment<N>;\n\n /**\n * Type-safe decrement operation for positive SmallInt values.\n *\n * Decrements a positive SmallInt (1-40) by 1 with the result type computed at\n * compile time. This provides type-level arithmetic for small positive\n * integers, useful for type-safe countdown operations.\n *\n * @template N - A positive SmallInt literal type (1-40)\n * @param n - The positive SmallInt value to decrement\n * @returns The decremented value with type Decrement<N>\n */\n export const decrement = <N extends SmallPositiveInt>(n: N): Decrement<N> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n (n - 1) as Decrement<N>;\n}\n"],"names":["Num","Result.err","Result.ok"],"mappings":";;;;IA4CiB;AAAA,CAAV,CAAUA,IAAAA,KAAV;AAiBE,EAAMA,KAAA,IAAA,GAA+B,MAAA;AAiErC,EAAMA,IAAAA,CAAA,YAAA,GAAe,CAAC,CAAA,KAAkC;AAC7D,IAAA,MAAM,SAAA,GAAY,OAAO,CAAC,CAAA;AAK1B,IAAA,OAAO,MAAA,CAAO,KAAA,CAAM,SAAS,CAAA,IAAK,MAAA,CAAO,KAAA,CAAM,MAAA,CAAO,QAAA,CAAS,CAAA,EAAG,EAAE,CAAC,CAAA,GACjEC,GAAO;AAAA,MACL,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,CAAC,CAAA,gCAAA,CAAkC;AA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KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,CAAC,CAAC,CAAA;AAGzD,IAAA,OAAO,QAAA;AAAA,EAAA,CACT;AAYO,EAAMA,IAAAA,CAAA,OAAA,GAAU,CACrB,GAAA,EACA,SAAA,KACW;AACX,IAAA,MAAM,QAAQ,EAAA,IAAM,SAAA;AAGpB,IAAA,OAAO,IAAA,CAAK,KAAA,CAAM,GAAA,GAAM,KAAK,CAAA,GAAI,KAAA;AAAA,EAAA,CACnC;AAaO,EAAMA,KAAA,UAAA,GAAa,CAAC,QAAqB,IAAA,CAAK,KAAA,CAAM,MAAM,GAAG,CAAA;AAY7D,EAAMA,IAAAA,CAAA,KAAA,GAAQ,CACnB,KAAA,KAC8B;AAC9B,IAAA,MAAM,YAAY,EAAA,IAAM,KAAA;AAExB,IAAA,OAAO,CAAC,MAAA;AAAA;AAAA,MAAA,IAENA,IAAAA,CAAA,UAAA,EAAW,SAAA,GAAY,MAAM,CAAA,GAAI;AAAA,KAAA;AAAA,EAAA,CACrC;AAaO,EAAMA,KAAA,gBAAA,GAAmB,CAC9B,QAEA,MAAA,CAAO,KAAA,CAAM,GAAG,CAAA,GACZ,MAAA;AAAA;AAAA,IAEC;AAAA,GAAA;AAaA,EAAMA,IAAAA,CAAA,YAAY,CAAsB,CAAA;AAAA;AAAA,IAE5C,CAAA,GAAI;AAAA,GAAA;AAaA,EAAMA,IAAAA,CAAA,YAAY,CAA6B,CAAA;AAAA;AAAA,IAEnD,CAAA,GAAI;AAAA,GAAA;AAAA,CAAA,EArqBQ,GAAA,KAAA,GAAA,GAAA,EAAA,CAAA,CAAA;;;;"}
|
|
@@ -189,7 +189,7 @@ export declare namespace TsDataForgeInternals {
|
|
|
189
189
|
* @internal
|
|
190
190
|
*/
|
|
191
191
|
export const operatorsForInteger: <ElementType extends Int, MIN_VALUE extends number, MAX_VALUE extends number>({ integerOrSafeInteger, nonZero, MIN_VALUE, MAX_VALUE, typeNameInMessage, }: Readonly<{
|
|
192
|
-
integerOrSafeInteger:
|
|
192
|
+
integerOrSafeInteger: 'Integer' | 'SafeInteger';
|
|
193
193
|
nonZero?: boolean;
|
|
194
194
|
MIN_VALUE: MIN_VALUE;
|
|
195
195
|
MAX_VALUE: MAX_VALUE;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refined-number-utils.d.mts","sourceRoot":"","sources":["../../src/number/refined-number-utils.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,KAAK,EACV,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,GAAG,EACR,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAKvB,gBAAgB;AAChB,yBAAiB,oBAAoB,CAAC;IACpC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,UAAiB,kBAAkB,CAAC;QAclC,KAAK,kBAAkB,GAAG,eAAe,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAEhE;;;;;WAKG;QACH,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,kBAAkB,IAAI,cAAc,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAEzE,KAAK,SAAS,CAAC,CAAC,SAAS,kBAAkB,IAAI,cAAc,CAC3D,CAAC,EACD,aAAa,CACd,CAAC;QAMF,KAAK,wBAAwB,CAAC,CAAC,SAAS,GAAG,IAAI,YAAY,CACzD,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CACxB,CAAC;QAEF;;;;;WAKG;QACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,kBAAkB,IACpD,KAAK,SAAS,mBAAmB,CAAC,CAAC,CAAC,GAChC,cAAc,CAAC,C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AAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;YACvB,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;SACnC,CAAC,EACF,MAAM,CACP,GACD,QAAQ,CAAC;YACP,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;YAC1B,GAAG,EAAE,CAAC,GAAG,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC;YACpC,GAAG,EAAE,CAAC,GAAG,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC;YACpC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;YAC9B,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;SACxB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"refined-number-utils.d.mts","sourceRoot":"","sources":["../../src/number/refined-number-utils.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,KAAK,EACV,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,GAAG,EACR,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAKvB,gBAAgB;AAChB,yBAAiB,oBAAoB,CAAC;IACpC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,UAAiB,kBAAkB,CAAC;QAclC,KAAK,kBAAkB,GAAG,eAAe,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAEhE;;;;;WAKG;QACH,MAAM,MAAM,KAAK,CAAC,CAAC,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
|
|
4
4
|
|
|
5
|
-
/** @internal */
|
|
6
5
|
var TsDataForgeInternals;
|
|
7
|
-
(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
MAX_VALUE,
|
|
135
|
-
is,
|
|
136
|
-
abs,
|
|
137
|
-
min: min_,
|
|
138
|
-
max: max_,
|
|
139
|
-
pow,
|
|
140
|
-
add,
|
|
141
|
-
sub,
|
|
142
|
-
mul,
|
|
143
|
-
div,
|
|
144
|
-
random,
|
|
145
|
-
randomNonZero,
|
|
146
|
-
castType,
|
|
147
|
-
clamp:
|
|
148
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
149
|
-
clamp,
|
|
150
|
-
};
|
|
151
|
-
};
|
|
152
|
-
/**
|
|
153
|
-
* Factory function that creates a complete set of type-safe operations for
|
|
154
|
-
* floating-point types.
|
|
155
|
-
*
|
|
156
|
-
* This function generates:
|
|
157
|
-
*
|
|
158
|
-
* - Type guards and validators (checking for finite values)
|
|
159
|
-
* - Arithmetic operations that preserve type constraints
|
|
160
|
-
* - Utility functions (min, max, abs, random)
|
|
161
|
-
* - Automatic clamping for bounded types
|
|
162
|
-
*
|
|
163
|
-
* All operations ensure results remain finite and within any specified
|
|
164
|
-
* bounds. Division by zero is prevented through type constraints.
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
*
|
|
168
|
-
* ```ts
|
|
169
|
-
* const floatOps = TsDataForgeInternals.RefinedNumberUtils.operatorsForFloat<
|
|
170
|
-
* PositiveFiniteNumber,
|
|
171
|
-
* number,
|
|
172
|
-
* number
|
|
173
|
-
* >({
|
|
174
|
-
* nonZero: true,
|
|
175
|
-
* MIN_VALUE: Number.MIN_VALUE,
|
|
176
|
-
* MAX_VALUE: Number.MAX_VALUE,
|
|
177
|
-
* typeNameInMessage: 'PositiveFiniteNumber',
|
|
178
|
-
* } as const);
|
|
179
|
-
*
|
|
180
|
-
* const fortyTwo = floatOps.castType(42.5);
|
|
181
|
-
*
|
|
182
|
-
* const seven = floatOps.castType(7.5);
|
|
183
|
-
*
|
|
184
|
-
* const sum = floatOps.add(fortyTwo, seven);
|
|
185
|
-
*
|
|
186
|
-
* const ratio = floatOps.div(sum, floatOps.castType(10));
|
|
187
|
-
*
|
|
188
|
-
* const clamped = floatOps.clamp(0);
|
|
189
|
-
*
|
|
190
|
-
* const boundedRandom = floatOps.random(
|
|
191
|
-
* floatOps.castType(10),
|
|
192
|
-
* floatOps.castType(20),
|
|
193
|
-
* );
|
|
194
|
-
*
|
|
195
|
-
* const nonZeroRandom = floatOps.randomNonZero();
|
|
196
|
-
*
|
|
197
|
-
* assert.isTrue(sum === 50);
|
|
198
|
-
*
|
|
199
|
-
* assert.isTrue(ratio === 5);
|
|
200
|
-
*
|
|
201
|
-
* assert.isTrue(clamped >= Number.MIN_VALUE);
|
|
202
|
-
*
|
|
203
|
-
* assert.isTrue(boundedRandom >= 10 && boundedRandom <= 20);
|
|
204
|
-
*
|
|
205
|
-
* assert.isTrue(nonZeroRandom > 0);
|
|
206
|
-
* ```
|
|
207
|
-
*
|
|
208
|
-
* @template ElementType - The floating-point branded type
|
|
209
|
-
* @template MIN_VALUE - Optional minimum value for bounded types
|
|
210
|
-
* @template MAX_VALUE - Optional maximum value for bounded types
|
|
211
|
-
* @param config - Configuration object
|
|
212
|
-
* @param config.nonZero - If true, excludes zero from valid values
|
|
213
|
-
* @param config.MIN_VALUE - Minimum valid value (inclusive)
|
|
214
|
-
* @param config.MAX_VALUE - Maximum valid value (inclusive)
|
|
215
|
-
* @param config.typeNameInMessage - Human-readable type name for error
|
|
216
|
-
* messages
|
|
217
|
-
* @returns Object containing all type-safe operations for the
|
|
218
|
-
* floating-point type
|
|
219
|
-
* @internal
|
|
220
|
-
*/
|
|
221
|
-
RefinedNumberUtils.operatorsForFloat = ({ nonZero, MIN_VALUE, MAX_VALUE, typeNameInMessage, }) => {
|
|
222
|
-
const is = (a) => Number.isFinite(a) &&
|
|
223
|
-
(nonZero === true ? a !== 0 : true) &&
|
|
224
|
-
(isFnOrUndefined(MIN_VALUE, MAX_VALUE)?.(a) ?? true);
|
|
225
|
-
const castType = castTypeImpl(is, typeNameInMessage);
|
|
226
|
-
const clamp = pipe(clampFnOrUndefined(MIN_VALUE, MAX_VALUE)).mapNullable((cl) => (x) => castType(cl(x))).value;
|
|
227
|
-
const clampOrCastFn = clamp ?? castType;
|
|
228
|
-
const abs = (x) =>
|
|
229
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
230
|
-
Math.abs(x);
|
|
231
|
-
const min_ = (...values) => clampOrCastFn(Math.min(...values));
|
|
232
|
-
const max_ = (...values) => clampOrCastFn(Math.max(...values));
|
|
233
|
-
const pow = (x, y) => clampOrCastFn(x ** y);
|
|
234
|
-
const add = (x, y) => clampOrCastFn(x + y);
|
|
235
|
-
const sub = (x, y) => clampOrCastFn(x - y);
|
|
236
|
-
const mul = (x, y) => clampOrCastFn(x * y);
|
|
237
|
-
const div = (x, y) =>
|
|
238
|
-
// eslint-disable-next-line total-functions/no-partial-division
|
|
239
|
-
clampOrCastFn(x / y);
|
|
240
|
-
const randomImpl = (min = MIN_VALUE, max = MAX_VALUE) => min + (Math.max(max, min) - min) * Math.random();
|
|
241
|
-
const random = (min, max) => clampOrCastFn(randomImpl(min, max));
|
|
242
|
-
const randomNonZero = (min, max) => {
|
|
243
|
-
while (true) {
|
|
244
|
-
const r = random(min, max);
|
|
245
|
-
if (isNonZero(r))
|
|
246
|
-
return r;
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
return {
|
|
250
|
-
MIN_VALUE,
|
|
251
|
-
MAX_VALUE,
|
|
252
|
-
is,
|
|
253
|
-
abs,
|
|
254
|
-
min: min_,
|
|
255
|
-
max: max_,
|
|
256
|
-
pow,
|
|
257
|
-
add,
|
|
258
|
-
sub,
|
|
259
|
-
mul,
|
|
260
|
-
div,
|
|
261
|
-
random,
|
|
262
|
-
randomNonZero,
|
|
263
|
-
castType,
|
|
264
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
265
|
-
clamp: clamp,
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
})(TsDataForgeInternals.RefinedNumberUtils || (TsDataForgeInternals.RefinedNumberUtils = {}));
|
|
6
|
+
((TsDataForgeInternals2) => {
|
|
7
|
+
((RefinedNumberUtils2) => {
|
|
8
|
+
const castTypeImpl = (is, typeNameInErrorMessage) => (a) => {
|
|
9
|
+
if (!is(a)) {
|
|
10
|
+
throw new TypeError(`Expected ${typeNameInErrorMessage}, got: ${a}`);
|
|
11
|
+
}
|
|
12
|
+
return a;
|
|
13
|
+
};
|
|
14
|
+
const isNonZero = (n) => n !== 0;
|
|
15
|
+
const isFnOrUndefined = (min, max) => min === void 0 ? max === void 0 ? void 0 : (n) => n <= max : max === void 0 ? (n) => min <= n : Num.isInRangeInclusive(min, max);
|
|
16
|
+
const clampFnOrUndefined = (min, max) => min === void 0 ? max === void 0 ? void 0 : (n) => Math.min(max, n) : max === void 0 ? (n) => Math.max(min, n) : Num.clamp(min, max);
|
|
17
|
+
RefinedNumberUtils2.operatorsForInteger = ({
|
|
18
|
+
integerOrSafeInteger,
|
|
19
|
+
nonZero,
|
|
20
|
+
MIN_VALUE,
|
|
21
|
+
MAX_VALUE,
|
|
22
|
+
typeNameInMessage
|
|
23
|
+
}) => {
|
|
24
|
+
const is = (a) => (integerOrSafeInteger === "Integer" ? Number.isInteger(a) : Number.isSafeInteger(a)) && (nonZero === true ? a !== 0 : true) && (isFnOrUndefined(MIN_VALUE, MAX_VALUE)?.(a) ?? true);
|
|
25
|
+
const castType = castTypeImpl(is, typeNameInMessage);
|
|
26
|
+
const clamp = pipe(
|
|
27
|
+
clampFnOrUndefined(MIN_VALUE, MAX_VALUE)
|
|
28
|
+
).mapNullable(
|
|
29
|
+
(cl) => (x) => castType(Math.round(cl(x)))
|
|
30
|
+
).value;
|
|
31
|
+
const clampOrCastFn = clamp ?? castType;
|
|
32
|
+
const abs = (x) => (
|
|
33
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
34
|
+
Math.abs(clampOrCastFn(x))
|
|
35
|
+
);
|
|
36
|
+
const min_ = (...values) => clampOrCastFn(Math.min(...values));
|
|
37
|
+
const max_ = (...values) => clampOrCastFn(Math.max(...values));
|
|
38
|
+
const pow = (x, y) => clampOrCastFn(x ** y);
|
|
39
|
+
const add = (x, y) => clampOrCastFn(x + y);
|
|
40
|
+
const sub = (x, y) => clampOrCastFn(x - y);
|
|
41
|
+
const mul = (x, y) => clampOrCastFn(x * y);
|
|
42
|
+
const div = (x, y) => clampOrCastFn(
|
|
43
|
+
Math.floor(
|
|
44
|
+
// eslint-disable-next-line total-functions/no-partial-division
|
|
45
|
+
x / y
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
const randomImpl = (min = MIN_VALUE, max = MAX_VALUE) => min + Math.floor((Math.max(max, min) - min + 1) * Math.random());
|
|
49
|
+
const random = (min, max) => clampOrCastFn(randomImpl(min, max));
|
|
50
|
+
const randomNonZero = (min, max) => {
|
|
51
|
+
while (true) {
|
|
52
|
+
const r = randomImpl(min, max);
|
|
53
|
+
if (Num.isNonZero(r)) return clampOrCastFn(r);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
MIN_VALUE,
|
|
58
|
+
MAX_VALUE,
|
|
59
|
+
is,
|
|
60
|
+
abs,
|
|
61
|
+
min: min_,
|
|
62
|
+
max: max_,
|
|
63
|
+
pow,
|
|
64
|
+
add,
|
|
65
|
+
sub,
|
|
66
|
+
mul,
|
|
67
|
+
div,
|
|
68
|
+
random,
|
|
69
|
+
randomNonZero,
|
|
70
|
+
castType,
|
|
71
|
+
clamp: (
|
|
72
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
73
|
+
clamp
|
|
74
|
+
)
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
RefinedNumberUtils2.operatorsForFloat = ({
|
|
78
|
+
nonZero,
|
|
79
|
+
MIN_VALUE,
|
|
80
|
+
MAX_VALUE,
|
|
81
|
+
typeNameInMessage
|
|
82
|
+
}) => {
|
|
83
|
+
const is = (a) => Number.isFinite(a) && (nonZero === true ? a !== 0 : true) && (isFnOrUndefined(MIN_VALUE, MAX_VALUE)?.(a) ?? true);
|
|
84
|
+
const castType = castTypeImpl(is, typeNameInMessage);
|
|
85
|
+
const clamp = pipe(
|
|
86
|
+
clampFnOrUndefined(MIN_VALUE, MAX_VALUE)
|
|
87
|
+
).mapNullable(
|
|
88
|
+
(cl) => (x) => castType(cl(x))
|
|
89
|
+
).value;
|
|
90
|
+
const clampOrCastFn = clamp ?? castType;
|
|
91
|
+
const abs = (x) => (
|
|
92
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
93
|
+
Math.abs(x)
|
|
94
|
+
);
|
|
95
|
+
const min_ = (...values) => clampOrCastFn(Math.min(...values));
|
|
96
|
+
const max_ = (...values) => clampOrCastFn(Math.max(...values));
|
|
97
|
+
const pow = (x, y) => clampOrCastFn(x ** y);
|
|
98
|
+
const add = (x, y) => clampOrCastFn(x + y);
|
|
99
|
+
const sub = (x, y) => clampOrCastFn(x - y);
|
|
100
|
+
const mul = (x, y) => clampOrCastFn(x * y);
|
|
101
|
+
const div = (x, y) => (
|
|
102
|
+
// eslint-disable-next-line total-functions/no-partial-division
|
|
103
|
+
clampOrCastFn(x / y)
|
|
104
|
+
);
|
|
105
|
+
const randomImpl = (min = MIN_VALUE, max = MAX_VALUE) => min + (Math.max(max, min) - min) * Math.random();
|
|
106
|
+
const random = (min, max) => clampOrCastFn(randomImpl(min, max));
|
|
107
|
+
const randomNonZero = (min, max) => {
|
|
108
|
+
while (true) {
|
|
109
|
+
const r = random(min, max);
|
|
110
|
+
if (isNonZero(r)) return r;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
MIN_VALUE,
|
|
115
|
+
MAX_VALUE,
|
|
116
|
+
is,
|
|
117
|
+
abs,
|
|
118
|
+
min: min_,
|
|
119
|
+
max: max_,
|
|
120
|
+
pow,
|
|
121
|
+
add,
|
|
122
|
+
sub,
|
|
123
|
+
mul,
|
|
124
|
+
div,
|
|
125
|
+
random,
|
|
126
|
+
randomNonZero,
|
|
127
|
+
castType,
|
|
128
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
129
|
+
clamp
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
})(TsDataForgeInternals2.RefinedNumberUtils || (TsDataForgeInternals2.RefinedNumberUtils = {}));
|
|
269
133
|
})(TsDataForgeInternals || (TsDataForgeInternals = {}));
|
|
270
134
|
|
|
271
135
|
export { TsDataForgeInternals };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refined-number-utils.mjs","sources":["../../src/number/refined-number-utils.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAoBA;IACiB;AAAjB,CAAA,UAAiB,oBAAoB,EAAA;AAuBnC,IAAA,CAAA,UAAiB,kBAAkB,EAAA;AACjC,QAAA,MAAM,YAAY,GAChB,CACE,EAAmC,EACnC,sBAA8B,KAEhC,CAAmB,CAAI,KAAqB;AAC1C,YAAA,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;gBACV,MAAM,IAAI,SAAS,CAAC,CAAA,SAAA,EAAY,sBAAsB,CAAA,OAAA,EAAU,CAAC,CAAA,CAAE,CAAC;;AAGtE,YAAA,OAAO,CAAC;AACV,QAAA,CAAC;QAiBH,MAAM,SAAS,GAAG,CAChB,CAAI,KACsB,CAAC,KAAK,CA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C,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE;AAE7D,YAAA,MAAM,MAAM,GAAG,CAAC,GAAiB,EAAE,GAAiB,KAClD,aAAa,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAErC,YAAA,MAAM,aAAa,GAAG,CACpB,GAAiB,EACjB,GAAiB,KACF;gBACf,OAAO,IAAI,EAAE;oBACX,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC;oBAE1B,IAAI,SAAS,CAAC,CAAC,CAAC;AAAE,wBAAA,OAAO,CAAC;;AAE9B,YAAA,CAAC;YAED,OAAO;gBACL,SAAS;gBACT,SAAS;gBACT,EAAE;gBACF,GAAG;AACH,gBAAA,GAAG,EAAE,IAAI;AACT,gBAAA,GAAG,EAAE,IAAI;gBACT,GAAG;gBACH,GAAG;gBACH,GAAG;gBACH,GAAG;gBACH,GAAG;gBACH,MAAM;gBACN,aAAa;gBACb,QAAQ;;AAGR,gBAAA,KAAK,EAAE,KAEuB;aACtB;AACZ,QAAA,CAAC;AACH,IAAA,CAAC,EAlpBgB,oBAAA,CAAA,kBAAkB,KAAlB,uCAAkB,GAAA,EAAA,CAAA,CAAA;AAmpBrC,CAAC,EA1qBgB,oBAAoB,KAApB,oBAAoB,GAAA,EAAA,CAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"refined-number-utils.mjs","sources":["../../src/number/refined-number-utils.mts"],"sourcesContent":["import {\n type Brand,\n type ChangeBaseBrand,\n type GetBrandValuePart,\n type Int,\n type IntersectBrand,\n type NonNegativeNumber,\n type NonZeroNumber,\n type PositiveNumber,\n type RelaxedExclude,\n type TypeEq,\n type UnknownBrand,\n type UnwrapBrandFalseKeys,\n type UnwrapBrandTrueKeys,\n type WithSmallInt,\n} from 'ts-type-forge';\nimport { expectType } from '../expect-type.mjs';\nimport { pipe } from '../functional/index.mjs';\nimport { Num } from './num.mjs';\n\n/** @internal */\nexport namespace TsDataForgeInternals {\n /**\n * Internal utilities for creating and managing refined (branded) number\n * types.\n *\n * This namespace provides factory functions and type utilities for building\n * type-safe numeric operations with compile-time constraints. It serves as\n * the foundation for all branded number types in the library, including:\n *\n * - Integer types (Int, SafeInt, Int8, Int16, Int32)\n * - Unsigned types (UInt, UInt8, UInt16, UInt32)\n * - Constrained types (NonZero, NonNegative, Positive)\n * - Range-bounded types\n *\n * The utilities handle:\n *\n * - Type validation and narrowing\n * - Arithmetic operations that preserve type constraints\n * - Automatic clamping for bounded types\n * - Random number generation within type bounds\n *\n * @internal This namespace is not part of the public API\n */\n export namespace RefinedNumberUtils {\n const castTypeImpl =\n <BrandedType extends number>(\n is: (n: number) => n is BrandedType,\n typeNameInErrorMessage: string,\n ) =>\n <N extends number>(a: N): BrandedType & N => {\n if (!is(a)) {\n throw new TypeError(`Expected ${typeNameInErrorMessage}, got: ${a}`);\n }\n\n return a;\n };\n\n type UnknownNumberBrand = ChangeBaseBrand<UnknownBrand, number>;\n\n /**\n * Converts a branded number type to include the Int brand.\n *\n * @template N - A branded number type\n * @internal\n */\n export type ToInt<N extends UnknownNumberBrand> = IntersectBrand<N, Int>;\n\n type ToNonZero<N extends UnknownNumberBrand> = IntersectBrand<\n N,\n NonZeroNumber\n >;\n\n const isNonZero = <N extends UnknownNumberBrand>(\n n: N,\n ): n is N & ToNonZero<N> => n !== 0;\n\n type ToNonZeroIntWithSmallInt<N extends Int> = WithSmallInt<\n CastToInt<ToNonZero<N>>\n >;\n\n /**\n * Converts a branded number type to include the NonNegativeNumber brand.\n *\n * @template N - A branded number type\n * @internal\n */\n export type ToNonNegative<N extends UnknownNumberBrand> =\n '!=0' extends UnwrapBrandTrueKeys<N>\n ? IntersectBrand<N, PositiveNumber>\n : IntersectBrand<N, NonNegativeNumber>;\n\n /**\n * Removes the non-zero brand constraint from a branded number type. Used\n * when operations may produce zero values.\n *\n * @template N - A branded number type\n * @internal\n */\n export type RemoveNonZeroBrandKey<N extends UnknownNumberBrand> = Brand<\n GetBrandValuePart<N>,\n RelaxedExclude<UnwrapBrandTrueKeys<N>, '!=0'> & string,\n RelaxedExclude<UnwrapBrandFalseKeys<N>, '<=0' | '>=0'> & string\n >;\n\n type CastToInt<N> = N extends Int ? N : never;\n\n /**\n * Generates a type-safe API for a branded number type based on its\n * characteristics.\n *\n * This type dynamically constructs an object type with appropriate methods\n * based on the number class. For example:\n *\n * - Integer types don't get floor/ceil/round methods\n * - Non-negative types don't get abs method\n * - Range-bounded types get MIN_VALUE/MAX_VALUE constants\n *\n * @template N - The branded number type\n * @template classes - Union of characteristics: 'int' | 'non-negative' |\n * 'positive' | 'range'\n * @internal\n */\n /** The closed binary arithmetic operations a branded namespace may expose. */\n export type NumberClassBinOp = 'add' | 'div' | 'mul' | 'sub';\n\n export type NumberClass<\n N extends UnknownNumberBrand,\n classes extends 'int' | 'non-negative' | 'positive' | 'range',\n binOps extends NumberClassBinOp = NumberClassBinOp,\n > = ('int' extends classes\n ? unknown\n : 'positive' extends classes\n ? Readonly<{\n floor: (x: N, y: N) => RemoveNonZeroBrandKey<ToInt<N>>;\n ceil: (x: N, y: N) => ToInt<N>;\n round: (x: N, y: N) => RemoveNonZeroBrandKey<ToInt<N>>;\n }>\n : Readonly<{\n floor: (x: N, y: N) => ToInt<N>;\n ceil: (x: N, y: N) => ToInt<N>;\n round: (x: N, y: N) => ToInt<N>;\n }>) &\n ('non-negative' extends classes\n ? Readonly<{\n MIN_VALUE: number;\n clamp: (a: number) => N;\n }>\n : unknown) &\n ('non-negative' extends classes\n ? unknown\n : 'positive' extends classes\n ? unknown\n : Readonly<{\n abs: (x: N) => ToNonNegative<N>;\n }>) &\n ('positive' extends classes\n ? Readonly<{\n MIN_VALUE: number;\n clamp: (a: number) => N;\n }>\n : unknown) &\n ('range' extends classes\n ? Readonly<{\n MIN_VALUE: number;\n MAX_VALUE: number;\n clamp: (a: number) => N;\n }>\n : unknown) &\n Pick<\n Readonly<{\n add: (x: N, y: N) => N;\n sub: (x: N, y: N) => N;\n mul: (x: N, y: N) => N;\n div: (x: N, y: ToNonZero<N>) => N;\n }>,\n binOps\n > &\n Readonly<{\n is: (a: number) => a is N;\n min: (...values: readonly N[]) => N;\n max: (...values: readonly N[]) => N;\n random: (min: N, max: N) => N;\n pow: (x: N, y: N) => N;\n }>;\n\n type BaseKeys =\n 'add' | 'div' | 'is' | 'max' | 'min' | 'mul' | 'pow' | 'random' | 'sub';\n\n type FloatMethods = 'ceil' | 'floor' | 'round';\n\n expectType<keyof NumberClass<UnknownNumberBrand, 'int'>, BaseKeys | 'abs'>(\n '=',\n );\n\n expectType<\n keyof NumberClass<UnknownNumberBrand, never>,\n BaseKeys | FloatMethods | 'abs'\n >('=');\n\n expectType<\n keyof NumberClass<UnknownNumberBrand, 'non-negative'>,\n BaseKeys | FloatMethods | 'clamp' | 'MIN_VALUE'\n >('=');\n\n expectType<\n keyof NumberClass<UnknownNumberBrand, 'positive'>,\n BaseKeys | FloatMethods | 'clamp' | 'MIN_VALUE'\n >('=');\n\n expectType<\n keyof NumberClass<UnknownNumberBrand, 'int' | 'range'>,\n BaseKeys | 'abs' | 'clamp' | 'MAX_VALUE' | 'MIN_VALUE'\n >('=');\n\n const isFnOrUndefined = (\n min: number | undefined,\n max: number | undefined,\n ): ((n: number) => boolean) | undefined =>\n min === undefined\n ? max === undefined\n ? undefined\n : (n) => n <= max\n : max === undefined\n ? (n) => min <= n\n : Num.isInRangeInclusive(min, max);\n\n const clampFnOrUndefined = (\n min: number | undefined,\n max: number | undefined,\n ): ((n: number) => number) | undefined =>\n min === undefined\n ? max === undefined\n ? undefined\n : (n) => Math.min(max, n)\n : max === undefined\n ? (n) => Math.max(min, n)\n : Num.clamp(min, max);\n\n type OperatorsForInteger<\n ElementType extends Int,\n MIN_VALUE extends number,\n MAX_VALUE extends number,\n ElementTypeWithSmallInt extends WithSmallInt<ElementType> =\n WithSmallInt<ElementType>,\n > = Readonly<{\n MIN_VALUE: MIN_VALUE;\n MAX_VALUE: MAX_VALUE;\n\n is: (a: number) => a is ElementType;\n\n abs: (x: ElementTypeWithSmallInt) => ToNonNegative<ElementType>;\n\n min: (...values: readonly ElementTypeWithSmallInt[]) => ElementType;\n\n max: (...values: readonly ElementTypeWithSmallInt[]) => ElementType;\n\n pow: (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ) => ElementType;\n\n add: (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ) => ElementType;\n\n sub: (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ) => ElementType;\n\n mul: (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ) => ElementType;\n\n div: (\n x: ElementTypeWithSmallInt,\n y: ToNonZeroIntWithSmallInt<ElementType>,\n ) => ElementType;\n\n random: (\n min?: ElementTypeWithSmallInt,\n max?: ElementTypeWithSmallInt,\n ) => ElementType;\n\n randomNonZero: (\n min?: ElementTypeWithSmallInt,\n max?: ElementTypeWithSmallInt,\n ) => ElementType;\n\n castType: <N extends number>(x: N) => ElementType & N;\n\n clamp: TypeEq<MAX_VALUE | MIN_VALUE, undefined> extends true\n ? undefined\n : (x: number) => ElementType;\n }>;\n\n /**\n * Factory function that creates a complete set of type-safe operations for\n * integer types.\n *\n * This function generates:\n *\n * - Type guards and validators\n * - Arithmetic operations that preserve type constraints\n * - Utility functions (min, max, abs, random)\n * - Automatic clamping for bounded types\n *\n * All operations ensure results remain within the type's constraints, using\n * clamping when bounds are specified.\n *\n * @example\n *\n * ```ts\n * const intOps = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger<\n * SafeInt,\n * number,\n * number\n * >({\n * integerOrSafeInteger: 'SafeInteger',\n * MIN_VALUE: Number.MIN_SAFE_INTEGER,\n * MAX_VALUE: Number.MAX_SAFE_INTEGER,\n * typeNameInMessage: 'SafeInt',\n * } as const);\n *\n * const six = intOps.castType(6);\n *\n * const four = intOps.castType(4);\n *\n * const sum = intOps.add(six, four);\n *\n * const difference = intOps.sub(six, four);\n *\n * const product = intOps.mul(six, four);\n *\n * const quotient = intOps.div(six, intOps.castType(2));\n *\n * const roundedClamp = intOps.clamp(1.5);\n *\n * const randomValue = intOps.random();\n *\n * assert.isTrue(sum === 10);\n *\n * assert.isTrue(difference === 2);\n *\n * assert.isTrue(product === 24);\n *\n * assert.isTrue(quotient === 3);\n *\n * assert.isTrue(roundedClamp === 2);\n *\n * assert.isTrue(Number.isSafeInteger(randomValue));\n * ```\n *\n * @template ElementType - The integer branded type\n * @template MIN_VALUE - Optional minimum value for bounded types\n * @template MAX_VALUE - Optional maximum value for bounded types\n * @param config - Configuration object\n * @param config.integerOrSafeInteger - Whether to use Number.isInteger or\n * Number.isSafeInteger\n * @param config.nonZero - If true, excludes zero from valid values\n * @param config.MIN_VALUE - Minimum valid value (inclusive)\n * @param config.MAX_VALUE - Maximum valid value (inclusive)\n * @param config.typeNameInMessage - Human-readable type name for error\n * messages\n * @returns Object containing all type-safe operations for the integer type\n * @internal\n */\n export const operatorsForInteger = <\n ElementType extends Int,\n MIN_VALUE extends number,\n MAX_VALUE extends number,\n >({\n integerOrSafeInteger,\n nonZero,\n MIN_VALUE,\n MAX_VALUE,\n typeNameInMessage,\n }: Readonly<{\n integerOrSafeInteger: 'Integer' | 'SafeInteger';\n nonZero?: boolean;\n MIN_VALUE: MIN_VALUE;\n MAX_VALUE: MAX_VALUE;\n typeNameInMessage: string;\n }>): OperatorsForInteger<ElementType, MIN_VALUE, MAX_VALUE> => {\n type ElementTypeWithSmallInt = WithSmallInt<ElementType>;\n\n const is = (a: number): a is ElementType =>\n (integerOrSafeInteger === 'Integer'\n ? Number.isInteger(a)\n : Number.isSafeInteger(a)) &&\n (nonZero === true ? a !== 0 : true) &&\n (isFnOrUndefined(MIN_VALUE, MAX_VALUE)?.(a) ?? true);\n\n const castType = castTypeImpl<ElementType>(is, typeNameInMessage);\n\n const clamp: ((a: number) => ElementType) | undefined = pipe(\n clampFnOrUndefined(MIN_VALUE, MAX_VALUE),\n ).mapNullable(\n (cl) =>\n (x: number): ElementType =>\n castType(Math.round(cl(x))),\n ).value;\n\n const clampOrCastFn: (a: number) => ElementType = clamp ?? castType;\n\n const abs = (x: ElementTypeWithSmallInt): ToNonNegative<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.abs(clampOrCastFn(x)) as ToNonNegative<ElementType>;\n\n const min_ = (\n ...values: readonly ElementTypeWithSmallInt[]\n ): ElementType => clampOrCastFn(Math.min(...values));\n\n const max_ = (\n ...values: readonly ElementTypeWithSmallInt[]\n ): ElementType => clampOrCastFn(Math.max(...values));\n\n const pow = (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(x ** y);\n\n const add = (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(x + y);\n\n const sub = (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(x - y);\n\n const mul = (\n x: ElementTypeWithSmallInt,\n y: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(x * y);\n\n const div = (\n x: ElementTypeWithSmallInt,\n y: ToNonZeroIntWithSmallInt<ElementType>,\n ): ElementType =>\n clampOrCastFn(\n Math.floor(\n // eslint-disable-next-line total-functions/no-partial-division\n x / y,\n ),\n );\n\n const randomImpl = (\n min: number = MIN_VALUE,\n max: number = MAX_VALUE,\n ): number =>\n min + Math.floor((Math.max(max, min) - min + 1) * Math.random());\n\n // [-5, 5] -> floor(11 * Math.random()) + (-5)\n const random = (\n min?: ElementTypeWithSmallInt,\n max?: ElementTypeWithSmallInt,\n ): ElementType => clampOrCastFn(randomImpl(min, max));\n\n const randomNonZero = (\n min?: ElementTypeWithSmallInt,\n max?: ElementTypeWithSmallInt,\n ): ElementType => {\n while (true) {\n const r = randomImpl(min, max);\n\n if (Num.isNonZero(r)) return clampOrCastFn(r);\n }\n };\n\n return {\n MIN_VALUE,\n MAX_VALUE,\n is,\n abs,\n min: min_,\n max: max_,\n pow,\n add,\n sub,\n mul,\n div,\n random,\n randomNonZero,\n castType,\n\n clamp:\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n clamp as TypeEq<MAX_VALUE | MIN_VALUE, undefined> extends true\n ? undefined\n : (x: number) => ElementType,\n } as const;\n };\n\n type OperatorsForFloat<\n ElementType extends UnknownNumberBrand,\n MIN_VALUE extends number | undefined,\n MAX_VALUE extends number | undefined,\n > = Readonly<{\n MIN_VALUE: MIN_VALUE;\n MAX_VALUE: MAX_VALUE;\n\n is: (a: number) => a is ElementType;\n\n abs: (x: ElementType) => ToNonNegative<ElementType>;\n min: (...values: readonly ElementType[]) => ElementType;\n max: (...values: readonly ElementType[]) => ElementType;\n pow: (x: ElementType, y: ElementType) => ElementType;\n add: (x: ElementType, y: ElementType) => ElementType;\n sub: (x: ElementType, y: ElementType) => ElementType;\n mul: (x: ElementType, y: ElementType) => ElementType;\n div: (x: ElementType, y: ToNonZero<ElementType>) => ElementType;\n random: (min?: ElementType, max?: ElementType) => ElementType;\n randomNonZero: (min?: ElementType, max?: ElementType) => ElementType;\n\n castType: <N extends number>(x: N) => ElementType & N;\n\n clamp: TypeEq<MAX_VALUE | MIN_VALUE, undefined> extends true\n ? undefined\n : (x: number) => ElementType;\n }>;\n\n /**\n * Factory function that creates a complete set of type-safe operations for\n * floating-point types.\n *\n * This function generates:\n *\n * - Type guards and validators (checking for finite values)\n * - Arithmetic operations that preserve type constraints\n * - Utility functions (min, max, abs, random)\n * - Automatic clamping for bounded types\n *\n * All operations ensure results remain finite and within any specified\n * bounds. Division by zero is prevented through type constraints.\n *\n * @example\n *\n * ```ts\n * const floatOps = TsDataForgeInternals.RefinedNumberUtils.operatorsForFloat<\n * PositiveFiniteNumber,\n * number,\n * number\n * >({\n * nonZero: true,\n * MIN_VALUE: Number.MIN_VALUE,\n * MAX_VALUE: Number.MAX_VALUE,\n * typeNameInMessage: 'PositiveFiniteNumber',\n * } as const);\n *\n * const fortyTwo = floatOps.castType(42.5);\n *\n * const seven = floatOps.castType(7.5);\n *\n * const sum = floatOps.add(fortyTwo, seven);\n *\n * const ratio = floatOps.div(sum, floatOps.castType(10));\n *\n * const clamped = floatOps.clamp(0);\n *\n * const boundedRandom = floatOps.random(\n * floatOps.castType(10),\n * floatOps.castType(20),\n * );\n *\n * const nonZeroRandom = floatOps.randomNonZero();\n *\n * assert.isTrue(sum === 50);\n *\n * assert.isTrue(ratio === 5);\n *\n * assert.isTrue(clamped >= Number.MIN_VALUE);\n *\n * assert.isTrue(boundedRandom >= 10 && boundedRandom <= 20);\n *\n * assert.isTrue(nonZeroRandom > 0);\n * ```\n *\n * @template ElementType - The floating-point branded type\n * @template MIN_VALUE - Optional minimum value for bounded types\n * @template MAX_VALUE - Optional maximum value for bounded types\n * @param config - Configuration object\n * @param config.nonZero - If true, excludes zero from valid values\n * @param config.MIN_VALUE - Minimum valid value (inclusive)\n * @param config.MAX_VALUE - Maximum valid value (inclusive)\n * @param config.typeNameInMessage - Human-readable type name for error\n * messages\n * @returns Object containing all type-safe operations for the\n * floating-point type\n * @internal\n */\n export const operatorsForFloat = <\n ElementType extends UnknownNumberBrand,\n MIN_VALUE extends number,\n MAX_VALUE extends number,\n >({\n nonZero,\n MIN_VALUE,\n MAX_VALUE,\n typeNameInMessage,\n }: Readonly<{\n nonZero?: boolean;\n MIN_VALUE: MIN_VALUE;\n MAX_VALUE: MAX_VALUE;\n typeNameInMessage: string;\n }>): OperatorsForFloat<ElementType, MIN_VALUE, MAX_VALUE> => {\n const is = (a: number): a is ElementType =>\n Number.isFinite(a) &&\n (nonZero === true ? a !== 0 : true) &&\n (isFnOrUndefined(MIN_VALUE, MAX_VALUE)?.(a) ?? true);\n\n const castType = castTypeImpl<ElementType>(is, typeNameInMessage);\n\n const clamp: ((a: number) => ElementType) | undefined = pipe(\n clampFnOrUndefined(MIN_VALUE, MAX_VALUE),\n ).mapNullable(\n (cl) =>\n (x: number): ElementType =>\n castType(cl(x)),\n ).value;\n\n const clampOrCastFn: (a: number) => ElementType = clamp ?? castType;\n\n const abs = (x: ElementType): ToNonNegative<ElementType> =>\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n Math.abs(x) as ToNonNegative<ElementType>;\n\n const min_ = (...values: readonly ElementType[]): ElementType =>\n clampOrCastFn(Math.min(...values));\n\n const max_ = (...values: readonly ElementType[]): ElementType =>\n clampOrCastFn(Math.max(...values));\n\n const pow = (x: ElementType, y: ElementType): ElementType =>\n clampOrCastFn(x ** y);\n\n const add = (x: ElementType, y: ElementType): ElementType =>\n clampOrCastFn(x + y);\n\n const sub = (x: ElementType, y: ElementType): ElementType =>\n clampOrCastFn(x - y);\n\n const mul = (x: ElementType, y: ElementType): ElementType =>\n clampOrCastFn(x * y);\n\n const div = (x: ElementType, y: ToNonZero<ElementType>): ElementType =>\n // eslint-disable-next-line total-functions/no-partial-division\n clampOrCastFn(x / y);\n\n const randomImpl = (\n min: number = MIN_VALUE,\n max: number = MAX_VALUE,\n ): number => min + (Math.max(max, min) - min) * Math.random();\n\n const random = (min?: ElementType, max?: ElementType): ElementType =>\n clampOrCastFn(randomImpl(min, max));\n\n const randomNonZero = (\n min?: ElementType,\n max?: ElementType,\n ): ElementType => {\n while (true) {\n const r = random(min, max);\n\n if (isNonZero(r)) return r;\n }\n };\n\n return {\n MIN_VALUE,\n MAX_VALUE,\n is,\n abs,\n min: min_,\n max: max_,\n pow,\n add,\n sub,\n mul,\n div,\n random,\n randomNonZero,\n castType,\n\n // eslint-disable-next-line total-functions/no-unsafe-type-assertion\n clamp: clamp as TypeEq<MAX_VALUE | MIN_VALUE, undefined> extends true\n ? undefined\n : (x: number) => ElementType,\n } as const;\n };\n }\n}\n"],"names":["TsDataForgeInternals","RefinedNumberUtils"],"mappings":";;;;IAqBiB;AAAA,CAAV,CAAUA,qBAAAA,KAAV;AAuBE,EAAA,CAAA,CAAUC,mBAAAA,KAAV;AACL,IAAA,MAAM,YA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