ts-data-forge 3.2.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 +45 -21
- 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 +3 -0
- package/dist/entry-point.d.mts.map +1 -0
- package/dist/entry-point.mjs +62 -0
- package/dist/entry-point.mjs.map +1 -0
- 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 +14 -127
- 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/dist/types.d.mts +1 -1
- package/package.json +54 -50
- 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 +2 -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-record.test.mts +0 -1
- 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 +15 -127
- package/src/others/unknown-to-string.test.mts +14 -2
- 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
|
@@ -1,68 +1,112 @@
|
|
|
1
1
|
import { Optional } from '../functional/index.mjs';
|
|
2
2
|
/**
|
|
3
|
-
* Interface for an immutable map with
|
|
3
|
+
* Interface for an immutable map with lookup operations and functional
|
|
4
|
+
* programming patterns.
|
|
4
5
|
*
|
|
5
|
-
* This interface defines all methods and properties available on IMap
|
|
6
|
-
* that modify the map return new IMap instances,
|
|
7
|
-
*
|
|
6
|
+
* This interface defines all methods and properties available on IMap
|
|
7
|
+
* instances. All operations that modify the map return new IMap instances,
|
|
8
|
+
* preserving immutability. The underlying implementation uses JavaScript's
|
|
9
|
+
* native Map but creates copies on mutations to maintain immutability.
|
|
8
10
|
*
|
|
9
11
|
* **Immutability Guarantees:**
|
|
12
|
+
*
|
|
10
13
|
* - All mutation operations (set, delete, update) return new IMap instances
|
|
11
14
|
* - Original IMap instances are never modified
|
|
12
15
|
* - Safe for concurrent access and functional programming patterns
|
|
13
16
|
*
|
|
14
17
|
* **Performance Characteristics:**
|
|
15
|
-
*
|
|
16
|
-
* -
|
|
18
|
+
*
|
|
19
|
+
* - get/has: O(1) average case
|
|
20
|
+
* - set/delete: O(n) due to copying for immutability
|
|
17
21
|
* - map/filter operations: O(n)
|
|
18
|
-
* -
|
|
22
|
+
* - iteration: O(n)
|
|
19
23
|
*
|
|
20
|
-
* @template K The type of the keys in the map. Must extend MapSetKeyType
|
|
24
|
+
* @template K The type of the keys in the map. Must extend MapSetKeyType
|
|
25
|
+
* (string, number, boolean, etc.)
|
|
21
26
|
* @template V The type of the values in the map.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* // This is a type alias describing an interface, so it's not directly instantiated.
|
|
26
|
-
* // See IMap.create for examples of creating IMap instances that conform to this interface.
|
|
27
|
-
*
|
|
28
|
-
* // Example of how you might use a variable that implements this structure:
|
|
29
|
-
* declare const userMap: IMap<string, User>;
|
|
30
|
-
*
|
|
31
|
-
* // Immutable operations - original map is never modified
|
|
32
|
-
* const hasUser = userMap.has("alice"); // O(1)
|
|
33
|
-
* const user = userMap.get("alice").unwrapOr(defaultUser); // O(1)
|
|
34
|
-
* const newMap = userMap.set("bob", newUser); // O(1) - returns new IMap
|
|
35
|
-
* const updated = userMap.update("alice", u => ({ ...u, active: true })); // O(1)
|
|
36
|
-
*
|
|
37
|
-
* // Functional transformations
|
|
38
|
-
* const activeUsers = userMap.map((user, id) => ({ ...user, lastSeen: Date.now() })); // O(n)
|
|
39
|
-
* ```
|
|
40
27
|
*/
|
|
41
28
|
type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
42
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* The number of elements in the map.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* const entries = [
|
|
36
|
+
* ['a', 1],
|
|
37
|
+
* ['b', 2],
|
|
38
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
39
|
+
*
|
|
40
|
+
* const map = IMap.create(entries);
|
|
41
|
+
*
|
|
42
|
+
* assert(map.size === 2);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
43
45
|
size: SizeType.Arr;
|
|
44
46
|
/**
|
|
45
|
-
* Checks if a key exists in the map.
|
|
46
|
-
*
|
|
47
|
+
* Checks if a key exists in the map. Allows for wider literal types for keys
|
|
48
|
+
* during checking.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* const map = IMap.create<'id' | 'enabled', number | boolean>([
|
|
54
|
+
* ['id', 42],
|
|
55
|
+
* ['enabled', true],
|
|
56
|
+
* ]);
|
|
57
|
+
*
|
|
58
|
+
* assert.ok(map.has('id'));
|
|
59
|
+
* assert.notOk(map.has('missing'));
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
47
62
|
* @param key The key to check.
|
|
48
63
|
* @returns `true` if the key exists, `false` otherwise.
|
|
49
64
|
*/
|
|
50
65
|
has: (key: K | (WidenLiteral<K> & {})) => boolean;
|
|
51
66
|
/**
|
|
52
67
|
* Retrieves the value associated with a key.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
*
|
|
71
|
+
* ```ts
|
|
72
|
+
* const map = IMap.create([['user', { id: 1 }]]);
|
|
73
|
+
*
|
|
74
|
+
* assert.deepStrictEqual(map.get('user'), Optional.some({ id: 1 }));
|
|
75
|
+
* assert.deepStrictEqual(map.get('missing'), Optional.none);
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
53
78
|
* @param key The key to retrieve.
|
|
54
|
-
* @returns The value associated with the key wrapped with Optional.some, or
|
|
79
|
+
* @returns The value associated with the key wrapped with Optional.some, or
|
|
80
|
+
* `Optional.none` if the key does not exist.
|
|
55
81
|
*/
|
|
56
82
|
get: (key: K | (WidenLiteral<K> & {})) => Optional<V>;
|
|
57
83
|
/**
|
|
58
84
|
* Checks if all elements in the map satisfy a predicate.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* const map = IMap.create([
|
|
90
|
+
* ['a', 2],
|
|
91
|
+
* ['b', 4],
|
|
92
|
+
* ]);
|
|
93
|
+
*
|
|
94
|
+
* const allEven = map.every((value) => value % 2 === 0);
|
|
95
|
+
* const isNarrowed = map.every((value): value is 2 | 4 => value % 2 === 0);
|
|
96
|
+
*
|
|
97
|
+
* assert.ok(allEven);
|
|
98
|
+
* assert.ok(isNarrowed);
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
59
101
|
* @param predicate A function to test each key-value pair.
|
|
60
102
|
* @returns `true` if all elements satisfy the predicate, `false` otherwise.
|
|
61
103
|
*/
|
|
62
104
|
every: ((predicate: (value: V, key: K) => boolean) => boolean) &
|
|
63
105
|
/**
|
|
64
|
-
* Checks if all elements in the map satisfy a type predicate.
|
|
65
|
-
*
|
|
106
|
+
* Checks if all elements in the map satisfy a type predicate. Narrows the
|
|
107
|
+
* type of values in the map if the predicate returns true for all
|
|
108
|
+
* elements.
|
|
109
|
+
*
|
|
66
110
|
* @template W The narrowed type of the values.
|
|
67
111
|
* @param predicate A type predicate function.
|
|
68
112
|
* @returns `true` if all elements satisfy the predicate, `false` otherwise.
|
|
@@ -70,18 +114,70 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
70
114
|
(<W extends V>(predicate: (value: V, key: K) => value is W) => this is IMap<K, W>);
|
|
71
115
|
/**
|
|
72
116
|
* Checks if at least one element in the map satisfies a predicate.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
*
|
|
120
|
+
* ```ts
|
|
121
|
+
* const entries = [
|
|
122
|
+
* ['alice', 3],
|
|
123
|
+
* ['bob', 5],
|
|
124
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
125
|
+
*
|
|
126
|
+
* const map = IMap.create(entries);
|
|
127
|
+
*
|
|
128
|
+
* assert.ok(map.some((value) => value > 4));
|
|
129
|
+
* assert.notOk(map.some((value) => value > 10));
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
73
132
|
* @param predicate A function to test each key-value pair.
|
|
74
|
-
* @returns `true` if at least one element satisfies the predicate, `false`
|
|
133
|
+
* @returns `true` if at least one element satisfies the predicate, `false`
|
|
134
|
+
* otherwise.
|
|
75
135
|
*/
|
|
76
136
|
some: (predicate: (value: V, key: K) => boolean) => boolean;
|
|
77
137
|
/**
|
|
78
138
|
* Deletes a key-value pair from the map.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
*
|
|
142
|
+
* ```ts
|
|
143
|
+
* const original = IMap.create([
|
|
144
|
+
* ['a', 1],
|
|
145
|
+
* ['b', 2],
|
|
146
|
+
* ]);
|
|
147
|
+
*
|
|
148
|
+
* const withoutB = original.delete('b');
|
|
149
|
+
*
|
|
150
|
+
* assert.deepStrictEqual(original.get('b'), Optional.some(2));
|
|
151
|
+
* assert.deepStrictEqual(withoutB.get('b'), Optional.none);
|
|
152
|
+
* assert(original.size === 2);
|
|
153
|
+
* assert(withoutB.size === 1);
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
79
156
|
* @param key The key to delete.
|
|
80
157
|
* @returns A new IMap instance without the specified key.
|
|
81
158
|
*/
|
|
82
159
|
delete: (key: K) => IMap<K, V>;
|
|
83
160
|
/**
|
|
84
161
|
* Sets a key-value pair in the map.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
*
|
|
165
|
+
* ```ts
|
|
166
|
+
* const entries = [['count', 1]] satisfies readonly (readonly [
|
|
167
|
+
* 'count' | 'status',
|
|
168
|
+
* number | string,
|
|
169
|
+
* ])[];
|
|
170
|
+
*
|
|
171
|
+
* const base = IMap.create<'count' | 'status', number | string>(entries);
|
|
172
|
+
*
|
|
173
|
+
* const updated = base.set('count', 2);
|
|
174
|
+
* const extended = base.set('status', 'ok');
|
|
175
|
+
*
|
|
176
|
+
* assert.deepStrictEqual(base.get('count'), Optional.some(1));
|
|
177
|
+
* assert.deepStrictEqual(updated.get('count'), Optional.some(2));
|
|
178
|
+
* assert.deepStrictEqual(extended.get('status'), Optional.some('ok'));
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
85
181
|
* @param key The key to set.
|
|
86
182
|
* @param value The value to associate with the key.
|
|
87
183
|
* @returns A new IMap instance with the specified key-value pair.
|
|
@@ -89,13 +185,62 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
89
185
|
set: (key: K, value: V) => IMap<K, V>;
|
|
90
186
|
/**
|
|
91
187
|
* Updates the value associated with a key using an updater function.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
*
|
|
191
|
+
* ```ts
|
|
192
|
+
* const entries = [
|
|
193
|
+
* ['alice', 10],
|
|
194
|
+
* ['bob', 8],
|
|
195
|
+
* ] satisfies readonly (readonly ['alice' | 'bob' | 'charlie', number])[];
|
|
196
|
+
*
|
|
197
|
+
* const scores = IMap.create<'alice' | 'bob' | 'charlie', number>(entries);
|
|
198
|
+
*
|
|
199
|
+
* const boosted = scores.update('alice', (value) => value + 5);
|
|
200
|
+
* const unchanged = scores.update('charlie', (value) => value + 1);
|
|
201
|
+
*
|
|
202
|
+
* assert.deepStrictEqual(boosted.get('alice'), Optional.some(15));
|
|
203
|
+
* assert.deepStrictEqual(scores.get('alice'), Optional.some(10));
|
|
204
|
+
* assert(unchanged === scores);
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
92
207
|
* @param key The key whose value to update.
|
|
93
|
-
* @param updater A function that takes the current value and returns the new
|
|
208
|
+
* @param updater A function that takes the current value and returns the new
|
|
209
|
+
* value.
|
|
94
210
|
* @returns A new IMap instance with the updated value.
|
|
95
211
|
*/
|
|
96
212
|
update: (key: K, updater: (value: V) => V) => IMap<K, V>;
|
|
97
213
|
/**
|
|
98
214
|
* Applies a series of mutations to the map.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
*
|
|
218
|
+
* ```ts
|
|
219
|
+
* const entries = [
|
|
220
|
+
* ['a', 1],
|
|
221
|
+
* ['b', 2],
|
|
222
|
+
* ] satisfies readonly (readonly ['a' | 'b' | 'c', number])[];
|
|
223
|
+
*
|
|
224
|
+
* const base = IMap.create<'a' | 'b' | 'c', number>(entries);
|
|
225
|
+
*
|
|
226
|
+
* const actions: readonly Readonly<
|
|
227
|
+
* | { type: 'set'; key: 'c'; value: number }
|
|
228
|
+
* | { type: 'update'; key: 'b'; updater: (value: number) => number }
|
|
229
|
+
* | { type: 'delete'; key: 'a' }
|
|
230
|
+
* >[] = [
|
|
231
|
+
* { type: 'set', key: 'c', value: 3 },
|
|
232
|
+
* { type: 'update', key: 'b', updater: (value) => value * 10 },
|
|
233
|
+
* { type: 'delete', key: 'a' },
|
|
234
|
+
* ];
|
|
235
|
+
*
|
|
236
|
+
* const mutated = base.withMutations(actions);
|
|
237
|
+
*
|
|
238
|
+
* assert.deepStrictEqual(mutated.get('c'), Optional.some(3));
|
|
239
|
+
* assert.deepStrictEqual(mutated.get('b'), Optional.some(20));
|
|
240
|
+
* assert.deepStrictEqual(mutated.get('a'), Optional.none);
|
|
241
|
+
* assert.deepStrictEqual(base.get('b'), Optional.some(2));
|
|
242
|
+
* ```
|
|
243
|
+
*
|
|
99
244
|
* @param actions An array of mutation actions (delete, set, or update).
|
|
100
245
|
* @returns A new IMap instance with all mutations applied.
|
|
101
246
|
*/
|
|
@@ -113,6 +258,25 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
113
258
|
}>[]) => IMap<K, V>;
|
|
114
259
|
/**
|
|
115
260
|
* Maps the values of the map to new values.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
*
|
|
264
|
+
* ```ts
|
|
265
|
+
* const entries = [
|
|
266
|
+
* ['a', 1],
|
|
267
|
+
* ['b', 2],
|
|
268
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
269
|
+
*
|
|
270
|
+
* const map = IMap.create(entries);
|
|
271
|
+
*
|
|
272
|
+
* const doubled = map.map((value) => value * 2);
|
|
273
|
+
*
|
|
274
|
+
* assert.deepStrictEqual(Array.from(doubled), [
|
|
275
|
+
* ['a', 2],
|
|
276
|
+
* ['b', 4],
|
|
277
|
+
* ]);
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
116
280
|
* @template V2 The type of the new values.
|
|
117
281
|
* @param mapFn A function that maps a value and key to a new value.
|
|
118
282
|
* @returns A new IMap instance with mapped values.
|
|
@@ -120,6 +284,25 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
120
284
|
map: <V2>(mapFn: (value: V, key: K) => V2) => IMap<K, V2>;
|
|
121
285
|
/**
|
|
122
286
|
* Maps the keys of the map to new keys.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
*
|
|
290
|
+
* ```ts
|
|
291
|
+
* const entries = [
|
|
292
|
+
* ['first', 1],
|
|
293
|
+
* ['second', 2],
|
|
294
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
295
|
+
*
|
|
296
|
+
* const map = IMap.create(entries);
|
|
297
|
+
*
|
|
298
|
+
* const upperKeys = map.mapKeys((key) => key.toUpperCase());
|
|
299
|
+
*
|
|
300
|
+
* assert.deepStrictEqual(Array.from(upperKeys), [
|
|
301
|
+
* ['FIRST', 1],
|
|
302
|
+
* ['SECOND', 2],
|
|
303
|
+
* ]);
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
123
306
|
* @template K2 The type of the new keys.
|
|
124
307
|
* @param mapFn A function that maps a key to a new key.
|
|
125
308
|
* @returns A new IMap instance with mapped keys and original values.
|
|
@@ -127,6 +310,27 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
127
310
|
mapKeys: <K2 extends MapSetKeyType>(mapFn: (key: K) => K2) => IMap<K2, V>;
|
|
128
311
|
/**
|
|
129
312
|
* Maps the entries (key-value pairs) of the map to new entries.
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
*
|
|
316
|
+
* ```ts
|
|
317
|
+
* const entries = [
|
|
318
|
+
* ['a', 1],
|
|
319
|
+
* ['b', 2],
|
|
320
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
321
|
+
*
|
|
322
|
+
* const map = IMap.create(entries);
|
|
323
|
+
*
|
|
324
|
+
* const swapped = map.mapEntries(
|
|
325
|
+
* ([key, value]) => [value, key] satisfies readonly [number, string],
|
|
326
|
+
* );
|
|
327
|
+
*
|
|
328
|
+
* assert.deepStrictEqual(Array.from(swapped), [
|
|
329
|
+
* [1, 'a'],
|
|
330
|
+
* [2, 'b'],
|
|
331
|
+
* ]);
|
|
332
|
+
* ```
|
|
333
|
+
*
|
|
130
334
|
* @template K2 The type of the new keys in the entries.
|
|
131
335
|
* @template V2 The type of the new values in the entries.
|
|
132
336
|
* @param mapFn A function that maps an entry to a new entry.
|
|
@@ -135,66 +339,215 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
135
339
|
mapEntries: <K2 extends MapSetKeyType, V2>(mapFn: (entry: readonly [K, V]) => readonly [K2, V2]) => IMap<K2, V2>;
|
|
136
340
|
/**
|
|
137
341
|
* Executes a callback function for each key-value pair in the map.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
*
|
|
345
|
+
* ```ts
|
|
346
|
+
* const map = IMap.create([
|
|
347
|
+
* ['a', 1],
|
|
348
|
+
* ['b', 2],
|
|
349
|
+
* ]);
|
|
350
|
+
*
|
|
351
|
+
* const entries: (readonly [string, number])[] = [];
|
|
352
|
+
*
|
|
353
|
+
* for (const [key, value] of map.entries()) {
|
|
354
|
+
* entries.push([key, value]);
|
|
355
|
+
* }
|
|
356
|
+
*
|
|
357
|
+
* assert.deepStrictEqual(entries, [
|
|
358
|
+
* ['a', 1],
|
|
359
|
+
* ['b', 2],
|
|
360
|
+
* ]);
|
|
361
|
+
* ```
|
|
362
|
+
*
|
|
138
363
|
* @param callbackfn A function to execute for each element.
|
|
139
364
|
*/
|
|
140
365
|
forEach: (callbackfn: (value: V, key: K) => void) => void;
|
|
141
366
|
/**
|
|
142
367
|
* Returns an iterator for the keys in the map.
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
*
|
|
371
|
+
* ```ts
|
|
372
|
+
* const entries = [
|
|
373
|
+
* ['a', 1],
|
|
374
|
+
* ['b', 2],
|
|
375
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
376
|
+
*
|
|
377
|
+
* const map = IMap.create(entries);
|
|
378
|
+
*
|
|
379
|
+
* const keys = Array.from(map.keys());
|
|
380
|
+
*
|
|
381
|
+
* assert.deepStrictEqual(keys, ['a', 'b']);
|
|
382
|
+
* ```
|
|
383
|
+
*
|
|
143
384
|
* @returns An iterable iterator of keys.
|
|
144
385
|
*/
|
|
145
386
|
keys: () => IterableIterator<K>;
|
|
146
387
|
/**
|
|
147
388
|
* Returns an iterator for the values in the map.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
*
|
|
392
|
+
* ```ts
|
|
393
|
+
* const entries = [
|
|
394
|
+
* ['a', 1],
|
|
395
|
+
* ['b', 2],
|
|
396
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
397
|
+
*
|
|
398
|
+
* const map = IMap.create(entries);
|
|
399
|
+
*
|
|
400
|
+
* const values = Array.from(map.values());
|
|
401
|
+
*
|
|
402
|
+
* assert.deepStrictEqual(values, [1, 2]);
|
|
403
|
+
* ```
|
|
404
|
+
*
|
|
148
405
|
* @returns An iterable iterator of values.
|
|
149
406
|
*/
|
|
150
407
|
values: () => IterableIterator<V>;
|
|
151
408
|
/**
|
|
152
409
|
* Returns an iterator for the entries (key-value pairs) in the map.
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
*
|
|
413
|
+
* ```ts
|
|
414
|
+
* const map = IMap.create([
|
|
415
|
+
* ['a', 1],
|
|
416
|
+
* ['b', 2],
|
|
417
|
+
* ]);
|
|
418
|
+
*
|
|
419
|
+
* const entries = Array.from(map.entries());
|
|
420
|
+
*
|
|
421
|
+
* assert.deepStrictEqual(entries, [
|
|
422
|
+
* ['a', 1],
|
|
423
|
+
* ['b', 2],
|
|
424
|
+
* ]);
|
|
425
|
+
* ```
|
|
426
|
+
*
|
|
153
427
|
* @returns An iterable iterator of entries.
|
|
154
428
|
*/
|
|
155
429
|
entries: () => IterableIterator<readonly [K, V]>;
|
|
156
430
|
/**
|
|
157
431
|
* Converts the keys of the map to an array.
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
*
|
|
435
|
+
* ```ts
|
|
436
|
+
* const entries = [
|
|
437
|
+
* ['x', 10],
|
|
438
|
+
* ['y', 20],
|
|
439
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
440
|
+
*
|
|
441
|
+
* const map = IMap.create(entries);
|
|
442
|
+
*
|
|
443
|
+
* assert.deepStrictEqual(map.toKeysArray(), ['x', 'y']);
|
|
444
|
+
* ```
|
|
445
|
+
*
|
|
158
446
|
* @returns A readonly array of keys.
|
|
159
447
|
*/
|
|
160
448
|
toKeysArray: () => readonly K[];
|
|
161
449
|
/**
|
|
162
450
|
* Converts the values of the map to an array.
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
*
|
|
454
|
+
* ```ts
|
|
455
|
+
* const entries = [
|
|
456
|
+
* ['x', 10],
|
|
457
|
+
* ['y', 20],
|
|
458
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
459
|
+
*
|
|
460
|
+
* const map = IMap.create(entries);
|
|
461
|
+
*
|
|
462
|
+
* assert.deepStrictEqual(map.toValuesArray(), [10, 20]);
|
|
463
|
+
* ```
|
|
464
|
+
*
|
|
163
465
|
* @returns A readonly array of values.
|
|
164
466
|
*/
|
|
165
467
|
toValuesArray: () => readonly V[];
|
|
166
468
|
/**
|
|
167
469
|
* Converts the entries (key-value pairs) of the map to an array.
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
*
|
|
473
|
+
* ```ts
|
|
474
|
+
* const entries = [
|
|
475
|
+
* ['a', 1],
|
|
476
|
+
* ['b', 2],
|
|
477
|
+
* ] satisfies readonly (readonly [string, number])[];
|
|
478
|
+
*
|
|
479
|
+
* const map = IMap.create(entries);
|
|
480
|
+
*
|
|
481
|
+
* assert.deepStrictEqual(map.toEntriesArray(), [
|
|
482
|
+
* ['a', 1],
|
|
483
|
+
* ['b', 2],
|
|
484
|
+
* ]);
|
|
485
|
+
* ```
|
|
486
|
+
*
|
|
168
487
|
* @returns A readonly array of entries.
|
|
169
488
|
*/
|
|
170
489
|
toEntriesArray: () => readonly (readonly [K, V])[];
|
|
171
490
|
/**
|
|
172
|
-
* Converts the map to an array of entries (key-value pairs).
|
|
173
|
-
*
|
|
491
|
+
* Converts the map to an array of entries (key-value pairs). Alias for
|
|
492
|
+
* `toEntriesArray`.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
*
|
|
496
|
+
* ```ts
|
|
497
|
+
* const entries = [
|
|
498
|
+
* ['k1', 'v1'],
|
|
499
|
+
* ['k2', 'v2'],
|
|
500
|
+
* ] satisfies readonly (readonly [string, string])[];
|
|
501
|
+
*
|
|
502
|
+
* const map = IMap.create(entries);
|
|
503
|
+
*
|
|
504
|
+
* assert.deepStrictEqual(map.toArray(), [
|
|
505
|
+
* ['k1', 'v1'],
|
|
506
|
+
* ['k2', 'v2'],
|
|
507
|
+
* ]);
|
|
508
|
+
* ```
|
|
509
|
+
*
|
|
174
510
|
* @returns A readonly array of entries.
|
|
175
511
|
*/
|
|
176
512
|
toArray: () => readonly (readonly [K, V])[];
|
|
177
513
|
/**
|
|
178
514
|
* Returns the underlying readonly JavaScript Map.
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
*
|
|
518
|
+
* ```ts
|
|
519
|
+
* const entries = [['key', 1]] satisfies readonly (readonly [string, number])[];
|
|
520
|
+
*
|
|
521
|
+
* const map = IMap.create(entries);
|
|
522
|
+
*
|
|
523
|
+
* const raw = map.toRawMap();
|
|
524
|
+
*
|
|
525
|
+
* assert.ok(is.map(raw));
|
|
526
|
+
* assert(raw.get('key') === 1);
|
|
527
|
+
* ```
|
|
528
|
+
*
|
|
179
529
|
* @returns The raw ReadonlyMap instance.
|
|
180
530
|
*/
|
|
181
531
|
toRawMap: () => ReadonlyMap<K, V>;
|
|
182
532
|
}>;
|
|
183
533
|
/**
|
|
184
|
-
* Represents an immutable map with high-performance operations and functional
|
|
534
|
+
* Represents an immutable map with high-performance operations and functional
|
|
535
|
+
* programming support.
|
|
185
536
|
*
|
|
186
|
-
* IMap is a persistent data structure that provides all the functionality of
|
|
187
|
-
* while maintaining immutability. All operations that would
|
|
188
|
-
* return new IMap instances, making it safe for
|
|
537
|
+
* IMap is a persistent data structure that provides all the functionality of
|
|
538
|
+
* JavaScript's Map while maintaining immutability. All operations that would
|
|
539
|
+
* normally mutate the map instead return new IMap instances, making it safe for
|
|
540
|
+
* functional programming and concurrent access.
|
|
189
541
|
*
|
|
190
542
|
* **Key Features:**
|
|
543
|
+
*
|
|
191
544
|
* - **Immutable**: All mutation operations return new instances
|
|
192
|
-
* - **High Performance**: O(1) average-case for get/set/has/delete operations
|
|
193
545
|
* - **Type Safe**: Full TypeScript support with generic key/value types
|
|
194
546
|
* - **Iterable**: Implements standard JavaScript iteration protocols
|
|
195
547
|
* - **Functional**: Rich API for map, filter, reduce-style operations
|
|
196
548
|
*
|
|
197
549
|
* **When to Use:**
|
|
550
|
+
*
|
|
198
551
|
* - State management in functional applications
|
|
199
552
|
* - Caching with immutable guarantees
|
|
200
553
|
* - Data structures that need to be shared across components
|
|
@@ -202,156 +555,76 @@ type IMapInterface<K extends MapSetKeyType, V> = Readonly<{
|
|
|
202
555
|
*
|
|
203
556
|
* @template K The type of the keys in the map. Must extend MapSetKeyType.
|
|
204
557
|
* @template V The type of the values in the map.
|
|
205
|
-
*
|
|
206
|
-
* @example
|
|
207
|
-
* ```typescript
|
|
208
|
-
* // Create an immutable map with initial data
|
|
209
|
-
* let userPreferences = IMap.create<string, UserPreference>([
|
|
210
|
-
* ["theme", { value: "dark", lastModified: Date.now() }],
|
|
211
|
-
* ["language", { value: "en", lastModified: Date.now() }]
|
|
212
|
-
* ]);
|
|
213
|
-
*
|
|
214
|
-
* console.log(userPreferences.get("theme").unwrapOr(defaultPreference));
|
|
215
|
-
* console.log(userPreferences.size); // Output: 2
|
|
216
|
-
*
|
|
217
|
-
* // All operations return new instances - original is unchanged
|
|
218
|
-
* const updated = userPreferences
|
|
219
|
-
* .set("notifications", { value: true, lastModified: Date.now() })
|
|
220
|
-
* .update("theme", pref => ({ ...pref, value: "light" }));
|
|
221
|
-
*
|
|
222
|
-
* console.log(userPreferences.has("notifications")); // false (original unchanged)
|
|
223
|
-
* console.log(updated.has("notifications")); // true (new instance)
|
|
224
|
-
*
|
|
225
|
-
* // Efficient iteration and transformation
|
|
226
|
-
* for (const [key, preference] of updated) {
|
|
227
|
-
* console.log(`${key}: ${preference.value}`);
|
|
228
|
-
* }
|
|
229
|
-
*
|
|
230
|
-
* // Functional transformations
|
|
231
|
-
* const withTimestamps = updated.map((pref, key) => ({
|
|
232
|
-
* ...pref,
|
|
233
|
-
* accessedAt: Date.now()
|
|
234
|
-
* }));
|
|
235
|
-
*
|
|
236
|
-
* // Type-safe operations with narrowing
|
|
237
|
-
* const stringKeys = IMap.create<number | string, any>([[1, "a"], ["b", 2]]);
|
|
238
|
-
* const onlyStringKeys = stringKeys.mapKeys(key =>
|
|
239
|
-
* typeof key === "string" ? key : key.toString()
|
|
240
|
-
* );
|
|
241
|
-
* ```
|
|
242
558
|
*/
|
|
243
559
|
export type IMap<K extends MapSetKeyType, V> = Iterable<readonly [K, V]> & IMapInterface<K, V>;
|
|
244
|
-
/**
|
|
245
|
-
* Provides utility functions for IMap.
|
|
246
|
-
*/
|
|
560
|
+
/** Provides utility functions for IMap. */
|
|
247
561
|
export declare namespace IMap {
|
|
248
562
|
/**
|
|
249
563
|
* Creates a new IMap instance from an iterable of key-value pairs.
|
|
250
564
|
*
|
|
251
|
-
* This factory function accepts any iterable of [key, value] tuples,
|
|
252
|
-
* JavaScript Maps, other IMaps, or custom iterables. The
|
|
253
|
-
* all the entries from the input iterable.
|
|
565
|
+
* This factory function accepts any iterable of [key, value] tuples,
|
|
566
|
+
* including arrays, JavaScript Maps, other IMaps, or custom iterables. The
|
|
567
|
+
* resulting IMap will contain all the entries from the input iterable.
|
|
254
568
|
*
|
|
255
569
|
* **Performance:** O(n) where n is the number of entries in the iterable.
|
|
256
570
|
*
|
|
257
|
-
* @template K The type of the keys. Must extend MapSetKeyType.
|
|
258
|
-
* @template V The type of the values.
|
|
259
|
-
* @param iterable An iterable of key-value pairs (e.g., Array, Map, IMap, etc.)
|
|
260
|
-
* @returns A new IMap instance containing all entries from the iterable.
|
|
261
|
-
*
|
|
262
571
|
* @example
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
* const
|
|
266
|
-
* [
|
|
267
|
-
* [
|
|
268
|
-
* ["charlie", 92]
|
|
572
|
+
*
|
|
573
|
+
* ```ts
|
|
574
|
+
* const map = IMap.create<string, number | string>([
|
|
575
|
+
* ['id', 1],
|
|
576
|
+
* ['status', 'active'],
|
|
269
577
|
* ]);
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
* const jsMap = new Map([["config", { debug: true }], ["env", "production"]]);
|
|
274
|
-
* const config = IMap.create(jsMap);
|
|
275
|
-
* console.log(config.get("env").unwrap()); // Output: "production"
|
|
276
|
-
*
|
|
277
|
-
* // From another IMap (creates a copy)
|
|
278
|
-
* const originalMap = IMap.create<string, boolean>([["enabled", true]]);
|
|
279
|
-
* const copiedMap = IMap.create(originalMap);
|
|
280
|
-
* console.log(copiedMap.get("enabled").unwrap()); // Output: true
|
|
281
|
-
*
|
|
282
|
-
* // Empty map
|
|
283
|
-
* const emptyMap = IMap.create<string, number>([]);
|
|
284
|
-
* console.log(emptyMap.size); // Output: 0
|
|
285
|
-
*
|
|
286
|
-
* // From custom iterable
|
|
287
|
-
* function* generateEntries(): Generator<[string, number]> {
|
|
288
|
-
* for (const i of range(3)) {
|
|
289
|
-
* yield [`item${i}`, i * 10];
|
|
290
|
-
* }
|
|
291
|
-
* }
|
|
292
|
-
* const generatedMap = IMap.create(generateEntries());
|
|
293
|
-
* console.log(generatedMap.size); // Output: 3
|
|
578
|
+
*
|
|
579
|
+
* assert(map.size === 2);
|
|
580
|
+
* assert.deepStrictEqual(map.get('status'), Optional.some('active'));
|
|
294
581
|
* ```
|
|
582
|
+
*
|
|
583
|
+
* @template K The type of the keys. Must extend MapSetKeyType.
|
|
584
|
+
* @template V The type of the values.
|
|
585
|
+
* @param iterable An iterable of key-value pairs (e.g., Array, Map, IMap,
|
|
586
|
+
* etc.)
|
|
587
|
+
* @returns A new IMap instance containing all entries from the iterable.
|
|
295
588
|
*/
|
|
296
589
|
const create: <K extends MapSetKeyType, V>(iterable: Iterable<readonly [K, V]>) => IMap<K, V>;
|
|
297
590
|
/**
|
|
298
591
|
* Checks if two IMap instances are structurally equal.
|
|
299
592
|
*
|
|
300
|
-
* Two IMaps are considered equal if they have the same size and contain
|
|
301
|
-
* key-value pairs. The order of entries does not matter for
|
|
302
|
-
* Values are compared using JavaScript's `===`
|
|
593
|
+
* Two IMaps are considered equal if they have the same size and contain
|
|
594
|
+
* exactly the same key-value pairs. The order of entries does not matter for
|
|
595
|
+
* equality comparison. Values are compared using JavaScript's `===`
|
|
596
|
+
* operator.
|
|
303
597
|
*
|
|
304
598
|
* **Performance:** O(n) where n is the size of the smaller map.
|
|
305
599
|
*
|
|
306
|
-
* @template K The type of the keys.
|
|
307
|
-
* @template V The type of the values.
|
|
308
|
-
* @param a The first IMap instance to compare.
|
|
309
|
-
* @param b The second IMap instance to compare.
|
|
310
|
-
* @returns `true` if the maps contain exactly the same key-value pairs, `false` otherwise.
|
|
311
|
-
*
|
|
312
600
|
* @example
|
|
313
|
-
* ```typescript
|
|
314
|
-
* // Basic equality comparison
|
|
315
|
-
* const preferences1 = IMap.create<string, boolean>([
|
|
316
|
-
* ["darkMode", true],
|
|
317
|
-
* ["notifications", false]
|
|
318
|
-
* ]);
|
|
319
|
-
* const preferences2 = IMap.create<string, boolean>([
|
|
320
|
-
* ["darkMode", true],
|
|
321
|
-
* ["notifications", false]
|
|
322
|
-
* ]);
|
|
323
|
-
* const preferences3 = IMap.create<string, boolean>([
|
|
324
|
-
* ["notifications", false],
|
|
325
|
-
* ["darkMode", true] // Order doesn't matter
|
|
326
|
-
* ]);
|
|
327
|
-
*
|
|
328
|
-
* console.log(IMap.equal(preferences1, preferences2)); // true
|
|
329
|
-
* console.log(IMap.equal(preferences1, preferences3)); // true (order doesn't matter)
|
|
330
601
|
*
|
|
331
|
-
*
|
|
332
|
-
* const
|
|
333
|
-
* [
|
|
334
|
-
* [
|
|
602
|
+
* ```ts
|
|
603
|
+
* const first = IMap.create<'a' | 'b', number>([
|
|
604
|
+
* ['a', 1],
|
|
605
|
+
* ['b', 2],
|
|
335
606
|
* ]);
|
|
336
|
-
* console.log(IMap.equal(preferences1, preferences4)); // false
|
|
337
607
|
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
* [
|
|
341
|
-
* ["sounds", false] // Different key
|
|
608
|
+
* const second = IMap.create<'a' | 'b', number>([
|
|
609
|
+
* ['b', 2],
|
|
610
|
+
* ['a', 1],
|
|
342
611
|
* ]);
|
|
343
|
-
* console.log(IMap.equal(preferences1, preferences5)); // false
|
|
344
612
|
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
613
|
+
* const third = IMap.create<'a' | 'b', number>([
|
|
614
|
+
* ['a', 1],
|
|
615
|
+
* ['b', 3],
|
|
616
|
+
* ]);
|
|
349
617
|
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
* const users2 = IMap.create<string, User>([["1", { name: "Alice" }]]);
|
|
353
|
-
* console.log(IMap.equal(users1, users2)); // false (different object references)
|
|
618
|
+
* assert.ok(IMap.equal(first, second));
|
|
619
|
+
* assert.notOk(IMap.equal(first, third));
|
|
354
620
|
* ```
|
|
621
|
+
*
|
|
622
|
+
* @template K The type of the keys.
|
|
623
|
+
* @template V The type of the values.
|
|
624
|
+
* @param a The first IMap instance to compare.
|
|
625
|
+
* @param b The second IMap instance to compare.
|
|
626
|
+
* @returns `true` if the maps contain exactly the same key-value pairs,
|
|
627
|
+
* `false` otherwise.
|
|
355
628
|
*/
|
|
356
629
|
const equal: <K extends MapSetKeyType, V>(a: IMap<K, V>, b: IMap<K, V>) => boolean;
|
|
357
630
|
}
|