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