@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
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# @vielzeug/arsenal
|
|
2
|
+
|
|
3
|
+
> Tree-shakeable, zero-dependency utility library for arrays, async control flow, objects, strings, functions, math, random, and typed checks.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@vielzeug/arsenal) [](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
<details>
|
|
8
|
+
<summary>Quick Reference</summary>
|
|
9
|
+
|
|
10
|
+
**Package:** `@vielzeug/arsenal` · **Category:** Utilities
|
|
11
|
+
|
|
12
|
+
**Key exports:** `chunk`, `debounce`, `throttle`, `allOf`, `clamp`, `isEqual`, `retry`, `sleep`, `stringify`, `fuzzy`, `getPath`, `deepMerge`, `diff`, `stash`, `memo`
|
|
13
|
+
|
|
14
|
+
**When to use:** Tree-shakeable, zero-dependency utility library for arrays, async control flow, objects, strings, functions, math, random, and typed checks.
|
|
15
|
+
|
|
16
|
+
**Related:** [`@vielzeug/coins`](https://www.npmjs.com/package/@vielzeug/coins) · [`@vielzeug/tempo`](https://www.npmjs.com/package/@vielzeug/tempo)
|
|
17
|
+
|
|
18
|
+
</details>
|
|
19
|
+
|
|
20
|
+
`@vielzeug/arsenal` is part of Vielzeug and ships as a zero-dependency TypeScript package with ESM+CJS output.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
pnpm add @vielzeug/arsenal
|
|
26
|
+
npm install @vielzeug/arsenal
|
|
27
|
+
yarn add @vielzeug/arsenal
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import {
|
|
34
|
+
allOf,
|
|
35
|
+
chunk,
|
|
36
|
+
deepMerge,
|
|
37
|
+
diff,
|
|
38
|
+
filterMap,
|
|
39
|
+
fuzzy,
|
|
40
|
+
groupBy,
|
|
41
|
+
noneOf,
|
|
42
|
+
partial,
|
|
43
|
+
pick,
|
|
44
|
+
queue,
|
|
45
|
+
retry,
|
|
46
|
+
stringify,
|
|
47
|
+
} from '@vielzeug/arsenal';
|
|
48
|
+
|
|
49
|
+
const users = [
|
|
50
|
+
{ id: 1, name: 'Alice', role: 'admin' },
|
|
51
|
+
{ id: 2, name: 'Bob', role: 'user' },
|
|
52
|
+
];
|
|
53
|
+
const pages = chunk([1, 2, 3, 4, 5], 2);
|
|
54
|
+
const byRole = groupBy(users, (u) => u.role);
|
|
55
|
+
const safe = pick(users[0], ['id', 'name']);
|
|
56
|
+
|
|
57
|
+
const q = queue({ concurrency: 2 });
|
|
58
|
+
await q.add(() => fetch('/api/a'));
|
|
59
|
+
|
|
60
|
+
const data = await retry(() => fetch('/api/health').then((r) => r.json()), {
|
|
61
|
+
times: 3,
|
|
62
|
+
delay: 200,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const doubleAll = partial((factor: number, values: number[]) => values.map((n) => n * factor), 2);
|
|
66
|
+
const doubled = filterMap(doubleAll([1, 2, 3]), (n) => (n > 2 ? n : undefined));
|
|
67
|
+
|
|
68
|
+
// Compose predicates — allOf / anyOf / noneOf
|
|
69
|
+
const isWorkingAge = allOf<number>(
|
|
70
|
+
(age) => age >= 18,
|
|
71
|
+
(age) => age < 65,
|
|
72
|
+
);
|
|
73
|
+
const evens = [1, 2, 3, 4].filter(noneOf((n: number) => n % 2 !== 0));
|
|
74
|
+
|
|
75
|
+
// Fuzzy search — filter mode or scored mode
|
|
76
|
+
const filtered = fuzzy(users, 'alice'); // User[]
|
|
77
|
+
const ranked = fuzzy(users, 'alice', { scored: true }); // ScoredResult<User>[]
|
|
78
|
+
// [{ item: { name: 'Alice', ... }, score: 0.91 }, ...]
|
|
79
|
+
|
|
80
|
+
// Deep merge with optional array strategy
|
|
81
|
+
deepMerge({ a: { x: 1 } }, { a: { y: 2 } }); // { a: { x: 1, y: 2 } }
|
|
82
|
+
deepMerge({ tags: ['a'] }, { tags: ['b'] }, { arrayStrategy: 'concat' }); // { tags: ['a', 'b'] }
|
|
83
|
+
|
|
84
|
+
// Structured object diff
|
|
85
|
+
diff({ port: 3000, host: 'localhost' }, { port: 4000 });
|
|
86
|
+
// { added: [], removed: ['host'], changed: { port: { before: 3000, after: 4000 } } }
|
|
87
|
+
|
|
88
|
+
// Deterministic cache keys
|
|
89
|
+
const key = stringify({ sort: 'asc', filter: { role: 'admin' } });
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
> **Money utilities** (`currency`, `exchange`) have moved to [`@vielzeug/coins`](https://www.npmjs.com/package/@vielzeug/coins).
|
|
93
|
+
> **Date utilities** (`expires`, `timeDiff`, `dateRange`) are available in [`@vielzeug/tempo`](https://www.npmjs.com/package/@vielzeug/tempo).
|
|
94
|
+
|
|
95
|
+
## Documentation
|
|
96
|
+
|
|
97
|
+
- [Overview](https://vielzeug.dev/arsenal/)
|
|
98
|
+
- [Usage Guide](https://vielzeug.dev/arsenal/usage)
|
|
99
|
+
- [API Reference](https://vielzeug.dev/arsenal/api)
|
|
100
|
+
- [Examples](https://vielzeug.dev/arsenal/examples)
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
MIT © [Helmuth Saatkamp](https://github.com/helmuthdu) — part of the [Vielzeug](https://github.com/helmuthdu/vielzeug) monorepo.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_abortable.d.ts","sourceRoot":"","sources":["../../src/_common/_abortable.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAejF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=class extends Map{maxSize;constructor(e){super(),this.maxSize=e}set(e,t){return this.has(e)&&this.delete(e),super.set(e,t),this.size>this.maxSize&&this.evictOldest(),this}evictOldest(e=()=>!0){for(let[t,n]of this)if(e(t,n))return this.delete(t),!0;return!1}};exports.LruMap=e;
|
|
2
|
+
//# sourceMappingURL=_lruMap.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_lruMap.cjs","names":[],"sources":["../../src/_common/_lruMap.ts"],"sourcesContent":["/**\n * A Map subclass that evicts the oldest non-excluded entry when the map exceeds\n * `maxSize`. Iteration order (insertion order) determines LRU — the first key\n * returned by `keys()` is the oldest.\n *\n * Calling `set` on an existing key refreshes its position (move-to-end).\n *\n * Module-private: underscore-prefixed file is excluded from barrel exports.\n */\nexport class LruMap<K, V> extends Map<K, V> {\n readonly maxSize: number;\n\n constructor(maxSize: number) {\n super();\n this.maxSize = maxSize;\n }\n\n override set(key: K, value: V): this {\n // Move existing entry to the end (most-recently-used position)\n if (this.has(key)) this.delete(key);\n\n super.set(key, value);\n\n // Evict oldest entry if we've exceeded maxSize\n if (this.size > this.maxSize) this.evictOldest();\n\n return this;\n }\n\n /**\n * Evicts the oldest entry for which `canEvict` returns true.\n * Returns `true` if an entry was evicted, `false` if all entries are guarded.\n */\n evictOldest(canEvict: (key: K, value: V) => boolean = () => true): boolean {\n for (const [k, v] of this) {\n if (canEvict(k, v)) {\n this.delete(k);\n\n return true;\n }\n }\n\n return false;\n }\n}\n"],"mappings":"AASA,IAAa,EAAb,cAAkC,GAAU,CAC1C,QAEA,YAAY,EAAiB,CAC3B,MAAM,EACN,KAAK,QAAU,CACjB,CAEA,IAAa,EAAQ,EAAgB,CASnC,OAPI,KAAK,IAAI,CAAG,GAAG,KAAK,OAAO,CAAG,EAElC,MAAM,IAAI,EAAK,CAAK,EAGhB,KAAK,KAAO,KAAK,SAAS,KAAK,YAAY,EAExC,IACT,CAMA,YAAY,MAAgD,GAAe,CACzE,IAAK,GAAM,CAAC,EAAG,KAAM,KACnB,GAAI,EAAS,EAAG,CAAC,EAGf,OAFA,KAAK,OAAO,CAAC,EAEN,GAIX,MAAO,EACT,CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Map subclass that evicts the oldest non-excluded entry when the map exceeds
|
|
3
|
+
* `maxSize`. Iteration order (insertion order) determines LRU — the first key
|
|
4
|
+
* returned by `keys()` is the oldest.
|
|
5
|
+
*
|
|
6
|
+
* Calling `set` on an existing key refreshes its position (move-to-end).
|
|
7
|
+
*
|
|
8
|
+
* Module-private: underscore-prefixed file is excluded from barrel exports.
|
|
9
|
+
*/
|
|
10
|
+
export declare class LruMap<K, V> extends Map<K, V> {
|
|
11
|
+
readonly maxSize: number;
|
|
12
|
+
constructor(maxSize: number);
|
|
13
|
+
set(key: K, value: V): this;
|
|
14
|
+
/**
|
|
15
|
+
* Evicts the oldest entry for which `canEvict` returns true.
|
|
16
|
+
* Returns `true` if an entry was evicted, `false` if all entries are guarded.
|
|
17
|
+
*/
|
|
18
|
+
evictOldest(canEvict?: (key: K, value: V) => boolean): boolean;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=_lruMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_lruMap.d.ts","sourceRoot":"","sources":["../../src/_common/_lruMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,MAAM,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM;IAKlB,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAYpC;;;OAGG;IACH,WAAW,CAAC,QAAQ,GAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,OAAoB,GAAG,OAAO;CAW3E"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/_common/_lruMap.ts
|
|
2
|
+
var e = class extends Map {
|
|
3
|
+
maxSize;
|
|
4
|
+
constructor(e) {
|
|
5
|
+
super(), this.maxSize = e;
|
|
6
|
+
}
|
|
7
|
+
set(e, t) {
|
|
8
|
+
return this.has(e) && this.delete(e), super.set(e, t), this.size > this.maxSize && this.evictOldest(), this;
|
|
9
|
+
}
|
|
10
|
+
evictOldest(e = () => !0) {
|
|
11
|
+
for (let [t, n] of this) if (e(t, n)) return this.delete(t), !0;
|
|
12
|
+
return !1;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { e as LruMap };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=_lruMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_lruMap.js","names":[],"sources":["../../src/_common/_lruMap.ts"],"sourcesContent":["/**\n * A Map subclass that evicts the oldest non-excluded entry when the map exceeds\n * `maxSize`. Iteration order (insertion order) determines LRU — the first key\n * returned by `keys()` is the oldest.\n *\n * Calling `set` on an existing key refreshes its position (move-to-end).\n *\n * Module-private: underscore-prefixed file is excluded from barrel exports.\n */\nexport class LruMap<K, V> extends Map<K, V> {\n readonly maxSize: number;\n\n constructor(maxSize: number) {\n super();\n this.maxSize = maxSize;\n }\n\n override set(key: K, value: V): this {\n // Move existing entry to the end (most-recently-used position)\n if (this.has(key)) this.delete(key);\n\n super.set(key, value);\n\n // Evict oldest entry if we've exceeded maxSize\n if (this.size > this.maxSize) this.evictOldest();\n\n return this;\n }\n\n /**\n * Evicts the oldest entry for which `canEvict` returns true.\n * Returns `true` if an entry was evicted, `false` if all entries are guarded.\n */\n evictOldest(canEvict: (key: K, value: V) => boolean = () => true): boolean {\n for (const [k, v] of this) {\n if (canEvict(k, v)) {\n this.delete(k);\n\n return true;\n }\n }\n\n return false;\n }\n}\n"],"mappings":";AASA,IAAa,IAAb,cAAkC,IAAU;CAC1C;CAEA,YAAY,GAAiB;EAE3B,AADA,MAAM,GACN,KAAK,UAAU;CACjB;CAEA,IAAa,GAAQ,GAAgB;EASnC,OAPI,KAAK,IAAI,CAAG,KAAG,KAAK,OAAO,CAAG,GAElC,MAAM,IAAI,GAAK,CAAK,GAGhB,KAAK,OAAO,KAAK,WAAS,KAAK,YAAY,GAExC;CACT;CAMA,YAAY,UAAgD,IAAe;EACzE,KAAK,IAAM,CAAC,GAAG,MAAM,MACnB,IAAI,EAAS,GAAG,CAAC,GAGf,OAFA,KAAK,OAAO,CAAC,GAEN;EAIX,OAAO;CACT;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_secureRandomIndex.cjs","names":[],"sources":["../../src/_common/_secureRandomIndex.ts"],"sourcesContent":["/**\n * Returns a cryptographically random integer in `[0, exclusiveMax)` via `crypto.getRandomValues`.\n * Shared by `random()`, `shuffle()`, and `drawMany()` — the single source of truth for converting\n * a random `Uint32` into a bounded index.\n *\n * Module-private: underscore-prefixed file is excluded from barrel exports.\n * @internal\n */\nexport function secureRandomIndex(exclusiveMax: number): number {\n // Divide by 0x100000000 (not 0xffffffff) to produce [0, 1) instead of [0, 1]\n const randomValue = crypto.getRandomValues(new Uint32Array(1))[0]! / 0x100000000;\n\n return Math.floor(randomValue * exclusiveMax);\n}\n"],"mappings":"AAQA,SAAgB,EAAkB,EAA8B,CAE9D,IAAM,EAAc,OAAO,gBAAgB,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,GAAM,WAErE,OAAO,KAAK,MAAM,EAAc,CAAY,CAC9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_secureRandomIndex.d.ts","sourceRoot":"","sources":["../../src/_common/_secureRandomIndex.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/_common/_secureRandomIndex.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(1))[0] / 4294967296;
|
|
4
|
+
return Math.floor(t * e);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { e as secureRandomIndex };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=_secureRandomIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_secureRandomIndex.js","names":[],"sources":["../../src/_common/_secureRandomIndex.ts"],"sourcesContent":["/**\n * Returns a cryptographically random integer in `[0, exclusiveMax)` via `crypto.getRandomValues`.\n * Shared by `random()`, `shuffle()`, and `drawMany()` — the single source of truth for converting\n * a random `Uint32` into a bounded index.\n *\n * Module-private: underscore-prefixed file is excluded from barrel exports.\n * @internal\n */\nexport function secureRandomIndex(exclusiveMax: number): number {\n // Divide by 0x100000000 (not 0xffffffff) to produce [0, 1) instead of [0, 1]\n const randomValue = crypto.getRandomValues(new Uint32Array(1))[0]! / 0x100000000;\n\n return Math.floor(randomValue * exclusiveMax);\n}\n"],"mappings":";AAQA,SAAgB,EAAkB,GAA8B;CAE9D,IAAM,IAAc,OAAO,gCAAgB,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,KAAM;CAErE,OAAO,KAAK,MAAM,IAAc,CAAY;AAC9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_selectorSet.cjs","names":[],"sources":["../../src/_common/_selectorSet.ts"],"sourcesContent":["import type { Primitive } from '../types';\n\n/**\n * Builds a `Set` of `selector(item)` results for O(1) membership checks — shared by\n * `intersection()` and `difference()`.\n *\n * Module-private: underscore-prefixed file is excluded from barrel exports.\n * @internal\n */\nexport function toSelectorSet<T>(items: readonly T[], selector: (item: T) => Primitive): Set<Primitive> {\n return new Set(items.map((item) => selector(item)));\n}\n\n/**\n * Returns `items` with duplicate `selector(item)` results removed, preserving the first\n * occurrence of each key — shared by `union()` and `uniq()`.\n *\n * Module-private: underscore-prefixed file is excluded from barrel exports.\n * @internal\n */\nexport function dedupeBySelector<T>(items: readonly T[], selector: (item: T) => Primitive): T[] {\n const seen = new Set<Primitive>();\n const out: T[] = [];\n\n for (const item of items) {\n const key = selector(item);\n\n if (seen.has(key)) continue;\n\n seen.add(key);\n out.push(item);\n }\n\n return out;\n}\n"],"mappings":"AASA,SAAgB,EAAiB,EAAqB,EAAkD,CACtG,OAAO,IAAI,IAAI,EAAM,IAAK,GAAS,EAAS,CAAI,CAAC,CAAC,CACpD,CASA,SAAgB,EAAoB,EAAqB,EAAuC,CAC9F,IAAM,EAAO,IAAI,IACX,EAAW,CAAC,EAElB,IAAK,IAAM,KAAQ,EAAO,CACxB,IAAM,EAAM,EAAS,CAAI,EAErB,EAAK,IAAI,CAAG,IAEhB,EAAK,IAAI,CAAG,EACZ,EAAI,KAAK,CAAI,EACf,CAEA,OAAO,CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_selectorSet.d.ts","sourceRoot":"","sources":["../../src/_common/_selectorSet.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/_common/_selectorSet.ts
|
|
2
|
+
function e(e, t) {
|
|
3
|
+
return new Set(e.map((e) => t(e)));
|
|
4
|
+
}
|
|
5
|
+
function t(e, t) {
|
|
6
|
+
let n = /* @__PURE__ */ new Set(), r = [];
|
|
7
|
+
for (let i of e) {
|
|
8
|
+
let e = t(i);
|
|
9
|
+
n.has(e) || (n.add(e), r.push(i));
|
|
10
|
+
}
|
|
11
|
+
return r;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { t as dedupeBySelector, e as toSelectorSet };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=_selectorSet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_selectorSet.js","names":[],"sources":["../../src/_common/_selectorSet.ts"],"sourcesContent":["import type { Primitive } from '../types';\n\n/**\n * Builds a `Set` of `selector(item)` results for O(1) membership checks — shared by\n * `intersection()` and `difference()`.\n *\n * Module-private: underscore-prefixed file is excluded from barrel exports.\n * @internal\n */\nexport function toSelectorSet<T>(items: readonly T[], selector: (item: T) => Primitive): Set<Primitive> {\n return new Set(items.map((item) => selector(item)));\n}\n\n/**\n * Returns `items` with duplicate `selector(item)` results removed, preserving the first\n * occurrence of each key — shared by `union()` and `uniq()`.\n *\n * Module-private: underscore-prefixed file is excluded from barrel exports.\n * @internal\n */\nexport function dedupeBySelector<T>(items: readonly T[], selector: (item: T) => Primitive): T[] {\n const seen = new Set<Primitive>();\n const out: T[] = [];\n\n for (const item of items) {\n const key = selector(item);\n\n if (seen.has(key)) continue;\n\n seen.add(key);\n out.push(item);\n }\n\n return out;\n}\n"],"mappings":";AASA,SAAgB,EAAiB,GAAqB,GAAkD;CACtG,OAAO,IAAI,IAAI,EAAM,KAAK,MAAS,EAAS,CAAI,CAAC,CAAC;AACpD;AASA,SAAgB,EAAoB,GAAqB,GAAuC;CAC9F,IAAM,oBAAO,IAAI,IAAe,GAC1B,IAAW,CAAC;CAElB,KAAK,IAAM,KAAQ,GAAO;EACxB,IAAM,IAAM,EAAS,CAAI;EAErB,EAAK,IAAI,CAAG,MAEhB,EAAK,IAAI,CAAG,GACZ,EAAI,KAAK,CAAI;CACf;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsafePaths.cjs","names":[],"sources":["../../src/_common/unsafePaths.ts"],"sourcesContent":["/**\n * Path segments that must be rejected in any dot-notation traversal or mutation\n * to prevent prototype pollution reads and writes.\n * @internal\n */\nexport const UNSAFE_PATH_SEGMENTS = new Set(['__proto__', 'constructor', 'prototype']);\n\n/**\n * Returns `true` if every dot-notation segment in `key` is safe to use as a\n * plain-object property.\n *\n * @example\n * ```ts\n * isSafePath('user.name') // true\n * isSafePath('__proto__.polluted') // false\n * ```\n */\nexport function isSafePath(key: string): boolean {\n return key.split('.').every((s) => !UNSAFE_PATH_SEGMENTS.has(s));\n}\n\n/**\n * Returns `true` if `key` is one of the dangerous own-property names that can be used to\n * pollute `Object.prototype` (`__proto__`, `constructor`, `prototype`). Use this for plain\n * (non-dotted) property keys — e.g. object keys being copied or reassigned. For dotted paths,\n * use `isSafePath` instead.\n *\n * @example\n * ```ts\n * isUnsafeKey('name') // false\n * isUnsafeKey('__proto__') // true\n * ```\n */\nexport function isUnsafeKey(key: PropertyKey): boolean {\n return typeof key === 'string' && UNSAFE_PATH_SEGMENTS.has(key);\n}\n"],"mappings":"AAKA,IAAa,EAAuB,IAAI,IAAI,CAAC,YAAa,cAAe,WAAW,CAAC,EA4BrF,SAAgB,EAAY,EAA2B,CACrD,OAAO,OAAO,GAAQ,UAAY,EAAqB,IAAI,CAAG,CAChE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns `true` if every dot-notation segment in `key` is safe to use as a
|
|
3
|
+
* plain-object property.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* isSafePath('user.name') // true
|
|
8
|
+
* isSafePath('__proto__.polluted') // false
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare function isSafePath(key: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Returns `true` if `key` is one of the dangerous own-property names that can be used to
|
|
14
|
+
* pollute `Object.prototype` (`__proto__`, `constructor`, `prototype`). Use this for plain
|
|
15
|
+
* (non-dotted) property keys — e.g. object keys being copied or reassigned. For dotted paths,
|
|
16
|
+
* use `isSafePath` instead.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* isUnsafeKey('name') // false
|
|
21
|
+
* isUnsafeKey('__proto__') // true
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function isUnsafeKey(key: PropertyKey): boolean;
|
|
25
|
+
//# sourceMappingURL=unsafePaths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsafePaths.d.ts","sourceRoot":"","sources":["../../src/_common/unsafePaths.ts"],"names":[],"mappings":"AAOA;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAErD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/_common/unsafePaths.ts
|
|
2
|
+
var e = /* @__PURE__ */ new Set([
|
|
3
|
+
"__proto__",
|
|
4
|
+
"constructor",
|
|
5
|
+
"prototype"
|
|
6
|
+
]);
|
|
7
|
+
function t(t) {
|
|
8
|
+
return typeof t == "string" && e.has(t);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { e as UNSAFE_PATH_SEGMENTS, t as isUnsafeKey };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=unsafePaths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsafePaths.js","names":[],"sources":["../../src/_common/unsafePaths.ts"],"sourcesContent":["/**\n * Path segments that must be rejected in any dot-notation traversal or mutation\n * to prevent prototype pollution reads and writes.\n * @internal\n */\nexport const UNSAFE_PATH_SEGMENTS = new Set(['__proto__', 'constructor', 'prototype']);\n\n/**\n * Returns `true` if every dot-notation segment in `key` is safe to use as a\n * plain-object property.\n *\n * @example\n * ```ts\n * isSafePath('user.name') // true\n * isSafePath('__proto__.polluted') // false\n * ```\n */\nexport function isSafePath(key: string): boolean {\n return key.split('.').every((s) => !UNSAFE_PATH_SEGMENTS.has(s));\n}\n\n/**\n * Returns `true` if `key` is one of the dangerous own-property names that can be used to\n * pollute `Object.prototype` (`__proto__`, `constructor`, `prototype`). Use this for plain\n * (non-dotted) property keys — e.g. object keys being copied or reassigned. For dotted paths,\n * use `isSafePath` instead.\n *\n * @example\n * ```ts\n * isUnsafeKey('name') // false\n * isUnsafeKey('__proto__') // true\n * ```\n */\nexport function isUnsafeKey(key: PropertyKey): boolean {\n return typeof key === 'string' && UNSAFE_PATH_SEGMENTS.has(key);\n}\n"],"mappings":";AAKA,IAAa,oBAAuB,IAAI,IAAI;CAAC;CAAa;CAAe;AAAW,CAAC;AA4BrF,SAAgB,EAAY,GAA2B;CACrD,OAAO,OAAO,KAAQ,YAAY,EAAqB,IAAI,CAAG;AAChE"}
|
package/dist/_dev.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dev.cjs","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __ARSENAL_PROD__?: boolean }).__ARSENAL_PROD__;\n\n/** @internal @security Messages may include user data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/arsenal] ${msg}`);\n}\n"],"mappings":"AAAA,IAAM,EAAQ,CAAE,WAA8C,iBAG9D,SAAgB,EAAK,EAAmB,CAClC,GAAO,QAAQ,KAAK,uBAAuB,GAAK,CACtD"}
|
package/dist/_dev.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dev.d.ts","sourceRoot":"","sources":["../src/_dev.ts"],"names":[],"mappings":""}
|
package/dist/_dev.js
ADDED
package/dist/_dev.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dev.js","names":[],"sources":["../src/_dev.ts"],"sourcesContent":["const isDev = !(globalThis as { __ARSENAL_PROD__?: boolean }).__ARSENAL_PROD__;\n\n/** @internal @security Messages may include user data. */\nexport function warn(msg: string): void {\n if (isDev) console.warn(`[@vielzeug/arsenal] ${msg}`);\n}\n"],"mappings":";AAAA,IAAM,IAAQ,CAAE,WAA8C;AAG9D,SAAgB,EAAK,GAAmB;CACtC,AAAI,KAAO,QAAQ,KAAK,uBAAuB,GAAK;AACtD"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../errors.cjs"),t=require("../guards/isString.cjs");function n(n,r=2){if(!Array.isArray(n)&&!t.isString(n))throw new e.ArsenalValidationError(`chunk: argument must be an array or string`);if(r<1)throw new e.ArsenalValidationError(`chunk: size must be at least 1`);return Array.from({length:Math.ceil(n.length/r)},(e,t)=>n.slice(t*r,t*r+r))}exports.chunk=n;
|
|
2
|
+
//# sourceMappingURL=chunk.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk.cjs","names":[],"sources":["../../src/array/chunk.ts"],"sourcesContent":["import { ArsenalValidationError } from '../errors';\nimport { isString } from '../guards/isString';\n\n/**\n * Splits an array or string into chunks of a specified size.\n *\n * @example\n * ```ts\n * chunk([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]\n * chunk('hello', 2) // ['he', 'll', 'o']\n * ```\n *\n * @param input - The input array or string to be chunked.\n * @param size - The size of each chunk (default 2).\n *\n * @returns An array of chunks.\n *\n * @throws {ArsenalValidationError} If the input is not an array or string, or if the chunk size is less than 1.\n */\nexport function chunk(input: string, size?: number): string[];\nexport function chunk<T>(input: T[], size?: number): T[][];\nexport function chunk<T>(input: T[] | string, size = 2): string[] | T[][] {\n if (!Array.isArray(input) && !isString(input))\n throw new ArsenalValidationError('chunk: argument must be an array or string');\n\n if (size < 1) throw new ArsenalValidationError('chunk: size must be at least 1');\n\n return Array.from({ length: Math.ceil(input.length / size) }, (_, i) => input.slice(i * size, i * size + size)) as\n string[] | T[][];\n}\n"],"mappings":"qEAqBA,SAAgB,EAAS,EAAqB,EAAO,EAAqB,CACxE,GAAI,CAAC,MAAM,QAAQ,CAAK,GAAK,CAAC,EAAA,SAAS,CAAK,EAC1C,MAAM,IAAI,EAAA,uBAAuB,4CAA4C,EAE/E,GAAI,EAAO,EAAG,MAAM,IAAI,EAAA,uBAAuB,gCAAgC,EAE/E,OAAO,MAAM,KAAK,CAAE,OAAQ,KAAK,KAAK,EAAM,OAAS,CAAI,CAAE,GAAI,EAAG,IAAM,EAAM,MAAM,EAAI,EAAM,EAAI,EAAO,CAAI,CAAC,CAEhH"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits an array or string into chunks of a specified size.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* chunk([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]
|
|
7
|
+
* chunk('hello', 2) // ['he', 'll', 'o']
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* @param input - The input array or string to be chunked.
|
|
11
|
+
* @param size - The size of each chunk (default 2).
|
|
12
|
+
*
|
|
13
|
+
* @returns An array of chunks.
|
|
14
|
+
*
|
|
15
|
+
* @throws {ArsenalValidationError} If the input is not an array or string, or if the chunk size is less than 1.
|
|
16
|
+
*/
|
|
17
|
+
export declare function chunk(input: string, size?: number): string[];
|
|
18
|
+
export declare function chunk<T>(input: T[], size?: number): T[][];
|
|
19
|
+
//# sourceMappingURL=chunk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk.d.ts","sourceRoot":"","sources":["../../src/array/chunk.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;AAC9D,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ArsenalValidationError as e } from "../errors.js";
|
|
2
|
+
import { isString as t } from "../guards/isString.js";
|
|
3
|
+
//#region src/array/chunk.ts
|
|
4
|
+
function n(n, r = 2) {
|
|
5
|
+
if (!Array.isArray(n) && !t(n)) throw new e("chunk: argument must be an array or string");
|
|
6
|
+
if (r < 1) throw new e("chunk: size must be at least 1");
|
|
7
|
+
return Array.from({ length: Math.ceil(n.length / r) }, (e, t) => n.slice(t * r, t * r + r));
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { n as chunk };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=chunk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk.js","names":[],"sources":["../../src/array/chunk.ts"],"sourcesContent":["import { ArsenalValidationError } from '../errors';\nimport { isString } from '../guards/isString';\n\n/**\n * Splits an array or string into chunks of a specified size.\n *\n * @example\n * ```ts\n * chunk([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]\n * chunk('hello', 2) // ['he', 'll', 'o']\n * ```\n *\n * @param input - The input array or string to be chunked.\n * @param size - The size of each chunk (default 2).\n *\n * @returns An array of chunks.\n *\n * @throws {ArsenalValidationError} If the input is not an array or string, or if the chunk size is less than 1.\n */\nexport function chunk(input: string, size?: number): string[];\nexport function chunk<T>(input: T[], size?: number): T[][];\nexport function chunk<T>(input: T[] | string, size = 2): string[] | T[][] {\n if (!Array.isArray(input) && !isString(input))\n throw new ArsenalValidationError('chunk: argument must be an array or string');\n\n if (size < 1) throw new ArsenalValidationError('chunk: size must be at least 1');\n\n return Array.from({ length: Math.ceil(input.length / size) }, (_, i) => input.slice(i * size, i * size + size)) as\n string[] | T[][];\n}\n"],"mappings":";;;AAqBA,SAAgB,EAAS,GAAqB,IAAO,GAAqB;CACxE,IAAI,CAAC,MAAM,QAAQ,CAAK,KAAK,CAAC,EAAS,CAAK,GAC1C,MAAM,IAAI,EAAuB,4CAA4C;CAE/E,IAAI,IAAO,GAAG,MAAM,IAAI,EAAuB,gCAAgC;CAE/E,OAAO,MAAM,KAAK,EAAE,QAAQ,KAAK,KAAK,EAAM,SAAS,CAAI,EAAE,IAAI,GAAG,MAAM,EAAM,MAAM,IAAI,GAAM,IAAI,IAAO,CAAI,CAAC;AAEhH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact.cjs","names":[],"sources":["../../src/array/compact.ts"],"sourcesContent":["type Falsy = false | '' | 0 | 0n | null | undefined;\n\n/**\n * Creates a new array with all falsy values removed.\n */\nexport function compact<T>(array: T[]): Array<Exclude<T, Falsy>> {\n return array.filter(Boolean) as Array<Exclude<T, Falsy>>;\n}\n"],"mappings":"AAKA,SAAgB,EAAW,EAAsC,CAC/D,OAAO,EAAM,OAAO,OAAO,CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact.d.ts","sourceRoot":"","sources":["../../src/array/compact.ts"],"names":[],"mappings":"AAAA,KAAK,KAAK,GAAG,KAAK,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;AAEpD;;GAEG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAE/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact.js","names":[],"sources":["../../src/array/compact.ts"],"sourcesContent":["type Falsy = false | '' | 0 | 0n | null | undefined;\n\n/**\n * Creates a new array with all falsy values removed.\n */\nexport function compact<T>(array: T[]): Array<Exclude<T, Falsy>> {\n return array.filter(Boolean) as Array<Exclude<T, Falsy>>;\n}\n"],"mappings":";AAKA,SAAgB,EAAW,GAAsC;CAC/D,OAAO,EAAM,OAAO,OAAO;AAC7B"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("../errors.cjs");var t=(t,n)=>{if(t===n)return 0;if(t===void 0)return 1;if(n===void 0)return-1;if(t===null)return n===null?0:-1;if(n===null)return 1;if(typeof t==`string`&&typeof n==`string`)return t.localeCompare(n);if(typeof t==`number`&&typeof n==`number`)return t===n?0:t>n?1:-1;if(t instanceof Date&&n instanceof Date){let e=t.getTime(),r=n.getTime();return e===r?0:e>r?1:-1}throw new e.ArsenalValidationError(`compare: unsupported types "${typeof t}" and "${typeof n}". Supported: number, string, Date, null, undefined.`)};exports.compare=t;
|
|
2
|
+
//# sourceMappingURL=compare.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.cjs","names":[],"sources":["../../src/array/compare.ts"],"sourcesContent":["import { ArsenalValidationError } from '../errors';\n\n/**\n * Compares two values and returns a number suitable for use as a sort comparator.\n *\n * - Numbers and Dates: returns `0`, `1`, or `-1`.\n * - Strings: delegates to `String.prototype.localeCompare`, which may return any integer\n * (not just `0`, `1`, `-1`) depending on locale and engine.\n * - `null` sorts before all non-null values; `undefined` sorts last.\n *\n * @example\n * ```ts\n * compare('a', 'b'); // negative (locale-dependent)\n * compare(1, 2); // -1\n * compare(new Date('2023-01-01'), new Date('2023-01-02')); // -1\n * compare('a', 'a'); // 0\n * compare(1, 1); // 0\n * compare(new Date('2023-01-01'), new Date('2023-01-01')); // 0\n * ```\n *\n * @param a - The first value to compare.\n * @param b - The second value to compare.\n *\n * @returns A negative number, zero, or a positive number.\n *\n * Pass directly as an `Array.sort` comparator:\n * ```ts\n * [3, 1, 2].sort(compare); // [1, 2, 3]\n * ['banana', 'apple', 'cherry'].sort(compare); // ['apple', 'banana', 'cherry']\n * ```\n */\nexport const compare = (a: unknown, b: unknown): number => {\n if (a === b) return 0;\n\n if (a === undefined) return 1;\n\n if (b === undefined) return -1;\n\n if (a === null) return b === null ? 0 : -1;\n\n if (b === null) return 1;\n\n if (typeof a === 'string' && typeof b === 'string') {\n return a.localeCompare(b);\n }\n\n if (typeof a === 'number' && typeof b === 'number') {\n return a === b ? 0 : a > b ? 1 : -1;\n }\n\n if (a instanceof Date && b instanceof Date) {\n const at = a.getTime();\n const bt = b.getTime();\n\n return at === bt ? 0 : at > bt ? 1 : -1;\n }\n\n throw new ArsenalValidationError(\n `compare: unsupported types \"${typeof a}\" and \"${typeof b}\". Supported: number, string, Date, null, undefined.`,\n );\n};\n"],"mappings":"iCA+BA,IAAa,GAAW,EAAY,IAAuB,CACzD,GAAI,IAAM,EAAG,MAAO,GAEpB,GAAI,IAAM,IAAA,GAAW,MAAO,GAE5B,GAAI,IAAM,IAAA,GAAW,MAAO,GAE5B,GAAI,IAAM,KAAM,OAAO,IAAM,KAAO,EAAI,GAExC,GAAI,IAAM,KAAM,MAAO,GAEvB,GAAI,OAAO,GAAM,UAAY,OAAO,GAAM,SACxC,OAAO,EAAE,cAAc,CAAC,EAG1B,GAAI,OAAO,GAAM,UAAY,OAAO,GAAM,SACxC,OAAO,IAAM,EAAI,EAAI,EAAI,EAAI,EAAI,GAGnC,GAAI,aAAa,MAAQ,aAAa,KAAM,CAC1C,IAAM,EAAK,EAAE,QAAQ,EACf,EAAK,EAAE,QAAQ,EAErB,OAAO,IAAO,EAAK,EAAI,EAAK,EAAK,EAAI,EACvC,CAEA,MAAM,IAAI,EAAA,uBACR,+BAA+B,OAAO,EAAE,SAAS,OAAO,EAAE,qDAC5D,CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares two values and returns a number suitable for use as a sort comparator.
|
|
3
|
+
*
|
|
4
|
+
* - Numbers and Dates: returns `0`, `1`, or `-1`.
|
|
5
|
+
* - Strings: delegates to `String.prototype.localeCompare`, which may return any integer
|
|
6
|
+
* (not just `0`, `1`, `-1`) depending on locale and engine.
|
|
7
|
+
* - `null` sorts before all non-null values; `undefined` sorts last.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* compare('a', 'b'); // negative (locale-dependent)
|
|
12
|
+
* compare(1, 2); // -1
|
|
13
|
+
* compare(new Date('2023-01-01'), new Date('2023-01-02')); // -1
|
|
14
|
+
* compare('a', 'a'); // 0
|
|
15
|
+
* compare(1, 1); // 0
|
|
16
|
+
* compare(new Date('2023-01-01'), new Date('2023-01-01')); // 0
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param a - The first value to compare.
|
|
20
|
+
* @param b - The second value to compare.
|
|
21
|
+
*
|
|
22
|
+
* @returns A negative number, zero, or a positive number.
|
|
23
|
+
*
|
|
24
|
+
* Pass directly as an `Array.sort` comparator:
|
|
25
|
+
* ```ts
|
|
26
|
+
* [3, 1, 2].sort(compare); // [1, 2, 3]
|
|
27
|
+
* ['banana', 'apple', 'cherry'].sort(compare); // ['apple', 'banana', 'cherry']
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const compare: (a: unknown, b: unknown) => number;
|
|
31
|
+
//# sourceMappingURL=compare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../src/array/compare.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,OAAO,GAAI,GAAG,OAAO,EAAE,GAAG,OAAO,KAAG,MA6BhD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ArsenalValidationError as e } from "../errors.js";
|
|
2
|
+
//#region src/array/compare.ts
|
|
3
|
+
var t = (t, n) => {
|
|
4
|
+
if (t === n) return 0;
|
|
5
|
+
if (t === void 0) return 1;
|
|
6
|
+
if (n === void 0) return -1;
|
|
7
|
+
if (t === null) return n === null ? 0 : -1;
|
|
8
|
+
if (n === null) return 1;
|
|
9
|
+
if (typeof t == "string" && typeof n == "string") return t.localeCompare(n);
|
|
10
|
+
if (typeof t == "number" && typeof n == "number") return t === n ? 0 : t > n ? 1 : -1;
|
|
11
|
+
if (t instanceof Date && n instanceof Date) {
|
|
12
|
+
let e = t.getTime(), r = n.getTime();
|
|
13
|
+
return e === r ? 0 : e > r ? 1 : -1;
|
|
14
|
+
}
|
|
15
|
+
throw new e(`compare: unsupported types "${typeof t}" and "${typeof n}". Supported: number, string, Date, null, undefined.`);
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { t as compare };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=compare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.js","names":[],"sources":["../../src/array/compare.ts"],"sourcesContent":["import { ArsenalValidationError } from '../errors';\n\n/**\n * Compares two values and returns a number suitable for use as a sort comparator.\n *\n * - Numbers and Dates: returns `0`, `1`, or `-1`.\n * - Strings: delegates to `String.prototype.localeCompare`, which may return any integer\n * (not just `0`, `1`, `-1`) depending on locale and engine.\n * - `null` sorts before all non-null values; `undefined` sorts last.\n *\n * @example\n * ```ts\n * compare('a', 'b'); // negative (locale-dependent)\n * compare(1, 2); // -1\n * compare(new Date('2023-01-01'), new Date('2023-01-02')); // -1\n * compare('a', 'a'); // 0\n * compare(1, 1); // 0\n * compare(new Date('2023-01-01'), new Date('2023-01-01')); // 0\n * ```\n *\n * @param a - The first value to compare.\n * @param b - The second value to compare.\n *\n * @returns A negative number, zero, or a positive number.\n *\n * Pass directly as an `Array.sort` comparator:\n * ```ts\n * [3, 1, 2].sort(compare); // [1, 2, 3]\n * ['banana', 'apple', 'cherry'].sort(compare); // ['apple', 'banana', 'cherry']\n * ```\n */\nexport const compare = (a: unknown, b: unknown): number => {\n if (a === b) return 0;\n\n if (a === undefined) return 1;\n\n if (b === undefined) return -1;\n\n if (a === null) return b === null ? 0 : -1;\n\n if (b === null) return 1;\n\n if (typeof a === 'string' && typeof b === 'string') {\n return a.localeCompare(b);\n }\n\n if (typeof a === 'number' && typeof b === 'number') {\n return a === b ? 0 : a > b ? 1 : -1;\n }\n\n if (a instanceof Date && b instanceof Date) {\n const at = a.getTime();\n const bt = b.getTime();\n\n return at === bt ? 0 : at > bt ? 1 : -1;\n }\n\n throw new ArsenalValidationError(\n `compare: unsupported types \"${typeof a}\" and \"${typeof b}\". Supported: number, string, Date, null, undefined.`,\n );\n};\n"],"mappings":";;AA+BA,IAAa,KAAW,GAAY,MAAuB;CACzD,IAAI,MAAM,GAAG,OAAO;CAEpB,IAAI,MAAM,KAAA,GAAW,OAAO;CAE5B,IAAI,MAAM,KAAA,GAAW,OAAO;CAE5B,IAAI,MAAM,MAAM,OAAO,MAAM,OAAO,IAAI;CAExC,IAAI,MAAM,MAAM,OAAO;CAEvB,IAAI,OAAO,KAAM,YAAY,OAAO,KAAM,UACxC,OAAO,EAAE,cAAc,CAAC;CAG1B,IAAI,OAAO,KAAM,YAAY,OAAO,KAAM,UACxC,OAAO,MAAM,IAAI,IAAI,IAAI,IAAI,IAAI;CAGnC,IAAI,aAAa,QAAQ,aAAa,MAAM;EAC1C,IAAM,IAAK,EAAE,QAAQ,GACf,IAAK,EAAE,QAAQ;EAErB,OAAO,MAAO,IAAK,IAAI,IAAK,IAAK,IAAI;CACvC;CAEA,MAAM,IAAI,EACR,+BAA+B,OAAO,EAAE,SAAS,OAAO,EAAE,qDAC5D;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compareBy.cjs","names":[],"sources":["../../src/array/compareBy.ts"],"sourcesContent":["import { compare } from './compare';\n\n/**\n * Compares two objects based on multiple selectors.\n * The comparison is done in the order of the selectors provided.\n * Each selector can be 'asc' for ascending or 'desc' for descending order.\n *\n * @example\n * ```ts\n * const compareByNameAndAge = compareBy<{ name: string; age: number }>({\n * name: 'asc',\n * age: 'desc',\n * });\n *\n * const a = { name: 'Alice', age: 30 };\n * const b = { name: 'Bob', age: 25 };\n *\n * console.log(compareByNameAndAge(a, b)); // -1 (Alice < Bob)\n * ```\n *\n * @param selectors - An object where keys are properties to compare and values are 'asc' or 'desc'.\n *\n * @returns A comparator for use with `Array.sort` or `sort()`.\n */\nexport const compareBy = <T>(selectors: Partial<Record<keyof T, 'asc' | 'desc'>>) => {\n const entries = Object.entries(selectors) as [keyof T, 'asc' | 'desc'][];\n\n return (a: T, b: T) => {\n for (const [key, direction] of entries) {\n const v1 = a[key];\n const v2 = b[key];\n const dir = direction === 'desc' ? -1 : 1;\n\n const cmp = compare(v1, v2);\n\n if (cmp !== 0) return cmp * dir;\n }\n\n return 0;\n };\n};\n"],"mappings":"iCAwBA,IAAa,EAAgB,GAAwD,CACnF,IAAM,EAAU,OAAO,QAAQ,CAAS,EAExC,OAAQ,EAAM,IAAS,CACrB,IAAK,GAAM,CAAC,EAAK,KAAc,EAAS,CACtC,IAAM,EAAK,EAAE,GACP,EAAK,EAAE,GACP,EAAM,IAAc,OAAS,GAAK,EAElC,EAAM,EAAA,QAAQ,EAAI,CAAE,EAE1B,GAAI,IAAQ,EAAG,OAAO,EAAM,CAC9B,CAEA,MAAO,EACT,CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares two objects based on multiple selectors.
|
|
3
|
+
* The comparison is done in the order of the selectors provided.
|
|
4
|
+
* Each selector can be 'asc' for ascending or 'desc' for descending order.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const compareByNameAndAge = compareBy<{ name: string; age: number }>({
|
|
9
|
+
* name: 'asc',
|
|
10
|
+
* age: 'desc',
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* const a = { name: 'Alice', age: 30 };
|
|
14
|
+
* const b = { name: 'Bob', age: 25 };
|
|
15
|
+
*
|
|
16
|
+
* console.log(compareByNameAndAge(a, b)); // -1 (Alice < Bob)
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param selectors - An object where keys are properties to compare and values are 'asc' or 'desc'.
|
|
20
|
+
*
|
|
21
|
+
* @returns A comparator for use with `Array.sort` or `sort()`.
|
|
22
|
+
*/
|
|
23
|
+
export declare const compareBy: <T>(selectors: Partial<Record<keyof T, "asc" | "desc">>) => (a: T, b: T) => number;
|
|
24
|
+
//# sourceMappingURL=compareBy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compareBy.d.ts","sourceRoot":"","sources":["../../src/array/compareBy.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,WAAW,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC,MAGtE,GAAG,CAAC,EAAE,GAAG,CAAC,WAanB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { compare as e } from "./compare.js";
|
|
2
|
+
//#region src/array/compareBy.ts
|
|
3
|
+
var t = (t) => {
|
|
4
|
+
let n = Object.entries(t);
|
|
5
|
+
return (t, r) => {
|
|
6
|
+
for (let [i, a] of n) {
|
|
7
|
+
let n = t[i], o = r[i], s = a === "desc" ? -1 : 1, c = e(n, o);
|
|
8
|
+
if (c !== 0) return c * s;
|
|
9
|
+
}
|
|
10
|
+
return 0;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { t as compareBy };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=compareBy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compareBy.js","names":[],"sources":["../../src/array/compareBy.ts"],"sourcesContent":["import { compare } from './compare';\n\n/**\n * Compares two objects based on multiple selectors.\n * The comparison is done in the order of the selectors provided.\n * Each selector can be 'asc' for ascending or 'desc' for descending order.\n *\n * @example\n * ```ts\n * const compareByNameAndAge = compareBy<{ name: string; age: number }>({\n * name: 'asc',\n * age: 'desc',\n * });\n *\n * const a = { name: 'Alice', age: 30 };\n * const b = { name: 'Bob', age: 25 };\n *\n * console.log(compareByNameAndAge(a, b)); // -1 (Alice < Bob)\n * ```\n *\n * @param selectors - An object where keys are properties to compare and values are 'asc' or 'desc'.\n *\n * @returns A comparator for use with `Array.sort` or `sort()`.\n */\nexport const compareBy = <T>(selectors: Partial<Record<keyof T, 'asc' | 'desc'>>) => {\n const entries = Object.entries(selectors) as [keyof T, 'asc' | 'desc'][];\n\n return (a: T, b: T) => {\n for (const [key, direction] of entries) {\n const v1 = a[key];\n const v2 = b[key];\n const dir = direction === 'desc' ? -1 : 1;\n\n const cmp = compare(v1, v2);\n\n if (cmp !== 0) return cmp * dir;\n }\n\n return 0;\n };\n};\n"],"mappings":";;AAwBA,IAAa,KAAgB,MAAwD;CACnF,IAAM,IAAU,OAAO,QAAQ,CAAS;CAExC,QAAQ,GAAM,MAAS;EACrB,KAAK,IAAM,CAAC,GAAK,MAAc,GAAS;GACtC,IAAM,IAAK,EAAE,IACP,IAAK,EAAE,IACP,IAAM,MAAc,SAAS,KAAK,GAElC,IAAM,EAAQ,GAAI,CAAE;GAE1B,IAAI,MAAQ,GAAG,OAAO,IAAM;EAC9B;EAEA,OAAO;CACT;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contains.cjs","names":[],"sources":["../../src/array/contains.ts"],"sourcesContent":["import { isEqual } from '../guards/isEqual';\n\n/**\n * Checks if a value is present in an array.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, { a: 1 }, 'hello'];\n * const value = { a: 1 };\n * contains(arr, value) // true;\n * ```\n *\n * @param array - The array to check.\n * @param value - The value to search for.\n *\n * @returns true if the value is present in the array, else false.\n */\n\nexport function contains<T>(array: T[], value: unknown): boolean {\n // Fast path: reference / primitive equality via Array.includes — avoids\n // deep-equal traversal for the common case of searching for a scalar.\n if (value === null || value === undefined || typeof value !== 'object') {\n return array.includes(value as T);\n }\n\n return array.some((val) => isEqual(val, value));\n}\n"],"mappings":"yCAkBA,SAAgB,EAAY,EAAY,EAAyB,CAO/D,OAJ6C,OAAO,GAAU,WAA1D,EACK,EAAM,SAAS,CAAU,EAG3B,EAAM,KAAM,GAAQ,EAAA,QAAQ,EAAK,CAAK,CAAC,CAChD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a value is present in an array.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* const arr = [1, 2, 3, { a: 1 }, 'hello'];
|
|
7
|
+
* const value = { a: 1 };
|
|
8
|
+
* contains(arr, value) // true;
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param array - The array to check.
|
|
12
|
+
* @param value - The value to search for.
|
|
13
|
+
*
|
|
14
|
+
* @returns true if the value is present in the array, else false.
|
|
15
|
+
*/
|
|
16
|
+
export declare function contains<T>(array: T[], value: unknown): boolean;
|
|
17
|
+
//# sourceMappingURL=contains.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contains.d.ts","sourceRoot":"","sources":["../../src/array/contains.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAQ/D"}
|