ts-data-forge 14.6.4 → 14.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -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/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 +5 -5
- 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/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
package/src/guard/has-key.mts
CHANGED
|
@@ -1,72 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Type guard function that checks if an object has a specific key as its own
|
|
5
|
-
* property.
|
|
6
|
-
*
|
|
7
|
-
* This function uses `Object.hasOwn()` to check if the given object has the
|
|
8
|
-
* specified key as its own property (not inherited). It acts as a type guard
|
|
9
|
-
* that narrows the type of the object to guarantee the key exists, enabling
|
|
10
|
-
* type-safe property access.
|
|
11
|
-
*
|
|
12
|
-
* **Type Narrowing Behavior:**
|
|
13
|
-
*
|
|
14
|
-
* - When the guard returns `true`, TypeScript narrows the object type to include
|
|
15
|
-
* the checked key
|
|
16
|
-
* - For union types, only union members that contain the key are preserved
|
|
17
|
-
* - The key's value type is preserved from the original object type when possible
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
*
|
|
21
|
-
* ```ts
|
|
22
|
-
* const maybeUser: Readonly<{ id?: number; name?: string }> = {
|
|
23
|
-
* id: 42,
|
|
24
|
-
* } as const;
|
|
25
|
-
*
|
|
26
|
-
* if (hasKey(maybeUser, 'id')) {
|
|
27
|
-
* // `maybeUser` is now known to have an `id` property.
|
|
28
|
-
* assert.isTrue(maybeUser.id === 42);
|
|
29
|
-
* } else {
|
|
30
|
-
* assert.fail();
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @template R - The type of the input object, must extend UnknownRecord
|
|
35
|
-
* @template K - The type of the key to check for, must extend PropertyKey
|
|
36
|
-
* (string | number | symbol)
|
|
37
|
-
* @param obj - The object to check for the presence of the key
|
|
38
|
-
* @param key - The key to check for in the object
|
|
39
|
-
* @returns `true` if the object has the specified key as its own property,
|
|
40
|
-
* `false` otherwise. When `true`, TypeScript narrows the object type to
|
|
41
|
-
* guarantee the key exists.
|
|
42
|
-
* @see {@link keyIsIn} - Similar function that narrows the key type instead of the object type
|
|
43
|
-
*/
|
|
44
|
-
export const hasKey = <
|
|
45
|
-
const R extends UnknownRecord,
|
|
46
|
-
const K extends PropertyKey,
|
|
47
|
-
>(
|
|
48
|
-
obj: R,
|
|
49
|
-
key: K,
|
|
50
|
-
): obj is HasKeyReturnType<R, K> => Object.hasOwn(obj, key);
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @internal
|
|
54
|
-
* When R is a union type (including the case with only one element), if any element in the union
|
|
55
|
-
* contains K as a key, returns a type that narrows the union to only those elements that contain K as a key.
|
|
56
|
-
* If none of the elements in the union contain K as a key, returns `ReadonlyRecord<K, unknown>`.
|
|
57
|
-
* The result is made readonly.
|
|
58
|
-
*/
|
|
59
|
-
export type HasKeyReturnType<
|
|
60
|
-
R extends UnknownRecord,
|
|
61
|
-
K extends PropertyKey,
|
|
62
|
-
> = R extends R // union distribution
|
|
63
|
-
? K extends keyof R
|
|
64
|
-
? string extends keyof R
|
|
65
|
-
? ReadonlyRecord<K, R[keyof R]> & R
|
|
66
|
-
: number extends keyof R
|
|
67
|
-
? ReadonlyRecord<K, R[keyof R]> & R
|
|
68
|
-
: symbol extends keyof R
|
|
69
|
-
? ReadonlyRecord<K, R[keyof R]> & R
|
|
70
|
-
: R
|
|
71
|
-
: never // omit union member that does not have key K
|
|
72
|
-
: never; // dummy case for union distribution
|
|
1
|
+
/** Implemented in ts-std-forge since Sumi D-49; re-exported here. */
|
|
2
|
+
export { hasKey, type HasKeyReturnType } from 'ts-std-forge';
|
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* This function checks if a value has type `"object"` according to the `typeof`
|
|
5
|
-
* operator and is not `null`. This includes all object types such as plain
|
|
6
|
-
* objects, arrays, dates, regular expressions, and other object instances, but
|
|
7
|
-
* excludes functions.
|
|
8
|
-
*
|
|
9
|
-
* **Type Narrowing Behavior:**
|
|
10
|
-
*
|
|
11
|
-
* - Narrows `unknown` to `object`
|
|
12
|
-
* - Excludes `null`, `undefined`, and all primitive types
|
|
13
|
-
* - Excludes functions (they have `typeof` === `"function"`, not `"object"`)
|
|
14
|
-
* - Includes arrays, dates, regex, and other object instances
|
|
15
|
-
*
|
|
16
|
-
* **Note:** This function returns `true` for arrays. If you need
|
|
17
|
-
* record-oriented narrowing that excludes arrays, use `isRecord()` instead.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
*
|
|
21
|
-
* ```ts
|
|
22
|
-
* const mixed: readonly unknown[] = [{ id: 1 }, null, 'Ada'] as const;
|
|
23
|
-
*
|
|
24
|
-
* const objects = mixed.filter(isNonNullObject);
|
|
25
|
-
*
|
|
26
|
-
* assert.deepStrictEqual(objects, [{ id: 1 }]);
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @param u - The value to check
|
|
30
|
-
* @returns `true` if `u` is an object and not `null`, `false` otherwise. When
|
|
31
|
-
* `true`, TypeScript narrows the type to `object`.
|
|
32
|
-
* @see {@link isRecord} - For record-oriented type narrowing (excludes arrays)
|
|
33
|
-
*/
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-restricted-types
|
|
35
|
-
export const isNonNullObject = (u: unknown): u is object =>
|
|
36
|
-
typeof u === 'object' && u !== null;
|
|
1
|
+
/** Implemented in ts-std-forge since Sumi D-49; re-exported here. */
|
|
2
|
+
export { isNonNullObject } from 'ts-std-forge';
|
package/src/guard/is-record.mts
CHANGED
|
@@ -1,95 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Type guard that checks if a value is a record — a non-null, non-array
|
|
6
|
-
* object — and narrows it to `UnknownRecord` (= `ReadonlyRecord<string,
|
|
7
|
-
* unknown>`).
|
|
8
|
-
*
|
|
9
|
-
* This function is designed to be combined with {@link hasKey} to probe
|
|
10
|
-
* values of type `unknown` (e.g. parsed JSON, caught errors, external data)
|
|
11
|
-
* in a type-safe way: `if (isRecord(u) && hasKey(u, 'some-key')) { ... }`.
|
|
12
|
-
*
|
|
13
|
-
* **Type Narrowing Behavior:**
|
|
14
|
-
*
|
|
15
|
-
* - Narrows `unknown` to `UnknownRecord` (= `ReadonlyRecord<string, unknown>`)
|
|
16
|
-
* - Excludes `null`, `undefined`, primitives, and functions
|
|
17
|
-
* - Excludes arrays: arrays have no string index signature, so they are not
|
|
18
|
-
* assignable to `UnknownRecord`; admitting them at runtime would be
|
|
19
|
-
* inconsistent with the narrowed type
|
|
20
|
-
* - Returns `true` for every other non-null object, including dictionary
|
|
21
|
-
* objects created with `Object.create(null)` and instances such as `Date`,
|
|
22
|
-
* `RegExp`, `Map`, `Set`, `Error`, and user-defined classes
|
|
23
|
-
*
|
|
24
|
-
* **Why non-plain objects are included:** since every property of
|
|
25
|
-
* `UnknownRecord` is typed `unknown`, reading properties from any object
|
|
26
|
-
* through this narrowing is type-safe, and `hasKey` (backed by
|
|
27
|
-
* `Object.hasOwn`) answers own-property questions correctly on any object
|
|
28
|
-
* (e.g. `Map` entries are not own properties, so `hasKey` correctly returns
|
|
29
|
-
* `false` for them). Restricting the guard to plain objects would require
|
|
30
|
-
* prototype checks that misjudge cross-realm objects and would prevent
|
|
31
|
-
* probing useful instances such as `Error` subclasses.
|
|
32
|
-
*
|
|
33
|
-
* **Implementation:** `isNonNullObject(u) && !Array.isArray(u)`.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
*
|
|
37
|
-
* ```ts
|
|
38
|
-
* const entries: readonly unknown[] = [
|
|
39
|
-
* { id: 1 },
|
|
40
|
-
* [1, 2],
|
|
41
|
-
* 'str',
|
|
42
|
-
* 0,
|
|
43
|
-
* null,
|
|
44
|
-
* ] as const;
|
|
45
|
-
*
|
|
46
|
-
* const records = entries.filter(isRecord);
|
|
47
|
-
*
|
|
48
|
-
* assert.deepStrictEqual(records, [{ id: 1 }]);
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* @param u - The value to check
|
|
52
|
-
* @returns `true` if `u` is a non-null, non-array object, `false` otherwise.
|
|
53
|
-
* When `true`, TypeScript narrows the type to `UnknownRecord`.
|
|
54
|
-
* @see {@link isNonNullObject} - For checking any non-null object (includes arrays)
|
|
55
|
-
* @see {@link hasKey} - For checking if a record has specific keys
|
|
56
|
-
*/
|
|
57
|
-
export const isRecord = (u: unknown): u is UnknownRecord =>
|
|
58
|
-
isNonNullObject(u) && !Array.isArray(u);
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Type guard that checks if a value is a mutable record.
|
|
62
|
-
*
|
|
63
|
-
* This function has the same runtime behavior as {@link isRecord} (non-null,
|
|
64
|
-
* non-array object check), but narrows the type to `MutableRecord<string,
|
|
65
|
-
* unknown>`, which is useful when you need to add or overwrite properties on
|
|
66
|
-
* the narrowed object.
|
|
67
|
-
*
|
|
68
|
-
* **Type Narrowing Behavior:**
|
|
69
|
-
*
|
|
70
|
-
* - Narrows `unknown` to `MutableRecord<string, unknown>`
|
|
71
|
-
* - Excludes `null`, `undefined`, primitives, functions, and arrays
|
|
72
|
-
* - Returns `true` for every other non-null object (see {@link isRecord} for
|
|
73
|
-
* details on non-plain objects such as `Date`, `Map`, and `Set`)
|
|
74
|
-
*
|
|
75
|
-
* **Implementation:** This is a type alias for {@link isRecord}.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
*
|
|
79
|
-
* ```ts
|
|
80
|
-
* const obj: unknown = { foo: 1 } as const;
|
|
81
|
-
*
|
|
82
|
-
* if (isMutableRecord(obj)) {
|
|
83
|
-
* obj['bar'] = 2; // Safe: obj is now known to be a mutable record
|
|
84
|
-
* }
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* @param u - The value to check
|
|
88
|
-
* @returns `true` if `u` is a non-null, non-array object, `false` otherwise.
|
|
89
|
-
* When `true`, TypeScript narrows the type to `MutableRecord<string,
|
|
90
|
-
* unknown>`.
|
|
91
|
-
* @see {@link isRecord} - For the underlying implementation and more details
|
|
92
|
-
*/
|
|
93
|
-
export const isMutableRecord: (
|
|
94
|
-
u: unknown,
|
|
95
|
-
) => u is MutableRecord<string, unknown> = isRecord;
|
|
1
|
+
/** Implemented in ts-std-forge since Sumi D-49; re-exported here. */
|
|
2
|
+
export { isMutableRecord, isRecord } from 'ts-std-forge';
|
package/src/guard/key-is-in.mts
CHANGED
|
@@ -1,49 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Type guard that checks if a key exists as an own property in an object.
|
|
5
|
-
*
|
|
6
|
-
* This function is similar to `hasKey()` but with reversed parameter order and
|
|
7
|
-
* different type narrowing behavior. While `hasKey()` narrows the object type,
|
|
8
|
-
* `keyIsIn()` narrows the key type to be a valid key of the given object.
|
|
9
|
-
*
|
|
10
|
-
* **Type Narrowing Behavior:**
|
|
11
|
-
*
|
|
12
|
-
* - Narrows the key type to be a key that exists in the object (`K & keyof R`)
|
|
13
|
-
* - Useful when you have a dynamic key and want to ensure it's valid for a
|
|
14
|
-
* specific object
|
|
15
|
-
* - The object type remains unchanged
|
|
16
|
-
*
|
|
17
|
-
* **Implementation:** Uses `Object.hasOwn()` to check for own properties (not
|
|
18
|
-
* inherited).
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
*
|
|
22
|
-
* ```ts
|
|
23
|
-
* const user = { id: 1, name: 'Ada' } as const;
|
|
24
|
-
*
|
|
25
|
-
* const maybeKey: string = 'name';
|
|
26
|
-
*
|
|
27
|
-
* if (keyIsIn(maybeKey, user)) {
|
|
28
|
-
* assert.isTrue(user[maybeKey] === 'Ada');
|
|
29
|
-
* } else {
|
|
30
|
-
* assert.fail();
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @template K - The type of the key to check, must extend PropertyKey (string |
|
|
35
|
-
* number | symbol)
|
|
36
|
-
* @template R - The type of the record (object), must extend UnknownRecord
|
|
37
|
-
* @param key - The key to check for
|
|
38
|
-
* @param obj - The object to check within
|
|
39
|
-
* @returns `true` if `key` is an own property of `obj`, `false` otherwise. When
|
|
40
|
-
* `true`, TypeScript narrows the key type to be a valid key of the object.
|
|
41
|
-
* @see {@link hasKey} - Similar function that narrows the object type instead of the key type
|
|
42
|
-
*/
|
|
43
|
-
export const keyIsIn = <
|
|
44
|
-
const K extends PropertyKey,
|
|
45
|
-
const R extends UnknownRecord,
|
|
46
|
-
>(
|
|
47
|
-
key: K,
|
|
48
|
-
obj: R,
|
|
49
|
-
): key is K & keyof typeof obj => Object.hasOwn(obj, key);
|
|
1
|
+
/** Implemented in ts-std-forge since Sumi D-49; re-exported here. */
|
|
2
|
+
export { keyIsIn } from 'ts-std-forge';
|
package/src/number/num.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SafeNumber } from 'ts-std-forge';
|
|
1
2
|
import {
|
|
2
3
|
type Decrement,
|
|
3
4
|
type FiniteNumber,
|
|
@@ -118,25 +119,34 @@ export namespace Num {
|
|
|
118
119
|
* assert.isTrue(Result.isErr(Num.safeParseInt('')));
|
|
119
120
|
*
|
|
120
121
|
* assert.strictEqual(Result.unwrapOk(Num.safeParseInt(' ')), undefined);
|
|
122
|
+
*
|
|
123
|
+
* // A value that overflows to Infinity is not an integer either, even
|
|
124
|
+
* // though native `parseInt` reads a 1 out of it.
|
|
125
|
+
*
|
|
126
|
+
* assert.strictEqual(Number.parseInt('1e400', 10), 1);
|
|
127
|
+
*
|
|
128
|
+
* assert.isTrue(Result.isErr(Num.safeParseInt('1e400')));
|
|
121
129
|
* ```
|
|
122
130
|
*
|
|
123
131
|
* @param s The string to parse.
|
|
124
132
|
* @returns `Result.ok(parsedInt)` for valid input, otherwise `Result.err`
|
|
125
|
-
* wrapping an `Error` describing the invalid input.
|
|
133
|
+
* wrapping an `Error` describing the invalid input. A value that
|
|
134
|
+
* overflows to `Infinity` is rejected, so the `Int` brand never lies.
|
|
126
135
|
*/
|
|
127
|
-
export const safeParseInt = (s: string): Result<Int, Error> =>
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
export const safeParseInt = (s: string): Result<Int, Error> =>
|
|
137
|
+
// The parsing itself is `SafeNumber.parseInteger` (Sumi D-49 (c)): one
|
|
138
|
+
// implementation, in the package that owns the standard-library
|
|
139
|
+
// boundary. What stays here is this function's own contract — the `Int`
|
|
140
|
+
// brand on the success side, and an `Error` rather than a tagged record
|
|
141
|
+
// on the failure side.
|
|
142
|
+
Result.match(SafeNumber.parseInteger(s), {
|
|
143
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
144
|
+
ok: (n) => Result.ok(n as Int),
|
|
145
|
+
err: () =>
|
|
146
|
+
Result.err(
|
|
135
147
|
new Error(`safeParseInt: "${s}" is not a valid base-10 integer`),
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
Result.ok(Math.trunc(viaNumber) as Int);
|
|
139
|
-
};
|
|
148
|
+
),
|
|
149
|
+
});
|
|
140
150
|
|
|
141
151
|
/**
|
|
142
152
|
* Safely parses a finite floating-point number from a string, returning a
|
|
@@ -201,22 +211,20 @@ export namespace Num {
|
|
|
201
211
|
* @returns `Result.ok(parsedFloat)` for valid finite input, otherwise
|
|
202
212
|
* `Result.err` wrapping an `Error` describing the invalid input.
|
|
203
213
|
*/
|
|
204
|
-
export const safeParseFloat = (s: string): Result<FiniteNumber, Error> =>
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
//
|
|
208
|
-
//
|
|
209
|
-
//
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
214
|
+
export const safeParseFloat = (s: string): Result<FiniteNumber, Error> =>
|
|
215
|
+
// The parsing itself is `SafeNumber.parse` (Sumi D-49 (c)): one
|
|
216
|
+
// implementation, in the package that owns the standard-library
|
|
217
|
+
// boundary. What stays here is this function's own contract — the
|
|
218
|
+
// `FiniteNumber` brand on the success side, and an `Error` rather than a
|
|
219
|
+
// tagged record on the failure side.
|
|
220
|
+
Result.match(SafeNumber.parse(s), {
|
|
221
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
222
|
+
ok: (n) => Result.ok(n as FiniteNumber),
|
|
223
|
+
err: () =>
|
|
224
|
+
Result.err(
|
|
215
225
|
new Error(`safeParseFloat: "${s}" is not a valid finite number`),
|
|
216
|
-
)
|
|
217
|
-
|
|
218
|
-
Result.ok(viaNumber as FiniteNumber);
|
|
219
|
-
};
|
|
226
|
+
),
|
|
227
|
+
});
|
|
220
228
|
|
|
221
229
|
/**
|
|
222
230
|
* Type guard that checks if a number is non-zero.
|
package/src/others/index.mts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The panic error. Implemented in ts-std-forge since Sumi D-49 / D-53; this
|
|
3
|
+
* re-export keeps the names importable from here. The boundary functions of
|
|
4
|
+
* this package recognize a panic through `isPanicError`, which matches on a
|
|
5
|
+
* mark rather than on a constructor, so a panic raised by either package is a
|
|
6
|
+
* panic to both.
|
|
7
|
+
*/
|
|
8
|
+
export { createPanicError, isPanicError, type PanicError } from 'ts-std-forge';
|
|
@@ -1,111 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Converts an unknown value to its string representation in a type-safe manner.
|
|
5
|
-
*
|
|
6
|
-
* This function handles all JavaScript types and provides consistent string
|
|
7
|
-
* conversion with proper error handling for edge cases like circular
|
|
8
|
-
* references. Unlike naive toString() calls, this function never throws and
|
|
9
|
-
* handles all value types gracefully.
|
|
10
|
-
*
|
|
11
|
-
* **Type conversion rules:**
|
|
12
|
-
*
|
|
13
|
-
* - Strings: returned as-is
|
|
14
|
-
* - Numbers, booleans, bigints: converted via toString()
|
|
15
|
-
* - Symbols: converted to their description string
|
|
16
|
-
* - Functions: converted to their string representation
|
|
17
|
-
* - null: returns "null" (not "null" from JSON)
|
|
18
|
-
* - undefined: returns "undefined"
|
|
19
|
-
* - Date: converted to ISO string
|
|
20
|
-
* - RegExp: converted to regex literal string
|
|
21
|
-
* - Map: converted to Map representation with entries
|
|
22
|
-
* - Set: converted to Set representation with values
|
|
23
|
-
* - Error: returns error message
|
|
24
|
-
* - Objects: JSON stringified (with optional pretty printing)
|
|
25
|
-
*
|
|
26
|
-
* @param value - The unknown value to convert to string
|
|
27
|
-
* @param options - Optional configuration for the conversion
|
|
28
|
-
* @param options.prettyPrintObject - If true, objects are formatted with
|
|
29
|
-
* 2-space indentation
|
|
30
|
-
* @returns The string representation of the value. For circular references or
|
|
31
|
-
* non-serializable objects, returns an error message string
|
|
32
|
-
*
|
|
33
|
-
* **Error Handling:** Circular references and non-serializable objects return
|
|
34
|
-
* descriptive error messages instead of throwing
|
|
35
|
-
* @see JSON.stringify - Underlying serialization for objects
|
|
36
|
-
*/
|
|
37
|
-
export const unknownToString = (
|
|
38
|
-
value: unknown,
|
|
39
|
-
options?: Partial<Readonly<{ prettyPrintObject: boolean }>>,
|
|
40
|
-
): string => {
|
|
41
|
-
switch (typeof value) {
|
|
42
|
-
case 'string':
|
|
43
|
-
return value;
|
|
44
|
-
|
|
45
|
-
case 'bigint':
|
|
46
|
-
return `${value.toString()}n`;
|
|
47
|
-
|
|
48
|
-
case 'number':
|
|
49
|
-
case 'boolean':
|
|
50
|
-
case 'symbol':
|
|
51
|
-
case 'function':
|
|
52
|
-
return value.toString();
|
|
53
|
-
|
|
54
|
-
case 'undefined':
|
|
55
|
-
return 'undefined';
|
|
56
|
-
|
|
57
|
-
case 'object': {
|
|
58
|
-
if (value === null) {
|
|
59
|
-
return 'null';
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
// Special handling for Date
|
|
64
|
-
if (isDate(value)) {
|
|
65
|
-
return value.toISOString();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Special handling for RegExp
|
|
69
|
-
if (isRegExp(value)) {
|
|
70
|
-
return value.toString();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (isError(value)) {
|
|
74
|
-
return value.message;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const prettyPrintObject = options?.prettyPrintObject === true;
|
|
78
|
-
|
|
79
|
-
// Special handling for Map
|
|
80
|
-
if (isMap(value)) {
|
|
81
|
-
const entries = Array.from(value);
|
|
82
|
-
|
|
83
|
-
const entriesStr = prettyPrintObject
|
|
84
|
-
? JSON.stringify(entries, undefined, 2)
|
|
85
|
-
: JSON.stringify(entries);
|
|
86
|
-
|
|
87
|
-
return `Map(${entriesStr})`;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Special handling for Set
|
|
91
|
-
if (isSet(value)) {
|
|
92
|
-
const values = Array.from(value);
|
|
93
|
-
|
|
94
|
-
const valuesStr = prettyPrintObject
|
|
95
|
-
? JSON.stringify(values, undefined, 2)
|
|
96
|
-
: JSON.stringify(values);
|
|
97
|
-
|
|
98
|
-
return `Set(${valuesStr})`;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return prettyPrintObject
|
|
102
|
-
? JSON.stringify(value, undefined, 2)
|
|
103
|
-
: JSON.stringify(value);
|
|
104
|
-
} catch (error) {
|
|
105
|
-
return isError(error)
|
|
106
|
-
? error.message
|
|
107
|
-
: '[Circular or Non-serializable]';
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
};
|
|
1
|
+
/** Implemented in ts-std-forge since Sumi D-49; re-exported here. */
|
|
2
|
+
export { unknownToString } from 'ts-std-forge';
|
package/src/types.mts
CHANGED
|
@@ -75,57 +75,7 @@ export namespace SizeType {
|
|
|
75
75
|
>;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
* @template S The type of the contained value.
|
|
83
|
-
*/
|
|
84
|
-
export type Some<S> = Readonly<{
|
|
85
|
-
/** @internal Discriminant property for the 'Some' type. */
|
|
86
|
-
$$tag: 'ts-data-forge::Optional.some';
|
|
87
|
-
|
|
88
|
-
/** The contained value. */
|
|
89
|
-
value: S;
|
|
90
|
-
}>;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Represents the 'None' variant of an Optional, indicating the absence
|
|
94
|
-
* of a value.
|
|
95
|
-
*/
|
|
96
|
-
export type None = Readonly<{
|
|
97
|
-
/** @internal Discriminant property for the 'None' type. */
|
|
98
|
-
$$tag: 'ts-data-forge::Optional.none';
|
|
99
|
-
}>;
|
|
100
|
-
|
|
101
|
-
// #endregion Optional
|
|
102
|
-
|
|
103
|
-
// #region Result
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Represents a `Result` that is a success, containing a value.
|
|
107
|
-
*
|
|
108
|
-
* @template S The type of the success value.
|
|
109
|
-
*/
|
|
110
|
-
export type Ok<S> = Readonly<{
|
|
111
|
-
/** @internal Discriminant property for the 'Ok' type. */
|
|
112
|
-
$$tag: 'ts-data-forge::Result.ok';
|
|
113
|
-
|
|
114
|
-
/** The success value. */
|
|
115
|
-
value: S;
|
|
116
|
-
}>;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Represents a `Result` that is an error, containing an error value.
|
|
120
|
-
*
|
|
121
|
-
* @template E The type of the error value.
|
|
122
|
-
*/
|
|
123
|
-
export type Err<E> = Readonly<{
|
|
124
|
-
/** @internal Discriminant property for the 'Err' type. */
|
|
125
|
-
$$tag: 'ts-data-forge::Result.err';
|
|
126
|
-
|
|
127
|
-
/** The error value. */
|
|
128
|
-
value: E;
|
|
129
|
-
}>;
|
|
130
|
-
|
|
131
|
-
// #endregion Result
|
|
78
|
+
// The four variant shapes of `Optional` and `Result` are implemented in
|
|
79
|
+
// ts-std-forge since Sumi D-49; re-exported here so that `Ok` / `Err` /
|
|
80
|
+
// `Some` / `None` keep denoting the same declarations in both packages.
|
|
81
|
+
export type { Err, None, Ok, Some } from 'ts-std-forge';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type Result } from '../result/index.mjs';
|
|
2
|
-
/**
|
|
3
|
-
* Represents an asynchronous computation that can either succeed (`Ok`) or
|
|
4
|
-
* fail (`Err`) — a `Promise` that resolves to a `Result<S, E>`.
|
|
5
|
-
*
|
|
6
|
-
* Unlike a raw `Promise`, an `AsyncResult` never rejects for expected
|
|
7
|
-
* failures: errors are carried in the `Err` channel with a concrete type `E`,
|
|
8
|
-
* so they can be handled with the same combinators as a synchronous
|
|
9
|
-
* `Result`.
|
|
10
|
-
*
|
|
11
|
-
* @template S The type of the success value.
|
|
12
|
-
* @template E The type of the error value.
|
|
13
|
-
*/
|
|
14
|
-
export type AsyncResult<S, E> = Promise<Result<S, E>>;
|
|
15
|
-
export * as AsyncResult from './impl/index.mjs';
|
|
16
|
-
//# sourceMappingURL=async-result.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-result.d.mts","sourceRoot":"","sources":["../../../src/functional/async-result/async-result.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEtD,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-result.mjs","sourceRoot":"","sources":["../../../src/functional/async-result/async-result.mts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type UnknownResult } from '../../result/index.mjs';
|
|
2
|
-
import { type AsyncResult } from '../async-result.mjs';
|
|
3
|
-
import { type UnknownAsyncResult, type UnwrapErr, type UnwrapOk } from './types.mjs';
|
|
4
|
-
/**
|
|
5
|
-
* Applies a function that returns an `AsyncResult` or a `Result` to the
|
|
6
|
-
* success value of an `AsyncResult`. If the input resolves to `Err`, the
|
|
7
|
-
* original `Err` is passed through and the function is not called. This is
|
|
8
|
-
* the monadic bind operation for `AsyncResult`.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const parseNumber = (input: string): Result<number, string> => {
|
|
14
|
-
* const num = Number.parseInt(input, 10);
|
|
15
|
-
*
|
|
16
|
-
* return Number.isNaN(num) ? Result.err('not a number') : Result.ok(num);
|
|
17
|
-
* };
|
|
18
|
-
*
|
|
19
|
-
* const input = AsyncResult.fromPromise(
|
|
20
|
-
* Promise.resolve('42'),
|
|
21
|
-
* () => 'failed',
|
|
22
|
-
* );
|
|
23
|
-
*
|
|
24
|
-
* const parsed = await AsyncResult.flatMap(input, parseNumber);
|
|
25
|
-
*
|
|
26
|
-
* assert.deepStrictEqual(parsed, Result.ok(42));
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @template S The type of the success value of the input.
|
|
30
|
-
* @template E The type of the error value of the input.
|
|
31
|
-
* @template R2 The `AsyncResult` or `Result` type returned by the function.
|
|
32
|
-
* @param asyncResult The `AsyncResult` to flat map.
|
|
33
|
-
* @param flatMapFn The function to apply that returns an `AsyncResult` or a
|
|
34
|
-
* `Result`.
|
|
35
|
-
* @returns The result of applying the function, or the original `Err`.
|
|
36
|
-
*/
|
|
37
|
-
export declare function flatMap<S, E, R2 extends UnknownAsyncResult | UnknownResult>(asyncResult: AsyncResult<S, E>, flatMapFn: (value: S) => R2): AsyncResult<UnwrapOk<R2>, E | UnwrapErr<R2>>;
|
|
38
|
-
export declare function flatMap<S, R2 extends UnknownAsyncResult | UnknownResult>(flatMapFn: (value: S) => R2): <E>(asyncResult: AsyncResult<S, E>) => AsyncResult<UnwrapOk<R2>, E | UnwrapErr<R2>>;
|
|
39
|
-
//# sourceMappingURL=async-result-flat-map.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-result-flat-map.d.mts","sourceRoot":"","sources":["../../../../src/functional/async-result/impl/async-result-flat-map.mts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACd,KAAK,QAAQ,EACd,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,SAAS,kBAAkB,GAAG,aAAa,EACzE,WAAW,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAC9B,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,GAC1B,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;AAWhD,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,SAAS,kBAAkB,GAAG,aAAa,EACtE,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,GAC1B,CAAC,CAAC,EACH,WAAW,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,KAC3B,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Result } from '../../result/index.mjs';
|
|
2
|
-
export function flatMap(...args) {
|
|
3
|
-
switch (args.length) {
|
|
4
|
-
case 2: {
|
|
5
|
-
|
|
6
|
-
const [asyncResult, flatMapFn] = args;
|
|
7
|
-
return flatMapImpl(asyncResult, flatMapFn);
|
|
8
|
-
}
|
|
9
|
-
case 1: {
|
|
10
|
-
|
|
11
|
-
const [flatMapFn] = args;
|
|
12
|
-
return (asyncResult) => flatMapImpl(asyncResult, flatMapFn);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
const flatMapImpl = async (asyncResult, flatMapFn) => {
|
|
17
|
-
const result = await asyncResult;
|
|
18
|
-
return Result.isErr(result)
|
|
19
|
-
? result
|
|
20
|
-
:
|
|
21
|
-
(await flatMapFn(result.value));
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=async-result-flat-map.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-result-flat-map.mjs","sourceRoot":"","sources":["../../../../src/functional/async-result/impl/async-result-flat-map.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAsB,MAAM,wBAAwB,CAAC;AA6DpE,MAAM,UAAU,OAAO,CACrB,GAAG,IAEuC;IAM1C,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,EAAE,CAAC;YACP,gDAAgD;YAChD,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC;YAEtC,OAAO,WAAW,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAC7C,CAAC;QAED,KAAK,CAAC,EAAE,CAAC;YACP,kBAAkB;YAClB,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;YAEzB,OAAO,CAAC,WAA8B,EAAE,EAAE,CACxC,WAAW,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,WAAW,GAAG,KAAK,EACvB,WAA8B,EAC9B,SAA2B,EACmB,EAAE;IAChD,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC;IAEjC,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;QACzB,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,oEAAoE;YACnE,CAAC,MAAM,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAyC,CAAC;AAC/E,CAAC,CAAC"}
|