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/expect-type.mjs
CHANGED
|
@@ -1,199 +1,70 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Compile-time type assertion utility for TypeScript type testing.
|
|
3
3
|
*
|
|
4
|
-
* This function performs static type relationship checking at compile-time and
|
|
5
|
-
* It is primarily used in test files to verify that
|
|
6
|
-
*
|
|
4
|
+
* This function performs static type relationship checking at compile-time and
|
|
5
|
+
* has no runtime effect. It is primarily used in test files to verify that
|
|
6
|
+
* TypeScript's type inference and type relationships work as expected. The
|
|
7
|
+
* function will cause TypeScript compilation errors if the specified type
|
|
7
8
|
* relationship does not hold.
|
|
8
9
|
*
|
|
9
10
|
* ## Supported Type Relations
|
|
10
11
|
*
|
|
11
12
|
* ### Equality Relations
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
*
|
|
14
|
+
* - **`"="` (strict equality)**: Asserts that types `A` and `B` are exactly the
|
|
15
|
+
* same type. Uses TypeScript's internal type equality checking.
|
|
16
|
+
* - **`"!="` (strict inequality)**: Asserts that types `A` and `B` are not
|
|
17
|
+
* exactly the same type.
|
|
15
18
|
*
|
|
16
19
|
* ### Assignability Relations
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
*
|
|
21
|
+
* - **`"~="` (mutual assignability)**: Asserts that `A` extends `B` AND `B`
|
|
22
|
+
* extends `A`. Types are structurally equivalent and mutually assignable.
|
|
23
|
+
* - **`"<="` (subtype relation)**: Asserts that type `A` extends (is assignable
|
|
24
|
+
* to) type `B`. Type `A` is a subtype of `B`.
|
|
25
|
+
* - **`">="` (supertype relation)**: Asserts that type `B` extends (is assignable
|
|
26
|
+
* to) type `A`. Type `A` is a supertype of `B`.
|
|
23
27
|
*
|
|
24
28
|
* ### Negative Assignability Relations
|
|
29
|
+
*
|
|
25
30
|
* - **`"!<="` (not subtype)**: Asserts that type `A` does NOT extend type `B`.
|
|
26
31
|
* - **`"!>="` (not supertype)**: Asserts that type `B` does NOT extend type `A`.
|
|
27
32
|
*
|
|
28
33
|
* ## Type Parameter Constraints
|
|
29
34
|
*
|
|
30
|
-
* @
|
|
35
|
+
* @since 1.0.0
|
|
36
|
+
* @template A - The first type for comparison. Can be any TypeScript type
|
|
37
|
+
* including:
|
|
38
|
+
*
|
|
31
39
|
* - Primitive types (string, number, boolean, etc.)
|
|
32
40
|
* - Object types and interfaces
|
|
33
41
|
* - Union and intersection types
|
|
34
42
|
* - Generic types and type parameters
|
|
35
43
|
* - Literal types and branded types
|
|
36
44
|
* - Function types and return types
|
|
37
|
-
* @template B - The second type for comparison. Same constraints as type `A`.
|
|
38
|
-
*
|
|
39
|
-
* @param _relation - A string literal representing the expected type relationship.
|
|
40
|
-
* TypeScript's type system automatically infers and restricts the available operators
|
|
41
|
-
* based on the actual relationship between types `A` and `B`. If an invalid relationship
|
|
42
|
-
* is specified, TypeScript will show a compilation error.
|
|
43
|
-
*
|
|
44
|
-
* ## Usage Patterns
|
|
45
|
-
*
|
|
46
|
-
* ### Basic Type Testing
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* import { expectType } from './expect-type.mjs';
|
|
50
|
-
*
|
|
51
|
-
* // Primitive type equality
|
|
52
|
-
* expectType<string, string>("="); // â exact match
|
|
53
|
-
* expectType<number, string>("!="); // â different types
|
|
54
|
-
* expectType<42, number>("<="); // â literal extends primitive
|
|
55
|
-
* expectType<number, 42>(">="); // â primitive is supertype
|
|
56
|
-
*
|
|
57
|
-
* // Type assertions will cause compilation errors for wrong relationships:
|
|
58
|
-
* // expectType<string, number>("="); // â TypeScript error
|
|
59
|
-
* // expectType<number, string>("<="); // â TypeScript error
|
|
60
|
-
* ```
|
|
61
|
-
*
|
|
62
|
-
* ### Array and Tuple Type Validation
|
|
63
|
-
* @example
|
|
64
|
-
* ```typescript
|
|
65
|
-
* // Testing array utility function return types
|
|
66
|
-
* const zeros = Arr.zeros(3);
|
|
67
|
-
* expectType<typeof zeros, readonly [0, 0, 0]>("=");
|
|
68
|
-
*
|
|
69
|
-
* const sequence = Arr.seq(5);
|
|
70
|
-
* expectType<typeof sequence, readonly [0, 1, 2, 3, 4]>("=");
|
|
71
|
-
*
|
|
72
|
-
* // Dynamic length arrays
|
|
73
|
-
* const dynamicArray = Arr.zeros(someLength);
|
|
74
|
-
* expectType<typeof dynamicArray, readonly 0[]>("=");
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* ### Function Return Type Testing
|
|
78
|
-
* @example
|
|
79
|
-
* ```typescript
|
|
80
|
-
* // Testing function return types
|
|
81
|
-
* const createUser = () => ({ id: 1, name: 'John' });
|
|
82
|
-
* expectType<ReturnType<typeof createUser>, { id: number; name: string }>("~=");
|
|
83
|
-
*
|
|
84
|
-
* // Generic function type inference
|
|
85
|
-
* const identity = <T>(x: T): T => x;
|
|
86
|
-
* const result = identity('hello');
|
|
87
|
-
* expectType<typeof result, string>("=");
|
|
88
|
-
* ```
|
|
89
|
-
*
|
|
90
|
-
* ### Union and Intersection Types
|
|
91
|
-
* @example
|
|
92
|
-
* ```typescript
|
|
93
|
-
* // Union type relationships
|
|
94
|
-
* expectType<string, string | number>("<="); // string extends union
|
|
95
|
-
* expectType<string | number, string>(">="); // union contains string
|
|
96
|
-
* expectType<string | number, number>(">="); // union contains number
|
|
97
|
-
*
|
|
98
|
-
* // Intersection type relationships
|
|
99
|
-
* type A = { a: number };
|
|
100
|
-
* type B = { b: string };
|
|
101
|
-
* expectType<A & B, A>(">="); // intersection extends component
|
|
102
|
-
* expectType<A, A & B>("<="); // component extends intersection
|
|
103
|
-
* ```
|
|
104
45
|
*
|
|
105
|
-
*
|
|
106
|
-
* @
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* if (Optional.isNone(optional)) {
|
|
128
|
-
* expectType<typeof optional, Optional.None>("<=");
|
|
129
|
-
* }
|
|
130
|
-
*
|
|
131
|
-
* // Result type validation
|
|
132
|
-
* const result: Result<string, Error> = Result.ok('success');
|
|
133
|
-
* expectType<typeof result, Result<string, Error>>("<=");
|
|
134
|
-
* ```
|
|
135
|
-
*
|
|
136
|
-
* ### Type Guard and Validation Testing
|
|
137
|
-
* @example
|
|
138
|
-
* ```typescript
|
|
139
|
-
* // Testing type guard functions
|
|
140
|
-
* if (isRecord(value)) {
|
|
141
|
-
* expectType<typeof value, UnknownRecord>("<=");
|
|
142
|
-
* }
|
|
143
|
-
*
|
|
144
|
-
* // Testing compile-time type predicates
|
|
145
|
-
* const obj = { key: 'value' };
|
|
146
|
-
* if (hasKey(obj, 'key')) {
|
|
147
|
-
* expectType<typeof obj.key, unknown>("<=");
|
|
148
|
-
* }
|
|
149
|
-
* ```
|
|
150
|
-
*
|
|
151
|
-
* ## Common Testing Patterns
|
|
152
|
-
*
|
|
153
|
-
* ### Dual Testing Strategy
|
|
154
|
-
* Combine `expectType` with runtime assertions for comprehensive testing:
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```typescript
|
|
158
|
-
* describe('Arr.zeros', () => {
|
|
159
|
-
* test('should create array of zeros with correct type', () => {
|
|
160
|
-
* const result = Arr.zeros(3);
|
|
161
|
-
*
|
|
162
|
-
* // Compile-time type assertion
|
|
163
|
-
* expectType<typeof result, readonly [0, 0, 0]>("=");
|
|
164
|
-
*
|
|
165
|
-
* // Runtime behavior assertion
|
|
166
|
-
* expect(result).toStrictEqual([0, 0, 0]);
|
|
167
|
-
* });
|
|
168
|
-
* });
|
|
169
|
-
* ```
|
|
170
|
-
*
|
|
171
|
-
* ### Type Relationship Validation
|
|
172
|
-
* Test complex type hierarchies and relationships:
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```typescript
|
|
176
|
-
* // Ensure proper type hierarchy
|
|
177
|
-
* expectType<PositiveInt, Int>("<="); // positive is subset of int
|
|
178
|
-
* expectType<Int, FiniteNumber>("<="); // int is subset of finite
|
|
179
|
-
* expectType<FiniteNumber, number>("<="); // finite is subset of number
|
|
180
|
-
*
|
|
181
|
-
* // Verify mutual exclusion
|
|
182
|
-
* expectType<PositiveInt, NegativeInt>("!="); // different int types
|
|
183
|
-
* expectType<PositiveInt, NegativeInt>("!<="); // neither extends the other
|
|
184
|
-
* expectType<NegativeInt, PositiveInt>("!<=");
|
|
185
|
-
* ```
|
|
186
|
-
*
|
|
187
|
-
* ## Important Notes
|
|
188
|
-
*
|
|
189
|
-
* - **Compile-time only**: This function has no runtime behavior and will be optimized away.
|
|
190
|
-
* - **Type inference**: The available relation operators are automatically inferred by TypeScript
|
|
191
|
-
* based on the actual type relationship between `A` and `B`.
|
|
192
|
-
* - **Error feedback**: Invalid type relationships will cause clear TypeScript compilation errors.
|
|
193
|
-
* - **Test organization**: Typically used in `.test.mts` files alongside runtime assertions.
|
|
194
|
-
* - **Performance**: Has zero runtime overhead as it's purely a compile-time construct.
|
|
195
|
-
*
|
|
196
|
-
* @since 1.0.0
|
|
46
|
+
* @template B - The second type for comparison. Same constraints as type `A`.
|
|
47
|
+
* @param _relation - A string literal representing the expected type
|
|
48
|
+
* relationship. TypeScript's type system automatically infers and restricts
|
|
49
|
+
* the available operators based on the actual relationship between types `A`
|
|
50
|
+
* and `B`. If an invalid relationship is specified, TypeScript will show a
|
|
51
|
+
* compilation error.
|
|
52
|
+
*
|
|
53
|
+
* Combine `expectType` with runtime assertions for comprehensive testing:
|
|
54
|
+
*
|
|
55
|
+
* ## Important Notes
|
|
56
|
+
*
|
|
57
|
+
* - **Compile-time only**: This function has no runtime behavior and will be
|
|
58
|
+
* optimized away.
|
|
59
|
+
* - **Type inference**: The available relation operators are automatically
|
|
60
|
+
* inferred by TypeScript based on the actual type relationship between
|
|
61
|
+
* `A` and `B`.
|
|
62
|
+
* - **Error feedback**: Invalid type relationships will cause clear TypeScript
|
|
63
|
+
* compilation errors.
|
|
64
|
+
* - **Test organization**: Typically used in `.test.mts` files alongside runtime
|
|
65
|
+
* assertions.
|
|
66
|
+
* - **Performance**: Has zero runtime overhead as it's purely a compile-time
|
|
67
|
+
* construct.
|
|
197
68
|
*/
|
|
198
69
|
const expectType = (_relation) => undefined;
|
|
199
70
|
|
package/dist/expect-type.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect-type.mjs","sources":["../src/expect-type.mts"],"sourcesContent":[null],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"expect-type.mjs","sources":["../src/expect-type.mts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEG;AACI,MAAM,UAAU,GAAG,CACxB,SAMoE,KAC3D;;;;"}
|
|
@@ -1,183 +1,78 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @internal
|
|
3
|
-
* Utility type to extract the union of all values from a record type.
|
|
4
|
-
* @template T The record type to extract values from.
|
|
5
|
-
*/
|
|
6
|
-
type ValueOf<T> = T[keyof T];
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
* Represents a record with unknown value types.
|
|
10
|
-
*/
|
|
11
|
-
type UnknownRecord = Record<PropertyKey, unknown>;
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
* Represents a readonly record mapping keys of type K to values of type V.
|
|
15
|
-
* @template K The type of keys.
|
|
16
|
-
* @template V The type of values.
|
|
17
|
-
*/
|
|
18
|
-
type ReadonlyRecord<K extends PropertyKey, V> = Readonly<Record<K, V>>;
|
|
19
|
-
/**
|
|
20
|
-
* @internal
|
|
21
|
-
* A relaxed version of Exclude that handles edge cases with property keys.
|
|
22
|
-
* @template T The type to exclude from.
|
|
23
|
-
* @template U The type to exclude.
|
|
24
|
-
*/
|
|
25
|
-
type RelaxedExclude<T, U> = T extends U ? never : T;
|
|
26
|
-
/**
|
|
27
|
-
* @internal
|
|
28
|
-
* Checks if two types are exactly equal.
|
|
29
|
-
* @template T First type to compare.
|
|
30
|
-
* @template U Second type to compare.
|
|
31
|
-
*/
|
|
32
|
-
type TypeEq<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false;
|
|
33
1
|
/**
|
|
34
2
|
* Type-safe pattern matching function for string-based discriminated unions.
|
|
35
3
|
*
|
|
36
|
-
* Provides compile-time guarantees for exhaustive case handling when working
|
|
37
|
-
* literal string unions. Automatically enforces completeness checking when
|
|
38
|
-
* cases are covered, and requires a default value when cases are
|
|
4
|
+
* Provides compile-time guarantees for exhaustive case handling when working
|
|
5
|
+
* with literal string unions. Automatically enforces completeness checking when
|
|
6
|
+
* all cases are covered, and requires a default value when cases are
|
|
7
|
+
* incomplete.
|
|
39
8
|
*
|
|
40
9
|
* ## Key Features:
|
|
41
|
-
*
|
|
42
|
-
* - **
|
|
10
|
+
*
|
|
11
|
+
* - **Exhaustive Matching**: When all cases of a literal union are handled, no
|
|
12
|
+
* default value is needed
|
|
13
|
+
* - **Partial Matching**: When cases are incomplete or working with general
|
|
14
|
+
* string types, a default value is required
|
|
43
15
|
* - **Type Safety**: Prevents extra cases and ensures only valid keys are used
|
|
44
16
|
* - **Strict Property Checking**: Rejects objects with unexpected properties
|
|
45
17
|
*
|
|
46
|
-
* @param target - The value to match against
|
|
47
|
-
* @param cases - Object mapping possible values to their corresponding results
|
|
48
|
-
* @param defaultValue - Fallback value (required when not all cases are covered)
|
|
49
|
-
* @returns The matched result or default value
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* Exhaustive matching (no default needed):
|
|
53
|
-
* ```typescript
|
|
54
|
-
* type Status = 'loading' | 'success' | 'error';
|
|
55
|
-
* const status: Status = 'loading';
|
|
56
|
-
*
|
|
57
|
-
* const message = match(status, {
|
|
58
|
-
* loading: 'Please wait...',
|
|
59
|
-
* success: 'Operation completed!',
|
|
60
|
-
* error: 'Something went wrong'
|
|
61
|
-
* });
|
|
62
|
-
* // Type: string
|
|
63
|
-
* // Result: 'Please wait...'
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* Partial matching (default required):
|
|
68
|
-
* ```typescript
|
|
69
|
-
* type Priority = 'low' | 'medium' | 'high' | 'critical';
|
|
70
|
-
* const priority: Priority = 'medium';
|
|
71
|
-
*
|
|
72
|
-
* const color = match(priority, {
|
|
73
|
-
* high: 'red',
|
|
74
|
-
* critical: 'darkred'
|
|
75
|
-
* }, 'gray'); // Default required for uncovered cases
|
|
76
|
-
* // Type: 'red' | 'darkred' | 'gray'
|
|
77
|
-
* // Result: 'gray'
|
|
78
|
-
* ```
|
|
79
|
-
*
|
|
80
18
|
* @example
|
|
81
|
-
* Working with general string types:
|
|
82
|
-
* ```typescript
|
|
83
|
-
* const userInput: string = getUserInput();
|
|
84
19
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* 'about': '/about',
|
|
88
|
-
* 'contact': '/contact'
|
|
89
|
-
* }, '/404'); // Default required for string type
|
|
90
|
-
* // Type: '/' | '/about' | '/contact' | '/404'
|
|
91
|
-
* ```
|
|
20
|
+
* ```ts
|
|
21
|
+
* type Status = 'draft' | 'review' | 'published';
|
|
92
22
|
*
|
|
93
|
-
*
|
|
94
|
-
* HTTP status code handling:
|
|
95
|
-
* ```typescript
|
|
96
|
-
* type HttpStatus = 200 | 404 | 500;
|
|
97
|
-
* const status: HttpStatus = 404;
|
|
23
|
+
* const status: Status = 'draft';
|
|
98
24
|
*
|
|
99
|
-
* const
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
25
|
+
* const message = match<
|
|
26
|
+
* Status,
|
|
27
|
+
* { draft: string; review: string; published: string }
|
|
28
|
+
* >(status, {
|
|
29
|
+
* draft: 'Work in progress',
|
|
30
|
+
* review: 'Awaiting feedback',
|
|
31
|
+
* published: 'Complete',
|
|
103
32
|
* });
|
|
104
|
-
* // All cases covered, no default needed
|
|
105
|
-
* // Result: { ok: false, message: 'Not Found' }
|
|
106
|
-
* ```
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* Complex discriminated union handling:
|
|
110
|
-
* ```typescript
|
|
111
|
-
* type ApiResponse =
|
|
112
|
-
* | { status: 'loading' }
|
|
113
|
-
* | { status: 'success'; data: string }
|
|
114
|
-
* | { status: 'error'; error: string };
|
|
115
33
|
*
|
|
116
|
-
*
|
|
117
|
-
* match(response.status, {
|
|
118
|
-
* loading: 'Please wait...',
|
|
119
|
-
* success: 'Data loaded successfully!',
|
|
120
|
-
* error: 'Failed to load data'
|
|
121
|
-
* });
|
|
34
|
+
* assert(message === 'Work in progress');
|
|
122
35
|
* ```
|
|
123
36
|
*
|
|
124
|
-
* @
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* 'debug': 'gray',
|
|
130
|
-
* 'info': 'blue',
|
|
131
|
-
* 'warn': 'yellow',
|
|
132
|
-
* 'error': 'red'
|
|
133
|
-
* }, 'black'); // Default for unknown levels
|
|
134
|
-
*
|
|
135
|
-
* const logLevelToIcon = (level: string) => match(level, {
|
|
136
|
-
* 'debug': 'đ',
|
|
137
|
-
* 'info': 'âšī¸',
|
|
138
|
-
* 'warn': 'â ī¸',
|
|
139
|
-
* 'error': 'â'
|
|
140
|
-
* }, 'đ');
|
|
141
|
-
*
|
|
142
|
-
* // Combining matchers
|
|
143
|
-
* const formatLogEntry = (level: string, message: string) => ({
|
|
144
|
-
* color: logLevelToColor(level),
|
|
145
|
-
* icon: logLevelToIcon(level),
|
|
146
|
-
* text: `${logLevelToIcon(level)} ${message}`
|
|
147
|
-
* });
|
|
148
|
-
* ```
|
|
37
|
+
* @param target - The value to match against
|
|
38
|
+
* @param cases - Object mapping possible values to their corresponding results
|
|
39
|
+
* @param defaultValue - Fallback value (required when not all cases are
|
|
40
|
+
* covered)
|
|
41
|
+
* @returns The matched result or default value
|
|
149
42
|
*/
|
|
150
43
|
export declare function match<const Case extends string, const R extends ReadonlyRecord<Case, unknown>>(target: Case, cases: StrictPropertyCheck<R, Case>): R[Case];
|
|
151
44
|
export declare function match<const Case extends string, const R extends UnknownRecord, const D>(target: Case, cases: StrictPropertyCheck<R, Case>, defaultValue: IsLiteralUnionFullyCovered<Case, R> extends true ? never : D): ValueOf<R> | D;
|
|
152
45
|
/**
|
|
46
|
+
* @template T The object type to check.
|
|
47
|
+
* @template ExpectedKeys The union of string literal types representing the
|
|
48
|
+
* allowed keys.
|
|
153
49
|
* @internal
|
|
154
50
|
* Helper type to ensure that an object `T` only contains keys specified in `ExpectedKeys`.
|
|
155
51
|
* If `T` has any keys not in `ExpectedKeys`, this type resolves to `never`.
|
|
156
|
-
* @template T The object type to check.
|
|
157
|
-
* @template ExpectedKeys The union of string literal types representing the allowed keys.
|
|
158
52
|
*/
|
|
159
53
|
type StrictPropertyCheck<T, ExpectedKeys extends PropertyKey> = RelaxedExclude<keyof T, ExpectedKeys> extends never ? T : never;
|
|
160
54
|
/**
|
|
55
|
+
* @template Case A union of string literal types representing the possible
|
|
56
|
+
* cases.
|
|
57
|
+
* @template R A record type.
|
|
161
58
|
* @internal
|
|
162
59
|
* Helper type to check if all cases in `Case` union are fully covered by keys in `R`.
|
|
163
60
|
* This checks bidirectional coverage: all Case members are in R, and no extra keys.
|
|
164
|
-
* @template Case A union of string literal types representing the possible cases.
|
|
165
|
-
* @template R A record type.
|
|
166
61
|
*/
|
|
167
62
|
type AllCasesCovered<Case extends PropertyKey, R> = TypeEq<Case, keyof R> extends true ? true : false;
|
|
168
63
|
/**
|
|
169
|
-
* @internal
|
|
170
|
-
* Helper type to check if Case is a literal union type and all cases are covered.
|
|
171
64
|
* @template Case A union of string literal types.
|
|
172
65
|
* @template R A record type.
|
|
66
|
+
* @internal
|
|
67
|
+
* Helper type to check if Case is a literal union type and all cases are covered.
|
|
173
68
|
*/
|
|
174
69
|
type IsLiteralUnionFullyCovered<Case extends PropertyKey, R extends UnknownRecord> = TypeEq<IsLiteralType<Case>, true> extends true ? AllCasesCovered<Case, R> : false;
|
|
175
70
|
/**
|
|
71
|
+
* @template T The PropertyKey type to check.
|
|
72
|
+
* @returns `true` if `T` is a literal type, `false` otherwise.
|
|
176
73
|
* @internal
|
|
177
74
|
* Helper type to determine if a given PropertyKey `T` is a literal type (e.g., 'a', 1)
|
|
178
75
|
* or a general type (e.g., string, number).
|
|
179
|
-
* @template T The PropertyKey type to check.
|
|
180
|
-
* @returns `true` if `T` is a literal type, `false` otherwise.
|
|
181
76
|
*/
|
|
182
77
|
type IsLiteralType<T extends PropertyKey> = string extends T ? false : number extends T ? false : symbol extends T ? false : true;
|
|
183
78
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.d.mts","sourceRoot":"","sources":["../../src/functional/match.mts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"match.d.mts","sourceRoot":"","sources":["../../src/functional/match.mts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,KAAK,CACnB,KAAK,CAAC,IAAI,SAAS,MAAM,EACzB,KAAK,CAAC,CAAC,SAAS,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,EAC7C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;AAE9D,wBAAgB,KAAK,CACnB,KAAK,CAAC,IAAI,SAAS,MAAM,EACzB,KAAK,CAAC,CAAC,SAAS,aAAa,EAC7B,KAAK,CAAC,CAAC,EAEP,MAAM,EAAE,IAAI,EACZ,KAAK,EAAE,mBAAmB,CAAC,CAAC,EAAE,IAAI,CAAC,EACnC,YAAY,EAAE,0BAA0B,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,CAAC,GACzE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAuBlB;;;;;;;GAOG;AACH,KAAK,mBAAmB,CAAC,CAAC,EAAE,YAAY,SAAS,WAAW,IAC1D,cAAc,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,SAAS,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC;AAElE;;;;;;;GAOG;AACH,KAAK,eAAe,CAAC,IAAI,SAAS,WAAW,EAAE,CAAC,IAC9C,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;AAOpD;;;;;GAKG;AACH,KAAK,0BAA0B,CAC7B,IAAI,SAAS,WAAW,EACxB,CAAC,SAAS,aAAa,IAEvB,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,SAAS,IAAI,GAC1C,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC,GACxB,KAAK,CAAC;AAkBZ;;;;;;GAMG;AACH,KAAK,aAAa,CAAC,CAAC,SAAS,WAAW,IAAI,MAAM,SAAS,CAAC,GACxD,KAAK,GACL,MAAM,SAAS,CAAC,GACd,KAAK,GACL,MAAM,SAAS,CAAC,GACd,KAAK,GACL,IAAI,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.mjs","sources":["../../src/functional/match.mts"],"sourcesContent":[null],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"match.mjs","sources":["../../src/functional/match.mts"],"sourcesContent":[null],"names":[],"mappings":";;AA4DM,SAAU,KAAK,CAKnB,GAAG,IAEmD,EAAA;AAEtD,IAAA,QAAQ,IAAI,CAAC,MAAM;QACjB,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI;AAC5B,YAAA,OAAO,KAAK,CAAC,MAAM,CAAC;;QAEtB,KAAK,CAAC,EAAE;YACN,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,GAAG,IAAI;AAC1C,YAAA,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,YAAY;;;AAGlE;;;;"}
|