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
|
@@ -3,49 +3,32 @@ import { asUint32 } from '../number/index.mjs';
|
|
|
3
3
|
import { tp } from '../others/index.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Interface for an immutable map with custom key mapping and
|
|
6
|
+
* Interface for an immutable map with custom key mapping and lookup operations.
|
|
7
7
|
*
|
|
8
|
-
* IMapMapped allows you to use complex objects as keys by providing
|
|
9
|
-
* that convert between your custom key type `K` and a
|
|
10
|
-
* be efficiently stored in JavaScript's
|
|
11
|
-
* on maps with complex keys while
|
|
8
|
+
* IMapMapped allows you to use complex objects as keys by providing
|
|
9
|
+
* transformation functions that convert between your custom key type `K` and a
|
|
10
|
+
* primitive `MapSetKeyType` `KM` that can be efficiently stored in JavaScript's
|
|
11
|
+
* native Map. This enables operations on maps with complex keys while
|
|
12
|
+
* maintaining type safety and immutability.
|
|
12
13
|
*
|
|
13
14
|
* **Key Features:**
|
|
14
|
-
*
|
|
15
|
-
* - **
|
|
15
|
+
*
|
|
16
|
+
* - **Custom Key Types**: Use any type as keys by providing `toKey`/`fromKey`
|
|
17
|
+
* functions
|
|
16
18
|
* - **Immutable**: All operations return new instances, preserving immutability
|
|
17
19
|
* - **Type Safe**: Full TypeScript support with generic key/value types
|
|
18
20
|
*
|
|
19
21
|
* **Performance Characteristics:**
|
|
20
|
-
*
|
|
21
|
-
* -
|
|
22
|
+
*
|
|
23
|
+
* - get/has: O(1) average case (plus key transformation overhead)
|
|
24
|
+
* - set/delete: O(n) due to copying for immutability (plus key transformation
|
|
25
|
+
* overhead)
|
|
22
26
|
* - map/filter operations: O(n)
|
|
23
|
-
* -
|
|
27
|
+
* - iteration: O(n) (plus key transformation overhead)
|
|
24
28
|
*
|
|
25
29
|
* @template K The type of the custom keys in the map.
|
|
26
30
|
* @template V The type of the values in the map.
|
|
27
31
|
* @template KM The type of the mapped primitive keys (string, number, etc.).
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* // Example with complex object keys
|
|
32
|
-
* type UserId = { department: string; employeeId: number };
|
|
33
|
-
*
|
|
34
|
-
* // Define transformation functions
|
|
35
|
-
* const userIdToKey = (id: UserId): string => `${id.department}:${id.employeeId}`;
|
|
36
|
-
* const keyToUserId = (key: string): UserId => {
|
|
37
|
-
* const [department, employeeId] = key.split(':');
|
|
38
|
-
* return { department, employeeId: Number(employeeId) };
|
|
39
|
-
* };
|
|
40
|
-
*
|
|
41
|
-
* declare const userMap: IMapMapped<UserId, UserProfile, string>;
|
|
42
|
-
*
|
|
43
|
-
* // All operations work with the complex key type
|
|
44
|
-
* const userId: UserId = { department: "engineering", employeeId: 123 };
|
|
45
|
-
* const hasUser = userMap.has(userId); // O(1)
|
|
46
|
-
* const profile = userMap.get(userId).unwrapOr(defaultProfile); // O(1)
|
|
47
|
-
* const updated = userMap.set(userId, newProfile); // O(1) - returns new IMapMapped
|
|
48
|
-
* ```
|
|
49
32
|
*/
|
|
50
33
|
type IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{
|
|
51
34
|
// Getting information
|
|
@@ -55,6 +38,7 @@ type IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{
|
|
|
55
38
|
|
|
56
39
|
/**
|
|
57
40
|
* Checks if a key exists in the map.
|
|
41
|
+
*
|
|
58
42
|
* @param key The key to check.
|
|
59
43
|
* @returns `true` if the key exists, `false` otherwise.
|
|
60
44
|
*/
|
|
@@ -62,8 +46,10 @@ type IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{
|
|
|
62
46
|
|
|
63
47
|
/**
|
|
64
48
|
* Retrieves the value associated with a key.
|
|
49
|
+
*
|
|
65
50
|
* @param key The key to retrieve.
|
|
66
|
-
* @returns The value associated with the key wrapped with `Optional.some`, or
|
|
51
|
+
* @returns The value associated with the key wrapped with `Optional.some`, or
|
|
52
|
+
* `Optional.none` if the key does not exist.
|
|
67
53
|
*/
|
|
68
54
|
get: (key: K) => Optional<V>;
|
|
69
55
|
|
|
@@ -71,13 +57,16 @@ type IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{
|
|
|
71
57
|
|
|
72
58
|
/**
|
|
73
59
|
* Checks if all elements in the map satisfy a predicate.
|
|
60
|
+
*
|
|
74
61
|
* @param predicate A function to test each key-value pair.
|
|
75
62
|
* @returns `true` if all elements satisfy the predicate, `false` otherwise.
|
|
76
63
|
*/
|
|
77
64
|
every: ((predicate: (value: V, key: K) => boolean) => boolean) &
|
|
78
65
|
/**
|
|
79
|
-
* Checks if all elements in the map satisfy a type predicate.
|
|
80
|
-
*
|
|
66
|
+
* Checks if all elements in the map satisfy a type predicate. Narrows the
|
|
67
|
+
* type of values in the map if the predicate returns true for all
|
|
68
|
+
* elements.
|
|
69
|
+
*
|
|
81
70
|
* @template W The narrowed type of the values.
|
|
82
71
|
* @param predicate A type predicate function.
|
|
83
72
|
* @returns `true` if all elements satisfy the predicate, `false` otherwise.
|
|
@@ -88,14 +77,18 @@ type IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{
|
|
|
88
77
|
|
|
89
78
|
/**
|
|
90
79
|
* Checks if at least one element in the map satisfies a predicate.
|
|
80
|
+
*
|
|
91
81
|
* @param predicate A function to test each key-value pair.
|
|
92
|
-
* @returns `true` if at least one element satisfies the predicate, `false`
|
|
82
|
+
* @returns `true` if at least one element satisfies the predicate, `false`
|
|
83
|
+
* otherwise.
|
|
93
84
|
*/
|
|
94
85
|
some: (predicate: (value: V, key: K) => boolean) => boolean;
|
|
95
86
|
|
|
96
87
|
// Mutation
|
|
88
|
+
|
|
97
89
|
/**
|
|
98
90
|
* Deletes a key-value pair from the map.
|
|
91
|
+
*
|
|
99
92
|
* @param key The key to delete.
|
|
100
93
|
* @returns A new IMapMapped instance without the specified key.
|
|
101
94
|
*/
|
|
@@ -103,6 +96,7 @@ type IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{
|
|
|
103
96
|
|
|
104
97
|
/**
|
|
105
98
|
* Sets a key-value pair in the map.
|
|
99
|
+
*
|
|
106
100
|
* @param key The key to set.
|
|
107
101
|
* @param value The value to associate with the key.
|
|
108
102
|
* @returns A new IMapMapped instance with the specified key-value pair.
|
|
@@ -111,14 +105,17 @@ type IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{
|
|
|
111
105
|
|
|
112
106
|
/**
|
|
113
107
|
* Updates the value associated with a key using an updater function.
|
|
108
|
+
*
|
|
114
109
|
* @param key The key whose value to update.
|
|
115
|
-
* @param updater A function that takes the current value and returns the new
|
|
110
|
+
* @param updater A function that takes the current value and returns the new
|
|
111
|
+
* value.
|
|
116
112
|
* @returns A new IMapMapped instance with the updated value.
|
|
117
113
|
*/
|
|
118
114
|
update: (key: K, updater: (value: V) => V) => IMapMapped<K, V, KM>;
|
|
119
115
|
|
|
120
116
|
/**
|
|
121
117
|
* Applies a series of mutations to the map.
|
|
118
|
+
*
|
|
122
119
|
* @param actions An array of mutation actions (delete, set, or update).
|
|
123
120
|
* @returns A new IMapMapped instance with all mutations applied.
|
|
124
121
|
*/
|
|
@@ -134,6 +131,7 @@ type IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{
|
|
|
134
131
|
|
|
135
132
|
/**
|
|
136
133
|
* Maps the values of the map to new values.
|
|
134
|
+
*
|
|
137
135
|
* @template V2 The type of the new values.
|
|
138
136
|
* @param mapFn A function that maps a value and key to a new value.
|
|
139
137
|
* @returns A new IMapMapped instance with mapped values.
|
|
@@ -141,8 +139,9 @@ type IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{
|
|
|
141
139
|
map: <V2>(mapFn: (value: V, key: K) => V2) => IMapMapped<K, V2, KM>;
|
|
142
140
|
|
|
143
141
|
/**
|
|
144
|
-
* Maps the keys of the map to new keys.
|
|
145
|
-
*
|
|
142
|
+
* Maps the keys of the map to new keys. Note: The key type cannot be changed
|
|
143
|
+
* because `toKey` and `fromKey` would become unusable.
|
|
144
|
+
*
|
|
146
145
|
* @param mapFn A function that maps a key to a new key of the same type.
|
|
147
146
|
* @returns A new IMapMapped instance with mapped keys.
|
|
148
147
|
*/
|
|
@@ -150,8 +149,10 @@ type IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{
|
|
|
150
149
|
|
|
151
150
|
/**
|
|
152
151
|
* Maps the entries (key-value pairs) of the map to new entries.
|
|
152
|
+
*
|
|
153
153
|
* @template V2 The type of the new values in the entries.
|
|
154
|
-
* @param mapFn A function that maps an entry to a new entry (key must remain
|
|
154
|
+
* @param mapFn A function that maps an entry to a new entry (key must remain
|
|
155
|
+
* the same type).
|
|
155
156
|
* @returns A new IMapMapped instance with mapped entries.
|
|
156
157
|
*/
|
|
157
158
|
mapEntries: <V2>(
|
|
@@ -162,6 +163,7 @@ type IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{
|
|
|
162
163
|
|
|
163
164
|
/**
|
|
164
165
|
* Executes a callback function for each key-value pair in the map.
|
|
166
|
+
*
|
|
165
167
|
* @param callbackfn A function to execute for each element.
|
|
166
168
|
*/
|
|
167
169
|
forEach: (callbackfn: (value: V, key: K) => void) => void;
|
|
@@ -170,18 +172,21 @@ type IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{
|
|
|
170
172
|
|
|
171
173
|
/**
|
|
172
174
|
* Returns an iterator for the keys in the map.
|
|
175
|
+
*
|
|
173
176
|
* @returns An iterable iterator of keys.
|
|
174
177
|
*/
|
|
175
178
|
keys: () => IterableIterator<K>;
|
|
176
179
|
|
|
177
180
|
/**
|
|
178
181
|
* Returns an iterator for the values in the map.
|
|
182
|
+
*
|
|
179
183
|
* @returns An iterable iterator of values.
|
|
180
184
|
*/
|
|
181
185
|
values: () => IterableIterator<V>;
|
|
182
186
|
|
|
183
187
|
/**
|
|
184
188
|
* Returns an iterator for the entries (key-value pairs) in the map.
|
|
189
|
+
*
|
|
185
190
|
* @returns An iterable iterator of entries.
|
|
186
191
|
*/
|
|
187
192
|
entries: () => IterableIterator<readonly [K, V]>;
|
|
@@ -190,52 +195,62 @@ type IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{
|
|
|
190
195
|
|
|
191
196
|
/**
|
|
192
197
|
* Converts the keys of the map to an array.
|
|
198
|
+
*
|
|
193
199
|
* @returns A readonly array of keys.
|
|
194
200
|
*/
|
|
195
201
|
toKeysArray: () => readonly K[];
|
|
196
202
|
|
|
197
203
|
/**
|
|
198
204
|
* Converts the values of the map to an array.
|
|
205
|
+
*
|
|
199
206
|
* @returns A readonly array of values.
|
|
200
207
|
*/
|
|
201
208
|
toValuesArray: () => readonly V[];
|
|
202
209
|
|
|
203
210
|
/**
|
|
204
211
|
* Converts the entries (key-value pairs) of the map to an array.
|
|
212
|
+
*
|
|
205
213
|
* @returns A readonly array of entries.
|
|
206
214
|
*/
|
|
207
215
|
toEntriesArray: () => readonly (readonly [K, V])[];
|
|
208
216
|
|
|
209
217
|
/**
|
|
210
|
-
* Converts the map to an array of entries (key-value pairs).
|
|
211
|
-
*
|
|
218
|
+
* Converts the map to an array of entries (key-value pairs). Alias for
|
|
219
|
+
* `toEntriesArray`.
|
|
220
|
+
*
|
|
212
221
|
* @returns A readonly array of entries.
|
|
213
222
|
*/
|
|
214
223
|
toArray: () => readonly (readonly [K, V])[];
|
|
215
224
|
|
|
216
225
|
/**
|
|
217
226
|
* Returns the underlying readonly JavaScript Map.
|
|
227
|
+
*
|
|
218
228
|
* @returns The raw ReadonlyMap instance.
|
|
219
229
|
*/
|
|
220
230
|
toRawMap: () => ReadonlyMap<KM, V>;
|
|
221
231
|
}>;
|
|
222
232
|
|
|
223
233
|
/**
|
|
224
|
-
* Represents an immutable map with custom key transformation and
|
|
234
|
+
* Represents an immutable map with custom key transformation and
|
|
235
|
+
* high-performance operations.
|
|
225
236
|
*
|
|
226
|
-
* IMapMapped is a specialized persistent data structure that enables using
|
|
227
|
-
* while maintaining the performance benefits of
|
|
228
|
-
*
|
|
229
|
-
* that
|
|
237
|
+
* IMapMapped is a specialized persistent data structure that enables using
|
|
238
|
+
* complex objects as map keys while maintaining the performance benefits of
|
|
239
|
+
* JavaScript's native Map. It achieves this by requiring bidirectional
|
|
240
|
+
* transformation functions that convert between your custom key type and a
|
|
241
|
+
* primitive type that can be efficiently stored and compared.
|
|
230
242
|
*
|
|
231
243
|
* **Key Features:**
|
|
244
|
+
*
|
|
232
245
|
* - **Complex Keys**: Use objects, arrays, or any custom type as map keys
|
|
233
|
-
* - **High Performance**: O(1) operations through efficient key transformation
|
|
234
246
|
* - **Immutable**: All mutation operations return new instances
|
|
235
|
-
* - **Type Safe**: Full TypeScript support with compile-time key/value type
|
|
236
|
-
*
|
|
247
|
+
* - **Type Safe**: Full TypeScript support with compile-time key/value type
|
|
248
|
+
* checking
|
|
249
|
+
* - **Bidirectional**: Maintains ability to reconstruct original keys from mapped
|
|
250
|
+
* keys
|
|
237
251
|
*
|
|
238
252
|
* **Use Cases:**
|
|
253
|
+
*
|
|
239
254
|
* - Maps with composite keys (e.g., coordinates, user IDs with metadata)
|
|
240
255
|
* - Caching with complex cache keys
|
|
241
256
|
* - State management where entities have multi-part identifiers
|
|
@@ -244,75 +259,22 @@ type IMapMappedInterface<K, V, KM extends MapSetKeyType> = Readonly<{
|
|
|
244
259
|
* @template K The type of the custom keys in the map.
|
|
245
260
|
* @template V The type of the values in the map.
|
|
246
261
|
* @template KM The type of the mapped primitive keys (string, number, etc.).
|
|
247
|
-
*
|
|
248
|
-
* @example
|
|
249
|
-
* ```typescript
|
|
250
|
-
* // Example: Product catalog with composite keys
|
|
251
|
-
* type ProductKey = { brand: string; model: string; year: number };
|
|
252
|
-
* type Product = { name: string; price: number; inStock: boolean };
|
|
253
|
-
*
|
|
254
|
-
* // Define bidirectional transformation functions
|
|
255
|
-
* const productKeyToString = (key: ProductKey): string =>
|
|
256
|
-
* `${key.brand}|${key.model}|${key.year}`;
|
|
257
|
-
*
|
|
258
|
-
* const stringToProductKey = (str: string): ProductKey => {
|
|
259
|
-
* const [brand, model, yearStr] = str.split('|');
|
|
260
|
-
* return { brand, model, year: Number(yearStr) };
|
|
261
|
-
* };
|
|
262
|
-
*
|
|
263
|
-
* // Create a map with complex keys
|
|
264
|
-
* let catalog = IMapMapped.create<ProductKey, Product, string>(
|
|
265
|
-
* [],
|
|
266
|
-
* productKeyToString,
|
|
267
|
-
* stringToProductKey
|
|
268
|
-
* );
|
|
269
|
-
*
|
|
270
|
-
* // Use complex objects as keys naturally
|
|
271
|
-
* const toyotaCamry2023: ProductKey = { brand: "Toyota", model: "Camry", year: 2023 };
|
|
272
|
-
* const hondaAccord2022: ProductKey = { brand: "Honda", model: "Accord", year: 2022 };
|
|
273
|
-
*
|
|
274
|
-
* catalog = catalog
|
|
275
|
-
* .set(toyotaCamry2023, { name: "Toyota Camry 2023", price: 28000, inStock: true })
|
|
276
|
-
* .set(hondaAccord2022, { name: "Honda Accord 2022", price: 26500, inStock: false });
|
|
277
|
-
*
|
|
278
|
-
* // All operations work with the original key type
|
|
279
|
-
* console.log(catalog.get(toyotaCamry2023).unwrapOr(notFound).name);
|
|
280
|
-
* // Output: "Toyota Camry 2023"
|
|
281
|
-
*
|
|
282
|
-
* console.log(catalog.has(hondaAccord2022)); // Output: true
|
|
283
|
-
* console.log(catalog.size); // Output: 2
|
|
284
|
-
*
|
|
285
|
-
* // Iteration preserves original key types
|
|
286
|
-
* for (const [productKey, product] of catalog) {
|
|
287
|
-
* console.log(`${productKey.brand} ${productKey.model} (${productKey.year}): $${product.price}`);
|
|
288
|
-
* }
|
|
289
|
-
* // Output:
|
|
290
|
-
* // Toyota Camry (2023): $28000
|
|
291
|
-
* // Honda Accord (2022): $26500
|
|
292
|
-
*
|
|
293
|
-
* // Functional transformations work seamlessly
|
|
294
|
-
* const discountedCatalog = catalog.map((product, key) => ({
|
|
295
|
-
* ...product,
|
|
296
|
-
* price: Math.round(product.price * 0.9) // 10% discount
|
|
297
|
-
* }));
|
|
298
|
-
* ```
|
|
299
262
|
*/
|
|
300
263
|
export type IMapMapped<K, V, KM extends MapSetKeyType> = Iterable<
|
|
301
264
|
readonly [K, V]
|
|
302
265
|
> &
|
|
303
266
|
IMapMappedInterface<K, V, KM>;
|
|
304
267
|
|
|
305
|
-
/**
|
|
306
|
-
* Provides utility functions for IMapMapped.
|
|
307
|
-
*/
|
|
268
|
+
/** Provides utility functions for IMapMapped. */
|
|
308
269
|
export namespace IMapMapped {
|
|
309
270
|
/**
|
|
310
271
|
* Creates a new IMapMapped instance with custom key transformation functions.
|
|
311
272
|
*
|
|
312
|
-
* This factory function creates an immutable map that can use complex objects
|
|
313
|
-
* by providing bidirectional transformation functions. The `toKey`
|
|
314
|
-
* your custom key type to a primitive type that can be
|
|
315
|
-
* `fromKey` reconstructs the original key type for
|
|
273
|
+
* This factory function creates an immutable map that can use complex objects
|
|
274
|
+
* as keys by providing bidirectional transformation functions. The `toKey`
|
|
275
|
+
* function converts your custom key type to a primitive type that can be
|
|
276
|
+
* efficiently stored, while `fromKey` reconstructs the original key type for
|
|
277
|
+
* iteration and access.
|
|
316
278
|
*
|
|
317
279
|
* **Performance:** O(n) where n is the number of entries in the iterable.
|
|
318
280
|
*
|
|
@@ -320,83 +282,13 @@ export namespace IMapMapped {
|
|
|
320
282
|
* @template V The type of the values.
|
|
321
283
|
* @template KM The type of the mapped primitive keys.
|
|
322
284
|
* @param iterable An iterable of key-value pairs using the custom key type.
|
|
323
|
-
* @param toKey A function that converts a custom key `K` to a primitive key
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
* ```typescript
|
|
331
|
-
* // Example 1: Geographic coordinates as keys
|
|
332
|
-
* type Coordinate = { lat: number; lng: number };
|
|
333
|
-
* type LocationInfo = { name: string; population: number };
|
|
334
|
-
*
|
|
335
|
-
* const coordToString = (coord: Coordinate): string => `${coord.lat},${coord.lng}`;
|
|
336
|
-
* const stringToCoord = (str: string): Coordinate => {
|
|
337
|
-
* const [lat, lng] = str.split(',').map(Number);
|
|
338
|
-
* return { lat, lng };
|
|
339
|
-
* };
|
|
340
|
-
*
|
|
341
|
-
* const locationMap = IMapMapped.create<Coordinate, LocationInfo, string>(
|
|
342
|
-
* [
|
|
343
|
-
* [{ lat: 40.7128, lng: -74.0060 }, { name: "New York", population: 8000000 }],
|
|
344
|
-
* [{ lat: 34.0522, lng: -118.2437 }, { name: "Los Angeles", population: 4000000 }]
|
|
345
|
-
* ],
|
|
346
|
-
* coordToString,
|
|
347
|
-
* stringToCoord
|
|
348
|
-
* );
|
|
349
|
-
*
|
|
350
|
-
* const nyCoord = { lat: 40.7128, lng: -74.0060 };
|
|
351
|
-
* console.log(locationMap.get(nyCoord).unwrap().name); // Output: "New York"
|
|
352
|
-
*
|
|
353
|
-
* // Example 2: Multi-part business keys
|
|
354
|
-
* type OrderId = { customerId: string; year: number; orderNumber: number };
|
|
355
|
-
*
|
|
356
|
-
* const orderIdToKey = (id: OrderId): string =>
|
|
357
|
-
* `${id.customerId}:${id.year}:${id.orderNumber}`;
|
|
358
|
-
*
|
|
359
|
-
* const keyToOrderId = (key: string): OrderId => {
|
|
360
|
-
* const [customerId, yearStr, orderNumStr] = key.split(':');
|
|
361
|
-
* return {
|
|
362
|
-
* customerId,
|
|
363
|
-
* year: Number(yearStr),
|
|
364
|
-
* orderNumber: Number(orderNumStr)
|
|
365
|
-
* };
|
|
366
|
-
* };
|
|
367
|
-
*
|
|
368
|
-
* const orderMap = IMapMapped.create<OrderId, Order, string>(
|
|
369
|
-
* [],
|
|
370
|
-
* orderIdToKey,
|
|
371
|
-
* keyToOrderId
|
|
372
|
-
* );
|
|
373
|
-
*
|
|
374
|
-
* // Example 3: Simple case with string keys (identity transformation)
|
|
375
|
-
* const simpleMap = IMapMapped.create<string, number, string>(
|
|
376
|
-
* [["key1", 100], ["key2", 200]],
|
|
377
|
-
* (s) => s, // identity function
|
|
378
|
-
* (s) => s // identity function
|
|
379
|
-
* );
|
|
380
|
-
*
|
|
381
|
-
* // Example 4: From existing data structures
|
|
382
|
-
* const existingEntries = new Map([
|
|
383
|
-
* [{ id: 1, type: "user" }, { name: "Alice", active: true }],
|
|
384
|
-
* [{ id: 2, type: "user" }, { name: "Bob", active: false }]
|
|
385
|
-
* ]);
|
|
386
|
-
*
|
|
387
|
-
* type EntityKey = { id: number; type: string };
|
|
388
|
-
* const entityKeyToString = (key: EntityKey): string => `${key.type}_${key.id}`;
|
|
389
|
-
* const stringToEntityKey = (str: string): EntityKey => {
|
|
390
|
-
* const [type, idStr] = str.split('_');
|
|
391
|
-
* return { type, id: Number(idStr) };
|
|
392
|
-
* };
|
|
393
|
-
*
|
|
394
|
-
* const entityMap = IMapMapped.create<EntityKey, Entity, string>(
|
|
395
|
-
* existingEntries,
|
|
396
|
-
* entityKeyToString,
|
|
397
|
-
* stringToEntityKey
|
|
398
|
-
* );
|
|
399
|
-
* ```
|
|
285
|
+
* @param toKey A function that converts a custom key `K` to a primitive key
|
|
286
|
+
* `KM`. This function must be deterministic and produce unique values for
|
|
287
|
+
* unique keys.
|
|
288
|
+
* @param fromKey A function that converts a primitive key `KM` back to the
|
|
289
|
+
* custom key `K`. This should be the inverse of `toKey`.
|
|
290
|
+
* @returns A new IMapMapped instance containing all entries from the
|
|
291
|
+
* iterable.
|
|
400
292
|
*/
|
|
401
293
|
export const create = <K, V, KM extends MapSetKeyType>(
|
|
402
294
|
iterable: Iterable<readonly [K, V]>,
|
|
@@ -408,10 +300,11 @@ export namespace IMapMapped {
|
|
|
408
300
|
/**
|
|
409
301
|
* Checks if two IMapMapped instances are structurally equal.
|
|
410
302
|
*
|
|
411
|
-
* Two IMapMapped instances are considered equal if they have the same size
|
|
412
|
-
* exactly the same key-value pairs. The comparison is performed
|
|
413
|
-
* keys and values, so the transformation functions
|
|
414
|
-
* Values are compared using
|
|
303
|
+
* Two IMapMapped instances are considered equal if they have the same size
|
|
304
|
+
* and contain exactly the same key-value pairs. The comparison is performed
|
|
305
|
+
* on the underlying mapped keys and values, so the transformation functions
|
|
306
|
+
* themselves don't need to be identical. Values are compared using
|
|
307
|
+
* JavaScript's `===` operator.
|
|
415
308
|
*
|
|
416
309
|
* **Performance:** O(n) where n is the size of the smaller map.
|
|
417
310
|
*
|
|
@@ -420,70 +313,8 @@ export namespace IMapMapped {
|
|
|
420
313
|
* @template KM The type of the mapped primitive keys.
|
|
421
314
|
* @param a The first IMapMapped instance to compare.
|
|
422
315
|
* @param b The second IMapMapped instance to compare.
|
|
423
|
-
* @returns `true` if the maps contain exactly the same key-value pairs,
|
|
424
|
-
*
|
|
425
|
-
* @example
|
|
426
|
-
* ```typescript
|
|
427
|
-
* // Example with coordinate keys
|
|
428
|
-
* type Point = { x: number; y: number };
|
|
429
|
-
* const pointToString = (p: Point): string => `${p.x},${p.y}`;
|
|
430
|
-
* const stringToPoint = (s: string): Point => {
|
|
431
|
-
* const [x, y] = s.split(',').map(Number);
|
|
432
|
-
* return { x, y };
|
|
433
|
-
* };
|
|
434
|
-
*
|
|
435
|
-
* const map1 = IMapMapped.create<Point, string, string>(
|
|
436
|
-
* [[{ x: 1, y: 2 }, "point1"], [{ x: 3, y: 4 }, "point2"]],
|
|
437
|
-
* pointToString,
|
|
438
|
-
* stringToPoint
|
|
439
|
-
* );
|
|
440
|
-
*
|
|
441
|
-
* const map2 = IMapMapped.create<Point, string, string>(
|
|
442
|
-
* [[{ x: 1, y: 2 }, "point1"], [{ x: 3, y: 4 }, "point2"]], // Same content
|
|
443
|
-
* pointToString,
|
|
444
|
-
* stringToPoint
|
|
445
|
-
* );
|
|
446
|
-
*
|
|
447
|
-
* const map3 = IMapMapped.create<Point, string, string>(
|
|
448
|
-
* [[{ x: 1, y: 2 }, "point1"], [{ x: 3, y: 4 }, "different"]], // Different value
|
|
449
|
-
* pointToString,
|
|
450
|
-
* stringToPoint
|
|
451
|
-
* );
|
|
452
|
-
*
|
|
453
|
-
* console.log(IMapMapped.equal(map1, map2)); // true
|
|
454
|
-
* console.log(IMapMapped.equal(map1, map3)); // false (different value)
|
|
455
|
-
*
|
|
456
|
-
* // Order doesn't matter for equality
|
|
457
|
-
* const map4 = IMapMapped.create<Point, string, string>(
|
|
458
|
-
* [[{ x: 3, y: 4 }, "point2"], [{ x: 1, y: 2 }, "point1"]], // Different order
|
|
459
|
-
* pointToString,
|
|
460
|
-
* stringToPoint
|
|
461
|
-
* );
|
|
462
|
-
*
|
|
463
|
-
* console.log(IMapMapped.equal(map1, map4)); // true
|
|
464
|
-
*
|
|
465
|
-
* // Different transformation functions but same logical content
|
|
466
|
-
* const alternativePointToString = (p: Point): string => `(${p.x},${p.y})`; // Different format
|
|
467
|
-
* const alternativeStringToPoint = (s: string): Point => {
|
|
468
|
-
* const match = s.match(/\((\d+),(\d+)\)/);
|
|
469
|
-
* return { x: Number(match![1]), y: Number(match![2]) };
|
|
470
|
-
* };
|
|
471
|
-
*
|
|
472
|
-
* const map5 = IMapMapped.create<Point, string, string>(
|
|
473
|
-
* [[{ x: 1, y: 2 }, "point1"], [{ x: 3, y: 4 }, "point2"]],
|
|
474
|
-
* alternativePointToString,
|
|
475
|
-
* alternativeStringToPoint
|
|
476
|
-
* );
|
|
477
|
-
*
|
|
478
|
-
* // This would be false because the underlying mapped keys are different
|
|
479
|
-
* // even though the logical content is the same
|
|
480
|
-
* console.log(IMapMapped.equal(map1, map5)); // false
|
|
481
|
-
*
|
|
482
|
-
* // Empty maps
|
|
483
|
-
* const empty1 = IMapMapped.create<Point, string, string>([], pointToString, stringToPoint);
|
|
484
|
-
* const empty2 = IMapMapped.create<Point, string, string>([], pointToString, stringToPoint);
|
|
485
|
-
* console.log(IMapMapped.equal(empty1, empty2)); // true
|
|
486
|
-
* ```
|
|
316
|
+
* @returns `true` if the maps contain exactly the same key-value pairs,
|
|
317
|
+
* `false` otherwise.
|
|
487
318
|
*/
|
|
488
319
|
export const equal = <K, V, KM extends MapSetKeyType>(
|
|
489
320
|
a: IMapMapped<K, V, KM>,
|
|
@@ -492,13 +323,16 @@ export namespace IMapMapped {
|
|
|
492
323
|
}
|
|
493
324
|
|
|
494
325
|
/**
|
|
495
|
-
* Internal class implementation for IMapMapped providing immutable map
|
|
326
|
+
* Internal class implementation for IMapMapped providing immutable map
|
|
327
|
+
* operations with key transformation.
|
|
496
328
|
*
|
|
497
|
-
* This class implements the IMapMapped interface by maintaining a JavaScript
|
|
498
|
-
* internally while exposing an API that works with
|
|
499
|
-
* custom
|
|
329
|
+
* This class implements the IMapMapped interface by maintaining a JavaScript
|
|
330
|
+
* Map with primitive keys internally while exposing an API that works with
|
|
331
|
+
* custom key types. The transformation between custom and primitive keys is
|
|
332
|
+
* handled transparently through the provided `toKey` and `fromKey` functions.
|
|
500
333
|
*
|
|
501
334
|
* **Implementation Details:**
|
|
335
|
+
*
|
|
502
336
|
* - Uses ReadonlyMap<KM, V> internally where KM is the primitive key type
|
|
503
337
|
* - Stores transformation functions for bidirectional key conversion
|
|
504
338
|
* - Implements copy-on-write semantics for efficiency
|
|
@@ -524,12 +358,12 @@ class IMapMappedClass<K, V, KM extends MapSetKeyType>
|
|
|
524
358
|
*
|
|
525
359
|
* @param iterable An iterable of key-value pairs using the custom key type K.
|
|
526
360
|
* @param toKey A function that converts a custom key K to a primitive key KM.
|
|
527
|
-
*
|
|
528
|
-
* @param fromKey A function that converts a primitive key KM back to the
|
|
529
|
-
*
|
|
361
|
+
* Must be deterministic and produce unique values for unique keys.
|
|
362
|
+
* @param fromKey A function that converts a primitive key KM back to the
|
|
363
|
+
* custom key K. Should be the inverse of the toKey function.
|
|
530
364
|
* @param showNotFoundMessage Whether to log warning messages when operations
|
|
531
|
-
*
|
|
532
|
-
*
|
|
365
|
+
* are performed on non-existent keys. Useful for debugging. Defaults to
|
|
366
|
+
* false for production use.
|
|
533
367
|
* @internal Use IMapMapped.create() instead of calling this constructor directly.
|
|
534
368
|
*/
|
|
535
369
|
constructor(
|
|
@@ -565,8 +399,10 @@ class IMapMappedClass<K, V, KM extends MapSetKeyType>
|
|
|
565
399
|
every<W extends V>(
|
|
566
400
|
predicate: (value: V, key: K) => value is W,
|
|
567
401
|
): this is IMapMapped<K, W, KM>;
|
|
402
|
+
|
|
568
403
|
/** @inheritdoc */
|
|
569
404
|
every(predicate: (value: V, key: K) => boolean): boolean;
|
|
405
|
+
|
|
570
406
|
/** @inheritdoc */
|
|
571
407
|
every(predicate: (value: V, key: K) => boolean): boolean {
|
|
572
408
|
for (const [k, v] of this.entries()) {
|
|
@@ -744,9 +580,7 @@ class IMapMappedClass<K, V, KM extends MapSetKeyType>
|
|
|
744
580
|
}
|
|
745
581
|
}
|
|
746
582
|
|
|
747
|
-
/**
|
|
748
|
-
* @inheritdoc
|
|
749
|
-
*/
|
|
583
|
+
/** @inheritdoc */
|
|
750
584
|
*[Symbol.iterator](): Iterator<readonly [K, V]> {
|
|
751
585
|
for (const e of this.entries()) {
|
|
752
586
|
yield e;
|