ts-data-forge 5.0.0 → 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 +7 -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 +1 -0
- 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 +2 -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 +1 -0
- 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 +7 -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 +1 -0
- 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 +3 -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 +9 -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 +8 -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 +4 -1
- 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 +4 -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 +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 +22 -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 +23 -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 +2 -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 +5 -0
- package/dist/promise/promise.mjs.map +1 -1
- package/package.json +20 -24
- 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 +55 -9
- 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 +6 -1
- 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 +5 -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 +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 +4 -1
- 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
|
@@ -3,67 +3,85 @@ import { memoizeFunction } from './memoize-function.mjs';
|
|
|
3
3
|
describe(memoizeFunction, () => {
|
|
4
4
|
test('should cache results for the same arguments', () => {
|
|
5
5
|
const mockFn = vi.fn((x: number) => x * 2);
|
|
6
|
+
|
|
6
7
|
const memoized = memoizeFunction(mockFn, (x) => x);
|
|
7
8
|
|
|
8
9
|
// First call
|
|
9
10
|
expect(memoized(5)).toBe(10);
|
|
11
|
+
|
|
10
12
|
expect(mockFn).toHaveBeenCalledOnce();
|
|
11
13
|
|
|
12
14
|
// Second call with same argument - should use cache
|
|
13
15
|
expect(memoized(5)).toBe(10);
|
|
16
|
+
|
|
14
17
|
expect(mockFn).toHaveBeenCalledOnce();
|
|
15
18
|
|
|
16
19
|
// Call with different argument
|
|
17
20
|
expect(memoized(3)).toBe(6);
|
|
21
|
+
|
|
18
22
|
expect(mockFn).toHaveBeenCalledTimes(2);
|
|
19
23
|
});
|
|
20
24
|
|
|
21
25
|
test('should work with multiple arguments', () => {
|
|
22
26
|
const mockFn = vi.fn((a: number, b: number) => a + b);
|
|
27
|
+
|
|
23
28
|
const memoized = memoizeFunction(mockFn, (a, b) => `${a},${b}`);
|
|
24
29
|
|
|
25
30
|
expect(memoized(2, 3)).toBe(5);
|
|
31
|
+
|
|
26
32
|
expect(mockFn).toHaveBeenCalledOnce();
|
|
27
33
|
|
|
28
34
|
expect(memoized(2, 3)).toBe(5);
|
|
35
|
+
|
|
29
36
|
expect(mockFn).toHaveBeenCalledOnce();
|
|
30
37
|
|
|
31
38
|
expect(memoized(3, 2)).toBe(5);
|
|
39
|
+
|
|
32
40
|
expect(mockFn).toHaveBeenCalledTimes(2);
|
|
33
41
|
});
|
|
34
42
|
|
|
35
43
|
test('should handle functions that return undefined', () => {
|
|
36
44
|
const mockFn = vi.fn((_x: number) => undefined);
|
|
45
|
+
|
|
37
46
|
const memoized = memoizeFunction(mockFn, (x) => x);
|
|
38
47
|
|
|
39
48
|
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
40
49
|
expect(memoized(5)).toBeUndefined();
|
|
50
|
+
|
|
41
51
|
expect(mockFn).toHaveBeenCalledOnce();
|
|
42
52
|
|
|
43
53
|
// Should use cache even for undefined
|
|
44
54
|
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
45
55
|
expect(memoized(5)).toBeUndefined();
|
|
56
|
+
|
|
46
57
|
expect(mockFn).toHaveBeenCalledOnce();
|
|
47
58
|
});
|
|
48
59
|
|
|
49
60
|
test('should work with object arguments using primitive cache keys', () => {
|
|
50
61
|
type User = Readonly<{ id: number; name: string }>;
|
|
62
|
+
|
|
51
63
|
const mockFn = vi.fn((user: User) => `Hello ${user.name}`);
|
|
64
|
+
|
|
52
65
|
const memoized = memoizeFunction(mockFn, (user) => user.id);
|
|
53
66
|
|
|
54
67
|
const user1 = { id: 1, name: 'Alice' };
|
|
68
|
+
|
|
55
69
|
const user2 = { id: 1, name: 'Bob' }; // Same id, different name
|
|
70
|
+
|
|
56
71
|
const user3 = { id: 2, name: 'Charlie' };
|
|
57
72
|
|
|
58
73
|
expect(memoized(user1)).toBe('Hello Alice');
|
|
74
|
+
|
|
59
75
|
expect(mockFn).toHaveBeenCalledOnce();
|
|
60
76
|
|
|
61
77
|
// Same id, should use cache (even though name is different)
|
|
62
78
|
expect(memoized(user2)).toBe('Hello Alice');
|
|
79
|
+
|
|
63
80
|
expect(mockFn).toHaveBeenCalledOnce();
|
|
64
81
|
|
|
65
82
|
// Different id, should call function
|
|
66
83
|
expect(memoized(user3)).toBe('Hello Charlie');
|
|
84
|
+
|
|
67
85
|
expect(mockFn).toHaveBeenCalledTimes(2);
|
|
68
86
|
});
|
|
69
87
|
|
|
@@ -75,6 +93,7 @@ describe(memoizeFunction, () => {
|
|
|
75
93
|
);
|
|
76
94
|
|
|
77
95
|
expect(withNumber('hello')).toBe(5);
|
|
96
|
+
|
|
78
97
|
expect(withNumber('world')).toBe(5); // Same length, uses cache
|
|
79
98
|
|
|
80
99
|
// Boolean key
|
|
@@ -84,57 +103,74 @@ describe(memoizeFunction, () => {
|
|
|
84
103
|
);
|
|
85
104
|
|
|
86
105
|
expect(withBoolean(5)).toBe(10);
|
|
106
|
+
|
|
87
107
|
expect(withBoolean(3)).toBe(10); // Both positive, uses cache
|
|
108
|
+
|
|
88
109
|
expect(withBoolean(-2)).toBe(-4); // Negative, new cache entry
|
|
89
110
|
|
|
90
111
|
// Symbol key
|
|
91
112
|
const sym1 = Symbol('test');
|
|
113
|
+
|
|
92
114
|
const sym2 = Symbol('test');
|
|
115
|
+
|
|
93
116
|
const withSymbol = memoizeFunction(
|
|
94
117
|
(_s: symbol) => Math.random(),
|
|
95
118
|
(s) => s,
|
|
96
119
|
);
|
|
120
|
+
|
|
97
121
|
const result1 = withSymbol(sym1);
|
|
98
122
|
|
|
99
123
|
expect(withSymbol(sym1)).toBe(result1); // Same symbol, uses cache
|
|
124
|
+
|
|
100
125
|
expect(withSymbol(sym2)).not.toBe(result1); // Different symbol
|
|
101
126
|
});
|
|
102
127
|
|
|
103
128
|
test('should handle null and undefined cache keys', () => {
|
|
104
129
|
const mockFn = vi.fn((x: string | null | undefined) => x ?? 'default');
|
|
130
|
+
|
|
105
131
|
const memoized = memoizeFunction(mockFn, (x) => x);
|
|
106
132
|
|
|
107
133
|
expect(memoized(null)).toBe('default');
|
|
134
|
+
|
|
108
135
|
expect(mockFn).toHaveBeenCalledOnce();
|
|
109
136
|
|
|
110
137
|
expect(memoized(null)).toBe('default');
|
|
138
|
+
|
|
111
139
|
expect(mockFn).toHaveBeenCalledOnce();
|
|
112
140
|
|
|
113
141
|
expect(memoized(undefined)).toBe('default');
|
|
142
|
+
|
|
114
143
|
expect(mockFn).toHaveBeenCalledTimes(2);
|
|
115
144
|
|
|
116
145
|
expect(memoized(undefined)).toBe('default');
|
|
146
|
+
|
|
117
147
|
expect(mockFn).toHaveBeenCalledTimes(2);
|
|
118
148
|
});
|
|
119
149
|
|
|
120
150
|
test('should maintain separate caches for different memoized functions', () => {
|
|
121
151
|
const fn1 = vi.fn((x: number) => x * 2);
|
|
152
|
+
|
|
122
153
|
const fn2 = vi.fn((x: number) => x * 3);
|
|
123
154
|
|
|
124
155
|
const memoized1 = memoizeFunction(fn1, (x) => x);
|
|
156
|
+
|
|
125
157
|
const memoized2 = memoizeFunction(fn2, (x) => x);
|
|
126
158
|
|
|
127
159
|
expect(memoized1(5)).toBe(10);
|
|
160
|
+
|
|
128
161
|
expect(memoized2(5)).toBe(15);
|
|
129
162
|
|
|
130
163
|
expect(fn1).toHaveBeenCalledOnce();
|
|
164
|
+
|
|
131
165
|
expect(fn2).toHaveBeenCalledOnce();
|
|
132
166
|
|
|
133
167
|
// Each has its own cache
|
|
134
168
|
expect(memoized1(5)).toBe(10);
|
|
169
|
+
|
|
135
170
|
expect(memoized2(5)).toBe(15);
|
|
136
171
|
|
|
137
172
|
expect(fn1).toHaveBeenCalledOnce();
|
|
173
|
+
|
|
138
174
|
expect(fn2).toHaveBeenCalledOnce();
|
|
139
175
|
});
|
|
140
176
|
|
|
@@ -155,18 +191,23 @@ describe(memoizeFunction, () => {
|
|
|
155
191
|
);
|
|
156
192
|
|
|
157
193
|
const args1 = { category: 'books', subcategory: 'fiction', id: 123 };
|
|
194
|
+
|
|
158
195
|
const args2 = { category: 'books', subcategory: 'fiction', id: 123 };
|
|
196
|
+
|
|
159
197
|
const args3 = { category: 'books', subcategory: 'fiction', id: 124 };
|
|
160
198
|
|
|
161
199
|
expect(memoized(args1)).toBe('books/fiction/123');
|
|
200
|
+
|
|
162
201
|
expect(mockFn).toHaveBeenCalledOnce();
|
|
163
202
|
|
|
164
203
|
// Same cache key, should use cache
|
|
165
204
|
expect(memoized(args2)).toBe('books/fiction/123');
|
|
205
|
+
|
|
166
206
|
expect(mockFn).toHaveBeenCalledOnce();
|
|
167
207
|
|
|
168
208
|
// Different id, different cache key
|
|
169
209
|
expect(memoized(args3)).toBe('books/fiction/124');
|
|
210
|
+
|
|
170
211
|
expect(mockFn).toHaveBeenCalledTimes(2);
|
|
171
212
|
});
|
|
172
213
|
});
|
package/src/others/tuple.mts
CHANGED
|
@@ -7,27 +7,38 @@
|
|
|
7
7
|
* ```ts
|
|
8
8
|
* // Create a tuple with literal types preserved
|
|
9
9
|
* const coordinates = tp(10, 20, 30);
|
|
10
|
+
*
|
|
10
11
|
* expectType<typeof coordinates, readonly [10, 20, 30]>('=');
|
|
12
|
+
*
|
|
11
13
|
* expectType<typeof coordinates, readonly number[]>('!=');
|
|
14
|
+
*
|
|
12
15
|
* assert.deepStrictEqual(coordinates, [10, 20, 30]);
|
|
13
16
|
*
|
|
14
17
|
* // The following two are equivalent
|
|
15
18
|
* const a = tp(1, 2);
|
|
19
|
+
*
|
|
16
20
|
* const b = [1, 2] as const;
|
|
21
|
+
*
|
|
17
22
|
* expectType<typeof a, typeof b>('=');
|
|
23
|
+
*
|
|
18
24
|
* assert.deepStrictEqual(a, b);
|
|
19
25
|
*
|
|
20
26
|
* // Without tp, type would be number[]
|
|
21
27
|
* const point = tp('x', 42, true);
|
|
28
|
+
*
|
|
22
29
|
* expectType<typeof point, readonly ['x', 42, true]>('=');
|
|
30
|
+
*
|
|
23
31
|
* assert.deepStrictEqual(point, ['x', 42, true]);
|
|
24
32
|
*
|
|
25
33
|
* // Useful for creating const tuples
|
|
26
34
|
* const rgb = tp(255, 128, 0);
|
|
35
|
+
*
|
|
27
36
|
* expectType<typeof rgb, readonly [255, 128, 0]>('=');
|
|
28
37
|
*
|
|
29
38
|
* assert(rgb[0] === 255);
|
|
39
|
+
*
|
|
30
40
|
* assert(rgb[1] === 128);
|
|
41
|
+
*
|
|
31
42
|
* assert(rgb[2] === 0);
|
|
32
43
|
* ```
|
|
33
44
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isError } from '@sindresorhus/is';
|
|
1
2
|
import { isNonNullish } from '../guard/index.mjs';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -50,14 +51,16 @@ export const unknownToString = (
|
|
|
50
51
|
if (!isNonNullish(value)) {
|
|
51
52
|
return 'null';
|
|
52
53
|
}
|
|
54
|
+
|
|
53
55
|
try {
|
|
54
56
|
const stringified =
|
|
55
57
|
options?.prettyPrintObject === true
|
|
56
58
|
? JSON.stringify(value, undefined, 2)
|
|
57
59
|
: JSON.stringify(value);
|
|
60
|
+
|
|
58
61
|
return stringified;
|
|
59
62
|
} catch (error) {
|
|
60
|
-
return
|
|
63
|
+
return isError(error)
|
|
61
64
|
? error.message
|
|
62
65
|
: '[Circular or Non-serializable]';
|
|
63
66
|
}
|
|
@@ -5,6 +5,7 @@ describe(unknownToString, () => {
|
|
|
5
5
|
const result = unknownToString('aaaaa');
|
|
6
6
|
|
|
7
7
|
expect(result).toBe('aaaaa');
|
|
8
|
+
|
|
8
9
|
expect(JSON.stringify('aaaaa')).toBe('"aaaaa"');
|
|
9
10
|
});
|
|
10
11
|
|
|
@@ -12,6 +13,7 @@ describe(unknownToString, () => {
|
|
|
12
13
|
const result = unknownToString(1);
|
|
13
14
|
|
|
14
15
|
expect(result).toBe('1');
|
|
16
|
+
|
|
15
17
|
expect(JSON.stringify(1)).toBe('1');
|
|
16
18
|
});
|
|
17
19
|
|
|
@@ -19,6 +21,7 @@ describe(unknownToString, () => {
|
|
|
19
21
|
const result = unknownToString(true);
|
|
20
22
|
|
|
21
23
|
expect(result).toBe('true');
|
|
24
|
+
|
|
22
25
|
expect(JSON.stringify(true)).toBe('true');
|
|
23
26
|
});
|
|
24
27
|
|
|
@@ -26,6 +29,7 @@ describe(unknownToString, () => {
|
|
|
26
29
|
const result = unknownToString(Symbol('sym'));
|
|
27
30
|
|
|
28
31
|
expect(result).toBe('Symbol(sym)');
|
|
32
|
+
|
|
29
33
|
expect(JSON.stringify(Symbol('sym'))).toBeUndefined();
|
|
30
34
|
});
|
|
31
35
|
|
|
@@ -33,6 +37,7 @@ describe(unknownToString, () => {
|
|
|
33
37
|
const result = unknownToString(() => 0);
|
|
34
38
|
|
|
35
39
|
expect(result).toBe('() => 0');
|
|
40
|
+
|
|
36
41
|
expect(JSON.stringify(() => 0)).toBeUndefined();
|
|
37
42
|
});
|
|
38
43
|
|
|
@@ -40,6 +45,7 @@ describe(unknownToString, () => {
|
|
|
40
45
|
const result = unknownToString(undefined);
|
|
41
46
|
|
|
42
47
|
expect(result).toBe('undefined');
|
|
48
|
+
|
|
43
49
|
expect(JSON.stringify(undefined)).toBeUndefined();
|
|
44
50
|
});
|
|
45
51
|
|
|
@@ -47,6 +53,7 @@ describe(unknownToString, () => {
|
|
|
47
53
|
const result = unknownToString(null);
|
|
48
54
|
|
|
49
55
|
expect(result).toBe('null');
|
|
56
|
+
|
|
50
57
|
expect(JSON.stringify(null)).toBe('null');
|
|
51
58
|
});
|
|
52
59
|
|
|
@@ -54,6 +61,7 @@ describe(unknownToString, () => {
|
|
|
54
61
|
const result = unknownToString({ a: { b: 1 } });
|
|
55
62
|
|
|
56
63
|
expect(result).toBe('{"a":{"b":1}}');
|
|
64
|
+
|
|
57
65
|
expect(JSON.stringify({ a: { b: 1 } })).toBe('{"a":{"b":1}}');
|
|
58
66
|
});
|
|
59
67
|
|
|
@@ -77,7 +85,9 @@ describe(unknownToString, () => {
|
|
|
77
85
|
|
|
78
86
|
test('circular reference returns error message', () => {
|
|
79
87
|
const mut_circular: { a: number; self?: unknown } = { a: 1 };
|
|
88
|
+
|
|
80
89
|
mut_circular.self = mut_circular;
|
|
90
|
+
|
|
81
91
|
const result = unknownToString(mut_circular);
|
|
82
92
|
|
|
83
93
|
// Should return an error message string instead of throwing
|
package/src/promise/promise.mts
CHANGED
|
@@ -17,7 +17,9 @@ import { Result } from '../functional/index.mjs';
|
|
|
17
17
|
* });
|
|
18
18
|
*
|
|
19
19
|
* const successResult = await successPromise;
|
|
20
|
+
*
|
|
20
21
|
* assert.ok(Result.isOk(successResult));
|
|
22
|
+
*
|
|
21
23
|
* if (Result.isOk(successResult)) {
|
|
22
24
|
* assert(successResult.value === 42);
|
|
23
25
|
* }
|
|
@@ -30,7 +32,9 @@ import { Result } from '../functional/index.mjs';
|
|
|
30
32
|
* });
|
|
31
33
|
*
|
|
32
34
|
* const errorResult = await errorPromise;
|
|
35
|
+
*
|
|
33
36
|
* assert.ok(Result.isErr(errorResult));
|
|
37
|
+
*
|
|
34
38
|
* if (Result.isErr(errorResult)) {
|
|
35
39
|
* assert(errorResult.value === 'Something went wrong');
|
|
36
40
|
* }
|