ts-data-forge 3.3.0 → 3.3.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/README.md +37 -13
- package/dist/array/impl/array-utils-creation.d.mts +116 -0
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -0
- package/dist/array/impl/array-utils-creation.mjs +110 -0
- package/dist/array/impl/array-utils-creation.mjs.map +1 -0
- package/dist/array/impl/array-utils-element-access.d.mts +61 -0
- package/dist/array/impl/array-utils-element-access.d.mts.map +1 -0
- package/dist/array/impl/array-utils-element-access.mjs +66 -0
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -0
- package/dist/array/impl/array-utils-iterators.d.mts +59 -0
- package/dist/array/impl/array-utils-iterators.d.mts.map +1 -0
- package/dist/array/impl/array-utils-iterators.mjs +104 -0
- package/dist/array/impl/array-utils-iterators.mjs.map +1 -0
- package/dist/array/impl/array-utils-modification.d.mts +154 -0
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -0
- package/dist/array/impl/array-utils-modification.mjs +139 -0
- package/dist/array/impl/array-utils-modification.mjs.map +1 -0
- package/dist/array/impl/array-utils-reducing-value.d.mts +214 -0
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -0
- package/dist/array/impl/array-utils-reducing-value.mjs +160 -0
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -0
- package/dist/array/impl/array-utils-search.d.mts +179 -0
- package/dist/array/impl/array-utils-search.d.mts.map +1 -0
- package/dist/array/impl/array-utils-search.mjs +153 -0
- package/dist/array/impl/array-utils-search.mjs.map +1 -0
- package/dist/array/impl/array-utils-set-op.d.mts +100 -0
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -0
- package/dist/array/impl/array-utils-set-op.mjs +137 -0
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -0
- package/dist/array/impl/array-utils-size.d.mts +24 -0
- package/dist/array/impl/array-utils-size.d.mts.map +1 -0
- package/dist/array/impl/array-utils-size.mjs +28 -0
- package/dist/array/impl/array-utils-size.mjs.map +1 -0
- package/dist/array/impl/array-utils-slice-clamped.d.mts +18 -0
- package/dist/array/impl/array-utils-slice-clamped.d.mts.map +1 -0
- package/dist/array/impl/array-utils-slice-clamped.mjs +49 -0
- package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -0
- package/dist/array/impl/array-utils-slicing.d.mts +120 -0
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -0
- package/dist/array/impl/array-utils-slicing.mjs +140 -0
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -0
- package/dist/array/impl/array-utils-transformation.d.mts +348 -0
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -0
- package/dist/array/impl/array-utils-transformation.mjs +331 -0
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -0
- package/dist/array/impl/array-utils-validation.d.mts +149 -0
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -0
- package/dist/array/impl/array-utils-validation.mjs +166 -0
- package/dist/array/impl/array-utils-validation.mjs.map +1 -0
- package/dist/array/impl/index.d.mts +13 -0
- package/dist/array/impl/index.d.mts.map +1 -0
- package/dist/array/impl/index.mjs +13 -0
- package/dist/array/impl/index.mjs.map +1 -0
- package/dist/array/index.d.mts +1 -1
- package/dist/array/index.d.mts.map +1 -1
- package/dist/array/index.mjs +2 -1
- package/dist/array/index.mjs.map +1 -1
- package/dist/collections/imap-mapped.d.mts +83 -253
- package/dist/collections/imap-mapped.d.mts.map +1 -1
- package/dist/collections/imap-mapped.mjs +33 -164
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +436 -163
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +74 -94
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +828 -345
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +200 -242
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +397 -205
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +102 -184
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.d.mts +155 -135
- package/dist/collections/queue.d.mts.map +1 -1
- package/dist/collections/queue.mjs +55 -156
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.d.mts +154 -154
- package/dist/collections/stack.d.mts.map +1 -1
- package/dist/collections/stack.mjs +54 -203
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/entry-point.d.mts +1 -0
- package/dist/entry-point.d.mts.map +1 -1
- package/dist/entry-point.mjs +2 -1
- package/dist/entry-point.mjs.map +1 -1
- package/dist/expect-type.d.mts +43 -172
- package/dist/expect-type.d.mts.map +1 -1
- package/dist/expect-type.mjs +43 -172
- package/dist/expect-type.mjs.map +1 -1
- package/dist/functional/match.d.mts +35 -140
- package/dist/functional/match.d.mts.map +1 -1
- package/dist/functional/match.mjs.map +1 -1
- package/dist/functional/optional.d.mts +282 -160
- package/dist/functional/optional.d.mts.map +1 -1
- package/dist/functional/optional.mjs +131 -71
- package/dist/functional/optional.mjs.map +1 -1
- package/dist/functional/pipe.d.mts +59 -113
- package/dist/functional/pipe.d.mts.map +1 -1
- package/dist/functional/pipe.mjs.map +1 -1
- package/dist/functional/result.d.mts +433 -332
- package/dist/functional/result.d.mts.map +1 -1
- package/dist/functional/result.mjs +233 -239
- package/dist/functional/result.mjs.map +1 -1
- package/dist/globals.d.mts +12 -5
- package/dist/guard/has-key.d.mts +23 -74
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +23 -74
- package/dist/guard/has-key.mjs.map +1 -1
- package/dist/guard/is-non-empty-string.d.mts +20 -87
- package/dist/guard/is-non-empty-string.d.mts.map +1 -1
- package/dist/guard/is-non-empty-string.mjs +20 -87
- package/dist/guard/is-non-empty-string.mjs.map +1 -1
- package/dist/guard/is-non-null-object.d.mts +14 -84
- package/dist/guard/is-non-null-object.d.mts.map +1 -1
- package/dist/guard/is-non-null-object.mjs +14 -84
- package/dist/guard/is-non-null-object.mjs.map +1 -1
- package/dist/guard/is-primitive.d.mts +13 -126
- package/dist/guard/is-primitive.d.mts.map +1 -1
- package/dist/guard/is-primitive.mjs +13 -126
- package/dist/guard/is-primitive.mjs.map +1 -1
- package/dist/guard/is-record.d.mts +21 -132
- package/dist/guard/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +21 -132
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/is-type.d.mts +201 -238
- package/dist/guard/is-type.d.mts.map +1 -1
- package/dist/guard/is-type.mjs +201 -238
- package/dist/guard/is-type.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts +22 -139
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +22 -139
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/iterator/range.d.mts +29 -62
- package/dist/iterator/range.d.mts.map +1 -1
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/json.d.mts +191 -121
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +238 -136
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/finite-number.d.mts +24 -156
- package/dist/number/branded-types/finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/finite-number.mjs +27 -159
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +122 -120
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +122 -120
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.d.mts +22 -30
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int16.mjs +22 -30
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +22 -31
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/int32.mjs +22 -31
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +28 -36
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +31 -39
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +24 -34
- package/dist/number/branded-types/non-negative-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +24 -34
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +26 -35
- package/dist/number/branded-types/non-negative-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +26 -35
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +22 -37
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.mjs +25 -40
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts +15 -30
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int.mjs +15 -30
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +27 -35
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +27 -35
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +29 -36
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +29 -36
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +37 -38
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +39 -40
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +24 -35
- package/dist/number/branded-types/non-zero-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +24 -35
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +24 -35
- package/dist/number/branded-types/non-zero-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +24 -35
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +26 -40
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +29 -43
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +133 -123
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +133 -123
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +24 -35
- package/dist/number/branded-types/positive-int16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int16.mjs +24 -35
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +24 -35
- package/dist/number/branded-types/positive-int32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int32.mjs +24 -35
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +159 -33
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +160 -34
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +24 -35
- package/dist/number/branded-types/positive-uint16.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +24 -35
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +26 -36
- package/dist/number/branded-types/positive-uint32.d.mts.map +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +26 -36
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +140 -99
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +142 -101
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +24 -33
- package/dist/number/branded-types/safe-uint.d.mts.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +25 -34
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +121 -30
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +121 -30
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +26 -34
- package/dist/number/branded-types/uint16.d.mts.map +1 -1
- package/dist/number/branded-types/uint16.mjs +26 -34
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +26 -68
- package/dist/number/branded-types/uint32.d.mts.map +1 -1
- package/dist/number/branded-types/uint32.mjs +26 -68
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.d.mts +37 -101
- package/dist/number/enum/int8.d.mts.map +1 -1
- package/dist/number/enum/int8.mjs +39 -170
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts +45 -55
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs +46 -155
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/num.d.mts +145 -206
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +143 -199
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +97 -21
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +91 -20
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +126 -208
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +68 -102
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/cast-mutable.d.mts +12 -88
- package/dist/others/cast-mutable.d.mts.map +1 -1
- package/dist/others/cast-mutable.mjs +13 -89
- package/dist/others/cast-mutable.mjs.map +1 -1
- package/dist/others/cast-readonly.d.mts +12 -168
- package/dist/others/cast-readonly.d.mts.map +1 -1
- package/dist/others/cast-readonly.mjs +13 -169
- package/dist/others/cast-readonly.mjs.map +1 -1
- package/dist/others/if-then.d.mts +6 -83
- package/dist/others/if-then.d.mts.map +1 -1
- package/dist/others/if-then.mjs +6 -83
- package/dist/others/if-then.mjs.map +1 -1
- package/dist/others/map-nullable.d.mts +12 -136
- package/dist/others/map-nullable.d.mts.map +1 -1
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/memoize-function.d.mts +14 -157
- package/dist/others/memoize-function.d.mts.map +1 -1
- package/dist/others/memoize-function.mjs +14 -157
- package/dist/others/memoize-function.mjs.map +1 -1
- package/dist/others/tuple.d.mts +33 -151
- package/dist/others/tuple.d.mts.map +1 -1
- package/dist/others/tuple.mjs +33 -151
- package/dist/others/tuple.mjs.map +1 -1
- package/dist/others/unknown-to-string.d.mts +11 -125
- package/dist/others/unknown-to-string.d.mts.map +1 -1
- package/dist/others/unknown-to-string.mjs +12 -126
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/promise/promise.d.mts +33 -20
- package/dist/promise/promise.d.mts.map +1 -1
- package/dist/promise/promise.mjs +34 -21
- package/dist/promise/promise.mjs.map +1 -1
- package/package.json +47 -39
- package/src/array/impl/array-utils-creation.mts +192 -0
- package/src/array/{array-utils-creation.test.mts → impl/array-utils-creation.test.mts} +121 -72
- package/src/array/impl/array-utils-element-access.mts +115 -0
- package/src/array/impl/array-utils-element-access.test.mts +151 -0
- package/src/array/impl/array-utils-iterators.mts +79 -0
- package/src/array/impl/array-utils-iterators.test.mts +98 -0
- package/src/array/impl/array-utils-modification.mts +434 -0
- package/src/array/{array-utils-modification.test.mts → impl/array-utils-modification.test.mts} +41 -28
- package/src/array/{array-utils-overload-type-error.test.mts → impl/array-utils-overload-type-error.test.mts} +33 -33
- package/src/array/impl/array-utils-reducing-value.mts +551 -0
- package/src/array/{array-utils-reducing-value.test.mts → impl/array-utils-reducing-value.test.mts} +45 -50
- package/src/array/impl/array-utils-search.mts +509 -0
- package/src/array/impl/array-utils-search.test.mts +346 -0
- package/src/array/impl/array-utils-set-op.mts +166 -0
- package/src/array/{array-utils-set-op.test.mts → impl/array-utils-set-op.test.mts} +42 -35
- package/src/array/impl/array-utils-size.mts +30 -0
- package/src/array/impl/array-utils-size.test.mts +9 -0
- package/src/array/impl/array-utils-slice-clamped.mts +51 -0
- package/src/array/{array-utils-slice-clamped.test.mts → impl/array-utils-slice-clamped.test.mts} +12 -12
- package/src/array/impl/array-utils-slicing.mts +275 -0
- package/src/array/impl/array-utils-slicing.test.mts +158 -0
- package/src/array/impl/array-utils-transformation.mts +746 -0
- package/src/array/{array-utils-transformation.test.mts → impl/array-utils-transformation.test.mts} +662 -889
- package/src/array/impl/array-utils-validation.mts +241 -0
- package/src/array/{array-utils-validation.test.mts → impl/array-utils-validation.test.mts} +194 -107
- package/src/array/{array.test.mts → impl/array.test.mts} +2 -2
- package/src/array/impl/index.mts +12 -0
- package/src/array/index.mts +1 -1
- package/src/collections/imap-mapped.mts +99 -265
- package/src/collections/imap.mts +477 -174
- package/src/collections/imap.test.mts +12 -19
- package/src/collections/iset-mapped.mts +892 -358
- package/src/collections/iset.mts +429 -213
- package/src/collections/queue.mts +174 -200
- package/src/collections/stack.mts +172 -245
- package/src/collections/stack.test.mts +9 -1
- package/src/entry-point.mts +1 -0
- package/src/expect-type.mts +43 -172
- package/src/functional/match.mts +35 -145
- package/src/functional/optional.mts +285 -163
- package/src/functional/optional.test.mts +4 -1
- package/src/functional/pipe.mts +60 -113
- package/src/functional/result.mts +452 -351
- package/src/functional/result.test.mts +9 -2
- package/src/globals.d.mts +12 -5
- package/src/guard/has-key.mts +23 -74
- package/src/guard/is-non-empty-string.mts +20 -87
- package/src/guard/is-non-null-object.mts +14 -84
- package/src/guard/is-non-null-object.test.mts +1 -1
- package/src/guard/is-primitive.mts +13 -126
- package/src/guard/is-primitive.test.mts +1 -1
- package/src/guard/is-record.mts +21 -132
- package/src/guard/is-type.mts +201 -238
- package/src/guard/is-type.test.mts +7 -7
- package/src/guard/key-is-in.mts +22 -139
- package/src/index.mts +0 -1
- package/src/iterator/range.mts +29 -62
- package/src/json/json.mts +202 -134
- package/src/json/json.test.mts +1 -3
- package/src/number/branded-types/finite-number.mts +27 -159
- package/src/number/branded-types/int.mts +122 -120
- package/src/number/branded-types/int16.mts +22 -30
- package/src/number/branded-types/int16.test.mts +24 -24
- package/src/number/branded-types/int32.mts +22 -31
- package/src/number/branded-types/int32.test.mts +39 -39
- package/src/number/branded-types/non-negative-finite-number.mts +31 -39
- package/src/number/branded-types/non-negative-int16.mts +24 -34
- package/src/number/branded-types/non-negative-int16.test.mts +16 -16
- package/src/number/branded-types/non-negative-int32.mts +26 -35
- package/src/number/branded-types/non-negative-int32.test.mts +30 -30
- package/src/number/branded-types/non-zero-finite-number.mts +25 -40
- package/src/number/branded-types/non-zero-int.mts +15 -30
- package/src/number/branded-types/non-zero-int16.mts +27 -35
- package/src/number/branded-types/non-zero-int16.test.mts +26 -26
- package/src/number/branded-types/non-zero-int32.mts +29 -36
- package/src/number/branded-types/non-zero-int32.test.mts +45 -42
- package/src/number/branded-types/non-zero-safe-int.mts +39 -40
- package/src/number/branded-types/non-zero-uint16.mts +24 -35
- package/src/number/branded-types/non-zero-uint16.test.mts +16 -16
- package/src/number/branded-types/non-zero-uint32.mts +24 -35
- package/src/number/branded-types/non-zero-uint32.test.mts +28 -28
- package/src/number/branded-types/positive-finite-number.mts +29 -43
- package/src/number/branded-types/positive-int.mts +134 -124
- package/src/number/branded-types/positive-int16.mts +24 -35
- package/src/number/branded-types/positive-int16.test.mts +14 -14
- package/src/number/branded-types/positive-int32.mts +24 -35
- package/src/number/branded-types/positive-int32.test.mts +26 -26
- package/src/number/branded-types/positive-safe-int.mts +160 -34
- package/src/number/branded-types/positive-uint16.mts +24 -35
- package/src/number/branded-types/positive-uint16.test.mts +16 -16
- package/src/number/branded-types/positive-uint32.mts +26 -36
- package/src/number/branded-types/positive-uint32.test.mts +31 -28
- package/src/number/branded-types/safe-int.mts +142 -101
- package/src/number/branded-types/safe-uint.mts +25 -34
- package/src/number/branded-types/uint.mts +121 -30
- package/src/number/branded-types/uint16.mts +26 -34
- package/src/number/branded-types/uint16.test.mts +16 -16
- package/src/number/branded-types/uint32.mts +26 -68
- package/src/number/branded-types/uint32.test.mts +28 -28
- package/src/number/enum/int8.mts +39 -170
- package/src/number/enum/uint8.mts +46 -155
- package/src/number/num.mts +157 -212
- package/src/number/num.test.mts +4 -4
- package/src/number/refined-number-utils.mts +109 -26
- package/src/object/object.mts +130 -212
- package/src/object/object.test.mts +29 -0
- package/src/others/cast-mutable.mts +13 -89
- package/src/others/cast-mutable.test.mts +80 -0
- package/src/others/cast-readonly.mts +13 -169
- package/src/others/if-then.mts +6 -83
- package/src/others/map-nullable.mts +12 -136
- package/src/others/map-nullable.test.mts +6 -6
- package/src/others/memoize-function.mts +14 -157
- package/src/others/tuple.mts +33 -151
- package/src/others/unknown-to-string.mts +12 -126
- package/src/others/unknown-to-string.test.mts +13 -1
- package/src/promise/promise.mts +34 -21
- package/src/promise/promise.test.mts +43 -0
- package/dist/array/array-utils.d.mts +0 -2956
- package/dist/array/array-utils.d.mts.map +0 -1
- package/dist/array/array-utils.mjs +0 -1838
- package/dist/array/array-utils.mjs.map +0 -1
- package/src/array/array-utils-search.test.mts +0 -169
- package/src/array/array-utils-slicing.test.mts +0 -274
- package/src/array/array-utils.mts +0 -4834
package/dist/number/num.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Namespace providing utility functions for number manipulation and validation.
|
|
3
3
|
*
|
|
4
|
-
* This namespace offers a comprehensive set of type-safe number utilities
|
|
4
|
+
* This namespace offers a comprehensive set of type-safe number utilities
|
|
5
|
+
* including:
|
|
6
|
+
*
|
|
5
7
|
* - Type conversion and validation
|
|
6
8
|
* - Type guards for numeric constraints (non-zero, non-negative, positive)
|
|
7
9
|
* - Range checking and clamping operations
|
|
@@ -10,203 +12,197 @@
|
|
|
10
12
|
*
|
|
11
13
|
* Many functions in this namespace leverage TypeScript's type system to provide
|
|
12
14
|
* compile-time guarantees about numeric constraints.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* // Type conversion
|
|
17
|
-
* const num = Num.from('123.45'); // 123.45
|
|
18
|
-
* const invalid = Num.from('abc'); // NaN
|
|
19
|
-
*
|
|
20
|
-
* // Type guards
|
|
21
|
-
* const value = 5;
|
|
22
|
-
* if (Num.isPositive(value)) {
|
|
23
|
-
* // value is typed as PositiveNumber & 5
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
* // Range checking
|
|
27
|
-
* const isValid = Num.isInRange(0, 100)(50); // true
|
|
28
|
-
*
|
|
29
|
-
* // Clamping
|
|
30
|
-
* const clamped = Num.clamp(150, 0, 100); // 100
|
|
31
|
-
* const clampFn = Num.clamp(0, 100);
|
|
32
|
-
* const result = clampFn(150); // 100
|
|
33
|
-
* ```
|
|
34
15
|
*/
|
|
35
16
|
var Num;
|
|
36
17
|
(function (Num) {
|
|
37
18
|
/**
|
|
38
19
|
* Converts an unknown value to a number. Alias for the `Number` constructor.
|
|
39
|
-
*
|
|
40
|
-
* @returns The numeric representation of `n`.
|
|
20
|
+
*
|
|
41
21
|
* @example
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const input = '123.45';
|
|
25
|
+
*
|
|
26
|
+
* const result = Num.from(input);
|
|
27
|
+
*
|
|
28
|
+
* assert(result === 123.45);
|
|
45
29
|
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param n The value to convert.
|
|
32
|
+
* @returns The numeric representation of `n`.
|
|
46
33
|
*/
|
|
47
34
|
Num.from = Number;
|
|
48
35
|
/**
|
|
49
36
|
* Type guard that checks if a number is non-zero.
|
|
50
37
|
*
|
|
51
|
-
* When this function returns `true`, TypeScript narrows the type to exclude
|
|
52
|
-
* providing compile-time safety for division operations and other
|
|
53
|
-
* that require non-zero values.
|
|
54
|
-
*
|
|
55
|
-
* @template N - The numeric literal type or number type to check
|
|
56
|
-
* @param num - The number to check
|
|
57
|
-
* @returns `true` if the number is not zero, `false` otherwise
|
|
38
|
+
* When this function returns `true`, TypeScript narrows the type to exclude
|
|
39
|
+
* zero, providing compile-time safety for division operations and other
|
|
40
|
+
* calculations that require non-zero values.
|
|
58
41
|
*
|
|
59
42
|
* @example
|
|
60
|
-
*
|
|
61
|
-
*
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* const value: number = 5;
|
|
46
|
+
*
|
|
62
47
|
* if (Num.isNonZero(value)) {
|
|
63
|
-
* //
|
|
64
|
-
*
|
|
48
|
+
* // Safe to divide now that we know value is non-zero
|
|
49
|
+
* // eslint-disable-next-line total-functions/no-partial-division
|
|
50
|
+
* const inverted = 1 / value;
|
|
51
|
+
* assert(inverted === 0.2);
|
|
65
52
|
* }
|
|
66
53
|
*
|
|
67
|
-
*
|
|
68
|
-
* const literal = 0 as 0 | 1 | 2;
|
|
69
|
-
* if (Num.isNonZero(literal)) {
|
|
70
|
-
* // literal is typed as 1 | 2
|
|
71
|
-
* }
|
|
54
|
+
* assert.notOk(Num.isNonZero(0));
|
|
72
55
|
* ```
|
|
56
|
+
*
|
|
57
|
+
* @template N - The numeric literal type or number type to check
|
|
58
|
+
* @param num - The number to check
|
|
59
|
+
* @returns `true` if the number is not zero, `false` otherwise
|
|
73
60
|
*/
|
|
74
61
|
Num.isNonZero = (num) => num !== 0;
|
|
75
62
|
/**
|
|
76
|
-
* Type guard that checks if a number is non-negative (greater than or equal
|
|
63
|
+
* Type guard that checks if a number is non-negative (greater than or equal
|
|
64
|
+
* to zero).
|
|
77
65
|
*
|
|
78
|
-
* When this function returns `true`, TypeScript narrows the type to exclude
|
|
79
|
-
* values, which is useful for operations that require non-negative
|
|
80
|
-
* array indices or measurements.
|
|
81
|
-
*
|
|
82
|
-
* @template N - The numeric literal type or number type to check
|
|
83
|
-
* @param num - The number to check
|
|
84
|
-
* @returns `true` if the number is >= 0, `false` otherwise
|
|
66
|
+
* When this function returns `true`, TypeScript narrows the type to exclude
|
|
67
|
+
* negative values, which is useful for operations that require non-negative
|
|
68
|
+
* inputs like array indices or measurements.
|
|
85
69
|
*
|
|
86
70
|
* @example
|
|
87
|
-
* ```typescript
|
|
88
|
-
* const value = 10;
|
|
89
|
-
* if (Num.isNonNegative(value)) {
|
|
90
|
-
* // value is typed as NonNegativeNumber & 10
|
|
91
|
-
* const arr = new Array(value); // Safe array creation
|
|
92
|
-
* }
|
|
93
71
|
*
|
|
94
|
-
*
|
|
95
|
-
* const
|
|
96
|
-
*
|
|
97
|
-
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* const candidate = 10;
|
|
74
|
+
*
|
|
75
|
+
* if (Num.isNonNegative(candidate)) {
|
|
76
|
+
* const index: number = candidate;
|
|
77
|
+
* assert(index === 10);
|
|
98
78
|
* }
|
|
79
|
+
*
|
|
80
|
+
* assert.notOk(Num.isNonNegative(-1));
|
|
99
81
|
* ```
|
|
82
|
+
*
|
|
83
|
+
* @template N - The numeric literal type or number type to check
|
|
84
|
+
* @param num - The number to check
|
|
85
|
+
* @returns `true` if the number is >= 0, `false` otherwise
|
|
100
86
|
*/
|
|
101
87
|
Num.isNonNegative = (num) => num >= 0;
|
|
102
88
|
/**
|
|
103
89
|
* Type guard that checks if a number is positive (greater than zero).
|
|
104
90
|
*
|
|
105
|
-
* When this function returns `true`, TypeScript narrows the type to exclude
|
|
106
|
-
* and negative values. This is particularly useful for validating inputs
|
|
107
|
-
* must be strictly positive, such as dimensions, counts, or rates.
|
|
108
|
-
*
|
|
109
|
-
* @template N - The numeric literal type or number type to check
|
|
110
|
-
* @param num - The number to check
|
|
111
|
-
* @returns `true` if the number is > 0, `false` otherwise
|
|
91
|
+
* When this function returns `true`, TypeScript narrows the type to exclude
|
|
92
|
+
* zero and negative values. This is particularly useful for validating inputs
|
|
93
|
+
* that must be strictly positive, such as dimensions, counts, or rates.
|
|
112
94
|
*
|
|
113
95
|
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* const count = 5;
|
|
116
|
-
* if (Num.isPositive(count)) {
|
|
117
|
-
* // count is typed as PositiveNumber & 5
|
|
118
|
-
* const average = total / count; // Safe division
|
|
119
|
-
* }
|
|
120
96
|
*
|
|
121
|
-
*
|
|
122
|
-
* const
|
|
123
|
-
*
|
|
124
|
-
*
|
|
97
|
+
* ```ts
|
|
98
|
+
* const amount = 42;
|
|
99
|
+
*
|
|
100
|
+
* if (Num.isPositive(amount)) {
|
|
101
|
+
* assert.ok(amount > 0);
|
|
125
102
|
* }
|
|
103
|
+
*
|
|
104
|
+
* assert.notOk(Num.isPositive(0));
|
|
126
105
|
* ```
|
|
106
|
+
*
|
|
107
|
+
* @template N - The numeric literal type or number type to check
|
|
108
|
+
* @param num - The number to check
|
|
109
|
+
* @returns `true` if the number is > 0, `false` otherwise
|
|
127
110
|
*/
|
|
128
111
|
Num.isPositive = (num) => num > 0;
|
|
129
112
|
/**
|
|
130
|
-
* Creates a function that checks if a number `x` is within the range
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* @returns A function that takes a number `x` and returns `true` if `x` is in the range, `false` otherwise.
|
|
113
|
+
* Creates a function that checks if a number `x` is within the range
|
|
114
|
+
* `lowerBound <= x < upperBound`.
|
|
115
|
+
*
|
|
134
116
|
* @example
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
117
|
+
*
|
|
118
|
+
* ```ts
|
|
119
|
+
* const isGrade = Num.isInRange(0, 100);
|
|
120
|
+
*
|
|
121
|
+
* assert.ok(isGrade(50));
|
|
122
|
+
* assert.notOk(isGrade(100));
|
|
141
123
|
* ```
|
|
124
|
+
*
|
|
125
|
+
* @param lowerBound The lower bound (inclusive).
|
|
126
|
+
* @param upperBound The upper bound (exclusive).
|
|
127
|
+
* @returns A function that takes a number `x` and returns `true` if `x` is in
|
|
128
|
+
* the range, `false` otherwise.
|
|
142
129
|
*/
|
|
143
130
|
Num.isInRange = (lowerBound, upperBound) => (x) => lowerBound <= x && x < upperBound;
|
|
144
131
|
/**
|
|
145
|
-
* Creates a function that checks if a number `x` is within the range
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* @returns A function that takes a number `x` and returns `true` if `x` is in the range, `false` otherwise.
|
|
132
|
+
* Creates a function that checks if a number `x` is within the range
|
|
133
|
+
* `lowerBound <= x <= upperBound`.
|
|
134
|
+
*
|
|
149
135
|
* @example
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
136
|
+
*
|
|
137
|
+
* ```ts
|
|
138
|
+
* const isPercentage = Num.isInRangeInclusive(0, 100);
|
|
139
|
+
*
|
|
140
|
+
* assert.ok(isPercentage(100));
|
|
141
|
+
* assert.notOk(isPercentage(-1));
|
|
156
142
|
* ```
|
|
143
|
+
*
|
|
144
|
+
* @param lowerBound The lower bound (inclusive).
|
|
145
|
+
* @param upperBound The upper bound (inclusive).
|
|
146
|
+
* @returns A function that takes a number `x` and returns `true` if `x` is in
|
|
147
|
+
* the range, `false` otherwise.
|
|
157
148
|
*/
|
|
158
149
|
Num.isInRangeInclusive = (lowerBound, upperBound) => (x) => lowerBound <= x && x <= upperBound;
|
|
159
150
|
/**
|
|
160
|
-
* Creates a type guard that checks if a number is an unsigned integer within
|
|
151
|
+
* Creates a type guard that checks if a number is an unsigned integer within
|
|
152
|
+
* a specified range.
|
|
161
153
|
*
|
|
162
154
|
* This function returns a predicate that validates whether a number is:
|
|
155
|
+
*
|
|
163
156
|
* - A safe integer (no floating point)
|
|
164
157
|
* - Within the range [lowerBound, upperBound)
|
|
165
158
|
*
|
|
166
159
|
* The returned type guard provides precise type narrowing when the bounds are
|
|
167
160
|
* SmallUint literals, making it ideal for array index validation.
|
|
168
161
|
*
|
|
162
|
+
* @example
|
|
163
|
+
*
|
|
164
|
+
* ```ts
|
|
165
|
+
* const indexGuard = Num.isUintInRange(0, 5);
|
|
166
|
+
*
|
|
167
|
+
* assert.ok(indexGuard(3));
|
|
168
|
+
* assert.notOk(indexGuard(5));
|
|
169
|
+
* assert.notOk(indexGuard(-1));
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
169
172
|
* @template L - The lower bound as a SmallUint literal type
|
|
170
173
|
* @template U - The upper bound as a SmallUint literal type
|
|
171
174
|
* @param lowerBound - The minimum value (inclusive)
|
|
172
175
|
* @param upperBound - The maximum value (exclusive)
|
|
173
176
|
* @returns A type guard function that validates and narrows number types
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* ```typescript
|
|
177
|
-
* // Custom range validation
|
|
178
|
-
* const isValidPercentage = Num.isUintInRange(0, 101);
|
|
179
|
-
* if (isValidPercentage(value)) {
|
|
180
|
-
* // value is typed as 0 | 1 | ... | 100
|
|
181
|
-
* }
|
|
182
|
-
* ```
|
|
183
177
|
*/
|
|
184
178
|
Num.isUintInRange = (lowerBound, upperBound) => (x) => Number.isSafeInteger(x) && lowerBound <= x && x < upperBound;
|
|
185
179
|
/**
|
|
186
|
-
* Creates a type guard that checks if a number is an unsigned integer within
|
|
180
|
+
* Creates a type guard that checks if a number is an unsigned integer within
|
|
181
|
+
* a specified inclusive range.
|
|
187
182
|
*
|
|
188
183
|
* This function returns a predicate that validates whether a number is:
|
|
184
|
+
*
|
|
189
185
|
* - A safe integer (no floating point)
|
|
190
186
|
* - Within the range [lowerBound, upperBound] (both bounds inclusive)
|
|
191
187
|
*
|
|
192
188
|
* The returned type guard provides precise type narrowing when the bounds are
|
|
193
|
-
* SmallUint literals, useful for validating scores, percentages, or other
|
|
189
|
+
* SmallUint literals, useful for validating scores, percentages, or other
|
|
190
|
+
* bounded values.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
*
|
|
194
|
+
* ```ts
|
|
195
|
+
* const inclusiveGuard = Num.isUintInRangeInclusive(0, 5);
|
|
196
|
+
*
|
|
197
|
+
* assert.ok(inclusiveGuard(5));
|
|
198
|
+
* assert.notOk(inclusiveGuard(6));
|
|
199
|
+
* ```
|
|
194
200
|
*
|
|
195
201
|
* @template L - The lower bound as a SmallUint literal type
|
|
196
202
|
* @template U - The upper bound as a SmallUint literal type
|
|
197
203
|
* @param lowerBound - The minimum value (inclusive)
|
|
198
204
|
* @param upperBound - The maximum value (inclusive)
|
|
199
205
|
* @returns A type guard function that validates and narrows number types
|
|
200
|
-
*
|
|
201
|
-
* @example
|
|
202
|
-
* ```typescript
|
|
203
|
-
* const isValidScore = Num.isUintInRangeInclusive(0, 100);
|
|
204
|
-
* const score: number = getTestScore();
|
|
205
|
-
* if (isValidScore(score)) {
|
|
206
|
-
* // score is typed as 0 | 1 | 2 | ... | 100
|
|
207
|
-
* const grade = calculateGrade(score);
|
|
208
|
-
* }
|
|
209
|
-
* ```
|
|
210
206
|
*/
|
|
211
207
|
Num.isUintInRangeInclusive = (lowerBound, upperBound) => (x) => Number.isSafeInteger(x) && lowerBound <= x && x <= upperBound;
|
|
212
208
|
function clamp(...args) {
|
|
@@ -227,31 +223,17 @@ var Num;
|
|
|
227
223
|
/**
|
|
228
224
|
* Performs type-safe division with compile-time zero-check.
|
|
229
225
|
*
|
|
230
|
-
* This function leverages TypeScript's type system to prevent division by
|
|
231
|
-
* at compile time. The divisor must be typed as NonZeroNumber or a
|
|
232
|
-
* numeric literal.
|
|
226
|
+
* This function leverages TypeScript's type system to prevent division by
|
|
227
|
+
* zero at compile time. The divisor must be typed as NonZeroNumber or a
|
|
228
|
+
* non-zero numeric literal.
|
|
233
229
|
*
|
|
234
230
|
* @param a - The dividend
|
|
235
231
|
* @param b - The divisor (must be non-zero, enforced by types)
|
|
236
232
|
* @returns The quotient of a / b
|
|
237
|
-
*
|
|
238
|
-
* @example
|
|
239
|
-
* ```typescript
|
|
240
|
-
* const result = Num.div(10, 2); // 5
|
|
241
|
-
* // Num.div(10, 0); // ❌ TypeScript error: Type '0' is not assignable
|
|
242
|
-
*
|
|
243
|
-
* // With type guards
|
|
244
|
-
* const divisor: number = getDivisor();
|
|
245
|
-
* if (Num.isNonZero(divisor)) {
|
|
246
|
-
* const result = Num.div(100, divisor); // ✅ Safe
|
|
247
|
-
* }
|
|
248
|
-
*
|
|
249
|
-
* // With branded types
|
|
250
|
-
* const nonZero = asNonZeroNumber(5);
|
|
251
|
-
* const result3 = Num.div(20, nonZero); // 4
|
|
252
|
-
* ```
|
|
253
233
|
*/
|
|
254
|
-
Num.div = (a, b) =>
|
|
234
|
+
Num.div = (a, b) =>
|
|
235
|
+
// eslint-disable-next-line total-functions/no-partial-division
|
|
236
|
+
a / b;
|
|
255
237
|
/**
|
|
256
238
|
* Performs integer division using floor division.
|
|
257
239
|
*
|
|
@@ -264,32 +246,23 @@ var Num;
|
|
|
264
246
|
* @param a - The dividend
|
|
265
247
|
* @param b - The divisor
|
|
266
248
|
* @returns The integer quotient, or `NaN` if b is zero
|
|
267
|
-
*
|
|
268
|
-
* @example
|
|
269
|
-
* ```typescript
|
|
270
|
-
* Num.divInt(10, 3); // 3
|
|
271
|
-
* Num.divInt(10, -3); // -4 (floor division)
|
|
272
|
-
* ```
|
|
273
249
|
*/
|
|
274
|
-
Num.divInt = (a, b) =>
|
|
250
|
+
Num.divInt = (a, b) =>
|
|
251
|
+
// eslint-disable-next-line total-functions/no-partial-division
|
|
252
|
+
Math.floor(Math.floor(a) / Math.floor(b));
|
|
275
253
|
/**
|
|
276
254
|
* Rounds a number to a specified number of decimal places.
|
|
277
255
|
*
|
|
278
|
-
* Uses the standard rounding algorithm (round half up) to round the number
|
|
279
|
-
*
|
|
256
|
+
* Uses the standard rounding algorithm (round half up) to round the number to
|
|
257
|
+
* the given precision. The precision must be a positive safe integer.
|
|
280
258
|
*
|
|
281
259
|
* @param num - The number to round
|
|
282
260
|
* @param precision - The number of decimal places (must be positive)
|
|
283
261
|
* @returns The rounded number
|
|
284
|
-
*
|
|
285
|
-
* @example
|
|
286
|
-
* ```typescript
|
|
287
|
-
* Num.roundAt(3.14159, 2); // 3.14
|
|
288
|
-
* Num.roundAt(10.5, 0); // 11
|
|
289
|
-
* ```
|
|
290
262
|
*/
|
|
291
263
|
Num.roundAt = (num, precision) => {
|
|
292
264
|
const digit = 10 ** precision;
|
|
265
|
+
// eslint-disable-next-line total-functions/no-partial-division
|
|
293
266
|
return Math.round(num * digit) / digit;
|
|
294
267
|
};
|
|
295
268
|
/**
|
|
@@ -301,35 +274,24 @@ var Num;
|
|
|
301
274
|
*
|
|
302
275
|
* @param num - The number to round
|
|
303
276
|
* @returns The rounded integer as an Int branded type
|
|
304
|
-
*
|
|
305
|
-
* @example
|
|
306
|
-
* ```typescript
|
|
307
|
-
* Num.roundToInt(3.2); // 3
|
|
308
|
-
* Num.roundToInt(3.5); // 4
|
|
309
|
-
* ```
|
|
310
277
|
*/
|
|
311
|
-
// eslint-disable-next-line
|
|
278
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
312
279
|
Num.roundToInt = (num) => (0 | (num + 0.5));
|
|
313
280
|
/**
|
|
314
281
|
* Creates a reusable rounding function with a fixed precision.
|
|
315
282
|
*
|
|
316
|
-
* This is a curried version of roundAt that returns a function configured
|
|
317
|
-
*
|
|
318
|
-
*
|
|
283
|
+
* This is a curried version of roundAt that returns a function configured to
|
|
284
|
+
* always round to the specified number of decimal places. Useful for creating
|
|
285
|
+
* consistent rounding behavior across multiple values.
|
|
319
286
|
*
|
|
320
287
|
* @param digit - The number of decimal places for rounding
|
|
321
288
|
* @returns A function that rounds numbers to the specified precision
|
|
322
|
-
*
|
|
323
|
-
* @example
|
|
324
|
-
* ```typescript
|
|
325
|
-
* const roundTo2 = Num.round(2);
|
|
326
|
-
* roundTo2(3.14159); // 3.14
|
|
327
|
-
* roundTo2(2.71828); // 2.72
|
|
328
|
-
* ```
|
|
329
289
|
*/
|
|
330
290
|
Num.round = (digit) => {
|
|
331
291
|
const powAmount = 10 ** digit;
|
|
332
|
-
return (target) =>
|
|
292
|
+
return (target) =>
|
|
293
|
+
// eslint-disable-next-line total-functions/no-partial-division
|
|
294
|
+
Num.roundToInt(powAmount * target) / powAmount;
|
|
333
295
|
};
|
|
334
296
|
/**
|
|
335
297
|
* Converts NaN values to undefined while preserving all other numbers.
|
|
@@ -341,56 +303,38 @@ var Num;
|
|
|
341
303
|
* @template N - The numeric type (literal or number)
|
|
342
304
|
* @param num - The number to check
|
|
343
305
|
* @returns The original number if not NaN, otherwise undefined
|
|
344
|
-
*
|
|
345
|
-
* @example
|
|
346
|
-
* ```typescript
|
|
347
|
-
* Num.mapNaN2Undefined(42); // 42
|
|
348
|
-
* Num.mapNaN2Undefined(NaN); // undefined
|
|
349
|
-
* ```
|
|
350
306
|
*/
|
|
351
307
|
Num.mapNaN2Undefined = (num) => Number.isNaN(num)
|
|
352
308
|
? undefined
|
|
353
|
-
: // eslint-disable-next-line
|
|
309
|
+
: // eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
354
310
|
num;
|
|
355
311
|
/**
|
|
356
312
|
* Type-safe increment operation for SmallUint values.
|
|
357
313
|
*
|
|
358
|
-
* Increments a SmallUint (0-40) by 1 with the result type computed at
|
|
359
|
-
*
|
|
360
|
-
*
|
|
314
|
+
* Increments a SmallUint (0-40) by 1 with the result type computed at compile
|
|
315
|
+
* time. This provides type-level arithmetic for small unsigned integers,
|
|
316
|
+
* useful for type-safe counter operations.
|
|
361
317
|
*
|
|
362
318
|
* @template N - A SmallUint literal type (0-40)
|
|
363
319
|
* @param n - The SmallUint value to increment
|
|
364
320
|
* @returns The incremented value with type Increment<N>
|
|
365
|
-
*
|
|
366
|
-
* @example
|
|
367
|
-
* ```typescript
|
|
368
|
-
* const zero = 0 as 0;
|
|
369
|
-
* const one = Num.increment(zero); // type is 1, value is 1
|
|
370
|
-
* ```
|
|
371
321
|
*/
|
|
372
322
|
Num.increment = (n) =>
|
|
373
|
-
// eslint-disable-next-line
|
|
323
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
374
324
|
(n + 1);
|
|
375
325
|
/**
|
|
376
326
|
* Type-safe decrement operation for positive SmallInt values.
|
|
377
327
|
*
|
|
378
|
-
* Decrements a positive SmallInt (1-40) by 1 with the result type computed
|
|
379
|
-
*
|
|
328
|
+
* Decrements a positive SmallInt (1-40) by 1 with the result type computed at
|
|
329
|
+
* compile time. This provides type-level arithmetic for small positive
|
|
380
330
|
* integers, useful for type-safe countdown operations.
|
|
381
331
|
*
|
|
382
332
|
* @template N - A positive SmallInt literal type (1-40)
|
|
383
333
|
* @param n - The positive SmallInt value to decrement
|
|
384
334
|
* @returns The decremented value with type Decrement<N>
|
|
385
|
-
*
|
|
386
|
-
* @example
|
|
387
|
-
* ```typescript
|
|
388
|
-
* const three = 3 as 3;
|
|
389
|
-
* const two = Num.decrement(three); // type is 2, value is 2
|
|
390
|
-
* ```
|
|
391
335
|
*/
|
|
392
336
|
Num.decrement = (n) =>
|
|
393
|
-
// eslint-disable-next-line
|
|
337
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
394
338
|
(n - 1);
|
|
395
339
|
})(Num || (Num = {}));
|
|
396
340
|
|
package/dist/number/num.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"num.mjs","sources":["../../src/number/num.mts"],"sourcesContent":[null],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"num.mjs","sources":["../../src/number/num.mts"],"sourcesContent":[null],"names":[],"mappings":"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"}
|