ts-data-forge 14.6.3 → 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/array/impl/array-utils-modification.mjs +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +2 -2
- 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 +6 -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/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,195 +0,0 @@
|
|
|
1
|
-
import { type ReadonlyRecord, type UnknownRecord } from 'ts-type-forge';
|
|
2
|
-
import { expectType } from '../expect-type.mjs';
|
|
3
|
-
import { hasKey } from './has-key.mjs';
|
|
4
|
-
import { isRecord } from './is-record.mjs';
|
|
5
|
-
|
|
6
|
-
describe(isRecord, () => {
|
|
7
|
-
describe('plain objects are records', () => {
|
|
8
|
-
test('{ x: 1 } is a record', () => {
|
|
9
|
-
const unk: unknown = { x: 1 } as const;
|
|
10
|
-
|
|
11
|
-
if (isRecord(unk)) {
|
|
12
|
-
expectType<typeof unk, UnknownRecord>('=');
|
|
13
|
-
} else {
|
|
14
|
-
assert.fail();
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('{} is a record', () => {
|
|
19
|
-
const unk: unknown = {} as const;
|
|
20
|
-
|
|
21
|
-
assert.isTrue(isRecord(unk));
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('Object.create(null) is a record', () => {
|
|
25
|
-
const unk: unknown = Object.create(null);
|
|
26
|
-
|
|
27
|
-
assert.isTrue(isRecord(unk));
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('arrays are not records', () => {
|
|
32
|
-
test('type-level: arrays are not assignable to UnknownRecord', () => {
|
|
33
|
-
// Arrays have a number index signature but no string index signature,
|
|
34
|
-
// so they are assignable to `ReadonlyRecord<number, unknown>` but not to
|
|
35
|
-
// `UnknownRecord` (= `ReadonlyRecord<string, unknown>`).
|
|
36
|
-
expectType<readonly number[], ReadonlyRecord<number, unknown>>('<=');
|
|
37
|
-
|
|
38
|
-
expectType<readonly number[], UnknownRecord>('!<=');
|
|
39
|
-
|
|
40
|
-
expectType<readonly string[], ReadonlyRecord<number, unknown>>('<=');
|
|
41
|
-
|
|
42
|
-
expectType<readonly string[], UnknownRecord>('!<=');
|
|
43
|
-
|
|
44
|
-
expectType<readonly [], UnknownRecord>('!<=');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('[1, 2, 3] is not a record', () => {
|
|
48
|
-
const unk: unknown = [1, 2, 3] as const;
|
|
49
|
-
|
|
50
|
-
assert.isFalse(isRecord(unk));
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('["1", "2", "3"] is not a record', () => {
|
|
54
|
-
const unk: unknown = ['1', '2', '3'] as const;
|
|
55
|
-
|
|
56
|
-
assert.isFalse(isRecord(unk));
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('[] is not a record', () => {
|
|
60
|
-
const unk: unknown = [] as const;
|
|
61
|
-
|
|
62
|
-
assert.isFalse(isRecord(unk));
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('other non-null objects are records', () => {
|
|
67
|
-
// These are not statically assignable to `UnknownRecord` either, but the
|
|
68
|
-
// guard intentionally admits them: every property read through
|
|
69
|
-
// `UnknownRecord` is typed `unknown`, so the narrowing is type-safe, and
|
|
70
|
-
// it keeps `isRecord(u) && hasKey(u, k)` usable for probing instances
|
|
71
|
-
// such as caught `Error` objects.
|
|
72
|
-
test('Date is a record', () => {
|
|
73
|
-
expectType<Date, UnknownRecord>('!<=');
|
|
74
|
-
|
|
75
|
-
const unk: unknown = new Date('2020-01-01');
|
|
76
|
-
|
|
77
|
-
assert.isTrue(isRecord(unk));
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('RegExp is a record', () => {
|
|
81
|
-
const unk: unknown = /test/u;
|
|
82
|
-
|
|
83
|
-
assert.isTrue(isRecord(unk));
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('Map is a record (but its entries are not own properties)', () => {
|
|
87
|
-
expectType<ReadonlyMap<string, number>, UnknownRecord>('!<=');
|
|
88
|
-
|
|
89
|
-
const unk: unknown = new Map([['a', 1]]);
|
|
90
|
-
|
|
91
|
-
if (isRecord(unk)) {
|
|
92
|
-
// Map entries are not own properties, so hasKey correctly rejects them.
|
|
93
|
-
assert.isFalse(hasKey(unk, 'a'));
|
|
94
|
-
} else {
|
|
95
|
-
assert.fail();
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('Set is a record', () => {
|
|
100
|
-
expectType<ReadonlySet<number>, UnknownRecord>('!<=');
|
|
101
|
-
|
|
102
|
-
const unk: unknown = new Set([1, 2, 3]);
|
|
103
|
-
|
|
104
|
-
assert.isTrue(isRecord(unk));
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test('Error is a record and its own properties can be probed', () => {
|
|
108
|
-
const unk: unknown = Object.assign(new Error('failure'), {
|
|
109
|
-
code: 'ENOENT',
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
if (isRecord(unk) && hasKey(unk, 'code')) {
|
|
113
|
-
expectType<(typeof unk)['code'], unknown>('=');
|
|
114
|
-
|
|
115
|
-
assert.strictEqual(unk.code, 'ENOENT');
|
|
116
|
-
} else {
|
|
117
|
-
assert.fail();
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test('class instance is a record', () => {
|
|
122
|
-
class Foo {
|
|
123
|
-
readonly x = 1;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const unk: unknown = new Foo();
|
|
127
|
-
|
|
128
|
-
assert.isTrue(isRecord(unk));
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('functions are not records', () => {
|
|
133
|
-
test('arrow function is not a record', () => {
|
|
134
|
-
const unk: unknown = () => 0;
|
|
135
|
-
|
|
136
|
-
assert.isFalse(isRecord(unk));
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
describe('primitives are not records', () => {
|
|
141
|
-
test('null is not a record', () => {
|
|
142
|
-
const unk: unknown = null;
|
|
143
|
-
|
|
144
|
-
assert.isFalse(isRecord(unk));
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test('undefined is not a record', () => {
|
|
148
|
-
const unk: unknown = undefined;
|
|
149
|
-
|
|
150
|
-
assert.isFalse(isRecord(unk));
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
test('3 is not a record', () => {
|
|
154
|
-
const unk: unknown = 3;
|
|
155
|
-
|
|
156
|
-
assert.isFalse(isRecord(unk));
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
test('"str" is not a record', () => {
|
|
160
|
-
const unk: unknown = 'str';
|
|
161
|
-
|
|
162
|
-
assert.isFalse(isRecord(unk));
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test('true is not a record', () => {
|
|
166
|
-
const unk: unknown = true;
|
|
167
|
-
|
|
168
|
-
assert.isFalse(isRecord(unk));
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
test('symbol is not a record', () => {
|
|
172
|
-
const unk: unknown = Symbol('sym');
|
|
173
|
-
|
|
174
|
-
assert.isFalse(isRecord(unk));
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
test('bigint is not a record', () => {
|
|
178
|
-
const unk: unknown = 1n;
|
|
179
|
-
|
|
180
|
-
assert.isFalse(isRecord(unk));
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
test('combined with hasKey', () => {
|
|
185
|
-
const unk: unknown = { 'some-key': 42 } as const;
|
|
186
|
-
|
|
187
|
-
if (isRecord(unk) && hasKey(unk, 'some-key')) {
|
|
188
|
-
expectType<(typeof unk)['some-key'], unknown>('=');
|
|
189
|
-
|
|
190
|
-
assert.strictEqual(unk['some-key'], 42);
|
|
191
|
-
} else {
|
|
192
|
-
assert.fail();
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type ReadonlyRecord } from 'ts-type-forge';
|
|
2
|
-
import { keyIsIn } from './key-is-in.mjs';
|
|
3
|
-
|
|
4
|
-
const f = <Key extends string, V, KeySub extends Key>(
|
|
5
|
-
key: Key,
|
|
6
|
-
obj: ReadonlyRecord<KeySub, V>,
|
|
7
|
-
): V | undefined => (keyIsIn(key, obj) ? obj[key] : undefined);
|
|
8
|
-
|
|
9
|
-
describe(keyIsIn, () => {
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
11
|
-
f('a' as 'a' | 'b' | 'c', { a: 0, b: 1 });
|
|
12
|
-
|
|
13
|
-
test('', () => {
|
|
14
|
-
assert.isTrue(
|
|
15
|
-
keyIsIn('a', {
|
|
16
|
-
a: 0,
|
|
17
|
-
b: 1,
|
|
18
|
-
}),
|
|
19
|
-
);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
import dedent from 'dedent';
|
|
2
|
-
import { unknownToString } from './unknown-to-string.mjs';
|
|
3
|
-
|
|
4
|
-
describe(unknownToString, () => {
|
|
5
|
-
test('string', () => {
|
|
6
|
-
const value = 'aaaaa';
|
|
7
|
-
|
|
8
|
-
expect(unknownToString(value)).toBe('aaaaa');
|
|
9
|
-
|
|
10
|
-
expect(JSON.stringify(value)).toBe('"aaaaa"');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test('number', () => {
|
|
14
|
-
expect(unknownToString(1)).toBe('1');
|
|
15
|
-
|
|
16
|
-
expect(JSON.stringify(1)).toBe('1');
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('BigInt value', () => {
|
|
20
|
-
const value = 123n;
|
|
21
|
-
|
|
22
|
-
expect(unknownToString(value)).toBe('123n');
|
|
23
|
-
|
|
24
|
-
expect(() => JSON.stringify(value)).toThrow(
|
|
25
|
-
'Do not know how to serialize a BigInt',
|
|
26
|
-
);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('boolean', () => {
|
|
30
|
-
expect(unknownToString(true)).toBe('true');
|
|
31
|
-
|
|
32
|
-
expect(JSON.stringify(true)).toBe('true');
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('undefined', () => {
|
|
36
|
-
expect(unknownToString(undefined)).toBe('undefined');
|
|
37
|
-
|
|
38
|
-
expect(JSON.stringify(undefined)).toBeUndefined();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('null', () => {
|
|
42
|
-
expect(unknownToString(null)).toBe('null');
|
|
43
|
-
|
|
44
|
-
expect(JSON.stringify(null)).toBe('null');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('symbol', () => {
|
|
48
|
-
const value = Symbol('sym');
|
|
49
|
-
|
|
50
|
-
expect(unknownToString(value)).toBe('Symbol(sym)');
|
|
51
|
-
|
|
52
|
-
expect(JSON.stringify(value)).toBeUndefined();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('function', () => {
|
|
56
|
-
test('() => 0', () => {
|
|
57
|
-
const fn = (): number => 0;
|
|
58
|
-
|
|
59
|
-
expect(unknownToString(fn)).toBe('() => 0');
|
|
60
|
-
|
|
61
|
-
expect(JSON.stringify(fn)).toBeUndefined();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('(args) => ({ ret: args })', () => {
|
|
65
|
-
const fn = (args: unknown): unknown => ({ ret: args }) as const;
|
|
66
|
-
|
|
67
|
-
expect(unknownToString(fn)).toBe('(args) => ({ ret: args })');
|
|
68
|
-
|
|
69
|
-
expect(JSON.stringify(fn)).toBeUndefined();
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('object', () => {
|
|
74
|
-
test('object', () => {
|
|
75
|
-
const obj = { a: { b: 1 } } as const;
|
|
76
|
-
|
|
77
|
-
expect(unknownToString(obj)).toBe('{"a":{"b":1}}');
|
|
78
|
-
|
|
79
|
-
expect(JSON.stringify(obj)).toBe('{"a":{"b":1}}');
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('object(prettyPrint=true)', () => {
|
|
83
|
-
const obj = { a: { b: 1 } } as const;
|
|
84
|
-
|
|
85
|
-
expect(unknownToString(obj, { prettyPrintObject: true })).toBe(
|
|
86
|
-
dedent`
|
|
87
|
-
{
|
|
88
|
-
"a": {
|
|
89
|
-
"b": 1
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
`,
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('array', () => {
|
|
97
|
-
test('array of primitives', () => {
|
|
98
|
-
const arr = [1, 2, 3, 'test', true] as const;
|
|
99
|
-
|
|
100
|
-
expect(unknownToString(arr)).toBe('[1,2,3,"test",true]');
|
|
101
|
-
|
|
102
|
-
expect(JSON.stringify(arr)).toBe('[1,2,3,"test",true]');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('array of objects', () => {
|
|
106
|
-
const arr = [{ a: 1 }, { b: 2 }] as const;
|
|
107
|
-
|
|
108
|
-
expect(unknownToString(arr)).toBe('[{"a":1},{"b":2}]');
|
|
109
|
-
|
|
110
|
-
expect(JSON.stringify(arr)).toBe('[{"a":1},{"b":2}]');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test('empty array', () => {
|
|
114
|
-
expect(unknownToString([])).toBe('[]');
|
|
115
|
-
|
|
116
|
-
expect(JSON.stringify([])).toBe('[]');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('nested array', () => {
|
|
120
|
-
const nestedArray = [
|
|
121
|
-
[1, 2],
|
|
122
|
-
[3, 4],
|
|
123
|
-
] as const;
|
|
124
|
-
|
|
125
|
-
expect(unknownToString(nestedArray)).toBe('[[1,2],[3,4]]');
|
|
126
|
-
|
|
127
|
-
expect(JSON.stringify(nestedArray)).toBe('[[1,2],[3,4]]');
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test('array with prettyPrint', () => {
|
|
131
|
-
const arr = [1, { a: 2 }, 3] as const;
|
|
132
|
-
|
|
133
|
-
expect(
|
|
134
|
-
unknownToString(arr, {
|
|
135
|
-
prettyPrintObject: true,
|
|
136
|
-
}),
|
|
137
|
-
).toBe(
|
|
138
|
-
dedent`
|
|
139
|
-
[
|
|
140
|
-
1,
|
|
141
|
-
{
|
|
142
|
-
"a": 2
|
|
143
|
-
},
|
|
144
|
-
3
|
|
145
|
-
]
|
|
146
|
-
`,
|
|
147
|
-
);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('special objects', () => {
|
|
152
|
-
test('Date object returns ISO string', () => {
|
|
153
|
-
const date = new Date('2024-01-15T10:30:00.000Z');
|
|
154
|
-
|
|
155
|
-
expect(unknownToString(date)).toBe('2024-01-15T10:30:00.000Z');
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test('RegExp returns regex literal', () => {
|
|
159
|
-
const regex = /test/giu;
|
|
160
|
-
|
|
161
|
-
expect(unknownToString(regex)).toBe('/test/giu');
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
test('RegExp without flags', () => {
|
|
165
|
-
// eslint-disable-next-line require-unicode-regexp
|
|
166
|
-
const regex = /hello/;
|
|
167
|
-
|
|
168
|
-
expect(unknownToString(regex)).toBe('/hello/');
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
test('Map with entries', () => {
|
|
172
|
-
const map = new Map<number | string, boolean | number | string>([
|
|
173
|
-
['key1', 'value1'],
|
|
174
|
-
['key2', 42],
|
|
175
|
-
[3, true],
|
|
176
|
-
]);
|
|
177
|
-
|
|
178
|
-
expect(unknownToString(map)).toBe(
|
|
179
|
-
'Map([["key1","value1"],["key2",42],[3,true]])',
|
|
180
|
-
);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
test('empty Map', () => {
|
|
184
|
-
const map = new Map();
|
|
185
|
-
|
|
186
|
-
expect(unknownToString(map)).toBe('Map([])');
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test('Map with prettyPrint', () => {
|
|
190
|
-
const map = new Map([
|
|
191
|
-
['a', 1],
|
|
192
|
-
['b', 2],
|
|
193
|
-
]);
|
|
194
|
-
|
|
195
|
-
expect(unknownToString(map, { prettyPrintObject: true })).toBe(
|
|
196
|
-
dedent`
|
|
197
|
-
Map([
|
|
198
|
-
[
|
|
199
|
-
"a",
|
|
200
|
-
1
|
|
201
|
-
],
|
|
202
|
-
[
|
|
203
|
-
"b",
|
|
204
|
-
2
|
|
205
|
-
]
|
|
206
|
-
])
|
|
207
|
-
`,
|
|
208
|
-
);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
test('Set with values', () => {
|
|
212
|
-
const set = new Set([1, 2, 3, 'test', true]);
|
|
213
|
-
|
|
214
|
-
expect(unknownToString(set)).toBe('Set([1,2,3,"test",true])');
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
test('empty Set', () => {
|
|
218
|
-
const set = new Set();
|
|
219
|
-
|
|
220
|
-
expect(unknownToString(set)).toBe('Set([])');
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
test('Set with prettyPrint', () => {
|
|
224
|
-
const set = new Set([1, { a: 2 }, 3]);
|
|
225
|
-
|
|
226
|
-
expect(unknownToString(set, { prettyPrintObject: true })).toBe(
|
|
227
|
-
dedent`
|
|
228
|
-
Set([
|
|
229
|
-
1,
|
|
230
|
-
{
|
|
231
|
-
"a": 2
|
|
232
|
-
},
|
|
233
|
-
3
|
|
234
|
-
])
|
|
235
|
-
`,
|
|
236
|
-
);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
test('nested Map and Set', () => {
|
|
240
|
-
const map = new Map([['set', new Set([1, 2])]]);
|
|
241
|
-
|
|
242
|
-
const result = unknownToString(map);
|
|
243
|
-
|
|
244
|
-
// Set is converted to object notation in JSON.stringify
|
|
245
|
-
expect(result).toMatch(/Map\(\[\["set",/u);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
test('Error object returns message', () => {
|
|
249
|
-
const err = new Error('Something went wrong');
|
|
250
|
-
|
|
251
|
-
expect(unknownToString(err)).toBe('Something went wrong');
|
|
252
|
-
|
|
253
|
-
expect(JSON.stringify(err)).toBe('{}');
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
test('Error object with empty message', () => {
|
|
257
|
-
// eslint-disable-next-line unicorn/error-message
|
|
258
|
-
const err = new Error('');
|
|
259
|
-
|
|
260
|
-
expect(unknownToString(err)).toBe('');
|
|
261
|
-
|
|
262
|
-
expect(JSON.stringify(err)).toBe('{}');
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
test('TypeError object with empty message', () => {
|
|
266
|
-
// eslint-disable-next-line unicorn/error-message
|
|
267
|
-
const err = new TypeError('');
|
|
268
|
-
|
|
269
|
-
expect(unknownToString(err)).toBe('');
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
test('circular reference returns error message', () => {
|
|
275
|
-
const mut_circular: { a: number; self?: unknown } = { a: 1 };
|
|
276
|
-
|
|
277
|
-
mut_circular.self = mut_circular;
|
|
278
|
-
|
|
279
|
-
// Should return an error message string instead of throwing
|
|
280
|
-
expectTypeOf(unknownToString(mut_circular)).toBeString();
|
|
281
|
-
|
|
282
|
-
expect(unknownToString(mut_circular)).toMatch(/circular|serialize/iu);
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
test('non-Error thrown during serialization returns fallback text', () => {
|
|
286
|
-
const value = {
|
|
287
|
-
toJSON: () => {
|
|
288
|
-
// eslint-disable-next-line @typescript-eslint/only-throw-error
|
|
289
|
-
throw 'custom failure';
|
|
290
|
-
},
|
|
291
|
-
} as const;
|
|
292
|
-
|
|
293
|
-
expect(unknownToString(value)).toBe('[Circular or Non-serializable]');
|
|
294
|
-
});
|
|
295
|
-
});
|