ts-data-forge 5.0.1 → 5.1.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 +101 -50
- package/dist/array/impl/array-utils-creation.d.mts +14 -0
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-creation.mjs +12 -0
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts +10 -0
- package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
- package/dist/array/impl/array-utils-element-access.mjs +6 -0
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-modification.d.mts +14 -0
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +34 -10
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts +34 -4
- package/dist/array/impl/array-utils-search.d.mts.map +1 -1
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts +20 -7
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +20 -7
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +5 -2
- package/dist/array/impl/array-utils-size.d.mts.map +1 -1
- package/dist/array/impl/array-utils-size.mjs +5 -2
- package/dist/array/impl/array-utils-size.mjs.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.d.mts +2 -0
- package/dist/array/impl/array-utils-slice-clamped.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts +17 -2
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs +9 -2
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +27 -0
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +6 -0
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +35 -18
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +25 -14
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +35 -15
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +5 -3
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +46 -19
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +9 -2
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +48 -19
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +9 -2
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.d.mts +65 -25
- package/dist/collections/queue.d.mts.map +1 -1
- package/dist/collections/queue.mjs +13 -5
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.d.mts +60 -25
- package/dist/collections/stack.d.mts.map +1 -1
- package/dist/collections/stack.mjs +12 -5
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/entry-point.mjs +1 -1
- package/dist/functional/match.d.mts +1 -1
- package/dist/functional/match.d.mts.map +1 -1
- package/dist/functional/match.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts +3 -2
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-filter.d.mts +3 -0
- package/dist/functional/optional/impl/optional-filter.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-flat-map.d.mts +2 -0
- package/dist/functional/optional/impl/optional-flat-map.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-from-nullable.d.mts +2 -0
- package/dist/functional/optional/impl/optional-from-nullable.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-from-nullable.mjs +2 -0
- package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-none.d.mts +1 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +1 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts +4 -2
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +4 -2
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts +2 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +2 -1
- package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-map.d.mts +2 -0
- package/dist/functional/optional/impl/optional-map.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-none.d.mts +4 -2
- package/dist/functional/optional/impl/optional-none.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-none.mjs +4 -2
- package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-or-else.d.mts +4 -0
- package/dist/functional/optional/impl/optional-or-else.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-some.d.mts +5 -3
- package/dist/functional/optional/impl/optional-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-some.mjs +4 -2
- package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +4 -2
- package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.mjs +4 -2
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +7 -4
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +2 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +2 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap.d.mts +4 -2
- package/dist/functional/optional/impl/optional-unwrap.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-zip.d.mts +3 -1
- package/dist/functional/optional/impl/optional-zip.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +3 -1
- package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
- package/dist/functional/pipe.d.mts +2 -2
- package/dist/functional/result/impl/result-err.d.mts +4 -2
- package/dist/functional/result/impl/result-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-err.mjs +3 -1
- package/dist/functional/result/impl/result-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-expect-to-be.d.mts +3 -2
- package/dist/functional/result/impl/result-expect-to-be.d.mts.map +1 -1
- package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
- package/dist/functional/result/impl/result-flat-map.d.mts +5 -0
- package/dist/functional/result/impl/result-flat-map.d.mts.map +1 -1
- package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-fold.d.mts +4 -0
- package/dist/functional/result/impl/result-fold.d.mts.map +1 -1
- package/dist/functional/result/impl/result-fold.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-promise.d.mts +4 -1
- package/dist/functional/result/impl/result-from-promise.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs +4 -1
- package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts +3 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +3 -1
- package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-err.d.mts +4 -2
- package/dist/functional/result/impl/result-is-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-err.mjs +4 -2
- package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-ok.d.mts +4 -2
- package/dist/functional/result/impl/result-is-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-ok.mjs +4 -2
- package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-result.d.mts +7 -3
- package/dist/functional/result/impl/result-is-result.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-result.mjs +7 -3
- package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
- package/dist/functional/result/impl/result-map-err.d.mts +3 -0
- package/dist/functional/result/impl/result-map-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-map.d.mts +4 -0
- package/dist/functional/result/impl/result-map.d.mts.map +1 -1
- package/dist/functional/result/impl/result-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-ok.d.mts +4 -2
- package/dist/functional/result/impl/result-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-ok.mjs +3 -1
- package/dist/functional/result/impl/result-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-or-else.d.mts +4 -0
- package/dist/functional/result/impl/result-or-else.d.mts.map +1 -1
- package/dist/functional/result/impl/result-or-else.mjs.map +1 -1
- package/dist/functional/result/impl/result-swap.d.mts +2 -0
- package/dist/functional/result/impl/result-swap.d.mts.map +1 -1
- package/dist/functional/result/impl/result-swap.mjs +2 -0
- package/dist/functional/result/impl/result-swap.mjs.map +1 -1
- package/dist/functional/result/impl/result-to-optional.d.mts +2 -0
- package/dist/functional/result/impl/result-to-optional.d.mts.map +1 -1
- package/dist/functional/result/impl/result-to-optional.mjs +2 -0
- package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts +7 -4
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +3 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +3 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts +3 -2
- package/dist/functional/result/impl/result-unwrap-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.mjs +3 -2
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +7 -4
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok.d.mts +3 -2
- package/dist/functional/result/impl/result-unwrap-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts +3 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +3 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-zip.d.mts +3 -1
- package/dist/functional/result/impl/result-zip.d.mts.map +1 -1
- package/dist/functional/result/impl/result-zip.mjs +3 -1
- package/dist/functional/result/impl/result-zip.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +3 -2
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +2 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts +4 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +3 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +3 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +3 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +3 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +7 -3
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +7 -3
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts +3 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts +3 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts +6 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts +4 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +4 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -1
- package/dist/globals.d.mts +12 -1
- package/dist/guard/has-key.d.mts +6 -3
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +2 -2
- package/dist/guard/index.mjs +1 -1
- package/dist/guard/is-record.d.mts +31 -0
- package/dist/guard/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +32 -1
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/is-type.d.mts +3 -0
- package/dist/guard/is-type.d.mts.map +1 -1
- package/dist/guard/is-type.mjs +3 -0
- package/dist/guard/is-type.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts +3 -2
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +3 -2
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/iterator/range.d.mts +4 -0
- package/dist/iterator/range.d.mts.map +1 -1
- package/dist/iterator/range.mjs +1 -0
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/json.d.mts +42 -21
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +42 -21
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +33 -19
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +33 -19
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +2 -2
- package/dist/number/branded-types/positive-int.d.mts +34 -20
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +34 -20
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +47 -26
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +48 -27
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +48 -27
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +50 -29
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +1 -1
- package/dist/number/branded-types/uint.d.mts +31 -19
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +31 -19
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/num.d.mts +29 -20
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +24 -17
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +33 -11
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +33 -11
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +12 -3
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +10 -3
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/tuple.d.mts +14 -3
- package/dist/others/tuple.d.mts.map +1 -1
- package/dist/others/tuple.mjs +14 -3
- package/dist/others/tuple.mjs.map +1 -1
- package/dist/others/unknown-to-string.d.mts.map +1 -1
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/promise/promise.d.mts +8 -4
- package/dist/promise/promise.d.mts.map +1 -1
- package/dist/promise/promise.mjs +8 -4
- package/dist/promise/promise.mjs.map +1 -1
- package/package.json +26 -28
- package/src/array/impl/array-utils-creation.mts +20 -0
- package/src/array/impl/array-utils-creation.test.mts +72 -1
- package/src/array/impl/array-utils-element-access.mts +13 -0
- package/src/array/impl/array-utils-element-access.test.mts +36 -15
- package/src/array/impl/array-utils-iterators.test.mts +17 -0
- package/src/array/impl/array-utils-modification.mts +78 -19
- package/src/array/impl/array-utils-modification.test.mts +75 -0
- package/src/array/impl/array-utils-overload-type-error.test.mts +19 -0
- package/src/array/impl/array-utils-reducing-value.mts +61 -16
- package/src/array/impl/array-utils-reducing-value.test.mts +107 -25
- package/src/array/impl/array-utils-search.mts +57 -4
- package/src/array/impl/array-utils-search.test.mts +61 -10
- package/src/array/impl/array-utils-set-op.mts +26 -7
- package/src/array/impl/array-utils-set-op.test.mts +129 -13
- package/src/array/impl/array-utils-size.mts +5 -2
- package/src/array/impl/array-utils-size.test.mts +1 -0
- package/src/array/impl/array-utils-slice-clamped.mts +7 -0
- package/src/array/impl/array-utils-slice-clamped.test.mts +20 -0
- package/src/array/impl/array-utils-slicing.mts +29 -2
- package/src/array/impl/array-utils-slicing.test.mts +57 -0
- package/src/array/impl/array-utils-transformation.mts +58 -0
- package/src/array/impl/array-utils-transformation.test.mts +115 -3
- package/src/array/impl/array-utils-validation.mts +41 -18
- package/src/array/impl/array-utils-validation.test.mts +176 -78
- package/src/array/impl/array.test.mts +18 -6
- package/src/collections/imap-mapped.mts +11 -0
- package/src/collections/imap-mapped.test.mts +86 -18
- package/src/collections/imap.mts +47 -15
- package/src/collections/imap.test.mts +137 -31
- package/src/collections/iset-mapped.mts +54 -19
- package/src/collections/iset-mapped.test.mts +163 -52
- package/src/collections/iset.mts +53 -19
- package/src/collections/iset.test.mts +323 -130
- package/src/collections/queue.mts +78 -25
- package/src/collections/queue.test.mts +65 -35
- package/src/collections/stack.mts +67 -25
- package/src/collections/stack.test.mts +59 -15
- package/src/functional/match.mts +17 -1
- package/src/functional/match.test.mts +2 -0
- package/src/functional/optional/impl/optional-expect-to-be.mts +5 -2
- package/src/functional/optional/impl/optional-filter.mts +6 -0
- package/src/functional/optional/impl/optional-flat-map.mts +4 -0
- package/src/functional/optional/impl/optional-from-nullable.mts +2 -0
- package/src/functional/optional/impl/optional-is-none.mts +1 -1
- package/src/functional/optional/impl/optional-is-optional.mts +4 -2
- package/src/functional/optional/impl/optional-is-some.mts +2 -1
- package/src/functional/optional/impl/optional-map.mts +5 -0
- package/src/functional/optional/impl/optional-none.mts +4 -2
- package/src/functional/optional/impl/optional-or-else.mts +6 -0
- package/src/functional/optional/impl/optional-some.mts +5 -3
- package/src/functional/optional/impl/optional-to-nullable.mts +4 -2
- package/src/functional/optional/impl/optional-unwrap-or.mts +9 -4
- package/src/functional/optional/impl/optional-unwrap-throw.mts +2 -1
- package/src/functional/optional/impl/optional-unwrap.mts +4 -2
- package/src/functional/optional/impl/optional-zip.mts +3 -1
- package/src/functional/optional.test.mts +126 -54
- package/src/functional/pipe.mts +2 -2
- package/src/functional/pipe.test.mts +7 -4
- package/src/functional/result/impl/result-err.mts +4 -2
- package/src/functional/result/impl/result-expect-to-be.mts +5 -2
- package/src/functional/result/impl/result-flat-map.mts +7 -0
- package/src/functional/result/impl/result-fold.mts +6 -0
- package/src/functional/result/impl/result-from-promise.mts +4 -1
- package/src/functional/result/impl/result-from-throwable.mts +5 -1
- package/src/functional/result/impl/result-is-err.mts +4 -2
- package/src/functional/result/impl/result-is-ok.mts +4 -2
- package/src/functional/result/impl/result-is-result.mts +7 -3
- package/src/functional/result/impl/result-map-err.mts +5 -0
- package/src/functional/result/impl/result-map.mts +6 -0
- package/src/functional/result/impl/result-ok.mts +4 -2
- package/src/functional/result/impl/result-or-else.mts +6 -0
- package/src/functional/result/impl/result-swap.mts +2 -0
- package/src/functional/result/impl/result-to-optional.mts +2 -0
- package/src/functional/result/impl/result-unwrap-err-or.mts +9 -4
- package/src/functional/result/impl/result-unwrap-err-throw.mts +3 -1
- package/src/functional/result/impl/result-unwrap-err.mts +3 -2
- package/src/functional/result/impl/result-unwrap-ok-or.mts +9 -4
- package/src/functional/result/impl/result-unwrap-ok.mts +4 -2
- package/src/functional/result/impl/result-unwrap-throw.mts +3 -1
- package/src/functional/result/impl/result-zip.mts +3 -1
- package/src/functional/result.test.mts +182 -152
- package/src/functional/ternary-result/impl/ternary-result-err.mts +3 -2
- package/src/functional/ternary-result/impl/ternary-result-expect-to-be.mts +4 -0
- package/src/functional/ternary-result/impl/ternary-result-flat-map.mts +7 -0
- package/src/functional/ternary-result/impl/ternary-result-fold.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +3 -1
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +4 -1
- package/src/functional/ternary-result/impl/ternary-result-is-ok.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +7 -3
- package/src/functional/ternary-result/impl/ternary-result-is-warn.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-map-err.mts +6 -0
- package/src/functional/ternary-result/impl/ternary-result-map-warn.mts +6 -0
- package/src/functional/ternary-result/impl/ternary-result-map.mts +9 -0
- package/src/functional/ternary-result/impl/ternary-result-ok.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-or-else.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-to-optional.mts +2 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-or.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err.mts +2 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok.mts +3 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-throw.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn.mts +2 -0
- package/src/functional/ternary-result/impl/ternary-result-warn.mts +4 -1
- package/src/functional/ternary-result/impl/ternary-result-zip.mts +4 -0
- package/src/functional/ternary-result.test.mts +99 -8
- package/src/globals.d.mts +12 -1
- package/src/guard/has-key.mts +8 -5
- package/src/guard/has-key.test.mts +9 -5
- package/src/guard/is-error.test.mts +143 -0
- package/src/guard/is-non-empty-string.test.mts +44 -24
- package/src/guard/is-non-null-object.test.mts +45 -26
- package/src/guard/is-primitive.test.mts +51 -28
- package/src/guard/is-record.mts +34 -0
- package/src/guard/is-record.test.mts +28 -7
- package/src/guard/is-type.mts +3 -0
- package/src/guard/is-type.test.mts +285 -155
- package/src/guard/key-is-in.mts +3 -2
- package/src/guard/key-is-in.test.mts +2 -2
- package/src/iterator/range.mts +9 -0
- package/src/json/json.mts +50 -21
- package/src/json/json.test.mts +224 -176
- package/src/number/branded-types/finite-number.test.mts +51 -11
- package/src/number/branded-types/int.mts +33 -19
- package/src/number/branded-types/int.test.mts +56 -14
- package/src/number/branded-types/int16.test.mts +63 -16
- package/src/number/branded-types/int32.test.mts +63 -16
- package/src/number/branded-types/non-negative-finite-number.test.mts +52 -12
- package/src/number/branded-types/non-negative-int16.test.mts +59 -16
- package/src/number/branded-types/non-negative-int32.test.mts +59 -16
- package/src/number/branded-types/non-zero-finite-number.test.mts +65 -14
- package/src/number/branded-types/non-zero-int.test.mts +72 -19
- package/src/number/branded-types/non-zero-int16.test.mts +60 -16
- package/src/number/branded-types/non-zero-int32.test.mts +60 -16
- package/src/number/branded-types/non-zero-safe-int.mts +2 -2
- package/src/number/branded-types/non-zero-safe-int.test.mts +85 -23
- package/src/number/branded-types/non-zero-uint16.test.mts +53 -16
- package/src/number/branded-types/non-zero-uint32.test.mts +53 -16
- package/src/number/branded-types/positive-finite-number.test.mts +59 -14
- package/src/number/branded-types/positive-int.mts +34 -20
- package/src/number/branded-types/positive-int.test.mts +64 -17
- package/src/number/branded-types/positive-int16.test.mts +50 -15
- package/src/number/branded-types/positive-int32.test.mts +50 -15
- package/src/number/branded-types/positive-safe-int.mts +48 -27
- package/src/number/branded-types/positive-safe-int.test.mts +68 -19
- package/src/number/branded-types/positive-uint16.test.mts +53 -16
- package/src/number/branded-types/positive-uint32.test.mts +53 -16
- package/src/number/branded-types/safe-int.mts +50 -29
- package/src/number/branded-types/safe-int.test.mts +70 -18
- package/src/number/branded-types/safe-uint.mts +1 -1
- package/src/number/branded-types/safe-uint.test.mts +65 -17
- package/src/number/branded-types/uint.mts +31 -19
- package/src/number/branded-types/uint.test.mts +58 -15
- package/src/number/branded-types/uint16.test.mts +56 -15
- package/src/number/branded-types/uint32.test.mts +56 -15
- package/src/number/enum/int8.test.mts +7 -1
- package/src/number/enum/uint8.test.mts +7 -1
- package/src/number/num.mts +32 -21
- package/src/number/num.test.mts +88 -26
- package/src/number/refined-number-utils.mts +38 -13
- package/src/object/object.mts +19 -3
- package/src/object/object.test.mts +16 -6
- package/src/others/cast-mutable.test.mts +8 -1
- package/src/others/cast-readonly.test.mts +21 -4
- package/src/others/if-then.test.mts +40 -24
- package/src/others/map-nullable.mts +3 -0
- package/src/others/map-nullable.test.mts +27 -0
- package/src/others/memoize-function.test.mts +41 -0
- package/src/others/tuple.mts +14 -3
- package/src/others/unknown-to-string.mts +2 -0
- package/src/others/unknown-to-string.test.mts +10 -0
- package/src/promise/promise.mts +8 -4
- package/src/promise/promise.test.mts +8 -13
|
@@ -26,9 +26,9 @@ const {
|
|
|
26
26
|
SafeUint
|
|
27
27
|
>({
|
|
28
28
|
integerOrSafeInteger: 'SafeInteger',
|
|
29
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
29
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-min-safe-integer
|
|
30
30
|
MIN_VALUE: Number.MIN_SAFE_INTEGER as SafeInt,
|
|
31
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
31
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer
|
|
32
32
|
MAX_VALUE: Number.MAX_SAFE_INTEGER as SafeUint,
|
|
33
33
|
typeNameInMessage,
|
|
34
34
|
} as const);
|
|
@@ -42,9 +42,11 @@ const {
|
|
|
42
42
|
* @example
|
|
43
43
|
*
|
|
44
44
|
* ```ts
|
|
45
|
-
* assert.
|
|
46
|
-
*
|
|
47
|
-
* assert.
|
|
45
|
+
* assert.isTrue(isSafeInt(Number.MAX_SAFE_INTEGER));
|
|
46
|
+
*
|
|
47
|
+
* assert.isFalse(isSafeInt(Number.MAX_SAFE_INTEGER + 0.5));
|
|
48
|
+
*
|
|
49
|
+
* assert.isTrue(SafeInt.is(Number.MIN_SAFE_INTEGER));
|
|
48
50
|
* ```
|
|
49
51
|
*
|
|
50
52
|
* @param value - The value to check
|
|
@@ -64,8 +66,9 @@ export const isSafeInt = is;
|
|
|
64
66
|
* ```ts
|
|
65
67
|
* const branded = asSafeInt(123);
|
|
66
68
|
*
|
|
67
|
-
* assert(branded === 123);
|
|
68
|
-
*
|
|
69
|
+
* assert.isTrue(branded === 123);
|
|
70
|
+
*
|
|
71
|
+
* assert.isTrue(SafeInt.is(branded));
|
|
69
72
|
* ```
|
|
70
73
|
*
|
|
71
74
|
* @param value - The value to cast
|
|
@@ -97,9 +100,11 @@ export const SafeInt = {
|
|
|
97
100
|
* @example
|
|
98
101
|
*
|
|
99
102
|
* ```ts
|
|
100
|
-
* assert.
|
|
101
|
-
*
|
|
102
|
-
* assert.
|
|
103
|
+
* assert.isTrue(isSafeInt(Number.MAX_SAFE_INTEGER));
|
|
104
|
+
*
|
|
105
|
+
* assert.isFalse(isSafeInt(Number.MAX_SAFE_INTEGER + 0.5));
|
|
106
|
+
*
|
|
107
|
+
* assert.isTrue(SafeInt.is(Number.MIN_SAFE_INTEGER));
|
|
103
108
|
* ```
|
|
104
109
|
*
|
|
105
110
|
* @param value - The value to check
|
|
@@ -132,10 +137,12 @@ export const SafeInt = {
|
|
|
132
137
|
*
|
|
133
138
|
* ```ts
|
|
134
139
|
* const negative = asSafeInt(-900);
|
|
140
|
+
*
|
|
135
141
|
* const absolute = SafeInt.abs(negative);
|
|
136
142
|
*
|
|
137
|
-
* assert(absolute === 900);
|
|
138
|
-
*
|
|
143
|
+
* assert.isTrue(absolute === 900);
|
|
144
|
+
*
|
|
145
|
+
* assert.isTrue(SafeInt.is(absolute));
|
|
139
146
|
* ```
|
|
140
147
|
*
|
|
141
148
|
* @param a - The safe integer value
|
|
@@ -151,7 +158,7 @@ export const SafeInt = {
|
|
|
151
158
|
* ```ts
|
|
152
159
|
* const smallest = SafeInt.min(asSafeInt(25), asSafeInt(-14), asSafeInt(99));
|
|
153
160
|
*
|
|
154
|
-
* assert(smallest === -14);
|
|
161
|
+
* assert.isTrue(smallest === -14);
|
|
155
162
|
* ```
|
|
156
163
|
*
|
|
157
164
|
* @param values - The safe integers to compare (at least one required)
|
|
@@ -167,7 +174,7 @@ export const SafeInt = {
|
|
|
167
174
|
* ```ts
|
|
168
175
|
* const largest = SafeInt.max(asSafeInt(25), asSafeInt(-14), asSafeInt(99));
|
|
169
176
|
*
|
|
170
|
-
* assert(largest === 99);
|
|
177
|
+
* assert.isTrue(largest === 99);
|
|
171
178
|
* ```
|
|
172
179
|
*
|
|
173
180
|
* @param values - The safe integers to compare (at least one required)
|
|
@@ -182,12 +189,16 @@ export const SafeInt = {
|
|
|
182
189
|
*
|
|
183
190
|
* ```ts
|
|
184
191
|
* const aboveRange = SafeInt.clamp(1e20);
|
|
192
|
+
*
|
|
185
193
|
* const withinRange = SafeInt.clamp(123);
|
|
194
|
+
*
|
|
186
195
|
* const belowRange = SafeInt.clamp(-1e20);
|
|
187
196
|
*
|
|
188
|
-
* assert(aboveRange === Number.MAX_SAFE_INTEGER);
|
|
189
|
-
*
|
|
190
|
-
* assert(
|
|
197
|
+
* assert.isTrue(aboveRange === Number.MAX_SAFE_INTEGER);
|
|
198
|
+
*
|
|
199
|
+
* assert.isTrue(withinRange === 123);
|
|
200
|
+
*
|
|
201
|
+
* assert.isTrue(belowRange === Number.MIN_SAFE_INTEGER);
|
|
191
202
|
* ```
|
|
192
203
|
*
|
|
193
204
|
* @param value The number to clamp.
|
|
@@ -206,11 +217,14 @@ export const SafeInt = {
|
|
|
206
217
|
*
|
|
207
218
|
* ```ts
|
|
208
219
|
* const min = asSafeInt(-10);
|
|
220
|
+
*
|
|
209
221
|
* const max = asSafeInt(10);
|
|
222
|
+
*
|
|
210
223
|
* const randomValue = SafeInt.random(min, max);
|
|
211
224
|
*
|
|
212
|
-
* assert.
|
|
213
|
-
*
|
|
225
|
+
* assert.isTrue(SafeInt.is(randomValue));
|
|
226
|
+
*
|
|
227
|
+
* assert.isTrue(randomValue >= -10 && randomValue <= 10);
|
|
214
228
|
* ```
|
|
215
229
|
*
|
|
216
230
|
* @param min - The minimum value (inclusive)
|
|
@@ -226,11 +240,14 @@ export const SafeInt = {
|
|
|
226
240
|
*
|
|
227
241
|
* ```ts
|
|
228
242
|
* const base = asSafeInt(3);
|
|
243
|
+
*
|
|
229
244
|
* const exponent = asSafeInt(5);
|
|
245
|
+
*
|
|
230
246
|
* const power = SafeInt.pow(base, exponent);
|
|
231
247
|
*
|
|
232
|
-
* assert(power === 243);
|
|
233
|
-
*
|
|
248
|
+
* assert.isTrue(power === 243);
|
|
249
|
+
*
|
|
250
|
+
* assert.isTrue(SafeInt.is(power));
|
|
234
251
|
* ```
|
|
235
252
|
*
|
|
236
253
|
* @param a The base SafeInt.
|
|
@@ -247,8 +264,9 @@ export const SafeInt = {
|
|
|
247
264
|
* ```ts
|
|
248
265
|
* const sum = SafeInt.add(asSafeInt(9), asSafeInt(4));
|
|
249
266
|
*
|
|
250
|
-
* assert(sum === 13);
|
|
251
|
-
*
|
|
267
|
+
* assert.isTrue(sum === 13);
|
|
268
|
+
*
|
|
269
|
+
* assert.isTrue(SafeInt.is(sum));
|
|
252
270
|
* ```
|
|
253
271
|
*
|
|
254
272
|
* @param a The first SafeInt.
|
|
@@ -265,8 +283,9 @@ export const SafeInt = {
|
|
|
265
283
|
* ```ts
|
|
266
284
|
* const difference = SafeInt.sub(asSafeInt(9), asSafeInt(14));
|
|
267
285
|
*
|
|
268
|
-
* assert(difference === -5);
|
|
269
|
-
*
|
|
286
|
+
* assert.isTrue(difference === -5);
|
|
287
|
+
*
|
|
288
|
+
* assert.isTrue(SafeInt.is(difference));
|
|
270
289
|
* ```
|
|
271
290
|
*
|
|
272
291
|
* @param a The minuend SafeInt.
|
|
@@ -283,8 +302,9 @@ export const SafeInt = {
|
|
|
283
302
|
* ```ts
|
|
284
303
|
* const product = SafeInt.mul(asSafeInt(-8), asSafeInt(7));
|
|
285
304
|
*
|
|
286
|
-
* assert(product === -56);
|
|
287
|
-
*
|
|
305
|
+
* assert.isTrue(product === -56);
|
|
306
|
+
*
|
|
307
|
+
* assert.isTrue(SafeInt.is(product));
|
|
288
308
|
* ```
|
|
289
309
|
*
|
|
290
310
|
* @param a The first SafeInt.
|
|
@@ -304,8 +324,9 @@ export const SafeInt = {
|
|
|
304
324
|
* ```ts
|
|
305
325
|
* const quotient = SafeInt.div(asSafeInt(-17), asSafeInt(5));
|
|
306
326
|
*
|
|
307
|
-
* assert(quotient === -4);
|
|
308
|
-
*
|
|
327
|
+
* assert.isTrue(quotient === -4);
|
|
328
|
+
*
|
|
329
|
+
* assert.isTrue(SafeInt.is(quotient));
|
|
309
330
|
* ```
|
|
310
331
|
*
|
|
311
332
|
* @param a - The dividend
|
|
@@ -6,34 +6,51 @@ describe('SafeInt test', () => {
|
|
|
6
6
|
describe(asSafeInt, () => {
|
|
7
7
|
test('accepts valid safe integers', () => {
|
|
8
8
|
expect(() => asSafeInt(0)).not.toThrow();
|
|
9
|
+
|
|
9
10
|
expect(() => asSafeInt(1)).not.toThrow();
|
|
11
|
+
|
|
10
12
|
expect(() => asSafeInt(-1)).not.toThrow();
|
|
13
|
+
|
|
11
14
|
expect(() => asSafeInt(42)).not.toThrow();
|
|
15
|
+
|
|
12
16
|
expect(() => asSafeInt(-42)).not.toThrow();
|
|
17
|
+
|
|
13
18
|
expect(() => asSafeInt(Number.MAX_SAFE_INTEGER)).not.toThrow();
|
|
19
|
+
|
|
14
20
|
expect(() => asSafeInt(Number.MIN_SAFE_INTEGER)).not.toThrow();
|
|
15
21
|
});
|
|
16
22
|
|
|
17
23
|
test('rejects values outside safe integer range', () => {
|
|
18
24
|
expect(() => asSafeInt(Number.MAX_SAFE_INTEGER + 1)).toThrow(TypeError);
|
|
25
|
+
|
|
19
26
|
expect(() => asSafeInt(Number.MIN_SAFE_INTEGER - 1)).toThrow(TypeError);
|
|
27
|
+
|
|
20
28
|
expect(() => asSafeInt(Number.MAX_VALUE)).toThrow(TypeError);
|
|
29
|
+
|
|
21
30
|
expect(() => asSafeInt(-Number.MAX_VALUE)).toThrow(TypeError);
|
|
22
31
|
});
|
|
23
32
|
|
|
24
33
|
test('rejects non-integers', () => {
|
|
25
34
|
expect(() => asSafeInt(Number.NaN)).toThrow(TypeError);
|
|
35
|
+
|
|
26
36
|
expect(() => asSafeInt(Number.POSITIVE_INFINITY)).toThrow(TypeError);
|
|
37
|
+
|
|
27
38
|
expect(() => asSafeInt(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
|
|
39
|
+
|
|
28
40
|
expect(() => asSafeInt(1.2)).toThrow(TypeError);
|
|
41
|
+
|
|
29
42
|
expect(() => asSafeInt(-3.4)).toThrow(TypeError);
|
|
30
43
|
});
|
|
31
44
|
|
|
32
45
|
test('returns the same value for valid inputs', () => {
|
|
33
46
|
expect(asSafeInt(5)).toBe(5);
|
|
47
|
+
|
|
34
48
|
expect(asSafeInt(-10)).toBe(-10);
|
|
49
|
+
|
|
35
50
|
expect(asSafeInt(0)).toBe(0);
|
|
51
|
+
|
|
36
52
|
expect(asSafeInt(Number.MAX_SAFE_INTEGER)).toBe(Number.MAX_SAFE_INTEGER);
|
|
53
|
+
|
|
37
54
|
expect(asSafeInt(Number.MIN_SAFE_INTEGER)).toBe(Number.MIN_SAFE_INTEGER);
|
|
38
55
|
});
|
|
39
56
|
|
|
@@ -52,69 +69,94 @@ describe('SafeInt test', () => {
|
|
|
52
69
|
|
|
53
70
|
describe('SafeInt.is', () => {
|
|
54
71
|
test('correctly identifies safe integers', () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
72
|
+
assert.isTrue(SafeInt.is(0));
|
|
73
|
+
|
|
74
|
+
assert.isTrue(SafeInt.is(1));
|
|
75
|
+
|
|
76
|
+
assert.isTrue(SafeInt.is(-1));
|
|
77
|
+
|
|
78
|
+
assert.isTrue(SafeInt.is(42));
|
|
79
|
+
|
|
80
|
+
assert.isTrue(SafeInt.is(-42));
|
|
81
|
+
|
|
82
|
+
assert.isTrue(SafeInt.is(Number.MAX_SAFE_INTEGER));
|
|
83
|
+
|
|
84
|
+
assert.isTrue(SafeInt.is(Number.MIN_SAFE_INTEGER));
|
|
62
85
|
});
|
|
63
86
|
|
|
64
87
|
test('correctly identifies values outside safe integer range', () => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
88
|
+
assert.isFalse(SafeInt.is(Number.MAX_SAFE_INTEGER + 1));
|
|
89
|
+
|
|
90
|
+
assert.isFalse(SafeInt.is(Number.MIN_SAFE_INTEGER - 1));
|
|
91
|
+
|
|
92
|
+
assert.isFalse(SafeInt.is(Number.MAX_VALUE));
|
|
93
|
+
|
|
94
|
+
assert.isFalse(SafeInt.is(-Number.MAX_VALUE));
|
|
69
95
|
});
|
|
70
96
|
|
|
71
97
|
test('correctly identifies non-integers', () => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
98
|
+
assert.isFalse(SafeInt.is(Number.NaN));
|
|
99
|
+
|
|
100
|
+
assert.isFalse(SafeInt.is(Number.POSITIVE_INFINITY));
|
|
101
|
+
|
|
102
|
+
assert.isFalse(SafeInt.is(Number.NEGATIVE_INFINITY));
|
|
103
|
+
|
|
104
|
+
assert.isFalse(SafeInt.is(1.2));
|
|
105
|
+
|
|
106
|
+
assert.isFalse(SafeInt.is(-3.4));
|
|
77
107
|
});
|
|
78
108
|
});
|
|
79
109
|
|
|
80
110
|
describe('constants', () => {
|
|
81
111
|
test('MIN_VALUE and MAX_VALUE', () => {
|
|
82
112
|
expect(SafeInt.MIN_VALUE).toBe(Number.MIN_SAFE_INTEGER);
|
|
113
|
+
|
|
83
114
|
expect(SafeInt.MAX_VALUE).toBe(Number.MAX_SAFE_INTEGER);
|
|
84
115
|
});
|
|
85
116
|
});
|
|
86
117
|
|
|
87
118
|
describe('mathematical operations', () => {
|
|
88
119
|
const a = asSafeInt(5);
|
|
120
|
+
|
|
89
121
|
const b = asSafeInt(2);
|
|
122
|
+
|
|
90
123
|
const c = asSafeInt(-3);
|
|
91
124
|
|
|
92
125
|
test('abs', () => {
|
|
93
126
|
expect(SafeInt.abs(a)).toBe(5);
|
|
127
|
+
|
|
94
128
|
expect(SafeInt.abs(c)).toBe(3);
|
|
129
|
+
|
|
95
130
|
expect(SafeInt.abs(asSafeInt(0))).toBe(0);
|
|
96
131
|
});
|
|
97
132
|
|
|
98
133
|
test('min and max', () => {
|
|
99
134
|
expect(SafeInt.min(a, b)).toBe(2);
|
|
135
|
+
|
|
100
136
|
expect(SafeInt.max(a, b)).toBe(5);
|
|
137
|
+
|
|
101
138
|
expect(SafeInt.min(a, c)).toBe(-3);
|
|
139
|
+
|
|
102
140
|
expect(SafeInt.max(a, c)).toBe(5);
|
|
103
141
|
});
|
|
104
142
|
|
|
105
143
|
test('add (with clamping to safe integer range)', () => {
|
|
106
144
|
const largeValue = asSafeInt(Number.MAX_SAFE_INTEGER - 1);
|
|
145
|
+
|
|
107
146
|
const result = SafeInt.add(largeValue, asSafeInt(10));
|
|
108
147
|
|
|
109
148
|
expect(result).toBe(Number.MAX_SAFE_INTEGER); // clamped to max
|
|
149
|
+
|
|
110
150
|
expect(SafeInt.add(a, b)).toBe(7);
|
|
111
151
|
});
|
|
112
152
|
|
|
113
153
|
test('sub (with clamping to safe integer range)', () => {
|
|
114
154
|
const smallValue = asSafeInt(Number.MIN_SAFE_INTEGER + 1);
|
|
155
|
+
|
|
115
156
|
const result = SafeInt.sub(smallValue, asSafeInt(10));
|
|
116
157
|
|
|
117
158
|
expect(result).toBe(Number.MIN_SAFE_INTEGER); // clamped to min
|
|
159
|
+
|
|
118
160
|
expect(SafeInt.sub(a, b)).toBe(3);
|
|
119
161
|
});
|
|
120
162
|
|
|
@@ -122,15 +164,19 @@ describe('SafeInt test', () => {
|
|
|
122
164
|
const largeValue = asSafeInt(
|
|
123
165
|
Math.floor(Math.sqrt(Number.MAX_SAFE_INTEGER)),
|
|
124
166
|
);
|
|
167
|
+
|
|
125
168
|
const result = SafeInt.mul(largeValue, largeValue);
|
|
126
169
|
|
|
127
170
|
expect(result).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER);
|
|
171
|
+
|
|
128
172
|
expect(SafeInt.mul(asSafeInt(10), asSafeInt(5))).toBe(50);
|
|
129
173
|
});
|
|
130
174
|
|
|
131
175
|
test('div (floor division with clamping)', () => {
|
|
132
176
|
expect(SafeInt.div(a, b)).toBe(2);
|
|
177
|
+
|
|
133
178
|
expect(SafeInt.div(asSafeInt(7), asSafeInt(3))).toBe(2);
|
|
179
|
+
|
|
134
180
|
expect(SafeInt.div(asSafeInt(-7), asSafeInt(3))).toBe(-3);
|
|
135
181
|
});
|
|
136
182
|
|
|
@@ -138,6 +184,7 @@ describe('SafeInt test', () => {
|
|
|
138
184
|
const result = SafeInt.pow(asSafeInt(1000), asSafeInt(10));
|
|
139
185
|
|
|
140
186
|
expect(result).toBe(Number.MAX_SAFE_INTEGER); // clamped to max
|
|
187
|
+
|
|
141
188
|
expect(SafeInt.pow(asSafeInt(2), asSafeInt(3))).toBe(8);
|
|
142
189
|
});
|
|
143
190
|
});
|
|
@@ -145,15 +192,19 @@ describe('SafeInt test', () => {
|
|
|
145
192
|
describe('random', () => {
|
|
146
193
|
test('generates safe integers within specified range', () => {
|
|
147
194
|
const min = -20;
|
|
195
|
+
|
|
148
196
|
const max = 20;
|
|
149
197
|
|
|
150
198
|
for (const _ of range(10)) {
|
|
151
199
|
const result = SafeInt.random(min, max);
|
|
152
200
|
|
|
153
201
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
202
|
+
|
|
154
203
|
expect(result).toBeLessThanOrEqual(max);
|
|
155
|
-
|
|
156
|
-
|
|
204
|
+
|
|
205
|
+
assert.isTrue(SafeInt.is(result));
|
|
206
|
+
|
|
207
|
+
assert.isTrue(Number.isInteger(result));
|
|
157
208
|
}
|
|
158
209
|
});
|
|
159
210
|
|
|
@@ -162,6 +213,7 @@ describe('SafeInt test', () => {
|
|
|
162
213
|
const result = SafeInt.random(-30, 30);
|
|
163
214
|
|
|
164
215
|
expect(result).toBeGreaterThanOrEqual(Number.MIN_SAFE_INTEGER);
|
|
216
|
+
|
|
165
217
|
expect(result).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER);
|
|
166
218
|
}
|
|
167
219
|
});
|
|
@@ -26,7 +26,7 @@ const {
|
|
|
26
26
|
>({
|
|
27
27
|
integerOrSafeInteger: 'SafeInteger',
|
|
28
28
|
MIN_VALUE: 0,
|
|
29
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
29
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, math/prefer-number-max-safe-integer
|
|
30
30
|
MAX_VALUE: Number.MAX_SAFE_INTEGER as SafeUint,
|
|
31
31
|
typeNameInMessage,
|
|
32
32
|
} as const);
|
|
@@ -6,35 +6,49 @@ describe('SafeUint test', () => {
|
|
|
6
6
|
describe(asSafeUint, () => {
|
|
7
7
|
test('accepts valid safe unsigned integers', () => {
|
|
8
8
|
expect(() => asSafeUint(0)).not.toThrow();
|
|
9
|
+
|
|
9
10
|
expect(() => asSafeUint(1)).not.toThrow();
|
|
11
|
+
|
|
10
12
|
expect(() => asSafeUint(42)).not.toThrow();
|
|
13
|
+
|
|
11
14
|
expect(() => asSafeUint(100)).not.toThrow();
|
|
15
|
+
|
|
12
16
|
expect(() => asSafeUint(Number.MAX_SAFE_INTEGER)).not.toThrow();
|
|
13
17
|
});
|
|
14
18
|
|
|
15
19
|
test('rejects negative numbers', () => {
|
|
16
20
|
expect(() => asSafeUint(-1)).toThrow(TypeError);
|
|
21
|
+
|
|
17
22
|
expect(() => asSafeUint(-42)).toThrow(TypeError);
|
|
23
|
+
|
|
18
24
|
expect(() => asSafeUint(Number.MIN_SAFE_INTEGER)).toThrow(TypeError);
|
|
19
25
|
});
|
|
20
26
|
|
|
21
27
|
test('rejects values outside safe integer range', () => {
|
|
22
28
|
expect(() => asSafeUint(Number.MAX_SAFE_INTEGER + 1)).toThrow(TypeError);
|
|
29
|
+
|
|
23
30
|
expect(() => asSafeUint(Number.MAX_VALUE)).toThrow(TypeError);
|
|
24
31
|
});
|
|
25
32
|
|
|
26
33
|
test('rejects non-integers', () => {
|
|
27
34
|
expect(() => asSafeUint(Number.NaN)).toThrow(TypeError);
|
|
35
|
+
|
|
28
36
|
expect(() => asSafeUint(Number.POSITIVE_INFINITY)).toThrow(TypeError);
|
|
37
|
+
|
|
29
38
|
expect(() => asSafeUint(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
|
|
39
|
+
|
|
30
40
|
expect(() => asSafeUint(1.2)).toThrow(TypeError);
|
|
41
|
+
|
|
31
42
|
expect(() => asSafeUint(-3.4)).toThrow(TypeError);
|
|
32
43
|
});
|
|
33
44
|
|
|
34
45
|
test('returns the same value for valid inputs', () => {
|
|
35
46
|
expect(asSafeUint(5)).toBe(5);
|
|
47
|
+
|
|
36
48
|
expect(asSafeUint(0)).toBe(0);
|
|
49
|
+
|
|
37
50
|
expect(asSafeUint(10)).toBe(10);
|
|
51
|
+
|
|
38
52
|
expect(asSafeUint(Number.MAX_SAFE_INTEGER)).toBe(Number.MAX_SAFE_INTEGER);
|
|
39
53
|
});
|
|
40
54
|
|
|
@@ -54,37 +68,50 @@ describe('SafeUint test', () => {
|
|
|
54
68
|
|
|
55
69
|
describe(isSafeUint, () => {
|
|
56
70
|
test('correctly identifies safe unsigned integers', () => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
71
|
+
assert.isTrue(isSafeUint(0));
|
|
72
|
+
|
|
73
|
+
assert.isTrue(isSafeUint(1));
|
|
74
|
+
|
|
75
|
+
assert.isTrue(isSafeUint(42));
|
|
76
|
+
|
|
77
|
+
assert.isTrue(isSafeUint(100));
|
|
78
|
+
|
|
79
|
+
assert.isTrue(isSafeUint(Number.MAX_SAFE_INTEGER));
|
|
62
80
|
});
|
|
63
81
|
|
|
64
82
|
test('correctly identifies negative numbers', () => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
83
|
+
assert.isFalse(isSafeUint(-1));
|
|
84
|
+
|
|
85
|
+
assert.isFalse(isSafeUint(-42));
|
|
86
|
+
|
|
87
|
+
assert.isFalse(isSafeUint(Number.MIN_SAFE_INTEGER));
|
|
68
88
|
});
|
|
69
89
|
|
|
70
90
|
test('correctly identifies values outside safe integer range', () => {
|
|
71
|
-
|
|
72
|
-
|
|
91
|
+
assert.isFalse(isSafeUint(Number.MAX_SAFE_INTEGER + 1));
|
|
92
|
+
|
|
93
|
+
assert.isFalse(isSafeUint(Number.MAX_VALUE));
|
|
73
94
|
});
|
|
74
95
|
|
|
75
96
|
test('correctly identifies non-integers', () => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
97
|
+
assert.isFalse(isSafeUint(Number.NaN));
|
|
98
|
+
|
|
99
|
+
assert.isFalse(isSafeUint(Number.POSITIVE_INFINITY));
|
|
100
|
+
|
|
101
|
+
assert.isFalse(isSafeUint(Number.NEGATIVE_INFINITY));
|
|
102
|
+
|
|
103
|
+
assert.isFalse(isSafeUint(1.2));
|
|
104
|
+
|
|
105
|
+
assert.isFalse(isSafeUint(-3.4));
|
|
81
106
|
});
|
|
82
107
|
});
|
|
83
108
|
|
|
84
109
|
describe('SafeUint.is', () => {
|
|
85
110
|
test('same as isSafeUint function', () => {
|
|
86
111
|
expect(SafeUint.is(5)).toBe(isSafeUint(5));
|
|
112
|
+
|
|
87
113
|
expect(SafeUint.is(-1)).toBe(isSafeUint(-1));
|
|
114
|
+
|
|
88
115
|
expect(SafeUint.is(0)).toBe(isSafeUint(0));
|
|
89
116
|
});
|
|
90
117
|
});
|
|
@@ -92,33 +119,43 @@ describe('SafeUint test', () => {
|
|
|
92
119
|
describe('constants', () => {
|
|
93
120
|
test('MIN_VALUE and MAX_VALUE', () => {
|
|
94
121
|
expect(SafeUint.MIN_VALUE).toBe(0);
|
|
122
|
+
|
|
95
123
|
expect(SafeUint.MAX_VALUE).toBe(Number.MAX_SAFE_INTEGER);
|
|
96
124
|
});
|
|
97
125
|
});
|
|
98
126
|
|
|
99
127
|
describe('mathematical operations', () => {
|
|
100
128
|
const a = asSafeUint(5);
|
|
129
|
+
|
|
101
130
|
const b = asSafeUint(2);
|
|
131
|
+
|
|
102
132
|
const c = asSafeUint(0);
|
|
103
133
|
|
|
104
134
|
test('min and max', () => {
|
|
105
135
|
expect(SafeUint.min(a, b)).toBe(2);
|
|
136
|
+
|
|
106
137
|
expect(SafeUint.max(a, b)).toBe(5);
|
|
138
|
+
|
|
107
139
|
expect(SafeUint.min(a, c)).toBe(0);
|
|
140
|
+
|
|
108
141
|
expect(SafeUint.max(a, c)).toBe(5);
|
|
109
142
|
});
|
|
110
143
|
|
|
111
144
|
test('add (clamped to safe uint range)', () => {
|
|
112
145
|
const largeValue = asSafeUint(Number.MAX_SAFE_INTEGER - 1);
|
|
146
|
+
|
|
113
147
|
const result = SafeUint.add(largeValue, asSafeUint(10));
|
|
114
148
|
|
|
115
149
|
expect(result).toBe(Number.MAX_SAFE_INTEGER); // clamped to max
|
|
150
|
+
|
|
116
151
|
expect(SafeUint.add(a, b)).toBe(7);
|
|
117
152
|
});
|
|
118
153
|
|
|
119
154
|
test('sub (never goes below 0)', () => {
|
|
120
155
|
expect(SafeUint.sub(a, b)).toBe(3);
|
|
156
|
+
|
|
121
157
|
expect(SafeUint.sub(b, a)).toBe(0); // clamped to 0
|
|
158
|
+
|
|
122
159
|
expect(SafeUint.sub(c, a)).toBe(0); // clamped to 0
|
|
123
160
|
});
|
|
124
161
|
|
|
@@ -126,15 +163,19 @@ describe('SafeUint test', () => {
|
|
|
126
163
|
const largeValue = asSafeUint(
|
|
127
164
|
Math.floor(Math.sqrt(Number.MAX_SAFE_INTEGER)),
|
|
128
165
|
);
|
|
166
|
+
|
|
129
167
|
const result = SafeUint.mul(largeValue, largeValue);
|
|
130
168
|
|
|
131
169
|
expect(result).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER);
|
|
170
|
+
|
|
132
171
|
expect(SafeUint.mul(asSafeUint(10), asSafeUint(5))).toBe(50);
|
|
133
172
|
});
|
|
134
173
|
|
|
135
174
|
test('div (floor division, never goes below 0)', () => {
|
|
136
175
|
expect(SafeUint.div(a, b)).toBe(2);
|
|
176
|
+
|
|
137
177
|
expect(SafeUint.div(asSafeUint(7), asSafeUint(3))).toBe(2);
|
|
178
|
+
|
|
138
179
|
expect(SafeUint.div(b, a)).toBe(0); // floor(2/5) = 0
|
|
139
180
|
});
|
|
140
181
|
|
|
@@ -142,6 +183,7 @@ describe('SafeUint test', () => {
|
|
|
142
183
|
const result = SafeUint.pow(asSafeUint(1000), asSafeUint(10));
|
|
143
184
|
|
|
144
185
|
expect(result).toBe(Number.MAX_SAFE_INTEGER); // clamped to max
|
|
186
|
+
|
|
145
187
|
expect(SafeUint.pow(asSafeUint(2), asSafeUint(3))).toBe(8);
|
|
146
188
|
});
|
|
147
189
|
});
|
|
@@ -149,15 +191,20 @@ describe('SafeUint test', () => {
|
|
|
149
191
|
describe('random', () => {
|
|
150
192
|
test('generates safe unsigned integers within specified range', () => {
|
|
151
193
|
const min = 0;
|
|
194
|
+
|
|
152
195
|
const max = 20;
|
|
153
196
|
|
|
154
197
|
for (const _ of range(10)) {
|
|
155
198
|
const result = SafeUint.random(min, max);
|
|
156
199
|
|
|
157
200
|
expect(result).toBeGreaterThanOrEqual(min);
|
|
201
|
+
|
|
158
202
|
expect(result).toBeLessThanOrEqual(max);
|
|
159
|
-
|
|
160
|
-
|
|
203
|
+
|
|
204
|
+
assert.isTrue(SafeUint.is(result));
|
|
205
|
+
|
|
206
|
+
assert.isTrue(Number.isInteger(result));
|
|
207
|
+
|
|
161
208
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
162
209
|
}
|
|
163
210
|
});
|
|
@@ -167,6 +214,7 @@ describe('SafeUint test', () => {
|
|
|
167
214
|
const result = SafeUint.random(0, 30);
|
|
168
215
|
|
|
169
216
|
expect(result).toBeGreaterThanOrEqual(0);
|
|
217
|
+
|
|
170
218
|
expect(result).toBeLessThanOrEqual(Number.MAX_SAFE_INTEGER);
|
|
171
219
|
}
|
|
172
220
|
});
|