ts-data-forge 5.0.1 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -50
- package/dist/array/impl/array-utils-creation.d.mts +14 -0
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-creation.mjs +12 -0
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts +10 -0
- package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
- package/dist/array/impl/array-utils-element-access.mjs +6 -0
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-modification.d.mts +14 -0
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +34 -10
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts +34 -4
- package/dist/array/impl/array-utils-search.d.mts.map +1 -1
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts +20 -7
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +20 -7
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +5 -2
- package/dist/array/impl/array-utils-size.d.mts.map +1 -1
- package/dist/array/impl/array-utils-size.mjs +5 -2
- package/dist/array/impl/array-utils-size.mjs.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.d.mts +2 -0
- package/dist/array/impl/array-utils-slice-clamped.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts +17 -2
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs +9 -2
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +27 -0
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +6 -0
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +35 -18
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +25 -14
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +35 -15
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +5 -3
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +46 -19
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +9 -2
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +48 -19
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +9 -2
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.d.mts +65 -25
- package/dist/collections/queue.d.mts.map +1 -1
- package/dist/collections/queue.mjs +13 -5
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.d.mts +60 -25
- package/dist/collections/stack.d.mts.map +1 -1
- package/dist/collections/stack.mjs +12 -5
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/entry-point.mjs +1 -1
- package/dist/functional/match.d.mts +1 -1
- package/dist/functional/match.d.mts.map +1 -1
- package/dist/functional/match.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts +3 -2
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-filter.d.mts +3 -0
- package/dist/functional/optional/impl/optional-filter.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-flat-map.d.mts +2 -0
- package/dist/functional/optional/impl/optional-flat-map.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-from-nullable.d.mts +2 -0
- package/dist/functional/optional/impl/optional-from-nullable.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-from-nullable.mjs +2 -0
- package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-none.d.mts +1 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +1 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts +4 -2
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +4 -2
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts +2 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +2 -1
- package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-map.d.mts +2 -0
- package/dist/functional/optional/impl/optional-map.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-none.d.mts +4 -2
- package/dist/functional/optional/impl/optional-none.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-none.mjs +4 -2
- package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-or-else.d.mts +4 -0
- package/dist/functional/optional/impl/optional-or-else.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-some.d.mts +5 -3
- package/dist/functional/optional/impl/optional-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-some.mjs +4 -2
- package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +4 -2
- package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.mjs +4 -2
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +7 -4
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +2 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +2 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap.d.mts +4 -2
- package/dist/functional/optional/impl/optional-unwrap.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-zip.d.mts +3 -1
- package/dist/functional/optional/impl/optional-zip.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +3 -1
- package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
- package/dist/functional/pipe.d.mts +2 -2
- package/dist/functional/result/impl/result-err.d.mts +4 -2
- package/dist/functional/result/impl/result-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-err.mjs +3 -1
- package/dist/functional/result/impl/result-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-expect-to-be.d.mts +3 -2
- package/dist/functional/result/impl/result-expect-to-be.d.mts.map +1 -1
- package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
- package/dist/functional/result/impl/result-flat-map.d.mts +5 -0
- package/dist/functional/result/impl/result-flat-map.d.mts.map +1 -1
- package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-fold.d.mts +4 -0
- package/dist/functional/result/impl/result-fold.d.mts.map +1 -1
- package/dist/functional/result/impl/result-fold.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-promise.d.mts +4 -1
- package/dist/functional/result/impl/result-from-promise.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs +4 -1
- package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts +3 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +3 -1
- package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-err.d.mts +4 -2
- package/dist/functional/result/impl/result-is-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-err.mjs +4 -2
- package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-ok.d.mts +4 -2
- package/dist/functional/result/impl/result-is-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-ok.mjs +4 -2
- package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-result.d.mts +7 -3
- package/dist/functional/result/impl/result-is-result.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-result.mjs +7 -3
- package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
- package/dist/functional/result/impl/result-map-err.d.mts +3 -0
- package/dist/functional/result/impl/result-map-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-map.d.mts +4 -0
- package/dist/functional/result/impl/result-map.d.mts.map +1 -1
- package/dist/functional/result/impl/result-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-ok.d.mts +4 -2
- package/dist/functional/result/impl/result-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-ok.mjs +3 -1
- package/dist/functional/result/impl/result-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-or-else.d.mts +4 -0
- package/dist/functional/result/impl/result-or-else.d.mts.map +1 -1
- package/dist/functional/result/impl/result-or-else.mjs.map +1 -1
- package/dist/functional/result/impl/result-swap.d.mts +2 -0
- package/dist/functional/result/impl/result-swap.d.mts.map +1 -1
- package/dist/functional/result/impl/result-swap.mjs +2 -0
- package/dist/functional/result/impl/result-swap.mjs.map +1 -1
- package/dist/functional/result/impl/result-to-optional.d.mts +2 -0
- package/dist/functional/result/impl/result-to-optional.d.mts.map +1 -1
- package/dist/functional/result/impl/result-to-optional.mjs +2 -0
- package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts +7 -4
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +3 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +3 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts +3 -2
- package/dist/functional/result/impl/result-unwrap-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.mjs +3 -2
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +7 -4
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok.d.mts +3 -2
- package/dist/functional/result/impl/result-unwrap-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts +3 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +3 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-zip.d.mts +3 -1
- package/dist/functional/result/impl/result-zip.d.mts.map +1 -1
- package/dist/functional/result/impl/result-zip.mjs +3 -1
- package/dist/functional/result/impl/result-zip.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +3 -2
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +2 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts +4 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +3 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +3 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +3 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +3 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +7 -3
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +7 -3
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts +3 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts +3 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts +6 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts +4 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +4 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -1
- package/dist/globals.d.mts +12 -1
- package/dist/guard/has-key.d.mts +6 -3
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +2 -2
- package/dist/guard/index.mjs +1 -1
- package/dist/guard/is-record.d.mts +31 -0
- package/dist/guard/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +32 -1
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/is-type.d.mts +3 -0
- package/dist/guard/is-type.d.mts.map +1 -1
- package/dist/guard/is-type.mjs +3 -0
- package/dist/guard/is-type.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts +3 -2
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +3 -2
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/iterator/range.d.mts +4 -0
- package/dist/iterator/range.d.mts.map +1 -1
- package/dist/iterator/range.mjs +1 -0
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/json.d.mts +42 -21
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +42 -21
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +33 -19
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +33 -19
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +2 -2
- package/dist/number/branded-types/positive-int.d.mts +34 -20
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +34 -20
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +47 -26
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +48 -27
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +48 -27
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +50 -29
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +1 -1
- package/dist/number/branded-types/uint.d.mts +31 -19
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +31 -19
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/num.d.mts +29 -20
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +24 -17
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +33 -11
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +33 -11
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +12 -3
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +10 -3
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/tuple.d.mts +14 -3
- package/dist/others/tuple.d.mts.map +1 -1
- package/dist/others/tuple.mjs +14 -3
- package/dist/others/tuple.mjs.map +1 -1
- package/dist/others/unknown-to-string.d.mts.map +1 -1
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/promise/promise.d.mts +8 -4
- package/dist/promise/promise.d.mts.map +1 -1
- package/dist/promise/promise.mjs +8 -4
- package/dist/promise/promise.mjs.map +1 -1
- package/package.json +26 -28
- package/src/array/impl/array-utils-creation.mts +20 -0
- package/src/array/impl/array-utils-creation.test.mts +72 -1
- package/src/array/impl/array-utils-element-access.mts +13 -0
- package/src/array/impl/array-utils-element-access.test.mts +36 -15
- package/src/array/impl/array-utils-iterators.test.mts +17 -0
- package/src/array/impl/array-utils-modification.mts +78 -19
- package/src/array/impl/array-utils-modification.test.mts +75 -0
- package/src/array/impl/array-utils-overload-type-error.test.mts +19 -0
- package/src/array/impl/array-utils-reducing-value.mts +61 -16
- package/src/array/impl/array-utils-reducing-value.test.mts +107 -25
- package/src/array/impl/array-utils-search.mts +57 -4
- package/src/array/impl/array-utils-search.test.mts +61 -10
- package/src/array/impl/array-utils-set-op.mts +26 -7
- package/src/array/impl/array-utils-set-op.test.mts +129 -13
- package/src/array/impl/array-utils-size.mts +5 -2
- package/src/array/impl/array-utils-size.test.mts +1 -0
- package/src/array/impl/array-utils-slice-clamped.mts +7 -0
- package/src/array/impl/array-utils-slice-clamped.test.mts +20 -0
- package/src/array/impl/array-utils-slicing.mts +29 -2
- package/src/array/impl/array-utils-slicing.test.mts +57 -0
- package/src/array/impl/array-utils-transformation.mts +58 -0
- package/src/array/impl/array-utils-transformation.test.mts +115 -3
- package/src/array/impl/array-utils-validation.mts +41 -18
- package/src/array/impl/array-utils-validation.test.mts +176 -78
- package/src/array/impl/array.test.mts +18 -6
- package/src/collections/imap-mapped.mts +11 -0
- package/src/collections/imap-mapped.test.mts +86 -18
- package/src/collections/imap.mts +47 -15
- package/src/collections/imap.test.mts +137 -31
- package/src/collections/iset-mapped.mts +54 -19
- package/src/collections/iset-mapped.test.mts +163 -52
- package/src/collections/iset.mts +53 -19
- package/src/collections/iset.test.mts +323 -130
- package/src/collections/queue.mts +78 -25
- package/src/collections/queue.test.mts +65 -35
- package/src/collections/stack.mts +67 -25
- package/src/collections/stack.test.mts +59 -15
- package/src/functional/match.mts +17 -1
- package/src/functional/match.test.mts +2 -0
- package/src/functional/optional/impl/optional-expect-to-be.mts +5 -2
- package/src/functional/optional/impl/optional-filter.mts +6 -0
- package/src/functional/optional/impl/optional-flat-map.mts +4 -0
- package/src/functional/optional/impl/optional-from-nullable.mts +2 -0
- package/src/functional/optional/impl/optional-is-none.mts +1 -1
- package/src/functional/optional/impl/optional-is-optional.mts +4 -2
- package/src/functional/optional/impl/optional-is-some.mts +2 -1
- package/src/functional/optional/impl/optional-map.mts +5 -0
- package/src/functional/optional/impl/optional-none.mts +4 -2
- package/src/functional/optional/impl/optional-or-else.mts +6 -0
- package/src/functional/optional/impl/optional-some.mts +5 -3
- package/src/functional/optional/impl/optional-to-nullable.mts +4 -2
- package/src/functional/optional/impl/optional-unwrap-or.mts +9 -4
- package/src/functional/optional/impl/optional-unwrap-throw.mts +2 -1
- package/src/functional/optional/impl/optional-unwrap.mts +4 -2
- package/src/functional/optional/impl/optional-zip.mts +3 -1
- package/src/functional/optional.test.mts +126 -54
- package/src/functional/pipe.mts +2 -2
- package/src/functional/pipe.test.mts +7 -4
- package/src/functional/result/impl/result-err.mts +4 -2
- package/src/functional/result/impl/result-expect-to-be.mts +5 -2
- package/src/functional/result/impl/result-flat-map.mts +7 -0
- package/src/functional/result/impl/result-fold.mts +6 -0
- package/src/functional/result/impl/result-from-promise.mts +4 -1
- package/src/functional/result/impl/result-from-throwable.mts +5 -1
- package/src/functional/result/impl/result-is-err.mts +4 -2
- package/src/functional/result/impl/result-is-ok.mts +4 -2
- package/src/functional/result/impl/result-is-result.mts +7 -3
- package/src/functional/result/impl/result-map-err.mts +5 -0
- package/src/functional/result/impl/result-map.mts +6 -0
- package/src/functional/result/impl/result-ok.mts +4 -2
- package/src/functional/result/impl/result-or-else.mts +6 -0
- package/src/functional/result/impl/result-swap.mts +2 -0
- package/src/functional/result/impl/result-to-optional.mts +2 -0
- package/src/functional/result/impl/result-unwrap-err-or.mts +9 -4
- package/src/functional/result/impl/result-unwrap-err-throw.mts +3 -1
- package/src/functional/result/impl/result-unwrap-err.mts +3 -2
- package/src/functional/result/impl/result-unwrap-ok-or.mts +9 -4
- package/src/functional/result/impl/result-unwrap-ok.mts +4 -2
- package/src/functional/result/impl/result-unwrap-throw.mts +3 -1
- package/src/functional/result/impl/result-zip.mts +3 -1
- package/src/functional/result.test.mts +182 -152
- package/src/functional/ternary-result/impl/ternary-result-err.mts +3 -2
- package/src/functional/ternary-result/impl/ternary-result-expect-to-be.mts +4 -0
- package/src/functional/ternary-result/impl/ternary-result-flat-map.mts +7 -0
- package/src/functional/ternary-result/impl/ternary-result-fold.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +3 -1
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +4 -1
- package/src/functional/ternary-result/impl/ternary-result-is-ok.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +7 -3
- package/src/functional/ternary-result/impl/ternary-result-is-warn.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-map-err.mts +6 -0
- package/src/functional/ternary-result/impl/ternary-result-map-warn.mts +6 -0
- package/src/functional/ternary-result/impl/ternary-result-map.mts +9 -0
- package/src/functional/ternary-result/impl/ternary-result-ok.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-or-else.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-to-optional.mts +2 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-or.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err.mts +2 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok.mts +3 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-throw.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn.mts +2 -0
- package/src/functional/ternary-result/impl/ternary-result-warn.mts +4 -1
- package/src/functional/ternary-result/impl/ternary-result-zip.mts +4 -0
- package/src/functional/ternary-result.test.mts +99 -8
- package/src/globals.d.mts +12 -1
- package/src/guard/has-key.mts +8 -5
- package/src/guard/has-key.test.mts +9 -5
- package/src/guard/is-error.test.mts +143 -0
- package/src/guard/is-non-empty-string.test.mts +44 -24
- package/src/guard/is-non-null-object.test.mts +45 -26
- package/src/guard/is-primitive.test.mts +51 -28
- package/src/guard/is-record.mts +34 -0
- package/src/guard/is-record.test.mts +28 -7
- package/src/guard/is-type.mts +3 -0
- package/src/guard/is-type.test.mts +285 -155
- package/src/guard/key-is-in.mts +3 -2
- package/src/guard/key-is-in.test.mts +2 -2
- package/src/iterator/range.mts +9 -0
- package/src/json/json.mts +50 -21
- package/src/json/json.test.mts +224 -176
- package/src/number/branded-types/finite-number.test.mts +51 -11
- package/src/number/branded-types/int.mts +33 -19
- package/src/number/branded-types/int.test.mts +56 -14
- package/src/number/branded-types/int16.test.mts +63 -16
- package/src/number/branded-types/int32.test.mts +63 -16
- package/src/number/branded-types/non-negative-finite-number.test.mts +52 -12
- package/src/number/branded-types/non-negative-int16.test.mts +59 -16
- package/src/number/branded-types/non-negative-int32.test.mts +59 -16
- package/src/number/branded-types/non-zero-finite-number.test.mts +65 -14
- package/src/number/branded-types/non-zero-int.test.mts +72 -19
- package/src/number/branded-types/non-zero-int16.test.mts +60 -16
- package/src/number/branded-types/non-zero-int32.test.mts +60 -16
- package/src/number/branded-types/non-zero-safe-int.mts +2 -2
- package/src/number/branded-types/non-zero-safe-int.test.mts +85 -23
- package/src/number/branded-types/non-zero-uint16.test.mts +53 -16
- package/src/number/branded-types/non-zero-uint32.test.mts +53 -16
- package/src/number/branded-types/positive-finite-number.test.mts +59 -14
- package/src/number/branded-types/positive-int.mts +34 -20
- package/src/number/branded-types/positive-int.test.mts +64 -17
- package/src/number/branded-types/positive-int16.test.mts +50 -15
- package/src/number/branded-types/positive-int32.test.mts +50 -15
- package/src/number/branded-types/positive-safe-int.mts +48 -27
- package/src/number/branded-types/positive-safe-int.test.mts +68 -19
- package/src/number/branded-types/positive-uint16.test.mts +53 -16
- package/src/number/branded-types/positive-uint32.test.mts +53 -16
- package/src/number/branded-types/safe-int.mts +50 -29
- package/src/number/branded-types/safe-int.test.mts +70 -18
- package/src/number/branded-types/safe-uint.mts +1 -1
- package/src/number/branded-types/safe-uint.test.mts +65 -17
- package/src/number/branded-types/uint.mts +31 -19
- package/src/number/branded-types/uint.test.mts +58 -15
- package/src/number/branded-types/uint16.test.mts +56 -15
- package/src/number/branded-types/uint32.test.mts +56 -15
- package/src/number/enum/int8.test.mts +7 -1
- package/src/number/enum/uint8.test.mts +7 -1
- package/src/number/num.mts +32 -21
- package/src/number/num.test.mts +88 -26
- package/src/number/refined-number-utils.mts +38 -13
- package/src/object/object.mts +19 -3
- package/src/object/object.test.mts +16 -6
- package/src/others/cast-mutable.test.mts +8 -1
- package/src/others/cast-readonly.test.mts +21 -4
- package/src/others/if-then.test.mts +40 -24
- package/src/others/map-nullable.mts +3 -0
- package/src/others/map-nullable.test.mts +27 -0
- package/src/others/memoize-function.test.mts +41 -0
- package/src/others/tuple.mts +14 -3
- package/src/others/unknown-to-string.mts +2 -0
- package/src/others/unknown-to-string.test.mts +10 -0
- package/src/promise/promise.mts +8 -4
- package/src/promise/promise.test.mts +8 -13
|
@@ -3,54 +3,73 @@ import { isNonNullObject } from './is-non-null-object.mjs';
|
|
|
3
3
|
|
|
4
4
|
describe(isNonNullObject, () => {
|
|
5
5
|
test('should return true for plain objects', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
assert.isTrue(isNonNullObject({}));
|
|
7
|
+
|
|
8
|
+
assert.isTrue(isNonNullObject({ a: 1, b: 'test' }));
|
|
9
|
+
|
|
10
|
+
assert.isTrue(isNonNullObject({ nested: { value: true } }));
|
|
9
11
|
});
|
|
10
12
|
|
|
11
13
|
test('should return true for arrays', () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
assert.isTrue(isNonNullObject([]));
|
|
15
|
+
|
|
16
|
+
assert.isTrue(isNonNullObject([1, 2, 3]));
|
|
17
|
+
|
|
18
|
+
assert.isTrue(isNonNullObject(['a', 'b', 'c']));
|
|
15
19
|
});
|
|
16
20
|
|
|
17
21
|
test('should return true for functions', () => {
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
assert.isFalse(isNonNullObject(() => {}));
|
|
23
|
+
|
|
24
|
+
assert.isFalse(isNonNullObject(async () => {}));
|
|
25
|
+
|
|
20
26
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
21
|
-
|
|
27
|
+
assert.isFalse(isNonNullObject(class MyClass {}));
|
|
22
28
|
});
|
|
23
29
|
|
|
24
30
|
test('should return true for built-in objects', () => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
assert.isTrue(isNonNullObject(new Date()));
|
|
32
|
+
|
|
33
|
+
assert.isTrue(isNonNullObject(/test/u));
|
|
34
|
+
|
|
35
|
+
assert.isTrue(isNonNullObject(/regex/u));
|
|
36
|
+
|
|
37
|
+
assert.isTrue(isNonNullObject(new Map()));
|
|
38
|
+
|
|
39
|
+
assert.isTrue(isNonNullObject(new Set()));
|
|
40
|
+
|
|
41
|
+
assert.isTrue(isNonNullObject(new Error('test')));
|
|
31
42
|
});
|
|
32
43
|
|
|
33
44
|
test('should return true for boxed primitives', () => {
|
|
34
45
|
// eslint-disable-next-line unicorn/new-for-builtins
|
|
35
|
-
|
|
46
|
+
assert.isTrue(isNonNullObject(new String('hello')));
|
|
47
|
+
|
|
36
48
|
// eslint-disable-next-line unicorn/new-for-builtins
|
|
37
|
-
|
|
49
|
+
assert.isTrue(isNonNullObject(new Number(42)));
|
|
50
|
+
|
|
38
51
|
// eslint-disable-next-line unicorn/new-for-builtins
|
|
39
|
-
|
|
52
|
+
assert.isTrue(isNonNullObject(new Boolean(true)));
|
|
40
53
|
});
|
|
41
54
|
|
|
42
55
|
test('should return false for null', () => {
|
|
43
|
-
|
|
56
|
+
assert.isFalse(isNonNullObject(null));
|
|
44
57
|
});
|
|
45
58
|
|
|
46
59
|
test('should return false for primitive values', () => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
assert.isFalse(isNonNullObject(undefined));
|
|
61
|
+
|
|
62
|
+
assert.isFalse(isNonNullObject('string'));
|
|
63
|
+
|
|
64
|
+
assert.isFalse(isNonNullObject(42));
|
|
65
|
+
|
|
66
|
+
assert.isFalse(isNonNullObject(true));
|
|
67
|
+
|
|
68
|
+
assert.isFalse(isNonNullObject(false));
|
|
69
|
+
|
|
70
|
+
assert.isFalse(isNonNullObject(Symbol('test')));
|
|
71
|
+
|
|
72
|
+
assert.isFalse(isNonNullObject(123n));
|
|
54
73
|
});
|
|
55
74
|
|
|
56
75
|
test('should act as a type guard', () => {
|
|
@@ -4,10 +4,12 @@ import { isSymbol } from './is-type.mjs';
|
|
|
4
4
|
|
|
5
5
|
describe(isPrimitive, () => {
|
|
6
6
|
test('should return true for string primitives', () => {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
assert.isTrue(isPrimitive('hello'));
|
|
8
|
+
|
|
9
|
+
assert.isTrue(isPrimitive(''));
|
|
9
10
|
|
|
10
11
|
const value: unknown = 'test';
|
|
12
|
+
|
|
11
13
|
if (isPrimitive(value)) {
|
|
12
14
|
expectType<
|
|
13
15
|
typeof value,
|
|
@@ -17,62 +19,77 @@ describe(isPrimitive, () => {
|
|
|
17
19
|
});
|
|
18
20
|
|
|
19
21
|
test('should return true for number primitives', () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
assert.isTrue(isPrimitive(42));
|
|
23
|
+
|
|
24
|
+
assert.isTrue(isPrimitive(0));
|
|
25
|
+
|
|
26
|
+
assert.isTrue(isPrimitive(-3.14));
|
|
27
|
+
|
|
28
|
+
assert.isTrue(isPrimitive(Number.NaN));
|
|
29
|
+
|
|
30
|
+
assert.isTrue(isPrimitive(Number.POSITIVE_INFINITY));
|
|
25
31
|
});
|
|
26
32
|
|
|
27
33
|
test('should return true for boolean primitives', () => {
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
assert.isTrue(isPrimitive(true));
|
|
35
|
+
|
|
36
|
+
assert.isTrue(isPrimitive(false));
|
|
30
37
|
});
|
|
31
38
|
|
|
32
39
|
test('should return true for symbol primitives', () => {
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
assert.isTrue(isPrimitive(Symbol('test')));
|
|
41
|
+
|
|
42
|
+
assert.isTrue(isPrimitive(Symbol.iterator));
|
|
35
43
|
});
|
|
36
44
|
|
|
37
45
|
test('should return true for bigint primitives', () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
assert.isTrue(isPrimitive(123n));
|
|
47
|
+
|
|
48
|
+
assert.isTrue(isPrimitive(0n));
|
|
49
|
+
|
|
50
|
+
assert.isTrue(isPrimitive(-123n));
|
|
41
51
|
});
|
|
42
52
|
|
|
43
53
|
test('should return true for null', () => {
|
|
44
54
|
// Note: null is considered an object by typeof, so isPrimitive returns false
|
|
45
|
-
|
|
55
|
+
assert.isTrue(isPrimitive(null));
|
|
46
56
|
});
|
|
47
57
|
|
|
48
58
|
test('should return true for undefined', () => {
|
|
49
|
-
|
|
59
|
+
assert.isTrue(isPrimitive(undefined));
|
|
50
60
|
});
|
|
51
61
|
|
|
52
62
|
test('should return false for objects', () => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
assert.isFalse(isPrimitive({}));
|
|
64
|
+
|
|
65
|
+
assert.isFalse(isPrimitive({ a: 1 }));
|
|
66
|
+
|
|
67
|
+
assert.isFalse(isPrimitive(new Date()));
|
|
56
68
|
});
|
|
57
69
|
|
|
58
70
|
test('should return false for arrays', () => {
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
assert.isFalse(isPrimitive([]));
|
|
72
|
+
|
|
73
|
+
assert.isFalse(isPrimitive([1, 2, 3]));
|
|
61
74
|
});
|
|
62
75
|
|
|
63
76
|
test('should return false for functions', () => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
77
|
+
assert.isFalse(isPrimitive(() => {}));
|
|
78
|
+
|
|
79
|
+
assert.isFalse(isPrimitive(() => {}));
|
|
80
|
+
|
|
81
|
+
assert.isFalse(isPrimitive(async () => {}));
|
|
67
82
|
});
|
|
68
83
|
|
|
69
84
|
test('should return false for boxed primitives', () => {
|
|
70
85
|
// eslint-disable-next-line unicorn/new-for-builtins
|
|
71
|
-
|
|
86
|
+
assert.isFalse(isPrimitive(new String('hello')));
|
|
87
|
+
|
|
72
88
|
// eslint-disable-next-line unicorn/new-for-builtins
|
|
73
|
-
|
|
89
|
+
assert.isFalse(isPrimitive(new Number(42)));
|
|
90
|
+
|
|
74
91
|
// eslint-disable-next-line unicorn/new-for-builtins
|
|
75
|
-
|
|
92
|
+
assert.isFalse(isPrimitive(new Boolean(true)));
|
|
76
93
|
});
|
|
77
94
|
|
|
78
95
|
test('should narrow types correctly in conditional', () => {
|
|
@@ -88,16 +105,22 @@ describe(isPrimitive, () => {
|
|
|
88
105
|
];
|
|
89
106
|
|
|
90
107
|
const primitives = values.filter(isPrimitive);
|
|
108
|
+
|
|
91
109
|
const nonPrimitives = values.filter((v) => !isPrimitive(v));
|
|
92
110
|
|
|
93
111
|
expect(primitives).toHaveLength(6); // string, 42, true, null, undefined, symbol
|
|
112
|
+
|
|
94
113
|
expect(primitives[0]).toBe('string');
|
|
114
|
+
|
|
95
115
|
expect(primitives[1]).toBe(42);
|
|
116
|
+
|
|
96
117
|
expect(primitives[2]).toBe(true);
|
|
118
|
+
|
|
97
119
|
expect(primitives[3]).toBeNull();
|
|
120
|
+
|
|
98
121
|
expect(primitives[4]).toBeUndefined();
|
|
99
122
|
|
|
100
|
-
|
|
123
|
+
assert.isTrue(isSymbol(primitives[5]));
|
|
101
124
|
|
|
102
125
|
assert.deepStrictEqual(nonPrimitives, [{}, []]);
|
|
103
126
|
});
|
package/src/guard/is-record.mts
CHANGED
|
@@ -40,3 +40,37 @@ import { isNonNullObject } from './is-non-null-object.mjs';
|
|
|
40
40
|
*/
|
|
41
41
|
export const isRecord = (u: unknown): u is UnknownRecord =>
|
|
42
42
|
isNonNullObject(u) && !Array.isArray(u);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Type guard that checks if a value is a mutable record (an object with mutable string keys).
|
|
46
|
+
*
|
|
47
|
+
* This function is an alias for {@link isRecord}, but narrows the type to
|
|
48
|
+
* `MutableRecord<string, unknown>`, which is useful when you need to ensure
|
|
49
|
+
* that the object can be safely mutated (i.e., its properties can be added or changed).
|
|
50
|
+
*
|
|
51
|
+
* **Type Narrowing Behavior:**
|
|
52
|
+
*
|
|
53
|
+
* - Narrows `unknown` to `MutableRecord<string, unknown>`
|
|
54
|
+
* - Excludes `null`, `undefined`, primitives, arrays, and functions
|
|
55
|
+
* - Returns `true` for plain objects with mutable string keys
|
|
56
|
+
* - Returns `false` for arrays and other non-record types
|
|
57
|
+
*
|
|
58
|
+
* **Implementation:** This is a type alias for {@link isRecord}.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const obj: unknown = { foo: 1 };
|
|
63
|
+
*
|
|
64
|
+
* if (isMutableRecord(obj)) {
|
|
65
|
+
* obj['bar'] = 2; // Safe: obj is now known to be a mutable record
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @param u - The value to check
|
|
70
|
+
* @returns `true` if `u` is a mutable record (plain object with string keys), `false` otherwise.
|
|
71
|
+
* When `true`, TypeScript narrows the type to `MutableRecord<string, unknown>`.
|
|
72
|
+
* @see {@link isRecord} - For the underlying implementation and more details
|
|
73
|
+
*/
|
|
74
|
+
export const isMutableRecord: (
|
|
75
|
+
u: unknown,
|
|
76
|
+
) => u is MutableRecord<string, unknown> = isRecord;
|
|
@@ -4,87 +4,108 @@ import { isRecord } from './is-record.mjs';
|
|
|
4
4
|
describe(isRecord, () => {
|
|
5
5
|
test('{ x: 1 } is a record', () => {
|
|
6
6
|
const obj = { x: 1 } as const;
|
|
7
|
+
|
|
7
8
|
const unk: unknown = obj;
|
|
9
|
+
|
|
8
10
|
const res = isRecord(unk);
|
|
9
11
|
|
|
10
12
|
expectType<typeof obj, UnknownRecord>('<=');
|
|
13
|
+
|
|
11
14
|
expectType<typeof res, boolean>('=');
|
|
12
15
|
|
|
13
16
|
if (res) {
|
|
14
17
|
expectType<typeof unk, UnknownRecord>('=');
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
assert.isTrue(res);
|
|
18
21
|
});
|
|
19
22
|
|
|
20
23
|
test('{} is a record', () => {
|
|
21
24
|
const obj = {} as const;
|
|
25
|
+
|
|
22
26
|
const unk: unknown = obj;
|
|
27
|
+
|
|
23
28
|
const res = isRecord(unk);
|
|
24
29
|
|
|
25
30
|
expectType<typeof obj, {}>('=');
|
|
31
|
+
|
|
26
32
|
expectType<typeof res, boolean>('=');
|
|
27
33
|
|
|
28
34
|
if (res) {
|
|
29
35
|
expectType<typeof unk, UnknownRecord>('=');
|
|
30
36
|
}
|
|
31
37
|
|
|
32
|
-
|
|
38
|
+
assert.isTrue(res);
|
|
33
39
|
});
|
|
34
40
|
|
|
35
41
|
test('[] is not a record', () => {
|
|
36
42
|
const obj: DeepReadonly<never[]> = [] as const;
|
|
43
|
+
|
|
37
44
|
const unk: unknown = obj;
|
|
45
|
+
|
|
38
46
|
const res = isRecord(unk);
|
|
39
47
|
|
|
40
48
|
expectType<typeof obj, readonly never[]>('=');
|
|
49
|
+
|
|
41
50
|
expectType<typeof res, boolean>('=');
|
|
42
51
|
|
|
43
|
-
|
|
52
|
+
assert.isFalse(res);
|
|
44
53
|
});
|
|
45
54
|
|
|
46
55
|
test('null is not a record', () => {
|
|
47
56
|
const obj = null;
|
|
57
|
+
|
|
48
58
|
const unk: unknown = obj;
|
|
59
|
+
|
|
49
60
|
const res = isRecord(unk);
|
|
50
61
|
|
|
51
62
|
expectType<typeof obj, null>('=');
|
|
63
|
+
|
|
52
64
|
expectType<typeof res, boolean>('=');
|
|
53
65
|
|
|
54
|
-
|
|
66
|
+
assert.isFalse(res);
|
|
55
67
|
});
|
|
56
68
|
|
|
57
69
|
test('undefined is not a record', () => {
|
|
58
70
|
const obj = undefined;
|
|
71
|
+
|
|
59
72
|
const unk: unknown = obj;
|
|
73
|
+
|
|
60
74
|
const res = isRecord(unk);
|
|
61
75
|
|
|
62
76
|
expectType<typeof obj, undefined>('=');
|
|
77
|
+
|
|
63
78
|
expectType<typeof res, boolean>('=');
|
|
64
79
|
|
|
65
|
-
|
|
80
|
+
assert.isFalse(res);
|
|
66
81
|
});
|
|
67
82
|
|
|
68
83
|
test('3 is not a record', () => {
|
|
69
84
|
const obj = 3;
|
|
85
|
+
|
|
70
86
|
const unk: unknown = obj;
|
|
87
|
+
|
|
71
88
|
const res = isRecord(unk);
|
|
72
89
|
|
|
73
90
|
expectType<typeof obj, 3>('=');
|
|
91
|
+
|
|
74
92
|
expectType<typeof res, boolean>('=');
|
|
75
93
|
|
|
76
|
-
|
|
94
|
+
assert.isFalse(res);
|
|
77
95
|
});
|
|
78
96
|
|
|
79
97
|
test('"str" is not a record', () => {
|
|
80
98
|
const obj = 'str';
|
|
99
|
+
|
|
81
100
|
const unk: unknown = obj;
|
|
101
|
+
|
|
82
102
|
const res = isRecord(unk);
|
|
83
103
|
|
|
84
104
|
expectType<typeof obj, 'str'>('=');
|
|
105
|
+
|
|
85
106
|
expectType<typeof res, boolean>('=');
|
|
86
107
|
|
|
87
|
-
|
|
108
|
+
assert.isFalse(res);
|
|
88
109
|
});
|
|
89
110
|
|
|
90
111
|
// test('Map is not a record', () => {
|
package/src/guard/is-type.mts
CHANGED
|
@@ -263,7 +263,9 @@ export const isNotString = <T,>(u: T): u is RelaxedExclude<T, string> =>
|
|
|
263
263
|
*
|
|
264
264
|
* ```ts
|
|
265
265
|
* const id = Symbol('id');
|
|
266
|
+
*
|
|
266
267
|
* const shared = Symbol.for('shared');
|
|
268
|
+
*
|
|
267
269
|
* const tokens: unknown[] = [id, 'shared', shared];
|
|
268
270
|
*
|
|
269
271
|
* const symbols = tokens.filter(isSymbol);
|
|
@@ -289,6 +291,7 @@ export const isSymbol = (u: unknown): u is symbol => typeof u === 'symbol';
|
|
|
289
291
|
*
|
|
290
292
|
* ```ts
|
|
291
293
|
* const id = Symbol('id');
|
|
294
|
+
*
|
|
292
295
|
* const tokens: unknown[] = [id, 'shared'];
|
|
293
296
|
*
|
|
294
297
|
* const nonSymbols = tokens.filter(isNotSymbol);
|