ts-data-forge 5.0.1 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -50
- package/dist/array/impl/array-utils-creation.d.mts +14 -0
- package/dist/array/impl/array-utils-creation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-creation.mjs +12 -0
- package/dist/array/impl/array-utils-creation.mjs.map +1 -1
- package/dist/array/impl/array-utils-element-access.d.mts +10 -0
- package/dist/array/impl/array-utils-element-access.d.mts.map +1 -1
- package/dist/array/impl/array-utils-element-access.mjs +6 -0
- package/dist/array/impl/array-utils-element-access.mjs.map +1 -1
- package/dist/array/impl/array-utils-modification.d.mts +14 -0
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +34 -10
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/array-utils-search.d.mts +34 -4
- package/dist/array/impl/array-utils-search.d.mts.map +1 -1
- package/dist/array/impl/array-utils-search.mjs.map +1 -1
- package/dist/array/impl/array-utils-set-op.d.mts +20 -7
- package/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +20 -7
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-size.d.mts +5 -2
- package/dist/array/impl/array-utils-size.d.mts.map +1 -1
- package/dist/array/impl/array-utils-size.mjs +5 -2
- package/dist/array/impl/array-utils-size.mjs.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.d.mts +2 -0
- package/dist/array/impl/array-utils-slice-clamped.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slice-clamped.mjs.map +1 -1
- package/dist/array/impl/array-utils-slicing.d.mts +17 -2
- package/dist/array/impl/array-utils-slicing.d.mts.map +1 -1
- package/dist/array/impl/array-utils-slicing.mjs +9 -2
- package/dist/array/impl/array-utils-slicing.mjs.map +1 -1
- package/dist/array/impl/array-utils-transformation.d.mts +27 -0
- package/dist/array/impl/array-utils-transformation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-transformation.mjs +6 -0
- package/dist/array/impl/array-utils-transformation.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts +35 -18
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +25 -14
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.d.mts +35 -15
- package/dist/collections/imap.d.mts.map +1 -1
- package/dist/collections/imap.mjs +5 -3
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts +46 -19
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +9 -2
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.d.mts +48 -19
- package/dist/collections/iset.d.mts.map +1 -1
- package/dist/collections/iset.mjs +9 -2
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.d.mts +65 -25
- package/dist/collections/queue.d.mts.map +1 -1
- package/dist/collections/queue.mjs +13 -5
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.d.mts +60 -25
- package/dist/collections/stack.d.mts.map +1 -1
- package/dist/collections/stack.mjs +12 -5
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/entry-point.mjs +1 -1
- package/dist/functional/match.d.mts +1 -1
- package/dist/functional/match.d.mts.map +1 -1
- package/dist/functional/match.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts +3 -2
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-filter.d.mts +3 -0
- package/dist/functional/optional/impl/optional-filter.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-filter.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-flat-map.d.mts +2 -0
- package/dist/functional/optional/impl/optional-flat-map.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-flat-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-from-nullable.d.mts +2 -0
- package/dist/functional/optional/impl/optional-from-nullable.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-from-nullable.mjs +2 -0
- package/dist/functional/optional/impl/optional-from-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-none.d.mts +1 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +1 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts +4 -2
- package/dist/functional/optional/impl/optional-is-optional.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-optional.mjs +4 -2
- package/dist/functional/optional/impl/optional-is-optional.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts +2 -1
- package/dist/functional/optional/impl/optional-is-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +2 -1
- package/dist/functional/optional/impl/optional-is-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-map.d.mts +2 -0
- package/dist/functional/optional/impl/optional-map.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-map.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-none.d.mts +4 -2
- package/dist/functional/optional/impl/optional-none.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-none.mjs +4 -2
- package/dist/functional/optional/impl/optional-none.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-or-else.d.mts +4 -0
- package/dist/functional/optional/impl/optional-or-else.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-or-else.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-some.d.mts +5 -3
- package/dist/functional/optional/impl/optional-some.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-some.mjs +4 -2
- package/dist/functional/optional/impl/optional-some.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +4 -2
- package/dist/functional/optional/impl/optional-to-nullable.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-to-nullable.mjs +4 -2
- package/dist/functional/optional/impl/optional-to-nullable.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +7 -4
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-or.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +2 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +2 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap.d.mts +4 -2
- package/dist/functional/optional/impl/optional-unwrap.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-unwrap.mjs.map +1 -1
- package/dist/functional/optional/impl/optional-zip.d.mts +3 -1
- package/dist/functional/optional/impl/optional-zip.d.mts.map +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +3 -1
- package/dist/functional/optional/impl/optional-zip.mjs.map +1 -1
- package/dist/functional/pipe.d.mts +2 -2
- package/dist/functional/result/impl/result-err.d.mts +4 -2
- package/dist/functional/result/impl/result-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-err.mjs +3 -1
- package/dist/functional/result/impl/result-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-expect-to-be.d.mts +3 -2
- package/dist/functional/result/impl/result-expect-to-be.d.mts.map +1 -1
- package/dist/functional/result/impl/result-expect-to-be.mjs.map +1 -1
- package/dist/functional/result/impl/result-flat-map.d.mts +5 -0
- package/dist/functional/result/impl/result-flat-map.d.mts.map +1 -1
- package/dist/functional/result/impl/result-flat-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-fold.d.mts +4 -0
- package/dist/functional/result/impl/result-fold.d.mts.map +1 -1
- package/dist/functional/result/impl/result-fold.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-promise.d.mts +4 -1
- package/dist/functional/result/impl/result-from-promise.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs +4 -1
- package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts +3 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +3 -1
- package/dist/functional/result/impl/result-from-throwable.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-err.d.mts +4 -2
- package/dist/functional/result/impl/result-is-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-err.mjs +4 -2
- package/dist/functional/result/impl/result-is-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-ok.d.mts +4 -2
- package/dist/functional/result/impl/result-is-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-ok.mjs +4 -2
- package/dist/functional/result/impl/result-is-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-is-result.d.mts +7 -3
- package/dist/functional/result/impl/result-is-result.d.mts.map +1 -1
- package/dist/functional/result/impl/result-is-result.mjs +7 -3
- package/dist/functional/result/impl/result-is-result.mjs.map +1 -1
- package/dist/functional/result/impl/result-map-err.d.mts +3 -0
- package/dist/functional/result/impl/result-map-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-map-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-map.d.mts +4 -0
- package/dist/functional/result/impl/result-map.d.mts.map +1 -1
- package/dist/functional/result/impl/result-map.mjs.map +1 -1
- package/dist/functional/result/impl/result-ok.d.mts +4 -2
- package/dist/functional/result/impl/result-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-ok.mjs +3 -1
- package/dist/functional/result/impl/result-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-or-else.d.mts +4 -0
- package/dist/functional/result/impl/result-or-else.d.mts.map +1 -1
- package/dist/functional/result/impl/result-or-else.mjs.map +1 -1
- package/dist/functional/result/impl/result-swap.d.mts +2 -0
- package/dist/functional/result/impl/result-swap.d.mts.map +1 -1
- package/dist/functional/result/impl/result-swap.mjs +2 -0
- package/dist/functional/result/impl/result-swap.mjs.map +1 -1
- package/dist/functional/result/impl/result-to-optional.d.mts +2 -0
- package/dist/functional/result/impl/result-to-optional.d.mts.map +1 -1
- package/dist/functional/result/impl/result-to-optional.mjs +2 -0
- package/dist/functional/result/impl/result-to-optional.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts +7 -4
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +3 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +3 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts +3 -2
- package/dist/functional/result/impl/result-unwrap-err.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-err.mjs +3 -2
- package/dist/functional/result/impl/result-unwrap-err.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +7 -4
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok-or.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok.d.mts +3 -2
- package/dist/functional/result/impl/result-unwrap-ok.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts +3 -1
- package/dist/functional/result/impl/result-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +3 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/result/impl/result-zip.d.mts +3 -1
- package/dist/functional/result/impl/result-zip.d.mts.map +1 -1
- package/dist/functional/result/impl/result-zip.mjs +3 -1
- package/dist/functional/result/impl/result-zip.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +3 -2
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +2 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-expect-to-be.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts +4 -0
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-fold.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-fold.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +3 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +3 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +3 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +3 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +7 -3
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +7 -3
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts +3 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts +3 -0
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts +6 -0
- package/dist/functional/ternary-result/impl/ternary-result-map.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-map.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-or-else.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-or-else.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +1 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +2 -0
- package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-warn.mjs.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts +4 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.d.mts.map +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +4 -0
- package/dist/functional/ternary-result/impl/ternary-result-zip.mjs.map +1 -1
- package/dist/globals.d.mts +12 -1
- package/dist/guard/has-key.d.mts +6 -3
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +2 -2
- package/dist/guard/index.mjs +1 -1
- package/dist/guard/is-record.d.mts +31 -0
- package/dist/guard/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +32 -1
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/is-type.d.mts +3 -0
- package/dist/guard/is-type.d.mts.map +1 -1
- package/dist/guard/is-type.mjs +3 -0
- package/dist/guard/is-type.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts +3 -2
- package/dist/guard/key-is-in.d.mts.map +1 -1
- package/dist/guard/key-is-in.mjs +3 -2
- package/dist/guard/key-is-in.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/iterator/range.d.mts +4 -0
- package/dist/iterator/range.d.mts.map +1 -1
- package/dist/iterator/range.mjs +1 -0
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/json.d.mts +42 -21
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +42 -21
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +33 -19
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +33 -19
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +2 -2
- package/dist/number/branded-types/positive-int.d.mts +34 -20
- package/dist/number/branded-types/positive-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-int.mjs +34 -20
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +47 -26
- package/dist/number/branded-types/positive-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +48 -27
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +48 -27
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +50 -29
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.mjs +1 -1
- package/dist/number/branded-types/uint.d.mts +31 -19
- package/dist/number/branded-types/uint.d.mts.map +1 -1
- package/dist/number/branded-types/uint.mjs +31 -19
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/num.d.mts +29 -20
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +24 -17
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.d.mts +33 -11
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +33 -11
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +12 -3
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +10 -3
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/tuple.d.mts +14 -3
- package/dist/others/tuple.d.mts.map +1 -1
- package/dist/others/tuple.mjs +14 -3
- package/dist/others/tuple.mjs.map +1 -1
- package/dist/others/unknown-to-string.d.mts.map +1 -1
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/dist/promise/promise.d.mts +8 -4
- package/dist/promise/promise.d.mts.map +1 -1
- package/dist/promise/promise.mjs +8 -4
- package/dist/promise/promise.mjs.map +1 -1
- package/package.json +26 -28
- package/src/array/impl/array-utils-creation.mts +20 -0
- package/src/array/impl/array-utils-creation.test.mts +72 -1
- package/src/array/impl/array-utils-element-access.mts +13 -0
- package/src/array/impl/array-utils-element-access.test.mts +36 -15
- package/src/array/impl/array-utils-iterators.test.mts +17 -0
- package/src/array/impl/array-utils-modification.mts +78 -19
- package/src/array/impl/array-utils-modification.test.mts +75 -0
- package/src/array/impl/array-utils-overload-type-error.test.mts +19 -0
- package/src/array/impl/array-utils-reducing-value.mts +61 -16
- package/src/array/impl/array-utils-reducing-value.test.mts +107 -25
- package/src/array/impl/array-utils-search.mts +57 -4
- package/src/array/impl/array-utils-search.test.mts +61 -10
- package/src/array/impl/array-utils-set-op.mts +26 -7
- package/src/array/impl/array-utils-set-op.test.mts +129 -13
- package/src/array/impl/array-utils-size.mts +5 -2
- package/src/array/impl/array-utils-size.test.mts +1 -0
- package/src/array/impl/array-utils-slice-clamped.mts +7 -0
- package/src/array/impl/array-utils-slice-clamped.test.mts +20 -0
- package/src/array/impl/array-utils-slicing.mts +29 -2
- package/src/array/impl/array-utils-slicing.test.mts +57 -0
- package/src/array/impl/array-utils-transformation.mts +58 -0
- package/src/array/impl/array-utils-transformation.test.mts +115 -3
- package/src/array/impl/array-utils-validation.mts +41 -18
- package/src/array/impl/array-utils-validation.test.mts +176 -78
- package/src/array/impl/array.test.mts +18 -6
- package/src/collections/imap-mapped.mts +11 -0
- package/src/collections/imap-mapped.test.mts +86 -18
- package/src/collections/imap.mts +47 -15
- package/src/collections/imap.test.mts +137 -31
- package/src/collections/iset-mapped.mts +54 -19
- package/src/collections/iset-mapped.test.mts +163 -52
- package/src/collections/iset.mts +53 -19
- package/src/collections/iset.test.mts +323 -130
- package/src/collections/queue.mts +78 -25
- package/src/collections/queue.test.mts +65 -35
- package/src/collections/stack.mts +67 -25
- package/src/collections/stack.test.mts +59 -15
- package/src/functional/match.mts +17 -1
- package/src/functional/match.test.mts +2 -0
- package/src/functional/optional/impl/optional-expect-to-be.mts +5 -2
- package/src/functional/optional/impl/optional-filter.mts +6 -0
- package/src/functional/optional/impl/optional-flat-map.mts +4 -0
- package/src/functional/optional/impl/optional-from-nullable.mts +2 -0
- package/src/functional/optional/impl/optional-is-none.mts +1 -1
- package/src/functional/optional/impl/optional-is-optional.mts +4 -2
- package/src/functional/optional/impl/optional-is-some.mts +2 -1
- package/src/functional/optional/impl/optional-map.mts +5 -0
- package/src/functional/optional/impl/optional-none.mts +4 -2
- package/src/functional/optional/impl/optional-or-else.mts +6 -0
- package/src/functional/optional/impl/optional-some.mts +5 -3
- package/src/functional/optional/impl/optional-to-nullable.mts +4 -2
- package/src/functional/optional/impl/optional-unwrap-or.mts +9 -4
- package/src/functional/optional/impl/optional-unwrap-throw.mts +2 -1
- package/src/functional/optional/impl/optional-unwrap.mts +4 -2
- package/src/functional/optional/impl/optional-zip.mts +3 -1
- package/src/functional/optional.test.mts +126 -54
- package/src/functional/pipe.mts +2 -2
- package/src/functional/pipe.test.mts +7 -4
- package/src/functional/result/impl/result-err.mts +4 -2
- package/src/functional/result/impl/result-expect-to-be.mts +5 -2
- package/src/functional/result/impl/result-flat-map.mts +7 -0
- package/src/functional/result/impl/result-fold.mts +6 -0
- package/src/functional/result/impl/result-from-promise.mts +4 -1
- package/src/functional/result/impl/result-from-throwable.mts +5 -1
- package/src/functional/result/impl/result-is-err.mts +4 -2
- package/src/functional/result/impl/result-is-ok.mts +4 -2
- package/src/functional/result/impl/result-is-result.mts +7 -3
- package/src/functional/result/impl/result-map-err.mts +5 -0
- package/src/functional/result/impl/result-map.mts +6 -0
- package/src/functional/result/impl/result-ok.mts +4 -2
- package/src/functional/result/impl/result-or-else.mts +6 -0
- package/src/functional/result/impl/result-swap.mts +2 -0
- package/src/functional/result/impl/result-to-optional.mts +2 -0
- package/src/functional/result/impl/result-unwrap-err-or.mts +9 -4
- package/src/functional/result/impl/result-unwrap-err-throw.mts +3 -1
- package/src/functional/result/impl/result-unwrap-err.mts +3 -2
- package/src/functional/result/impl/result-unwrap-ok-or.mts +9 -4
- package/src/functional/result/impl/result-unwrap-ok.mts +4 -2
- package/src/functional/result/impl/result-unwrap-throw.mts +3 -1
- package/src/functional/result/impl/result-zip.mts +3 -1
- package/src/functional/result.test.mts +182 -152
- package/src/functional/ternary-result/impl/ternary-result-err.mts +3 -2
- package/src/functional/ternary-result/impl/ternary-result-expect-to-be.mts +4 -0
- package/src/functional/ternary-result/impl/ternary-result-flat-map.mts +7 -0
- package/src/functional/ternary-result/impl/ternary-result-fold.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +3 -1
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +4 -1
- package/src/functional/ternary-result/impl/ternary-result-is-ok.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +7 -3
- package/src/functional/ternary-result/impl/ternary-result-is-warn.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-map-err.mts +6 -0
- package/src/functional/ternary-result/impl/ternary-result-map-warn.mts +6 -0
- package/src/functional/ternary-result/impl/ternary-result-map.mts +9 -0
- package/src/functional/ternary-result/impl/ternary-result-ok.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-or-else.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-to-optional.mts +2 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-or.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-err.mts +2 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok-or.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-ok.mts +3 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-throw.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-or.mts +5 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mts +1 -0
- package/src/functional/ternary-result/impl/ternary-result-unwrap-warn.mts +2 -0
- package/src/functional/ternary-result/impl/ternary-result-warn.mts +4 -1
- package/src/functional/ternary-result/impl/ternary-result-zip.mts +4 -0
- package/src/functional/ternary-result.test.mts +99 -8
- package/src/globals.d.mts +12 -1
- package/src/guard/has-key.mts +8 -5
- package/src/guard/has-key.test.mts +9 -5
- package/src/guard/is-error.test.mts +143 -0
- package/src/guard/is-non-empty-string.test.mts +44 -24
- package/src/guard/is-non-null-object.test.mts +45 -26
- package/src/guard/is-primitive.test.mts +51 -28
- package/src/guard/is-record.mts +34 -0
- package/src/guard/is-record.test.mts +28 -7
- package/src/guard/is-type.mts +3 -0
- package/src/guard/is-type.test.mts +285 -155
- package/src/guard/key-is-in.mts +3 -2
- package/src/guard/key-is-in.test.mts +2 -2
- package/src/iterator/range.mts +9 -0
- package/src/json/json.mts +50 -21
- package/src/json/json.test.mts +224 -176
- package/src/number/branded-types/finite-number.test.mts +51 -11
- package/src/number/branded-types/int.mts +33 -19
- package/src/number/branded-types/int.test.mts +56 -14
- package/src/number/branded-types/int16.test.mts +63 -16
- package/src/number/branded-types/int32.test.mts +63 -16
- package/src/number/branded-types/non-negative-finite-number.test.mts +52 -12
- package/src/number/branded-types/non-negative-int16.test.mts +59 -16
- package/src/number/branded-types/non-negative-int32.test.mts +59 -16
- package/src/number/branded-types/non-zero-finite-number.test.mts +65 -14
- package/src/number/branded-types/non-zero-int.test.mts +72 -19
- package/src/number/branded-types/non-zero-int16.test.mts +60 -16
- package/src/number/branded-types/non-zero-int32.test.mts +60 -16
- package/src/number/branded-types/non-zero-safe-int.mts +2 -2
- package/src/number/branded-types/non-zero-safe-int.test.mts +85 -23
- package/src/number/branded-types/non-zero-uint16.test.mts +53 -16
- package/src/number/branded-types/non-zero-uint32.test.mts +53 -16
- package/src/number/branded-types/positive-finite-number.test.mts +59 -14
- package/src/number/branded-types/positive-int.mts +34 -20
- package/src/number/branded-types/positive-int.test.mts +64 -17
- package/src/number/branded-types/positive-int16.test.mts +50 -15
- package/src/number/branded-types/positive-int32.test.mts +50 -15
- package/src/number/branded-types/positive-safe-int.mts +48 -27
- package/src/number/branded-types/positive-safe-int.test.mts +68 -19
- package/src/number/branded-types/positive-uint16.test.mts +53 -16
- package/src/number/branded-types/positive-uint32.test.mts +53 -16
- package/src/number/branded-types/safe-int.mts +50 -29
- package/src/number/branded-types/safe-int.test.mts +70 -18
- package/src/number/branded-types/safe-uint.mts +1 -1
- package/src/number/branded-types/safe-uint.test.mts +65 -17
- package/src/number/branded-types/uint.mts +31 -19
- package/src/number/branded-types/uint.test.mts +58 -15
- package/src/number/branded-types/uint16.test.mts +56 -15
- package/src/number/branded-types/uint32.test.mts +56 -15
- package/src/number/enum/int8.test.mts +7 -1
- package/src/number/enum/uint8.test.mts +7 -1
- package/src/number/num.mts +32 -21
- package/src/number/num.test.mts +88 -26
- package/src/number/refined-number-utils.mts +38 -13
- package/src/object/object.mts +19 -3
- package/src/object/object.test.mts +16 -6
- package/src/others/cast-mutable.test.mts +8 -1
- package/src/others/cast-readonly.test.mts +21 -4
- package/src/others/if-then.test.mts +40 -24
- package/src/others/map-nullable.mts +3 -0
- package/src/others/map-nullable.test.mts +27 -0
- package/src/others/memoize-function.test.mts +41 -0
- package/src/others/tuple.mts +14 -3
- package/src/others/unknown-to-string.mts +2 -0
- package/src/others/unknown-to-string.test.mts +10 -0
- package/src/promise/promise.mts +8 -4
- package/src/promise/promise.test.mts +8 -13
package/src/json/json.test.mts
CHANGED
|
@@ -6,18 +6,24 @@ import { Json } from './json.mjs';
|
|
|
6
6
|
describe('parse', () => {
|
|
7
7
|
test('should parse primitive values', () => {
|
|
8
8
|
assert.deepStrictEqual(Json.parse('"hello"'), Result.ok('hello'));
|
|
9
|
+
|
|
9
10
|
assert.deepStrictEqual(Json.parse('42'), Result.ok(42));
|
|
11
|
+
|
|
10
12
|
assert.deepStrictEqual(Json.parse('true'), Result.ok(true));
|
|
13
|
+
|
|
11
14
|
assert.deepStrictEqual(Json.parse('false'), Result.ok(false));
|
|
15
|
+
|
|
12
16
|
assert.deepStrictEqual(Json.parse('null'), Result.ok(null));
|
|
13
17
|
});
|
|
14
18
|
|
|
15
19
|
test('should parse arrays', () => {
|
|
16
20
|
assert.deepStrictEqual(Json.parse('[1,2,3]'), Result.ok([1, 2, 3]));
|
|
21
|
+
|
|
17
22
|
assert.deepStrictEqual(
|
|
18
23
|
Json.parse('["a","b","c"]'),
|
|
19
24
|
Result.ok(['a', 'b', 'c']),
|
|
20
25
|
);
|
|
26
|
+
|
|
21
27
|
assert.deepStrictEqual(
|
|
22
28
|
Json.parse('[1,"two",true,null]'),
|
|
23
29
|
Result.ok([1, 'two', true, null]),
|
|
@@ -29,6 +35,7 @@ describe('parse', () => {
|
|
|
29
35
|
Json.parse('{"a":1,"b":2}'),
|
|
30
36
|
Result.ok({ a: 1, b: 2 }),
|
|
31
37
|
);
|
|
38
|
+
|
|
32
39
|
assert.deepStrictEqual(
|
|
33
40
|
Json.parse('{"name":"test","value":42}'),
|
|
34
41
|
Result.ok({
|
|
@@ -40,6 +47,7 @@ describe('parse', () => {
|
|
|
40
47
|
|
|
41
48
|
test('should parse nested structures', () => {
|
|
42
49
|
const json = '{"level1":{"level2":{"array":[1,2,{"level3":"deep"}]}}}';
|
|
50
|
+
|
|
43
51
|
const expected = {
|
|
44
52
|
level1: {
|
|
45
53
|
level2: {
|
|
@@ -56,6 +64,7 @@ describe('parse', () => {
|
|
|
56
64
|
Json.parse(' { "a" : 1 , "b" : 2 } '),
|
|
57
65
|
Result.ok({ a: 1, b: 2 }),
|
|
58
66
|
);
|
|
67
|
+
|
|
59
68
|
assert.deepStrictEqual(
|
|
60
69
|
Json.parse('\n[\n 1,\n 2,\n 3\n]\n'),
|
|
61
70
|
Result.ok([1, 2, 3]),
|
|
@@ -63,38 +72,54 @@ describe('parse', () => {
|
|
|
63
72
|
});
|
|
64
73
|
|
|
65
74
|
test('should return error for invalid JSON', () => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
assert.isTrue(Result.isErr(Json.parse('invalid')));
|
|
76
|
+
|
|
77
|
+
assert.isTrue(Result.isErr(Json.parse('{missing quotes: true}')));
|
|
78
|
+
|
|
79
|
+
assert.isTrue(Result.isErr(Json.parse('[1,2,]'))); // Trailing comma
|
|
80
|
+
|
|
81
|
+
assert.isTrue(Result.isErr(Json.parse('undefined')));
|
|
70
82
|
});
|
|
71
83
|
|
|
72
84
|
test('should return parsed value for valid JSON', () => {
|
|
73
85
|
assert.deepStrictEqual(Json.parse('{"a":1}'), Result.ok({ a: 1 }));
|
|
86
|
+
|
|
74
87
|
assert.deepStrictEqual(Json.parse('[1,2,3]'), Result.ok([1, 2, 3]));
|
|
88
|
+
|
|
75
89
|
assert.deepStrictEqual(Json.parse('"string"'), Result.ok('string'));
|
|
90
|
+
|
|
76
91
|
assert.deepStrictEqual(Json.parse('42'), Result.ok(42));
|
|
92
|
+
|
|
77
93
|
assert.deepStrictEqual(Json.parse('true'), Result.ok(true));
|
|
94
|
+
|
|
78
95
|
assert.deepStrictEqual(Json.parse('null'), Result.ok(null));
|
|
79
96
|
});
|
|
80
97
|
|
|
81
98
|
test('should return error for invalid JSON cases', () => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
99
|
+
assert.isTrue(Result.isErr(Json.parse('invalid')));
|
|
100
|
+
|
|
101
|
+
assert.isTrue(Result.isErr(Json.parse('{bad json}')));
|
|
102
|
+
|
|
103
|
+
assert.isTrue(Result.isErr(Json.parse('[1,2,]')));
|
|
104
|
+
|
|
105
|
+
assert.isTrue(Result.isErr(Json.parse('undefined')));
|
|
106
|
+
|
|
107
|
+
assert.isTrue(Result.isErr(Json.parse('')));
|
|
87
108
|
});
|
|
88
109
|
|
|
89
110
|
test('should handle edge cases', () => {
|
|
90
111
|
assert.deepStrictEqual(Json.parse('0'), Result.ok(0));
|
|
112
|
+
|
|
91
113
|
assert.deepStrictEqual(Json.parse('""'), Result.ok(''));
|
|
114
|
+
|
|
92
115
|
assert.deepStrictEqual(Json.parse('[]'), Result.ok([]));
|
|
116
|
+
|
|
93
117
|
assert.deepStrictEqual(Json.parse('{}'), Result.ok({}));
|
|
94
118
|
});
|
|
95
119
|
|
|
96
120
|
test('should not throw errors', () => {
|
|
97
121
|
expect(() => Json.parse('{{{')).not.toThrow();
|
|
122
|
+
|
|
98
123
|
expect(() => Json.parse('null null')).not.toThrow();
|
|
99
124
|
|
|
100
125
|
expect(() => Json.parse(String(undefined))).not.toThrow();
|
|
@@ -105,21 +130,23 @@ describe('parse', () => {
|
|
|
105
130
|
if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T/u.test(value)) {
|
|
106
131
|
return new Date(value);
|
|
107
132
|
}
|
|
133
|
+
|
|
108
134
|
return value;
|
|
109
135
|
};
|
|
110
136
|
|
|
111
137
|
const jsonString = '{"name":"test","created":"2023-12-01T10:00:00.000Z"}';
|
|
138
|
+
|
|
112
139
|
const result = Json.parse(jsonString, dateReviver);
|
|
113
140
|
|
|
114
|
-
|
|
141
|
+
assert.isTrue(Result.isOk(result));
|
|
115
142
|
|
|
116
143
|
if (
|
|
117
|
-
Result.isOk(result) &&
|
|
118
144
|
isRecord(result.value) &&
|
|
119
145
|
hasKey(result.value, 'name') &&
|
|
120
146
|
hasKey(result.value, 'created')
|
|
121
147
|
) {
|
|
122
148
|
expect(result.value.name).toBe('test');
|
|
149
|
+
|
|
123
150
|
expect(result.value.created).toBeInstanceOf(Date);
|
|
124
151
|
}
|
|
125
152
|
});
|
|
@@ -129,6 +156,7 @@ describe('parse', () => {
|
|
|
129
156
|
if (key === 'number' && typeof value === 'string') {
|
|
130
157
|
return Number.parseInt(value, 10);
|
|
131
158
|
}
|
|
159
|
+
|
|
132
160
|
return value;
|
|
133
161
|
};
|
|
134
162
|
|
|
@@ -137,20 +165,20 @@ describe('parse', () => {
|
|
|
137
165
|
transformReviver,
|
|
138
166
|
);
|
|
139
167
|
|
|
140
|
-
|
|
168
|
+
assert.isTrue(Result.isOk(result));
|
|
141
169
|
|
|
142
|
-
|
|
143
|
-
expect(result.value).toHaveProperty('number');
|
|
144
|
-
expect(result.value).toHaveProperty('text');
|
|
170
|
+
expect(result.value).toHaveProperty('number');
|
|
145
171
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
172
|
+
expect(result.value).toHaveProperty('text');
|
|
173
|
+
|
|
174
|
+
if (
|
|
175
|
+
isRecord(result.value) &&
|
|
176
|
+
hasKey(result.value, 'number') &&
|
|
177
|
+
hasKey(result.value, 'text')
|
|
178
|
+
) {
|
|
179
|
+
expect(result.value.number).toBe(42);
|
|
180
|
+
|
|
181
|
+
expect(result.value.text).toBe('hello');
|
|
154
182
|
}
|
|
155
183
|
});
|
|
156
184
|
});
|
|
@@ -158,17 +186,22 @@ describe('parse', () => {
|
|
|
158
186
|
describe('stringify', () => {
|
|
159
187
|
test('should stringify primitive values', () => {
|
|
160
188
|
assert.deepStrictEqual(Json.stringify('hello'), Result.ok('"hello"'));
|
|
189
|
+
|
|
161
190
|
assert.deepStrictEqual(Json.stringify(42), Result.ok('42'));
|
|
191
|
+
|
|
162
192
|
assert.deepStrictEqual(Json.stringify(true), Result.ok('true'));
|
|
193
|
+
|
|
163
194
|
assert.deepStrictEqual(Json.stringify(null), Result.ok('null'));
|
|
164
195
|
});
|
|
165
196
|
|
|
166
197
|
test('should stringify arrays', () => {
|
|
167
198
|
assert.deepStrictEqual(Json.stringify([1, 2, 3]), Result.ok('[1,2,3]'));
|
|
199
|
+
|
|
168
200
|
assert.deepStrictEqual(
|
|
169
201
|
Json.stringify(['a', 'b', 'c']),
|
|
170
202
|
Result.ok('["a","b","c"]'),
|
|
171
203
|
);
|
|
204
|
+
|
|
172
205
|
assert.deepStrictEqual(
|
|
173
206
|
Json.stringify([1, 'two', true, null]),
|
|
174
207
|
Result.ok('[1,"two",true,null]'),
|
|
@@ -180,6 +213,7 @@ describe('stringify', () => {
|
|
|
180
213
|
Json.stringify({ a: 1, b: 2 }),
|
|
181
214
|
Result.ok('{"a":1,"b":2}'),
|
|
182
215
|
);
|
|
216
|
+
|
|
183
217
|
assert.deepStrictEqual(
|
|
184
218
|
Json.stringify({ name: 'test', value: 42 }),
|
|
185
219
|
Result.ok('{"name":"test","value":42}'),
|
|
@@ -203,6 +237,7 @@ describe('stringify', () => {
|
|
|
203
237
|
|
|
204
238
|
test('should handle empty structures', () => {
|
|
205
239
|
assert.deepStrictEqual(Json.stringify({}), Result.ok('{}'));
|
|
240
|
+
|
|
206
241
|
assert.deepStrictEqual(Json.stringify([]), Result.ok('[]'));
|
|
207
242
|
});
|
|
208
243
|
|
|
@@ -211,10 +246,12 @@ describe('stringify', () => {
|
|
|
211
246
|
Json.stringify('with "quotes"'),
|
|
212
247
|
Result.ok(String.raw`"with \"quotes\""`),
|
|
213
248
|
);
|
|
249
|
+
|
|
214
250
|
assert.deepStrictEqual(
|
|
215
251
|
Json.stringify('with\nnewline'),
|
|
216
252
|
Result.ok(String.raw`"with\nnewline"`),
|
|
217
253
|
);
|
|
254
|
+
|
|
218
255
|
assert.deepStrictEqual(
|
|
219
256
|
Json.stringify('with\ttab'),
|
|
220
257
|
Result.ok(String.raw`"with\ttab"`),
|
|
@@ -223,34 +260,42 @@ describe('stringify', () => {
|
|
|
223
260
|
|
|
224
261
|
test('should return stringified value for valid JSON values', () => {
|
|
225
262
|
assert.deepStrictEqual(Json.stringify({ a: 1 }), Result.ok('{"a":1}'));
|
|
263
|
+
|
|
226
264
|
assert.deepStrictEqual(Json.stringify([1, 2, 3]), Result.ok('[1,2,3]'));
|
|
265
|
+
|
|
227
266
|
assert.deepStrictEqual(Json.stringify('string'), Result.ok('"string"'));
|
|
267
|
+
|
|
228
268
|
assert.deepStrictEqual(Json.stringify(42), Result.ok('42'));
|
|
269
|
+
|
|
229
270
|
assert.deepStrictEqual(Json.stringify(true), Result.ok('true'));
|
|
271
|
+
|
|
230
272
|
assert.deepStrictEqual(Json.stringify(null), Result.ok('null'));
|
|
231
273
|
});
|
|
232
274
|
|
|
233
275
|
test('should handle non-serializable values', () => {
|
|
234
276
|
assert.deepStrictEqual(Json.stringify(undefined), Result.ok(undefined));
|
|
277
|
+
|
|
235
278
|
assert.deepStrictEqual(
|
|
236
279
|
Json.stringify(Symbol('test')),
|
|
237
280
|
Result.ok(undefined),
|
|
238
281
|
);
|
|
282
|
+
|
|
239
283
|
assert.deepStrictEqual(
|
|
240
284
|
Json.stringify(() => {}),
|
|
241
285
|
Result.ok(undefined),
|
|
242
286
|
);
|
|
243
287
|
|
|
244
288
|
// BigInt should cause an error
|
|
245
|
-
|
|
289
|
+
assert.isTrue(Result.isErr(Json.stringify(123n)));
|
|
246
290
|
});
|
|
247
291
|
|
|
248
292
|
test('should handle circular references', () => {
|
|
249
293
|
const mut_obj: any = { a: 1 };
|
|
294
|
+
|
|
250
295
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
251
296
|
mut_obj.circular = mut_obj;
|
|
252
297
|
|
|
253
|
-
|
|
298
|
+
assert.isTrue(Result.isErr(Json.stringify(mut_obj)));
|
|
254
299
|
});
|
|
255
300
|
|
|
256
301
|
test('should handle objects with toJSON method', () => {
|
|
@@ -275,9 +320,11 @@ describe('stringify', () => {
|
|
|
275
320
|
|
|
276
321
|
test('should not throw errors', () => {
|
|
277
322
|
const mut_circularArray: any[] = [];
|
|
323
|
+
|
|
278
324
|
mut_circularArray.push(mut_circularArray);
|
|
279
325
|
|
|
280
326
|
expect(() => Json.stringify(mut_circularArray)).not.toThrow();
|
|
327
|
+
|
|
281
328
|
expect(() => Json.stringify({ fn: () => {} })).not.toThrow();
|
|
282
329
|
});
|
|
283
330
|
|
|
@@ -290,41 +337,41 @@ describe('stringify', () => {
|
|
|
290
337
|
|
|
291
338
|
const secureReplacer = (key: string, value: unknown): unknown => {
|
|
292
339
|
if (key === 'password') return '[REDACTED]';
|
|
340
|
+
|
|
293
341
|
return value;
|
|
294
342
|
};
|
|
295
343
|
|
|
296
344
|
const result = Json.stringify(data, secureReplacer);
|
|
297
345
|
|
|
298
|
-
|
|
346
|
+
assert.isTrue(Result.isOk(result));
|
|
299
347
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
348
|
+
expect(result.value).toContain('[REDACTED]');
|
|
349
|
+
|
|
350
|
+
expect(result.value).not.toContain('secret123');
|
|
304
351
|
});
|
|
305
352
|
|
|
306
353
|
test('should format output with space parameter (number)', () => {
|
|
307
354
|
const data = { a: 1, b: 2 };
|
|
355
|
+
|
|
308
356
|
const result = Json.stringify(data, undefined, 2);
|
|
309
357
|
|
|
310
|
-
|
|
358
|
+
assert.isTrue(Result.isOk(result));
|
|
311
359
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
360
|
+
expect(result.value).toContain('\n');
|
|
361
|
+
|
|
362
|
+
expect(result.value).toContain(' '); // 2 spaces indentation
|
|
316
363
|
});
|
|
317
364
|
|
|
318
365
|
test('should format output with space parameter (string)', () => {
|
|
319
366
|
const data = { a: 1, b: 2 };
|
|
367
|
+
|
|
320
368
|
const result = Json.stringify(data, undefined, '\t');
|
|
321
369
|
|
|
322
|
-
|
|
370
|
+
assert.isTrue(Result.isOk(result));
|
|
323
371
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
372
|
+
expect(result.value).toContain('\n');
|
|
373
|
+
|
|
374
|
+
expect(result.value).toContain('\t'); // tab indentation
|
|
328
375
|
});
|
|
329
376
|
});
|
|
330
377
|
|
|
@@ -340,22 +387,21 @@ describe('stringifySelected', () => {
|
|
|
340
387
|
|
|
341
388
|
const result = Json.stringifySelected(user, ['id', 'name', 'email']);
|
|
342
389
|
|
|
343
|
-
|
|
390
|
+
assert.isTrue(Result.isOk(result));
|
|
344
391
|
|
|
345
|
-
|
|
346
|
-
assert(isString(result.value));
|
|
392
|
+
assert.isTrue(isString(result.value));
|
|
347
393
|
|
|
348
|
-
|
|
394
|
+
const parsed: unknown = JSON.parse(result.value);
|
|
349
395
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
396
|
+
assert.deepStrictEqual(parsed, {
|
|
397
|
+
id: 1,
|
|
398
|
+
name: 'Alice',
|
|
399
|
+
email: 'alice@example.com',
|
|
400
|
+
});
|
|
355
401
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
402
|
+
expect(parsed).not.toHaveProperty('password');
|
|
403
|
+
|
|
404
|
+
expect(parsed).not.toHaveProperty('lastLogin');
|
|
359
405
|
});
|
|
360
406
|
|
|
361
407
|
test('should work with nested objects', () => {
|
|
@@ -375,26 +421,29 @@ describe('stringifySelected', () => {
|
|
|
375
421
|
'total',
|
|
376
422
|
]);
|
|
377
423
|
|
|
378
|
-
|
|
424
|
+
assert.isTrue(Result.isOk(result));
|
|
379
425
|
|
|
380
|
-
|
|
381
|
-
assert(isString(result.value));
|
|
382
|
-
const parsed: unknown = JSON.parse(result.value);
|
|
383
|
-
if (isRecord(parsed) && hasKey(parsed, 'users')) {
|
|
384
|
-
expect(isRecord(parsed.users)).toBe(false);
|
|
385
|
-
expect(parsed.users).toHaveLength(2);
|
|
426
|
+
assert.isTrue(isString(result.value));
|
|
386
427
|
|
|
387
|
-
|
|
388
|
-
assert.deepStrictEqual(parsed.users[0], { id: 1, name: 'Alice' });
|
|
428
|
+
const parsed: unknown = JSON.parse(result.value);
|
|
389
429
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
if (isRecord(parsed) && hasKey(parsed, 'metadata')) {
|
|
393
|
-
assert.deepStrictEqual(parsed.metadata, { total: 2 });
|
|
430
|
+
if (isRecord(parsed) && hasKey(parsed, 'users')) {
|
|
431
|
+
assert.isTrue(Arr.isArray(parsed.users));
|
|
394
432
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
433
|
+
expect(parsed.users).toHaveLength(2);
|
|
434
|
+
|
|
435
|
+
if (Arr.isArray(parsed.users)) {
|
|
436
|
+
assert.deepStrictEqual(parsed.users[0], { id: 1, name: 'Alice' });
|
|
437
|
+
|
|
438
|
+
expect(parsed.users[0]).not.toHaveProperty('secret');
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (isRecord(parsed) && hasKey(parsed, 'metadata')) {
|
|
442
|
+
assert.deepStrictEqual(parsed.metadata, { total: 2 });
|
|
443
|
+
|
|
444
|
+
expect(parsed.metadata).not.toHaveProperty('page');
|
|
445
|
+
|
|
446
|
+
expect(parsed.metadata).not.toHaveProperty('internal');
|
|
398
447
|
}
|
|
399
448
|
}
|
|
400
449
|
});
|
|
@@ -408,65 +457,66 @@ describe('stringifySelected', () => {
|
|
|
408
457
|
|
|
409
458
|
const result = Json.stringifySelected(matrix, [0, 1]);
|
|
410
459
|
|
|
411
|
-
|
|
460
|
+
assert.isTrue(Result.isOk(result));
|
|
412
461
|
|
|
413
|
-
|
|
414
|
-
assert(isString(result.value));
|
|
415
|
-
const parsed: unknown = JSON.parse(result.value);
|
|
462
|
+
assert.isTrue(isString(result.value));
|
|
416
463
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
464
|
+
const parsed: unknown = JSON.parse(result.value);
|
|
465
|
+
|
|
466
|
+
// Note: stringifySelected works with JSON.stringify's replacer parameter
|
|
467
|
+
// which may not work as expected with arrays
|
|
468
|
+
assert.isTrue(Array.isArray(parsed));
|
|
469
|
+
|
|
470
|
+
expect(parsed).toHaveLength(3);
|
|
422
471
|
});
|
|
423
472
|
|
|
424
473
|
test('should handle formatting with space parameter', () => {
|
|
425
474
|
const data = { a: 1, b: { c: 2 } };
|
|
475
|
+
|
|
426
476
|
const result = Json.stringifySelected(data, ['a', 'b', 'c'], 2);
|
|
427
477
|
|
|
428
|
-
|
|
478
|
+
assert.isTrue(Result.isOk(result));
|
|
429
479
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
}
|
|
480
|
+
expect(result.value).toContain('\n');
|
|
481
|
+
|
|
482
|
+
expect(result.value).toContain(' ');
|
|
434
483
|
});
|
|
435
484
|
|
|
436
485
|
test('should handle empty selection array', () => {
|
|
437
486
|
const data = { a: 1, b: 2, c: 3 };
|
|
487
|
+
|
|
438
488
|
const result = Json.stringifySelected(data, []);
|
|
439
489
|
|
|
440
|
-
|
|
490
|
+
assert.isTrue(Result.isOk(result));
|
|
441
491
|
|
|
442
|
-
|
|
443
|
-
expect(result.value).toBe('{}');
|
|
444
|
-
}
|
|
492
|
+
expect(result.value).toBe('{}');
|
|
445
493
|
});
|
|
446
494
|
|
|
447
495
|
test('should handle undefined properties parameter', () => {
|
|
448
496
|
const data = { a: 1, b: 2 };
|
|
497
|
+
|
|
449
498
|
const result = Json.stringifySelected(data, undefined);
|
|
450
499
|
|
|
451
|
-
|
|
500
|
+
assert.isTrue(Result.isOk(result));
|
|
452
501
|
|
|
453
|
-
|
|
454
|
-
assert(isString(result.value));
|
|
455
|
-
const parsed: unknown = JSON.parse(result.value);
|
|
502
|
+
assert.isTrue(isString(result.value));
|
|
456
503
|
|
|
457
|
-
|
|
458
|
-
|
|
504
|
+
const parsed: unknown = JSON.parse(result.value);
|
|
505
|
+
|
|
506
|
+
assert.deepStrictEqual(parsed, { a: 1, b: 2 });
|
|
459
507
|
});
|
|
460
508
|
|
|
461
509
|
test('should handle circular references with error', () => {
|
|
462
510
|
type CircularType = { name: string; self?: CircularType };
|
|
511
|
+
|
|
463
512
|
const mut_circular: CircularType = { name: 'test' };
|
|
513
|
+
|
|
464
514
|
mut_circular.self = mut_circular;
|
|
465
515
|
|
|
466
516
|
const result = Json.stringifySelected(mut_circular, ['name', 'self']);
|
|
467
517
|
|
|
468
518
|
// Note: JSON.stringify may handle circular references differently depending on the replacer
|
|
469
|
-
|
|
519
|
+
assert.isTrue(Result.isOk(result) || Result.isErr(result));
|
|
470
520
|
|
|
471
521
|
if (Result.isErr(result)) {
|
|
472
522
|
expectTypeOf(result.value).toBeString();
|
|
@@ -485,13 +535,11 @@ describe('stringifySortedKey', () => {
|
|
|
485
535
|
|
|
486
536
|
const result = Json.stringifySortedKey(unsortedObj);
|
|
487
537
|
|
|
488
|
-
|
|
538
|
+
assert.isTrue(Result.isOk(result));
|
|
489
539
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
);
|
|
494
|
-
}
|
|
540
|
+
expect(result.value).toBe(
|
|
541
|
+
'{"aardvark":"animal","apple":"fruit","banana":"fruit","zebra":"animal"}',
|
|
542
|
+
);
|
|
495
543
|
});
|
|
496
544
|
|
|
497
545
|
test('should sort nested object keys', () => {
|
|
@@ -513,26 +561,26 @@ describe('stringifySortedKey', () => {
|
|
|
513
561
|
|
|
514
562
|
const result = Json.stringifySortedKey(nestedObj);
|
|
515
563
|
|
|
516
|
-
|
|
564
|
+
assert.isTrue(Result.isOk(result));
|
|
517
565
|
|
|
518
|
-
|
|
519
|
-
assert(isString(result.value));
|
|
520
|
-
const parsed: unknown = JSON.parse(result.value);
|
|
521
|
-
if (isRecord(parsed)) {
|
|
522
|
-
const keys = Object.keys(parsed);
|
|
566
|
+
assert.isTrue(isString(result.value));
|
|
523
567
|
|
|
524
|
-
|
|
568
|
+
const parsed: unknown = JSON.parse(result.value);
|
|
525
569
|
|
|
526
|
-
|
|
527
|
-
|
|
570
|
+
if (isRecord(parsed)) {
|
|
571
|
+
const keys = Object.keys(parsed);
|
|
528
572
|
|
|
529
|
-
|
|
573
|
+
assert.deepStrictEqual(keys, ['settings', 'user']); // sorted top-level keys
|
|
530
574
|
|
|
531
|
-
|
|
532
|
-
|
|
575
|
+
if (hasKey(parsed, 'user') && isRecord(parsed.user)) {
|
|
576
|
+
const userKeys = Object.keys(parsed.user);
|
|
533
577
|
|
|
534
|
-
|
|
535
|
-
|
|
578
|
+
assert.deepStrictEqual(userKeys, ['address', 'age', 'name']); // sorted nested keys
|
|
579
|
+
|
|
580
|
+
if (hasKey(parsed.user, 'address') && isRecord(parsed.user.address)) {
|
|
581
|
+
const addressKeys = Object.keys(parsed.user.address);
|
|
582
|
+
|
|
583
|
+
assert.deepStrictEqual(addressKeys, ['city', 'country', 'zip']); // sorted deeper nested keys
|
|
536
584
|
}
|
|
537
585
|
}
|
|
538
586
|
}
|
|
@@ -553,41 +601,37 @@ describe('stringifySortedKey', () => {
|
|
|
553
601
|
|
|
554
602
|
const result = Json.stringifySortedKey(dataWithArrays);
|
|
555
603
|
|
|
556
|
-
|
|
604
|
+
assert.isTrue(Result.isOk(result));
|
|
557
605
|
|
|
558
|
-
|
|
559
|
-
assert(isString(result.value));
|
|
560
|
-
const parsed: unknown = JSON.parse(result.value);
|
|
606
|
+
assert.isTrue(isString(result.value));
|
|
561
607
|
|
|
562
|
-
|
|
563
|
-
// Check top-level keys are sorted
|
|
564
|
-
const topKeys = Object.keys(parsed);
|
|
608
|
+
const parsed: unknown = JSON.parse(result.value);
|
|
565
609
|
|
|
566
|
-
|
|
610
|
+
if (isRecord(parsed)) {
|
|
611
|
+
// Check top-level keys are sorted
|
|
612
|
+
const topKeys = Object.keys(parsed);
|
|
567
613
|
|
|
568
|
-
|
|
569
|
-
if (hasKey(parsed, 'metadata') && isRecord(parsed.metadata)) {
|
|
570
|
-
const metadataKeys = Object.keys(parsed.metadata);
|
|
614
|
+
assert.deepStrictEqual(topKeys, ['metadata', 'users']);
|
|
571
615
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
'version',
|
|
576
|
-
]);
|
|
577
|
-
}
|
|
616
|
+
// Check metadata keys are sorted
|
|
617
|
+
if (hasKey(parsed, 'metadata') && isRecord(parsed.metadata)) {
|
|
618
|
+
const metadataKeys = Object.keys(parsed.metadata);
|
|
578
619
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
hasKey(parsed, 'users') &&
|
|
582
|
-
Arr.isArray(parsed.users) &&
|
|
583
|
-
Arr.isNonEmpty(parsed.users)
|
|
584
|
-
) {
|
|
585
|
-
const firstUser = parsed.users[0];
|
|
586
|
-
if (isRecord(firstUser)) {
|
|
587
|
-
const userKeys = Object.keys(firstUser);
|
|
620
|
+
assert.deepStrictEqual(metadataKeys, ['author', 'created', 'version']);
|
|
621
|
+
}
|
|
588
622
|
|
|
589
|
-
|
|
590
|
-
|
|
623
|
+
// Check user object keys are sorted
|
|
624
|
+
if (
|
|
625
|
+
hasKey(parsed, 'users') &&
|
|
626
|
+
Arr.isArray(parsed.users) &&
|
|
627
|
+
Arr.isNonEmpty(parsed.users)
|
|
628
|
+
) {
|
|
629
|
+
const firstUser = parsed.users[0];
|
|
630
|
+
|
|
631
|
+
if (isRecord(firstUser)) {
|
|
632
|
+
const userKeys = Object.keys(firstUser);
|
|
633
|
+
|
|
634
|
+
assert.deepStrictEqual(userKeys, ['active', 'id', 'name']);
|
|
591
635
|
}
|
|
592
636
|
}
|
|
593
637
|
}
|
|
@@ -595,30 +639,32 @@ describe('stringifySortedKey', () => {
|
|
|
595
639
|
|
|
596
640
|
test('should handle formatting with space parameter', () => {
|
|
597
641
|
const obj = { b: 2, a: 1 };
|
|
642
|
+
|
|
598
643
|
const result = Json.stringifySortedKey(obj, 2);
|
|
599
644
|
|
|
600
|
-
|
|
645
|
+
assert.isTrue(Result.isOk(result));
|
|
601
646
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
}
|
|
647
|
+
expect(result.value).toContain('\n');
|
|
648
|
+
|
|
649
|
+
expect(result.value).toContain(' ');
|
|
650
|
+
|
|
651
|
+
expect(result.value).toMatch(/\{\s+"a": 1,\s+"b": 2\s+\}/u);
|
|
607
652
|
});
|
|
608
653
|
|
|
609
654
|
test('should produce deterministic output', () => {
|
|
610
655
|
const obj1 = { c: 3, a: 1, b: 2 };
|
|
656
|
+
|
|
611
657
|
const obj2 = { b: 2, a: 1, c: 3 };
|
|
612
658
|
|
|
613
659
|
const result1 = Json.stringifySortedKey(obj1);
|
|
660
|
+
|
|
614
661
|
const result2 = Json.stringifySortedKey(obj2);
|
|
615
662
|
|
|
616
|
-
|
|
617
|
-
expect(Result.isOk(result2)).toBe(true);
|
|
663
|
+
assert.isTrue(Result.isOk(result1));
|
|
618
664
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
665
|
+
assert.isTrue(Result.isOk(result2));
|
|
666
|
+
|
|
667
|
+
expect(result1.value).toBe(result2.value);
|
|
622
668
|
});
|
|
623
669
|
|
|
624
670
|
test('should handle problematic objects', () => {
|
|
@@ -627,16 +673,18 @@ describe('stringifySortedKey', () => {
|
|
|
627
673
|
normal: string;
|
|
628
674
|
circular: { self?: CircularObj };
|
|
629
675
|
};
|
|
676
|
+
|
|
630
677
|
const mut_problematicObj: CircularObj = {
|
|
631
678
|
normal: 'value',
|
|
632
679
|
circular: {},
|
|
633
680
|
};
|
|
681
|
+
|
|
634
682
|
mut_problematicObj.circular.self = mut_problematicObj;
|
|
635
683
|
|
|
636
684
|
const result = Json.stringifySortedKey(mut_problematicObj);
|
|
637
685
|
|
|
638
686
|
// This may throw due to circular reference during key extraction
|
|
639
|
-
|
|
687
|
+
assert.isTrue(Result.isErr(result));
|
|
640
688
|
|
|
641
689
|
if (Result.isErr(result)) {
|
|
642
690
|
expectTypeOf(result.value).toBeString();
|
|
@@ -650,11 +698,9 @@ describe('stringifySortedKey', () => {
|
|
|
650
698
|
test('should handle empty object', () => {
|
|
651
699
|
const result = Json.stringifySortedKey({});
|
|
652
700
|
|
|
653
|
-
|
|
701
|
+
assert.isTrue(Result.isOk(result));
|
|
654
702
|
|
|
655
|
-
|
|
656
|
-
expect(result.value).toBe('{}');
|
|
657
|
-
}
|
|
703
|
+
expect(result.value).toBe('{}');
|
|
658
704
|
});
|
|
659
705
|
|
|
660
706
|
test('should handle deeply nested structures', () => {
|
|
@@ -672,25 +718,27 @@ describe('stringifySortedKey', () => {
|
|
|
672
718
|
|
|
673
719
|
const result = Json.stringifySortedKey(deep);
|
|
674
720
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
)
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
721
|
+
assert.isTrue(Result.isOk(result));
|
|
722
|
+
|
|
723
|
+
assert.isTrue(isString(result.value));
|
|
724
|
+
|
|
725
|
+
const parsed: unknown = JSON.parse(result.value);
|
|
726
|
+
|
|
727
|
+
if (isRecord(parsed) && hasKey(parsed, 'level1')) {
|
|
728
|
+
const level1 = parsed.level1;
|
|
729
|
+
|
|
730
|
+
if (isRecord(level1)) {
|
|
731
|
+
assert.deepStrictEqual(Object.keys(level1), ['a', 'z']);
|
|
732
|
+
|
|
733
|
+
if (
|
|
734
|
+
hasKey(level1, 'a') &&
|
|
735
|
+
isRecord(level1.a) &&
|
|
736
|
+
hasKey(level1.a, 'nested')
|
|
737
|
+
) {
|
|
738
|
+
const nested = level1.a.nested;
|
|
739
|
+
|
|
740
|
+
if (isRecord(nested)) {
|
|
741
|
+
assert.deepStrictEqual(Object.keys(nested), ['x', 'y']);
|
|
694
742
|
}
|
|
695
743
|
}
|
|
696
744
|
}
|