@vielzeug/arsenal 2.1.0 → 26.10.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 +5 -18
- package/dist/_common/_lruMap.cjs +1 -1
- package/dist/_common/_lruMap.cjs.map +1 -1
- package/dist/_common/_lruMap.js +1 -17
- package/dist/_common/_lruMap.js.map +1 -1
- package/dist/_common/_selectorSet.cjs +1 -1
- package/dist/_common/_selectorSet.cjs.map +1 -1
- package/dist/_common/_selectorSet.js +1 -15
- package/dist/_common/_selectorSet.js.map +1 -1
- package/dist/_common/unsafePaths.cjs +1 -1
- package/dist/_common/unsafePaths.cjs.map +1 -1
- package/dist/_common/unsafePaths.js +1 -12
- package/dist/_common/unsafePaths.js.map +1 -1
- package/dist/_dev.cjs +1 -1
- package/dist/_dev.cjs.map +1 -1
- package/dist/_dev.js +1 -5
- package/dist/_dev.js.map +1 -1
- package/dist/array/chunk.cjs +1 -1
- package/dist/array/chunk.cjs.map +1 -1
- package/dist/array/chunk.d.ts +1 -1
- package/dist/array/chunk.d.ts.map +1 -1
- package/dist/array/chunk.js +1 -9
- package/dist/array/chunk.js.map +1 -1
- package/dist/array/compact.cjs +1 -1
- package/dist/array/compact.cjs.map +1 -1
- package/dist/array/compact.d.ts +1 -1
- package/dist/array/compact.d.ts.map +1 -1
- package/dist/array/compact.js +1 -7
- package/dist/array/compact.js.map +1 -1
- package/dist/array/compare.cjs +1 -1
- package/dist/array/compare.cjs.map +1 -1
- package/dist/array/compare.js +1 -18
- package/dist/array/compare.js.map +1 -1
- package/dist/array/compareBy.cjs +1 -1
- package/dist/array/compareBy.cjs.map +1 -1
- package/dist/array/compareBy.js +1 -15
- package/dist/array/compareBy.js.map +1 -1
- package/dist/array/contains.cjs +1 -1
- package/dist/array/contains.cjs.map +1 -1
- package/dist/array/contains.d.ts +1 -1
- package/dist/array/contains.d.ts.map +1 -1
- package/dist/array/contains.js +1 -8
- package/dist/array/contains.js.map +1 -1
- package/dist/array/countBy.cjs +1 -1
- package/dist/array/countBy.cjs.map +1 -1
- package/dist/array/countBy.d.ts +1 -1
- package/dist/array/countBy.d.ts.map +1 -1
- package/dist/array/countBy.js +1 -13
- package/dist/array/countBy.js.map +1 -1
- package/dist/array/difference.cjs +1 -1
- package/dist/array/difference.cjs.map +1 -1
- package/dist/array/difference.d.ts +4 -2
- package/dist/array/difference.d.ts.map +1 -1
- package/dist/array/difference.js +1 -13
- package/dist/array/difference.js.map +1 -1
- package/dist/array/drop.cjs +1 -1
- package/dist/array/drop.cjs.map +1 -1
- package/dist/array/drop.d.ts +1 -1
- package/dist/array/drop.d.ts.map +1 -1
- package/dist/array/drop.js +1 -8
- package/dist/array/drop.js.map +1 -1
- package/dist/array/dropLast.cjs +1 -1
- package/dist/array/dropLast.cjs.map +1 -1
- package/dist/array/dropLast.d.ts +1 -1
- package/dist/array/dropLast.d.ts.map +1 -1
- package/dist/array/dropLast.js +1 -8
- package/dist/array/dropLast.js.map +1 -1
- package/dist/array/filterMap.cjs +1 -1
- package/dist/array/filterMap.cjs.map +1 -1
- package/dist/array/filterMap.d.ts +3 -1
- package/dist/array/filterMap.d.ts.map +1 -1
- package/dist/array/filterMap.js +1 -12
- package/dist/array/filterMap.js.map +1 -1
- package/dist/array/first.cjs +1 -1
- package/dist/array/first.cjs.map +1 -1
- package/dist/array/first.d.ts +1 -1
- package/dist/array/first.d.ts.map +1 -1
- package/dist/array/first.js +1 -7
- package/dist/array/first.js.map +1 -1
- package/dist/array/groupBy.cjs +1 -1
- package/dist/array/groupBy.cjs.map +1 -1
- package/dist/array/groupBy.d.ts +1 -1
- package/dist/array/groupBy.d.ts.map +1 -1
- package/dist/array/groupBy.js +1 -13
- package/dist/array/groupBy.js.map +1 -1
- package/dist/array/index.cjs +1 -1
- package/dist/array/index.d.ts +0 -1
- package/dist/array/index.d.ts.map +1 -1
- package/dist/array/index.js +1 -29
- package/dist/array/indexBy.cjs +1 -1
- package/dist/array/indexBy.cjs.map +1 -1
- package/dist/array/indexBy.d.ts +1 -1
- package/dist/array/indexBy.d.ts.map +1 -1
- package/dist/array/indexBy.js +1 -13
- package/dist/array/indexBy.js.map +1 -1
- package/dist/array/intersection.cjs +1 -1
- package/dist/array/intersection.cjs.map +1 -1
- package/dist/array/intersection.d.ts +4 -2
- package/dist/array/intersection.d.ts.map +1 -1
- package/dist/array/intersection.js +1 -13
- package/dist/array/intersection.js.map +1 -1
- package/dist/array/last.cjs +1 -1
- package/dist/array/last.cjs.map +1 -1
- package/dist/array/last.d.ts +1 -1
- package/dist/array/last.d.ts.map +1 -1
- package/dist/array/last.js +1 -7
- package/dist/array/last.js.map +1 -1
- package/dist/array/partition.cjs +1 -1
- package/dist/array/partition.cjs.map +1 -1
- package/dist/array/partition.d.ts +3 -1
- package/dist/array/partition.d.ts.map +1 -1
- package/dist/array/partition.js +1 -9
- package/dist/array/partition.js.map +1 -1
- package/dist/array/replace.cjs +1 -1
- package/dist/array/replace.cjs.map +1 -1
- package/dist/array/replace.d.ts +2 -15
- package/dist/array/replace.d.ts.map +1 -1
- package/dist/array/replace.js +1 -12
- package/dist/array/replace.js.map +1 -1
- package/dist/array/rotate.cjs +1 -1
- package/dist/array/rotate.cjs.map +1 -1
- package/dist/array/rotate.d.ts +5 -17
- package/dist/array/rotate.d.ts.map +1 -1
- package/dist/array/rotate.js +1 -9
- package/dist/array/rotate.js.map +1 -1
- package/dist/array/search.cjs +1 -1
- package/dist/array/search.cjs.map +1 -1
- package/dist/array/search.js +1 -29
- package/dist/array/search.js.map +1 -1
- package/dist/array/sort.cjs +1 -1
- package/dist/array/sort.cjs.map +1 -1
- package/dist/array/sort.d.ts +2 -2
- package/dist/array/sort.d.ts.map +1 -1
- package/dist/array/sort.js +1 -14
- package/dist/array/sort.js.map +1 -1
- package/dist/array/take.cjs +1 -1
- package/dist/array/take.cjs.map +1 -1
- package/dist/array/take.d.ts +1 -1
- package/dist/array/take.d.ts.map +1 -1
- package/dist/array/take.js +1 -8
- package/dist/array/take.js.map +1 -1
- package/dist/array/takeLast.cjs +1 -1
- package/dist/array/takeLast.cjs.map +1 -1
- package/dist/array/takeLast.d.ts +1 -1
- package/dist/array/takeLast.d.ts.map +1 -1
- package/dist/array/takeLast.js +1 -8
- package/dist/array/takeLast.js.map +1 -1
- package/dist/array/toggle.cjs +1 -1
- package/dist/array/toggle.cjs.map +1 -1
- package/dist/array/toggle.d.ts +1 -1
- package/dist/array/toggle.d.ts.map +1 -1
- package/dist/array/toggle.js +1 -8
- package/dist/array/toggle.js.map +1 -1
- package/dist/array/union.cjs +1 -1
- package/dist/array/union.cjs.map +1 -1
- package/dist/array/union.d.ts +4 -2
- package/dist/array/union.d.ts.map +1 -1
- package/dist/array/union.js +1 -8
- package/dist/array/union.js.map +1 -1
- package/dist/array/uniq.cjs +1 -1
- package/dist/array/uniq.cjs.map +1 -1
- package/dist/array/uniq.d.ts +1 -1
- package/dist/array/uniq.d.ts.map +1 -1
- package/dist/array/uniq.js +1 -8
- package/dist/array/uniq.js.map +1 -1
- package/dist/array/unzip.cjs +1 -1
- package/dist/array/unzip.cjs.map +1 -1
- package/dist/array/unzip.js +1 -10
- package/dist/array/unzip.js.map +1 -1
- package/dist/array/zip.cjs +1 -1
- package/dist/array/zip.cjs.map +1 -1
- package/dist/array/zip.d.ts +1 -1
- package/dist/array/zip.d.ts.map +1 -1
- package/dist/array/zip.js +1 -10
- package/dist/array/zip.js.map +1 -1
- package/dist/arsenal.cjs +1 -1
- package/dist/arsenal.cjs.map +1 -1
- package/dist/arsenal.iife.js +1 -1
- package/dist/arsenal.iife.js.map +1 -1
- package/dist/arsenal.js +1 -1
- package/dist/arsenal.js.map +1 -1
- package/dist/async/abortError.cjs +1 -1
- package/dist/async/abortError.cjs.map +1 -1
- package/dist/async/abortError.d.ts +3 -2
- package/dist/async/abortError.d.ts.map +1 -1
- package/dist/async/abortError.js +1 -7
- package/dist/async/abortError.js.map +1 -1
- package/dist/async/abortable.cjs +1 -1
- package/dist/async/abortable.cjs.map +1 -1
- package/dist/async/abortable.js +1 -11
- package/dist/async/abortable.js.map +1 -1
- package/dist/async/attempt.cjs +1 -1
- package/dist/async/attempt.cjs.map +1 -1
- package/dist/async/attempt.js +1 -23
- package/dist/async/attempt.js.map +1 -1
- package/dist/async/backoff.cjs +1 -1
- package/dist/async/backoff.cjs.map +1 -1
- package/dist/async/backoff.js +1 -7
- package/dist/async/backoff.js.map +1 -1
- package/dist/async/index.js +1 -10
- package/dist/async/parallel.cjs +1 -1
- package/dist/async/parallel.cjs.map +1 -1
- package/dist/async/parallel.js +1 -24
- package/dist/async/parallel.js.map +1 -1
- package/dist/async/retry.cjs +1 -1
- package/dist/async/retry.cjs.map +1 -1
- package/dist/async/retry.d.ts +4 -6
- package/dist/async/retry.d.ts.map +1 -1
- package/dist/async/retry.js +1 -24
- package/dist/async/retry.js.map +1 -1
- package/dist/async/sleep.cjs +1 -1
- package/dist/async/sleep.cjs.map +1 -1
- package/dist/async/sleep.js +1 -15
- package/dist/async/sleep.js.map +1 -1
- package/dist/async/taskPool.cjs +1 -1
- package/dist/async/taskPool.cjs.map +1 -1
- package/dist/async/taskPool.js +1 -50
- package/dist/async/taskPool.js.map +1 -1
- package/dist/async/waitFor.cjs +1 -1
- package/dist/async/waitFor.cjs.map +1 -1
- package/dist/async/waitFor.js +1 -12
- package/dist/async/waitFor.js.map +1 -1
- package/dist/cache/cache.cjs +1 -1
- package/dist/cache/cache.cjs.map +1 -1
- package/dist/cache/cache.d.ts +1 -0
- package/dist/cache/cache.d.ts.map +1 -1
- package/dist/cache/cache.js +1 -58
- package/dist/cache/cache.js.map +1 -1
- package/dist/cache/index.js +1 -3
- package/dist/cache/memo.cjs +1 -1
- package/dist/cache/memo.cjs.map +1 -1
- package/dist/cache/memo.js +1 -37
- package/dist/cache/memo.js.map +1 -1
- package/dist/encoding/base64url.cjs +2 -0
- package/dist/encoding/base64url.cjs.map +1 -0
- package/dist/encoding/base64url.d.ts +9 -0
- package/dist/encoding/base64url.d.ts.map +1 -0
- package/dist/encoding/base64url.js +2 -0
- package/dist/encoding/base64url.js.map +1 -0
- package/dist/encoding/index.cjs +1 -0
- package/dist/encoding/index.d.ts +2 -0
- package/dist/encoding/index.d.ts.map +1 -0
- package/dist/encoding/index.js +1 -0
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +1 -9
- package/dist/errors.js.map +1 -1
- package/dist/function/assert.cjs +1 -1
- package/dist/function/assert.cjs.map +1 -1
- package/dist/function/assert.d.ts +1 -1
- package/dist/function/assert.js +1 -7
- package/dist/function/assert.js.map +1 -1
- package/dist/function/debounce.cjs +1 -1
- package/dist/function/debounce.cjs.map +1 -1
- package/dist/function/debounce.js +1 -26
- package/dist/function/debounce.js.map +1 -1
- package/dist/function/index.cjs +1 -1
- package/dist/function/index.d.ts +1 -0
- package/dist/function/index.d.ts.map +1 -1
- package/dist/function/index.js +1 -8
- package/dist/function/once.cjs +1 -1
- package/dist/function/once.cjs.map +1 -1
- package/dist/function/once.js +1 -10
- package/dist/function/once.js.map +1 -1
- package/dist/function/pipe.cjs +1 -1
- package/dist/function/pipe.cjs.map +1 -1
- package/dist/function/pipe.js +1 -9
- package/dist/function/pipe.js.map +1 -1
- package/dist/function/runAll.cjs +1 -1
- package/dist/function/runAll.cjs.map +1 -1
- package/dist/function/runAll.js +1 -18
- package/dist/function/runAll.js.map +1 -1
- package/dist/function/tap.cjs +1 -1
- package/dist/function/tap.cjs.map +1 -1
- package/dist/function/tap.js +1 -7
- package/dist/function/tap.js.map +1 -1
- package/dist/function/tapper.cjs +2 -0
- package/dist/function/tapper.cjs.map +1 -0
- package/dist/function/tapper.d.ts +27 -0
- package/dist/function/tapper.d.ts.map +1 -0
- package/dist/function/tapper.js +2 -0
- package/dist/function/tapper.js.map +1 -0
- package/dist/function/throttle.cjs +1 -1
- package/dist/function/throttle.cjs.map +1 -1
- package/dist/function/throttle.js +1 -35
- package/dist/function/throttle.js.map +1 -1
- package/dist/guards/combinators.cjs +1 -1
- package/dist/guards/combinators.cjs.map +1 -1
- package/dist/guards/combinators.js +1 -16
- package/dist/guards/combinators.js.map +1 -1
- package/dist/guards/index.cjs +1 -1
- package/dist/guards/index.js +1 -17
- package/dist/guards/isAbortError.cjs +1 -1
- package/dist/guards/isAbortError.cjs.map +1 -1
- package/dist/guards/isAbortError.js +1 -7
- package/dist/guards/isAbortError.js.map +1 -1
- package/dist/guards/isDate.cjs +1 -1
- package/dist/guards/isDate.cjs.map +1 -1
- package/dist/guards/isDate.js +1 -7
- package/dist/guards/isDate.js.map +1 -1
- package/dist/guards/isDefined.cjs +1 -1
- package/dist/guards/isDefined.cjs.map +1 -1
- package/dist/guards/isDefined.js +1 -7
- package/dist/guards/isDefined.js.map +1 -1
- package/dist/guards/isEmpty.cjs +1 -1
- package/dist/guards/isEmpty.cjs.map +1 -1
- package/dist/guards/isEmpty.d.ts.map +1 -1
- package/dist/guards/isEmpty.js +1 -9
- package/dist/guards/isEmpty.js.map +1 -1
- package/dist/guards/isEqual.cjs +1 -1
- package/dist/guards/isEqual.cjs.map +1 -1
- package/dist/guards/isEqual.js +1 -33
- package/dist/guards/isEqual.js.map +1 -1
- package/dist/guards/isError.cjs +1 -1
- package/dist/guards/isError.cjs.map +1 -1
- package/dist/guards/isError.js +1 -7
- package/dist/guards/isError.js.map +1 -1
- package/dist/guards/isFunction.cjs +1 -1
- package/dist/guards/isFunction.cjs.map +1 -1
- package/dist/guards/isFunction.d.ts +1 -1
- package/dist/guards/isFunction.d.ts.map +1 -1
- package/dist/guards/isFunction.js +1 -7
- package/dist/guards/isFunction.js.map +1 -1
- package/dist/guards/isMatch.cjs +1 -1
- package/dist/guards/isMatch.cjs.map +1 -1
- package/dist/guards/isMatch.js +1 -22
- package/dist/guards/isMatch.js.map +1 -1
- package/dist/guards/isNil.cjs +1 -1
- package/dist/guards/isNil.cjs.map +1 -1
- package/dist/guards/isNil.js +1 -7
- package/dist/guards/isNil.js.map +1 -1
- package/dist/guards/isNumber.cjs +1 -1
- package/dist/guards/isNumber.cjs.map +1 -1
- package/dist/guards/isNumber.js +1 -7
- package/dist/guards/isNumber.js.map +1 -1
- package/dist/guards/isPlainObject.cjs +1 -1
- package/dist/guards/isPlainObject.cjs.map +1 -1
- package/dist/guards/isPlainObject.js +1 -9
- package/dist/guards/isPlainObject.js.map +1 -1
- package/dist/guards/isPrimitive.cjs +1 -1
- package/dist/guards/isPrimitive.cjs.map +1 -1
- package/dist/guards/isPrimitive.d.ts +4 -17
- package/dist/guards/isPrimitive.d.ts.map +1 -1
- package/dist/guards/isPrimitive.js +1 -8
- package/dist/guards/isPrimitive.js.map +1 -1
- package/dist/guards/isPromise.cjs +1 -1
- package/dist/guards/isPromise.cjs.map +1 -1
- package/dist/guards/isPromise.js +1 -7
- package/dist/guards/isPromise.js.map +1 -1
- package/dist/guards/isRegex.cjs +1 -1
- package/dist/guards/isRegex.cjs.map +1 -1
- package/dist/guards/isRegex.js +1 -7
- package/dist/guards/isRegex.js.map +1 -1
- package/dist/guards/shallowEqual.cjs +1 -1
- package/dist/guards/shallowEqual.cjs.map +1 -1
- package/dist/guards/shallowEqual.js +1 -19
- package/dist/guards/shallowEqual.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -30
- package/dist/math/allocate.cjs +1 -1
- package/dist/math/allocate.cjs.map +1 -1
- package/dist/math/allocate.js +1 -18
- package/dist/math/allocate.js.map +1 -1
- package/dist/math/average.cjs +1 -1
- package/dist/math/average.cjs.map +1 -1
- package/dist/math/average.d.ts +3 -2
- package/dist/math/average.d.ts.map +1 -1
- package/dist/math/average.js +1 -13
- package/dist/math/average.js.map +1 -1
- package/dist/math/clamp.cjs +1 -1
- package/dist/math/clamp.cjs.map +1 -1
- package/dist/math/clamp.js +1 -7
- package/dist/math/clamp.js.map +1 -1
- package/dist/math/gcd.cjs +1 -1
- package/dist/math/gcd.cjs.map +1 -1
- package/dist/math/gcd.d.ts.map +1 -1
- package/dist/math/gcd.js +1 -12
- package/dist/math/gcd.js.map +1 -1
- package/dist/math/index.cjs +1 -1
- package/dist/math/index.d.ts +0 -1
- package/dist/math/index.d.ts.map +1 -1
- package/dist/math/index.js +1 -17
- package/dist/math/lcm.cjs +1 -1
- package/dist/math/lcm.cjs.map +1 -1
- package/dist/math/lcm.d.ts.map +1 -1
- package/dist/math/lcm.js +1 -8
- package/dist/math/lcm.js.map +1 -1
- package/dist/math/lerp.cjs +1 -1
- package/dist/math/lerp.cjs.map +1 -1
- package/dist/math/lerp.js +1 -7
- package/dist/math/lerp.js.map +1 -1
- package/dist/math/linspace.cjs +1 -1
- package/dist/math/linspace.cjs.map +1 -1
- package/dist/math/linspace.d.ts.map +1 -1
- package/dist/math/linspace.js +1 -10
- package/dist/math/linspace.js.map +1 -1
- package/dist/math/median.cjs +1 -1
- package/dist/math/median.cjs.map +1 -1
- package/dist/math/median.d.ts +1 -1
- package/dist/math/median.d.ts.map +1 -1
- package/dist/math/median.js +1 -11
- package/dist/math/median.js.map +1 -1
- package/dist/math/mod.cjs +1 -1
- package/dist/math/mod.cjs.map +1 -1
- package/dist/math/mod.js +1 -8
- package/dist/math/mod.js.map +1 -1
- package/dist/math/normalize.cjs +1 -1
- package/dist/math/normalize.cjs.map +1 -1
- package/dist/math/normalize.js +1 -8
- package/dist/math/normalize.js.map +1 -1
- package/dist/math/range.cjs +1 -1
- package/dist/math/range.cjs.map +1 -1
- package/dist/math/range.js +1 -25
- package/dist/math/range.js.map +1 -1
- package/dist/math/round.cjs +1 -1
- package/dist/math/round.cjs.map +1 -1
- package/dist/math/round.js +1 -9
- package/dist/math/round.js.map +1 -1
- package/dist/math/standardDeviation.cjs +1 -1
- package/dist/math/standardDeviation.cjs.map +1 -1
- package/dist/math/standardDeviation.d.ts +1 -1
- package/dist/math/standardDeviation.d.ts.map +1 -1
- package/dist/math/standardDeviation.js +1 -8
- package/dist/math/standardDeviation.js.map +1 -1
- package/dist/math/sum.cjs +1 -1
- package/dist/math/sum.cjs.map +1 -1
- package/dist/math/sum.d.ts +1 -1
- package/dist/math/sum.d.ts.map +1 -1
- package/dist/math/sum.js +1 -11
- package/dist/math/sum.js.map +1 -1
- package/dist/math/variance.cjs +1 -1
- package/dist/math/variance.cjs.map +1 -1
- package/dist/math/variance.d.ts +1 -1
- package/dist/math/variance.d.ts.map +1 -1
- package/dist/math/variance.js +1 -10
- package/dist/math/variance.js.map +1 -1
- package/dist/object/defaults.cjs +1 -1
- package/dist/object/defaults.cjs.map +1 -1
- package/dist/object/defaults.js +1 -11
- package/dist/object/defaults.js.map +1 -1
- package/dist/object/diff.cjs +1 -1
- package/dist/object/diff.cjs.map +1 -1
- package/dist/object/diff.d.ts +1 -1
- package/dist/object/diff.d.ts.map +1 -1
- package/dist/object/diff.js +1 -26
- package/dist/object/diff.js.map +1 -1
- package/dist/object/filterValues.cjs +1 -1
- package/dist/object/filterValues.cjs.map +1 -1
- package/dist/object/filterValues.js +1 -10
- package/dist/object/filterValues.js.map +1 -1
- package/dist/object/flattenPaths.cjs +1 -1
- package/dist/object/flattenPaths.cjs.map +1 -1
- package/dist/object/flattenPaths.js +1 -30
- package/dist/object/flattenPaths.js.map +1 -1
- package/dist/object/getPath.cjs +1 -1
- package/dist/object/getPath.cjs.map +1 -1
- package/dist/object/getPath.js +1 -25
- package/dist/object/getPath.js.map +1 -1
- package/dist/object/hash.cjs +1 -1
- package/dist/object/hash.cjs.map +1 -1
- package/dist/object/hash.js +1 -27
- package/dist/object/hash.js.map +1 -1
- package/dist/object/index.js +1 -15
- package/dist/object/invert.cjs +1 -1
- package/dist/object/invert.cjs.map +1 -1
- package/dist/object/invert.js +1 -10
- package/dist/object/invert.js.map +1 -1
- package/dist/object/mapKeys.cjs +1 -1
- package/dist/object/mapKeys.cjs.map +1 -1
- package/dist/object/mapKeys.js +1 -14
- package/dist/object/mapKeys.js.map +1 -1
- package/dist/object/mapValues.cjs +1 -1
- package/dist/object/mapValues.cjs.map +1 -1
- package/dist/object/mapValues.js +1 -10
- package/dist/object/mapValues.js.map +1 -1
- package/dist/object/merge.cjs +1 -1
- package/dist/object/merge.cjs.map +1 -1
- package/dist/object/merge.js +1 -25
- package/dist/object/merge.js.map +1 -1
- package/dist/object/omit.cjs +1 -1
- package/dist/object/omit.cjs.map +1 -1
- package/dist/object/omit.js +1 -10
- package/dist/object/omit.js.map +1 -1
- package/dist/object/pick.cjs +1 -1
- package/dist/object/pick.cjs.map +1 -1
- package/dist/object/pick.js +1 -10
- package/dist/object/pick.js.map +1 -1
- package/dist/object/prune.cjs +1 -1
- package/dist/object/prune.cjs.map +1 -1
- package/dist/object/prune.d.ts.map +1 -1
- package/dist/object/prune.js +1 -34
- package/dist/object/prune.js.map +1 -1
- package/dist/object/tryParseJson.cjs +1 -1
- package/dist/object/tryParseJson.cjs.map +1 -1
- package/dist/object/tryParseJson.js +1 -17
- package/dist/object/tryParseJson.js.map +1 -1
- package/dist/random/_index.cjs +1 -1
- package/dist/random/_index.cjs.map +1 -1
- package/dist/random/_index.d.ts +1 -1
- package/dist/random/_index.d.ts.map +1 -1
- package/dist/random/_index.js +1 -9
- package/dist/random/_index.js.map +1 -1
- package/dist/random/draw.cjs +1 -1
- package/dist/random/draw.cjs.map +1 -1
- package/dist/random/draw.js +1 -20
- package/dist/random/draw.js.map +1 -1
- package/dist/random/index.cjs +1 -1
- package/dist/random/index.d.ts +0 -1
- package/dist/random/index.d.ts.map +1 -1
- package/dist/random/index.js +1 -5
- package/dist/random/random.cjs +1 -1
- package/dist/random/random.cjs.map +1 -1
- package/dist/random/random.js +1 -9
- package/dist/random/random.js.map +1 -1
- package/dist/random/shuffle.cjs +1 -1
- package/dist/random/shuffle.cjs.map +1 -1
- package/dist/random/shuffle.js +1 -13
- package/dist/random/shuffle.js.map +1 -1
- package/dist/random/source.cjs +2 -0
- package/dist/random/source.cjs.map +1 -0
- package/dist/random/source.d.ts +2 -0
- package/dist/random/source.d.ts.map +1 -1
- package/dist/random/source.js +2 -0
- package/dist/random/source.js.map +1 -0
- package/dist/string/_caseUtils.cjs +1 -1
- package/dist/string/_caseUtils.cjs.map +1 -1
- package/dist/string/_caseUtils.js +1 -12
- package/dist/string/_caseUtils.js.map +1 -1
- package/dist/string/camelCase.cjs +1 -1
- package/dist/string/camelCase.cjs.map +1 -1
- package/dist/string/camelCase.js +1 -8
- package/dist/string/camelCase.js.map +1 -1
- package/dist/string/escape.cjs +1 -1
- package/dist/string/escape.cjs.map +1 -1
- package/dist/string/escape.js +1 -14
- package/dist/string/escape.js.map +1 -1
- package/dist/string/index.cjs +1 -1
- package/dist/string/index.d.ts +1 -1
- package/dist/string/index.d.ts.map +1 -1
- package/dist/string/index.js +1 -12
- package/dist/string/kebabCase.cjs +1 -1
- package/dist/string/kebabCase.cjs.map +1 -1
- package/dist/string/kebabCase.js +1 -8
- package/dist/string/kebabCase.js.map +1 -1
- package/dist/string/padCenter.cjs +2 -0
- package/dist/string/padCenter.cjs.map +1 -0
- package/dist/string/padCenter.d.ts +3 -0
- package/dist/string/padCenter.d.ts.map +1 -0
- package/dist/string/padCenter.js +2 -0
- package/dist/string/padCenter.js.map +1 -0
- package/dist/string/pascalCase.cjs +1 -1
- package/dist/string/pascalCase.cjs.map +1 -1
- package/dist/string/pascalCase.js +1 -8
- package/dist/string/pascalCase.js.map +1 -1
- package/dist/string/similarity.cjs +1 -1
- package/dist/string/similarity.cjs.map +1 -1
- package/dist/string/similarity.js +1 -22
- package/dist/string/similarity.js.map +1 -1
- package/dist/string/snakeCase.cjs +1 -1
- package/dist/string/snakeCase.cjs.map +1 -1
- package/dist/string/snakeCase.js +1 -8
- package/dist/string/snakeCase.js.map +1 -1
- package/dist/string/titleCase.cjs +1 -1
- package/dist/string/titleCase.cjs.map +1 -1
- package/dist/string/titleCase.js +1 -8
- package/dist/string/titleCase.js.map +1 -1
- package/dist/string/truncate.cjs +1 -1
- package/dist/string/truncate.cjs.map +1 -1
- package/dist/string/truncate.js +1 -15
- package/dist/string/truncate.js.map +1 -1
- package/dist/string/unescape.cjs +1 -1
- package/dist/string/unescape.cjs.map +1 -1
- package/dist/string/unescape.js +1 -14
- package/dist/string/unescape.js.map +1 -1
- package/dist/string/words.cjs +1 -1
- package/dist/string/words.cjs.map +1 -1
- package/dist/string/words.js +1 -9
- package/dist/string/words.js.map +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +16 -8
- package/dist/array/flatten.cjs +0 -2
- package/dist/array/flatten.cjs.map +0 -1
- package/dist/array/flatten.d.ts +0 -5
- package/dist/array/flatten.d.ts.map +0 -1
- package/dist/array/flatten.js +0 -11
- package/dist/array/flatten.js.map +0 -1
- package/dist/math/percent.cjs +0 -2
- package/dist/math/percent.cjs.map +0 -1
- package/dist/math/percent.d.ts +0 -19
- package/dist/math/percent.d.ts.map +0 -1
- package/dist/math/percent.js +0 -8
- package/dist/math/percent.js.map +0 -1
- package/dist/random/uuid.cjs +0 -2
- package/dist/random/uuid.cjs.map +0 -1
- package/dist/random/uuid.d.ts +0 -12
- package/dist/random/uuid.d.ts.map +0 -1
- package/dist/random/uuid.js +0 -8
- package/dist/random/uuid.js.map +0 -1
- package/dist/string/pad.cjs +0 -2
- package/dist/string/pad.cjs.map +0 -1
- package/dist/string/pad.d.ts +0 -5
- package/dist/string/pad.d.ts.map +0 -1
- package/dist/string/pad.js +0 -10
- package/dist/string/pad.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standardDeviation.js","names":[],"sources":["../../src/math/standardDeviation.ts"],"sourcesContent":["import { variance } from './variance';\n\n/**\n * Computes the population standard deviation (square root of `variance`) of an array of\n * numbers, or of values mapped by a callback.\n *\n * @example\n * ```ts\n * standardDeviation([2, 4, 4, 4, 5, 5, 7, 9]); // 2\n * standardDeviation([]); // 0\n * ```\n *\n * @param array - The array to compute standard deviation over.\n * @param callback - An optional callback to map each item to a number.\n * @returns The population standard deviation, or `0` for an empty array.\n */\nexport function standardDeviation<T>(array: T[], callback?: (item: T) => number): number {\n return Math.sqrt(variance(array, callback));\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"standardDeviation.js","names":[],"sources":["../../src/math/standardDeviation.ts"],"sourcesContent":["import { variance } from './variance';\n\n/**\n * Computes the population standard deviation (square root of `variance`) of an array of\n * numbers, or of values mapped by a callback.\n *\n * @example\n * ```ts\n * standardDeviation([2, 4, 4, 4, 5, 5, 7, 9]); // 2\n * standardDeviation([]); // 0\n * ```\n *\n * @param array - The array to compute standard deviation over.\n * @param callback - An optional callback to map each item to a number.\n * @returns The population standard deviation, or `0` for an empty array.\n */\nexport function standardDeviation<T>(array: readonly T[], callback?: (item: T) => number): number {\n return Math.sqrt(variance(array, callback));\n}\n"],"mappings":"yCAgBA,SAAgB,kBAAqB,EAAqB,EAAwC,CAChG,OAAO,KAAK,KAAK,EAAS,EAAO,CAAQ,CAAC,CAC5C"}
|
package/dist/math/sum.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function sum(e,t){return e.length===0?0:e.reduce((e,n)=>{let r=t?t(n):n;if(!Number.isFinite(r))throw TypeError(`sum: encountered a non-numeric value; provide a callback to map non-number items`);return e+r},0)}exports.sum=sum;
|
|
2
2
|
//# sourceMappingURL=sum.cjs.map
|
package/dist/math/sum.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sum.cjs","names":[],"sources":["../../src/math/sum.ts"],"sourcesContent":["/**\n * Sum numbers in an array or numbers mapped by a callback function.\n *\n * @example\n * ```ts\n * sum([1, 2, 3]) // 6\n * sum([{value: 1}, {value: 2}, {value: 3}], (item) => item.value) // 6\n * sum(['apple', 'banana', 'cherry']) // TypeError\n * ```\n *\n * @param array - The array to sum.\n * @param callback - An optional callback function to map the values.\n *\n * @returns The sum of the numbers in the array or the sum of the mapped values.\n *\n * @throws {TypeError} If (after an optional `callback` mapping) any item is not a finite number.\n */\nexport function sum<T>(array: T[], callback?: (item: T) => number): number {\n if (array.length === 0) return 0;\n\n return array.reduce<number>((acc, item) => {\n const val = callback ? callback(item) : (item as unknown as number);\n\n if (
|
|
1
|
+
{"version":3,"file":"sum.cjs","names":[],"sources":["../../src/math/sum.ts"],"sourcesContent":["/**\n * Sum numbers in an array or numbers mapped by a callback function.\n *\n * @example\n * ```ts\n * sum([1, 2, 3]) // 6\n * sum([{value: 1}, {value: 2}, {value: 3}], (item) => item.value) // 6\n * sum(['apple', 'banana', 'cherry']) // TypeError\n * ```\n *\n * @param array - The array to sum.\n * @param callback - An optional callback function to map the values.\n *\n * @returns The sum of the numbers in the array or the sum of the mapped values.\n *\n * @throws {TypeError} If (after an optional `callback` mapping) any item is not a finite number.\n */\nexport function sum<T>(array: readonly T[], callback?: (item: T) => number): number {\n if (array.length === 0) return 0;\n\n return array.reduce<number>((acc, item) => {\n const val = callback ? callback(item) : (item as unknown as number);\n\n if (!Number.isFinite(val)) {\n throw new TypeError('sum: encountered a non-numeric value; provide a callback to map non-number items');\n }\n\n return acc + val;\n }, 0);\n}\n"],"mappings":"AAiBA,SAAgB,IAAO,EAAqB,EAAwC,CAGlF,OAFI,EAAM,SAAW,EAAU,EAExB,EAAM,QAAgB,EAAK,IAAS,CACzC,IAAM,EAAM,EAAW,EAAS,CAAI,EAAK,EAEzC,GAAI,CAAC,OAAO,SAAS,CAAG,EACtB,MAAU,UAAU,kFAAkF,EAGxG,OAAO,EAAM,CACf,EAAG,CAAC,CACN"}
|
package/dist/math/sum.d.ts
CHANGED
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @throws {TypeError} If (after an optional `callback` mapping) any item is not a finite number.
|
|
17
17
|
*/
|
|
18
|
-
export declare function sum<T>(array: T[], callback?: (item: T) => number): number;
|
|
18
|
+
export declare function sum<T>(array: readonly T[], callback?: (item: T) => number): number;
|
|
19
19
|
//# sourceMappingURL=sum.d.ts.map
|
package/dist/math/sum.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sum.d.ts","sourceRoot":"","sources":["../../src/math/sum.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"sum.d.ts","sourceRoot":"","sources":["../../src/math/sum.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,CAYlF"}
|
package/dist/math/sum.js
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
function e(e, t) {
|
|
3
|
-
return e.length === 0 ? 0 : e.reduce((e, n) => {
|
|
4
|
-
let r = t ? t(n) : n;
|
|
5
|
-
if (typeof r != "number" || Number.isNaN(r)) throw TypeError("sum: encountered a non-numeric value; provide a callback to map non-number items");
|
|
6
|
-
return e + r;
|
|
7
|
-
}, 0);
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
10
|
-
export { e as sum };
|
|
11
|
-
|
|
1
|
+
function sum(e,t){return e.length===0?0:e.reduce((e,n)=>{let r=t?t(n):n;if(!Number.isFinite(r))throw TypeError(`sum: encountered a non-numeric value; provide a callback to map non-number items`);return e+r},0)}export{sum};
|
|
12
2
|
//# sourceMappingURL=sum.js.map
|
package/dist/math/sum.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sum.js","names":[],"sources":["../../src/math/sum.ts"],"sourcesContent":["/**\n * Sum numbers in an array or numbers mapped by a callback function.\n *\n * @example\n * ```ts\n * sum([1, 2, 3]) // 6\n * sum([{value: 1}, {value: 2}, {value: 3}], (item) => item.value) // 6\n * sum(['apple', 'banana', 'cherry']) // TypeError\n * ```\n *\n * @param array - The array to sum.\n * @param callback - An optional callback function to map the values.\n *\n * @returns The sum of the numbers in the array or the sum of the mapped values.\n *\n * @throws {TypeError} If (after an optional `callback` mapping) any item is not a finite number.\n */\nexport function sum<T>(array: T[], callback?: (item: T) => number): number {\n if (array.length === 0) return 0;\n\n return array.reduce<number>((acc, item) => {\n const val = callback ? callback(item) : (item as unknown as number);\n\n if (
|
|
1
|
+
{"version":3,"file":"sum.js","names":[],"sources":["../../src/math/sum.ts"],"sourcesContent":["/**\n * Sum numbers in an array or numbers mapped by a callback function.\n *\n * @example\n * ```ts\n * sum([1, 2, 3]) // 6\n * sum([{value: 1}, {value: 2}, {value: 3}], (item) => item.value) // 6\n * sum(['apple', 'banana', 'cherry']) // TypeError\n * ```\n *\n * @param array - The array to sum.\n * @param callback - An optional callback function to map the values.\n *\n * @returns The sum of the numbers in the array or the sum of the mapped values.\n *\n * @throws {TypeError} If (after an optional `callback` mapping) any item is not a finite number.\n */\nexport function sum<T>(array: readonly T[], callback?: (item: T) => number): number {\n if (array.length === 0) return 0;\n\n return array.reduce<number>((acc, item) => {\n const val = callback ? callback(item) : (item as unknown as number);\n\n if (!Number.isFinite(val)) {\n throw new TypeError('sum: encountered a non-numeric value; provide a callback to map non-number items');\n }\n\n return acc + val;\n }, 0);\n}\n"],"mappings":"AAiBA,SAAgB,IAAO,EAAqB,EAAwC,CAGlF,OAFI,EAAM,SAAW,EAAU,EAExB,EAAM,QAAgB,EAAK,IAAS,CACzC,IAAM,EAAM,EAAW,EAAS,CAAI,EAAK,EAEzC,GAAI,CAAC,OAAO,SAAS,CAAG,EACtB,MAAU,UAAU,kFAAkF,EAGxG,OAAO,EAAM,CACf,EAAG,CAAC,CACN"}
|
package/dist/math/variance.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./average.cjs");function
|
|
1
|
+
const e=require("./average.cjs");function variance(t,n){if(t.length===0)return 0;let r=n?t.map(n):t,i=e.average(r)??0;return e.average(r.map(e=>(e-i)**2))??0}exports.variance=variance;
|
|
2
2
|
//# sourceMappingURL=variance.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variance.cjs","names":[],"sources":["../../src/math/variance.ts"],"sourcesContent":["import { average } from './average';\n\n/**\n * Computes the population variance (average squared deviation from the mean) of an array of\n * numbers, or of values mapped by a callback.\n *\n * @example\n * ```ts\n * variance([2, 4, 4, 4, 5, 5, 7, 9]); // 4\n * variance([{ n: 1 }, { n: 3 }], (item) => item.n); // 1\n * variance([]); // 0\n * ```\n *\n * @param array - The array to compute variance over.\n * @param callback - An optional callback to map each item to a number.\n * @returns The population variance, or `0` for an empty array.\n */\nexport function variance<T>(array: T[], callback?: (item: T) => number): number {\n if (array.length === 0) return 0;\n\n const values = callback ? array.map(callback) : (array as unknown as number[]);\n const mean = average(values) ?? 0;\n\n return average(values.map((value) => (value - mean) ** 2)) ?? 0;\n}\n"],"mappings":"iCAiBA,SAAgB,
|
|
1
|
+
{"version":3,"file":"variance.cjs","names":[],"sources":["../../src/math/variance.ts"],"sourcesContent":["import { average } from './average';\n\n/**\n * Computes the population variance (average squared deviation from the mean) of an array of\n * numbers, or of values mapped by a callback.\n *\n * @example\n * ```ts\n * variance([2, 4, 4, 4, 5, 5, 7, 9]); // 4\n * variance([{ n: 1 }, { n: 3 }], (item) => item.n); // 1\n * variance([]); // 0\n * ```\n *\n * @param array - The array to compute variance over.\n * @param callback - An optional callback to map each item to a number.\n * @returns The population variance, or `0` for an empty array.\n */\nexport function variance<T>(array: readonly T[], callback?: (item: T) => number): number {\n if (array.length === 0) return 0;\n\n const values = callback ? array.map(callback) : (array as unknown as number[]);\n const mean = average(values) ?? 0;\n\n return average(values.map((value) => (value - mean) ** 2)) ?? 0;\n}\n"],"mappings":"iCAiBA,SAAgB,SAAY,EAAqB,EAAwC,CACvF,GAAI,EAAM,SAAW,EAAG,MAAO,GAE/B,IAAM,EAAS,EAAW,EAAM,IAAI,CAAQ,EAAK,EAC3C,EAAO,EAAA,QAAQ,CAAM,GAAK,EAEhC,OAAO,EAAA,QAAQ,EAAO,IAAK,IAAW,EAAQ,IAAS,CAAC,CAAC,GAAK,CAChE"}
|
package/dist/math/variance.d.ts
CHANGED
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
* @param callback - An optional callback to map each item to a number.
|
|
14
14
|
* @returns The population variance, or `0` for an empty array.
|
|
15
15
|
*/
|
|
16
|
-
export declare function variance<T>(array: T[], callback?: (item: T) => number): number;
|
|
16
|
+
export declare function variance<T>(array: readonly T[], callback?: (item: T) => number): number;
|
|
17
17
|
//# sourceMappingURL=variance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variance.d.ts","sourceRoot":"","sources":["../../src/math/variance.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"variance.d.ts","sourceRoot":"","sources":["../../src/math/variance.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,CAOvF"}
|
package/dist/math/variance.js
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
//#region src/math/variance.ts
|
|
3
|
-
function t(t, n) {
|
|
4
|
-
if (t.length === 0) return 0;
|
|
5
|
-
let r = n ? t.map(n) : t, i = e(r) ?? 0;
|
|
6
|
-
return e(r.map((e) => (e - i) ** 2)) ?? 0;
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
export { t as variance };
|
|
10
|
-
|
|
1
|
+
import{average as e}from"./average.js";function variance(t,n){if(t.length===0)return 0;let r=n?t.map(n):t,i=e(r)??0;return e(r.map(e=>(e-i)**2))??0}export{variance};
|
|
11
2
|
//# sourceMappingURL=variance.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variance.js","names":[],"sources":["../../src/math/variance.ts"],"sourcesContent":["import { average } from './average';\n\n/**\n * Computes the population variance (average squared deviation from the mean) of an array of\n * numbers, or of values mapped by a callback.\n *\n * @example\n * ```ts\n * variance([2, 4, 4, 4, 5, 5, 7, 9]); // 4\n * variance([{ n: 1 }, { n: 3 }], (item) => item.n); // 1\n * variance([]); // 0\n * ```\n *\n * @param array - The array to compute variance over.\n * @param callback - An optional callback to map each item to a number.\n * @returns The population variance, or `0` for an empty array.\n */\nexport function variance<T>(array: T[], callback?: (item: T) => number): number {\n if (array.length === 0) return 0;\n\n const values = callback ? array.map(callback) : (array as unknown as number[]);\n const mean = average(values) ?? 0;\n\n return average(values.map((value) => (value - mean) ** 2)) ?? 0;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"variance.js","names":[],"sources":["../../src/math/variance.ts"],"sourcesContent":["import { average } from './average';\n\n/**\n * Computes the population variance (average squared deviation from the mean) of an array of\n * numbers, or of values mapped by a callback.\n *\n * @example\n * ```ts\n * variance([2, 4, 4, 4, 5, 5, 7, 9]); // 4\n * variance([{ n: 1 }, { n: 3 }], (item) => item.n); // 1\n * variance([]); // 0\n * ```\n *\n * @param array - The array to compute variance over.\n * @param callback - An optional callback to map each item to a number.\n * @returns The population variance, or `0` for an empty array.\n */\nexport function variance<T>(array: readonly T[], callback?: (item: T) => number): number {\n if (array.length === 0) return 0;\n\n const values = callback ? array.map(callback) : (array as unknown as number[]);\n const mean = average(values) ?? 0;\n\n return average(values.map((value) => (value - mean) ** 2)) ?? 0;\n}\n"],"mappings":"uCAiBA,SAAgB,SAAY,EAAqB,EAAwC,CACvF,GAAI,EAAM,SAAW,EAAG,MAAO,GAE/B,IAAM,EAAS,EAAW,EAAM,IAAI,CAAQ,EAAK,EAC3C,EAAO,EAAQ,CAAM,GAAK,EAEhC,OAAO,EAAQ,EAAO,IAAK,IAAW,EAAQ,IAAS,CAAC,CAAC,GAAK,CAChE"}
|
package/dist/object/defaults.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../_common/unsafePaths.cjs"),t=require("../guards/isPlainObject.cjs");function
|
|
1
|
+
const e=require("../_common/unsafePaths.cjs"),t=require("../guards/isPlainObject.cjs");function defaults(n,...r){let i={...n};for(let n of r)if(t.isPlainObject(n))for(let t of Object.keys(n))e.isUnsafeKey(t)||i[t]===void 0&&(i[t]=n[t]);return i}exports.defaults=defaults;
|
|
2
2
|
//# sourceMappingURL=defaults.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.cjs","names":[],"sources":["../../src/object/defaults.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { isPlainObject } from '../guards/isPlainObject';\nimport type { Obj } from '../types';\n\n/**\n * Fills in `undefined` properties in `target` with values from `sources`. First source wins\n * — unlike `shallowMerge`, already-set keys are never overwritten.\n *\n * @example\n * ```ts\n * defaults({ a: 1, b: undefined }, { a: 99, b: 2, c: 3 });\n * // { a: 1, b: 2, c: 3 }\n * ```\n *\n * @param target - The object to fill in.\n * @param sources - One or more partial objects supplying default values.\n * @returns A new object with missing keys filled from `sources`.\n */\nexport function defaults<T extends Obj>(target: T, ...sources: Array<Partial<T>>): T {\n const out = { ...target };\n\n for (const source of sources) {\n if (!isPlainObject(source)) continue;\n\n for (const key of Object.keys(source) as Array<keyof T>) {\n if (isUnsafeKey(key as PropertyKey)) continue;\n\n if (out[key] === undefined) {\n out[key] = source[key] as T[keyof T];\n }\n }\n }\n\n return out;\n}\n"],"mappings":"uFAkBA,SAAgB,
|
|
1
|
+
{"version":3,"file":"defaults.cjs","names":[],"sources":["../../src/object/defaults.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { isPlainObject } from '../guards/isPlainObject';\nimport type { Obj } from '../types';\n\n/**\n * Fills in `undefined` properties in `target` with values from `sources`. First source wins\n * — unlike `shallowMerge`, already-set keys are never overwritten.\n *\n * @example\n * ```ts\n * defaults({ a: 1, b: undefined }, { a: 99, b: 2, c: 3 });\n * // { a: 1, b: 2, c: 3 }\n * ```\n *\n * @param target - The object to fill in.\n * @param sources - One or more partial objects supplying default values.\n * @returns A new object with missing keys filled from `sources`.\n */\nexport function defaults<T extends Obj>(target: T, ...sources: Array<Partial<T>>): T {\n const out = { ...target };\n\n for (const source of sources) {\n if (!isPlainObject(source)) continue;\n\n for (const key of Object.keys(source) as Array<keyof T>) {\n if (isUnsafeKey(key as PropertyKey)) continue;\n\n if (out[key] === undefined) {\n out[key] = source[key] as T[keyof T];\n }\n }\n }\n\n return out;\n}\n"],"mappings":"uFAkBA,SAAgB,SAAwB,EAAW,GAAG,EAA+B,CACnF,IAAM,EAAM,CAAE,GAAG,CAAO,EAExB,IAAK,IAAM,KAAU,EACd,KAAA,cAAc,CAAM,EAEzB,IAAK,IAAM,KAAO,OAAO,KAAK,CAAM,EAC9B,EAAA,YAAY,CAAkB,GAE9B,EAAI,KAAS,IAAA,KACf,EAAI,GAAO,EAAO,IAKxB,OAAO,CACT"}
|
package/dist/object/defaults.js
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { isPlainObject as t } from "../guards/isPlainObject.js";
|
|
3
|
-
//#region src/object/defaults.ts
|
|
4
|
-
function n(n, ...r) {
|
|
5
|
-
let i = { ...n };
|
|
6
|
-
for (let n of r) if (t(n)) for (let t of Object.keys(n)) e(t) || i[t] === void 0 && (i[t] = n[t]);
|
|
7
|
-
return i;
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
10
|
-
export { n as defaults };
|
|
11
|
-
|
|
1
|
+
import{isUnsafeKey as e}from"../_common/unsafePaths.js";import{isPlainObject as t}from"../guards/isPlainObject.js";function defaults(n,...r){let i={...n};for(let n of r)if(t(n))for(let t of Object.keys(n))e(t)||i[t]===void 0&&(i[t]=n[t]);return i}export{defaults};
|
|
12
2
|
//# sourceMappingURL=defaults.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","names":[],"sources":["../../src/object/defaults.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { isPlainObject } from '../guards/isPlainObject';\nimport type { Obj } from '../types';\n\n/**\n * Fills in `undefined` properties in `target` with values from `sources`. First source wins\n * — unlike `shallowMerge`, already-set keys are never overwritten.\n *\n * @example\n * ```ts\n * defaults({ a: 1, b: undefined }, { a: 99, b: 2, c: 3 });\n * // { a: 1, b: 2, c: 3 }\n * ```\n *\n * @param target - The object to fill in.\n * @param sources - One or more partial objects supplying default values.\n * @returns A new object with missing keys filled from `sources`.\n */\nexport function defaults<T extends Obj>(target: T, ...sources: Array<Partial<T>>): T {\n const out = { ...target };\n\n for (const source of sources) {\n if (!isPlainObject(source)) continue;\n\n for (const key of Object.keys(source) as Array<keyof T>) {\n if (isUnsafeKey(key as PropertyKey)) continue;\n\n if (out[key] === undefined) {\n out[key] = source[key] as T[keyof T];\n }\n }\n }\n\n return out;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"defaults.js","names":[],"sources":["../../src/object/defaults.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { isPlainObject } from '../guards/isPlainObject';\nimport type { Obj } from '../types';\n\n/**\n * Fills in `undefined` properties in `target` with values from `sources`. First source wins\n * — unlike `shallowMerge`, already-set keys are never overwritten.\n *\n * @example\n * ```ts\n * defaults({ a: 1, b: undefined }, { a: 99, b: 2, c: 3 });\n * // { a: 1, b: 2, c: 3 }\n * ```\n *\n * @param target - The object to fill in.\n * @param sources - One or more partial objects supplying default values.\n * @returns A new object with missing keys filled from `sources`.\n */\nexport function defaults<T extends Obj>(target: T, ...sources: Array<Partial<T>>): T {\n const out = { ...target };\n\n for (const source of sources) {\n if (!isPlainObject(source)) continue;\n\n for (const key of Object.keys(source) as Array<keyof T>) {\n if (isUnsafeKey(key as PropertyKey)) continue;\n\n if (out[key] === undefined) {\n out[key] = source[key] as T[keyof T];\n }\n }\n }\n\n return out;\n}\n"],"mappings":"mHAkBA,SAAgB,SAAwB,EAAW,GAAG,EAA+B,CACnF,IAAM,EAAM,CAAE,GAAG,CAAO,EAExB,IAAK,IAAM,KAAU,EACd,KAAc,CAAM,EAEzB,IAAK,IAAM,KAAO,OAAO,KAAK,CAAM,EAC9B,EAAY,CAAkB,GAE9B,EAAI,KAAS,IAAA,KACf,EAAI,GAAO,EAAO,IAKxB,OAAO,CACT"}
|
package/dist/object/diff.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../guards/isEqual.cjs"),t=require("../_common/unsafePaths.cjs");function
|
|
1
|
+
const e=require("../guards/isEqual.cjs"),t=require("../_common/unsafePaths.cjs");function diff(n={},r={},i=e.isEqual){let a=[],o=[],s={},c=new Set(Object.keys(n)),l=new Set(Object.keys(r));for(let e of l)c.has(e)?!t.isUnsafeKey(e)&&!i(n[e],r[e])&&(s[e]={after:r[e],before:n[e]}):a.push(e);for(let e of c)l.has(e)||o.push(e);return{added:a,changed:s,removed:o}}function diffArrays(t,n,r){let i=r?.compareFn??((t,n)=>e.isEqual(t,n));return{added:n.filter(e=>!t.some(t=>i(t,e))),removed:t.filter(e=>!n.some(t=>i(e,t)))}}exports.diff=diff,exports.diffArrays=diffArrays;
|
|
2
2
|
//# sourceMappingURL=diff.cjs.map
|
package/dist/object/diff.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.cjs","names":[],"sources":["../../src/object/diff.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { isEqual } from '../guards/isEqual';\nimport type { Obj } from '../types';\n\nexport type DiffResult<T extends Obj> = {\n /** Keys present in `after` but not in `before`. */\n added: Array<keyof T & string>;\n /** Keys present in both objects whose values differ. Maps key → `{ before, after }`. */\n changed: { [K in keyof T]?: { after: T[K]; before: T[K] } };\n /** Keys present in `before` but not in `after`. */\n removed: Array<keyof T & string>;\n};\n\n/**\n * Computes the structural difference between two plain objects.\n * Returns an `{ added, removed, changed }` result — no sentinel symbols needed.\n * Dangerous keys (`__proto__`, `constructor`, `prototype`) are omitted from `changed`.\n *\n * @example\n * ```ts\n * diff({ a: 1, b: 2, c: 3 }, { a: 1, b: 99 });\n * // { added: [], removed: ['c'], changed: { b: { before: 2, after: 99 } } }\n *\n * diff({ x: { n: 1 } }, { x: { n: 2 } });\n * // { added: [], removed: [], changed: { x: { before: { n: 1 }, after: { n: 2 } } } }\n * ```\n *\n * @param before - The original object.\n * @param after - The updated object.\n * @param compareFn - Custom equality function. Defaults to deep `isEqual`.\n */\nexport function diff<T extends Obj>(\n before: T = {} as T,\n after: T = {} as T,\n compareFn: (a: unknown, b: unknown) => boolean = isEqual,\n): DiffResult<T> {\n const added: Array<keyof T & string> = [];\n const removed: Array<keyof T & string> = [];\n const changed: Record<string, { after: unknown; before: unknown }> = {};\n\n const beforeKeys = new Set(Object.keys(before));\n const afterKeys = new Set(Object.keys(after));\n\n for (const key of afterKeys) {\n if (!beforeKeys.has(key)) {\n added.push(key as keyof T & string);\n } else if (!isUnsafeKey(key) && !compareFn(before[key], after[key])) {\n changed[key] = { after: after[key], before: before[key] };\n }\n }\n\n for (const key of beforeKeys) {\n if (!afterKeys.has(key)) {\n removed.push(key as keyof T & string);\n }\n }\n\n return { added, changed: changed as DiffResult<T>['changed'], removed };\n}\n\nexport type ArrayDiff<T> = {\n added: T[];\n removed: T[];\n};\n\nexport type ArrayDiffOptions<T> = {\n compareFn?: (a: T, b: T) => boolean;\n};\n\n/**\n * Computes the set-difference between two arrays.\n * Items present in `after` but not `before` are `added`.\n * Items present in `before` but not `after` are `removed`.\n * Order-independent; uses deep equality by default.\n *\n * @example\n * ```ts\n * diffArrays([1, 2, 3], [2, 3, 4]); // { added: [4], removed: [1] }\n * diffArrays(\n * [{ id: 1 }, { id: 2 }],\n * [{ id: 2 }, { id: 3 }],\n * { compareFn: (a, b) => a.id === b.id },\n * ); // { added: [{ id: 3 }], removed: [{ id: 1 }] }\n * ```\n *\n * @param before - The original array.\n * @param after - The updated array.\n * @param [options.compareFn] - Custom equality function. Defaults to deep `isEqual`.\n * @returns An object with `added` and `removed` arrays.\n */\nexport function diffArrays<T>(before: T[], after: T[], options?: ArrayDiffOptions<T>): ArrayDiff<T> {\n const compareFn = options?.compareFn ?? ((a: T, b: T) => isEqual(a, b));\n\n return {\n added: after.filter((item) => !before.some((b) => compareFn(b, item))),\n removed: before.filter((item) => !after.some((a) => compareFn(item, a))),\n };\n}\n"],"mappings":"iFA+BA,SAAgB,
|
|
1
|
+
{"version":3,"file":"diff.cjs","names":[],"sources":["../../src/object/diff.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { isEqual } from '../guards/isEqual';\nimport type { Obj } from '../types';\n\nexport type DiffResult<T extends Obj> = {\n /** Keys present in `after` but not in `before`. */\n added: Array<keyof T & string>;\n /** Keys present in both objects whose values differ. Maps key → `{ before, after }`. */\n changed: { [K in keyof T]?: { after: T[K]; before: T[K] } };\n /** Keys present in `before` but not in `after`. */\n removed: Array<keyof T & string>;\n};\n\n/**\n * Computes the structural difference between two plain objects.\n * Returns an `{ added, removed, changed }` result — no sentinel symbols needed.\n * Dangerous keys (`__proto__`, `constructor`, `prototype`) are omitted from `changed`.\n *\n * @example\n * ```ts\n * diff({ a: 1, b: 2, c: 3 }, { a: 1, b: 99 });\n * // { added: [], removed: ['c'], changed: { b: { before: 2, after: 99 } } }\n *\n * diff({ x: { n: 1 } }, { x: { n: 2 } });\n * // { added: [], removed: [], changed: { x: { before: { n: 1 }, after: { n: 2 } } } }\n * ```\n *\n * @param before - The original object.\n * @param after - The updated object.\n * @param compareFn - Custom equality function. Defaults to deep `isEqual`.\n */\nexport function diff<T extends Obj>(\n before: T = {} as T,\n after: T = {} as T,\n compareFn: (a: unknown, b: unknown) => boolean = isEqual,\n): DiffResult<T> {\n const added: Array<keyof T & string> = [];\n const removed: Array<keyof T & string> = [];\n const changed: Record<string, { after: unknown; before: unknown }> = {};\n\n const beforeKeys = new Set(Object.keys(before));\n const afterKeys = new Set(Object.keys(after));\n\n for (const key of afterKeys) {\n if (!beforeKeys.has(key)) {\n added.push(key as keyof T & string);\n } else if (!isUnsafeKey(key) && !compareFn(before[key], after[key])) {\n changed[key] = { after: after[key], before: before[key] };\n }\n }\n\n for (const key of beforeKeys) {\n if (!afterKeys.has(key)) {\n removed.push(key as keyof T & string);\n }\n }\n\n return { added, changed: changed as DiffResult<T>['changed'], removed };\n}\n\nexport type ArrayDiff<T> = {\n added: T[];\n removed: T[];\n};\n\nexport type ArrayDiffOptions<T> = {\n compareFn?: (a: T, b: T) => boolean;\n};\n\n/**\n * Computes the set-difference between two arrays.\n * Items present in `after` but not `before` are `added`.\n * Items present in `before` but not `after` are `removed`.\n * Order-independent; uses deep equality by default.\n *\n * @example\n * ```ts\n * diffArrays([1, 2, 3], [2, 3, 4]); // { added: [4], removed: [1] }\n * diffArrays(\n * [{ id: 1 }, { id: 2 }],\n * [{ id: 2 }, { id: 3 }],\n * { compareFn: (a, b) => a.id === b.id },\n * ); // { added: [{ id: 3 }], removed: [{ id: 1 }] }\n * ```\n *\n * @param before - The original array.\n * @param after - The updated array.\n * @param [options.compareFn] - Custom equality function. Defaults to deep `isEqual`.\n * @returns An object with `added` and `removed` arrays.\n */\nexport function diffArrays<T>(before: readonly T[], after: readonly T[], options?: ArrayDiffOptions<T>): ArrayDiff<T> {\n const compareFn = options?.compareFn ?? ((a: T, b: T) => isEqual(a, b));\n\n return {\n added: after.filter((item) => !before.some((b) => compareFn(b, item))),\n removed: before.filter((item) => !after.some((a) => compareFn(item, a))),\n };\n}\n"],"mappings":"iFA+BA,SAAgB,KACd,EAAY,CAAC,EACb,EAAW,CAAC,EACZ,EAAiD,EAAA,QAClC,CACf,IAAM,EAAiC,CAAC,EAClC,EAAmC,CAAC,EACpC,EAA+D,CAAC,EAEhE,EAAa,IAAI,IAAI,OAAO,KAAK,CAAM,CAAC,EACxC,EAAY,IAAI,IAAI,OAAO,KAAK,CAAK,CAAC,EAE5C,IAAK,IAAM,KAAO,EACX,EAAW,IAAI,CAAG,EAEZ,CAAC,EAAA,YAAY,CAAG,GAAK,CAAC,EAAU,EAAO,GAAM,EAAM,EAAI,IAChE,EAAQ,GAAO,CAAE,MAAO,EAAM,GAAM,OAAQ,EAAO,EAAK,GAFxD,EAAM,KAAK,CAAuB,EAMtC,IAAK,IAAM,KAAO,EACX,EAAU,IAAI,CAAG,GACpB,EAAQ,KAAK,CAAuB,EAIxC,MAAO,CAAE,QAAgB,UAAqC,SAAQ,CACxE,CAgCA,SAAgB,WAAc,EAAsB,EAAqB,EAA6C,CACpH,IAAM,EAAY,GAAS,aAAe,EAAM,IAAS,EAAA,QAAQ,EAAG,CAAC,GAErE,MAAO,CACL,MAAO,EAAM,OAAQ,GAAS,CAAC,EAAO,KAAM,GAAM,EAAU,EAAG,CAAI,CAAC,CAAC,EACrE,QAAS,EAAO,OAAQ,GAAS,CAAC,EAAM,KAAM,GAAM,EAAU,EAAM,CAAC,CAAC,CAAC,CACzE,CACF"}
|
package/dist/object/diff.d.ts
CHANGED
|
@@ -59,5 +59,5 @@ export type ArrayDiffOptions<T> = {
|
|
|
59
59
|
* @param [options.compareFn] - Custom equality function. Defaults to deep `isEqual`.
|
|
60
60
|
* @returns An object with `added` and `removed` arrays.
|
|
61
61
|
*/
|
|
62
|
-
export declare function diffArrays<T>(before: T[], after: T[], options?: ArrayDiffOptions<T>): ArrayDiff<T>;
|
|
62
|
+
export declare function diffArrays<T>(before: readonly T[], after: readonly T[], options?: ArrayDiffOptions<T>): ArrayDiff<T>;
|
|
63
63
|
//# sourceMappingURL=diff.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/object/diff.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,GAAG,IAAI;IACtC,mDAAmD;IACnD,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;IAC/B,wFAAwF;IACxF,OAAO,EAAE;SAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE;YAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;SAAE;KAAE,CAAC;IAC5D,mDAAmD;IACnD,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;CAClC,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,GAAG,EAChC,MAAM,GAAE,CAAW,EACnB,KAAK,GAAE,CAAW,EAClB,SAAS,GAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,KAAK,OAAiB,GACvD,UAAU,CAAC,CAAC,CAAC,CAuBf;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,OAAO,EAAE,CAAC,EAAE,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;IAChC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/object/diff.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,GAAG,IAAI;IACtC,mDAAmD;IACnD,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;IAC/B,wFAAwF;IACxF,OAAO,EAAE;SAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE;YAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;SAAE;KAAE,CAAC;IAC5D,mDAAmD;IACnD,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;CAClC,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,GAAG,EAChC,MAAM,GAAE,CAAW,EACnB,KAAK,GAAE,CAAW,EAClB,SAAS,GAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,KAAK,OAAiB,GACvD,UAAU,CAAC,CAAC,CAAC,CAuBf;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,OAAO,EAAE,CAAC,EAAE,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;IAChC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAOpH"}
|
package/dist/object/diff.js
CHANGED
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { isUnsafeKey as t } from "../_common/unsafePaths.js";
|
|
3
|
-
//#region src/object/diff.ts
|
|
4
|
-
function n(n = {}, r = {}, i = e) {
|
|
5
|
-
let a = [], o = [], s = {}, c = new Set(Object.keys(n)), l = new Set(Object.keys(r));
|
|
6
|
-
for (let e of l) c.has(e) ? !t(e) && !i(n[e], r[e]) && (s[e] = {
|
|
7
|
-
after: r[e],
|
|
8
|
-
before: n[e]
|
|
9
|
-
}) : a.push(e);
|
|
10
|
-
for (let e of c) l.has(e) || o.push(e);
|
|
11
|
-
return {
|
|
12
|
-
added: a,
|
|
13
|
-
changed: s,
|
|
14
|
-
removed: o
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function r(t, n, r) {
|
|
18
|
-
let i = r?.compareFn ?? ((t, n) => e(t, n));
|
|
19
|
-
return {
|
|
20
|
-
added: n.filter((e) => !t.some((t) => i(t, e))),
|
|
21
|
-
removed: t.filter((e) => !n.some((t) => i(e, t)))
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
export { n as diff, r as diffArrays };
|
|
26
|
-
|
|
1
|
+
import{isEqual as e}from"../guards/isEqual.js";import{isUnsafeKey as t}from"../_common/unsafePaths.js";function diff(n={},r={},i=e){let a=[],o=[],s={},c=new Set(Object.keys(n)),l=new Set(Object.keys(r));for(let e of l)c.has(e)?!t(e)&&!i(n[e],r[e])&&(s[e]={after:r[e],before:n[e]}):a.push(e);for(let e of c)l.has(e)||o.push(e);return{added:a,changed:s,removed:o}}function diffArrays(t,n,r){let i=r?.compareFn??((t,n)=>e(t,n));return{added:n.filter(e=>!t.some(t=>i(t,e))),removed:t.filter(e=>!n.some(t=>i(e,t)))}}export{diff,diffArrays};
|
|
27
2
|
//# sourceMappingURL=diff.js.map
|
package/dist/object/diff.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.js","names":[],"sources":["../../src/object/diff.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { isEqual } from '../guards/isEqual';\nimport type { Obj } from '../types';\n\nexport type DiffResult<T extends Obj> = {\n /** Keys present in `after` but not in `before`. */\n added: Array<keyof T & string>;\n /** Keys present in both objects whose values differ. Maps key → `{ before, after }`. */\n changed: { [K in keyof T]?: { after: T[K]; before: T[K] } };\n /** Keys present in `before` but not in `after`. */\n removed: Array<keyof T & string>;\n};\n\n/**\n * Computes the structural difference between two plain objects.\n * Returns an `{ added, removed, changed }` result — no sentinel symbols needed.\n * Dangerous keys (`__proto__`, `constructor`, `prototype`) are omitted from `changed`.\n *\n * @example\n * ```ts\n * diff({ a: 1, b: 2, c: 3 }, { a: 1, b: 99 });\n * // { added: [], removed: ['c'], changed: { b: { before: 2, after: 99 } } }\n *\n * diff({ x: { n: 1 } }, { x: { n: 2 } });\n * // { added: [], removed: [], changed: { x: { before: { n: 1 }, after: { n: 2 } } } }\n * ```\n *\n * @param before - The original object.\n * @param after - The updated object.\n * @param compareFn - Custom equality function. Defaults to deep `isEqual`.\n */\nexport function diff<T extends Obj>(\n before: T = {} as T,\n after: T = {} as T,\n compareFn: (a: unknown, b: unknown) => boolean = isEqual,\n): DiffResult<T> {\n const added: Array<keyof T & string> = [];\n const removed: Array<keyof T & string> = [];\n const changed: Record<string, { after: unknown; before: unknown }> = {};\n\n const beforeKeys = new Set(Object.keys(before));\n const afterKeys = new Set(Object.keys(after));\n\n for (const key of afterKeys) {\n if (!beforeKeys.has(key)) {\n added.push(key as keyof T & string);\n } else if (!isUnsafeKey(key) && !compareFn(before[key], after[key])) {\n changed[key] = { after: after[key], before: before[key] };\n }\n }\n\n for (const key of beforeKeys) {\n if (!afterKeys.has(key)) {\n removed.push(key as keyof T & string);\n }\n }\n\n return { added, changed: changed as DiffResult<T>['changed'], removed };\n}\n\nexport type ArrayDiff<T> = {\n added: T[];\n removed: T[];\n};\n\nexport type ArrayDiffOptions<T> = {\n compareFn?: (a: T, b: T) => boolean;\n};\n\n/**\n * Computes the set-difference between two arrays.\n * Items present in `after` but not `before` are `added`.\n * Items present in `before` but not `after` are `removed`.\n * Order-independent; uses deep equality by default.\n *\n * @example\n * ```ts\n * diffArrays([1, 2, 3], [2, 3, 4]); // { added: [4], removed: [1] }\n * diffArrays(\n * [{ id: 1 }, { id: 2 }],\n * [{ id: 2 }, { id: 3 }],\n * { compareFn: (a, b) => a.id === b.id },\n * ); // { added: [{ id: 3 }], removed: [{ id: 1 }] }\n * ```\n *\n * @param before - The original array.\n * @param after - The updated array.\n * @param [options.compareFn] - Custom equality function. Defaults to deep `isEqual`.\n * @returns An object with `added` and `removed` arrays.\n */\nexport function diffArrays<T>(before: T[], after: T[], options?: ArrayDiffOptions<T>): ArrayDiff<T> {\n const compareFn = options?.compareFn ?? ((a: T, b: T) => isEqual(a, b));\n\n return {\n added: after.filter((item) => !before.some((b) => compareFn(b, item))),\n removed: before.filter((item) => !after.some((a) => compareFn(item, a))),\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"diff.js","names":[],"sources":["../../src/object/diff.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { isEqual } from '../guards/isEqual';\nimport type { Obj } from '../types';\n\nexport type DiffResult<T extends Obj> = {\n /** Keys present in `after` but not in `before`. */\n added: Array<keyof T & string>;\n /** Keys present in both objects whose values differ. Maps key → `{ before, after }`. */\n changed: { [K in keyof T]?: { after: T[K]; before: T[K] } };\n /** Keys present in `before` but not in `after`. */\n removed: Array<keyof T & string>;\n};\n\n/**\n * Computes the structural difference between two plain objects.\n * Returns an `{ added, removed, changed }` result — no sentinel symbols needed.\n * Dangerous keys (`__proto__`, `constructor`, `prototype`) are omitted from `changed`.\n *\n * @example\n * ```ts\n * diff({ a: 1, b: 2, c: 3 }, { a: 1, b: 99 });\n * // { added: [], removed: ['c'], changed: { b: { before: 2, after: 99 } } }\n *\n * diff({ x: { n: 1 } }, { x: { n: 2 } });\n * // { added: [], removed: [], changed: { x: { before: { n: 1 }, after: { n: 2 } } } }\n * ```\n *\n * @param before - The original object.\n * @param after - The updated object.\n * @param compareFn - Custom equality function. Defaults to deep `isEqual`.\n */\nexport function diff<T extends Obj>(\n before: T = {} as T,\n after: T = {} as T,\n compareFn: (a: unknown, b: unknown) => boolean = isEqual,\n): DiffResult<T> {\n const added: Array<keyof T & string> = [];\n const removed: Array<keyof T & string> = [];\n const changed: Record<string, { after: unknown; before: unknown }> = {};\n\n const beforeKeys = new Set(Object.keys(before));\n const afterKeys = new Set(Object.keys(after));\n\n for (const key of afterKeys) {\n if (!beforeKeys.has(key)) {\n added.push(key as keyof T & string);\n } else if (!isUnsafeKey(key) && !compareFn(before[key], after[key])) {\n changed[key] = { after: after[key], before: before[key] };\n }\n }\n\n for (const key of beforeKeys) {\n if (!afterKeys.has(key)) {\n removed.push(key as keyof T & string);\n }\n }\n\n return { added, changed: changed as DiffResult<T>['changed'], removed };\n}\n\nexport type ArrayDiff<T> = {\n added: T[];\n removed: T[];\n};\n\nexport type ArrayDiffOptions<T> = {\n compareFn?: (a: T, b: T) => boolean;\n};\n\n/**\n * Computes the set-difference between two arrays.\n * Items present in `after` but not `before` are `added`.\n * Items present in `before` but not `after` are `removed`.\n * Order-independent; uses deep equality by default.\n *\n * @example\n * ```ts\n * diffArrays([1, 2, 3], [2, 3, 4]); // { added: [4], removed: [1] }\n * diffArrays(\n * [{ id: 1 }, { id: 2 }],\n * [{ id: 2 }, { id: 3 }],\n * { compareFn: (a, b) => a.id === b.id },\n * ); // { added: [{ id: 3 }], removed: [{ id: 1 }] }\n * ```\n *\n * @param before - The original array.\n * @param after - The updated array.\n * @param [options.compareFn] - Custom equality function. Defaults to deep `isEqual`.\n * @returns An object with `added` and `removed` arrays.\n */\nexport function diffArrays<T>(before: readonly T[], after: readonly T[], options?: ArrayDiffOptions<T>): ArrayDiff<T> {\n const compareFn = options?.compareFn ?? ((a: T, b: T) => isEqual(a, b));\n\n return {\n added: after.filter((item) => !before.some((b) => compareFn(b, item))),\n removed: before.filter((item) => !after.some((a) => compareFn(item, a))),\n };\n}\n"],"mappings":"uGA+BA,SAAgB,KACd,EAAY,CAAC,EACb,EAAW,CAAC,EACZ,EAAiD,EAClC,CACf,IAAM,EAAiC,CAAC,EAClC,EAAmC,CAAC,EACpC,EAA+D,CAAC,EAEhE,EAAa,IAAI,IAAI,OAAO,KAAK,CAAM,CAAC,EACxC,EAAY,IAAI,IAAI,OAAO,KAAK,CAAK,CAAC,EAE5C,IAAK,IAAM,KAAO,EACX,EAAW,IAAI,CAAG,EAEZ,CAAC,EAAY,CAAG,GAAK,CAAC,EAAU,EAAO,GAAM,EAAM,EAAI,IAChE,EAAQ,GAAO,CAAE,MAAO,EAAM,GAAM,OAAQ,EAAO,EAAK,GAFxD,EAAM,KAAK,CAAuB,EAMtC,IAAK,IAAM,KAAO,EACX,EAAU,IAAI,CAAG,GACpB,EAAQ,KAAK,CAAuB,EAIxC,MAAO,CAAE,QAAgB,UAAqC,SAAQ,CACxE,CAgCA,SAAgB,WAAc,EAAsB,EAAqB,EAA6C,CACpH,IAAM,EAAY,GAAS,aAAe,EAAM,IAAS,EAAQ,EAAG,CAAC,GAErE,MAAO,CACL,MAAO,EAAM,OAAQ,GAAS,CAAC,EAAO,KAAM,GAAM,EAAU,EAAG,CAAI,CAAC,CAAC,EACrE,QAAS,EAAO,OAAQ,GAAS,CAAC,EAAM,KAAM,GAAM,EAAU,EAAM,CAAC,CAAC,CAAC,CACzE,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../_common/unsafePaths.cjs");function
|
|
1
|
+
const e=require("../_common/unsafePaths.cjs");function filterValues(t,n){let r={};for(let i of Object.keys(t))e.isUnsafeKey(i)||n(t[i],i,t)&&(r[i]=t[i]);return r}exports.filterValues=filterValues;
|
|
2
2
|
//# sourceMappingURL=filterValues.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterValues.cjs","names":[],"sources":["../../src/object/filterValues.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport type { Obj } from '../types';\n\n/**\n * Filters object entries using a value predicate. Dangerous keys (`__proto__`, `constructor`,\n * `prototype`) are always skipped.\n *\n * @example\n * ```ts\n * filterValues({ a: 1, b: 2, c: 3 }, (value) => value > 1); // { b: 2, c: 3 }\n * ```\n *\n * @param obj - The source object.\n * @param predicate - Returns `true` to keep an entry.\n * @returns A new object containing only entries for which `predicate` returned `true`.\n */\nexport function filterValues<T extends Obj>(\n obj: T,\n predicate: (value: T[keyof T], key: keyof T, obj: T) => boolean,\n): Partial<T> {\n const out: Partial<T> = {};\n\n for (const key of Object.keys(obj) as Array<keyof T>) {\n if (isUnsafeKey(key as PropertyKey)) continue;\n\n if (predicate(obj[key], key, obj)) {\n out[key] = obj[key];\n }\n }\n\n return out;\n}\n"],"mappings":"8CAgBA,SAAgB,
|
|
1
|
+
{"version":3,"file":"filterValues.cjs","names":[],"sources":["../../src/object/filterValues.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport type { Obj } from '../types';\n\n/**\n * Filters object entries using a value predicate. Dangerous keys (`__proto__`, `constructor`,\n * `prototype`) are always skipped.\n *\n * @example\n * ```ts\n * filterValues({ a: 1, b: 2, c: 3 }, (value) => value > 1); // { b: 2, c: 3 }\n * ```\n *\n * @param obj - The source object.\n * @param predicate - Returns `true` to keep an entry.\n * @returns A new object containing only entries for which `predicate` returned `true`.\n */\nexport function filterValues<T extends Obj>(\n obj: T,\n predicate: (value: T[keyof T], key: keyof T, obj: T) => boolean,\n): Partial<T> {\n const out: Partial<T> = {};\n\n for (const key of Object.keys(obj) as Array<keyof T>) {\n if (isUnsafeKey(key as PropertyKey)) continue;\n\n if (predicate(obj[key], key, obj)) {\n out[key] = obj[key];\n }\n }\n\n return out;\n}\n"],"mappings":"8CAgBA,SAAgB,aACd,EACA,EACY,CACZ,IAAM,EAAkB,CAAC,EAEzB,IAAK,IAAM,KAAO,OAAO,KAAK,CAAG,EAC3B,EAAA,YAAY,CAAkB,GAE9B,EAAU,EAAI,GAAM,EAAK,CAAG,IAC9B,EAAI,GAAO,EAAI,IAInB,OAAO,CACT"}
|
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
//#region src/object/filterValues.ts
|
|
3
|
-
function t(t, n) {
|
|
4
|
-
let r = {};
|
|
5
|
-
for (let i of Object.keys(t)) e(i) || n(t[i], i, t) && (r[i] = t[i]);
|
|
6
|
-
return r;
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
export { t as filterValues };
|
|
10
|
-
|
|
1
|
+
import{isUnsafeKey as e}from"../_common/unsafePaths.js";function filterValues(t,n){let r={};for(let i of Object.keys(t))e(i)||n(t[i],i,t)&&(r[i]=t[i]);return r}export{filterValues};
|
|
11
2
|
//# sourceMappingURL=filterValues.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterValues.js","names":[],"sources":["../../src/object/filterValues.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport type { Obj } from '../types';\n\n/**\n * Filters object entries using a value predicate. Dangerous keys (`__proto__`, `constructor`,\n * `prototype`) are always skipped.\n *\n * @example\n * ```ts\n * filterValues({ a: 1, b: 2, c: 3 }, (value) => value > 1); // { b: 2, c: 3 }\n * ```\n *\n * @param obj - The source object.\n * @param predicate - Returns `true` to keep an entry.\n * @returns A new object containing only entries for which `predicate` returned `true`.\n */\nexport function filterValues<T extends Obj>(\n obj: T,\n predicate: (value: T[keyof T], key: keyof T, obj: T) => boolean,\n): Partial<T> {\n const out: Partial<T> = {};\n\n for (const key of Object.keys(obj) as Array<keyof T>) {\n if (isUnsafeKey(key as PropertyKey)) continue;\n\n if (predicate(obj[key], key, obj)) {\n out[key] = obj[key];\n }\n }\n\n return out;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"filterValues.js","names":[],"sources":["../../src/object/filterValues.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport type { Obj } from '../types';\n\n/**\n * Filters object entries using a value predicate. Dangerous keys (`__proto__`, `constructor`,\n * `prototype`) are always skipped.\n *\n * @example\n * ```ts\n * filterValues({ a: 1, b: 2, c: 3 }, (value) => value > 1); // { b: 2, c: 3 }\n * ```\n *\n * @param obj - The source object.\n * @param predicate - Returns `true` to keep an entry.\n * @returns A new object containing only entries for which `predicate` returned `true`.\n */\nexport function filterValues<T extends Obj>(\n obj: T,\n predicate: (value: T[keyof T], key: keyof T, obj: T) => boolean,\n): Partial<T> {\n const out: Partial<T> = {};\n\n for (const key of Object.keys(obj) as Array<keyof T>) {\n if (isUnsafeKey(key as PropertyKey)) continue;\n\n if (predicate(obj[key], key, obj)) {\n out[key] = obj[key];\n }\n }\n\n return out;\n}\n"],"mappings":"wDAgBA,SAAgB,aACd,EACA,EACY,CACZ,IAAM,EAAkB,CAAC,EAEzB,IAAK,IAAM,KAAO,OAAO,KAAK,CAAG,EAC3B,EAAY,CAAkB,GAE9B,EAAU,EAAI,GAAM,EAAK,CAAG,IAC9B,EAAI,GAAO,EAAI,IAInB,OAAO,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../_common/unsafePaths.cjs"),t=require("../guards/isPlainObject.cjs");var n=10;function r
|
|
1
|
+
const e=require("../_common/unsafePaths.cjs"),t=require("../guards/isPlainObject.cjs");var n=10;function _flattenPaths(r,i,a){let o={};for(let[s,c]of Object.entries(r)){if(e.UNSAFE_PATH_SEGMENTS.has(s))continue;let r=i?`${i}.${s}`:s;t.isPlainObject(c)&&a<n?Object.assign(o,_flattenPaths(c,r,a+1)):o[r]=c}return o}function flattenPaths(e){return _flattenPaths(e,``,0)}function unflattenPaths(n){let r={};for(let[i,a]of Object.entries(n)){let n=i.split(`.`);if(n.some(t=>e.UNSAFE_PATH_SEGMENTS.has(t)))continue;let o=r;for(let e=0;e<n.length-1;e++)t.isPlainObject(o[n[e]])||(o[n[e]]={}),o=o[n[e]];o[n[n.length-1]]=a}return r}exports.flattenPaths=flattenPaths,exports.unflattenPaths=unflattenPaths;
|
|
2
2
|
//# sourceMappingURL=flattenPaths.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenPaths.cjs","names":[],"sources":["../../src/object/flattenPaths.ts"],"sourcesContent":["import { UNSAFE_PATH_SEGMENTS } from '../_common/unsafePaths';\nimport { isPlainObject } from '../guards/isPlainObject';\n\n/**\n * Flattens a nested plain object into a map of dot-notation path keys to leaf values.\n * Keys containing unsafe segments (`__proto__`, `constructor`, `prototype`) are silently skipped.\n * Nesting beyond MAX_FLATTEN_DEPTH is treated as an opaque leaf value to prevent stack overflows.\n *\n * @example\n * ```ts\n * flattenPaths({ a: { b: 1, c: 2 }, d: 3 })\n * // { 'a.b': 1, 'a.c': 2, 'd': 3 }\n * ```\n */\nconst MAX_FLATTEN_DEPTH = 10;\n\nfunction _flattenPaths(obj: Record<string, unknown>, prefix: string, depth: number): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n\n for (const [key, val] of Object.entries(obj)) {\n if (UNSAFE_PATH_SEGMENTS.has(key)) continue;\n\n const fullKey = prefix ? `${prefix}.${key}` : key;\n\n if (isPlainObject(val) && depth < MAX_FLATTEN_DEPTH) {\n Object.assign(result, _flattenPaths(val as Record<string, unknown>, fullKey, depth + 1));\n } else {\n result[fullKey] = val;\n }\n }\n\n return result;\n}\n\nexport function flattenPaths(obj: Record<string, unknown>): Record<string, unknown> {\n return _flattenPaths(obj, '', 0);\n}\n\n/**\n * Reconstructs a nested plain object from a map of dot-notation path keys to leaf values.\n * Any path containing an unsafe segment is silently skipped.\n *\n * @example\n * ```ts\n * unflattenPaths({ 'a.b': 1, 'a.c': 2, 'd': 3 })\n * // { a: { b: 1, c: 2 }, d: 3 }\n * ```\n */\nexport function unflattenPaths(flat: Record<string, unknown>): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n\n for (const [key, val] of Object.entries(flat)) {\n const parts = key.split('.');\n\n if (parts.some((p) => UNSAFE_PATH_SEGMENTS.has(p))) continue;\n\n let obj = result;\n\n for (let i = 0; i < parts.length - 1; i++) {\n if (!isPlainObject(obj[parts[i]])) {\n obj[parts[i]] = {};\n }\n\n obj = obj[parts[i]] as Record<string, unknown>;\n }\n\n obj[parts[parts.length - 1]] = val;\n }\n\n return result;\n}\n"],"mappings":"uFAcA,IAAM,EAAoB,GAE1B,SAAS,
|
|
1
|
+
{"version":3,"file":"flattenPaths.cjs","names":[],"sources":["../../src/object/flattenPaths.ts"],"sourcesContent":["import { UNSAFE_PATH_SEGMENTS } from '../_common/unsafePaths';\nimport { isPlainObject } from '../guards/isPlainObject';\n\n/**\n * Flattens a nested plain object into a map of dot-notation path keys to leaf values.\n * Keys containing unsafe segments (`__proto__`, `constructor`, `prototype`) are silently skipped.\n * Nesting beyond MAX_FLATTEN_DEPTH is treated as an opaque leaf value to prevent stack overflows.\n *\n * @example\n * ```ts\n * flattenPaths({ a: { b: 1, c: 2 }, d: 3 })\n * // { 'a.b': 1, 'a.c': 2, 'd': 3 }\n * ```\n */\nconst MAX_FLATTEN_DEPTH = 10;\n\nfunction _flattenPaths(obj: Record<string, unknown>, prefix: string, depth: number): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n\n for (const [key, val] of Object.entries(obj)) {\n if (UNSAFE_PATH_SEGMENTS.has(key)) continue;\n\n const fullKey = prefix ? `${prefix}.${key}` : key;\n\n if (isPlainObject(val) && depth < MAX_FLATTEN_DEPTH) {\n Object.assign(result, _flattenPaths(val as Record<string, unknown>, fullKey, depth + 1));\n } else {\n result[fullKey] = val;\n }\n }\n\n return result;\n}\n\nexport function flattenPaths(obj: Record<string, unknown>): Record<string, unknown> {\n return _flattenPaths(obj, '', 0);\n}\n\n/**\n * Reconstructs a nested plain object from a map of dot-notation path keys to leaf values.\n * Any path containing an unsafe segment is silently skipped.\n *\n * @example\n * ```ts\n * unflattenPaths({ 'a.b': 1, 'a.c': 2, 'd': 3 })\n * // { a: { b: 1, c: 2 }, d: 3 }\n * ```\n */\nexport function unflattenPaths(flat: Record<string, unknown>): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n\n for (const [key, val] of Object.entries(flat)) {\n const parts = key.split('.');\n\n if (parts.some((p) => UNSAFE_PATH_SEGMENTS.has(p))) continue;\n\n let obj = result;\n\n for (let i = 0; i < parts.length - 1; i++) {\n if (!isPlainObject(obj[parts[i]])) {\n obj[parts[i]] = {};\n }\n\n obj = obj[parts[i]] as Record<string, unknown>;\n }\n\n obj[parts[parts.length - 1]] = val;\n }\n\n return result;\n}\n"],"mappings":"uFAcA,IAAM,EAAoB,GAE1B,SAAS,cAAc,EAA8B,EAAgB,EAAwC,CAC3G,IAAM,EAAkC,CAAC,EAEzC,IAAK,GAAM,CAAC,EAAK,KAAQ,OAAO,QAAQ,CAAG,EAAG,CAC5C,GAAI,EAAA,qBAAqB,IAAI,CAAG,EAAG,SAEnC,IAAM,EAAU,EAAS,GAAG,EAAO,GAAG,IAAQ,EAE1C,EAAA,cAAc,CAAG,GAAK,EAAQ,EAChC,OAAO,OAAO,EAAQ,cAAc,EAAgC,EAAS,EAAQ,CAAC,CAAC,EAEvF,EAAO,GAAW,CAEtB,CAEA,OAAO,CACT,CAEA,SAAgB,aAAa,EAAuD,CAClF,OAAO,cAAc,EAAK,GAAI,CAAC,CACjC,CAYA,SAAgB,eAAe,EAAwD,CACrF,IAAM,EAAkC,CAAC,EAEzC,IAAK,GAAM,CAAC,EAAK,KAAQ,OAAO,QAAQ,CAAI,EAAG,CAC7C,IAAM,EAAQ,EAAI,MAAM,GAAG,EAE3B,GAAI,EAAM,KAAM,GAAM,EAAA,qBAAqB,IAAI,CAAC,CAAC,EAAG,SAEpD,IAAI,EAAM,EAEV,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAS,EAAG,IAC/B,EAAA,cAAc,EAAI,EAAM,GAAG,IAC9B,EAAI,EAAM,IAAM,CAAC,GAGnB,EAAM,EAAI,EAAM,IAGlB,EAAI,EAAM,EAAM,OAAS,IAAM,CACjC,CAEA,OAAO,CACT"}
|
|
@@ -1,31 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { isPlainObject as t } from "../guards/isPlainObject.js";
|
|
3
|
-
//#region src/object/flattenPaths.ts
|
|
4
|
-
var n = 10;
|
|
5
|
-
function r(i, a, o) {
|
|
6
|
-
let s = {};
|
|
7
|
-
for (let [c, l] of Object.entries(i)) {
|
|
8
|
-
if (e.has(c)) continue;
|
|
9
|
-
let i = a ? `${a}.${c}` : c;
|
|
10
|
-
t(l) && o < n ? Object.assign(s, r(l, i, o + 1)) : s[i] = l;
|
|
11
|
-
}
|
|
12
|
-
return s;
|
|
13
|
-
}
|
|
14
|
-
function i(e) {
|
|
15
|
-
return r(e, "", 0);
|
|
16
|
-
}
|
|
17
|
-
function a(n) {
|
|
18
|
-
let r = {};
|
|
19
|
-
for (let [i, a] of Object.entries(n)) {
|
|
20
|
-
let n = i.split(".");
|
|
21
|
-
if (n.some((t) => e.has(t))) continue;
|
|
22
|
-
let o = r;
|
|
23
|
-
for (let e = 0; e < n.length - 1; e++) t(o[n[e]]) || (o[n[e]] = {}), o = o[n[e]];
|
|
24
|
-
o[n[n.length - 1]] = a;
|
|
25
|
-
}
|
|
26
|
-
return r;
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
|
-
export { i as flattenPaths, a as unflattenPaths };
|
|
30
|
-
|
|
1
|
+
import{UNSAFE_PATH_SEGMENTS as e}from"../_common/unsafePaths.js";import{isPlainObject as t}from"../guards/isPlainObject.js";var n=10;function _flattenPaths(r,i,a){let o={};for(let[s,c]of Object.entries(r)){if(e.has(s))continue;let r=i?`${i}.${s}`:s;t(c)&&a<n?Object.assign(o,_flattenPaths(c,r,a+1)):o[r]=c}return o}function flattenPaths(e){return _flattenPaths(e,``,0)}function unflattenPaths(n){let r={};for(let[i,a]of Object.entries(n)){let n=i.split(`.`);if(n.some(t=>e.has(t)))continue;let o=r;for(let e=0;e<n.length-1;e++)t(o[n[e]])||(o[n[e]]={}),o=o[n[e]];o[n[n.length-1]]=a}return r}export{flattenPaths,unflattenPaths};
|
|
31
2
|
//# sourceMappingURL=flattenPaths.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenPaths.js","names":[],"sources":["../../src/object/flattenPaths.ts"],"sourcesContent":["import { UNSAFE_PATH_SEGMENTS } from '../_common/unsafePaths';\nimport { isPlainObject } from '../guards/isPlainObject';\n\n/**\n * Flattens a nested plain object into a map of dot-notation path keys to leaf values.\n * Keys containing unsafe segments (`__proto__`, `constructor`, `prototype`) are silently skipped.\n * Nesting beyond MAX_FLATTEN_DEPTH is treated as an opaque leaf value to prevent stack overflows.\n *\n * @example\n * ```ts\n * flattenPaths({ a: { b: 1, c: 2 }, d: 3 })\n * // { 'a.b': 1, 'a.c': 2, 'd': 3 }\n * ```\n */\nconst MAX_FLATTEN_DEPTH = 10;\n\nfunction _flattenPaths(obj: Record<string, unknown>, prefix: string, depth: number): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n\n for (const [key, val] of Object.entries(obj)) {\n if (UNSAFE_PATH_SEGMENTS.has(key)) continue;\n\n const fullKey = prefix ? `${prefix}.${key}` : key;\n\n if (isPlainObject(val) && depth < MAX_FLATTEN_DEPTH) {\n Object.assign(result, _flattenPaths(val as Record<string, unknown>, fullKey, depth + 1));\n } else {\n result[fullKey] = val;\n }\n }\n\n return result;\n}\n\nexport function flattenPaths(obj: Record<string, unknown>): Record<string, unknown> {\n return _flattenPaths(obj, '', 0);\n}\n\n/**\n * Reconstructs a nested plain object from a map of dot-notation path keys to leaf values.\n * Any path containing an unsafe segment is silently skipped.\n *\n * @example\n * ```ts\n * unflattenPaths({ 'a.b': 1, 'a.c': 2, 'd': 3 })\n * // { a: { b: 1, c: 2 }, d: 3 }\n * ```\n */\nexport function unflattenPaths(flat: Record<string, unknown>): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n\n for (const [key, val] of Object.entries(flat)) {\n const parts = key.split('.');\n\n if (parts.some((p) => UNSAFE_PATH_SEGMENTS.has(p))) continue;\n\n let obj = result;\n\n for (let i = 0; i < parts.length - 1; i++) {\n if (!isPlainObject(obj[parts[i]])) {\n obj[parts[i]] = {};\n }\n\n obj = obj[parts[i]] as Record<string, unknown>;\n }\n\n obj[parts[parts.length - 1]] = val;\n }\n\n return result;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"flattenPaths.js","names":[],"sources":["../../src/object/flattenPaths.ts"],"sourcesContent":["import { UNSAFE_PATH_SEGMENTS } from '../_common/unsafePaths';\nimport { isPlainObject } from '../guards/isPlainObject';\n\n/**\n * Flattens a nested plain object into a map of dot-notation path keys to leaf values.\n * Keys containing unsafe segments (`__proto__`, `constructor`, `prototype`) are silently skipped.\n * Nesting beyond MAX_FLATTEN_DEPTH is treated as an opaque leaf value to prevent stack overflows.\n *\n * @example\n * ```ts\n * flattenPaths({ a: { b: 1, c: 2 }, d: 3 })\n * // { 'a.b': 1, 'a.c': 2, 'd': 3 }\n * ```\n */\nconst MAX_FLATTEN_DEPTH = 10;\n\nfunction _flattenPaths(obj: Record<string, unknown>, prefix: string, depth: number): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n\n for (const [key, val] of Object.entries(obj)) {\n if (UNSAFE_PATH_SEGMENTS.has(key)) continue;\n\n const fullKey = prefix ? `${prefix}.${key}` : key;\n\n if (isPlainObject(val) && depth < MAX_FLATTEN_DEPTH) {\n Object.assign(result, _flattenPaths(val as Record<string, unknown>, fullKey, depth + 1));\n } else {\n result[fullKey] = val;\n }\n }\n\n return result;\n}\n\nexport function flattenPaths(obj: Record<string, unknown>): Record<string, unknown> {\n return _flattenPaths(obj, '', 0);\n}\n\n/**\n * Reconstructs a nested plain object from a map of dot-notation path keys to leaf values.\n * Any path containing an unsafe segment is silently skipped.\n *\n * @example\n * ```ts\n * unflattenPaths({ 'a.b': 1, 'a.c': 2, 'd': 3 })\n * // { a: { b: 1, c: 2 }, d: 3 }\n * ```\n */\nexport function unflattenPaths(flat: Record<string, unknown>): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n\n for (const [key, val] of Object.entries(flat)) {\n const parts = key.split('.');\n\n if (parts.some((p) => UNSAFE_PATH_SEGMENTS.has(p))) continue;\n\n let obj = result;\n\n for (let i = 0; i < parts.length - 1; i++) {\n if (!isPlainObject(obj[parts[i]])) {\n obj[parts[i]] = {};\n }\n\n obj = obj[parts[i]] as Record<string, unknown>;\n }\n\n obj[parts[parts.length - 1]] = val;\n }\n\n return result;\n}\n"],"mappings":"4HAcA,IAAM,EAAoB,GAE1B,SAAS,cAAc,EAA8B,EAAgB,EAAwC,CAC3G,IAAM,EAAkC,CAAC,EAEzC,IAAK,GAAM,CAAC,EAAK,KAAQ,OAAO,QAAQ,CAAG,EAAG,CAC5C,GAAI,EAAqB,IAAI,CAAG,EAAG,SAEnC,IAAM,EAAU,EAAS,GAAG,EAAO,GAAG,IAAQ,EAE1C,EAAc,CAAG,GAAK,EAAQ,EAChC,OAAO,OAAO,EAAQ,cAAc,EAAgC,EAAS,EAAQ,CAAC,CAAC,EAEvF,EAAO,GAAW,CAEtB,CAEA,OAAO,CACT,CAEA,SAAgB,aAAa,EAAuD,CAClF,OAAO,cAAc,EAAK,GAAI,CAAC,CACjC,CAYA,SAAgB,eAAe,EAAwD,CACrF,IAAM,EAAkC,CAAC,EAEzC,IAAK,GAAM,CAAC,EAAK,KAAQ,OAAO,QAAQ,CAAI,EAAG,CAC7C,IAAM,EAAQ,EAAI,MAAM,GAAG,EAE3B,GAAI,EAAM,KAAM,GAAM,EAAqB,IAAI,CAAC,CAAC,EAAG,SAEpD,IAAI,EAAM,EAEV,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAS,EAAG,IAC/B,EAAc,EAAI,EAAM,GAAG,IAC9B,EAAI,EAAM,IAAM,CAAC,GAGnB,EAAM,EAAI,EAAM,IAGlB,EAAI,EAAM,EAAM,OAAS,IAAM,CACjC,CAEA,OAAO,CACT"}
|
package/dist/object/getPath.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../_common/unsafePaths.cjs");function
|
|
1
|
+
const e=require("../_common/unsafePaths.cjs");function pathSegments(e){return e.replace(/\[(\d+)\]/g,`.$1`).replace(/^\.|\.$/g,``).split(`.`).filter(Boolean)}function readPath(t,n){let r=t;for(let t of pathSegments(n))if(e.UNSAFE_PATH_SEGMENTS.has(t)||typeof r!=`object`||!r||(r=r[t],r===void 0))return;return r}function getPath(e,t){return readPath(e,t)}function getPathOr(e,t,n){let r=readPath(e,t);return r===void 0?n:r}function requirePath(e,t){let n=readPath(e,t);if(n===void 0)throw TypeError(`Path does not exist: '${t}'`);return n}exports.getPath=getPath,exports.getPathOr=getPathOr,exports.requirePath=requirePath;
|
|
2
2
|
//# sourceMappingURL=getPath.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPath.cjs","names":[],"sources":["../../src/object/getPath.ts"],"sourcesContent":["import { UNSAFE_PATH_SEGMENTS } from '../_common/unsafePaths';\nimport type { Obj } from '../types';\n\ntype PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : undefined\n : P extends keyof T\n ? T[P]\n : undefined;\n\nfunction pathSegments(path: string): string[] {\n return path\n .replace(/\\[(\\d+)\\]/g, '.$1')\n .replace(/^\\.|\\.$/g, '')\n .split('.')\n .filter(Boolean);\n}\n\nfunction readPath(item: Obj, path: string): unknown {\n let current: unknown = item;\n\n for (const segment of pathSegments(path)) {\n if (UNSAFE_PATH_SEGMENTS.has(segment) || current == null || typeof current !== 'object') return undefined;\n\n current = (current as Record<string, unknown>)[segment];\n\n if (current === undefined) return undefined;\n }\n\n return current;\n}\n\n/**\n * Retrieves a value at a dot-notation or numeric bracket-notation path.\n * Returns `undefined` when the path is missing or contains an unsafe segment.\n * Use `getPathOr` to supply a fallback or `requirePath` to throw on a missing path.\n */\nexport function getPath<T extends Obj, P extends string>(item: T, path: P): PathValue<T, P> | undefined {\n return readPath(item, path) as PathValue<T, P> | undefined;\n}\n\n/**\n * Retrieves a value at a path or returns `fallback` when the path is missing.\n */\nexport function getPathOr<T extends Obj, P extends string, F>(item: T, path: P, fallback: F): PathValue<T, P> | F {\n const value = readPath(item, path);\n\n return (value === undefined ? fallback : value) as PathValue<T, P> | F;\n}\n\n/**\n * Retrieves a value at a path or throws when the path is missing.\n */\nexport function requirePath<T extends Obj, P extends string>(item: T, path: P): Exclude<PathValue<T, P>, undefined> {\n const value = readPath(item, path);\n\n if (value === undefined) throw new TypeError(`Path does not exist: '${path}'`);\n\n return value as Exclude<PathValue<T, P>, undefined>;\n}\n"],"mappings":"8CAWA,SAAS,
|
|
1
|
+
{"version":3,"file":"getPath.cjs","names":[],"sources":["../../src/object/getPath.ts"],"sourcesContent":["import { UNSAFE_PATH_SEGMENTS } from '../_common/unsafePaths';\nimport type { Obj } from '../types';\n\ntype PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : undefined\n : P extends keyof T\n ? T[P]\n : undefined;\n\nfunction pathSegments(path: string): string[] {\n return path\n .replace(/\\[(\\d+)\\]/g, '.$1')\n .replace(/^\\.|\\.$/g, '')\n .split('.')\n .filter(Boolean);\n}\n\nfunction readPath(item: Obj, path: string): unknown {\n let current: unknown = item;\n\n for (const segment of pathSegments(path)) {\n if (UNSAFE_PATH_SEGMENTS.has(segment) || current == null || typeof current !== 'object') return undefined;\n\n current = (current as Record<string, unknown>)[segment];\n\n if (current === undefined) return undefined;\n }\n\n return current;\n}\n\n/**\n * Retrieves a value at a dot-notation or numeric bracket-notation path.\n * Returns `undefined` when the path is missing or contains an unsafe segment.\n * Use `getPathOr` to supply a fallback or `requirePath` to throw on a missing path.\n */\nexport function getPath<T extends Obj, P extends string>(item: T, path: P): PathValue<T, P> | undefined {\n return readPath(item, path) as PathValue<T, P> | undefined;\n}\n\n/**\n * Retrieves a value at a path or returns `fallback` when the path is missing.\n */\nexport function getPathOr<T extends Obj, P extends string, F>(item: T, path: P, fallback: F): PathValue<T, P> | F {\n const value = readPath(item, path);\n\n return (value === undefined ? fallback : value) as PathValue<T, P> | F;\n}\n\n/**\n * Retrieves a value at a path or throws when the path is missing.\n */\nexport function requirePath<T extends Obj, P extends string>(item: T, path: P): Exclude<PathValue<T, P>, undefined> {\n const value = readPath(item, path);\n\n if (value === undefined) throw new TypeError(`Path does not exist: '${path}'`);\n\n return value as Exclude<PathValue<T, P>, undefined>;\n}\n"],"mappings":"8CAWA,SAAS,aAAa,EAAwB,CAC5C,OAAO,EACJ,QAAQ,aAAc,KAAK,CAAC,CAC5B,QAAQ,WAAY,EAAE,CAAC,CACvB,MAAM,GAAG,CAAC,CACV,OAAO,OAAO,CACnB,CAEA,SAAS,SAAS,EAAW,EAAuB,CAClD,IAAI,EAAmB,EAEvB,IAAK,IAAM,KAAW,aAAa,CAAI,EAKrC,GAJI,EAAA,qBAAqB,IAAI,CAAO,GAAwB,OAAO,GAAY,WAAtC,IAEzC,EAAW,EAAoC,GAE3C,IAAY,IAAA,IAAW,OAG7B,OAAO,CACT,CAOA,SAAgB,QAAyC,EAAS,EAAsC,CACtG,OAAO,SAAS,EAAM,CAAI,CAC5B,CAKA,SAAgB,UAA8C,EAAS,EAAS,EAAkC,CAChH,IAAM,EAAQ,SAAS,EAAM,CAAI,EAEjC,OAAQ,IAAU,IAAA,GAAY,EAAW,CAC3C,CAKA,SAAgB,YAA6C,EAAS,EAA8C,CAClH,IAAM,EAAQ,SAAS,EAAM,CAAI,EAEjC,GAAI,IAAU,IAAA,GAAW,MAAU,UAAU,yBAAyB,EAAK,EAAE,EAE7E,OAAO,CACT"}
|
package/dist/object/getPath.js
CHANGED
|
@@ -1,26 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
//#region src/object/getPath.ts
|
|
3
|
-
function t(e) {
|
|
4
|
-
return e.replace(/\[(\d+)\]/g, ".$1").replace(/^\.|\.$/g, "").split(".").filter(Boolean);
|
|
5
|
-
}
|
|
6
|
-
function n(n, r) {
|
|
7
|
-
let i = n;
|
|
8
|
-
for (let n of t(r)) if (e.has(n) || typeof i != "object" || !i || (i = i[n], i === void 0)) return;
|
|
9
|
-
return i;
|
|
10
|
-
}
|
|
11
|
-
function r(e, t) {
|
|
12
|
-
return n(e, t);
|
|
13
|
-
}
|
|
14
|
-
function i(e, t, r) {
|
|
15
|
-
let i = n(e, t);
|
|
16
|
-
return i === void 0 ? r : i;
|
|
17
|
-
}
|
|
18
|
-
function a(e, t) {
|
|
19
|
-
let r = n(e, t);
|
|
20
|
-
if (r === void 0) throw TypeError(`Path does not exist: '${t}'`);
|
|
21
|
-
return r;
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
|
-
export { r as getPath, i as getPathOr, a as requirePath };
|
|
25
|
-
|
|
1
|
+
import{UNSAFE_PATH_SEGMENTS as e}from"../_common/unsafePaths.js";function pathSegments(e){return e.replace(/\[(\d+)\]/g,`.$1`).replace(/^\.|\.$/g,``).split(`.`).filter(Boolean)}function readPath(t,n){let r=t;for(let t of pathSegments(n))if(e.has(t)||typeof r!=`object`||!r||(r=r[t],r===void 0))return;return r}function getPath(e,t){return readPath(e,t)}function getPathOr(e,t,n){let r=readPath(e,t);return r===void 0?n:r}function requirePath(e,t){let n=readPath(e,t);if(n===void 0)throw TypeError(`Path does not exist: '${t}'`);return n}export{getPath,getPathOr,requirePath};
|
|
26
2
|
//# sourceMappingURL=getPath.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPath.js","names":[],"sources":["../../src/object/getPath.ts"],"sourcesContent":["import { UNSAFE_PATH_SEGMENTS } from '../_common/unsafePaths';\nimport type { Obj } from '../types';\n\ntype PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : undefined\n : P extends keyof T\n ? T[P]\n : undefined;\n\nfunction pathSegments(path: string): string[] {\n return path\n .replace(/\\[(\\d+)\\]/g, '.$1')\n .replace(/^\\.|\\.$/g, '')\n .split('.')\n .filter(Boolean);\n}\n\nfunction readPath(item: Obj, path: string): unknown {\n let current: unknown = item;\n\n for (const segment of pathSegments(path)) {\n if (UNSAFE_PATH_SEGMENTS.has(segment) || current == null || typeof current !== 'object') return undefined;\n\n current = (current as Record<string, unknown>)[segment];\n\n if (current === undefined) return undefined;\n }\n\n return current;\n}\n\n/**\n * Retrieves a value at a dot-notation or numeric bracket-notation path.\n * Returns `undefined` when the path is missing or contains an unsafe segment.\n * Use `getPathOr` to supply a fallback or `requirePath` to throw on a missing path.\n */\nexport function getPath<T extends Obj, P extends string>(item: T, path: P): PathValue<T, P> | undefined {\n return readPath(item, path) as PathValue<T, P> | undefined;\n}\n\n/**\n * Retrieves a value at a path or returns `fallback` when the path is missing.\n */\nexport function getPathOr<T extends Obj, P extends string, F>(item: T, path: P, fallback: F): PathValue<T, P> | F {\n const value = readPath(item, path);\n\n return (value === undefined ? fallback : value) as PathValue<T, P> | F;\n}\n\n/**\n * Retrieves a value at a path or throws when the path is missing.\n */\nexport function requirePath<T extends Obj, P extends string>(item: T, path: P): Exclude<PathValue<T, P>, undefined> {\n const value = readPath(item, path);\n\n if (value === undefined) throw new TypeError(`Path does not exist: '${path}'`);\n\n return value as Exclude<PathValue<T, P>, undefined>;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getPath.js","names":[],"sources":["../../src/object/getPath.ts"],"sourcesContent":["import { UNSAFE_PATH_SEGMENTS } from '../_common/unsafePaths';\nimport type { Obj } from '../types';\n\ntype PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : undefined\n : P extends keyof T\n ? T[P]\n : undefined;\n\nfunction pathSegments(path: string): string[] {\n return path\n .replace(/\\[(\\d+)\\]/g, '.$1')\n .replace(/^\\.|\\.$/g, '')\n .split('.')\n .filter(Boolean);\n}\n\nfunction readPath(item: Obj, path: string): unknown {\n let current: unknown = item;\n\n for (const segment of pathSegments(path)) {\n if (UNSAFE_PATH_SEGMENTS.has(segment) || current == null || typeof current !== 'object') return undefined;\n\n current = (current as Record<string, unknown>)[segment];\n\n if (current === undefined) return undefined;\n }\n\n return current;\n}\n\n/**\n * Retrieves a value at a dot-notation or numeric bracket-notation path.\n * Returns `undefined` when the path is missing or contains an unsafe segment.\n * Use `getPathOr` to supply a fallback or `requirePath` to throw on a missing path.\n */\nexport function getPath<T extends Obj, P extends string>(item: T, path: P): PathValue<T, P> | undefined {\n return readPath(item, path) as PathValue<T, P> | undefined;\n}\n\n/**\n * Retrieves a value at a path or returns `fallback` when the path is missing.\n */\nexport function getPathOr<T extends Obj, P extends string, F>(item: T, path: P, fallback: F): PathValue<T, P> | F {\n const value = readPath(item, path);\n\n return (value === undefined ? fallback : value) as PathValue<T, P> | F;\n}\n\n/**\n * Retrieves a value at a path or throws when the path is missing.\n */\nexport function requirePath<T extends Obj, P extends string>(item: T, path: P): Exclude<PathValue<T, P>, undefined> {\n const value = readPath(item, path);\n\n if (value === undefined) throw new TypeError(`Path does not exist: '${path}'`);\n\n return value as Exclude<PathValue<T, P>, undefined>;\n}\n"],"mappings":"iEAWA,SAAS,aAAa,EAAwB,CAC5C,OAAO,EACJ,QAAQ,aAAc,KAAK,CAAC,CAC5B,QAAQ,WAAY,EAAE,CAAC,CACvB,MAAM,GAAG,CAAC,CACV,OAAO,OAAO,CACnB,CAEA,SAAS,SAAS,EAAW,EAAuB,CAClD,IAAI,EAAmB,EAEvB,IAAK,IAAM,KAAW,aAAa,CAAI,EAKrC,GAJI,EAAqB,IAAI,CAAO,GAAwB,OAAO,GAAY,WAAtC,IAEzC,EAAW,EAAoC,GAE3C,IAAY,IAAA,IAAW,OAG7B,OAAO,CACT,CAOA,SAAgB,QAAyC,EAAS,EAAsC,CACtG,OAAO,SAAS,EAAM,CAAI,CAC5B,CAKA,SAAgB,UAA8C,EAAS,EAAS,EAAkC,CAChH,IAAM,EAAQ,SAAS,EAAM,CAAI,EAEjC,OAAQ,IAAU,IAAA,GAAY,EAAW,CAC3C,CAKA,SAAgB,YAA6C,EAAS,EAA8C,CAClH,IAAM,EAAQ,SAAS,EAAM,CAAI,EAEjC,GAAI,IAAU,IAAA,GAAW,MAAU,UAAU,yBAAyB,EAAK,EAAE,EAE7E,OAAO,CACT"}
|
package/dist/object/hash.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../errors.cjs");function t
|
|
1
|
+
const e=require("../errors.cjs");function _hash(t,n,r){if(t===void 0)return`undefined`;if(t===null)return`null`;if(typeof t==`bigint`)return`${t}n`;if(typeof t!=`object`)return JSON.stringify(t);if(r.has(t))return`[Circular]`;if(r.add(t),t instanceof Date)return`[Date:${Number.isNaN(t.getTime())?`Invalid`:t.toISOString()}]`;if(t instanceof RegExp)return`[RegExp:${t.source}/${t.flags}]`;if(t instanceof Set)return`[Set:${[...t].map(e=>_hash(e,n,r)).sort().join(`,`)}]`;if(t instanceof Map)return`[Map:${[...t.entries()].map(([e,t])=>[_hash(e,n,r),_hash(t,n,r)]).sort(([e,t],[n,r])=>e===n?t.localeCompare(r):e.localeCompare(n)).map(([e,t])=>`${e}=>${t}`).join(`,`)}]`;if(Array.isArray(t))return`[${t.map(e=>_hash(e,n,r)).join(`,`)}]`;let i=Object.getPrototypeOf(t);if(i!==Object.prototype&&i!==null){if(n?.onClassInstance===`throw`)throw new e.ArsenalSerializationError(`hash: unsupported type ${t.constructor?.name??`unknown`}`);return String(t)}let a=t;return`{${Object.keys(a).filter(e=>a[e]!==void 0).sort().map(e=>`${JSON.stringify(e)}:${_hash(a[e],n,r)}`).join(`,`)}}`}function hash(e,t){return _hash(e,t,new Set)}exports.hash=hash;
|
|
2
2
|
//# sourceMappingURL=hash.cjs.map
|
package/dist/object/hash.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.cjs","names":[],"sources":["../../src/object/hash.ts"],"sourcesContent":["import { ArsenalSerializationError } from '../errors';\n\nexport type HashOptions = {\n /**\n * What to do when a class instance is encountered (an object whose prototype is\n * neither `Object.prototype` nor `null`).\n *\n * - `'coerce'` (default) — calls `String(value)`.\n * - `'throw'` — throws an `ArsenalSerializationError`.\n */\n onClassInstance?: 'coerce' | 'throw';\n};\n\n/**\n * Produces a deterministic, order-independent string representation of any value.\n * Object keys are sorted alphabetically, so `{ b: 1, a: 2 }` and `{ a: 2, b: 1 }` produce\n * the same output. Handles `Date`, `RegExp`, `Set`, `Map`, and `bigint` in addition to plain JSON.\n *\n * Useful for generating stable cache keys from arbitrary query parameters or options objects.\n *\n * Class instances fall back to `String(value)` by default.\n * Pass `{ onClassInstance: 'throw' }` to throw an `ArsenalSerializationError` instead.\n *\n * @example\n * ```ts\n * hash({ b: 2, a: 1 }) // '{\"a\":1,\"b\":2}'\n * hash([3, 1, 2]) // '[3,1,2]'\n * hash(new Date('2024-01-01T00:00:00Z')) // '[Date:2024-01-01T00:00:00.000Z]'\n * hash(new Set([3, 1, 2])) // '[Set:1,2,3]'\n * hash(new MyClass(), { onClassInstance: 'throw' }) // throws ArsenalSerializationError\n * ```\n *\n * @throws {ArsenalSerializationError} If `options.onClassInstance` is `'throw'` and a class instance is encountered.\n */\nfunction _hash(value: unknown, options: HashOptions | undefined, visited: Set<object>): string {\n if (value === undefined) return 'undefined';\n\n if (value === null) return 'null';\n\n if (typeof value === 'bigint') return `${value}n`;\n\n if (typeof value !== 'object') return JSON.stringify(value);\n\n if (visited.has(value as object)) return '[Circular]';\n\n visited.add(value as object);\n\n if (value instanceof Date) return `[Date:${Number.isNaN(value.getTime()) ? 'Invalid' : value.toISOString()}]`;\n\n if (value instanceof RegExp) return `[RegExp:${value.source}/${value.flags}]`;\n\n if (value instanceof Set)\n return `[Set:${[...value]\n .map((v) => _hash(v, options, visited))\n .sort()\n .join(',')}]`;\n\n if (value instanceof Map) {\n const entries = [...value.entries()]\n .map(([key, entryValue]) => [_hash(key, options, visited), _hash(entryValue, options, visited)] as const)\n .sort(([leftKey, leftValue], [rightKey, rightValue]) =>\n leftKey === rightKey ? leftValue.localeCompare(rightValue) : leftKey.localeCompare(rightKey),\n );\n\n return `[Map:${entries.map(([key, entryValue]) => `${key}=>${entryValue}`).join(',')}]`;\n }\n\n if (Array.isArray(value)) return `[${value.map((v) => _hash(v, options, visited)).join(',')}]`;\n\n const proto = Object.getPrototypeOf(value) as unknown;\n\n if (proto !== Object.prototype && proto !== null) {\n if (options?.onClassInstance === 'throw') {\n throw new ArsenalSerializationError(\n `hash: unsupported type ${(value as { constructor?: { name?: string } }).constructor?.name ?? 'unknown'}`,\n );\n }\n\n return String(value);\n }\n\n const rec = value as Record<string, unknown>;\n const keys = Object.keys(rec)\n .filter((k) => rec[k] !== undefined)\n .sort();\n\n return `{${keys.map((k) => `${JSON.stringify(k)}:${_hash(rec[k], options, visited)}`).join(',')}}`;\n}\n\nexport function hash(value: unknown, options?: HashOptions): string {\n return _hash(value, options, new Set<object>());\n}\n"],"mappings":"iCAkCA,SAAS,
|
|
1
|
+
{"version":3,"file":"hash.cjs","names":[],"sources":["../../src/object/hash.ts"],"sourcesContent":["import { ArsenalSerializationError } from '../errors';\n\nexport type HashOptions = {\n /**\n * What to do when a class instance is encountered (an object whose prototype is\n * neither `Object.prototype` nor `null`).\n *\n * - `'coerce'` (default) — calls `String(value)`.\n * - `'throw'` — throws an `ArsenalSerializationError`.\n */\n onClassInstance?: 'coerce' | 'throw';\n};\n\n/**\n * Produces a deterministic, order-independent string representation of any value.\n * Object keys are sorted alphabetically, so `{ b: 1, a: 2 }` and `{ a: 2, b: 1 }` produce\n * the same output. Handles `Date`, `RegExp`, `Set`, `Map`, and `bigint` in addition to plain JSON.\n *\n * Useful for generating stable cache keys from arbitrary query parameters or options objects.\n *\n * Class instances fall back to `String(value)` by default.\n * Pass `{ onClassInstance: 'throw' }` to throw an `ArsenalSerializationError` instead.\n *\n * @example\n * ```ts\n * hash({ b: 2, a: 1 }) // '{\"a\":1,\"b\":2}'\n * hash([3, 1, 2]) // '[3,1,2]'\n * hash(new Date('2024-01-01T00:00:00Z')) // '[Date:2024-01-01T00:00:00.000Z]'\n * hash(new Set([3, 1, 2])) // '[Set:1,2,3]'\n * hash(new MyClass(), { onClassInstance: 'throw' }) // throws ArsenalSerializationError\n * ```\n *\n * @throws {ArsenalSerializationError} If `options.onClassInstance` is `'throw'` and a class instance is encountered.\n */\nfunction _hash(value: unknown, options: HashOptions | undefined, visited: Set<object>): string {\n if (value === undefined) return 'undefined';\n\n if (value === null) return 'null';\n\n if (typeof value === 'bigint') return `${value}n`;\n\n if (typeof value !== 'object') return JSON.stringify(value);\n\n if (visited.has(value as object)) return '[Circular]';\n\n visited.add(value as object);\n\n if (value instanceof Date) return `[Date:${Number.isNaN(value.getTime()) ? 'Invalid' : value.toISOString()}]`;\n\n if (value instanceof RegExp) return `[RegExp:${value.source}/${value.flags}]`;\n\n if (value instanceof Set)\n return `[Set:${[...value]\n .map((v) => _hash(v, options, visited))\n .sort()\n .join(',')}]`;\n\n if (value instanceof Map) {\n const entries = [...value.entries()]\n .map(([key, entryValue]) => [_hash(key, options, visited), _hash(entryValue, options, visited)] as const)\n .sort(([leftKey, leftValue], [rightKey, rightValue]) =>\n leftKey === rightKey ? leftValue.localeCompare(rightValue) : leftKey.localeCompare(rightKey),\n );\n\n return `[Map:${entries.map(([key, entryValue]) => `${key}=>${entryValue}`).join(',')}]`;\n }\n\n if (Array.isArray(value)) return `[${value.map((v) => _hash(v, options, visited)).join(',')}]`;\n\n const proto = Object.getPrototypeOf(value) as unknown;\n\n if (proto !== Object.prototype && proto !== null) {\n if (options?.onClassInstance === 'throw') {\n throw new ArsenalSerializationError(\n `hash: unsupported type ${(value as { constructor?: { name?: string } }).constructor?.name ?? 'unknown'}`,\n );\n }\n\n return String(value);\n }\n\n const rec = value as Record<string, unknown>;\n const keys = Object.keys(rec)\n .filter((k) => rec[k] !== undefined)\n .sort();\n\n return `{${keys.map((k) => `${JSON.stringify(k)}:${_hash(rec[k], options, visited)}`).join(',')}}`;\n}\n\nexport function hash(value: unknown, options?: HashOptions): string {\n return _hash(value, options, new Set<object>());\n}\n"],"mappings":"iCAkCA,SAAS,MAAM,EAAgB,EAAkC,EAA8B,CAC7F,GAAI,IAAU,IAAA,GAAW,MAAO,YAEhC,GAAI,IAAU,KAAM,MAAO,OAE3B,GAAI,OAAO,GAAU,SAAU,MAAO,GAAG,EAAM,GAE/C,GAAI,OAAO,GAAU,SAAU,OAAO,KAAK,UAAU,CAAK,EAE1D,GAAI,EAAQ,IAAI,CAAe,EAAG,MAAO,aAIzC,GAFA,EAAQ,IAAI,CAAe,EAEvB,aAAiB,KAAM,MAAO,SAAS,OAAO,MAAM,EAAM,QAAQ,CAAC,EAAI,UAAY,EAAM,YAAY,EAAE,GAE3G,GAAI,aAAiB,OAAQ,MAAO,WAAW,EAAM,OAAO,GAAG,EAAM,MAAM,GAE3E,GAAI,aAAiB,IACnB,MAAO,QAAQ,CAAC,GAAG,CAAK,CAAC,CACtB,IAAK,GAAM,MAAM,EAAG,EAAS,CAAO,CAAC,CAAC,CACtC,KAAK,CAAC,CACN,KAAK,GAAG,EAAE,GAEf,GAAI,aAAiB,IAOnB,MAAO,QANS,CAAC,GAAG,EAAM,QAAQ,CAAC,CAAC,CACjC,KAAK,CAAC,EAAK,KAAgB,CAAC,MAAM,EAAK,EAAS,CAAO,EAAG,MAAM,EAAY,EAAS,CAAO,CAAC,CAAU,CAAC,CACxG,MAAM,CAAC,EAAS,GAAY,CAAC,EAAU,KACtC,IAAY,EAAW,EAAU,cAAc,CAAU,EAAI,EAAQ,cAAc,CAAQ,CAGhF,CAAA,CAAQ,KAAK,CAAC,EAAK,KAAgB,GAAG,EAAI,IAAI,GAAY,CAAC,CAAC,KAAK,GAAG,EAAE,GAGvF,GAAI,MAAM,QAAQ,CAAK,EAAG,MAAO,IAAI,EAAM,IAAK,GAAM,MAAM,EAAG,EAAS,CAAO,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,GAE5F,IAAM,EAAQ,OAAO,eAAe,CAAK,EAEzC,GAAI,IAAU,OAAO,WAAa,IAAU,KAAM,CAChD,GAAI,GAAS,kBAAoB,QAC/B,MAAM,IAAI,EAAA,0BACR,0BAA2B,EAA8C,aAAa,MAAQ,WAChG,EAGF,OAAO,OAAO,CAAK,CACrB,CAEA,IAAM,EAAM,EAKZ,MAAO,IAJM,OAAO,KAAK,CAAG,CAAC,CAC1B,OAAQ,GAAM,EAAI,KAAO,IAAA,EAAS,CAAC,CACnC,KAEQ,CAAA,CAAK,IAAK,GAAM,GAAG,KAAK,UAAU,CAAC,EAAE,GAAG,MAAM,EAAI,GAAI,EAAS,CAAO,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,EAClG,CAEA,SAAgB,KAAK,EAAgB,EAA+B,CAClE,OAAO,MAAM,EAAO,EAAS,IAAI,GAAa,CAChD"}
|
package/dist/object/hash.js
CHANGED
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
//#region src/object/hash.ts
|
|
3
|
-
function t(n, r, i) {
|
|
4
|
-
if (n === void 0) return "undefined";
|
|
5
|
-
if (n === null) return "null";
|
|
6
|
-
if (typeof n == "bigint") return `${n}n`;
|
|
7
|
-
if (typeof n != "object") return JSON.stringify(n);
|
|
8
|
-
if (i.has(n)) return "[Circular]";
|
|
9
|
-
if (i.add(n), n instanceof Date) return `[Date:${Number.isNaN(n.getTime()) ? "Invalid" : n.toISOString()}]`;
|
|
10
|
-
if (n instanceof RegExp) return `[RegExp:${n.source}/${n.flags}]`;
|
|
11
|
-
if (n instanceof Set) return `[Set:${[...n].map((e) => t(e, r, i)).sort().join(",")}]`;
|
|
12
|
-
if (n instanceof Map) return `[Map:${[...n.entries()].map(([e, n]) => [t(e, r, i), t(n, r, i)]).sort(([e, t], [n, r]) => e === n ? t.localeCompare(r) : e.localeCompare(n)).map(([e, t]) => `${e}=>${t}`).join(",")}]`;
|
|
13
|
-
if (Array.isArray(n)) return `[${n.map((e) => t(e, r, i)).join(",")}]`;
|
|
14
|
-
let a = Object.getPrototypeOf(n);
|
|
15
|
-
if (a !== Object.prototype && a !== null) {
|
|
16
|
-
if (r?.onClassInstance === "throw") throw new e(`hash: unsupported type ${n.constructor?.name ?? "unknown"}`);
|
|
17
|
-
return String(n);
|
|
18
|
-
}
|
|
19
|
-
let o = n;
|
|
20
|
-
return `{${Object.keys(o).filter((e) => o[e] !== void 0).sort().map((e) => `${JSON.stringify(e)}:${t(o[e], r, i)}`).join(",")}}`;
|
|
21
|
-
}
|
|
22
|
-
function n(e, n) {
|
|
23
|
-
return t(e, n, /* @__PURE__ */ new Set());
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
export { n as hash };
|
|
27
|
-
|
|
1
|
+
import{ArsenalSerializationError as e}from"../errors.js";function _hash(t,n,r){if(t===void 0)return`undefined`;if(t===null)return`null`;if(typeof t==`bigint`)return`${t}n`;if(typeof t!=`object`)return JSON.stringify(t);if(r.has(t))return`[Circular]`;if(r.add(t),t instanceof Date)return`[Date:${Number.isNaN(t.getTime())?`Invalid`:t.toISOString()}]`;if(t instanceof RegExp)return`[RegExp:${t.source}/${t.flags}]`;if(t instanceof Set)return`[Set:${[...t].map(e=>_hash(e,n,r)).sort().join(`,`)}]`;if(t instanceof Map)return`[Map:${[...t.entries()].map(([e,t])=>[_hash(e,n,r),_hash(t,n,r)]).sort(([e,t],[n,r])=>e===n?t.localeCompare(r):e.localeCompare(n)).map(([e,t])=>`${e}=>${t}`).join(`,`)}]`;if(Array.isArray(t))return`[${t.map(e=>_hash(e,n,r)).join(`,`)}]`;let i=Object.getPrototypeOf(t);if(i!==Object.prototype&&i!==null){if(n?.onClassInstance===`throw`)throw new e(`hash: unsupported type ${t.constructor?.name??`unknown`}`);return String(t)}let a=t;return`{${Object.keys(a).filter(e=>a[e]!==void 0).sort().map(e=>`${JSON.stringify(e)}:${_hash(a[e],n,r)}`).join(`,`)}}`}function hash(e,t){return _hash(e,t,new Set)}export{hash};
|
|
28
2
|
//# sourceMappingURL=hash.js.map
|
package/dist/object/hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","names":[],"sources":["../../src/object/hash.ts"],"sourcesContent":["import { ArsenalSerializationError } from '../errors';\n\nexport type HashOptions = {\n /**\n * What to do when a class instance is encountered (an object whose prototype is\n * neither `Object.prototype` nor `null`).\n *\n * - `'coerce'` (default) — calls `String(value)`.\n * - `'throw'` — throws an `ArsenalSerializationError`.\n */\n onClassInstance?: 'coerce' | 'throw';\n};\n\n/**\n * Produces a deterministic, order-independent string representation of any value.\n * Object keys are sorted alphabetically, so `{ b: 1, a: 2 }` and `{ a: 2, b: 1 }` produce\n * the same output. Handles `Date`, `RegExp`, `Set`, `Map`, and `bigint` in addition to plain JSON.\n *\n * Useful for generating stable cache keys from arbitrary query parameters or options objects.\n *\n * Class instances fall back to `String(value)` by default.\n * Pass `{ onClassInstance: 'throw' }` to throw an `ArsenalSerializationError` instead.\n *\n * @example\n * ```ts\n * hash({ b: 2, a: 1 }) // '{\"a\":1,\"b\":2}'\n * hash([3, 1, 2]) // '[3,1,2]'\n * hash(new Date('2024-01-01T00:00:00Z')) // '[Date:2024-01-01T00:00:00.000Z]'\n * hash(new Set([3, 1, 2])) // '[Set:1,2,3]'\n * hash(new MyClass(), { onClassInstance: 'throw' }) // throws ArsenalSerializationError\n * ```\n *\n * @throws {ArsenalSerializationError} If `options.onClassInstance` is `'throw'` and a class instance is encountered.\n */\nfunction _hash(value: unknown, options: HashOptions | undefined, visited: Set<object>): string {\n if (value === undefined) return 'undefined';\n\n if (value === null) return 'null';\n\n if (typeof value === 'bigint') return `${value}n`;\n\n if (typeof value !== 'object') return JSON.stringify(value);\n\n if (visited.has(value as object)) return '[Circular]';\n\n visited.add(value as object);\n\n if (value instanceof Date) return `[Date:${Number.isNaN(value.getTime()) ? 'Invalid' : value.toISOString()}]`;\n\n if (value instanceof RegExp) return `[RegExp:${value.source}/${value.flags}]`;\n\n if (value instanceof Set)\n return `[Set:${[...value]\n .map((v) => _hash(v, options, visited))\n .sort()\n .join(',')}]`;\n\n if (value instanceof Map) {\n const entries = [...value.entries()]\n .map(([key, entryValue]) => [_hash(key, options, visited), _hash(entryValue, options, visited)] as const)\n .sort(([leftKey, leftValue], [rightKey, rightValue]) =>\n leftKey === rightKey ? leftValue.localeCompare(rightValue) : leftKey.localeCompare(rightKey),\n );\n\n return `[Map:${entries.map(([key, entryValue]) => `${key}=>${entryValue}`).join(',')}]`;\n }\n\n if (Array.isArray(value)) return `[${value.map((v) => _hash(v, options, visited)).join(',')}]`;\n\n const proto = Object.getPrototypeOf(value) as unknown;\n\n if (proto !== Object.prototype && proto !== null) {\n if (options?.onClassInstance === 'throw') {\n throw new ArsenalSerializationError(\n `hash: unsupported type ${(value as { constructor?: { name?: string } }).constructor?.name ?? 'unknown'}`,\n );\n }\n\n return String(value);\n }\n\n const rec = value as Record<string, unknown>;\n const keys = Object.keys(rec)\n .filter((k) => rec[k] !== undefined)\n .sort();\n\n return `{${keys.map((k) => `${JSON.stringify(k)}:${_hash(rec[k], options, visited)}`).join(',')}}`;\n}\n\nexport function hash(value: unknown, options?: HashOptions): string {\n return _hash(value, options, new Set<object>());\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"hash.js","names":[],"sources":["../../src/object/hash.ts"],"sourcesContent":["import { ArsenalSerializationError } from '../errors';\n\nexport type HashOptions = {\n /**\n * What to do when a class instance is encountered (an object whose prototype is\n * neither `Object.prototype` nor `null`).\n *\n * - `'coerce'` (default) — calls `String(value)`.\n * - `'throw'` — throws an `ArsenalSerializationError`.\n */\n onClassInstance?: 'coerce' | 'throw';\n};\n\n/**\n * Produces a deterministic, order-independent string representation of any value.\n * Object keys are sorted alphabetically, so `{ b: 1, a: 2 }` and `{ a: 2, b: 1 }` produce\n * the same output. Handles `Date`, `RegExp`, `Set`, `Map`, and `bigint` in addition to plain JSON.\n *\n * Useful for generating stable cache keys from arbitrary query parameters or options objects.\n *\n * Class instances fall back to `String(value)` by default.\n * Pass `{ onClassInstance: 'throw' }` to throw an `ArsenalSerializationError` instead.\n *\n * @example\n * ```ts\n * hash({ b: 2, a: 1 }) // '{\"a\":1,\"b\":2}'\n * hash([3, 1, 2]) // '[3,1,2]'\n * hash(new Date('2024-01-01T00:00:00Z')) // '[Date:2024-01-01T00:00:00.000Z]'\n * hash(new Set([3, 1, 2])) // '[Set:1,2,3]'\n * hash(new MyClass(), { onClassInstance: 'throw' }) // throws ArsenalSerializationError\n * ```\n *\n * @throws {ArsenalSerializationError} If `options.onClassInstance` is `'throw'` and a class instance is encountered.\n */\nfunction _hash(value: unknown, options: HashOptions | undefined, visited: Set<object>): string {\n if (value === undefined) return 'undefined';\n\n if (value === null) return 'null';\n\n if (typeof value === 'bigint') return `${value}n`;\n\n if (typeof value !== 'object') return JSON.stringify(value);\n\n if (visited.has(value as object)) return '[Circular]';\n\n visited.add(value as object);\n\n if (value instanceof Date) return `[Date:${Number.isNaN(value.getTime()) ? 'Invalid' : value.toISOString()}]`;\n\n if (value instanceof RegExp) return `[RegExp:${value.source}/${value.flags}]`;\n\n if (value instanceof Set)\n return `[Set:${[...value]\n .map((v) => _hash(v, options, visited))\n .sort()\n .join(',')}]`;\n\n if (value instanceof Map) {\n const entries = [...value.entries()]\n .map(([key, entryValue]) => [_hash(key, options, visited), _hash(entryValue, options, visited)] as const)\n .sort(([leftKey, leftValue], [rightKey, rightValue]) =>\n leftKey === rightKey ? leftValue.localeCompare(rightValue) : leftKey.localeCompare(rightKey),\n );\n\n return `[Map:${entries.map(([key, entryValue]) => `${key}=>${entryValue}`).join(',')}]`;\n }\n\n if (Array.isArray(value)) return `[${value.map((v) => _hash(v, options, visited)).join(',')}]`;\n\n const proto = Object.getPrototypeOf(value) as unknown;\n\n if (proto !== Object.prototype && proto !== null) {\n if (options?.onClassInstance === 'throw') {\n throw new ArsenalSerializationError(\n `hash: unsupported type ${(value as { constructor?: { name?: string } }).constructor?.name ?? 'unknown'}`,\n );\n }\n\n return String(value);\n }\n\n const rec = value as Record<string, unknown>;\n const keys = Object.keys(rec)\n .filter((k) => rec[k] !== undefined)\n .sort();\n\n return `{${keys.map((k) => `${JSON.stringify(k)}:${_hash(rec[k], options, visited)}`).join(',')}}`;\n}\n\nexport function hash(value: unknown, options?: HashOptions): string {\n return _hash(value, options, new Set<object>());\n}\n"],"mappings":"yDAkCA,SAAS,MAAM,EAAgB,EAAkC,EAA8B,CAC7F,GAAI,IAAU,IAAA,GAAW,MAAO,YAEhC,GAAI,IAAU,KAAM,MAAO,OAE3B,GAAI,OAAO,GAAU,SAAU,MAAO,GAAG,EAAM,GAE/C,GAAI,OAAO,GAAU,SAAU,OAAO,KAAK,UAAU,CAAK,EAE1D,GAAI,EAAQ,IAAI,CAAe,EAAG,MAAO,aAIzC,GAFA,EAAQ,IAAI,CAAe,EAEvB,aAAiB,KAAM,MAAO,SAAS,OAAO,MAAM,EAAM,QAAQ,CAAC,EAAI,UAAY,EAAM,YAAY,EAAE,GAE3G,GAAI,aAAiB,OAAQ,MAAO,WAAW,EAAM,OAAO,GAAG,EAAM,MAAM,GAE3E,GAAI,aAAiB,IACnB,MAAO,QAAQ,CAAC,GAAG,CAAK,CAAC,CACtB,IAAK,GAAM,MAAM,EAAG,EAAS,CAAO,CAAC,CAAC,CACtC,KAAK,CAAC,CACN,KAAK,GAAG,EAAE,GAEf,GAAI,aAAiB,IAOnB,MAAO,QANS,CAAC,GAAG,EAAM,QAAQ,CAAC,CAAC,CACjC,KAAK,CAAC,EAAK,KAAgB,CAAC,MAAM,EAAK,EAAS,CAAO,EAAG,MAAM,EAAY,EAAS,CAAO,CAAC,CAAU,CAAC,CACxG,MAAM,CAAC,EAAS,GAAY,CAAC,EAAU,KACtC,IAAY,EAAW,EAAU,cAAc,CAAU,EAAI,EAAQ,cAAc,CAAQ,CAGhF,CAAA,CAAQ,KAAK,CAAC,EAAK,KAAgB,GAAG,EAAI,IAAI,GAAY,CAAC,CAAC,KAAK,GAAG,EAAE,GAGvF,GAAI,MAAM,QAAQ,CAAK,EAAG,MAAO,IAAI,EAAM,IAAK,GAAM,MAAM,EAAG,EAAS,CAAO,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,GAE5F,IAAM,EAAQ,OAAO,eAAe,CAAK,EAEzC,GAAI,IAAU,OAAO,WAAa,IAAU,KAAM,CAChD,GAAI,GAAS,kBAAoB,QAC/B,MAAM,IAAI,EACR,0BAA2B,EAA8C,aAAa,MAAQ,WAChG,EAGF,OAAO,OAAO,CAAK,CACrB,CAEA,IAAM,EAAM,EAKZ,MAAO,IAJM,OAAO,KAAK,CAAG,CAAC,CAC1B,OAAQ,GAAM,EAAI,KAAO,IAAA,EAAS,CAAC,CACnC,KAEQ,CAAA,CAAK,IAAK,GAAM,GAAG,KAAK,UAAU,CAAC,EAAE,GAAG,MAAM,EAAI,GAAI,EAAS,CAAO,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,EAClG,CAEA,SAAgB,KAAK,EAAgB,EAA+B,CAClE,OAAO,MAAM,EAAO,EAAS,IAAI,GAAa,CAChD"}
|