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
|
@@ -5,47 +5,65 @@ import { TernaryResult } from './ternary-result/index.mjs';
|
|
|
5
5
|
describe('TernaryResult test', () => {
|
|
6
6
|
test('constructors and guards', () => {
|
|
7
7
|
const ok = TernaryResult.ok(1);
|
|
8
|
+
|
|
8
9
|
const warn = TernaryResult.warn(1, 'caution');
|
|
10
|
+
|
|
9
11
|
const err = TernaryResult.err(new Error('boom'));
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
assert.isTrue(TernaryResult.isOk(ok));
|
|
14
|
+
|
|
15
|
+
assert.isTrue(TernaryResult.isWarn(warn));
|
|
16
|
+
|
|
17
|
+
assert.isTrue(TernaryResult.isErr(err));
|
|
18
|
+
|
|
19
|
+
assert.isTrue(TernaryResult.isTernaryResult(ok));
|
|
20
|
+
|
|
21
|
+
assert.isFalse(TernaryResult.isTernaryResult({}));
|
|
16
22
|
|
|
17
23
|
expectType<typeof ok, TernaryResult<number, never, never>>('<=');
|
|
24
|
+
|
|
18
25
|
expectType<typeof warn, TernaryResult<number, never, string>>('<=');
|
|
26
|
+
|
|
19
27
|
expectType<typeof err, TernaryResult<never, Error, never>>('<=');
|
|
20
28
|
});
|
|
21
29
|
|
|
22
30
|
test('map transforms Ok and Warn success values', () => {
|
|
23
31
|
const ok = TernaryResult.ok(2);
|
|
32
|
+
|
|
24
33
|
const warn = TernaryResult.warn(2, 'check');
|
|
34
|
+
|
|
25
35
|
const err = TernaryResult.err('fail');
|
|
26
36
|
|
|
27
37
|
const double = TernaryResult.map((value: number) => value * 2);
|
|
28
38
|
|
|
29
39
|
expect(TernaryResult.unwrapOk(double(ok))).toBe(4);
|
|
40
|
+
|
|
30
41
|
expect(TernaryResult.unwrapOk(double(warn))).toBe(4);
|
|
42
|
+
|
|
31
43
|
expect(TernaryResult.unwrapWarn(double(warn))).toBe('check');
|
|
44
|
+
|
|
32
45
|
expect(TernaryResult.unwrapErr(double(err))).toBe('fail');
|
|
33
46
|
});
|
|
34
47
|
|
|
35
48
|
test('mapWarn and mapErr leave other variants untouched', () => {
|
|
36
49
|
const warn = TernaryResult.warn(2, 'slow');
|
|
50
|
+
|
|
37
51
|
const err = TernaryResult.err('err');
|
|
38
52
|
|
|
39
53
|
const warnMessage = TernaryResult.mapWarn(
|
|
40
54
|
(warning: string) => `${warning}!`,
|
|
41
55
|
);
|
|
56
|
+
|
|
42
57
|
const errUpper = TernaryResult.mapErr((value: string) =>
|
|
43
58
|
value.toUpperCase(),
|
|
44
59
|
);
|
|
45
60
|
|
|
46
61
|
expect(TernaryResult.unwrapWarn(warnMessage(warn))).toBe('slow!');
|
|
62
|
+
|
|
47
63
|
expect(TernaryResult.unwrapOk(warnMessage(warn))).toBe(2);
|
|
64
|
+
|
|
48
65
|
expect(TernaryResult.unwrapWarn(errUpper(warn))).toBe('slow');
|
|
66
|
+
|
|
49
67
|
expect(TernaryResult.unwrapErr(errUpper(err))).toBe('ERR');
|
|
50
68
|
});
|
|
51
69
|
|
|
@@ -56,17 +74,22 @@ describe('TernaryResult test', () => {
|
|
|
56
74
|
: TernaryResult.ok(Number(value));
|
|
57
75
|
|
|
58
76
|
const warn = TernaryResult.warn('3', 'slow');
|
|
77
|
+
|
|
59
78
|
const err = TernaryResult.err('bad');
|
|
60
79
|
|
|
61
80
|
const okResult = TernaryResult.flatMap(TernaryResult.ok('3'), parse);
|
|
81
|
+
|
|
62
82
|
const warnResult = TernaryResult.flatMap(warn, parse);
|
|
83
|
+
|
|
63
84
|
const errResult = TernaryResult.flatMap(err, parse);
|
|
64
85
|
|
|
65
86
|
expect(TernaryResult.unwrapOk(okResult)).toBe(3);
|
|
66
|
-
|
|
87
|
+
|
|
88
|
+
assert.isTrue(TernaryResult.isWarn(warnResult));
|
|
67
89
|
|
|
68
90
|
if (TernaryResult.isWarn(warnResult)) {
|
|
69
91
|
expect(warnResult.value).toBe(3);
|
|
92
|
+
|
|
70
93
|
expect(warnResult.warning).toBe('slow');
|
|
71
94
|
}
|
|
72
95
|
|
|
@@ -80,12 +103,14 @@ describe('TernaryResult test', () => {
|
|
|
80
103
|
(w: string) => ({ warning: w }),
|
|
81
104
|
(e: string) => ({ message: e }),
|
|
82
105
|
);
|
|
106
|
+
|
|
83
107
|
const warn = TernaryResult.fold(
|
|
84
108
|
TernaryResult.warn(2, 'heads up'),
|
|
85
109
|
(x) => x * 2,
|
|
86
110
|
(w: string) => ({ warning: w }),
|
|
87
111
|
(e: string) => ({ message: e }),
|
|
88
112
|
);
|
|
113
|
+
|
|
89
114
|
const err = TernaryResult.fold(
|
|
90
115
|
TernaryResult.err('boom'),
|
|
91
116
|
(x) => x,
|
|
@@ -94,11 +119,13 @@ describe('TernaryResult test', () => {
|
|
|
94
119
|
);
|
|
95
120
|
|
|
96
121
|
expect(TernaryResult.unwrapOk(value)).toBe(2);
|
|
122
|
+
|
|
97
123
|
expect(TernaryResult.unwrapOk(warn)).toBe(4);
|
|
98
124
|
|
|
99
125
|
assert.deepStrictEqual(TernaryResult.unwrapWarn(warn), {
|
|
100
126
|
warning: 'heads up',
|
|
101
127
|
});
|
|
128
|
+
|
|
102
129
|
assert.deepStrictEqual(TernaryResult.unwrapErr(err), { message: 'boom' });
|
|
103
130
|
});
|
|
104
131
|
|
|
@@ -109,10 +136,12 @@ describe('TernaryResult test', () => {
|
|
|
109
136
|
TernaryResult.orElse(TernaryResult.ok('value'), fallback),
|
|
110
137
|
TernaryResult.ok('value'),
|
|
111
138
|
);
|
|
139
|
+
|
|
112
140
|
assert.deepStrictEqual(
|
|
113
141
|
TernaryResult.orElse(TernaryResult.warn('value', 'warn'), fallback),
|
|
114
142
|
TernaryResult.warn('value', 'warn'),
|
|
115
143
|
);
|
|
144
|
+
|
|
116
145
|
assert.deepStrictEqual(
|
|
117
146
|
TernaryResult.orElse(TernaryResult.err('err'), fallback),
|
|
118
147
|
fallback,
|
|
@@ -121,14 +150,21 @@ describe('TernaryResult test', () => {
|
|
|
121
150
|
|
|
122
151
|
test('unwrap helpers', () => {
|
|
123
152
|
const warn = TernaryResult.warn('value', 'careful');
|
|
153
|
+
|
|
124
154
|
const err = TernaryResult.err('broken');
|
|
125
155
|
|
|
126
156
|
expect(TernaryResult.unwrapOk(TernaryResult.ok(3))).toBe(3);
|
|
157
|
+
|
|
127
158
|
expect(TernaryResult.unwrapOk(warn)).toBe('value');
|
|
159
|
+
|
|
128
160
|
expect(TernaryResult.unwrapWarn(warn)).toBe('careful');
|
|
161
|
+
|
|
129
162
|
expect(TernaryResult.unwrapErr(err)).toBe('broken');
|
|
163
|
+
|
|
130
164
|
expect(TernaryResult.unwrapOkOr(err, 0)).toBe(0);
|
|
165
|
+
|
|
131
166
|
expect(TernaryResult.unwrapWarnOr(err, 'default')).toBe('default');
|
|
167
|
+
|
|
132
168
|
expect(TernaryResult.unwrapErrOr(warn, 'default')).toBe('default');
|
|
133
169
|
});
|
|
134
170
|
|
|
@@ -136,9 +172,11 @@ describe('TernaryResult test', () => {
|
|
|
136
172
|
expect(() =>
|
|
137
173
|
TernaryResult.unwrapThrow(TernaryResult.warn('notice', 'warned')),
|
|
138
174
|
).toThrow(/Warn/u);
|
|
175
|
+
|
|
139
176
|
expect(() =>
|
|
140
177
|
TernaryResult.unwrapWarnThrow(TernaryResult.err('no warn')),
|
|
141
178
|
).toThrow(/Err/u);
|
|
179
|
+
|
|
142
180
|
expect(() =>
|
|
143
181
|
TernaryResult.unwrapErrThrow(TernaryResult.ok('no err')),
|
|
144
182
|
).toThrow(/Ok/u);
|
|
@@ -146,6 +184,7 @@ describe('TernaryResult test', () => {
|
|
|
146
184
|
|
|
147
185
|
test('expectToBe unwraps Ok values', () => {
|
|
148
186
|
expect(TernaryResult.expectToBe(TernaryResult.ok('v'), 'msg')).toBe('v');
|
|
187
|
+
|
|
149
188
|
expect(() =>
|
|
150
189
|
TernaryResult.expectToBe(TernaryResult.err('x'), 'missing'),
|
|
151
190
|
).toThrow(/missing/u);
|
|
@@ -153,22 +192,28 @@ describe('TernaryResult test', () => {
|
|
|
153
192
|
|
|
154
193
|
test('zip prefers Err over Warn or Ok.', () => {
|
|
155
194
|
const ok = TernaryResult.ok('x');
|
|
195
|
+
|
|
156
196
|
const warn = TernaryResult.warn('warn', 'warned');
|
|
197
|
+
|
|
157
198
|
const err = TernaryResult.err('err');
|
|
158
199
|
|
|
159
200
|
assert.deepStrictEqual(
|
|
160
201
|
TernaryResult.zip(ok, TernaryResult.ok(1)),
|
|
161
202
|
TernaryResult.ok(['x', 1] as const),
|
|
162
203
|
);
|
|
204
|
+
|
|
163
205
|
assert.deepStrictEqual(
|
|
164
206
|
TernaryResult.zip(ok, warn),
|
|
165
207
|
TernaryResult.warn(['x', 'warn'] as const, 'warned'),
|
|
166
208
|
);
|
|
209
|
+
|
|
167
210
|
assert.deepStrictEqual(
|
|
168
211
|
TernaryResult.zip(warn, ok),
|
|
169
212
|
TernaryResult.warn(['warn', 'x'] as const, 'warned'),
|
|
170
213
|
);
|
|
214
|
+
|
|
171
215
|
assert.deepStrictEqual(TernaryResult.zip(ok, err), err);
|
|
216
|
+
|
|
172
217
|
assert.deepStrictEqual(TernaryResult.zip(err, warn), err);
|
|
173
218
|
});
|
|
174
219
|
|
|
@@ -177,6 +222,7 @@ describe('TernaryResult test', () => {
|
|
|
177
222
|
TernaryResult.toOptional(TernaryResult.ok(1)),
|
|
178
223
|
Optional.some(1),
|
|
179
224
|
);
|
|
225
|
+
|
|
180
226
|
assert.deepStrictEqual(
|
|
181
227
|
TernaryResult.toOptional(TernaryResult.warn(1, 'warn')),
|
|
182
228
|
Optional.some(1),
|
|
@@ -196,7 +242,7 @@ describe('TernaryResult test', () => {
|
|
|
196
242
|
Promise.reject(new Error('bad')),
|
|
197
243
|
);
|
|
198
244
|
|
|
199
|
-
|
|
245
|
+
assert.isTrue(TernaryResult.isErr(rejected));
|
|
200
246
|
});
|
|
201
247
|
|
|
202
248
|
test('fromThrowable converts thrown values', () => {
|
|
@@ -209,6 +255,51 @@ describe('TernaryResult test', () => {
|
|
|
209
255
|
throw new Error('boom');
|
|
210
256
|
});
|
|
211
257
|
|
|
212
|
-
|
|
258
|
+
assert.isTrue(TernaryResult.isErr(errorResult));
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test('unwrapOkOr curried version', () => {
|
|
262
|
+
const unwrap = TernaryResult.unwrapOkOr(999);
|
|
263
|
+
|
|
264
|
+
expect(unwrap(TernaryResult.ok(42))).toBe(42);
|
|
265
|
+
|
|
266
|
+
expect(unwrap(TernaryResult.warn(10, 'notice'))).toBe(10);
|
|
267
|
+
|
|
268
|
+
expect(unwrap(TernaryResult.err('error'))).toBe(999);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test('unwrapWarnOr curried version', () => {
|
|
272
|
+
const unwrap = TernaryResult.unwrapWarnOr('default');
|
|
273
|
+
|
|
274
|
+
expect(unwrap(TernaryResult.warn(1, 'alert'))).toBe('alert');
|
|
275
|
+
|
|
276
|
+
expect(unwrap(TernaryResult.ok(5))).toBe('default');
|
|
277
|
+
|
|
278
|
+
expect(unwrap(TernaryResult.err('fail'))).toBe('default');
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('unwrapErrOr curried version', () => {
|
|
282
|
+
const unwrap = TernaryResult.unwrapErrOr('fallback');
|
|
283
|
+
|
|
284
|
+
expect(unwrap(TernaryResult.err('bad'))).toBe('bad');
|
|
285
|
+
|
|
286
|
+
expect(unwrap(TernaryResult.ok(3))).toBe('fallback');
|
|
287
|
+
|
|
288
|
+
expect(unwrap(TernaryResult.warn(1, 'note'))).toBe('fallback');
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test('orElse curried version', () => {
|
|
292
|
+
const fallback = TernaryResult.ok('backup');
|
|
293
|
+
|
|
294
|
+
const useBackup = TernaryResult.orElse(fallback);
|
|
295
|
+
|
|
296
|
+
assert.deepStrictEqual(useBackup(TernaryResult.ok(1)), TernaryResult.ok(1));
|
|
297
|
+
|
|
298
|
+
assert.deepStrictEqual(
|
|
299
|
+
useBackup(TernaryResult.warn(2, 'w')),
|
|
300
|
+
TernaryResult.warn(2, 'w'),
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
assert.deepStrictEqual(useBackup(TernaryResult.err('e')), fallback);
|
|
213
304
|
});
|
|
214
305
|
});
|
package/src/globals.d.mts
CHANGED
|
@@ -13,7 +13,8 @@ type ArgArrayIndex<Ar extends readonly unknown[]> =
|
|
|
13
13
|
|
|
14
14
|
type ArgArrayIndexWithNegative<Ar extends readonly unknown[]> =
|
|
15
15
|
IsFixedLengthList<Ar> extends true
|
|
16
|
-
?
|
|
16
|
+
? // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
17
|
+
IndexOfTuple<[...Ar, 0]> | NegativeIndexOfTuple<Ar>
|
|
17
18
|
: SizeType.ArgArrWithNegative;
|
|
18
19
|
|
|
19
20
|
// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/length
|
|
@@ -23,27 +24,37 @@ type ArgArrayIndexWithNegative<Ar extends readonly unknown[]> =
|
|
|
23
24
|
|
|
24
25
|
declare namespace SizeType {
|
|
25
26
|
type Arr = Uint32;
|
|
27
|
+
|
|
26
28
|
type TypedArray = SafeUint;
|
|
29
|
+
|
|
27
30
|
type Str = SafeUint;
|
|
28
31
|
|
|
29
32
|
type ArrSearchResult = Arr | -1;
|
|
33
|
+
|
|
30
34
|
type TypedArraySearchResult = TypedArray | -1;
|
|
35
|
+
|
|
31
36
|
type StrSearchResult = Str | -1;
|
|
32
37
|
|
|
33
38
|
type ArgArr = WithSmallInt<Arr>;
|
|
39
|
+
|
|
34
40
|
type ArgTypedArray = WithSmallInt<TypedArray>;
|
|
41
|
+
|
|
35
42
|
type ArgStr = WithSmallInt<Str>;
|
|
36
43
|
|
|
37
44
|
type ArgArrWithNegative = WithSmallInt<
|
|
38
45
|
NormalizeBrandUnion<NegativeInt32 | Arr>
|
|
39
46
|
>;
|
|
47
|
+
|
|
40
48
|
type ArgTypedArrayWithNegative = WithSmallInt<SafeInt>;
|
|
49
|
+
|
|
41
50
|
type ArgStrWithNegative = WithSmallInt<SafeInt>;
|
|
42
51
|
|
|
43
52
|
type ArgArrPositive = WithSmallInt<IntersectBrand<PositiveNumber, Arr>>;
|
|
53
|
+
|
|
44
54
|
type ArgTypedArrayPositive = WithSmallInt<
|
|
45
55
|
IntersectBrand<PositiveNumber, TypedArray>
|
|
46
56
|
>;
|
|
57
|
+
|
|
47
58
|
type ArgStrPositive = WithSmallInt<IntersectBrand<PositiveNumber, Str>>;
|
|
48
59
|
}
|
|
49
60
|
|
package/src/guard/has-key.mts
CHANGED
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
*
|
|
22
22
|
* if (hasKey(maybeUser, 'id')) {
|
|
23
23
|
* // `maybeUser` is now known to have an `id` property.
|
|
24
|
-
* assert(maybeUser.id === 42);
|
|
24
|
+
* assert.isTrue(maybeUser.id === 42);
|
|
25
25
|
* } else {
|
|
26
|
-
* assert.fail(
|
|
26
|
+
* assert.fail();
|
|
27
27
|
* }
|
|
28
28
|
* ```
|
|
29
29
|
*
|
|
@@ -58,11 +58,14 @@ export type HasKeyReturnType<
|
|
|
58
58
|
> = R extends R // union distribution
|
|
59
59
|
? K extends keyof R
|
|
60
60
|
? string extends keyof R
|
|
61
|
-
?
|
|
61
|
+
? // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
62
|
+
ReadonlyRecord<K, R[keyof R]> & R
|
|
62
63
|
: number extends keyof R
|
|
63
|
-
?
|
|
64
|
+
? // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
65
|
+
ReadonlyRecord<K, R[keyof R]> & R
|
|
64
66
|
: symbol extends keyof R
|
|
65
|
-
?
|
|
67
|
+
? // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
68
|
+
ReadonlyRecord<K, R[keyof R]> & R
|
|
66
69
|
: R
|
|
67
70
|
: never // omit union member that does not have key K
|
|
68
71
|
: never; // dummy case for union distribution
|
|
@@ -61,11 +61,11 @@ import { hasKey, type HasKeyReturnType } from './has-key.mjs';
|
|
|
61
61
|
{
|
|
62
62
|
type R = Readonly<{ a: 0 }> | Readonly<{ b: 1 }>;
|
|
63
63
|
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
65
64
|
const obj: R = { a: 0 } as R;
|
|
66
65
|
|
|
67
66
|
if (hasKey(obj, 'a')) {
|
|
68
67
|
expectType<typeof obj.a, 0>('=');
|
|
68
|
+
|
|
69
69
|
expectType<typeof obj, Readonly<{ a: 0 }>>('=');
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -81,12 +81,13 @@ import { hasKey, type HasKeyReturnType } from './has-key.mjs';
|
|
|
81
81
|
| Readonly<{ b: 2 }>
|
|
82
82
|
| Readonly<{ c: 3 }>;
|
|
83
83
|
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
85
84
|
const obj: R = { a: 0 } as R;
|
|
86
85
|
|
|
87
86
|
if (hasKey(obj, 'a') && hasKey(obj, 'b')) {
|
|
88
87
|
expectType<typeof obj.a, 1>('=');
|
|
88
|
+
|
|
89
89
|
expectType<typeof obj.b, 1>('=');
|
|
90
|
+
|
|
90
91
|
expectType<typeof obj, Readonly<{ a: 1; b: 1 }>>('=');
|
|
91
92
|
}
|
|
92
93
|
}
|
|
@@ -98,7 +99,6 @@ import { hasKey, type HasKeyReturnType } from './has-key.mjs';
|
|
|
98
99
|
| Readonly<{ a: 1; b: 1 }>
|
|
99
100
|
| Readonly<{ b: 2 }>;
|
|
100
101
|
|
|
101
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
102
102
|
const obj: R = { a: 0 } as R;
|
|
103
103
|
|
|
104
104
|
expectType<
|
|
@@ -122,7 +122,9 @@ import { hasKey, type HasKeyReturnType } from './has-key.mjs';
|
|
|
122
122
|
|
|
123
123
|
if (hasKey(obj, 'a') && hasKey(obj, 'b')) {
|
|
124
124
|
expectType<typeof obj.a, number>('=');
|
|
125
|
+
|
|
125
126
|
expectType<typeof obj.b, number>('=');
|
|
127
|
+
|
|
126
128
|
expectType<
|
|
127
129
|
typeof obj,
|
|
128
130
|
| Readonly<{ a: 1; b: 1 }>
|
|
@@ -138,6 +140,7 @@ import { hasKey, type HasKeyReturnType } from './has-key.mjs';
|
|
|
138
140
|
|
|
139
141
|
if (hasKey(o, 'a')) {
|
|
140
142
|
expectType<typeof o.a, unknown>('=');
|
|
143
|
+
|
|
141
144
|
expectType<
|
|
142
145
|
typeof o,
|
|
143
146
|
ReadonlyRecord<'a', unknown> & ReadonlyRecord<string, unknown>
|
|
@@ -146,6 +149,7 @@ import { hasKey, type HasKeyReturnType } from './has-key.mjs';
|
|
|
146
149
|
|
|
147
150
|
if (hasKey(o, 'c')) {
|
|
148
151
|
expectType<typeof o.c, unknown>('=');
|
|
152
|
+
|
|
149
153
|
expectType<
|
|
150
154
|
typeof o,
|
|
151
155
|
ReadonlyRecord<'c', unknown> & ReadonlyRecord<string, unknown>
|
|
@@ -154,7 +158,9 @@ import { hasKey, type HasKeyReturnType } from './has-key.mjs';
|
|
|
154
158
|
|
|
155
159
|
if (hasKey(o, 'a') && hasKey(o, 'b')) {
|
|
156
160
|
expectType<typeof o.a, unknown>('=');
|
|
161
|
+
|
|
157
162
|
expectType<typeof o.b, unknown>('=');
|
|
163
|
+
|
|
158
164
|
expectType<
|
|
159
165
|
typeof o,
|
|
160
166
|
ReadonlyRecord<'a', unknown> &
|
|
@@ -184,7 +190,6 @@ import { hasKey, type HasKeyReturnType } from './has-key.mjs';
|
|
|
184
190
|
| Readonly<{ b: 2 }>
|
|
185
191
|
| Record<string, number>;
|
|
186
192
|
|
|
187
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
188
193
|
const o2 = { b: 2 } as O;
|
|
189
194
|
|
|
190
195
|
if (hasOwnNaive(o2, 'a')) {
|
|
@@ -203,7 +208,6 @@ import { hasKey, type HasKeyReturnType } from './has-key.mjs';
|
|
|
203
208
|
| Readonly<{ a: 1; b: 1 }>
|
|
204
209
|
| Readonly<{ b: 2 }>;
|
|
205
210
|
|
|
206
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
207
211
|
const o2 = { b: 2 } as O;
|
|
208
212
|
|
|
209
213
|
if (hasOwnNaive(o2, 'a')) {
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/* eslint-disable functional/immutable-data */
|
|
2
|
+
/* eslint-disable functional/no-class-inheritance */
|
|
3
|
+
/* eslint-disable unicorn/error-message */
|
|
4
|
+
import { isError as isErrorBySindreSorhus } from '@sindresorhus/is';
|
|
5
|
+
import { expectType } from '../expect-type.mjs';
|
|
6
|
+
|
|
7
|
+
describe('isError from @sindresorhus/is', () => {
|
|
8
|
+
test('should return true for native Error instances', () => {
|
|
9
|
+
assert.isTrue(isErrorBySindreSorhus(new Error()));
|
|
10
|
+
|
|
11
|
+
assert.isTrue(isErrorBySindreSorhus(new Error('test message')));
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('should return true for native Error subclasses', () => {
|
|
15
|
+
assert.isTrue(isErrorBySindreSorhus(new TypeError()));
|
|
16
|
+
|
|
17
|
+
assert.isTrue(isErrorBySindreSorhus(new RangeError()));
|
|
18
|
+
|
|
19
|
+
assert.isTrue(isErrorBySindreSorhus(new ReferenceError()));
|
|
20
|
+
|
|
21
|
+
assert.isTrue(isErrorBySindreSorhus(new SyntaxError()));
|
|
22
|
+
|
|
23
|
+
assert.isTrue(isErrorBySindreSorhus(new EvalError()));
|
|
24
|
+
|
|
25
|
+
assert.isTrue(isErrorBySindreSorhus(new URIError()));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('should return true for custom Error subclasses', () => {
|
|
29
|
+
class CustomError extends Error {
|
|
30
|
+
constructor(message?: string) {
|
|
31
|
+
super(message);
|
|
32
|
+
|
|
33
|
+
this.name = 'CustomError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
assert.isTrue(isErrorBySindreSorhus(new CustomError()));
|
|
38
|
+
|
|
39
|
+
assert.isTrue(
|
|
40
|
+
isErrorBySindreSorhus(new CustomError('custom error message')),
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('should return true for Error subclass with additional properties', () => {
|
|
45
|
+
class ExtendedError extends Error {
|
|
46
|
+
code: number;
|
|
47
|
+
|
|
48
|
+
constructor(message: string, code: number) {
|
|
49
|
+
super(message);
|
|
50
|
+
|
|
51
|
+
this.name = 'ExtendedError';
|
|
52
|
+
|
|
53
|
+
this.code = code;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
assert.isTrue(
|
|
58
|
+
isErrorBySindreSorhus(new ExtendedError('error with code', 404)),
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('should return true for deeply nested Error subclass', () => {
|
|
63
|
+
class BaseCustomError extends Error {
|
|
64
|
+
constructor(message?: string) {
|
|
65
|
+
super(message);
|
|
66
|
+
|
|
67
|
+
this.name = 'BaseCustomError';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
class DerivedCustomError extends BaseCustomError {
|
|
72
|
+
constructor(message?: string) {
|
|
73
|
+
super(message);
|
|
74
|
+
|
|
75
|
+
this.name = 'DerivedCustomError';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
assert.isTrue(isErrorBySindreSorhus(new DerivedCustomError()));
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('should return false for Error-like objects', () => {
|
|
83
|
+
const errorLikeObject = {
|
|
84
|
+
name: 'Error',
|
|
85
|
+
message: 'This is not a real error',
|
|
86
|
+
stack: 'fake stack trace',
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
assert.isFalse(isErrorBySindreSorhus(errorLikeObject));
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('should return false for non-Error values', () => {
|
|
93
|
+
assert.isFalse(isErrorBySindreSorhus(null));
|
|
94
|
+
|
|
95
|
+
assert.isFalse(isErrorBySindreSorhus(undefined));
|
|
96
|
+
|
|
97
|
+
assert.isFalse(isErrorBySindreSorhus(0));
|
|
98
|
+
|
|
99
|
+
assert.isFalse(isErrorBySindreSorhus(''));
|
|
100
|
+
|
|
101
|
+
assert.isFalse(isErrorBySindreSorhus('Error'));
|
|
102
|
+
|
|
103
|
+
assert.isFalse(isErrorBySindreSorhus(true));
|
|
104
|
+
|
|
105
|
+
assert.isFalse(isErrorBySindreSorhus({}));
|
|
106
|
+
|
|
107
|
+
assert.isFalse(isErrorBySindreSorhus([]));
|
|
108
|
+
|
|
109
|
+
assert.isFalse(isErrorBySindreSorhus(() => {}));
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('should act as a type guard', () => {
|
|
113
|
+
const value: Error | string = new Error('test');
|
|
114
|
+
|
|
115
|
+
if (isErrorBySindreSorhus(value)) {
|
|
116
|
+
expectType<typeof value, Error>('=');
|
|
117
|
+
|
|
118
|
+
expect(value.message).toBe('test');
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('should work with AggregateError', () => {
|
|
123
|
+
const aggregateError = new AggregateError(
|
|
124
|
+
[new Error('error 1'), new Error('error 2')],
|
|
125
|
+
'Multiple errors occurred',
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
assert.isTrue(isErrorBySindreSorhus(aggregateError));
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('should return false for errors created with Object.create', () => {
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
133
|
+
const protoError = Object.create(Error.prototype);
|
|
134
|
+
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
136
|
+
protoError.message = 'proto error';
|
|
137
|
+
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
139
|
+
protoError.name = 'ProtoError';
|
|
140
|
+
|
|
141
|
+
assert.isFalse(isErrorBySindreSorhus(protoError));
|
|
142
|
+
});
|
|
143
|
+
});
|
|
@@ -3,37 +3,51 @@ import { isNonEmptyString } from './is-non-empty-string.mjs';
|
|
|
3
3
|
|
|
4
4
|
describe(isNonEmptyString, () => {
|
|
5
5
|
test('should return true for non-empty strings', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
assert.isTrue(isNonEmptyString('hello'));
|
|
7
|
+
|
|
8
|
+
assert.isTrue(isNonEmptyString('a'));
|
|
9
|
+
|
|
10
|
+
assert.isTrue(isNonEmptyString(' ')); // Space is not empty
|
|
11
|
+
|
|
12
|
+
assert.isTrue(isNonEmptyString(' multiple spaces '));
|
|
13
|
+
|
|
14
|
+
assert.isTrue(isNonEmptyString('123'));
|
|
15
|
+
|
|
16
|
+
assert.isTrue(isNonEmptyString('special!@#$%'));
|
|
12
17
|
});
|
|
13
18
|
|
|
14
19
|
test('should return false for empty string', () => {
|
|
15
|
-
|
|
20
|
+
assert.isFalse(isNonEmptyString(''));
|
|
16
21
|
});
|
|
17
22
|
|
|
18
23
|
test('should return false for non-string values', () => {
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
assert.isFalse(isNonEmptyString(null));
|
|
25
|
+
|
|
26
|
+
assert.isFalse(isNonEmptyString(undefined));
|
|
27
|
+
|
|
21
28
|
// @ts-expect-error Testing non-string types
|
|
22
|
-
|
|
29
|
+
assert.isFalse(isNonEmptyString(42));
|
|
30
|
+
|
|
23
31
|
// @ts-expect-error Testing non-string types
|
|
24
|
-
|
|
32
|
+
assert.isFalse(isNonEmptyString(0));
|
|
33
|
+
|
|
25
34
|
// @ts-expect-error Testing non-string types
|
|
26
|
-
|
|
35
|
+
assert.isFalse(isNonEmptyString(true));
|
|
36
|
+
|
|
27
37
|
// @ts-expect-error Testing non-string types
|
|
28
|
-
|
|
38
|
+
assert.isFalse(isNonEmptyString(false));
|
|
39
|
+
|
|
29
40
|
// @ts-expect-error Testing non-string types
|
|
30
|
-
|
|
41
|
+
assert.isFalse(isNonEmptyString({}));
|
|
42
|
+
|
|
31
43
|
// @ts-expect-error Testing non-string types
|
|
32
|
-
|
|
44
|
+
assert.isFalse(isNonEmptyString([]));
|
|
45
|
+
|
|
33
46
|
// @ts-expect-error Testing non-string types
|
|
34
|
-
|
|
47
|
+
assert.isFalse(isNonEmptyString(['string']));
|
|
48
|
+
|
|
35
49
|
// @ts-expect-error Testing non-string types
|
|
36
|
-
|
|
50
|
+
assert.isFalse(isNonEmptyString(() => 'string'));
|
|
37
51
|
});
|
|
38
52
|
|
|
39
53
|
test('should act as a type guard', () => {
|
|
@@ -45,6 +59,7 @@ describe(isNonEmptyString, () => {
|
|
|
45
59
|
|
|
46
60
|
// TypeScript knows it's a string
|
|
47
61
|
expect(value.length).toBeGreaterThan(0);
|
|
62
|
+
|
|
48
63
|
expect(value.charAt(0)).toBe('t');
|
|
49
64
|
}
|
|
50
65
|
});
|
|
@@ -78,17 +93,22 @@ describe(isNonEmptyString, () => {
|
|
|
78
93
|
});
|
|
79
94
|
|
|
80
95
|
test('should handle string edge cases', () => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
96
|
+
assert.isTrue(isNonEmptyString('\n')); // Newline
|
|
97
|
+
|
|
98
|
+
assert.isTrue(isNonEmptyString('\t')); // Tab
|
|
99
|
+
|
|
100
|
+
assert.isTrue(isNonEmptyString('\r')); // Carriage return
|
|
101
|
+
|
|
102
|
+
assert.isTrue(isNonEmptyString('\0')); // Null character
|
|
103
|
+
|
|
104
|
+
assert.isTrue(isNonEmptyString('🎉')); // Emoji
|
|
105
|
+
|
|
106
|
+
assert.isTrue(isNonEmptyString('你好')); // Unicode characters
|
|
87
107
|
});
|
|
88
108
|
|
|
89
109
|
test('should not accept String objects', () => {
|
|
90
110
|
// @ts-expect-error Testing non-string types
|
|
91
111
|
// eslint-disable-next-line unicorn/new-for-builtins
|
|
92
|
-
|
|
112
|
+
assert.isFalse(isNonEmptyString(new String('hello') as unknown));
|
|
93
113
|
});
|
|
94
114
|
});
|