@vielzeug/arsenal 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -0
- package/dist/_common/_abortable.d.ts +5 -0
- package/dist/_common/_abortable.d.ts.map +1 -0
- package/dist/_common/_lruMap.cjs +2 -0
- package/dist/_common/_lruMap.cjs.map +1 -0
- package/dist/_common/_lruMap.d.ts +20 -0
- package/dist/_common/_lruMap.d.ts.map +1 -0
- package/dist/_common/_lruMap.js +18 -0
- package/dist/_common/_lruMap.js.map +1 -0
- package/dist/_common/_secureRandomIndex.cjs +2 -0
- package/dist/_common/_secureRandomIndex.cjs.map +1 -0
- package/dist/_common/_secureRandomIndex.d.ts +2 -0
- package/dist/_common/_secureRandomIndex.d.ts.map +1 -0
- package/dist/_common/_secureRandomIndex.js +9 -0
- package/dist/_common/_secureRandomIndex.js.map +1 -0
- package/dist/_common/_selectorSet.cjs +2 -0
- package/dist/_common/_selectorSet.cjs.map +1 -0
- package/dist/_common/_selectorSet.d.ts +2 -0
- package/dist/_common/_selectorSet.d.ts.map +1 -0
- package/dist/_common/_selectorSet.js +16 -0
- package/dist/_common/_selectorSet.js.map +1 -0
- package/dist/_common/unsafePaths.cjs +2 -0
- package/dist/_common/unsafePaths.cjs.map +1 -0
- package/dist/_common/unsafePaths.d.ts +25 -0
- package/dist/_common/unsafePaths.d.ts.map +1 -0
- package/dist/_common/unsafePaths.js +13 -0
- package/dist/_common/unsafePaths.js.map +1 -0
- package/dist/_dev.cjs +2 -0
- package/dist/_dev.cjs.map +1 -0
- package/dist/_dev.d.ts +2 -0
- package/dist/_dev.d.ts.map +1 -0
- package/dist/_dev.js +9 -0
- package/dist/_dev.js.map +1 -0
- package/dist/array/chunk.cjs +2 -0
- package/dist/array/chunk.cjs.map +1 -0
- package/dist/array/chunk.d.ts +19 -0
- package/dist/array/chunk.d.ts.map +1 -0
- package/dist/array/chunk.js +12 -0
- package/dist/array/chunk.js.map +1 -0
- package/dist/array/compact.cjs +2 -0
- package/dist/array/compact.cjs.map +1 -0
- package/dist/array/compact.d.ts +7 -0
- package/dist/array/compact.d.ts.map +1 -0
- package/dist/array/compact.js +8 -0
- package/dist/array/compact.js.map +1 -0
- package/dist/array/compare.cjs +2 -0
- package/dist/array/compare.cjs.map +1 -0
- package/dist/array/compare.d.ts +31 -0
- package/dist/array/compare.d.ts.map +1 -0
- package/dist/array/compare.js +20 -0
- package/dist/array/compare.js.map +1 -0
- package/dist/array/compareBy.cjs +2 -0
- package/dist/array/compareBy.cjs.map +1 -0
- package/dist/array/compareBy.d.ts +24 -0
- package/dist/array/compareBy.d.ts.map +1 -0
- package/dist/array/compareBy.js +16 -0
- package/dist/array/compareBy.js.map +1 -0
- package/dist/array/contains.cjs +2 -0
- package/dist/array/contains.cjs.map +1 -0
- package/dist/array/contains.d.ts +17 -0
- package/dist/array/contains.d.ts.map +1 -0
- package/dist/array/contains.js +9 -0
- package/dist/array/contains.js.map +1 -0
- package/dist/array/countBy.cjs +2 -0
- package/dist/array/countBy.cjs.map +1 -0
- package/dist/array/countBy.d.ts +8 -0
- package/dist/array/countBy.d.ts.map +1 -0
- package/dist/array/countBy.js +14 -0
- package/dist/array/countBy.js.map +1 -0
- package/dist/array/difference.cjs +2 -0
- package/dist/array/difference.cjs.map +1 -0
- package/dist/array/difference.d.ts +6 -0
- package/dist/array/difference.d.ts.map +1 -0
- package/dist/array/difference.js +14 -0
- package/dist/array/difference.js.map +1 -0
- package/dist/array/drop.cjs +2 -0
- package/dist/array/drop.cjs.map +1 -0
- package/dist/array/drop.d.ts +5 -0
- package/dist/array/drop.d.ts.map +1 -0
- package/dist/array/drop.js +9 -0
- package/dist/array/drop.js.map +1 -0
- package/dist/array/dropLast.cjs +2 -0
- package/dist/array/dropLast.cjs.map +1 -0
- package/dist/array/dropLast.d.ts +5 -0
- package/dist/array/dropLast.d.ts.map +1 -0
- package/dist/array/dropLast.js +9 -0
- package/dist/array/dropLast.js.map +1 -0
- package/dist/array/filterMap.cjs +2 -0
- package/dist/array/filterMap.cjs.map +1 -0
- package/dist/array/filterMap.d.ts +5 -0
- package/dist/array/filterMap.d.ts.map +1 -0
- package/dist/array/filterMap.js +13 -0
- package/dist/array/filterMap.js.map +1 -0
- package/dist/array/first.cjs +2 -0
- package/dist/array/first.cjs.map +1 -0
- package/dist/array/first.d.ts +5 -0
- package/dist/array/first.d.ts.map +1 -0
- package/dist/array/first.js +8 -0
- package/dist/array/first.js.map +1 -0
- package/dist/array/flatten.cjs +2 -0
- package/dist/array/flatten.cjs.map +1 -0
- package/dist/array/flatten.d.ts +5 -0
- package/dist/array/flatten.d.ts.map +1 -0
- package/dist/array/flatten.js +11 -0
- package/dist/array/flatten.js.map +1 -0
- package/dist/array/groupBy.cjs +2 -0
- package/dist/array/groupBy.cjs.map +1 -0
- package/dist/array/groupBy.d.ts +7 -0
- package/dist/array/groupBy.d.ts.map +1 -0
- package/dist/array/groupBy.js +14 -0
- package/dist/array/groupBy.js.map +1 -0
- package/dist/array/index.d.ts +29 -0
- package/dist/array/index.d.ts.map +1 -0
- package/dist/array/indexBy.cjs +2 -0
- package/dist/array/indexBy.cjs.map +1 -0
- package/dist/array/indexBy.d.ts +7 -0
- package/dist/array/indexBy.d.ts.map +1 -0
- package/dist/array/indexBy.js +14 -0
- package/dist/array/indexBy.js.map +1 -0
- package/dist/array/intersection.cjs +2 -0
- package/dist/array/intersection.cjs.map +1 -0
- package/dist/array/intersection.d.ts +6 -0
- package/dist/array/intersection.d.ts.map +1 -0
- package/dist/array/intersection.js +14 -0
- package/dist/array/intersection.js.map +1 -0
- package/dist/array/last.cjs +2 -0
- package/dist/array/last.cjs.map +1 -0
- package/dist/array/last.d.ts +5 -0
- package/dist/array/last.d.ts.map +1 -0
- package/dist/array/last.js +8 -0
- package/dist/array/last.js.map +1 -0
- package/dist/array/partition.cjs +2 -0
- package/dist/array/partition.cjs.map +1 -0
- package/dist/array/partition.d.ts +5 -0
- package/dist/array/partition.d.ts.map +1 -0
- package/dist/array/partition.js +10 -0
- package/dist/array/partition.js.map +1 -0
- package/dist/array/replace.cjs +2 -0
- package/dist/array/replace.cjs.map +1 -0
- package/dist/array/replace.d.ts +18 -0
- package/dist/array/replace.d.ts.map +1 -0
- package/dist/array/replace.js +13 -0
- package/dist/array/replace.js.map +1 -0
- package/dist/array/rotate.cjs +2 -0
- package/dist/array/rotate.cjs.map +1 -0
- package/dist/array/rotate.d.ts +20 -0
- package/dist/array/rotate.d.ts.map +1 -0
- package/dist/array/rotate.js +10 -0
- package/dist/array/rotate.js.map +1 -0
- package/dist/array/search.cjs +2 -0
- package/dist/array/search.cjs.map +1 -0
- package/dist/array/search.d.ts +85 -0
- package/dist/array/search.d.ts.map +1 -0
- package/dist/array/search.js +47 -0
- package/dist/array/search.js.map +1 -0
- package/dist/array/sort.cjs +2 -0
- package/dist/array/sort.cjs.map +1 -0
- package/dist/array/sort.d.ts +26 -0
- package/dist/array/sort.d.ts.map +1 -0
- package/dist/array/sort.js +16 -0
- package/dist/array/sort.js.map +1 -0
- package/dist/array/take.cjs +2 -0
- package/dist/array/take.cjs.map +1 -0
- package/dist/array/take.d.ts +5 -0
- package/dist/array/take.d.ts.map +1 -0
- package/dist/array/take.js +9 -0
- package/dist/array/take.js.map +1 -0
- package/dist/array/takeLast.cjs +2 -0
- package/dist/array/takeLast.cjs.map +1 -0
- package/dist/array/takeLast.d.ts +5 -0
- package/dist/array/takeLast.d.ts.map +1 -0
- package/dist/array/takeLast.js +9 -0
- package/dist/array/takeLast.js.map +1 -0
- package/dist/array/toggle.cjs +2 -0
- package/dist/array/toggle.cjs.map +1 -0
- package/dist/array/toggle.d.ts +29 -0
- package/dist/array/toggle.d.ts.map +1 -0
- package/dist/array/toggle.js +9 -0
- package/dist/array/toggle.js.map +1 -0
- package/dist/array/union.cjs +2 -0
- package/dist/array/union.cjs.map +1 -0
- package/dist/array/union.d.ts +6 -0
- package/dist/array/union.d.ts.map +1 -0
- package/dist/array/union.js +9 -0
- package/dist/array/union.js.map +1 -0
- package/dist/array/uniq.cjs +2 -0
- package/dist/array/uniq.cjs.map +1 -0
- package/dist/array/uniq.d.ts +18 -0
- package/dist/array/uniq.d.ts.map +1 -0
- package/dist/array/uniq.js +9 -0
- package/dist/array/uniq.js.map +1 -0
- package/dist/array/unzip.cjs +2 -0
- package/dist/array/unzip.cjs.map +1 -0
- package/dist/array/unzip.d.ts +7 -0
- package/dist/array/unzip.d.ts.map +1 -0
- package/dist/array/unzip.js +11 -0
- package/dist/array/unzip.js.map +1 -0
- package/dist/array/zip.cjs +2 -0
- package/dist/array/zip.cjs.map +1 -0
- package/dist/array/zip.d.ts +7 -0
- package/dist/array/zip.d.ts.map +1 -0
- package/dist/array/zip.js +11 -0
- package/dist/array/zip.js.map +1 -0
- package/dist/arsenal.cjs +2 -0
- package/dist/arsenal.cjs.map +1 -0
- package/dist/arsenal.iife.js +2 -0
- package/dist/arsenal.iife.js.map +1 -0
- package/dist/arsenal.js +2 -0
- package/dist/arsenal.js.map +1 -0
- package/dist/async/abortError.cjs +2 -0
- package/dist/async/abortError.cjs.map +1 -0
- package/dist/async/abortError.d.ts +23 -0
- package/dist/async/abortError.d.ts.map +1 -0
- package/dist/async/abortError.js +8 -0
- package/dist/async/abortError.js.map +1 -0
- package/dist/async/attempt.cjs +2 -0
- package/dist/async/attempt.cjs.map +1 -0
- package/dist/async/attempt.d.ts +58 -0
- package/dist/async/attempt.d.ts.map +1 -0
- package/dist/async/attempt.js +31 -0
- package/dist/async/attempt.js.map +1 -0
- package/dist/async/backoff.cjs +2 -0
- package/dist/async/backoff.cjs.map +1 -0
- package/dist/async/backoff.d.ts +20 -0
- package/dist/async/backoff.d.ts.map +1 -0
- package/dist/async/backoff.js +9 -0
- package/dist/async/backoff.js.map +1 -0
- package/dist/async/index.d.ts +9 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/async/parallel.cjs +2 -0
- package/dist/async/parallel.cjs.map +1 -0
- package/dist/async/parallel.d.ts +42 -0
- package/dist/async/parallel.d.ts.map +1 -0
- package/dist/async/parallel.js +26 -0
- package/dist/async/parallel.js.map +1 -0
- package/dist/async/queue.cjs +2 -0
- package/dist/async/queue.cjs.map +1 -0
- package/dist/async/queue.d.ts +42 -0
- package/dist/async/queue.d.ts.map +1 -0
- package/dist/async/queue.js +72 -0
- package/dist/async/queue.js.map +1 -0
- package/dist/async/retry.cjs +2 -0
- package/dist/async/retry.cjs.map +1 -0
- package/dist/async/retry.d.ts +46 -0
- package/dist/async/retry.d.ts.map +1 -0
- package/dist/async/retry.js +26 -0
- package/dist/async/retry.js.map +1 -0
- package/dist/async/sleep.cjs +2 -0
- package/dist/async/sleep.cjs.map +1 -0
- package/dist/async/sleep.d.ts +21 -0
- package/dist/async/sleep.d.ts.map +1 -0
- package/dist/async/sleep.js +16 -0
- package/dist/async/sleep.js.map +1 -0
- package/dist/async/waitFor.cjs +2 -0
- package/dist/async/waitFor.cjs.map +1 -0
- package/dist/async/waitFor.d.ts +34 -0
- package/dist/async/waitFor.d.ts.map +1 -0
- package/dist/async/waitFor.js +13 -0
- package/dist/async/waitFor.js.map +1 -0
- package/dist/cache/index.d.ts +3 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/memo.cjs +2 -0
- package/dist/cache/memo.cjs.map +1 -0
- package/dist/cache/memo.d.ts +40 -0
- package/dist/cache/memo.d.ts.map +1 -0
- package/dist/cache/memo.js +37 -0
- package/dist/cache/memo.js.map +1 -0
- package/dist/cache/stash.cjs +2 -0
- package/dist/cache/stash.cjs.map +1 -0
- package/dist/cache/stash.d.ts +111 -0
- package/dist/cache/stash.d.ts.map +1 -0
- package/dist/cache/stash.js +92 -0
- package/dist/cache/stash.js.map +1 -0
- package/dist/errors.cjs +2 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +20 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/function/assert.cjs +2 -0
- package/dist/function/assert.cjs.map +1 -0
- package/dist/function/assert.d.ts +19 -0
- package/dist/function/assert.d.ts.map +1 -0
- package/dist/function/assert.js +8 -0
- package/dist/function/assert.js.map +1 -0
- package/dist/function/constant.cjs +2 -0
- package/dist/function/constant.cjs.map +1 -0
- package/dist/function/constant.d.ts +5 -0
- package/dist/function/constant.d.ts.map +1 -0
- package/dist/function/constant.js +8 -0
- package/dist/function/constant.js.map +1 -0
- package/dist/function/debounce.cjs +2 -0
- package/dist/function/debounce.cjs.map +1 -0
- package/dist/function/debounce.d.ts +31 -0
- package/dist/function/debounce.d.ts.map +1 -0
- package/dist/function/debounce.js +29 -0
- package/dist/function/debounce.js.map +1 -0
- package/dist/function/identity.cjs +2 -0
- package/dist/function/identity.cjs.map +1 -0
- package/dist/function/identity.d.ts +5 -0
- package/dist/function/identity.d.ts.map +1 -0
- package/dist/function/identity.js +8 -0
- package/dist/function/identity.js.map +1 -0
- package/dist/function/index.d.ts +10 -0
- package/dist/function/index.d.ts.map +1 -0
- package/dist/function/once.cjs +2 -0
- package/dist/function/once.cjs.map +1 -0
- package/dist/function/once.d.ts +32 -0
- package/dist/function/once.d.ts.map +1 -0
- package/dist/function/once.js +11 -0
- package/dist/function/once.js.map +1 -0
- package/dist/function/pipe.cjs +2 -0
- package/dist/function/pipe.cjs.map +1 -0
- package/dist/function/pipe.d.ts +32 -0
- package/dist/function/pipe.d.ts.map +1 -0
- package/dist/function/pipe.js +10 -0
- package/dist/function/pipe.js.map +1 -0
- package/dist/function/runAll.cjs +2 -0
- package/dist/function/runAll.cjs.map +1 -0
- package/dist/function/runAll.d.ts +15 -0
- package/dist/function/runAll.d.ts.map +1 -0
- package/dist/function/runAll.js +19 -0
- package/dist/function/runAll.js.map +1 -0
- package/dist/function/tap.cjs +2 -0
- package/dist/function/tap.cjs.map +1 -0
- package/dist/function/tap.d.ts +5 -0
- package/dist/function/tap.d.ts.map +1 -0
- package/dist/function/tap.js +8 -0
- package/dist/function/tap.js.map +1 -0
- package/dist/function/throttle.cjs +2 -0
- package/dist/function/throttle.cjs.map +1 -0
- package/dist/function/throttle.d.ts +23 -0
- package/dist/function/throttle.d.ts.map +1 -0
- package/dist/function/throttle.js +36 -0
- package/dist/function/throttle.js.map +1 -0
- package/dist/guards/combinators.cjs +2 -0
- package/dist/guards/combinators.cjs.map +1 -0
- package/dist/guards/combinators.d.ts +49 -0
- package/dist/guards/combinators.d.ts.map +1 -0
- package/dist/guards/combinators.js +17 -0
- package/dist/guards/combinators.js.map +1 -0
- package/dist/guards/index.d.ts +20 -0
- package/dist/guards/index.d.ts.map +1 -0
- package/dist/guards/isAbortError.cjs +2 -0
- package/dist/guards/isAbortError.cjs.map +1 -0
- package/dist/guards/isAbortError.d.ts +19 -0
- package/dist/guards/isAbortError.d.ts.map +1 -0
- package/dist/guards/isAbortError.js +8 -0
- package/dist/guards/isAbortError.js.map +1 -0
- package/dist/guards/isArray.cjs +2 -0
- package/dist/guards/isArray.cjs.map +1 -0
- package/dist/guards/isArray.d.ts +16 -0
- package/dist/guards/isArray.d.ts.map +1 -0
- package/dist/guards/isArray.js +8 -0
- package/dist/guards/isArray.js.map +1 -0
- package/dist/guards/isBoolean.cjs +2 -0
- package/dist/guards/isBoolean.cjs.map +1 -0
- package/dist/guards/isBoolean.d.ts +23 -0
- package/dist/guards/isBoolean.d.ts.map +1 -0
- package/dist/guards/isBoolean.js +8 -0
- package/dist/guards/isBoolean.js.map +1 -0
- package/dist/guards/isDate.cjs +2 -0
- package/dist/guards/isDate.cjs.map +1 -0
- package/dist/guards/isDate.d.ts +15 -0
- package/dist/guards/isDate.d.ts.map +1 -0
- package/dist/guards/isDate.js +8 -0
- package/dist/guards/isDate.js.map +1 -0
- package/dist/guards/isDefined.cjs +2 -0
- package/dist/guards/isDefined.cjs.map +1 -0
- package/dist/guards/isDefined.d.ts +19 -0
- package/dist/guards/isDefined.d.ts.map +1 -0
- package/dist/guards/isDefined.js +8 -0
- package/dist/guards/isDefined.js.map +1 -0
- package/dist/guards/isEmpty.cjs +2 -0
- package/dist/guards/isEmpty.cjs.map +1 -0
- package/dist/guards/isEmpty.d.ts +23 -0
- package/dist/guards/isEmpty.d.ts.map +1 -0
- package/dist/guards/isEmpty.js +10 -0
- package/dist/guards/isEmpty.js.map +1 -0
- package/dist/guards/isEqual.cjs +2 -0
- package/dist/guards/isEqual.cjs.map +1 -0
- package/dist/guards/isEqual.d.ts +24 -0
- package/dist/guards/isEqual.d.ts.map +1 -0
- package/dist/guards/isEqual.js +34 -0
- package/dist/guards/isEqual.js.map +1 -0
- package/dist/guards/isError.cjs +2 -0
- package/dist/guards/isError.cjs.map +1 -0
- package/dist/guards/isError.d.ts +15 -0
- package/dist/guards/isError.d.ts.map +1 -0
- package/dist/guards/isError.js +8 -0
- package/dist/guards/isError.js.map +1 -0
- package/dist/guards/isFunction.cjs +2 -0
- package/dist/guards/isFunction.cjs.map +1 -0
- package/dist/guards/isFunction.d.ts +16 -0
- package/dist/guards/isFunction.d.ts.map +1 -0
- package/dist/guards/isFunction.js +8 -0
- package/dist/guards/isFunction.js.map +1 -0
- package/dist/guards/isMatch.cjs +2 -0
- package/dist/guards/isMatch.cjs.map +1 -0
- package/dist/guards/isMatch.d.ts +23 -0
- package/dist/guards/isMatch.d.ts.map +1 -0
- package/dist/guards/isMatch.js +23 -0
- package/dist/guards/isMatch.js.map +1 -0
- package/dist/guards/isNil.cjs +2 -0
- package/dist/guards/isNil.cjs.map +1 -0
- package/dist/guards/isNil.d.ts +17 -0
- package/dist/guards/isNil.d.ts.map +1 -0
- package/dist/guards/isNil.js +8 -0
- package/dist/guards/isNil.js.map +1 -0
- package/dist/guards/isNumber.cjs +2 -0
- package/dist/guards/isNumber.cjs.map +1 -0
- package/dist/guards/isNumber.d.ts +15 -0
- package/dist/guards/isNumber.d.ts.map +1 -0
- package/dist/guards/isNumber.js +8 -0
- package/dist/guards/isNumber.js.map +1 -0
- package/dist/guards/isPlainObject.cjs +2 -0
- package/dist/guards/isPlainObject.cjs.map +1 -0
- package/dist/guards/isPlainObject.d.ts +16 -0
- package/dist/guards/isPlainObject.d.ts.map +1 -0
- package/dist/guards/isPlainObject.js +10 -0
- package/dist/guards/isPlainObject.js.map +1 -0
- package/dist/guards/isPrimitive.cjs +2 -0
- package/dist/guards/isPrimitive.cjs.map +1 -0
- package/dist/guards/isPrimitive.d.ts +18 -0
- package/dist/guards/isPrimitive.d.ts.map +1 -0
- package/dist/guards/isPrimitive.js +9 -0
- package/dist/guards/isPrimitive.js.map +1 -0
- package/dist/guards/isPromise.cjs +2 -0
- package/dist/guards/isPromise.cjs.map +1 -0
- package/dist/guards/isPromise.d.ts +17 -0
- package/dist/guards/isPromise.d.ts.map +1 -0
- package/dist/guards/isPromise.js +8 -0
- package/dist/guards/isPromise.js.map +1 -0
- package/dist/guards/isRegex.cjs +2 -0
- package/dist/guards/isRegex.cjs.map +1 -0
- package/dist/guards/isRegex.d.ts +21 -0
- package/dist/guards/isRegex.d.ts.map +1 -0
- package/dist/guards/isRegex.js +8 -0
- package/dist/guards/isRegex.js.map +1 -0
- package/dist/guards/isString.cjs +2 -0
- package/dist/guards/isString.cjs.map +1 -0
- package/dist/guards/isString.d.ts +15 -0
- package/dist/guards/isString.d.ts.map +1 -0
- package/dist/guards/isString.js +8 -0
- package/dist/guards/isString.js.map +1 -0
- package/dist/guards/shallowEqual.cjs +2 -0
- package/dist/guards/shallowEqual.cjs.map +1 -0
- package/dist/guards/shallowEqual.d.ts +29 -0
- package/dist/guards/shallowEqual.d.ts.map +1 -0
- package/dist/guards/shallowEqual.js +20 -0
- package/dist/guards/shallowEqual.js.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +119 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +118 -0
- package/dist/math/abs.cjs +2 -0
- package/dist/math/abs.cjs.map +1 -0
- package/dist/math/abs.d.ts +17 -0
- package/dist/math/abs.d.ts.map +1 -0
- package/dist/math/abs.js +8 -0
- package/dist/math/abs.js.map +1 -0
- package/dist/math/allocate.cjs +2 -0
- package/dist/math/allocate.cjs.map +1 -0
- package/dist/math/allocate.d.ts +29 -0
- package/dist/math/allocate.d.ts.map +1 -0
- package/dist/math/allocate.js +20 -0
- package/dist/math/allocate.js.map +1 -0
- package/dist/math/average.cjs +2 -0
- package/dist/math/average.cjs.map +1 -0
- package/dist/math/average.d.ts +16 -0
- package/dist/math/average.d.ts.map +1 -0
- package/dist/math/average.js +14 -0
- package/dist/math/average.js.map +1 -0
- package/dist/math/clamp.cjs +2 -0
- package/dist/math/clamp.cjs.map +1 -0
- package/dist/math/clamp.d.ts +21 -0
- package/dist/math/clamp.d.ts.map +1 -0
- package/dist/math/clamp.js +8 -0
- package/dist/math/clamp.js.map +1 -0
- package/dist/math/gcd.cjs +2 -0
- package/dist/math/gcd.cjs.map +1 -0
- package/dist/math/gcd.d.ts +18 -0
- package/dist/math/gcd.d.ts.map +1 -0
- package/dist/math/gcd.js +13 -0
- package/dist/math/gcd.js.map +1 -0
- package/dist/math/index.d.ts +20 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/lcm.cjs +2 -0
- package/dist/math/lcm.cjs.map +1 -0
- package/dist/math/lcm.d.ts +15 -0
- package/dist/math/lcm.d.ts.map +1 -0
- package/dist/math/lcm.js +9 -0
- package/dist/math/lcm.js.map +1 -0
- package/dist/math/lerp.cjs +2 -0
- package/dist/math/lerp.cjs.map +1 -0
- package/dist/math/lerp.d.ts +17 -0
- package/dist/math/lerp.d.ts.map +1 -0
- package/dist/math/lerp.js +8 -0
- package/dist/math/lerp.js.map +1 -0
- package/dist/math/linspace.cjs +2 -0
- package/dist/math/linspace.cjs.map +1 -0
- package/dist/math/linspace.d.ts +19 -0
- package/dist/math/linspace.d.ts.map +1 -0
- package/dist/math/linspace.js +11 -0
- package/dist/math/linspace.js.map +1 -0
- package/dist/math/max.cjs +2 -0
- package/dist/math/max.cjs.map +1 -0
- package/dist/math/max.d.ts +21 -0
- package/dist/math/max.d.ts.map +1 -0
- package/dist/math/max.js +12 -0
- package/dist/math/max.js.map +1 -0
- package/dist/math/median.cjs +2 -0
- package/dist/math/median.cjs.map +1 -0
- package/dist/math/median.d.ts +17 -0
- package/dist/math/median.d.ts.map +1 -0
- package/dist/math/median.js +12 -0
- package/dist/math/median.js.map +1 -0
- package/dist/math/min.cjs +2 -0
- package/dist/math/min.cjs.map +1 -0
- package/dist/math/min.d.ts +21 -0
- package/dist/math/min.d.ts.map +1 -0
- package/dist/math/min.js +12 -0
- package/dist/math/min.js.map +1 -0
- package/dist/math/mod.cjs +2 -0
- package/dist/math/mod.cjs.map +1 -0
- package/dist/math/mod.d.ts +18 -0
- package/dist/math/mod.d.ts.map +1 -0
- package/dist/math/mod.js +10 -0
- package/dist/math/mod.js.map +1 -0
- package/dist/math/normalize.cjs +2 -0
- package/dist/math/normalize.cjs.map +1 -0
- package/dist/math/normalize.d.ts +18 -0
- package/dist/math/normalize.d.ts.map +1 -0
- package/dist/math/normalize.js +9 -0
- package/dist/math/normalize.js.map +1 -0
- package/dist/math/percent.cjs +2 -0
- package/dist/math/percent.cjs.map +1 -0
- package/dist/math/percent.d.ts +19 -0
- package/dist/math/percent.d.ts.map +1 -0
- package/dist/math/percent.js +8 -0
- package/dist/math/percent.js.map +1 -0
- package/dist/math/range.cjs +2 -0
- package/dist/math/range.cjs.map +1 -0
- package/dist/math/range.d.ts +37 -0
- package/dist/math/range.d.ts.map +1 -0
- package/dist/math/range.js +27 -0
- package/dist/math/range.js.map +1 -0
- package/dist/math/round.cjs +2 -0
- package/dist/math/round.cjs.map +1 -0
- package/dist/math/round.d.ts +21 -0
- package/dist/math/round.d.ts.map +1 -0
- package/dist/math/round.js +10 -0
- package/dist/math/round.js.map +1 -0
- package/dist/math/standardDeviation.cjs +2 -0
- package/dist/math/standardDeviation.cjs.map +1 -0
- package/dist/math/standardDeviation.d.ts +16 -0
- package/dist/math/standardDeviation.d.ts.map +1 -0
- package/dist/math/standardDeviation.js +9 -0
- package/dist/math/standardDeviation.js.map +1 -0
- package/dist/math/sum.cjs +2 -0
- package/dist/math/sum.cjs.map +1 -0
- package/dist/math/sum.d.ts +19 -0
- package/dist/math/sum.d.ts.map +1 -0
- package/dist/math/sum.js +13 -0
- package/dist/math/sum.js.map +1 -0
- package/dist/math/variance.cjs +2 -0
- package/dist/math/variance.cjs.map +1 -0
- package/dist/math/variance.d.ts +17 -0
- package/dist/math/variance.d.ts.map +1 -0
- package/dist/math/variance.js +11 -0
- package/dist/math/variance.js.map +1 -0
- package/dist/object/defaults.cjs +2 -0
- package/dist/object/defaults.cjs.map +1 -0
- package/dist/object/defaults.d.ts +17 -0
- package/dist/object/defaults.d.ts.map +1 -0
- package/dist/object/defaults.js +12 -0
- package/dist/object/defaults.js.map +1 -0
- package/dist/object/diff.cjs +2 -0
- package/dist/object/diff.cjs.map +1 -0
- package/dist/object/diff.d.ts +63 -0
- package/dist/object/diff.d.ts.map +1 -0
- package/dist/object/diff.js +27 -0
- package/dist/object/diff.js.map +1 -0
- package/dist/object/filterValues.cjs +2 -0
- package/dist/object/filterValues.cjs.map +1 -0
- package/dist/object/filterValues.d.ts +16 -0
- package/dist/object/filterValues.d.ts.map +1 -0
- package/dist/object/filterValues.js +11 -0
- package/dist/object/filterValues.js.map +1 -0
- package/dist/object/flattenPaths.cjs +2 -0
- package/dist/object/flattenPaths.cjs.map +1 -0
- package/dist/object/flattenPaths.d.ts +13 -0
- package/dist/object/flattenPaths.d.ts.map +1 -0
- package/dist/object/flattenPaths.js +31 -0
- package/dist/object/flattenPaths.js.map +1 -0
- package/dist/object/getPath.cjs +2 -0
- package/dist/object/getPath.cjs.map +1 -0
- package/dist/object/getPath.d.ts +48 -0
- package/dist/object/getPath.d.ts.map +1 -0
- package/dist/object/getPath.js +27 -0
- package/dist/object/getPath.js.map +1 -0
- package/dist/object/hash.cjs +2 -0
- package/dist/object/hash.cjs.map +1 -0
- package/dist/object/hash.d.ts +12 -0
- package/dist/object/hash.d.ts.map +1 -0
- package/dist/object/hash.js +28 -0
- package/dist/object/hash.js.map +1 -0
- package/dist/object/index.d.ts +15 -0
- package/dist/object/index.d.ts.map +1 -0
- package/dist/object/invert.cjs +2 -0
- package/dist/object/invert.cjs.map +1 -0
- package/dist/object/invert.d.ts +15 -0
- package/dist/object/invert.d.ts.map +1 -0
- package/dist/object/invert.js +11 -0
- package/dist/object/invert.js.map +1 -0
- package/dist/object/mapKeys.cjs +2 -0
- package/dist/object/mapKeys.cjs.map +1 -0
- package/dist/object/mapKeys.d.ts +16 -0
- package/dist/object/mapKeys.d.ts.map +1 -0
- package/dist/object/mapKeys.js +15 -0
- package/dist/object/mapKeys.js.map +1 -0
- package/dist/object/mapValues.cjs +2 -0
- package/dist/object/mapValues.cjs.map +1 -0
- package/dist/object/mapValues.d.ts +18 -0
- package/dist/object/mapValues.d.ts.map +1 -0
- package/dist/object/mapValues.js +11 -0
- package/dist/object/mapValues.js.map +1 -0
- package/dist/object/merge.cjs +2 -0
- package/dist/object/merge.cjs.map +1 -0
- package/dist/object/merge.d.ts +41 -0
- package/dist/object/merge.d.ts.map +1 -0
- package/dist/object/merge.js +27 -0
- package/dist/object/merge.js.map +1 -0
- package/dist/object/omit.cjs +2 -0
- package/dist/object/omit.cjs.map +1 -0
- package/dist/object/omit.d.ts +16 -0
- package/dist/object/omit.d.ts.map +1 -0
- package/dist/object/omit.js +11 -0
- package/dist/object/omit.js.map +1 -0
- package/dist/object/parseJSON.cjs +2 -0
- package/dist/object/parseJSON.cjs.map +1 -0
- package/dist/object/parseJSON.d.ts +32 -0
- package/dist/object/parseJSON.d.ts.map +1 -0
- package/dist/object/parseJSON.js +16 -0
- package/dist/object/parseJSON.js.map +1 -0
- package/dist/object/pick.cjs +2 -0
- package/dist/object/pick.cjs.map +1 -0
- package/dist/object/pick.d.ts +17 -0
- package/dist/object/pick.d.ts.map +1 -0
- package/dist/object/pick.js +11 -0
- package/dist/object/pick.js.map +1 -0
- package/dist/object/prune.cjs +2 -0
- package/dist/object/prune.cjs.map +1 -0
- package/dist/object/prune.d.ts +26 -0
- package/dist/object/prune.d.ts.map +1 -0
- package/dist/object/prune.js +36 -0
- package/dist/object/prune.js.map +1 -0
- package/dist/random/draw.cjs +2 -0
- package/dist/random/draw.cjs.map +1 -0
- package/dist/random/draw.d.ts +24 -0
- package/dist/random/draw.d.ts.map +1 -0
- package/dist/random/draw.js +21 -0
- package/dist/random/draw.js.map +1 -0
- package/dist/random/index.d.ts +5 -0
- package/dist/random/index.d.ts.map +1 -0
- package/dist/random/random.cjs +2 -0
- package/dist/random/random.cjs.map +1 -0
- package/dist/random/random.d.ts +14 -0
- package/dist/random/random.d.ts.map +1 -0
- package/dist/random/random.js +11 -0
- package/dist/random/random.js.map +1 -0
- package/dist/random/shuffle.cjs +2 -0
- package/dist/random/shuffle.cjs.map +1 -0
- package/dist/random/shuffle.d.ts +12 -0
- package/dist/random/shuffle.d.ts.map +1 -0
- package/dist/random/shuffle.js +14 -0
- package/dist/random/shuffle.js.map +1 -0
- package/dist/random/uuid.cjs +2 -0
- package/dist/random/uuid.cjs.map +1 -0
- package/dist/random/uuid.d.ts +12 -0
- package/dist/random/uuid.d.ts.map +1 -0
- package/dist/random/uuid.js +8 -0
- package/dist/random/uuid.js.map +1 -0
- package/dist/string/_caseUtils.cjs +2 -0
- package/dist/string/_caseUtils.cjs.map +1 -0
- package/dist/string/_caseUtils.d.ts +9 -0
- package/dist/string/_caseUtils.d.ts.map +1 -0
- package/dist/string/_caseUtils.js +13 -0
- package/dist/string/_caseUtils.js.map +1 -0
- package/dist/string/camelCase.cjs +2 -0
- package/dist/string/camelCase.cjs.map +1 -0
- package/dist/string/camelCase.d.ts +14 -0
- package/dist/string/camelCase.d.ts.map +1 -0
- package/dist/string/camelCase.js +9 -0
- package/dist/string/camelCase.js.map +1 -0
- package/dist/string/endsWith.cjs +2 -0
- package/dist/string/endsWith.cjs.map +1 -0
- package/dist/string/endsWith.d.ts +5 -0
- package/dist/string/endsWith.d.ts.map +1 -0
- package/dist/string/endsWith.js +8 -0
- package/dist/string/endsWith.js.map +1 -0
- package/dist/string/escape.cjs +2 -0
- package/dist/string/escape.cjs.map +1 -0
- package/dist/string/escape.d.ts +5 -0
- package/dist/string/escape.d.ts.map +1 -0
- package/dist/string/escape.js +15 -0
- package/dist/string/escape.js.map +1 -0
- package/dist/string/index.d.ts +14 -0
- package/dist/string/index.d.ts.map +1 -0
- package/dist/string/kebabCase.cjs +2 -0
- package/dist/string/kebabCase.cjs.map +1 -0
- package/dist/string/kebabCase.d.ts +15 -0
- package/dist/string/kebabCase.d.ts.map +1 -0
- package/dist/string/kebabCase.js +9 -0
- package/dist/string/kebabCase.js.map +1 -0
- package/dist/string/pad.cjs +2 -0
- package/dist/string/pad.cjs.map +1 -0
- package/dist/string/pad.d.ts +5 -0
- package/dist/string/pad.d.ts.map +1 -0
- package/dist/string/pad.js +10 -0
- package/dist/string/pad.js.map +1 -0
- package/dist/string/pascalCase.cjs +2 -0
- package/dist/string/pascalCase.cjs.map +1 -0
- package/dist/string/pascalCase.d.ts +15 -0
- package/dist/string/pascalCase.d.ts.map +1 -0
- package/dist/string/pascalCase.js +9 -0
- package/dist/string/pascalCase.js.map +1 -0
- package/dist/string/similarity.cjs +2 -0
- package/dist/string/similarity.cjs.map +1 -0
- package/dist/string/similarity.d.ts +2 -0
- package/dist/string/similarity.d.ts.map +1 -0
- package/dist/string/similarity.js +24 -0
- package/dist/string/similarity.js.map +1 -0
- package/dist/string/snakeCase.cjs +2 -0
- package/dist/string/snakeCase.cjs.map +1 -0
- package/dist/string/snakeCase.d.ts +15 -0
- package/dist/string/snakeCase.d.ts.map +1 -0
- package/dist/string/snakeCase.js +9 -0
- package/dist/string/snakeCase.js.map +1 -0
- package/dist/string/startsWith.cjs +2 -0
- package/dist/string/startsWith.cjs.map +1 -0
- package/dist/string/startsWith.d.ts +5 -0
- package/dist/string/startsWith.d.ts.map +1 -0
- package/dist/string/startsWith.js +8 -0
- package/dist/string/startsWith.js.map +1 -0
- package/dist/string/titleCase.cjs +2 -0
- package/dist/string/titleCase.cjs.map +1 -0
- package/dist/string/titleCase.d.ts +5 -0
- package/dist/string/titleCase.d.ts.map +1 -0
- package/dist/string/titleCase.js +9 -0
- package/dist/string/titleCase.js.map +1 -0
- package/dist/string/truncate.cjs +2 -0
- package/dist/string/truncate.cjs.map +1 -0
- package/dist/string/truncate.d.ts +27 -0
- package/dist/string/truncate.d.ts.map +1 -0
- package/dist/string/truncate.js +17 -0
- package/dist/string/truncate.js.map +1 -0
- package/dist/string/unescape.cjs +2 -0
- package/dist/string/unescape.cjs.map +1 -0
- package/dist/string/unescape.d.ts +5 -0
- package/dist/string/unescape.d.ts.map +1 -0
- package/dist/string/unescape.js +15 -0
- package/dist/string/unescape.js.map +1 -0
- package/dist/string/words.cjs +2 -0
- package/dist/string/words.cjs.map +1 -0
- package/dist/string/words.d.ts +5 -0
- package/dist/string/words.d.ts.map +1 -0
- package/dist/string/words.js +10 -0
- package/dist/string/words.js.map +1 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isEqual as e } from "../guards/isEqual.js";
|
|
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
|
+
|
|
27
|
+
//# sourceMappingURL=diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.js","names":[],"sources":["../../src/object/diff.ts"],"sourcesContent":["import type { Obj } from '../types';\n\nimport { isUnsafeKey } from '../_common/unsafePaths';\nimport { isEqual } from '../guards/isEqual';\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":";;;AAgCA,SAAgB,EACd,IAAY,CAAC,GACb,IAAW,CAAC,GACZ,IAAiD,GAClC;CACf,IAAM,IAAiC,CAAC,GAClC,IAAmC,CAAC,GACpC,IAA+D,CAAC,GAEhE,IAAa,IAAI,IAAI,OAAO,KAAK,CAAM,CAAC,GACxC,IAAY,IAAI,IAAI,OAAO,KAAK,CAAK,CAAC;CAE5C,KAAK,IAAM,KAAO,GAChB,AAAK,EAAW,IAAI,CAAG,IAEZ,CAAC,EAAY,CAAG,KAAK,CAAC,EAAU,EAAO,IAAM,EAAM,EAAI,MAChE,EAAQ,KAAO;EAAE,OAAO,EAAM;EAAM,QAAQ,EAAO;CAAK,KAFxD,EAAM,KAAK,CAAuB;CAMtC,KAAK,IAAM,KAAO,GAChB,AAAK,EAAU,IAAI,CAAG,KACpB,EAAQ,KAAK,CAAuB;CAIxC,OAAO;EAAE;EAAgB;EAAqC;CAAQ;AACxE;AAgCA,SAAgB,EAAc,GAAa,GAAY,GAA6C;CAClG,IAAM,IAAY,GAAS,eAAe,GAAM,MAAS,EAAQ,GAAG,CAAC;CAErE,OAAO;EACL,OAAO,EAAM,QAAQ,MAAS,CAAC,EAAO,MAAM,MAAM,EAAU,GAAG,CAAI,CAAC,CAAC;EACrE,SAAS,EAAO,QAAQ,MAAS,CAAC,EAAM,MAAM,MAAM,EAAU,GAAM,CAAC,CAAC,CAAC;CACzE;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterValues.cjs","names":[],"sources":["../../src/object/filterValues.ts"],"sourcesContent":["import type { Obj } from '../types';\n\nimport { isUnsafeKey } from '../_common/unsafePaths';\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":"8CAiBA,SAAgB,EACd,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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Obj } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Filters object entries using a value predicate. Dangerous keys (`__proto__`, `constructor`,
|
|
4
|
+
* `prototype`) are always skipped.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* filterValues({ a: 1, b: 2, c: 3 }, (value) => value > 1); // { b: 2, c: 3 }
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param obj - The source object.
|
|
12
|
+
* @param predicate - Returns `true` to keep an entry.
|
|
13
|
+
* @returns A new object containing only entries for which `predicate` returned `true`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function filterValues<T extends Obj>(obj: T, predicate: (value: T[keyof T], key: keyof T, obj: T) => boolean): Partial<T>;
|
|
16
|
+
//# sourceMappingURL=filterValues.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterValues.d.ts","sourceRoot":"","sources":["../../src/object/filterValues.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAIpC;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,GAAG,EACxC,GAAG,EAAE,CAAC,EACN,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,OAAO,GAC9D,OAAO,CAAC,CAAC,CAAC,CAYZ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isUnsafeKey as e } from "../_common/unsafePaths.js";
|
|
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
|
+
|
|
11
|
+
//# sourceMappingURL=filterValues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterValues.js","names":[],"sources":["../../src/object/filterValues.ts"],"sourcesContent":["import type { Obj } from '../types';\n\nimport { isUnsafeKey } from '../_common/unsafePaths';\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":";;AAiBA,SAAgB,EACd,GACA,GACY;CACZ,IAAM,IAAkB,CAAC;CAEzB,KAAK,IAAM,KAAO,OAAO,KAAK,CAAG,GAC3B,EAAY,CAAkB,KAE9B,EAAU,EAAI,IAAM,GAAK,CAAG,MAC9B,EAAI,KAAO,EAAI;CAInB,OAAO;AACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../_common/unsafePaths.cjs"),t=require("../guards/isPlainObject.cjs");var n=10;function r(i,a,o){let s={};for(let[c,l]of Object.entries(i)){if(e.UNSAFE_PATH_SEGMENTS.has(c))continue;let i=a?`${a}.${c}`:c;t.isPlainObject(l)&&o<n?Object.assign(s,r(l,i,o+1)):s[i]=l}return s}function i(e){return r(e,``,0)}function a(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=i,exports.unflattenPaths=a;
|
|
2
|
+
//# sourceMappingURL=flattenPaths.cjs.map
|
|
@@ -0,0 +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,EAAc,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,EAAc,EAAgC,EAAS,EAAQ,CAAC,CAAC,EAEvF,EAAO,GAAW,CAEtB,CAEA,OAAO,CACT,CAEA,SAAgB,EAAa,EAAuD,CAClF,OAAO,EAAc,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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function flattenPaths(obj: Record<string, unknown>): Record<string, unknown>;
|
|
2
|
+
/**
|
|
3
|
+
* Reconstructs a nested plain object from a map of dot-notation path keys to leaf values.
|
|
4
|
+
* Any path containing an unsafe segment is silently skipped.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* unflattenPaths({ 'a.b': 1, 'a.c': 2, 'd': 3 })
|
|
9
|
+
* // { a: { b: 1, c: 2 }, d: 3 }
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function unflattenPaths(flat: Record<string, unknown>): Record<string, unknown>;
|
|
13
|
+
//# sourceMappingURL=flattenPaths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flattenPaths.d.ts","sourceRoot":"","sources":["../../src/object/flattenPaths.ts"],"names":[],"mappings":"AAkCA,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAElF;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAsBrF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { UNSAFE_PATH_SEGMENTS as e } from "../_common/unsafePaths.js";
|
|
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
|
+
|
|
31
|
+
//# sourceMappingURL=flattenPaths.js.map
|
|
@@ -0,0 +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":";;;AAcA,IAAM,IAAoB;AAE1B,SAAS,EAAc,GAA8B,GAAgB,GAAwC;CAC3G,IAAM,IAAkC,CAAC;CAEzC,KAAK,IAAM,CAAC,GAAK,MAAQ,OAAO,QAAQ,CAAG,GAAG;EAC5C,IAAI,EAAqB,IAAI,CAAG,GAAG;EAEnC,IAAM,IAAU,IAAS,GAAG,EAAO,GAAG,MAAQ;EAE9C,AAAI,EAAc,CAAG,KAAK,IAAQ,IAChC,OAAO,OAAO,GAAQ,EAAc,GAAgC,GAAS,IAAQ,CAAC,CAAC,IAEvF,EAAO,KAAW;CAEtB;CAEA,OAAO;AACT;AAEA,SAAgB,EAAa,GAAuD;CAClF,OAAO,EAAc,GAAK,IAAI,CAAC;AACjC;AAYA,SAAgB,EAAe,GAAwD;CACrF,IAAM,IAAkC,CAAC;CAEzC,KAAK,IAAM,CAAC,GAAK,MAAQ,OAAO,QAAQ,CAAI,GAAG;EAC7C,IAAM,IAAQ,EAAI,MAAM,GAAG;EAE3B,IAAI,EAAM,MAAM,MAAM,EAAqB,IAAI,CAAC,CAAC,GAAG;EAEpD,IAAI,IAAM;EAEV,KAAK,IAAI,IAAI,GAAG,IAAI,EAAM,SAAS,GAAG,KAKpC,AAJK,EAAc,EAAI,EAAM,GAAG,MAC9B,EAAI,EAAM,MAAM,CAAC,IAGnB,IAAM,EAAI,EAAM;EAGlB,EAAI,EAAM,EAAM,SAAS,MAAM;CACjC;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../errors.cjs"),t=require("../_common/unsafePaths.cjs");function n(n,r,i={}){let{bracketNotation:a=!0,fallback:o,strict:s=!1}=i;if(/[[\]]/.test(r)){if(!a)throw new e.ArsenalValidationError(`getPath: bracket notation is not supported. Use dot notation: '${r.replace(/\[(\d+)\]/g,`.$1`).replace(/^\.|\.$/g,``)}' or pass { bracketNotation: true }.`);r=r.replace(/\[(\d+)\]/g,`.$1`).replace(/^\.|\.$/g,``)}let c=r.split(`.`).filter(Boolean),l=n;for(let n of c){if(t.UNSAFE_PATH_SEGMENTS.has(n))return o;if(typeof l!=`object`||!l){if(s)throw new e.ArsenalValidationError(`Cannot read property '${n}' of ${l}`);return o}if(l=l[n],l===void 0){if(s)throw new e.ArsenalValidationError(`Property '${n}' does not exist`);return o}}return l}exports.getPath=n;
|
|
2
|
+
//# sourceMappingURL=getPath.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPath.cjs","names":[],"sources":["../../src/object/getPath.ts"],"sourcesContent":["import type { Obj } from '../types';\n\nimport { UNSAFE_PATH_SEGMENTS } from '../_common/unsafePaths';\nimport { ArsenalValidationError } from '../errors';\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\nexport type GetPathOptions = {\n /**\n * When `false`, throws an `ArsenalValidationError` on bracket-notation segments instead of\n * auto-converting them to dot notation. Default: `true`.\n */\n bracketNotation?: boolean;\n /**\n * Returned when the path is missing or resolves to `undefined`.\n * Mutually exclusive with `strict` — if both are set, `strict` takes precedence.\n */\n fallback?: unknown;\n /**\n * When `true`, throws an `ArsenalValidationError` if any path segment is missing.\n * Default: `false`.\n */\n strict?: boolean;\n};\n\n/**\n * Retrieves the value at a dot-notation path of an object.\n *\n * Bracket notation (`a[0].b`) is automatically converted to dot notation by default.\n * Unsafe path segments (`__proto__`, `constructor`, `prototype`) always return `options.fallback`.\n *\n * @example\n * ```ts\n * const obj = { a: { b: { c: 3 } }, d: [1, 2, 3] };\n *\n * getPath(obj, 'a.b.c'); // 3\n * getPath(obj, 'a.b.x', { fallback: 'fallback' }); // 'fallback'\n * getPath(obj, 'd[1]'); // 2 (bracket auto-converted)\n * getPath(obj, 'e.f.g', { strict: true }); // throws ArsenalValidationError\n * getPath(obj, 'a[0]', { bracketNotation: false }); // throws ArsenalValidationError\n * ```\n *\n * @template T - The object type.\n * @template P - The path string type.\n * @param item - The object to query.\n * @param path - The dot-separated path.\n * @param [options] - Options: `fallback`, `strict`, `bracketNotation`.\n * @returns The resolved value, or `options.fallback` if missing.\n * @throws {ArsenalValidationError} When `bracketNotation: false` and bracket syntax is used.\n * @throws {ArsenalValidationError} When `strict: true` and the path does not exist.\n */\nexport function getPath<T extends Obj, P extends string>(\n item: T,\n path: P,\n options: GetPathOptions = {},\n): PathValue<T, P> | undefined {\n const { bracketNotation = true, fallback: defaultValue, strict = false } = options;\n\n if (/[[\\]]/.test(path)) {\n if (!bracketNotation) {\n throw new ArsenalValidationError(\n `getPath: bracket notation is not supported. Use dot notation: '${path.replace(/\\[(\\d+)\\]/g, '.$1').replace(/^\\.|\\.$/g, '')}' or pass { bracketNotation: true }.`,\n );\n }\n\n path = path.replace(/\\[(\\d+)\\]/g, '.$1').replace(/^\\.|\\.$/g, '') as P;\n }\n\n const fragments = path.split('.').filter(Boolean);\n let current: unknown = item;\n\n for (const fragment of fragments) {\n if (UNSAFE_PATH_SEGMENTS.has(fragment)) return defaultValue as PathValue<T, P>;\n\n if (current == null || typeof current !== 'object') {\n if (strict) throw new ArsenalValidationError(`Cannot read property '${fragment}' of ${current}`);\n\n return defaultValue as PathValue<T, P>;\n }\n\n current = (current as Record<string, unknown>)[fragment];\n\n if (current === undefined) {\n if (strict) throw new ArsenalValidationError(`Property '${fragment}' does not exist`);\n\n return defaultValue as PathValue<T, P>;\n }\n }\n\n return current as PathValue<T, P>;\n}\n"],"mappings":"yEAyDA,SAAgB,EACd,EACA,EACA,EAA0B,CAAC,EACE,CAC7B,GAAM,CAAE,kBAAkB,GAAM,SAAU,EAAc,SAAS,IAAU,EAE3E,GAAI,QAAQ,KAAK,CAAI,EAAG,CACtB,GAAI,CAAC,EACH,MAAM,IAAI,EAAA,uBACR,kEAAkE,EAAK,QAAQ,aAAc,KAAK,CAAC,CAAC,QAAQ,WAAY,EAAE,EAAE,qCAC9H,EAGF,EAAO,EAAK,QAAQ,aAAc,KAAK,CAAC,CAAC,QAAQ,WAAY,EAAE,CACjE,CAEA,IAAM,EAAY,EAAK,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,EAC5C,EAAmB,EAEvB,IAAK,IAAM,KAAY,EAAW,CAChC,GAAI,EAAA,qBAAqB,IAAI,CAAQ,EAAG,OAAO,EAE/C,GAAuB,OAAO,GAAY,WAAtC,EAAgD,CAClD,GAAI,EAAQ,MAAM,IAAI,EAAA,uBAAuB,yBAAyB,EAAS,OAAO,GAAS,EAE/F,OAAO,CACT,CAIA,GAFA,EAAW,EAAoC,GAE3C,IAAY,IAAA,GAAW,CACzB,GAAI,EAAQ,MAAM,IAAI,EAAA,uBAAuB,aAAa,EAAS,iBAAiB,EAEpF,OAAO,CACT,CACF,CAEA,OAAO,CACT"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Obj } from '../types';
|
|
2
|
+
type PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? PathValue<T[Key], Rest> : undefined : P extends keyof T ? T[P] : undefined;
|
|
3
|
+
export type GetPathOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* When `false`, throws an `ArsenalValidationError` on bracket-notation segments instead of
|
|
6
|
+
* auto-converting them to dot notation. Default: `true`.
|
|
7
|
+
*/
|
|
8
|
+
bracketNotation?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Returned when the path is missing or resolves to `undefined`.
|
|
11
|
+
* Mutually exclusive with `strict` — if both are set, `strict` takes precedence.
|
|
12
|
+
*/
|
|
13
|
+
fallback?: unknown;
|
|
14
|
+
/**
|
|
15
|
+
* When `true`, throws an `ArsenalValidationError` if any path segment is missing.
|
|
16
|
+
* Default: `false`.
|
|
17
|
+
*/
|
|
18
|
+
strict?: boolean;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the value at a dot-notation path of an object.
|
|
22
|
+
*
|
|
23
|
+
* Bracket notation (`a[0].b`) is automatically converted to dot notation by default.
|
|
24
|
+
* Unsafe path segments (`__proto__`, `constructor`, `prototype`) always return `options.fallback`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const obj = { a: { b: { c: 3 } }, d: [1, 2, 3] };
|
|
29
|
+
*
|
|
30
|
+
* getPath(obj, 'a.b.c'); // 3
|
|
31
|
+
* getPath(obj, 'a.b.x', { fallback: 'fallback' }); // 'fallback'
|
|
32
|
+
* getPath(obj, 'd[1]'); // 2 (bracket auto-converted)
|
|
33
|
+
* getPath(obj, 'e.f.g', { strict: true }); // throws ArsenalValidationError
|
|
34
|
+
* getPath(obj, 'a[0]', { bracketNotation: false }); // throws ArsenalValidationError
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @template T - The object type.
|
|
38
|
+
* @template P - The path string type.
|
|
39
|
+
* @param item - The object to query.
|
|
40
|
+
* @param path - The dot-separated path.
|
|
41
|
+
* @param [options] - Options: `fallback`, `strict`, `bracketNotation`.
|
|
42
|
+
* @returns The resolved value, or `options.fallback` if missing.
|
|
43
|
+
* @throws {ArsenalValidationError} When `bracketNotation: false` and bracket syntax is used.
|
|
44
|
+
* @throws {ArsenalValidationError} When `strict: true` and the path does not exist.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getPath<T extends Obj, P extends string>(item: T, path: P, options?: GetPathOptions): PathValue<T, P> | undefined;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=getPath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPath.d.ts","sourceRoot":"","sources":["../../src/object/getPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAKpC,KAAK,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,GAAG,IAAI,MAAM,IAAI,EAAE,GACxE,GAAG,SAAS,MAAM,CAAC,GACjB,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,GACvB,SAAS,GACX,CAAC,SAAS,MAAM,CAAC,GACf,CAAC,CAAC,CAAC,CAAC,GACJ,SAAS,CAAC;AAEhB,MAAM,MAAM,cAAc,GAAG;IAC3B;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,MAAM,EACrD,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,CAAC,EACP,OAAO,GAAE,cAAmB,GAC3B,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAmC7B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ArsenalValidationError as e } from "../errors.js";
|
|
2
|
+
import { UNSAFE_PATH_SEGMENTS as t } from "../_common/unsafePaths.js";
|
|
3
|
+
//#region src/object/getPath.ts
|
|
4
|
+
function n(n, r, i = {}) {
|
|
5
|
+
let { bracketNotation: a = !0, fallback: o, strict: s = !1 } = i;
|
|
6
|
+
if (/[[\]]/.test(r)) {
|
|
7
|
+
if (!a) throw new e(`getPath: bracket notation is not supported. Use dot notation: '${r.replace(/\[(\d+)\]/g, ".$1").replace(/^\.|\.$/g, "")}' or pass { bracketNotation: true }.`);
|
|
8
|
+
r = r.replace(/\[(\d+)\]/g, ".$1").replace(/^\.|\.$/g, "");
|
|
9
|
+
}
|
|
10
|
+
let c = r.split(".").filter(Boolean), l = n;
|
|
11
|
+
for (let n of c) {
|
|
12
|
+
if (t.has(n)) return o;
|
|
13
|
+
if (typeof l != "object" || !l) {
|
|
14
|
+
if (s) throw new e(`Cannot read property '${n}' of ${l}`);
|
|
15
|
+
return o;
|
|
16
|
+
}
|
|
17
|
+
if (l = l[n], l === void 0) {
|
|
18
|
+
if (s) throw new e(`Property '${n}' does not exist`);
|
|
19
|
+
return o;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return l;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { n as getPath };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=getPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPath.js","names":[],"sources":["../../src/object/getPath.ts"],"sourcesContent":["import type { Obj } from '../types';\n\nimport { UNSAFE_PATH_SEGMENTS } from '../_common/unsafePaths';\nimport { ArsenalValidationError } from '../errors';\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\nexport type GetPathOptions = {\n /**\n * When `false`, throws an `ArsenalValidationError` on bracket-notation segments instead of\n * auto-converting them to dot notation. Default: `true`.\n */\n bracketNotation?: boolean;\n /**\n * Returned when the path is missing or resolves to `undefined`.\n * Mutually exclusive with `strict` — if both are set, `strict` takes precedence.\n */\n fallback?: unknown;\n /**\n * When `true`, throws an `ArsenalValidationError` if any path segment is missing.\n * Default: `false`.\n */\n strict?: boolean;\n};\n\n/**\n * Retrieves the value at a dot-notation path of an object.\n *\n * Bracket notation (`a[0].b`) is automatically converted to dot notation by default.\n * Unsafe path segments (`__proto__`, `constructor`, `prototype`) always return `options.fallback`.\n *\n * @example\n * ```ts\n * const obj = { a: { b: { c: 3 } }, d: [1, 2, 3] };\n *\n * getPath(obj, 'a.b.c'); // 3\n * getPath(obj, 'a.b.x', { fallback: 'fallback' }); // 'fallback'\n * getPath(obj, 'd[1]'); // 2 (bracket auto-converted)\n * getPath(obj, 'e.f.g', { strict: true }); // throws ArsenalValidationError\n * getPath(obj, 'a[0]', { bracketNotation: false }); // throws ArsenalValidationError\n * ```\n *\n * @template T - The object type.\n * @template P - The path string type.\n * @param item - The object to query.\n * @param path - The dot-separated path.\n * @param [options] - Options: `fallback`, `strict`, `bracketNotation`.\n * @returns The resolved value, or `options.fallback` if missing.\n * @throws {ArsenalValidationError} When `bracketNotation: false` and bracket syntax is used.\n * @throws {ArsenalValidationError} When `strict: true` and the path does not exist.\n */\nexport function getPath<T extends Obj, P extends string>(\n item: T,\n path: P,\n options: GetPathOptions = {},\n): PathValue<T, P> | undefined {\n const { bracketNotation = true, fallback: defaultValue, strict = false } = options;\n\n if (/[[\\]]/.test(path)) {\n if (!bracketNotation) {\n throw new ArsenalValidationError(\n `getPath: bracket notation is not supported. Use dot notation: '${path.replace(/\\[(\\d+)\\]/g, '.$1').replace(/^\\.|\\.$/g, '')}' or pass { bracketNotation: true }.`,\n );\n }\n\n path = path.replace(/\\[(\\d+)\\]/g, '.$1').replace(/^\\.|\\.$/g, '') as P;\n }\n\n const fragments = path.split('.').filter(Boolean);\n let current: unknown = item;\n\n for (const fragment of fragments) {\n if (UNSAFE_PATH_SEGMENTS.has(fragment)) return defaultValue as PathValue<T, P>;\n\n if (current == null || typeof current !== 'object') {\n if (strict) throw new ArsenalValidationError(`Cannot read property '${fragment}' of ${current}`);\n\n return defaultValue as PathValue<T, P>;\n }\n\n current = (current as Record<string, unknown>)[fragment];\n\n if (current === undefined) {\n if (strict) throw new ArsenalValidationError(`Property '${fragment}' does not exist`);\n\n return defaultValue as PathValue<T, P>;\n }\n }\n\n return current as PathValue<T, P>;\n}\n"],"mappings":";;;AAyDA,SAAgB,EACd,GACA,GACA,IAA0B,CAAC,GACE;CAC7B,IAAM,EAAE,qBAAkB,IAAM,UAAU,GAAc,YAAS,OAAU;CAE3E,IAAI,QAAQ,KAAK,CAAI,GAAG;EACtB,IAAI,CAAC,GACH,MAAM,IAAI,EACR,kEAAkE,EAAK,QAAQ,cAAc,KAAK,CAAC,CAAC,QAAQ,YAAY,EAAE,EAAE,qCAC9H;EAGF,IAAO,EAAK,QAAQ,cAAc,KAAK,CAAC,CAAC,QAAQ,YAAY,EAAE;CACjE;CAEA,IAAM,IAAY,EAAK,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,GAC5C,IAAmB;CAEvB,KAAK,IAAM,KAAY,GAAW;EAChC,IAAI,EAAqB,IAAI,CAAQ,GAAG,OAAO;EAE/C,IAAuB,OAAO,KAAY,aAAtC,GAAgD;GAClD,IAAI,GAAQ,MAAM,IAAI,EAAuB,yBAAyB,EAAS,OAAO,GAAS;GAE/F,OAAO;EACT;EAIA,IAFA,IAAW,EAAoC,IAE3C,MAAY,KAAA,GAAW;GACzB,IAAI,GAAQ,MAAM,IAAI,EAAuB,aAAa,EAAS,iBAAiB;GAEpF,OAAO;EACT;CACF;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../errors.cjs");function t(n,r,i){if(n===void 0)return`undefined`;if(n===null)return`null`;if(typeof n==`bigint`)return`${n}n`;if(typeof n!=`object`)return JSON.stringify(n);if(i.has(n))return`[Circular]`;if(i.add(n),n instanceof Date)return`[Date:${Number.isNaN(n.getTime())?`Invalid`:n.toISOString()}]`;if(n instanceof RegExp)return`[RegExp:${n.source}/${n.flags}]`;if(n instanceof Set)return`[Set:${[...n].map(e=>t(e,r,i)).sort().join(`,`)}]`;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(`,`)}]`;if(Array.isArray(n))return`[${n.map(e=>t(e,r,i)).join(`,`)}]`;let a=Object.getPrototypeOf(n);if(a!==Object.prototype&&a!==null){if(r?.onClassInstance===`throw`)throw new e.ArsenalSerializationError(`hash: unsupported type ${n.constructor?.name??`unknown`}`);return String(n)}let o=n;return`{${Object.keys(o).filter(e=>o[e]!==void 0).sort().map(e=>`${JSON.stringify(e)}:${t(o[e],r,i)}`).join(`,`)}}`}function n(e,n){return t(e,n,new Set)}exports.hash=n;
|
|
2
|
+
//# sourceMappingURL=hash.cjs.map
|
|
@@ -0,0 +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,EAAM,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,EAAM,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,EAAM,EAAK,EAAS,CAAO,EAAG,EAAM,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,EAAM,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,EAAM,EAAI,GAAI,EAAS,CAAO,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,EAClG,CAEA,SAAgB,EAAK,EAAgB,EAA+B,CAClE,OAAO,EAAM,EAAO,EAAS,IAAI,GAAa,CAChD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type HashOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* What to do when a class instance is encountered (an object whose prototype is
|
|
4
|
+
* neither `Object.prototype` nor `null`).
|
|
5
|
+
*
|
|
6
|
+
* - `'coerce'` (default) — calls `String(value)`.
|
|
7
|
+
* - `'throw'` — throws an `ArsenalSerializationError`.
|
|
8
|
+
*/
|
|
9
|
+
onClassInstance?: 'coerce' | 'throw';
|
|
10
|
+
};
|
|
11
|
+
export declare function hash(value: unknown, options?: HashOptions): string;
|
|
12
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/object/hash.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG;IACxB;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;CACtC,CAAC;AA8EF,wBAAgB,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,CAElE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ArsenalSerializationError as e } from "../errors.js";
|
|
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
|
+
|
|
28
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +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":";;AAkCA,SAAS,EAAM,GAAgB,GAAkC,GAA8B;CAC7F,IAAI,MAAU,KAAA,GAAW,OAAO;CAEhC,IAAI,MAAU,MAAM,OAAO;CAE3B,IAAI,OAAO,KAAU,UAAU,OAAO,GAAG,EAAM;CAE/C,IAAI,OAAO,KAAU,UAAU,OAAO,KAAK,UAAU,CAAK;CAE1D,IAAI,EAAQ,IAAI,CAAe,GAAG,OAAO;CAIzC,IAFA,EAAQ,IAAI,CAAe,GAEvB,aAAiB,MAAM,OAAO,SAAS,OAAO,MAAM,EAAM,QAAQ,CAAC,IAAI,YAAY,EAAM,YAAY,EAAE;CAE3G,IAAI,aAAiB,QAAQ,OAAO,WAAW,EAAM,OAAO,GAAG,EAAM,MAAM;CAE3E,IAAI,aAAiB,KACnB,OAAO,QAAQ,CAAC,GAAG,CAAK,CAAC,CACtB,KAAK,MAAM,EAAM,GAAG,GAAS,CAAO,CAAC,CAAC,CACtC,KAAK,CAAC,CACN,KAAK,GAAG,EAAE;CAEf,IAAI,aAAiB,KAOnB,OAAO,QANS,CAAC,GAAG,EAAM,QAAQ,CAAC,CAAC,CACjC,KAAK,CAAC,GAAK,OAAgB,CAAC,EAAM,GAAK,GAAS,CAAO,GAAG,EAAM,GAAY,GAAS,CAAO,CAAC,CAAU,CAAC,CACxG,MAAM,CAAC,GAAS,IAAY,CAAC,GAAU,OACtC,MAAY,IAAW,EAAU,cAAc,CAAU,IAAI,EAAQ,cAAc,CAAQ,CAGhF,CAAA,CAAQ,KAAK,CAAC,GAAK,OAAgB,GAAG,EAAI,IAAI,GAAY,CAAC,CAAC,KAAK,GAAG,EAAE;CAGvF,IAAI,MAAM,QAAQ,CAAK,GAAG,OAAO,IAAI,EAAM,KAAK,MAAM,EAAM,GAAG,GAAS,CAAO,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;CAE5F,IAAM,IAAQ,OAAO,eAAe,CAAK;CAEzC,IAAI,MAAU,OAAO,aAAa,MAAU,MAAM;EAChD,IAAI,GAAS,oBAAoB,SAC/B,MAAM,IAAI,EACR,0BAA2B,EAA8C,aAAa,QAAQ,WAChG;EAGF,OAAO,OAAO,CAAK;CACrB;CAEA,IAAM,IAAM;CAKZ,OAAO,IAJM,OAAO,KAAK,CAAG,CAAC,CAC1B,QAAQ,MAAM,EAAI,OAAO,KAAA,CAAS,CAAC,CACnC,KAEQ,CAAA,CAAK,KAAK,MAAM,GAAG,KAAK,UAAU,CAAC,EAAE,GAAG,EAAM,EAAI,IAAI,GAAS,CAAO,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE;AAClG;AAEA,SAAgB,EAAK,GAAgB,GAA+B;CAClE,OAAO,EAAM,GAAO,mBAAS,IAAI,IAAY,CAAC;AAChD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './defaults';
|
|
2
|
+
export * from './diff';
|
|
3
|
+
export * from './filterValues';
|
|
4
|
+
export * from './flattenPaths';
|
|
5
|
+
export * from './getPath';
|
|
6
|
+
export * from './hash';
|
|
7
|
+
export * from './invert';
|
|
8
|
+
export * from './mapKeys';
|
|
9
|
+
export * from './mapValues';
|
|
10
|
+
export * from './merge';
|
|
11
|
+
export * from './omit';
|
|
12
|
+
export * from './parseJSON';
|
|
13
|
+
export * from './pick';
|
|
14
|
+
export * from './prune';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/object/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invert.cjs","names":[],"sources":["../../src/object/invert.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\n\n/**\n * Inverts key-value pairs, so each value becomes a key and each key becomes its value.\n * Entries whose value is a dangerous key (`__proto__`, `constructor`, `prototype`) are skipped\n * to avoid prototype pollution. If multiple keys share the same value, the last one wins.\n *\n * @example\n * ```ts\n * invert({ a: 'x', b: 'y' }); // { x: 'a', y: 'b' }\n * ```\n *\n * @param obj - The source object. Values must be valid property keys (string, number, or symbol).\n * @returns A new object with keys and values swapped.\n */\nexport function invert<T extends Record<PropertyKey, PropertyKey>>(obj: T): Record<T[keyof T], keyof T> {\n const out = {} as Record<T[keyof T], keyof T>;\n\n for (const [key, value] of Object.entries(obj) as Array<[keyof T, T[keyof T]]>) {\n if (isUnsafeKey(value)) continue;\n\n out[value] = key;\n }\n\n return out;\n}\n"],"mappings":"8CAeA,SAAgB,EAAmD,EAAqC,CACtG,IAAM,EAAM,CAAC,EAEb,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAAG,EACvC,EAAA,YAAY,CAAK,IAErB,EAAI,GAAS,GAGf,OAAO,CACT"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inverts key-value pairs, so each value becomes a key and each key becomes its value.
|
|
3
|
+
* Entries whose value is a dangerous key (`__proto__`, `constructor`, `prototype`) are skipped
|
|
4
|
+
* to avoid prototype pollution. If multiple keys share the same value, the last one wins.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* invert({ a: 'x', b: 'y' }); // { x: 'a', y: 'b' }
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param obj - The source object. Values must be valid property keys (string, number, or symbol).
|
|
12
|
+
* @returns A new object with keys and values swapped.
|
|
13
|
+
*/
|
|
14
|
+
export declare function invert<T extends Record<PropertyKey, PropertyKey>>(obj: T): Record<T[keyof T], keyof T>;
|
|
15
|
+
//# sourceMappingURL=invert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invert.d.ts","sourceRoot":"","sources":["../../src/object/invert.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAUtG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isUnsafeKey as e } from "../_common/unsafePaths.js";
|
|
2
|
+
//#region src/object/invert.ts
|
|
3
|
+
function t(t) {
|
|
4
|
+
let n = {};
|
|
5
|
+
for (let [r, i] of Object.entries(t)) e(i) || (n[i] = r);
|
|
6
|
+
return n;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { t as invert };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=invert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invert.js","names":[],"sources":["../../src/object/invert.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\n\n/**\n * Inverts key-value pairs, so each value becomes a key and each key becomes its value.\n * Entries whose value is a dangerous key (`__proto__`, `constructor`, `prototype`) are skipped\n * to avoid prototype pollution. If multiple keys share the same value, the last one wins.\n *\n * @example\n * ```ts\n * invert({ a: 'x', b: 'y' }); // { x: 'a', y: 'b' }\n * ```\n *\n * @param obj - The source object. Values must be valid property keys (string, number, or symbol).\n * @returns A new object with keys and values swapped.\n */\nexport function invert<T extends Record<PropertyKey, PropertyKey>>(obj: T): Record<T[keyof T], keyof T> {\n const out = {} as Record<T[keyof T], keyof T>;\n\n for (const [key, value] of Object.entries(obj) as Array<[keyof T, T[keyof T]]>) {\n if (isUnsafeKey(value)) continue;\n\n out[value] = key;\n }\n\n return out;\n}\n"],"mappings":";;AAeA,SAAgB,EAAmD,GAAqC;CACtG,IAAM,IAAM,CAAC;CAEb,KAAK,IAAM,CAAC,GAAK,MAAU,OAAO,QAAQ,CAAG,GACvC,EAAY,CAAK,MAErB,EAAI,KAAS;CAGf,OAAO;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapKeys.cjs","names":[],"sources":["../../src/object/mapKeys.ts"],"sourcesContent":["import type { Obj } from '../types';\n\nimport { isUnsafeKey } from '../_common/unsafePaths';\n\n/**\n * Maps object keys while preserving values. Both the original key and any mapped key that\n * resolve to a dangerous key (`__proto__`, `constructor`, `prototype`) are skipped.\n *\n * @example\n * ```ts\n * mapKeys({ a: 1, b: 2 }, (key) => `x_${String(key)}`); // { x_a: 1, x_b: 2 }\n * ```\n *\n * @param obj - The source object.\n * @param mapper - Function producing the new key for each entry.\n * @returns A new object with mapped keys and the original values.\n */\nexport function mapKeys<T extends Obj>(\n obj: T,\n mapper: (key: keyof T, value: T[keyof T], obj: T) => PropertyKey,\n): Record<PropertyKey, T[keyof T]> {\n const out: Record<PropertyKey, T[keyof T]> = {};\n\n for (const key of Object.keys(obj) as Array<keyof T>) {\n if (isUnsafeKey(key as PropertyKey)) continue;\n\n const mappedKey = mapper(key, obj[key], obj);\n\n if (isUnsafeKey(mappedKey)) continue;\n\n out[mappedKey] = obj[key];\n }\n\n return out;\n}\n"],"mappings":"8CAiBA,SAAgB,EACd,EACA,EACiC,CACjC,IAAM,EAAuC,CAAC,EAE9C,IAAK,IAAM,KAAO,OAAO,KAAK,CAAG,EAAqB,CACpD,GAAI,EAAA,YAAY,CAAkB,EAAG,SAErC,IAAM,EAAY,EAAO,EAAK,EAAI,GAAM,CAAG,EAEvC,EAAA,YAAY,CAAS,IAEzB,EAAI,GAAa,EAAI,GACvB,CAEA,OAAO,CACT"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Obj } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Maps object keys while preserving values. Both the original key and any mapped key that
|
|
4
|
+
* resolve to a dangerous key (`__proto__`, `constructor`, `prototype`) are skipped.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* mapKeys({ a: 1, b: 2 }, (key) => `x_${String(key)}`); // { x_a: 1, x_b: 2 }
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param obj - The source object.
|
|
12
|
+
* @param mapper - Function producing the new key for each entry.
|
|
13
|
+
* @returns A new object with mapped keys and the original values.
|
|
14
|
+
*/
|
|
15
|
+
export declare function mapKeys<T extends Obj>(obj: T, mapper: (key: keyof T, value: T[keyof T], obj: T) => PropertyKey): Record<PropertyKey, T[keyof T]>;
|
|
16
|
+
//# sourceMappingURL=mapKeys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapKeys.d.ts","sourceRoot":"","sources":["../../src/object/mapKeys.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAIpC;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,GAAG,EACnC,GAAG,EAAE,CAAC,EACN,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,WAAW,GAC/D,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAcjC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isUnsafeKey as e } from "../_common/unsafePaths.js";
|
|
2
|
+
//#region src/object/mapKeys.ts
|
|
3
|
+
function t(t, n) {
|
|
4
|
+
let r = {};
|
|
5
|
+
for (let i of Object.keys(t)) {
|
|
6
|
+
if (e(i)) continue;
|
|
7
|
+
let a = n(i, t[i], t);
|
|
8
|
+
e(a) || (r[a] = t[i]);
|
|
9
|
+
}
|
|
10
|
+
return r;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { t as mapKeys };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=mapKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapKeys.js","names":[],"sources":["../../src/object/mapKeys.ts"],"sourcesContent":["import type { Obj } from '../types';\n\nimport { isUnsafeKey } from '../_common/unsafePaths';\n\n/**\n * Maps object keys while preserving values. Both the original key and any mapped key that\n * resolve to a dangerous key (`__proto__`, `constructor`, `prototype`) are skipped.\n *\n * @example\n * ```ts\n * mapKeys({ a: 1, b: 2 }, (key) => `x_${String(key)}`); // { x_a: 1, x_b: 2 }\n * ```\n *\n * @param obj - The source object.\n * @param mapper - Function producing the new key for each entry.\n * @returns A new object with mapped keys and the original values.\n */\nexport function mapKeys<T extends Obj>(\n obj: T,\n mapper: (key: keyof T, value: T[keyof T], obj: T) => PropertyKey,\n): Record<PropertyKey, T[keyof T]> {\n const out: Record<PropertyKey, T[keyof T]> = {};\n\n for (const key of Object.keys(obj) as Array<keyof T>) {\n if (isUnsafeKey(key as PropertyKey)) continue;\n\n const mappedKey = mapper(key, obj[key], obj);\n\n if (isUnsafeKey(mappedKey)) continue;\n\n out[mappedKey] = obj[key];\n }\n\n return out;\n}\n"],"mappings":";;AAiBA,SAAgB,EACd,GACA,GACiC;CACjC,IAAM,IAAuC,CAAC;CAE9C,KAAK,IAAM,KAAO,OAAO,KAAK,CAAG,GAAqB;EACpD,IAAI,EAAY,CAAkB,GAAG;EAErC,IAAM,IAAY,EAAO,GAAK,EAAI,IAAM,CAAG;EAEvC,EAAY,CAAS,MAEzB,EAAI,KAAa,EAAI;CACvB;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapValues.cjs","names":[],"sources":["../../src/object/mapValues.ts"],"sourcesContent":["import type { Obj } from '../types';\n\nimport { isUnsafeKey } from '../_common/unsafePaths';\n\n/**\n * Maps object values while preserving the original keys. Dangerous keys (`__proto__`,\n * `constructor`, `prototype`) are always skipped.\n *\n * @example\n * ```ts\n * mapValues({ a: 1, b: 2 }, (value) => value * 2); // { a: 2, b: 4 }\n * ```\n *\n * @param obj - The source object.\n * @param mapper - Function producing the new value for each entry.\n * @returns A new object with the same keys and mapped values.\n */\nexport function mapValues<T extends Obj, R>(\n obj: T,\n mapper: (value: T[keyof T], key: keyof T, obj: T) => R,\n): { [K in keyof T]: R } {\n const out = {} as { [K in keyof T]: R };\n\n for (const key of Object.keys(obj) as Array<keyof T>) {\n if (isUnsafeKey(key as PropertyKey)) continue;\n\n out[key] = mapper(obj[key], key, obj);\n }\n\n return out;\n}\n"],"mappings":"8CAiBA,SAAgB,EACd,EACA,EACuB,CACvB,IAAM,EAAM,CAAC,EAEb,IAAK,IAAM,KAAO,OAAO,KAAK,CAAG,EAC3B,EAAA,YAAY,CAAkB,IAElC,EAAI,GAAO,EAAO,EAAI,GAAM,EAAK,CAAG,GAGtC,OAAO,CACT"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Obj } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Maps object values while preserving the original keys. Dangerous keys (`__proto__`,
|
|
4
|
+
* `constructor`, `prototype`) are always skipped.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* mapValues({ a: 1, b: 2 }, (value) => value * 2); // { a: 2, b: 4 }
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param obj - The source object.
|
|
12
|
+
* @param mapper - Function producing the new value for each entry.
|
|
13
|
+
* @returns A new object with the same keys and mapped values.
|
|
14
|
+
*/
|
|
15
|
+
export declare function mapValues<T extends Obj, R>(obj: T, mapper: (value: T[keyof T], key: keyof T, obj: T) => R): {
|
|
16
|
+
[K in keyof T]: R;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=mapValues.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapValues.d.ts","sourceRoot":"","sources":["../../src/object/mapValues.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAIpC;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,GAAG,EAAE,CAAC,EACxC,GAAG,EAAE,CAAC,EACN,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,GACrD;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC;CAAE,CAUvB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isUnsafeKey as e } from "../_common/unsafePaths.js";
|
|
2
|
+
//#region src/object/mapValues.ts
|
|
3
|
+
function t(t, n) {
|
|
4
|
+
let r = {};
|
|
5
|
+
for (let i of Object.keys(t)) e(i) || (r[i] = n(t[i], i, t));
|
|
6
|
+
return r;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { t as mapValues };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=mapValues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapValues.js","names":[],"sources":["../../src/object/mapValues.ts"],"sourcesContent":["import type { Obj } from '../types';\n\nimport { isUnsafeKey } from '../_common/unsafePaths';\n\n/**\n * Maps object values while preserving the original keys. Dangerous keys (`__proto__`,\n * `constructor`, `prototype`) are always skipped.\n *\n * @example\n * ```ts\n * mapValues({ a: 1, b: 2 }, (value) => value * 2); // { a: 2, b: 4 }\n * ```\n *\n * @param obj - The source object.\n * @param mapper - Function producing the new value for each entry.\n * @returns A new object with the same keys and mapped values.\n */\nexport function mapValues<T extends Obj, R>(\n obj: T,\n mapper: (value: T[keyof T], key: keyof T, obj: T) => R,\n): { [K in keyof T]: R } {\n const out = {} as { [K in keyof T]: R };\n\n for (const key of Object.keys(obj) as Array<keyof T>) {\n if (isUnsafeKey(key as PropertyKey)) continue;\n\n out[key] = mapper(obj[key], key, obj);\n }\n\n return out;\n}\n"],"mappings":";;AAiBA,SAAgB,EACd,GACA,GACuB;CACvB,IAAM,IAAM,CAAC;CAEb,KAAK,IAAM,KAAO,OAAO,KAAK,CAAG,GAC3B,EAAY,CAAkB,MAElC,EAAI,KAAO,EAAO,EAAI,IAAM,GAAK,CAAG;CAGtC,OAAO;AACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../_common/unsafePaths.cjs"),t=require("../guards/isPlainObject.cjs");function n(r,i,a){if(!t.isPlainObject(i))return i;let o={...r};for(let r of Object.keys(i)){if(e.isUnsafeKey(r))continue;let s=i[r],c=o[r];o[r]=Array.isArray(s)&&Array.isArray(c)?a.arrayStrategy===`concat`?[...c,...s]:s:t.isPlainObject(s)&&t.isPlainObject(c)?n(c,s,a):s}return o}function r(...e){let t=e[e.length-1],r=e.length>0&&typeof t==`object`&&!!t&&!Array.isArray(t)&&`arrayStrategy`in t&&Object.keys(t).length===1&&(t.arrayStrategy===`concat`||t.arrayStrategy===`replace`),i=r?t:{},a=r?e.slice(0,-1):e;return a.length===0?{}:a.reduce((e,t)=>n(e,t,i),{})}function i(...t){if(t.length===0)return{};let n={};for(let r of t)for(let t of Object.keys(r))e.isUnsafeKey(t)||(n[t]=r[t]);return n}exports.deepMerge=r,exports.shallowMerge=i;
|
|
2
|
+
//# sourceMappingURL=merge.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.cjs","names":[],"sources":["../../src/object/merge.ts"],"sourcesContent":["import type { Obj } from '../types';\n\nimport { isUnsafeKey } from '../_common/unsafePaths';\nimport { isPlainObject } from '../guards/isPlainObject';\n\nexport type DeepMergeOptions = {\n /** How to handle arrays when both source and target contain one. Default: `'replace'`. */\n arrayStrategy?: 'concat' | 'replace';\n};\n\ntype DeepMerge<T, U> = T extends Obj\n ? U extends Obj\n ? {\n [K in keyof T | keyof U]: K extends keyof T\n ? K extends keyof U\n ? DeepMerge<T[K], U[K]>\n : T[K]\n : K extends keyof U\n ? U[K]\n : never;\n }\n : U\n : U;\n\ntype Merge<T extends Obj[]> = T extends [infer First, ...infer Rest]\n ? First extends Obj\n ? Rest extends Obj[]\n ? DeepMerge<First, Merge<Rest>>\n : First\n : Obj\n : Obj;\n\nfunction mergeObjects<T extends Obj, U extends Obj>(target: T, source: U, options: DeepMergeOptions): DeepMerge<T, U> {\n if (!isPlainObject(source)) return source as DeepMerge<T, U>;\n\n const result = { ...target } as DeepMerge<T, U>;\n\n for (const key of Object.keys(source)) {\n // Guard against prototype pollution: skip dangerous keys\n if (isUnsafeKey(key)) {\n continue;\n }\n\n const sourceValue = source[key];\n const targetValue = result[key];\n\n (result as Record<string, unknown>)[key] =\n Array.isArray(sourceValue) && Array.isArray(targetValue)\n ? options.arrayStrategy === 'concat'\n ? [...targetValue, ...sourceValue]\n : sourceValue\n : isPlainObject(sourceValue) && isPlainObject(targetValue)\n ? mergeObjects(targetValue as Obj, sourceValue as Obj, options)\n : sourceValue;\n }\n\n return result;\n}\n\n/**\n * Deeply merges two or more objects. Arrays in source objects **replace** the target array by default.\n * Pass `{ arrayStrategy: 'concat' }` as the last argument to concatenate arrays instead.\n *\n * @example\n * ```ts\n * deepMerge({ a: 1, b: { x: 1 } }, { b: { y: 2 }, c: 3 });\n * // { a: 1, b: { x: 1, y: 2 }, c: 3 }\n *\n * deepMerge({ tags: ['a'] }, { tags: ['b'] });\n * // { tags: ['b'] } ← arrays replaced\n *\n * deepMerge({ tags: ['a'] }, { tags: ['b'] }, { arrayStrategy: 'concat' });\n * // { tags: ['a', 'b'] }\n * ```\n */\nexport function deepMerge<T extends Obj[]>(...args: [...T] | [...T, DeepMergeOptions]): Merge<T> {\n const lastArg = args[args.length - 1];\n const hasOptions =\n args.length > 0 &&\n typeof lastArg === 'object' &&\n lastArg !== null &&\n !Array.isArray(lastArg) &&\n 'arrayStrategy' in lastArg &&\n Object.keys(lastArg).length === 1 &&\n ((lastArg as DeepMergeOptions).arrayStrategy === 'concat' ||\n (lastArg as DeepMergeOptions).arrayStrategy === 'replace');\n\n const options: DeepMergeOptions = hasOptions ? (lastArg as DeepMergeOptions) : {};\n const items = (hasOptions ? args.slice(0, -1) : args) as Obj[];\n\n if (items.length === 0) return {} as Merge<T>;\n\n return items.reduce((acc: Obj, obj: Obj) => mergeObjects(acc, obj, options) as Obj, {} as Obj) as unknown as Merge<T>;\n}\n\n/**\n * Shallowly merges two or more objects. Later sources win for duplicate keys.\n * Dangerous keys (`__proto__`, `constructor`, `prototype`) are always skipped.\n *\n * @example\n * ```ts\n * shallowMerge({ a: 1, b: { x: 1 } }, { b: { y: 2 } });\n * // { a: 1, b: { y: 2 } } ← nested object replaced, not merged\n *\n * shallowMerge(defaults, overrides, extras);\n * ```\n */\nexport function shallowMerge<T extends Obj[]>(...items: [...T]): Merge<T> {\n if (items.length === 0) return {} as Merge<T>;\n\n const result: Obj = {};\n\n for (const item of items) {\n for (const key of Object.keys(item)) {\n if (isUnsafeKey(key)) continue;\n\n result[key] = item[key];\n }\n }\n\n return result as Merge<T>;\n}\n"],"mappings":"uFAgCA,SAAS,EAA2C,EAAW,EAAW,EAA4C,CACpH,GAAI,CAAC,EAAA,cAAc,CAAM,EAAG,OAAO,EAEnC,IAAM,EAAS,CAAE,GAAG,CAAO,EAE3B,IAAK,IAAM,KAAO,OAAO,KAAK,CAAM,EAAG,CAErC,GAAI,EAAA,YAAY,CAAG,EACjB,SAGF,IAAM,EAAc,EAAO,GACrB,EAAc,EAAO,GAE3B,EAAoC,GAClC,MAAM,QAAQ,CAAW,GAAK,MAAM,QAAQ,CAAW,EACnD,EAAQ,gBAAkB,SACxB,CAAC,GAAG,EAAa,GAAG,CAAW,EAC/B,EACF,EAAA,cAAc,CAAW,GAAK,EAAA,cAAc,CAAW,EACrD,EAAa,EAAoB,EAAoB,CAAO,EAC5D,CACV,CAEA,OAAO,CACT,CAkBA,SAAgB,EAA2B,GAAG,EAAmD,CAC/F,IAAM,EAAU,EAAK,EAAK,OAAS,GAC7B,EACJ,EAAK,OAAS,GACd,OAAO,GAAY,YACnB,GACA,CAAC,MAAM,QAAQ,CAAO,GACtB,kBAAmB,GACnB,OAAO,KAAK,CAAO,CAAC,CAAC,SAAW,IAC9B,EAA6B,gBAAkB,UAC9C,EAA6B,gBAAkB,WAE9C,EAA4B,EAAc,EAA+B,CAAC,EAC1E,EAAS,EAAa,EAAK,MAAM,EAAG,EAAE,EAAI,EAIhD,OAFI,EAAM,SAAW,EAAU,CAAC,EAEzB,EAAM,QAAQ,EAAU,IAAa,EAAa,EAAK,EAAK,CAAO,EAAU,CAAC,CAAQ,CAC/F,CAcA,SAAgB,EAA8B,GAAG,EAAyB,CACxE,GAAI,EAAM,SAAW,EAAG,MAAO,CAAC,EAEhC,IAAM,EAAc,CAAC,EAErB,IAAK,IAAM,KAAQ,EACjB,IAAK,IAAM,KAAO,OAAO,KAAK,CAAI,EAC5B,EAAA,YAAY,CAAG,IAEnB,EAAO,GAAO,EAAK,IAIvB,OAAO,CACT"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Obj } from '../types';
|
|
2
|
+
export type DeepMergeOptions = {
|
|
3
|
+
/** How to handle arrays when both source and target contain one. Default: `'replace'`. */
|
|
4
|
+
arrayStrategy?: 'concat' | 'replace';
|
|
5
|
+
};
|
|
6
|
+
type DeepMerge<T, U> = T extends Obj ? U extends Obj ? {
|
|
7
|
+
[K in keyof T | keyof U]: K extends keyof T ? K extends keyof U ? DeepMerge<T[K], U[K]> : T[K] : K extends keyof U ? U[K] : never;
|
|
8
|
+
} : U : U;
|
|
9
|
+
type Merge<T extends Obj[]> = T extends [infer First, ...infer Rest] ? First extends Obj ? Rest extends Obj[] ? DeepMerge<First, Merge<Rest>> : First : Obj : Obj;
|
|
10
|
+
/**
|
|
11
|
+
* Deeply merges two or more objects. Arrays in source objects **replace** the target array by default.
|
|
12
|
+
* Pass `{ arrayStrategy: 'concat' }` as the last argument to concatenate arrays instead.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* deepMerge({ a: 1, b: { x: 1 } }, { b: { y: 2 }, c: 3 });
|
|
17
|
+
* // { a: 1, b: { x: 1, y: 2 }, c: 3 }
|
|
18
|
+
*
|
|
19
|
+
* deepMerge({ tags: ['a'] }, { tags: ['b'] });
|
|
20
|
+
* // { tags: ['b'] } ← arrays replaced
|
|
21
|
+
*
|
|
22
|
+
* deepMerge({ tags: ['a'] }, { tags: ['b'] }, { arrayStrategy: 'concat' });
|
|
23
|
+
* // { tags: ['a', 'b'] }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function deepMerge<T extends Obj[]>(...args: [...T] | [...T, DeepMergeOptions]): Merge<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Shallowly merges two or more objects. Later sources win for duplicate keys.
|
|
29
|
+
* Dangerous keys (`__proto__`, `constructor`, `prototype`) are always skipped.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* shallowMerge({ a: 1, b: { x: 1 } }, { b: { y: 2 } });
|
|
34
|
+
* // { a: 1, b: { y: 2 } } ← nested object replaced, not merged
|
|
35
|
+
*
|
|
36
|
+
* shallowMerge(defaults, overrides, extras);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function shallowMerge<T extends Obj[]>(...items: [...T]): Merge<T>;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/object/merge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAKpC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,0FAA0F;IAC1F,aAAa,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;CACtC,CAAC;AAEF,KAAK,SAAS,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,GAAG,GAChC,CAAC,SAAS,GAAG,GACX;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GACvC,CAAC,SAAS,MAAM,CAAC,GACf,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GACrB,CAAC,CAAC,CAAC,CAAC,GACN,CAAC,SAAS,MAAM,CAAC,GACf,CAAC,CAAC,CAAC,CAAC,GACJ,KAAK;CACZ,GACD,CAAC,GACH,CAAC,CAAC;AAEN,KAAK,KAAK,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,GAChE,KAAK,SAAS,GAAG,GACf,IAAI,SAAS,GAAG,EAAE,GAChB,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,GAC7B,KAAK,GACP,GAAG,GACL,GAAG,CAAC;AA6BR;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,gBAAgB,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAkB/F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAcxE"}
|