ts-data-forge 14.6.4 → 14.7.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 +2 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts +36 -6
- package/dist/array/impl/array-utils-length-bounded-array-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +4 -0
- package/dist/array/impl/array-utils-length-bounded-array-cast.mjs.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts +26 -6
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.d.mts.map +1 -1
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +4 -0
- package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs.map +1 -1
- package/dist/expect-type.d.mts +2 -70
- package/dist/expect-type.d.mts.map +1 -1
- package/dist/expect-type.mjs +1 -68
- package/dist/expect-type.mjs.map +1 -1
- package/dist/functional/index.d.mts +11 -6
- package/dist/functional/index.d.mts.map +1 -1
- package/dist/functional/index.mjs +10 -6
- package/dist/functional/index.mjs.map +1 -1
- package/dist/guard/has-key.d.mts +2 -51
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +1 -41
- package/dist/guard/has-key.mjs.map +1 -1
- package/dist/guard/is-non-null-object.d.mts +2 -34
- package/dist/guard/is-non-null-object.d.mts.map +1 -1
- package/dist/guard/is-non-null-object.mjs +1 -34
- package/dist/guard/is-non-null-object.mjs.map +1 -1
- package/dist/guard/is-record.d.mts +2 -89
- package/dist/guard/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +1 -88
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts +2 -42
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +1 -40
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/number/num.d.mts +9 -1
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +24 -16
- package/dist/number/num.mjs.map +1 -1
- package/dist/others/index.d.mts +1 -0
- package/dist/others/index.d.mts.map +1 -1
- package/dist/others/index.mjs +1 -0
- package/dist/others/index.mjs.map +1 -1
- package/dist/others/panic-error.d.mts +9 -0
- package/dist/others/panic-error.d.mts.map +1 -0
- package/dist/others/panic-error.mjs +9 -0
- package/dist/others/panic-error.mjs.map +1 -0
- package/dist/others/unknown-to-string.d.mts +2 -37
- package/dist/others/unknown-to-string.d.mts.map +1 -1
- package/dist/others/unknown-to-string.mjs +1 -92
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/types.d.mts +1 -41
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +0 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +9 -9
- package/src/array/impl/array-utils-length-bounded-array-cast.mts +36 -6
- package/src/array/impl/array-utils-length-bounded-tuple-cast.mts +26 -6
- package/src/expect-type.mts +2 -78
- package/src/functional/index.mts +31 -6
- package/src/guard/has-key.mts +2 -72
- package/src/guard/is-non-null-object.mts +2 -36
- package/src/guard/is-record.mts +2 -95
- package/src/guard/key-is-in.mts +2 -49
- package/src/index.mts +2 -0
- package/src/number/num.mts +36 -28
- package/src/others/index.mts +1 -0
- package/src/others/panic-error.mts +8 -0
- package/src/others/unknown-to-string.mts +2 -111
- package/src/types.mts +4 -54
- package/dist/functional/async-result/async-result.d.mts +0 -16
- package/dist/functional/async-result/async-result.d.mts.map +0 -1
- package/dist/functional/async-result/async-result.mjs +0 -2
- package/dist/functional/async-result/async-result.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-flat-map.d.mts +0 -39
- package/dist/functional/async-result/impl/async-result-flat-map.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-flat-map.mjs +0 -23
- package/dist/functional/async-result/impl/async-result-flat-map.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-promise.d.mts +0 -47
- package/dist/functional/async-result/impl/async-result-from-promise.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-promise.mjs +0 -10
- package/dist/functional/async-result/impl/async-result-from-promise.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-throwable.d.mts +0 -53
- package/dist/functional/async-result/impl/async-result-from-throwable.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-from-throwable.mjs +0 -15
- package/dist/functional/async-result/impl/async-result-from-throwable.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-map-err.d.mts +0 -35
- package/dist/functional/async-result/impl/async-result-map-err.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-map-err.mjs +0 -20
- package/dist/functional/async-result/impl/async-result-map-err.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-map.d.mts +0 -45
- package/dist/functional/async-result/impl/async-result-map.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-map.mjs +0 -20
- package/dist/functional/async-result/impl/async-result-map.mjs.map +0 -1
- package/dist/functional/async-result/impl/async-result-unwrap-or.d.mts +0 -34
- package/dist/functional/async-result/impl/async-result-unwrap-or.d.mts.map +0 -1
- package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +0 -37
- package/dist/functional/async-result/impl/async-result-unwrap-or.mjs.map +0 -1
- package/dist/functional/async-result/impl/index.d.mts +0 -8
- package/dist/functional/async-result/impl/index.d.mts.map +0 -1
- package/dist/functional/async-result/impl/index.mjs +0 -8
- package/dist/functional/async-result/impl/index.mjs.map +0 -1
- package/dist/functional/async-result/impl/types.d.mts +0 -45
- package/dist/functional/async-result/impl/types.d.mts.map +0 -1
- package/dist/functional/async-result/impl/types.mjs +0 -2
- package/dist/functional/async-result/impl/types.mjs.map +0 -1
- package/dist/functional/async-result/index.d.mts +0 -2
- package/dist/functional/async-result/index.d.mts.map +0 -1
- package/dist/functional/async-result/index.mjs +0 -2
- package/dist/functional/async-result/index.mjs.map +0 -1
- package/dist/functional/match.d.mts +0 -80
- package/dist/functional/match.d.mts.map +0 -1
- package/dist/functional/match.mjs +0 -31
- package/dist/functional/match.mjs.map +0 -1
- package/dist/functional/optional/impl/index.d.mts +0 -19
- package/dist/functional/optional/impl/index.d.mts.map +0 -1
- package/dist/functional/optional/impl/index.mjs +0 -19
- package/dist/functional/optional/impl/index.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts +0 -37
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-expect-to-be.mjs +0 -22
- package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-filter.d.mts +0 -33
- package/dist/functional/optional/impl/optional-filter.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-filter.mjs +0 -25
- package/dist/functional/optional/impl/optional-filter.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-flat-map.d.mts +0 -39
- package/dist/functional/optional/impl/optional-flat-map.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-flat-map.mjs +0 -18
- package/dist/functional/optional/impl/optional-flat-map.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-from-nullable.d.mts +0 -27
- package/dist/functional/optional/impl/optional-from-nullable.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-from-nullable.mjs +0 -28
- package/dist/functional/optional/impl/optional-from-nullable.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-is-none.d.mts +0 -23
- package/dist/functional/optional/impl/optional-is-none.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +0 -22
- package/dist/functional/optional/impl/optional-is-none.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts +0 -21
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +0 -26
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts +0 -24
- package/dist/functional/optional/impl/optional-is-some.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +0 -23
- package/dist/functional/optional/impl/optional-is-some.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-map.d.mts +0 -34
- package/dist/functional/optional/impl/optional-map.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-map.mjs +0 -22
- package/dist/functional/optional/impl/optional-map.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-match.d.mts +0 -48
- package/dist/functional/optional/impl/optional-match.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-match.mjs +0 -20
- package/dist/functional/optional/impl/optional-match.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-none.d.mts +0 -19
- package/dist/functional/optional/impl/optional-none.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-none.mjs +0 -19
- package/dist/functional/optional/impl/optional-none.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-or-else.d.mts +0 -43
- package/dist/functional/optional/impl/optional-or-else.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-or-else.mjs +0 -16
- package/dist/functional/optional/impl/optional-or-else.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-some.d.mts +0 -22
- package/dist/functional/optional/impl/optional-some.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-some.mjs +0 -25
- package/dist/functional/optional/impl/optional-some.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +0 -30
- package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-to-nullable.mjs +0 -30
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +0 -37
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-or.mjs +0 -16
- package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +0 -31
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +0 -36
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap.d.mts +0 -32
- package/dist/functional/optional/impl/optional-unwrap.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-unwrap.mjs +0 -8
- package/dist/functional/optional/impl/optional-unwrap.mjs.map +0 -1
- package/dist/functional/optional/impl/optional-zip.d.mts +0 -35
- package/dist/functional/optional/impl/optional-zip.d.mts.map +0 -1
- package/dist/functional/optional/impl/optional-zip.mjs +0 -39
- package/dist/functional/optional/impl/optional-zip.mjs.map +0 -1
- package/dist/functional/optional/impl/tag.d.mts +0 -6
- package/dist/functional/optional/impl/tag.d.mts.map +0 -1
- package/dist/functional/optional/impl/tag.mjs +0 -4
- package/dist/functional/optional/impl/tag.mjs.map +0 -1
- package/dist/functional/optional/impl/types.d.mts +0 -24
- package/dist/functional/optional/impl/types.d.mts.map +0 -1
- package/dist/functional/optional/impl/types.mjs +0 -2
- package/dist/functional/optional/impl/types.mjs.map +0 -1
- package/dist/functional/optional/index.d.mts +0 -2
- package/dist/functional/optional/index.d.mts.map +0 -1
- package/dist/functional/optional/index.mjs +0 -2
- package/dist/functional/optional/index.mjs.map +0 -1
- package/dist/functional/optional/optional.d.mts +0 -16
- package/dist/functional/optional/optional.d.mts.map +0 -1
- package/dist/functional/optional/optional.mjs +0 -2
- package/dist/functional/optional/optional.mjs.map +0 -1
- package/dist/functional/pipe.d.mts +0 -102
- package/dist/functional/pipe.d.mts.map +0 -1
- package/dist/functional/pipe.mjs +0 -45
- package/dist/functional/pipe.mjs.map +0 -1
- package/dist/functional/result/impl/index.d.mts +0 -28
- package/dist/functional/result/impl/index.d.mts.map +0 -1
- package/dist/functional/result/impl/index.mjs +0 -28
- package/dist/functional/result/impl/index.mjs.map +0 -1
- package/dist/functional/result/impl/result-err.d.mts +0 -28
- package/dist/functional/result/impl/result-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-err.mjs +0 -31
- package/dist/functional/result/impl/result-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-expect-to-be.d.mts +0 -33
- package/dist/functional/result/impl/result-expect-to-be.d.mts.map +0 -1
- package/dist/functional/result/impl/result-expect-to-be.mjs +0 -23
- package/dist/functional/result/impl/result-expect-to-be.mjs.map +0 -1
- package/dist/functional/result/impl/result-flat-map.d.mts +0 -45
- package/dist/functional/result/impl/result-flat-map.d.mts.map +0 -1
- package/dist/functional/result/impl/result-flat-map.mjs +0 -21
- package/dist/functional/result/impl/result-flat-map.mjs.map +0 -1
- package/dist/functional/result/impl/result-fold.d.mts +0 -50
- package/dist/functional/result/impl/result-fold.d.mts.map +0 -1
- package/dist/functional/result/impl/result-fold.mjs +0 -23
- package/dist/functional/result/impl/result-fold.mjs.map +0 -1
- package/dist/functional/result/impl/result-from-optional.d.mts +0 -41
- package/dist/functional/result/impl/result-from-optional.d.mts.map +0 -1
- package/dist/functional/result/impl/result-from-optional.mjs +0 -21
- package/dist/functional/result/impl/result-from-optional.mjs.map +0 -1
- package/dist/functional/result/impl/result-from-promise.d.mts +0 -43
- package/dist/functional/result/impl/result-from-promise.d.mts.map +0 -1
- package/dist/functional/result/impl/result-from-promise.mjs +0 -39
- package/dist/functional/result/impl/result-from-promise.mjs.map +0 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts +0 -32
- package/dist/functional/result/impl/result-from-throwable.d.mts.map +0 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +0 -46
- package/dist/functional/result/impl/result-from-throwable.mjs.map +0 -1
- package/dist/functional/result/impl/result-is-err.d.mts +0 -23
- package/dist/functional/result/impl/result-is-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-is-err.mjs +0 -22
- package/dist/functional/result/impl/result-is-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-is-ok.d.mts +0 -23
- package/dist/functional/result/impl/result-is-ok.d.mts.map +0 -1
- package/dist/functional/result/impl/result-is-ok.mjs +0 -22
- package/dist/functional/result/impl/result-is-ok.mjs.map +0 -1
- package/dist/functional/result/impl/result-is-result.d.mts +0 -22
- package/dist/functional/result/impl/result-is-result.d.mts.map +0 -1
- package/dist/functional/result/impl/result-is-result.mjs +0 -26
- package/dist/functional/result/impl/result-is-result.mjs.map +0 -1
- package/dist/functional/result/impl/result-map-err.d.mts +0 -39
- package/dist/functional/result/impl/result-map-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-map-err.mjs +0 -22
- package/dist/functional/result/impl/result-map-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-map.d.mts +0 -39
- package/dist/functional/result/impl/result-map.d.mts.map +0 -1
- package/dist/functional/result/impl/result-map.mjs +0 -22
- package/dist/functional/result/impl/result-map.mjs.map +0 -1
- package/dist/functional/result/impl/result-match.d.mts +0 -47
- package/dist/functional/result/impl/result-match.d.mts.map +0 -1
- package/dist/functional/result/impl/result-match.mjs +0 -20
- package/dist/functional/result/impl/result-match.mjs.map +0 -1
- package/dist/functional/result/impl/result-ok.d.mts +0 -28
- package/dist/functional/result/impl/result-ok.d.mts.map +0 -1
- package/dist/functional/result/impl/result-ok.mjs +0 -31
- package/dist/functional/result/impl/result-ok.mjs.map +0 -1
- package/dist/functional/result/impl/result-or-else.d.mts +0 -40
- package/dist/functional/result/impl/result-or-else.d.mts.map +0 -1
- package/dist/functional/result/impl/result-or-else.mjs +0 -17
- package/dist/functional/result/impl/result-or-else.mjs.map +0 -1
- package/dist/functional/result/impl/result-safe-try.d.mts +0 -51
- package/dist/functional/result/impl/result-safe-try.d.mts.map +0 -1
- package/dist/functional/result/impl/result-safe-try.mjs +0 -35
- package/dist/functional/result/impl/result-safe-try.mjs.map +0 -1
- package/dist/functional/result/impl/result-safe-unwrap.d.mts +0 -36
- package/dist/functional/result/impl/result-safe-unwrap.d.mts.map +0 -1
- package/dist/functional/result/impl/result-safe-unwrap.mjs +0 -42
- package/dist/functional/result/impl/result-safe-unwrap.mjs.map +0 -1
- package/dist/functional/result/impl/result-swap.d.mts +0 -23
- package/dist/functional/result/impl/result-swap.d.mts.map +0 -1
- package/dist/functional/result/impl/result-swap.mjs +0 -27
- package/dist/functional/result/impl/result-swap.mjs.map +0 -1
- package/dist/functional/result/impl/result-to-optional.d.mts +0 -32
- package/dist/functional/result/impl/result-to-optional.d.mts.map +0 -1
- package/dist/functional/result/impl/result-to-optional.mjs +0 -32
- package/dist/functional/result/impl/result-to-optional.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-or.mjs +0 -17
- package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +0 -46
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-err.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-err.mjs +0 -34
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs +0 -17
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok.d.mts +0 -26
- package/dist/functional/result/impl/result-unwrap-ok.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-ok.mjs +0 -8
- package/dist/functional/result/impl/result-unwrap-ok.mjs.map +0 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts +0 -33
- package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +0 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +0 -40
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +0 -1
- package/dist/functional/result/impl/result-zip.d.mts +0 -32
- package/dist/functional/result/impl/result-zip.d.mts.map +0 -1
- package/dist/functional/result/impl/result-zip.mjs +0 -37
- package/dist/functional/result/impl/result-zip.mjs.map +0 -1
- package/dist/functional/result/impl/tag.d.mts +0 -6
- package/dist/functional/result/impl/tag.d.mts.map +0 -1
- package/dist/functional/result/impl/tag.mjs +0 -4
- package/dist/functional/result/impl/tag.mjs.map +0 -1
- package/dist/functional/result/impl/types.d.mts +0 -31
- package/dist/functional/result/impl/types.d.mts.map +0 -1
- package/dist/functional/result/impl/types.mjs +0 -2
- package/dist/functional/result/impl/types.mjs.map +0 -1
- package/dist/functional/result/index.d.mts +0 -2
- package/dist/functional/result/index.d.mts.map +0 -1
- package/dist/functional/result/index.mjs +0 -2
- package/dist/functional/result/index.mjs.map +0 -1
- package/dist/functional/result/result.d.mts +0 -16
- package/dist/functional/result/result.d.mts.map +0 -1
- package/dist/functional/result/result.mjs +0 -2
- package/dist/functional/result/result.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/index.d.mts +0 -29
- package/dist/functional/ternary-result/impl/index.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/index.mjs +0 -29
- package/dist/functional/ternary-result/impl/index.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/tag.d.mts +0 -8
- package/dist/functional/ternary-result/impl/tag.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/tag.mjs +0 -6
- package/dist/functional/ternary-result/impl/tag.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +0 -16
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +0 -19
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts +0 -24
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts +0 -39
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +0 -38
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts +0 -30
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +0 -33
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +0 -33
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-is-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +0 -28
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts +0 -27
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts +0 -28
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +0 -26
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts +0 -36
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs +0 -32
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts +0 -17
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts +0 -29
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs +0 -16
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +0 -26
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts +0 -28
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs +0 -14
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +0 -34
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts +0 -25
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs +0 -14
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +0 -10
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +0 -35
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts +0 -22
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs +0 -14
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +0 -30
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts +0 -20
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +0 -21
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts +0 -19
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +0 -23
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts +0 -34
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +0 -52
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/types.d.mts +0 -26
- package/dist/functional/ternary-result/impl/types.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/types.mjs +0 -2
- package/dist/functional/ternary-result/impl/types.mjs.map +0 -1
- package/dist/functional/ternary-result/impl/variant-name.d.mts +0 -4
- package/dist/functional/ternary-result/impl/variant-name.d.mts.map +0 -1
- package/dist/functional/ternary-result/impl/variant-name.mjs +0 -13
- package/dist/functional/ternary-result/impl/variant-name.mjs.map +0 -1
- package/dist/functional/ternary-result/index.d.mts +0 -2
- package/dist/functional/ternary-result/index.d.mts.map +0 -1
- package/dist/functional/ternary-result/index.mjs +0 -2
- package/dist/functional/ternary-result/index.mjs.map +0 -1
- package/dist/functional/ternary-result/ternary-result.d.mts +0 -40
- package/dist/functional/ternary-result/ternary-result.d.mts.map +0 -1
- package/dist/functional/ternary-result/ternary-result.mjs +0 -2
- package/dist/functional/ternary-result/ternary-result.mjs.map +0 -1
- package/src/functional/async-result/async-result.mts +0 -17
- package/src/functional/async-result/impl/async-result-flat-map.mts +0 -99
- package/src/functional/async-result/impl/async-result-from-promise.mts +0 -69
- package/src/functional/async-result/impl/async-result-from-throwable.mts +0 -78
- package/src/functional/async-result/impl/async-result-map-err.mts +0 -84
- package/src/functional/async-result/impl/async-result-map.mts +0 -94
- package/src/functional/async-result/impl/async-result-unwrap-or.mts +0 -42
- package/src/functional/async-result/impl/index.mts +0 -7
- package/src/functional/async-result/impl/types.mts +0 -51
- package/src/functional/async-result/index.mts +0 -1
- package/src/functional/async-result.test.mts +0 -291
- package/src/functional/match.mts +0 -193
- package/src/functional/match.test.mts +0 -180
- package/src/functional/optional/impl/index.mts +0 -18
- package/src/functional/optional/impl/optional-expect-to-be.mts +0 -75
- package/src/functional/optional/impl/optional-filter.mts +0 -78
- package/src/functional/optional/impl/optional-flat-map.mts +0 -75
- package/src/functional/optional/impl/optional-from-nullable.mts +0 -31
- package/src/functional/optional/impl/optional-is-none.mts +0 -26
- package/src/functional/optional/impl/optional-is-optional.mts +0 -30
- package/src/functional/optional/impl/optional-is-some.mts +0 -27
- package/src/functional/optional/impl/optional-map.mts +0 -90
- package/src/functional/optional/impl/optional-match.mts +0 -108
- package/src/functional/optional/impl/optional-none.mts +0 -20
- package/src/functional/optional/impl/optional-or-else.mts +0 -83
- package/src/functional/optional/impl/optional-some.mts +0 -27
- package/src/functional/optional/impl/optional-to-nullable.mts +0 -34
- package/src/functional/optional/impl/optional-unwrap-or.mts +0 -70
- package/src/functional/optional/impl/optional-unwrap-throw.mts +0 -41
- package/src/functional/optional/impl/optional-unwrap.mts +0 -45
- package/src/functional/optional/impl/optional-zip.mts +0 -44
- package/src/functional/optional/impl/tag.mts +0 -8
- package/src/functional/optional/impl/types.mts +0 -31
- package/src/functional/optional/index.mts +0 -1
- package/src/functional/optional/optional.mts +0 -19
- package/src/functional/optional.test.mts +0 -883
- package/src/functional/pipe.mts +0 -180
- package/src/functional/pipe.test.mts +0 -155
- package/src/functional/result/impl/index.mts +0 -27
- package/src/functional/result/impl/result-err.mts +0 -33
- package/src/functional/result/impl/result-expect-to-be.mts +0 -73
- package/src/functional/result/impl/result-flat-map.mts +0 -88
- package/src/functional/result/impl/result-fold.mts +0 -102
- package/src/functional/result/impl/result-from-optional.mts +0 -80
- package/src/functional/result/impl/result-from-promise.mts +0 -51
- package/src/functional/result/impl/result-from-throwable.mts +0 -48
- package/src/functional/result/impl/result-is-err.mts +0 -26
- package/src/functional/result/impl/result-is-ok.mts +0 -26
- package/src/functional/result/impl/result-is-result.mts +0 -28
- package/src/functional/result/impl/result-map-err.mts +0 -96
- package/src/functional/result/impl/result-map.mts +0 -96
- package/src/functional/result/impl/result-match.mts +0 -108
- package/src/functional/result/impl/result-ok.mts +0 -33
- package/src/functional/result/impl/result-or-else.mts +0 -73
- package/src/functional/result/impl/result-safe-try.mts +0 -110
- package/src/functional/result/impl/result-safe-unwrap.mts +0 -50
- package/src/functional/result/impl/result-swap.mts +0 -31
- package/src/functional/result/impl/result-to-optional.mts +0 -37
- package/src/functional/result/impl/result-unwrap-err-or.mts +0 -66
- package/src/functional/result/impl/result-unwrap-err-throw.mts +0 -56
- package/src/functional/result/impl/result-unwrap-err.mts +0 -38
- package/src/functional/result/impl/result-unwrap-ok-or.mts +0 -66
- package/src/functional/result/impl/result-unwrap-ok.mts +0 -39
- package/src/functional/result/impl/result-unwrap-throw.mts +0 -46
- package/src/functional/result/impl/result-zip.mts +0 -42
- package/src/functional/result/impl/tag.mts +0 -8
- package/src/functional/result/impl/types.mts +0 -38
- package/src/functional/result/index.mts +0 -1
- package/src/functional/result/result.mts +0 -19
- package/src/functional/result.test.mts +0 -1349
- package/src/functional/ternary-result/impl/index.mts +0 -28
- package/src/functional/ternary-result/impl/tag.mts +0 -17
- package/src/functional/ternary-result/impl/ternary-result-err.mts +0 -21
- package/src/functional/ternary-result/impl/ternary-result-expect-to-be.mts +0 -65
- package/src/functional/ternary-result/impl/ternary-result-flat-map.mts +0 -112
- package/src/functional/ternary-result/impl/ternary-result-fold.mts +0 -102
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +0 -30
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +0 -36
- package/src/functional/ternary-result/impl/ternary-result-is-err.mts +0 -24
- package/src/functional/ternary-result/impl/ternary-result-is-ok.mts +0 -26
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +0 -32
- package/src/functional/ternary-result/impl/ternary-result-is-warn.mts +0 -25
- package/src/functional/ternary-result/impl/ternary-result-map-err.mts +0 -74
- package/src/functional/ternary-result/impl/ternary-result-map-warn.mts +0 -79
- package/src/functional/ternary-result/impl/ternary-result-map.mts +0 -95
- package/src/functional/ternary-result/impl/ternary-result-ok.mts +0 -22
- package/src/functional/ternary-result/impl/ternary-result-or-else.mts +0 -72
- package/src/functional/ternary-result/impl/ternary-result-to-optional.mts +0 -31
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-or.mts +0 -54
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mts +0 -42
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err.mts +0 -25
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mts +0 -51
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok.mts +0 -39
- package/src/functional/ternary-result/impl/ternary-result-unwrap-throw.mts +0 -48
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mts +0 -48
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mts +0 -40
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn.mts +0 -25
- package/src/functional/ternary-result/impl/ternary-result-warn.mts +0 -28
- package/src/functional/ternary-result/impl/ternary-result-zip.mts +0 -61
- package/src/functional/ternary-result/impl/types.mts +0 -46
- package/src/functional/ternary-result/impl/variant-name.mts +0 -18
- package/src/functional/ternary-result/index.mts +0 -1
- package/src/functional/ternary-result/ternary-result.mts +0 -50
- package/src/functional/ternary-result.test.mts +0 -310
- package/src/guard/has-key.test.mts +0 -111
- package/src/guard/is-non-null-object.test.mts +0 -109
- package/src/guard/is-record.test.mts +0 -195
- package/src/guard/key-is-in.test.mts +0 -21
- package/src/others/unknown-to-string.test.mts +0 -295
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type TernaryErr,
|
|
3
|
-
type TernaryOk,
|
|
4
|
-
type TernaryWarn,
|
|
5
|
-
type UnknownTernaryResult,
|
|
6
|
-
} from '../ternary-result.mjs';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Extracts the success value type `S` from a `TernaryResult.Ok<S>`.
|
|
10
|
-
*/
|
|
11
|
-
export type UnwrapOk<R extends UnknownTernaryResult> =
|
|
12
|
-
R extends TernaryOk<infer S>
|
|
13
|
-
? S
|
|
14
|
-
: R extends TernaryWarn<infer S, unknown>
|
|
15
|
-
? S
|
|
16
|
-
: never;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Extracts the warning value type `W` from a `TernaryResult.Warn<W>`.
|
|
20
|
-
*/
|
|
21
|
-
export type UnwrapWarn<R extends UnknownTernaryResult> =
|
|
22
|
-
R extends TernaryWarn<unknown, infer E> ? E : never;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Extracts the error value type `E` from a `TernaryResult.Err<E>`.
|
|
26
|
-
*/
|
|
27
|
-
export type UnwrapErr<R extends UnknownTernaryResult> =
|
|
28
|
-
R extends TernaryErr<infer E> ? E : never;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Narrows the provided `UnknownTernaryResult` to its Ok variant.
|
|
32
|
-
*/
|
|
33
|
-
export type NarrowToOk<R extends UnknownTernaryResult> =
|
|
34
|
-
R extends TernaryOk<unknown> ? R : never;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Narrows the provided `UnknownTernaryResult` to its Warn variant.
|
|
38
|
-
*/
|
|
39
|
-
export type NarrowToWarn<R extends UnknownTernaryResult> =
|
|
40
|
-
R extends TernaryWarn<unknown, unknown> ? R : never;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Narrows the provided `UnknownTernaryResult` to its Err variant.
|
|
44
|
-
*/
|
|
45
|
-
export type NarrowToErr<R extends UnknownTernaryResult> =
|
|
46
|
-
R extends TernaryErr<unknown> ? R : never;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type UnknownTernaryResult } from '../ternary-result.mjs';
|
|
2
|
-
import { ErrTypeTagName, OkTypeTagName, WarnTypeTagName } from './tag.mjs';
|
|
3
|
-
|
|
4
|
-
/** @internal Returns the human readable variant label for the given tag. */
|
|
5
|
-
export const variantName = (
|
|
6
|
-
tag: UnknownTernaryResult['$$tag'],
|
|
7
|
-
): 'Ok' | 'Warn' | 'Err' => {
|
|
8
|
-
switch (tag) {
|
|
9
|
-
case OkTypeTagName:
|
|
10
|
-
return 'Ok';
|
|
11
|
-
|
|
12
|
-
case WarnTypeTagName:
|
|
13
|
-
return 'Warn';
|
|
14
|
-
|
|
15
|
-
case ErrTypeTagName:
|
|
16
|
-
return 'Err';
|
|
17
|
-
}
|
|
18
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ternary-result.mjs';
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a `TernaryResult` that is a success, containing a value.
|
|
3
|
-
*/
|
|
4
|
-
export type TernaryOk<S> = Readonly<{
|
|
5
|
-
/** @internal Discriminant property for the 'Ok' type. */
|
|
6
|
-
$$tag: 'ts-data-forge::Result.ok';
|
|
7
|
-
|
|
8
|
-
/** The success value. */
|
|
9
|
-
value: S;
|
|
10
|
-
}>;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Represents a `TernaryResult` that contains a success value and an attached
|
|
14
|
-
* warning.
|
|
15
|
-
*/
|
|
16
|
-
export type TernaryWarn<S, W> = Readonly<{
|
|
17
|
-
/** @internal Discriminant property for the 'Warn' type. */
|
|
18
|
-
$$tag: 'ts-data-forge::Result.warn';
|
|
19
|
-
|
|
20
|
-
/** The success value. */
|
|
21
|
-
value: S;
|
|
22
|
-
|
|
23
|
-
/** The warning value. */
|
|
24
|
-
warning: W;
|
|
25
|
-
}>;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Represents a `TernaryResult` that is an error, containing an error value.
|
|
29
|
-
*/
|
|
30
|
-
export type TernaryErr<E> = Readonly<{
|
|
31
|
-
/** @internal Discriminant property for the 'Err' type. */
|
|
32
|
-
$$tag: 'ts-data-forge::Result.err';
|
|
33
|
-
|
|
34
|
-
/** The error value. */
|
|
35
|
-
value: E;
|
|
36
|
-
}>;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Represents a value that can be `Ok`, `Warn`, or `Err`.
|
|
40
|
-
*/
|
|
41
|
-
export type TernaryResult<S, E, W = E> =
|
|
42
|
-
TernaryOk<S> | TernaryWarn<S, W> | TernaryErr<E>;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Base type for any `TernaryResult`, used for generic constraints.
|
|
46
|
-
*/
|
|
47
|
-
export type UnknownTernaryResult =
|
|
48
|
-
TernaryOk<unknown> | TernaryWarn<unknown, unknown> | TernaryErr<unknown>;
|
|
49
|
-
|
|
50
|
-
export * as TernaryResult from './impl/index.mjs';
|
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import { expectType } from '../expect-type.mjs';
|
|
2
|
-
import { Num } from '../number/index.mjs';
|
|
3
|
-
import { Optional } from './optional/index.mjs';
|
|
4
|
-
import { pipe } from './pipe.mjs';
|
|
5
|
-
import { Result } from './result/index.mjs';
|
|
6
|
-
import { TernaryResult } from './ternary-result/index.mjs';
|
|
7
|
-
|
|
8
|
-
describe('TernaryResult test', () => {
|
|
9
|
-
test('constructors and guards', () => {
|
|
10
|
-
const ok = TernaryResult.ok(1);
|
|
11
|
-
|
|
12
|
-
const warn = TernaryResult.warn(1, 'caution');
|
|
13
|
-
|
|
14
|
-
const err = TernaryResult.err(new Error('boom'));
|
|
15
|
-
|
|
16
|
-
assert.isTrue(TernaryResult.isOk(ok));
|
|
17
|
-
|
|
18
|
-
assert.isTrue(TernaryResult.isWarn(warn));
|
|
19
|
-
|
|
20
|
-
assert.isTrue(TernaryResult.isErr(err));
|
|
21
|
-
|
|
22
|
-
assert.isTrue(TernaryResult.isTernaryResult(ok));
|
|
23
|
-
|
|
24
|
-
assert.isFalse(TernaryResult.isTernaryResult({}));
|
|
25
|
-
|
|
26
|
-
expectType<typeof ok, TernaryResult<number, never, never>>('<=');
|
|
27
|
-
|
|
28
|
-
expectType<typeof warn, TernaryResult<number, never, string>>('<=');
|
|
29
|
-
|
|
30
|
-
expectType<typeof err, TernaryResult<never, Error, never>>('<=');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('map transforms Ok and Warn success values', () => {
|
|
34
|
-
const ok = TernaryResult.ok(2);
|
|
35
|
-
|
|
36
|
-
const warn = TernaryResult.warn(2, 'check');
|
|
37
|
-
|
|
38
|
-
const err = TernaryResult.err('fail');
|
|
39
|
-
|
|
40
|
-
const double = TernaryResult.map((value: number) => value * 2);
|
|
41
|
-
|
|
42
|
-
expect(TernaryResult.unwrapOk(double(ok))).toBe(4);
|
|
43
|
-
|
|
44
|
-
expect(TernaryResult.unwrapOk(double(warn))).toBe(4);
|
|
45
|
-
|
|
46
|
-
expect(TernaryResult.unwrapWarn(double(warn))).toBe('check');
|
|
47
|
-
|
|
48
|
-
expect(TernaryResult.unwrapErr(double(err))).toBe('fail');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('mapWarn and mapErr leave other variants untouched', () => {
|
|
52
|
-
const warn = TernaryResult.warn(2, 'slow');
|
|
53
|
-
|
|
54
|
-
const err = TernaryResult.err('err');
|
|
55
|
-
|
|
56
|
-
const warnMessage = TernaryResult.mapWarn(
|
|
57
|
-
(warning: string) => `${warning}!`,
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const errUpper = TernaryResult.mapErr((value: string) =>
|
|
61
|
-
value.toUpperCase(),
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
expect(TernaryResult.unwrapWarn(warnMessage(warn))).toBe('slow!');
|
|
65
|
-
|
|
66
|
-
expect(TernaryResult.unwrapOk(warnMessage(warn))).toBe(2);
|
|
67
|
-
|
|
68
|
-
expect(TernaryResult.unwrapWarn(errUpper(warn))).toBe('slow');
|
|
69
|
-
|
|
70
|
-
expect(TernaryResult.unwrapErr(errUpper(err))).toBe('ERR');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('flatMap propagates Warn and Err while keeping warnings', () => {
|
|
74
|
-
const parse = (value: string): TernaryResult<number, string, never> =>
|
|
75
|
-
pipe(Num.safeParseFloat(value)).map((result) =>
|
|
76
|
-
Result.isErr(result)
|
|
77
|
-
? TernaryResult.err('NaN')
|
|
78
|
-
: TernaryResult.ok(result.value),
|
|
79
|
-
).value;
|
|
80
|
-
|
|
81
|
-
const warn = TernaryResult.warn('3', 'slow');
|
|
82
|
-
|
|
83
|
-
const err = TernaryResult.err('bad');
|
|
84
|
-
|
|
85
|
-
const okResult = TernaryResult.flatMap(TernaryResult.ok('3'), parse);
|
|
86
|
-
|
|
87
|
-
const warnResult = TernaryResult.flatMap(warn, parse);
|
|
88
|
-
|
|
89
|
-
const errResult = TernaryResult.flatMap(err, parse);
|
|
90
|
-
|
|
91
|
-
expect(TernaryResult.unwrapOk(okResult)).toBe(3);
|
|
92
|
-
|
|
93
|
-
assert.isTrue(TernaryResult.isWarn(warnResult));
|
|
94
|
-
|
|
95
|
-
if (TernaryResult.isWarn(warnResult)) {
|
|
96
|
-
expect(warnResult.value).toBe(3);
|
|
97
|
-
|
|
98
|
-
expect(warnResult.warning).toBe('slow');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
expect(TernaryResult.unwrapErr(errResult)).toBe('bad');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test('fold maps each variant independently', () => {
|
|
105
|
-
const value = TernaryResult.fold(
|
|
106
|
-
TernaryResult.ok(1),
|
|
107
|
-
(o: number) => o + 1,
|
|
108
|
-
(w: string) => ({ warning: w }),
|
|
109
|
-
(e: string) => ({ message: e }),
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const warn = TernaryResult.fold(
|
|
113
|
-
TernaryResult.warn(2, 'heads up'),
|
|
114
|
-
(x) => x * 2,
|
|
115
|
-
(w: string) => ({ warning: w }),
|
|
116
|
-
(e: string) => ({ message: e }),
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
const err = TernaryResult.fold(
|
|
120
|
-
TernaryResult.err('boom'),
|
|
121
|
-
(x) => x,
|
|
122
|
-
(w: string) => ({ warning: w }),
|
|
123
|
-
(e: string) => ({ message: e }),
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
expect(TernaryResult.unwrapOk(value)).toBe(2);
|
|
127
|
-
|
|
128
|
-
expect(TernaryResult.unwrapOk(warn)).toBe(4);
|
|
129
|
-
|
|
130
|
-
assert.deepStrictEqual(TernaryResult.unwrapWarn(warn), {
|
|
131
|
-
warning: 'heads up',
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
assert.deepStrictEqual(TernaryResult.unwrapErr(err), { message: 'boom' });
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test('orElse keeps Ok and Warn variants', () => {
|
|
138
|
-
const fallback = TernaryResult.ok('fallback');
|
|
139
|
-
|
|
140
|
-
assert.deepStrictEqual(
|
|
141
|
-
TernaryResult.orElse(TernaryResult.ok('value'), fallback),
|
|
142
|
-
TernaryResult.ok('value'),
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
assert.deepStrictEqual(
|
|
146
|
-
TernaryResult.orElse(TernaryResult.warn('value', 'warn'), fallback),
|
|
147
|
-
TernaryResult.warn('value', 'warn'),
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
assert.deepStrictEqual(
|
|
151
|
-
TernaryResult.orElse(TernaryResult.err('err'), fallback),
|
|
152
|
-
fallback,
|
|
153
|
-
);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test('unwrap helpers', () => {
|
|
157
|
-
const warn = TernaryResult.warn('value', 'careful');
|
|
158
|
-
|
|
159
|
-
const err = TernaryResult.err('broken');
|
|
160
|
-
|
|
161
|
-
expect(TernaryResult.unwrapOk(TernaryResult.ok(3))).toBe(3);
|
|
162
|
-
|
|
163
|
-
expect(TernaryResult.unwrapOk(warn)).toBe('value');
|
|
164
|
-
|
|
165
|
-
expect(TernaryResult.unwrapWarn(warn)).toBe('careful');
|
|
166
|
-
|
|
167
|
-
expect(TernaryResult.unwrapErr(err)).toBe('broken');
|
|
168
|
-
|
|
169
|
-
expect(TernaryResult.unwrapOkOr(err, 0)).toBe(0);
|
|
170
|
-
|
|
171
|
-
expect(TernaryResult.unwrapWarnOr(err, 'default')).toBe('default');
|
|
172
|
-
|
|
173
|
-
expect(TernaryResult.unwrapErrOr(warn, 'default')).toBe('default');
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
test('throwing unwrap variants provide descriptive errors', () => {
|
|
177
|
-
expect(() =>
|
|
178
|
-
TernaryResult.unwrapThrow(TernaryResult.warn('notice', 'warned')),
|
|
179
|
-
).toThrow(/Warn/u);
|
|
180
|
-
|
|
181
|
-
expect(() =>
|
|
182
|
-
TernaryResult.unwrapWarnThrow(TernaryResult.err('no warn')),
|
|
183
|
-
).toThrow(/Err/u);
|
|
184
|
-
|
|
185
|
-
expect(() =>
|
|
186
|
-
TernaryResult.unwrapErrThrow(TernaryResult.ok('no err')),
|
|
187
|
-
).toThrow(/Ok/u);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
test('expectToBe unwraps Ok values', () => {
|
|
191
|
-
expect(TernaryResult.expectToBe(TernaryResult.ok('v'), 'msg')).toBe('v');
|
|
192
|
-
|
|
193
|
-
expect(() =>
|
|
194
|
-
TernaryResult.expectToBe(TernaryResult.err('x'), 'missing'),
|
|
195
|
-
).toThrow(/missing/u);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test('zip prefers Err over Warn or Ok.', () => {
|
|
199
|
-
const ok = TernaryResult.ok('x');
|
|
200
|
-
|
|
201
|
-
const warn = TernaryResult.warn('warn', 'warned');
|
|
202
|
-
|
|
203
|
-
const err = TernaryResult.err('err');
|
|
204
|
-
|
|
205
|
-
assert.deepStrictEqual(
|
|
206
|
-
TernaryResult.zip(ok, TernaryResult.ok(1)),
|
|
207
|
-
TernaryResult.ok(['x', 1] as const),
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
assert.deepStrictEqual(
|
|
211
|
-
TernaryResult.zip(ok, warn),
|
|
212
|
-
TernaryResult.warn(['x', 'warn'] as const, 'warned'),
|
|
213
|
-
);
|
|
214
|
-
|
|
215
|
-
assert.deepStrictEqual(
|
|
216
|
-
TernaryResult.zip(warn, ok),
|
|
217
|
-
TernaryResult.warn(['warn', 'x'] as const, 'warned'),
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
assert.deepStrictEqual(TernaryResult.zip(ok, err), err);
|
|
221
|
-
|
|
222
|
-
assert.deepStrictEqual(TernaryResult.zip(err, warn), err);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
test('toOptional keeps only Ok values', () => {
|
|
226
|
-
assert.deepStrictEqual(
|
|
227
|
-
TernaryResult.toOptional(TernaryResult.ok(1)),
|
|
228
|
-
Optional.some(1),
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
assert.deepStrictEqual(
|
|
232
|
-
TernaryResult.toOptional(TernaryResult.warn(1, 'warn')),
|
|
233
|
-
Optional.some(1),
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
expect(TernaryResult.toOptional(TernaryResult.err('err'))).toBe(
|
|
237
|
-
Optional.none,
|
|
238
|
-
);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
test('fromPromise resolves into TernaryResult', async () => {
|
|
242
|
-
await expect(
|
|
243
|
-
TernaryResult.fromPromise(Promise.resolve('ok')),
|
|
244
|
-
).resolves.toStrictEqual(TernaryResult.ok('ok'));
|
|
245
|
-
|
|
246
|
-
const rejected = await TernaryResult.fromPromise(
|
|
247
|
-
Promise.reject(new Error('bad')),
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
assert.isTrue(TernaryResult.isErr(rejected));
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
test('fromThrowable converts thrown values', () => {
|
|
254
|
-
assert.deepStrictEqual(
|
|
255
|
-
TernaryResult.fromThrowable(() => 5),
|
|
256
|
-
TernaryResult.ok(5),
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
const errorResult = TernaryResult.fromThrowable(() => {
|
|
260
|
-
throw new Error('boom');
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
assert.isTrue(TernaryResult.isErr(errorResult));
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
test('unwrapOkOr curried version', () => {
|
|
267
|
-
const unwrap = TernaryResult.unwrapOkOr(999);
|
|
268
|
-
|
|
269
|
-
expect(unwrap(TernaryResult.ok(42))).toBe(42);
|
|
270
|
-
|
|
271
|
-
expect(unwrap(TernaryResult.warn(10, 'notice'))).toBe(10);
|
|
272
|
-
|
|
273
|
-
expect(unwrap(TernaryResult.err('error'))).toBe(999);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
test('unwrapWarnOr curried version', () => {
|
|
277
|
-
const unwrap = TernaryResult.unwrapWarnOr('default');
|
|
278
|
-
|
|
279
|
-
expect(unwrap(TernaryResult.warn(1, 'alert'))).toBe('alert');
|
|
280
|
-
|
|
281
|
-
expect(unwrap(TernaryResult.ok(5))).toBe('default');
|
|
282
|
-
|
|
283
|
-
expect(unwrap(TernaryResult.err('fail'))).toBe('default');
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
test('unwrapErrOr curried version', () => {
|
|
287
|
-
const unwrap = TernaryResult.unwrapErrOr('fallback');
|
|
288
|
-
|
|
289
|
-
expect(unwrap(TernaryResult.err('bad'))).toBe('bad');
|
|
290
|
-
|
|
291
|
-
expect(unwrap(TernaryResult.ok(3))).toBe('fallback');
|
|
292
|
-
|
|
293
|
-
expect(unwrap(TernaryResult.warn(1, 'note'))).toBe('fallback');
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
test('orElse curried version', () => {
|
|
297
|
-
const fallback = TernaryResult.ok('backup');
|
|
298
|
-
|
|
299
|
-
const useBackup = TernaryResult.orElse(fallback);
|
|
300
|
-
|
|
301
|
-
assert.deepStrictEqual(useBackup(TernaryResult.ok(1)), TernaryResult.ok(1));
|
|
302
|
-
|
|
303
|
-
assert.deepStrictEqual(
|
|
304
|
-
useBackup(TernaryResult.warn(2, 'w')),
|
|
305
|
-
TernaryResult.warn(2, 'w'),
|
|
306
|
-
);
|
|
307
|
-
|
|
308
|
-
assert.deepStrictEqual(useBackup(TernaryResult.err('e')), fallback);
|
|
309
|
-
});
|
|
310
|
-
});
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { type ReadonlyRecord } from 'ts-type-forge';
|
|
2
|
-
import { expectType } from '../expect-type.mjs';
|
|
3
|
-
import { hasKey, type HasKeyReturnType } from './has-key.mjs';
|
|
4
|
-
|
|
5
|
-
test('hasKey type inferences', () => {
|
|
6
|
-
{
|
|
7
|
-
expectType<
|
|
8
|
-
HasKeyReturnType<Readonly<{ a: 0 } | { b: 1 }>, 'a'>,
|
|
9
|
-
Readonly<{ a: 0 }>
|
|
10
|
-
>('=');
|
|
11
|
-
|
|
12
|
-
expectType<
|
|
13
|
-
HasKeyReturnType<Readonly<{ a: 0 } | { b: 1 }>, 'b'>,
|
|
14
|
-
Readonly<{ b: 1 }>
|
|
15
|
-
>('=');
|
|
16
|
-
|
|
17
|
-
expectType<HasKeyReturnType<Readonly<{ a: 0 } | { b: 1 }>, 'd'>, never>(
|
|
18
|
-
'=',
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
expectType<
|
|
22
|
-
HasKeyReturnType<
|
|
23
|
-
Readonly<{ a: 0 } | { a: 1; b: 1 } | { b: 2 } | { c: 3 }>,
|
|
24
|
-
'a'
|
|
25
|
-
>,
|
|
26
|
-
Readonly<{ a: 0 } | { a: 1; b: 1 }>
|
|
27
|
-
>('=');
|
|
28
|
-
|
|
29
|
-
expectType<
|
|
30
|
-
HasKeyReturnType<
|
|
31
|
-
Readonly<{ a: 0 } | { a: 1; b: 1 } | { b: 2 } | { c: 3 }>,
|
|
32
|
-
'b'
|
|
33
|
-
>,
|
|
34
|
-
Readonly<{ a: 1; b: 1 } | { b: 2 }>
|
|
35
|
-
>('=');
|
|
36
|
-
|
|
37
|
-
expectType<
|
|
38
|
-
HasKeyReturnType<
|
|
39
|
-
| ReadonlyRecord<string, number>
|
|
40
|
-
| Readonly<{ a: 0 } | { a: 1; b: 1 } | { b: 2 }>,
|
|
41
|
-
'a'
|
|
42
|
-
>,
|
|
43
|
-
| Readonly<{ a: 0 } | { a: 1; b: 1 }>
|
|
44
|
-
| (ReadonlyRecord<'a', number> & ReadonlyRecord<string, number>)
|
|
45
|
-
>('=');
|
|
46
|
-
|
|
47
|
-
expectType<
|
|
48
|
-
HasKeyReturnType<ReadonlyRecord<string, unknown>, 'a'>,
|
|
49
|
-
ReadonlyRecord<'a', unknown> & ReadonlyRecord<string, unknown>
|
|
50
|
-
>('=');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
type R = Readonly<{ a: 0 } | { b: 1 }>;
|
|
55
|
-
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
57
|
-
const obj: R = { a: 0 } as R;
|
|
58
|
-
|
|
59
|
-
if (hasKey(obj, 'a')) {
|
|
60
|
-
expectType<typeof obj.a, 0>('=');
|
|
61
|
-
|
|
62
|
-
expectType<typeof obj, Readonly<{ a: 0 }>>('=');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (hasKey(obj, 'c')) {
|
|
66
|
-
expectType<typeof obj, never>('=');
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
{
|
|
71
|
-
type R = Readonly<{ a: 0 } | { a: 1; b: 1 } | { b: 2 } | { c: 3 }>;
|
|
72
|
-
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
74
|
-
const obj: R = { a: 0 } as R;
|
|
75
|
-
|
|
76
|
-
if (hasKey(obj, 'a') && hasKey(obj, 'b')) {
|
|
77
|
-
expectType<typeof obj.a, 1>('=');
|
|
78
|
-
|
|
79
|
-
expectType<typeof obj.b, 1>('=');
|
|
80
|
-
|
|
81
|
-
expectType<typeof obj, Readonly<{ a: 1; b: 1 }>>('=');
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
{
|
|
86
|
-
type R =
|
|
87
|
-
| ReadonlyRecord<string, number>
|
|
88
|
-
| Readonly<{ a: 0 } | { a: 1; b: 1 } | { b: 2 }>;
|
|
89
|
-
|
|
90
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
91
|
-
const obj: R = { a: 0 } as R;
|
|
92
|
-
|
|
93
|
-
expectType<
|
|
94
|
-
R,
|
|
95
|
-
| ReadonlyRecord<string, number>
|
|
96
|
-
| Readonly<{ a: 0 } | { a: 1; b: 1 } | { b: 2 }>
|
|
97
|
-
>('=');
|
|
98
|
-
|
|
99
|
-
if (hasKey(obj, 'a')) {
|
|
100
|
-
expectType<typeof obj.a, number>('=');
|
|
101
|
-
|
|
102
|
-
expectType<
|
|
103
|
-
typeof obj,
|
|
104
|
-
| Readonly<{ a: 0 } | { a: 1; b: 1 }>
|
|
105
|
-
| (ReadonlyRecord<'a', number> & ReadonlyRecord<string, number>)
|
|
106
|
-
>('=');
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
assert.strictEqual(true, true);
|
|
111
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { type UnknownRecord } from 'ts-type-forge';
|
|
2
|
-
import { expectType } from '../expect-type.mjs';
|
|
3
|
-
import { isNonNullObject } from './is-non-null-object.mjs';
|
|
4
|
-
|
|
5
|
-
describe(isNonNullObject, () => {
|
|
6
|
-
test('should return true for plain objects', () => {
|
|
7
|
-
assert.isTrue(isNonNullObject({}));
|
|
8
|
-
|
|
9
|
-
assert.isTrue(isNonNullObject({ a: 1, b: 'test' }));
|
|
10
|
-
|
|
11
|
-
assert.isTrue(isNonNullObject({ nested: { value: true } }));
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('should return true for arrays', () => {
|
|
15
|
-
assert.isTrue(isNonNullObject([]));
|
|
16
|
-
|
|
17
|
-
assert.isTrue(isNonNullObject([1, 2, 3]));
|
|
18
|
-
|
|
19
|
-
assert.isTrue(isNonNullObject(['a', 'b', 'c']));
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('should return true for functions', () => {
|
|
23
|
-
assert.isFalse(isNonNullObject(() => {}));
|
|
24
|
-
|
|
25
|
-
assert.isFalse(isNonNullObject(async () => {}));
|
|
26
|
-
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
28
|
-
assert.isFalse(isNonNullObject(class MyClass {}));
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('should return true for built-in objects', () => {
|
|
32
|
-
assert.isTrue(isNonNullObject(new Date()));
|
|
33
|
-
|
|
34
|
-
assert.isTrue(isNonNullObject(/test/u));
|
|
35
|
-
|
|
36
|
-
assert.isTrue(isNonNullObject(/regex/u));
|
|
37
|
-
|
|
38
|
-
assert.isTrue(isNonNullObject(new Map()));
|
|
39
|
-
|
|
40
|
-
assert.isTrue(isNonNullObject(new Set()));
|
|
41
|
-
|
|
42
|
-
assert.isTrue(isNonNullObject(new Error('test')));
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('should return true for boxed primitives', () => {
|
|
46
|
-
// eslint-disable-next-line unicorn/new-for-builtins, @typescript-eslint/no-deprecated
|
|
47
|
-
assert.isTrue(isNonNullObject(new String('hello')));
|
|
48
|
-
|
|
49
|
-
// eslint-disable-next-line unicorn/new-for-builtins, @typescript-eslint/no-deprecated
|
|
50
|
-
assert.isTrue(isNonNullObject(new Number(42)));
|
|
51
|
-
|
|
52
|
-
// eslint-disable-next-line unicorn/new-for-builtins, @typescript-eslint/no-deprecated
|
|
53
|
-
assert.isTrue(isNonNullObject(new Boolean(true)));
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('should return false for null', () => {
|
|
57
|
-
assert.isFalse(isNonNullObject(null));
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('should return false for primitive values', () => {
|
|
61
|
-
assert.isFalse(isNonNullObject(undefined));
|
|
62
|
-
|
|
63
|
-
assert.isFalse(isNonNullObject('string'));
|
|
64
|
-
|
|
65
|
-
assert.isFalse(isNonNullObject(42));
|
|
66
|
-
|
|
67
|
-
assert.isFalse(isNonNullObject(true));
|
|
68
|
-
|
|
69
|
-
assert.isFalse(isNonNullObject(false));
|
|
70
|
-
|
|
71
|
-
assert.isFalse(isNonNullObject(Symbol('test')));
|
|
72
|
-
|
|
73
|
-
assert.isFalse(isNonNullObject(123n));
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('should act as a type guard', () => {
|
|
77
|
-
const value: unknown = { test: true } as const;
|
|
78
|
-
|
|
79
|
-
if (isNonNullObject(value)) {
|
|
80
|
-
expectType<typeof value, object>('=');
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('should narrow nullable object types', () => {
|
|
85
|
-
const nullable: UnknownRecord | null =
|
|
86
|
-
Math.random() > 0.5 ? ({} as const) : null;
|
|
87
|
-
|
|
88
|
-
if (isNonNullObject(nullable)) {
|
|
89
|
-
expectType<typeof nullable, UnknownRecord>('=');
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test('should work in filter operations', () => {
|
|
94
|
-
const mixed: readonly unknown[] = [
|
|
95
|
-
'string',
|
|
96
|
-
42,
|
|
97
|
-
{ a: 1 },
|
|
98
|
-
null,
|
|
99
|
-
undefined,
|
|
100
|
-
[],
|
|
101
|
-
() => {},
|
|
102
|
-
true,
|
|
103
|
-
] as const;
|
|
104
|
-
|
|
105
|
-
const objects = mixed.filter(isNonNullObject);
|
|
106
|
-
|
|
107
|
-
assert.deepStrictEqual(objects, [{ a: 1 }, []]);
|
|
108
|
-
});
|
|
109
|
-
});
|