@vielzeug/toolkit 1.0.11
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/dist/array/aggregate.cjs +2 -0
- package/dist/array/aggregate.cjs.map +1 -0
- package/dist/array/aggregate.js +16 -0
- package/dist/array/aggregate.js.map +1 -0
- package/dist/array/alternate.cjs +2 -0
- package/dist/array/alternate.cjs.map +1 -0
- package/dist/array/alternate.js +9 -0
- package/dist/array/alternate.js.map +1 -0
- package/dist/array/chunk.cjs +2 -0
- package/dist/array/chunk.cjs.map +1 -0
- package/dist/array/chunk.js +22 -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.js +9 -0
- package/dist/array/compact.js.map +1 -0
- package/dist/array/contains.cjs +2 -0
- package/dist/array/contains.cjs.map +1 -0
- package/dist/array/contains.js +11 -0
- package/dist/array/contains.js.map +1 -0
- package/dist/array/every.cjs +2 -0
- package/dist/array/every.cjs.map +1 -0
- package/dist/array/every.js +14 -0
- package/dist/array/every.js.map +1 -0
- package/dist/array/filter.cjs +2 -0
- package/dist/array/filter.cjs.map +1 -0
- package/dist/array/filter.js +14 -0
- package/dist/array/filter.js.map +1 -0
- package/dist/array/find.cjs +2 -0
- package/dist/array/find.cjs.map +1 -0
- package/dist/array/find.js +14 -0
- package/dist/array/find.js.map +1 -0
- package/dist/array/findIndex.cjs +2 -0
- package/dist/array/findIndex.cjs.map +1 -0
- package/dist/array/findIndex.js +14 -0
- package/dist/array/findIndex.js.map +1 -0
- package/dist/array/findLast.cjs +2 -0
- package/dist/array/findLast.cjs.map +1 -0
- package/dist/array/findLast.js +14 -0
- package/dist/array/findLast.js.map +1 -0
- package/dist/array/flatten.cjs +2 -0
- package/dist/array/flatten.cjs.map +1 -0
- package/dist/array/flatten.js +7 -0
- package/dist/array/flatten.js.map +1 -0
- package/dist/array/group.cjs +2 -0
- package/dist/array/group.cjs.map +1 -0
- package/dist/array/group.js +16 -0
- package/dist/array/group.js.map +1 -0
- package/dist/array/list.cjs +2 -0
- package/dist/array/list.cjs.map +1 -0
- package/dist/array/list.js +70 -0
- package/dist/array/list.js.map +1 -0
- package/dist/array/map.cjs +2 -0
- package/dist/array/map.cjs.map +1 -0
- package/dist/array/map.js +18 -0
- package/dist/array/map.js.map +1 -0
- package/dist/array/pick.cjs +2 -0
- package/dist/array/pick.cjs.map +1 -0
- package/dist/array/pick.js +15 -0
- package/dist/array/pick.js.map +1 -0
- package/dist/array/reduce.cjs +2 -0
- package/dist/array/reduce.cjs.map +1 -0
- package/dist/array/reduce.js +16 -0
- package/dist/array/reduce.js.map +1 -0
- package/dist/array/search.cjs +2 -0
- package/dist/array/search.cjs.map +1 -0
- package/dist/array/search.js +14 -0
- package/dist/array/search.js.map +1 -0
- package/dist/array/select.cjs +2 -0
- package/dist/array/select.cjs.map +1 -0
- package/dist/array/select.js +16 -0
- package/dist/array/select.js.map +1 -0
- package/dist/array/shift.cjs +2 -0
- package/dist/array/shift.cjs.map +1 -0
- package/dist/array/shift.js +13 -0
- package/dist/array/shift.js.map +1 -0
- package/dist/array/some.cjs +2 -0
- package/dist/array/some.cjs.map +1 -0
- package/dist/array/some.js +14 -0
- package/dist/array/some.js.map +1 -0
- package/dist/array/sort.cjs +2 -0
- package/dist/array/sort.cjs.map +1 -0
- package/dist/array/sort.js +13 -0
- package/dist/array/sort.js.map +1 -0
- package/dist/array/sortBy.cjs +2 -0
- package/dist/array/sortBy.cjs.map +1 -0
- package/dist/array/sortBy.js +6 -0
- package/dist/array/sortBy.js.map +1 -0
- package/dist/array/substitute.cjs +2 -0
- package/dist/array/substitute.cjs.map +1 -0
- package/dist/array/substitute.js +13 -0
- package/dist/array/substitute.js.map +1 -0
- package/dist/array/uniq.cjs +2 -0
- package/dist/array/uniq.cjs.map +1 -0
- package/dist/array/uniq.js +18 -0
- package/dist/array/uniq.js.map +1 -0
- package/dist/date/expires.cjs +2 -0
- package/dist/date/expires.cjs.map +1 -0
- package/dist/date/expires.js +11 -0
- package/dist/date/expires.js.map +1 -0
- package/dist/date/interval.cjs +2 -0
- package/dist/date/interval.cjs.map +1 -0
- package/dist/date/interval.js +39 -0
- package/dist/date/interval.js.map +1 -0
- package/dist/date/timeDiff.cjs +2 -0
- package/dist/date/timeDiff.cjs.map +1 -0
- package/dist/date/timeDiff.js +29 -0
- package/dist/date/timeDiff.js.map +1 -0
- package/dist/function/assert.cjs +3 -0
- package/dist/function/assert.cjs.map +1 -0
- package/dist/function/assert.js +12 -0
- package/dist/function/assert.js.map +1 -0
- package/dist/function/assertParams.cjs +2 -0
- package/dist/function/assertParams.cjs.map +1 -0
- package/dist/function/assertParams.js +13 -0
- package/dist/function/assertParams.js.map +1 -0
- package/dist/function/attempt.cjs +2 -0
- package/dist/function/attempt.cjs.map +1 -0
- package/dist/function/attempt.js +15 -0
- package/dist/function/attempt.js.map +1 -0
- package/dist/function/compare.cjs +2 -0
- package/dist/function/compare.cjs.map +1 -0
- package/dist/function/compare.js +22 -0
- package/dist/function/compare.js.map +1 -0
- package/dist/function/compareBy.cjs +2 -0
- package/dist/function/compareBy.cjs.map +1 -0
- package/dist/function/compareBy.js +15 -0
- package/dist/function/compareBy.js.map +1 -0
- package/dist/function/compose.cjs +2 -0
- package/dist/function/compose.cjs.map +1 -0
- package/dist/function/compose.js +14 -0
- package/dist/function/compose.js.map +1 -0
- package/dist/function/curry.cjs +2 -0
- package/dist/function/curry.cjs.map +1 -0
- package/dist/function/curry.js +8 -0
- package/dist/function/curry.js.map +1 -0
- package/dist/function/debounce.cjs +2 -0
- package/dist/function/debounce.cjs.map +1 -0
- package/dist/function/debounce.js +10 -0
- package/dist/function/debounce.js.map +1 -0
- package/dist/function/delay.cjs +2 -0
- package/dist/function/delay.cjs.map +1 -0
- package/dist/function/delay.js +8 -0
- package/dist/function/delay.js.map +1 -0
- package/dist/function/fp.cjs +2 -0
- package/dist/function/fp.cjs.map +1 -0
- package/dist/function/fp.js +10 -0
- package/dist/function/fp.js.map +1 -0
- package/dist/function/memo.cjs +2 -0
- package/dist/function/memo.cjs.map +1 -0
- package/dist/function/memo.js +24 -0
- package/dist/function/memo.js.map +1 -0
- package/dist/function/once.cjs +2 -0
- package/dist/function/once.cjs.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.js +11 -0
- package/dist/function/pipe.js.map +1 -0
- package/dist/function/predict.cjs +2 -0
- package/dist/function/predict.cjs.map +1 -0
- package/dist/function/predict.js +13 -0
- package/dist/function/predict.js.map +1 -0
- package/dist/function/proxy.cjs +2 -0
- package/dist/function/proxy.cjs.map +1 -0
- package/dist/function/proxy.js +22 -0
- package/dist/function/proxy.js.map +1 -0
- package/dist/function/retry.cjs +2 -0
- package/dist/function/retry.cjs.map +1 -0
- package/dist/function/retry.js +25 -0
- package/dist/function/retry.js.map +1 -0
- package/dist/function/sleep.cjs +2 -0
- package/dist/function/sleep.cjs.map +1 -0
- package/dist/function/sleep.js +7 -0
- package/dist/function/sleep.js.map +1 -0
- package/dist/function/throttle.cjs +2 -0
- package/dist/function/throttle.cjs.map +1 -0
- package/dist/function/throttle.js +11 -0
- package/dist/function/throttle.js.map +1 -0
- package/dist/function/worker.cjs +14 -0
- package/dist/function/worker.cjs.map +1 -0
- package/dist/function/worker.js +29 -0
- package/dist/function/worker.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2278 -0
- package/dist/index.js +217 -0
- package/dist/index.js.map +1 -0
- package/dist/logit/dist/logit.cjs +2 -0
- package/dist/logit/dist/logit.cjs.map +1 -0
- package/dist/logit/dist/logit.js +178 -0
- package/dist/logit/dist/logit.js.map +1 -0
- package/dist/math/average.cjs +2 -0
- package/dist/math/average.cjs.map +1 -0
- package/dist/math/average.js +19 -0
- package/dist/math/average.js.map +1 -0
- package/dist/math/boil.cjs +2 -0
- package/dist/math/boil.cjs.map +1 -0
- package/dist/math/boil.js +17 -0
- package/dist/math/boil.js.map +1 -0
- package/dist/math/clamp.cjs +2 -0
- package/dist/math/clamp.cjs.map +1 -0
- package/dist/math/clamp.js +7 -0
- package/dist/math/clamp.js.map +1 -0
- package/dist/math/max.cjs +2 -0
- package/dist/math/max.cjs.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.js +11 -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.js +12 -0
- package/dist/math/min.js.map +1 -0
- package/dist/math/range.cjs +2 -0
- package/dist/math/range.cjs.map +1 -0
- package/dist/math/range.js +10 -0
- package/dist/math/range.js.map +1 -0
- package/dist/math/rate.cjs +2 -0
- package/dist/math/rate.cjs.map +1 -0
- package/dist/math/rate.js +9 -0
- package/dist/math/rate.js.map +1 -0
- package/dist/math/round.cjs +2 -0
- package/dist/math/round.cjs.map +1 -0
- package/dist/math/round.js +9 -0
- package/dist/math/round.js.map +1 -0
- package/dist/math/sum.cjs +2 -0
- package/dist/math/sum.cjs.map +1 -0
- package/dist/math/sum.js +22 -0
- package/dist/math/sum.js.map +1 -0
- package/dist/object/clone.cjs +2 -0
- package/dist/object/clone.cjs.map +1 -0
- package/dist/object/clone.js +7 -0
- package/dist/object/clone.js.map +1 -0
- package/dist/object/diff.cjs +2 -0
- package/dist/object/diff.cjs.map +1 -0
- package/dist/object/diff.js +18 -0
- package/dist/object/diff.js.map +1 -0
- package/dist/object/entries.cjs +2 -0
- package/dist/object/entries.cjs.map +1 -0
- package/dist/object/entries.js +9 -0
- package/dist/object/entries.js.map +1 -0
- package/dist/object/keys.cjs +2 -0
- package/dist/object/keys.cjs.map +1 -0
- package/dist/object/keys.js +9 -0
- package/dist/object/keys.js.map +1 -0
- package/dist/object/merge.cjs +2 -0
- package/dist/object/merge.cjs.map +1 -0
- package/dist/object/merge.js +29 -0
- package/dist/object/merge.js.map +1 -0
- package/dist/object/parseJSON.cjs +2 -0
- package/dist/object/parseJSON.cjs.map +1 -0
- package/dist/object/parseJSON.js +19 -0
- package/dist/object/parseJSON.js.map +1 -0
- package/dist/object/path.cjs +2 -0
- package/dist/object/path.cjs.map +1 -0
- package/dist/object/path.js +24 -0
- package/dist/object/path.js.map +1 -0
- package/dist/object/seek.cjs +2 -0
- package/dist/object/seek.cjs.map +1 -0
- package/dist/object/seek.js +11 -0
- package/dist/object/seek.js.map +1 -0
- package/dist/object/values.cjs +2 -0
- package/dist/object/values.cjs.map +1 -0
- package/dist/object/values.js +9 -0
- package/dist/object/values.js.map +1 -0
- package/dist/random/draw.cjs +2 -0
- package/dist/random/draw.cjs.map +1 -0
- package/dist/random/draw.js +11 -0
- package/dist/random/draw.js.map +1 -0
- package/dist/random/random.cjs +2 -0
- package/dist/random/random.cjs.map +1 -0
- package/dist/random/random.js +10 -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.js +15 -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.js +7 -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.js +9 -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.js +8 -0
- package/dist/string/camelCase.js.map +1 -0
- package/dist/string/kebabCase.cjs +2 -0
- package/dist/string/kebabCase.cjs.map +1 -0
- package/dist/string/kebabCase.js +8 -0
- package/dist/string/kebabCase.js.map +1 -0
- package/dist/string/pascalCase.cjs +2 -0
- package/dist/string/pascalCase.cjs.map +1 -0
- package/dist/string/pascalCase.js +8 -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.js +34 -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.js +8 -0
- package/dist/string/snakeCase.js.map +1 -0
- package/dist/string/truncate.cjs +2 -0
- package/dist/string/truncate.cjs.map +1 -0
- package/dist/string/truncate.js +9 -0
- package/dist/string/truncate.js.map +1 -0
- package/dist/typed/ge.cjs +2 -0
- package/dist/typed/ge.cjs.map +1 -0
- package/dist/typed/ge.js +7 -0
- package/dist/typed/ge.js.map +1 -0
- package/dist/typed/gt.cjs +2 -0
- package/dist/typed/gt.cjs.map +1 -0
- package/dist/typed/gt.js +7 -0
- package/dist/typed/gt.js.map +1 -0
- package/dist/typed/is.cjs +2 -0
- package/dist/typed/is.cjs.map +1 -0
- package/dist/typed/is.js +44 -0
- package/dist/typed/is.js.map +1 -0
- package/dist/typed/isArray.cjs +2 -0
- package/dist/typed/isArray.cjs.map +1 -0
- package/dist/typed/isArray.js +9 -0
- package/dist/typed/isArray.js.map +1 -0
- package/dist/typed/isBoolean.cjs +2 -0
- package/dist/typed/isBoolean.cjs.map +1 -0
- package/dist/typed/isBoolean.js +7 -0
- package/dist/typed/isBoolean.js.map +1 -0
- package/dist/typed/isDate.cjs +2 -0
- package/dist/typed/isDate.cjs.map +1 -0
- package/dist/typed/isDate.js +9 -0
- package/dist/typed/isDate.js.map +1 -0
- package/dist/typed/isDefined.cjs +2 -0
- package/dist/typed/isDefined.cjs.map +1 -0
- package/dist/typed/isDefined.js +7 -0
- package/dist/typed/isDefined.js.map +1 -0
- package/dist/typed/isEmpty.cjs +2 -0
- package/dist/typed/isEmpty.cjs.map +1 -0
- package/dist/typed/isEmpty.js +12 -0
- package/dist/typed/isEmpty.js.map +1 -0
- package/dist/typed/isEqual.cjs +2 -0
- package/dist/typed/isEqual.cjs.map +1 -0
- package/dist/typed/isEqual.js +25 -0
- package/dist/typed/isEqual.js.map +1 -0
- package/dist/typed/isEven.cjs +2 -0
- package/dist/typed/isEven.cjs.map +1 -0
- package/dist/typed/isEven.js +7 -0
- package/dist/typed/isEven.js.map +1 -0
- package/dist/typed/isFunction.cjs +2 -0
- package/dist/typed/isFunction.cjs.map +1 -0
- package/dist/typed/isFunction.js +9 -0
- package/dist/typed/isFunction.js.map +1 -0
- package/dist/typed/isMatch.cjs +2 -0
- package/dist/typed/isMatch.cjs.map +1 -0
- package/dist/typed/isMatch.js +19 -0
- package/dist/typed/isMatch.js.map +1 -0
- package/dist/typed/isNegative.cjs +2 -0
- package/dist/typed/isNegative.cjs.map +1 -0
- package/dist/typed/isNegative.js +7 -0
- package/dist/typed/isNegative.js.map +1 -0
- package/dist/typed/isNil.cjs +2 -0
- package/dist/typed/isNil.cjs.map +1 -0
- package/dist/typed/isNil.js +9 -0
- package/dist/typed/isNil.js.map +1 -0
- package/dist/typed/isNumber.cjs +2 -0
- package/dist/typed/isNumber.cjs.map +1 -0
- package/dist/typed/isNumber.js +9 -0
- package/dist/typed/isNumber.js.map +1 -0
- package/dist/typed/isObject.cjs +2 -0
- package/dist/typed/isObject.cjs.map +1 -0
- package/dist/typed/isObject.js +9 -0
- package/dist/typed/isObject.js.map +1 -0
- package/dist/typed/isOdd.cjs +2 -0
- package/dist/typed/isOdd.cjs.map +1 -0
- package/dist/typed/isOdd.js +7 -0
- package/dist/typed/isOdd.js.map +1 -0
- package/dist/typed/isPositive.cjs +2 -0
- package/dist/typed/isPositive.cjs.map +1 -0
- package/dist/typed/isPositive.js +7 -0
- package/dist/typed/isPositive.js.map +1 -0
- package/dist/typed/isPrimitive.cjs +2 -0
- package/dist/typed/isPrimitive.cjs.map +1 -0
- package/dist/typed/isPrimitive.js +10 -0
- package/dist/typed/isPrimitive.js.map +1 -0
- package/dist/typed/isPromise.cjs +2 -0
- package/dist/typed/isPromise.cjs.map +1 -0
- package/dist/typed/isPromise.js +10 -0
- package/dist/typed/isPromise.js.map +1 -0
- package/dist/typed/isRegex.cjs +2 -0
- package/dist/typed/isRegex.cjs.map +1 -0
- package/dist/typed/isRegex.js +7 -0
- package/dist/typed/isRegex.js.map +1 -0
- package/dist/typed/isString.cjs +2 -0
- package/dist/typed/isString.cjs.map +1 -0
- package/dist/typed/isString.js +9 -0
- package/dist/typed/isString.js.map +1 -0
- package/dist/typed/isWithin.cjs +2 -0
- package/dist/typed/isWithin.cjs.map +1 -0
- package/dist/typed/isWithin.js +10 -0
- package/dist/typed/isWithin.js.map +1 -0
- package/dist/typed/isZero.cjs +2 -0
- package/dist/typed/isZero.cjs.map +1 -0
- package/dist/typed/isZero.js +7 -0
- package/dist/typed/isZero.js.map +1 -0
- package/dist/typed/le.cjs +2 -0
- package/dist/typed/le.cjs.map +1 -0
- package/dist/typed/le.js +7 -0
- package/dist/typed/le.js.map +1 -0
- package/dist/typed/lt.cjs +2 -0
- package/dist/typed/lt.cjs.map +1 -0
- package/dist/typed/lt.js +7 -0
- package/dist/typed/lt.js.map +1 -0
- package/dist/typed/typeOf.cjs +2 -0
- package/dist/typed/typeOf.cjs.map +1 -0
- package/dist/typed/typeOf.js +14 -0
- package/dist/typed/typeOf.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reduce.cjs","sources":["../../src/array/reduce.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport { isPromise } from '../typed/isPromise';\nimport type { Result } from '../types';\n\ntype SyncCallback<R, T> = (prev: R, curr: T, index: number, array: T[]) => R;\ntype AsyncCallback<R, T> = (prev: R, curr: T, index: number, array: T[]) => Promise<R>;\ntype Callback<R, T> = SyncCallback<R, T> | AsyncCallback<R, T>;\n\n/**\n * Reduces an array to a single value by applying a callback function\n * to each element in the array, passing the accumulated result and\n * the current element as arguments. Supports both synchronous and\n * asynchronous callback functions.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3];\n * reduce(arr, (acc, curr) => acc + curr, 0); // 10\n * await reduce(arr, async (acc, curr) => acc + curr, 0); // 10\n * ```\n *\n * @param array - The array to reduce.\n * @param callback - The callback function to apply to each element.\n * @param initialValue - The initial value for the accumulator.\n *\n * @returns The reduced value, or a Promise that resolves to the reduced value if the callback is asynchronous.\n *\n * @throws {TypeError} If the first argument is not an array.\n */\nexport function reduce<T, R, C extends Callback<R, T>>(array: T[], callback: C, initialValue: R) {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n const lazy = isPromise(callback);\n\n let acc: R | Promise<R> = lazy ? Promise.resolve(initialValue) : initialValue;\n\n for (let i = 0; i < array.length; i++) {\n if (lazy) {\n acc = (acc as Promise<R>).then((resolvedAcc) => callback(resolvedAcc, array[i], i, array));\n } else {\n acc = callback(acc as R, array[i], i, array);\n }\n }\n\n return acc as Result<C>;\n}\n\nreduce.fn = true;\n"],"names":["reduce","array","callback","initialValue","assert","isArray","IS_ARRAY_ERROR_MSG","lazy","isPromise","acc","i","resolvedAcc"],"mappings":"gMA8BO,SAASA,EAAuCC,EAAYC,EAAaC,EAAiB,CAC/FC,EAAAA,OAAOC,EAAAA,QAAQJ,CAAK,EAAGK,qBAAoB,CAAE,KAAM,CAAE,MAAAL,CAAA,EAAS,KAAM,UAAW,EAE/E,MAAMM,EAAOC,EAAAA,UAAUN,CAAQ,EAE/B,IAAIO,EAAsBF,EAAO,QAAQ,QAAQJ,CAAY,EAAIA,EAEjE,QAASO,EAAI,EAAGA,EAAIT,EAAM,OAAQS,IAC5BH,EACFE,EAAOA,EAAmB,KAAME,GAAgBT,EAASS,EAAaV,EAAMS,CAAC,EAAGA,EAAGT,CAAK,CAAC,EAEzFQ,EAAMP,EAASO,EAAUR,EAAMS,CAAC,EAAGA,EAAGT,CAAK,EAI/C,OAAOQ,CACT,CAEAT,EAAO,GAAK"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { assert as i } from "../function/assert.js";
|
|
2
|
+
import { IS_ARRAY_ERROR_MSG as n, isArray as p } from "../typed/isArray.js";
|
|
3
|
+
import { isPromise as R } from "../typed/isPromise.js";
|
|
4
|
+
function u(e, r, s) {
|
|
5
|
+
i(p(e), n, { args: { array: e }, type: TypeError });
|
|
6
|
+
const m = R(r);
|
|
7
|
+
let t = m ? Promise.resolve(s) : s;
|
|
8
|
+
for (let o = 0; o < e.length; o++)
|
|
9
|
+
m ? t = t.then((f) => r(f, e[o], o, e)) : t = r(t, e[o], o, e);
|
|
10
|
+
return t;
|
|
11
|
+
}
|
|
12
|
+
u.fn = !0;
|
|
13
|
+
export {
|
|
14
|
+
u as reduce
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=reduce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reduce.js","sources":["../../src/array/reduce.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport { isPromise } from '../typed/isPromise';\nimport type { Result } from '../types';\n\ntype SyncCallback<R, T> = (prev: R, curr: T, index: number, array: T[]) => R;\ntype AsyncCallback<R, T> = (prev: R, curr: T, index: number, array: T[]) => Promise<R>;\ntype Callback<R, T> = SyncCallback<R, T> | AsyncCallback<R, T>;\n\n/**\n * Reduces an array to a single value by applying a callback function\n * to each element in the array, passing the accumulated result and\n * the current element as arguments. Supports both synchronous and\n * asynchronous callback functions.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3];\n * reduce(arr, (acc, curr) => acc + curr, 0); // 10\n * await reduce(arr, async (acc, curr) => acc + curr, 0); // 10\n * ```\n *\n * @param array - The array to reduce.\n * @param callback - The callback function to apply to each element.\n * @param initialValue - The initial value for the accumulator.\n *\n * @returns The reduced value, or a Promise that resolves to the reduced value if the callback is asynchronous.\n *\n * @throws {TypeError} If the first argument is not an array.\n */\nexport function reduce<T, R, C extends Callback<R, T>>(array: T[], callback: C, initialValue: R) {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n const lazy = isPromise(callback);\n\n let acc: R | Promise<R> = lazy ? Promise.resolve(initialValue) : initialValue;\n\n for (let i = 0; i < array.length; i++) {\n if (lazy) {\n acc = (acc as Promise<R>).then((resolvedAcc) => callback(resolvedAcc, array[i], i, array));\n } else {\n acc = callback(acc as R, array[i], i, array);\n }\n }\n\n return acc as Result<C>;\n}\n\nreduce.fn = true;\n"],"names":["reduce","array","callback","initialValue","assert","isArray","IS_ARRAY_ERROR_MSG","lazy","isPromise","acc","i","resolvedAcc"],"mappings":";;;AA8BO,SAASA,EAAuCC,GAAYC,GAAaC,GAAiB;AAC/F,EAAAC,EAAOC,EAAQJ,CAAK,GAAGK,GAAoB,EAAE,MAAM,EAAE,OAAAL,EAAA,GAAS,MAAM,WAAW;AAE/E,QAAMM,IAAOC,EAAUN,CAAQ;AAE/B,MAAIO,IAAsBF,IAAO,QAAQ,QAAQJ,CAAY,IAAIA;AAEjE,WAASO,IAAI,GAAGA,IAAIT,EAAM,QAAQS;AAChC,IAAIH,IACFE,IAAOA,EAAmB,KAAK,CAACE,MAAgBT,EAASS,GAAaV,EAAMS,CAAC,GAAGA,GAAGT,CAAK,CAAC,IAEzFQ,IAAMP,EAASO,GAAUR,EAAMS,CAAC,GAAGA,GAAGT,CAAK;AAI/C,SAAOQ;AACT;AAEAT,EAAO,KAAK;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../function/assert.cjs"),c=require("../object/seek.cjs"),t=require("../typed/isString.cjs"),i=require("../typed/isWithin.cjs"),S=require("./filter.cjs");function u(n,r,e=.25){if(s.assert(t.isString(r),t.IS_STRING_ERROR_MSG,{args:{query:r},type:TypeError}),s.assert(i.isWithin(e,0,1),i.IS_WITHIN_ERROR_MSG,{args:{max:1,min:0,tone:e},type:TypeError}),!r)return[];const o=r.toLowerCase();return S.filter(n,a=>c.seek(a,o,e))}exports.search=u;
|
|
2
|
+
//# sourceMappingURL=search.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.cjs","sources":["../../src/array/search.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { seek } from '../object/seek';\nimport { IS_STRING_ERROR_MSG, isString } from '../typed/isString';\nimport { IS_WITHIN_ERROR_MSG, isWithin } from '../typed/isWithin';\nimport { filter } from './filter';\n\n/**\n * Performs a search on an array of objects, checking all values for a match with the search string.\n *\n * @example\n * ```ts\n * const data = [{ name: 'John Doe', age: 25 }, { name: 'Jane Doe', age: 30 }];\n * search(data, 'doe', 0.5); // [{ name: 'John Doe', age: 25 }, { name: 'Jane Doe', age: 30 }]\n * ```\n *\n * @param array - The array of objects to search.\n * @param query - The string to search for.\n * @param [tone=0.25] - Degree of similarity between 0 and 1.\n *\n * @returns The filtered array of objects that match the search string.\n *\n * @throws {Error} If input values are invalid.\n */\nexport function search<T>(array: T[], query: string, tone = 0.25): T[] {\n assert(isString(query), IS_STRING_ERROR_MSG, { args: { query }, type: TypeError });\n assert(isWithin(tone, 0, 1), IS_WITHIN_ERROR_MSG, { args: { max: 1, min: 0, tone }, type: TypeError });\n\n if (!query) return [];\n\n const searchTerm = query.toLowerCase();\n\n return filter(array, (obj) => seek(obj, searchTerm, tone));\n}\n"],"names":["search","array","query","tone","assert","isString","IS_STRING_ERROR_MSG","isWithin","IS_WITHIN_ERROR_MSG","searchTerm","filter","obj","seek"],"mappings":"0PAuBO,SAASA,EAAUC,EAAYC,EAAeC,EAAO,IAAW,CAIrE,GAHAC,EAAAA,OAAOC,EAAAA,SAASH,CAAK,EAAGI,sBAAqB,CAAE,KAAM,CAAE,MAAAJ,CAAA,EAAS,KAAM,UAAW,EACjFE,EAAAA,OAAOG,EAAAA,SAASJ,EAAM,EAAG,CAAC,EAAGK,EAAAA,oBAAqB,CAAE,KAAM,CAAE,IAAK,EAAG,IAAK,EAAG,KAAAL,GAAQ,KAAM,UAAW,EAEjG,CAACD,EAAO,MAAO,CAAA,EAEnB,MAAMO,EAAaP,EAAM,YAAA,EAEzB,OAAOQ,EAAAA,OAAOT,EAAQU,GAAQC,EAAAA,KAAKD,EAAKF,EAAYN,CAAI,CAAC,CAC3D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { assert as t } from "../function/assert.js";
|
|
2
|
+
import { seek as s } from "../object/seek.js";
|
|
3
|
+
import { IS_STRING_ERROR_MSG as p, isString as f } from "../typed/isString.js";
|
|
4
|
+
import { IS_WITHIN_ERROR_MSG as a, isWithin as R } from "../typed/isWithin.js";
|
|
5
|
+
import { filter as n } from "./filter.js";
|
|
6
|
+
function E(i, r, o = 0.25) {
|
|
7
|
+
if (t(f(r), p, { args: { query: r }, type: TypeError }), t(R(o, 0, 1), a, { args: { max: 1, min: 0, tone: o }, type: TypeError }), !r) return [];
|
|
8
|
+
const m = r.toLowerCase();
|
|
9
|
+
return n(i, (e) => s(e, m, o));
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
E as search
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sources":["../../src/array/search.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { seek } from '../object/seek';\nimport { IS_STRING_ERROR_MSG, isString } from '../typed/isString';\nimport { IS_WITHIN_ERROR_MSG, isWithin } from '../typed/isWithin';\nimport { filter } from './filter';\n\n/**\n * Performs a search on an array of objects, checking all values for a match with the search string.\n *\n * @example\n * ```ts\n * const data = [{ name: 'John Doe', age: 25 }, { name: 'Jane Doe', age: 30 }];\n * search(data, 'doe', 0.5); // [{ name: 'John Doe', age: 25 }, { name: 'Jane Doe', age: 30 }]\n * ```\n *\n * @param array - The array of objects to search.\n * @param query - The string to search for.\n * @param [tone=0.25] - Degree of similarity between 0 and 1.\n *\n * @returns The filtered array of objects that match the search string.\n *\n * @throws {Error} If input values are invalid.\n */\nexport function search<T>(array: T[], query: string, tone = 0.25): T[] {\n assert(isString(query), IS_STRING_ERROR_MSG, { args: { query }, type: TypeError });\n assert(isWithin(tone, 0, 1), IS_WITHIN_ERROR_MSG, { args: { max: 1, min: 0, tone }, type: TypeError });\n\n if (!query) return [];\n\n const searchTerm = query.toLowerCase();\n\n return filter(array, (obj) => seek(obj, searchTerm, tone));\n}\n"],"names":["search","array","query","tone","assert","isString","IS_STRING_ERROR_MSG","isWithin","IS_WITHIN_ERROR_MSG","searchTerm","filter","obj","seek"],"mappings":";;;;;AAuBO,SAASA,EAAUC,GAAYC,GAAeC,IAAO,MAAW;AAIrE,MAHAC,EAAOC,EAASH,CAAK,GAAGI,GAAqB,EAAE,MAAM,EAAE,OAAAJ,EAAA,GAAS,MAAM,WAAW,GACjFE,EAAOG,EAASJ,GAAM,GAAG,CAAC,GAAGK,GAAqB,EAAE,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,MAAAL,KAAQ,MAAM,WAAW,GAEjG,CAACD,EAAO,QAAO,CAAA;AAEnB,QAAMO,IAAaP,EAAM,YAAA;AAEzB,SAAOQ,EAAOT,GAAO,CAACU,MAAQC,EAAKD,GAAKF,GAAYN,CAAI,CAAC;AAC3D;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../function/assert.cjs"),r=require("../typed/isArray.cjs"),c=require("../typed/isNil.cjs"),f=require("../typed/isPromise.cjs");function o(s,t,n){l.assert(r.isArray(s),r.IS_ARRAY_ERROR_MSG,{args:{array:s},type:TypeError});const i=[],u=n??(e=>!c.isNil(e));for(let e=0;e<s.length;e++)u(s[e],e,s)&&i.push(t(s[e],e,s));return f.isPromise(t)?Promise.all(i):i}o.fp=!0;exports.select=o;
|
|
2
|
+
//# sourceMappingURL=select.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.cjs","sources":["../../src/array/select.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport { isNil } from '../typed/isNil';\nimport { isPromise } from '../typed/isPromise';\nimport type { CallbackDynamic, Predicate, ResultArray } from '../types';\n\n/**\n * Selects elements from an array based on a callback function and an optional predicate function.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, 4];\n * select(arr, x => x * x, x => x > 2) // [9, 16]\n * await select(arr, async x => x * x, x => x > 2) // [9, 16]\n * ```\n *\n * @param array - The array to select from.\n * @param callback - The function to map the values.\n * @param [predicate] - (optional) The function to filter the values.\n *\n * @returns A new array with the selected values.\n *\n * @throws {TypeError} If the provided array is not an array.\n */\nexport function select<T, R, C extends CallbackDynamic<T, R>>(\n array: T[],\n callback: C,\n predicate?: Predicate<T>,\n): ResultArray<C> {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n const result = [];\n\n const isValid = predicate ?? ((value: T) => !isNil(value));\n\n for (let index = 0; index < array.length; index++) {\n if (isValid(array[index], index, array)) {\n result.push(callback(array[index], index, array));\n }\n }\n\n return (isPromise(callback) ? Promise.all(result) : result) as ResultArray<C>;\n}\n\nselect.fp = true;\n"],"names":["select","array","callback","predicate","assert","isArray","IS_ARRAY_ERROR_MSG","result","isValid","value","isNil","index","isPromise"],"mappings":"gOAwBO,SAASA,EACdC,EACAC,EACAC,EACgB,CAChBC,EAAAA,OAAOC,EAAAA,QAAQJ,CAAK,EAAGK,qBAAoB,CAAE,KAAM,CAAE,MAAAL,CAAA,EAAS,KAAM,UAAW,EAE/E,MAAMM,EAAS,CAAA,EAETC,EAAUL,IAAeM,GAAa,CAACC,EAAAA,MAAMD,CAAK,GAExD,QAASE,EAAQ,EAAGA,EAAQV,EAAM,OAAQU,IACpCH,EAAQP,EAAMU,CAAK,EAAGA,EAAOV,CAAK,GACpCM,EAAO,KAAKL,EAASD,EAAMU,CAAK,EAAGA,EAAOV,CAAK,CAAC,EAIpD,OAAQW,EAAAA,UAAUV,CAAQ,EAAI,QAAQ,IAAIK,CAAM,EAAIA,CACtD,CAEAP,EAAO,GAAK"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { assert as m } from "../function/assert.js";
|
|
2
|
+
import { IS_ARRAY_ERROR_MSG as p, isArray as f } from "../typed/isArray.js";
|
|
3
|
+
import { isNil as n } from "../typed/isNil.js";
|
|
4
|
+
import { isPromise as l } from "../typed/isPromise.js";
|
|
5
|
+
function u(t, e, s) {
|
|
6
|
+
m(f(t), p, { args: { array: t }, type: TypeError });
|
|
7
|
+
const i = [], r = s ?? ((o) => !n(o));
|
|
8
|
+
for (let o = 0; o < t.length; o++)
|
|
9
|
+
r(t[o], o, t) && i.push(e(t[o], o, t));
|
|
10
|
+
return l(e) ? Promise.all(i) : i;
|
|
11
|
+
}
|
|
12
|
+
u.fp = !0;
|
|
13
|
+
export {
|
|
14
|
+
u as select
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","sources":["../../src/array/select.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport { isNil } from '../typed/isNil';\nimport { isPromise } from '../typed/isPromise';\nimport type { CallbackDynamic, Predicate, ResultArray } from '../types';\n\n/**\n * Selects elements from an array based on a callback function and an optional predicate function.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, 4];\n * select(arr, x => x * x, x => x > 2) // [9, 16]\n * await select(arr, async x => x * x, x => x > 2) // [9, 16]\n * ```\n *\n * @param array - The array to select from.\n * @param callback - The function to map the values.\n * @param [predicate] - (optional) The function to filter the values.\n *\n * @returns A new array with the selected values.\n *\n * @throws {TypeError} If the provided array is not an array.\n */\nexport function select<T, R, C extends CallbackDynamic<T, R>>(\n array: T[],\n callback: C,\n predicate?: Predicate<T>,\n): ResultArray<C> {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n const result = [];\n\n const isValid = predicate ?? ((value: T) => !isNil(value));\n\n for (let index = 0; index < array.length; index++) {\n if (isValid(array[index], index, array)) {\n result.push(callback(array[index], index, array));\n }\n }\n\n return (isPromise(callback) ? Promise.all(result) : result) as ResultArray<C>;\n}\n\nselect.fp = true;\n"],"names":["select","array","callback","predicate","assert","isArray","IS_ARRAY_ERROR_MSG","result","isValid","value","isNil","index","isPromise"],"mappings":";;;;AAwBO,SAASA,EACdC,GACAC,GACAC,GACgB;AAChB,EAAAC,EAAOC,EAAQJ,CAAK,GAAGK,GAAoB,EAAE,MAAM,EAAE,OAAAL,EAAA,GAAS,MAAM,WAAW;AAE/E,QAAMM,IAAS,CAAA,GAETC,IAAUL,MAAc,CAACM,MAAa,CAACC,EAAMD,CAAK;AAExD,WAASE,IAAQ,GAAGA,IAAQV,EAAM,QAAQU;AACxC,IAAIH,EAAQP,EAAMU,CAAK,GAAGA,GAAOV,CAAK,KACpCM,EAAO,KAAKL,EAASD,EAAMU,CAAK,GAAGA,GAAOV,CAAK,CAAC;AAIpD,SAAQW,EAAUV,CAAQ,IAAI,QAAQ,IAAIK,CAAM,IAAIA;AACtD;AAEAP,EAAO,KAAK;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../function/assert.cjs"),n=require("../typed/isArray.cjs"),u=require("../typed/isNumber.cjs");function l(e,t,c=!1){if(i.assert(n.isArray(e),n.IS_ARRAY_ERROR_MSG,{args:{array:e},type:TypeError}),i.assert(u.isNumber(t),u.IS_NUMBER_ERROR_MSG,{args:{positions:t},type:TypeError}),e.length===0)return e;const s=(t%e.length+e.length)%e.length,r=e.slice(s);return c?[...r,...e.slice(0,s)]:r}l.fp=!0;exports.shift=l;
|
|
2
|
+
//# sourceMappingURL=shift.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shift.cjs","sources":["../../src/array/shift.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport { IS_NUMBER_ERROR_MSG, isNumber } from '../typed/isNumber';\n\n/**\n * Shifts the elements of an array to the left by a specified number of positions.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, 4, 5];\n * shift(arr, 2); // [3, 4, 5]\n * shift(arr, 2, true); // [3, 4, 5, 1, 2]\n * ```\n * @param array - The array to shift.\n * @param positions - The number of positions to shift the array.\n * @param rotate - If `true`, the elements that are shifted out will be added to the end of the array.\n *\n * @returns A new array with the elements shifted.\n *\n * @throws {TypeError} If the first argument is not an array, or the second argument is not a number.\n */\nexport function shift<T>(array: T[], positions: number, rotate = false): T[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n assert(isNumber(positions), IS_NUMBER_ERROR_MSG, { args: { positions }, type: TypeError });\n\n if (array.length === 0) return array;\n\n const normalizedPos = ((positions % array.length) + array.length) % array.length;\n const shifted = array.slice(normalizedPos);\n\n return rotate ? [...shifted, ...array.slice(0, normalizedPos)] : shifted;\n}\n\nshift.fp = true;\n"],"names":["shift","array","positions","rotate","assert","isArray","IS_ARRAY_ERROR_MSG","isNumber","IS_NUMBER_ERROR_MSG","normalizedPos","shifted"],"mappings":"+LAqBO,SAASA,EAASC,EAAYC,EAAmBC,EAAS,GAAY,CAI3E,GAHAC,EAAAA,OAAOC,EAAAA,QAAQJ,CAAK,EAAGK,qBAAoB,CAAE,KAAM,CAAE,MAAAL,CAAA,EAAS,KAAM,UAAW,EAC/EG,EAAAA,OAAOG,EAAAA,SAASL,CAAS,EAAGM,sBAAqB,CAAE,KAAM,CAAE,UAAAN,CAAA,EAAa,KAAM,UAAW,EAErFD,EAAM,SAAW,EAAG,OAAOA,EAE/B,MAAMQ,GAAkBP,EAAYD,EAAM,OAAUA,EAAM,QAAUA,EAAM,OACpES,EAAUT,EAAM,MAAMQ,CAAa,EAEzC,OAAON,EAAS,CAAC,GAAGO,EAAS,GAAGT,EAAM,MAAM,EAAGQ,CAAa,CAAC,EAAIC,CACnE,CAEAV,EAAM,GAAK"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { assert as f } from "../function/assert.js";
|
|
2
|
+
import { IS_ARRAY_ERROR_MSG as r, isArray as R } from "../typed/isArray.js";
|
|
3
|
+
import { IS_NUMBER_ERROR_MSG as i, isNumber as l } from "../typed/isNumber.js";
|
|
4
|
+
function m(e, t, n = !1) {
|
|
5
|
+
if (f(R(e), r, { args: { array: e }, type: TypeError }), f(l(t), i, { args: { positions: t }, type: TypeError }), e.length === 0) return e;
|
|
6
|
+
const o = (t % e.length + e.length) % e.length, s = e.slice(o);
|
|
7
|
+
return n ? [...s, ...e.slice(0, o)] : s;
|
|
8
|
+
}
|
|
9
|
+
m.fp = !0;
|
|
10
|
+
export {
|
|
11
|
+
m as shift
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=shift.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shift.js","sources":["../../src/array/shift.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport { IS_NUMBER_ERROR_MSG, isNumber } from '../typed/isNumber';\n\n/**\n * Shifts the elements of an array to the left by a specified number of positions.\n *\n * @example\n * ```ts\n * const arr = [1, 2, 3, 4, 5];\n * shift(arr, 2); // [3, 4, 5]\n * shift(arr, 2, true); // [3, 4, 5, 1, 2]\n * ```\n * @param array - The array to shift.\n * @param positions - The number of positions to shift the array.\n * @param rotate - If `true`, the elements that are shifted out will be added to the end of the array.\n *\n * @returns A new array with the elements shifted.\n *\n * @throws {TypeError} If the first argument is not an array, or the second argument is not a number.\n */\nexport function shift<T>(array: T[], positions: number, rotate = false): T[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n assert(isNumber(positions), IS_NUMBER_ERROR_MSG, { args: { positions }, type: TypeError });\n\n if (array.length === 0) return array;\n\n const normalizedPos = ((positions % array.length) + array.length) % array.length;\n const shifted = array.slice(normalizedPos);\n\n return rotate ? [...shifted, ...array.slice(0, normalizedPos)] : shifted;\n}\n\nshift.fp = true;\n"],"names":["shift","array","positions","rotate","assert","isArray","IS_ARRAY_ERROR_MSG","isNumber","IS_NUMBER_ERROR_MSG","normalizedPos","shifted"],"mappings":";;;AAqBO,SAASA,EAASC,GAAYC,GAAmBC,IAAS,IAAY;AAI3E,MAHAC,EAAOC,EAAQJ,CAAK,GAAGK,GAAoB,EAAE,MAAM,EAAE,OAAAL,EAAA,GAAS,MAAM,WAAW,GAC/EG,EAAOG,EAASL,CAAS,GAAGM,GAAqB,EAAE,MAAM,EAAE,WAAAN,EAAA,GAAa,MAAM,WAAW,GAErFD,EAAM,WAAW,EAAG,QAAOA;AAE/B,QAAMQ,KAAkBP,IAAYD,EAAM,SAAUA,EAAM,UAAUA,EAAM,QACpES,IAAUT,EAAM,MAAMQ,CAAa;AAEzC,SAAON,IAAS,CAAC,GAAGO,GAAS,GAAGT,EAAM,MAAM,GAAGQ,CAAa,CAAC,IAAIC;AACnE;AAEAV,EAAM,KAAK;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../function/assert.cjs"),r=require("../typed/isArray.cjs");function s(e,o){i.assert(r.isArray(e),r.IS_ARRAY_ERROR_MSG,{args:{array:e},type:TypeError});for(let t=0;t<e.length;t++)if(o(e[t],t,e))return!0;return!1}s.fp=!0;exports.some=s;
|
|
2
|
+
//# sourceMappingURL=some.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"some.cjs","sources":["../../src/array/some.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport type { Predicate } from '../types';\n\n/**\n * Checks if at least one element in the array satisfies the provided predicate function.\n *\n * @example\n * ```ts\n * some([1, 2, 3], (n) => n === 2) // true\n * some([1, 2, 3], (n) => n === 4) // false\n * ```\n *\n * @param array - The array to be checked.\n * @param predicate - The function to test each element of the array.\n *\n * @returns `true` if at least one element satisfies the predicate, otherwise `false`.\n *\n * @throws {TypeError} If the provided array is not an array.\n */\nexport function some<T>(array: T[], predicate: Predicate<T>) {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n for (let index = 0; index < array.length; index++) {\n if (predicate(array[index], index, array)) {\n return true;\n }\n }\n\n return false;\n}\n\nsome.fp = true;\n"],"names":["some","array","predicate","assert","isArray","IS_ARRAY_ERROR_MSG","index"],"mappings":"4JAoBO,SAASA,EAAQC,EAAYC,EAAyB,CAC3DC,EAAAA,OAAOC,EAAAA,QAAQH,CAAK,EAAGI,qBAAoB,CAAE,KAAM,CAAE,MAAAJ,CAAA,EAAS,KAAM,UAAW,EAE/E,QAASK,EAAQ,EAAGA,EAAQL,EAAM,OAAQK,IACxC,GAAIJ,EAAUD,EAAMK,CAAK,EAAGA,EAAOL,CAAK,EACtC,MAAO,GAIX,MAAO,EACT,CAEAD,EAAK,GAAK"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { assert as o } from "../function/assert.js";
|
|
2
|
+
import { IS_ARRAY_ERROR_MSG as f, isArray as i } from "../typed/isArray.js";
|
|
3
|
+
function n(e, r) {
|
|
4
|
+
o(i(e), f, { args: { array: e }, type: TypeError });
|
|
5
|
+
for (let t = 0; t < e.length; t++)
|
|
6
|
+
if (r(e[t], t, e))
|
|
7
|
+
return !0;
|
|
8
|
+
return !1;
|
|
9
|
+
}
|
|
10
|
+
n.fp = !0;
|
|
11
|
+
export {
|
|
12
|
+
n as some
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=some.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"some.js","sources":["../../src/array/some.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport type { Predicate } from '../types';\n\n/**\n * Checks if at least one element in the array satisfies the provided predicate function.\n *\n * @example\n * ```ts\n * some([1, 2, 3], (n) => n === 2) // true\n * some([1, 2, 3], (n) => n === 4) // false\n * ```\n *\n * @param array - The array to be checked.\n * @param predicate - The function to test each element of the array.\n *\n * @returns `true` if at least one element satisfies the predicate, otherwise `false`.\n *\n * @throws {TypeError} If the provided array is not an array.\n */\nexport function some<T>(array: T[], predicate: Predicate<T>) {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n for (let index = 0; index < array.length; index++) {\n if (predicate(array[index], index, array)) {\n return true;\n }\n }\n\n return false;\n}\n\nsome.fp = true;\n"],"names":["some","array","predicate","assert","isArray","IS_ARRAY_ERROR_MSG","index"],"mappings":";;AAoBO,SAASA,EAAQC,GAAYC,GAAyB;AAC3D,EAAAC,EAAOC,EAAQH,CAAK,GAAGI,GAAoB,EAAE,MAAM,EAAE,OAAAJ,EAAA,GAAS,MAAM,WAAW;AAE/E,WAASK,IAAQ,GAAGA,IAAQL,EAAM,QAAQK;AACxC,QAAIJ,EAAUD,EAAMK,CAAK,GAAGA,GAAOL,CAAK;AACtC,aAAO;AAIX,SAAO;AACT;AAEAD,EAAK,KAAK;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../function/assert.cjs"),p=require("../function/compare.cjs"),t=require("../typed/isArray.cjs"),s=(r,e,o=!1)=>{n.assert(t.isArray(r),t.IS_ARRAY_ERROR_MSG,{args:{array:r},type:TypeError});const i=o?-1:1;return[...r].sort((u,c)=>p.compare(e(u),e(c))*i)};s.fp=!0;exports.sort=s;
|
|
2
|
+
//# sourceMappingURL=sort.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort.cjs","sources":["../../src/array/sort.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { compare } from '../function/compare';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\n\n/**\n * Sorts an array of objects by a specific key in ascending order.\n *\n * @example\n * ```ts\n * const data = [{ a: 2 }, { a: 3 }, { a: 1 }];\n * sort(data, (item) => item.a); // [{ a: 1 }, { a: 2 }, { a: 3 }]\n * ```\n *\n * @param array - The array of objects to sort.\n * @param selector - A function that extracts the key to sort by.\n * @param desc - A boolean indicating whether to sort in descending order (default: false).\n *\n * @returns A new array sorted by the specified key.\n *\n * @throws {TypeError} If the provided array is not an array.\n */\n// biome-ignore lint/suspicious/noExplicitAny: -\nexport const sort = <T>(array: T[], selector: (item: T) => any, desc = false) => {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n const multiplier = desc ? -1 : 1;\n\n return [...array].sort((a, b) => compare(selector(a), selector(b)) * multiplier);\n};\n\nsort.fp = true;\n"],"names":["sort","array","selector","desc","assert","isArray","IS_ARRAY_ERROR_MSG","multiplier","a","b","compare"],"mappings":"iMAsBaA,EAAO,CAAIC,EAAYC,EAA4BC,EAAO,KAAU,CAC/EC,EAAAA,OAAOC,EAAAA,QAAQJ,CAAK,EAAGK,qBAAoB,CAAE,KAAM,CAAE,MAAAL,CAAA,EAAS,KAAM,UAAW,EAE/E,MAAMM,EAAaJ,EAAO,GAAK,EAE/B,MAAO,CAAC,GAAGF,CAAK,EAAE,KAAK,CAACO,EAAGC,IAAMC,EAAAA,QAAQR,EAASM,CAAC,EAAGN,EAASO,CAAC,CAAC,EAAIF,CAAU,CACjF,EAEAP,EAAK,GAAK"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { assert as e } from "../function/assert.js";
|
|
2
|
+
import { compare as i } from "../function/compare.js";
|
|
3
|
+
import { IS_ARRAY_ERROR_MSG as f, isArray as R } from "../typed/isArray.js";
|
|
4
|
+
const n = (r, o, t = !1) => {
|
|
5
|
+
e(R(r), f, { args: { array: r }, type: TypeError });
|
|
6
|
+
const p = t ? -1 : 1;
|
|
7
|
+
return [...r].sort((m, s) => i(o(m), o(s)) * p);
|
|
8
|
+
};
|
|
9
|
+
n.fp = !0;
|
|
10
|
+
export {
|
|
11
|
+
n as sort
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=sort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort.js","sources":["../../src/array/sort.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { compare } from '../function/compare';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\n\n/**\n * Sorts an array of objects by a specific key in ascending order.\n *\n * @example\n * ```ts\n * const data = [{ a: 2 }, { a: 3 }, { a: 1 }];\n * sort(data, (item) => item.a); // [{ a: 1 }, { a: 2 }, { a: 3 }]\n * ```\n *\n * @param array - The array of objects to sort.\n * @param selector - A function that extracts the key to sort by.\n * @param desc - A boolean indicating whether to sort in descending order (default: false).\n *\n * @returns A new array sorted by the specified key.\n *\n * @throws {TypeError} If the provided array is not an array.\n */\n// biome-ignore lint/suspicious/noExplicitAny: -\nexport const sort = <T>(array: T[], selector: (item: T) => any, desc = false) => {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n const multiplier = desc ? -1 : 1;\n\n return [...array].sort((a, b) => compare(selector(a), selector(b)) * multiplier);\n};\n\nsort.fp = true;\n"],"names":["sort","array","selector","desc","assert","isArray","IS_ARRAY_ERROR_MSG","multiplier","a","b","compare"],"mappings":";;;AAsBO,MAAMA,IAAO,CAAIC,GAAYC,GAA4BC,IAAO,OAAU;AAC/E,EAAAC,EAAOC,EAAQJ,CAAK,GAAGK,GAAoB,EAAE,MAAM,EAAE,OAAAL,EAAA,GAAS,MAAM,WAAW;AAE/E,QAAMM,IAAaJ,IAAO,KAAK;AAE/B,SAAO,CAAC,GAAGF,CAAK,EAAE,KAAK,CAACO,GAAGC,MAAMC,EAAQR,EAASM,CAAC,GAAGN,EAASO,CAAC,CAAC,IAAIF,CAAU;AACjF;AAEAP,EAAK,KAAK;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortBy.cjs","sources":["../../src/array/sortBy.ts"],"sourcesContent":["import { compareBy } from '../function/compareBy';\n\n/**\n * Sorts an array of objects based on multiple selectors.\n *\n * @example\n * ```ts\n * const data = [\n * { name: 'Alice', age: 30 },\n * { name: 'Bob', age: 25 },\n * { name: 'Charlie', age: 35 },\n * { name: 'Alice', age: 25 },\n * { name: 'Bob', age: 30 },\n * { name: 'Charlie', age: 30 },\n * ].sortBy(data, { name: 'asc', age: 'desc' }); // [ { name: 'Alice', age: 30 }, { name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }, { name: 'Bob', age: 25 }, { name: 'Charlie', age: 35 }, { name: 'Charlie', age: 30 } ]\n * ```\n *\n * @param array - The array to sort.\n * @param selectors - An object where keys are the properties to sort by and values are 'asc' or 'desc'.\n * @returns A new sorted array.\n */\nexport const sortBy = <T>(array: T[], selectors: Partial<Record<keyof T, 'asc' | 'desc'>>) => {\n return [...array].sort(compareBy(selectors));\n};\n"],"names":["sortBy","array","selectors","compareBy"],"mappings":"6HAqBaA,EAAS,CAAIC,EAAYC,IAC7B,CAAC,GAAGD,CAAK,EAAE,KAAKE,EAAAA,UAAUD,CAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortBy.js","sources":["../../src/array/sortBy.ts"],"sourcesContent":["import { compareBy } from '../function/compareBy';\n\n/**\n * Sorts an array of objects based on multiple selectors.\n *\n * @example\n * ```ts\n * const data = [\n * { name: 'Alice', age: 30 },\n * { name: 'Bob', age: 25 },\n * { name: 'Charlie', age: 35 },\n * { name: 'Alice', age: 25 },\n * { name: 'Bob', age: 30 },\n * { name: 'Charlie', age: 30 },\n * ].sortBy(data, { name: 'asc', age: 'desc' }); // [ { name: 'Alice', age: 30 }, { name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }, { name: 'Bob', age: 25 }, { name: 'Charlie', age: 35 }, { name: 'Charlie', age: 30 } ]\n * ```\n *\n * @param array - The array to sort.\n * @param selectors - An object where keys are the properties to sort by and values are 'asc' or 'desc'.\n * @returns A new sorted array.\n */\nexport const sortBy = <T>(array: T[], selectors: Partial<Record<keyof T, 'asc' | 'desc'>>) => {\n return [...array].sort(compareBy(selectors));\n};\n"],"names":["sortBy","array","selectors","compareBy"],"mappings":";AAqBO,MAAMA,IAAS,CAAIC,GAAYC,MAC7B,CAAC,GAAGD,CAAK,EAAE,KAAKE,EAAUD,CAAS,CAAC;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../function/assert.cjs"),s=require("../typed/isArray.cjs"),o=require("./findIndex.cjs");function i(e,n,r){u.assert(s.isArray(e),s.IS_ARRAY_ERROR_MSG,{args:{array:e},type:TypeError});const t=o.findIndex(e,n);return t===-1?e:[...e.slice(0,t),r,...e.slice(t+1)]}i.fn=!0;exports.substitute=i;
|
|
2
|
+
//# sourceMappingURL=substitute.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"substitute.cjs","sources":["../../src/array/substitute.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport type { Predicate } from '../types';\nimport { findIndex } from './findIndex';\n\n/**\n * Replaces the first element in an array that satisfies the provided predicate function with a new value.\n *\n * @example\n * ```ts\n * substitute([1, 2, 3], (n) => n === 2, 4) // [1, 4, 3]\n * ```\n *\n * @param array - The array to search.\n * @param predicate - A function to test each element of the array.\n * @param value - The new value to replace the found element.\n *\n * @return A new array with the replaced value.\n *\n * @throws {TypeError} If the first argument is not an array.\n */\nexport function substitute<T>(array: T[], predicate: Predicate<T>, value: T): T[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n const index = findIndex(array, predicate);\n\n if (index === -1) return array;\n\n return [...array.slice(0, index), value, ...array.slice(index + 1)];\n}\n\nsubstitute.fn = true;\n"],"names":["substitute","array","predicate","value","assert","isArray","IS_ARRAY_ERROR_MSG","index","findIndex"],"mappings":"yLAqBO,SAASA,EAAcC,EAAYC,EAAyBC,EAAe,CAChFC,EAAAA,OAAOC,EAAAA,QAAQJ,CAAK,EAAGK,qBAAoB,CAAE,KAAM,CAAE,MAAAL,CAAA,EAAS,KAAM,UAAW,EAE/E,MAAMM,EAAQC,EAAAA,UAAUP,EAAOC,CAAS,EAExC,OAAIK,IAAU,GAAWN,EAElB,CAAC,GAAGA,EAAM,MAAM,EAAGM,CAAK,EAAGJ,EAAO,GAAGF,EAAM,MAAMM,EAAQ,CAAC,CAAC,CACpE,CAEAP,EAAW,GAAK"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { assert as n } from "../function/assert.js";
|
|
2
|
+
import { IS_ARRAY_ERROR_MSG as r, isArray as s } from "../typed/isArray.js";
|
|
3
|
+
import { findIndex as f } from "./findIndex.js";
|
|
4
|
+
function m(t, i, o) {
|
|
5
|
+
n(s(t), r, { args: { array: t }, type: TypeError });
|
|
6
|
+
const e = f(t, i);
|
|
7
|
+
return e === -1 ? t : [...t.slice(0, e), o, ...t.slice(e + 1)];
|
|
8
|
+
}
|
|
9
|
+
m.fn = !0;
|
|
10
|
+
export {
|
|
11
|
+
m as substitute
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=substitute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"substitute.js","sources":["../../src/array/substitute.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport type { Predicate } from '../types';\nimport { findIndex } from './findIndex';\n\n/**\n * Replaces the first element in an array that satisfies the provided predicate function with a new value.\n *\n * @example\n * ```ts\n * substitute([1, 2, 3], (n) => n === 2, 4) // [1, 4, 3]\n * ```\n *\n * @param array - The array to search.\n * @param predicate - A function to test each element of the array.\n * @param value - The new value to replace the found element.\n *\n * @return A new array with the replaced value.\n *\n * @throws {TypeError} If the first argument is not an array.\n */\nexport function substitute<T>(array: T[], predicate: Predicate<T>, value: T): T[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { args: { array }, type: TypeError });\n\n const index = findIndex(array, predicate);\n\n if (index === -1) return array;\n\n return [...array.slice(0, index), value, ...array.slice(index + 1)];\n}\n\nsubstitute.fn = true;\n"],"names":["substitute","array","predicate","value","assert","isArray","IS_ARRAY_ERROR_MSG","index","findIndex"],"mappings":";;;AAqBO,SAASA,EAAcC,GAAYC,GAAyBC,GAAe;AAChF,EAAAC,EAAOC,EAAQJ,CAAK,GAAGK,GAAoB,EAAE,MAAM,EAAE,OAAAL,EAAA,GAAS,MAAM,WAAW;AAE/E,QAAMM,IAAQC,EAAUP,GAAOC,CAAS;AAExC,SAAIK,MAAU,KAAWN,IAElB,CAAC,GAAGA,EAAM,MAAM,GAAGM,CAAK,GAAGJ,GAAO,GAAGF,EAAM,MAAMM,IAAQ,CAAC,CAAC;AACpE;AAEAP,EAAW,KAAK;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../function/assert.cjs"),i=require("../typed/isArray.cjs");function s(e,t){if(o.assert(i.isArray(e),i.IS_ARRAY_ERROR_MSG,{type:TypeError}),e.length<=1)return[...e];if(!t)return[...new Set(e)];const r=new Map,f=typeof t=="function"?t:n=>n[t];return e.filter(n=>{const u=f(n);return r.has(u)?!1:(r.set(u,n),!0)})}s.fp=!0;exports.uniq=s;
|
|
2
|
+
//# sourceMappingURL=uniq.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniq.cjs","sources":["../../src/array/uniq.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport type { Primitive, Selector } from '../types';\n\n/**\n * Creates a new array with duplicate values removed.\n *\n * @example\n * ```ts\n * uniq([1, 2, 2, 3, 3, 3]); // [1, 2, 3]\n * const arrObj = [{ id: 1 }, { id: 2 }, { id: 2 }, { id: 3 }, { id: 3 }, { id: 3 }];\n * uniq(arrObj, 'id'); // [{ id: 1 }, { id: 2 }, { id: 3 }]\n * uniq(arrObj, item => item.id); // [{ id: 1 }, { id: 2 }, { id: 3 }]\n * ```\n *\n * @param array - The array to process.\n * @param [selector] - The key(s) to compare objects or a function to generate comparison values.\n\n * @returns A new duplicate-free array.\n\n * @throws {TypeError} - If the input is not an array or if the key is invalid.\n */\nexport function uniq<T>(array: T[], selector?: Selector<T>): T[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { type: TypeError });\n\n if (array.length <= 1) {\n return [...array];\n }\n\n if (!selector) {\n return [...new Set(array)];\n }\n\n const seen = new Map<Primitive, T>();\n const getKey = typeof selector === 'function' ? selector : (item: T) => item[selector];\n\n return array.filter((item) => {\n const key = getKey(item) as Primitive;\n if (seen.has(key)) {\n return false;\n }\n seen.set(key, item);\n return true;\n });\n}\n\nuniq.fp = true;\n"],"names":["uniq","array","selector","assert","isArray","IS_ARRAY_ERROR_MSG","seen","getKey","item","key"],"mappings":"4JAsBO,SAASA,EAAQC,EAAYC,EAA6B,CAG/D,GAFAC,EAAAA,OAAOC,EAAAA,QAAQH,CAAK,EAAGI,EAAAA,mBAAoB,CAAE,KAAM,UAAW,EAE1DJ,EAAM,QAAU,EAClB,MAAO,CAAC,GAAGA,CAAK,EAGlB,GAAI,CAACC,EACH,MAAO,CAAC,GAAG,IAAI,IAAID,CAAK,CAAC,EAG3B,MAAMK,MAAW,IACXC,EAAS,OAAOL,GAAa,WAAaA,EAAYM,GAAYA,EAAKN,CAAQ,EAErF,OAAOD,EAAM,OAAQO,GAAS,CAC5B,MAAMC,EAAMF,EAAOC,CAAI,EACvB,OAAIF,EAAK,IAAIG,CAAG,EACP,IAETH,EAAK,IAAIG,EAAKD,CAAI,EACX,GACT,CAAC,CACH,CAEAR,EAAK,GAAK"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { assert as i } from "../function/assert.js";
|
|
2
|
+
import { IS_ARRAY_ERROR_MSG as o, isArray as p } from "../typed/isArray.js";
|
|
3
|
+
function s(t, e) {
|
|
4
|
+
if (i(p(t), o, { type: TypeError }), t.length <= 1)
|
|
5
|
+
return [...t];
|
|
6
|
+
if (!e)
|
|
7
|
+
return [...new Set(t)];
|
|
8
|
+
const r = /* @__PURE__ */ new Map(), u = typeof e == "function" ? e : (n) => n[e];
|
|
9
|
+
return t.filter((n) => {
|
|
10
|
+
const f = u(n);
|
|
11
|
+
return r.has(f) ? !1 : (r.set(f, n), !0);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
s.fp = !0;
|
|
15
|
+
export {
|
|
16
|
+
s as uniq
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=uniq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniq.js","sources":["../../src/array/uniq.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { IS_ARRAY_ERROR_MSG, isArray } from '../typed/isArray';\nimport type { Primitive, Selector } from '../types';\n\n/**\n * Creates a new array with duplicate values removed.\n *\n * @example\n * ```ts\n * uniq([1, 2, 2, 3, 3, 3]); // [1, 2, 3]\n * const arrObj = [{ id: 1 }, { id: 2 }, { id: 2 }, { id: 3 }, { id: 3 }, { id: 3 }];\n * uniq(arrObj, 'id'); // [{ id: 1 }, { id: 2 }, { id: 3 }]\n * uniq(arrObj, item => item.id); // [{ id: 1 }, { id: 2 }, { id: 3 }]\n * ```\n *\n * @param array - The array to process.\n * @param [selector] - The key(s) to compare objects or a function to generate comparison values.\n\n * @returns A new duplicate-free array.\n\n * @throws {TypeError} - If the input is not an array or if the key is invalid.\n */\nexport function uniq<T>(array: T[], selector?: Selector<T>): T[] {\n assert(isArray(array), IS_ARRAY_ERROR_MSG, { type: TypeError });\n\n if (array.length <= 1) {\n return [...array];\n }\n\n if (!selector) {\n return [...new Set(array)];\n }\n\n const seen = new Map<Primitive, T>();\n const getKey = typeof selector === 'function' ? selector : (item: T) => item[selector];\n\n return array.filter((item) => {\n const key = getKey(item) as Primitive;\n if (seen.has(key)) {\n return false;\n }\n seen.set(key, item);\n return true;\n });\n}\n\nuniq.fp = true;\n"],"names":["uniq","array","selector","assert","isArray","IS_ARRAY_ERROR_MSG","seen","getKey","item","key"],"mappings":";;AAsBO,SAASA,EAAQC,GAAYC,GAA6B;AAG/D,MAFAC,EAAOC,EAAQH,CAAK,GAAGI,GAAoB,EAAE,MAAM,WAAW,GAE1DJ,EAAM,UAAU;AAClB,WAAO,CAAC,GAAGA,CAAK;AAGlB,MAAI,CAACC;AACH,WAAO,CAAC,GAAG,IAAI,IAAID,CAAK,CAAC;AAG3B,QAAMK,wBAAW,IAAA,GACXC,IAAS,OAAOL,KAAa,aAAaA,IAAW,CAACM,MAAYA,EAAKN,CAAQ;AAErF,SAAOD,EAAM,OAAO,CAACO,MAAS;AAC5B,UAAMC,IAAMF,EAAOC,CAAI;AACvB,WAAIF,EAAK,IAAIG,CAAG,IACP,MAETH,EAAK,IAAIG,GAAKD,CAAI,GACX;AAAA,EACT,CAAC;AACH;AAEAR,EAAK,KAAK;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function u(e,i=7){const t=typeof e=="string"?new Date(e):e,r=t.getTime();if(Number.isNaN(r))return"UNKNOWN";if(t.getFullYear()>=9999)return"NEVER";const o=Date.now(),n=r-o;return n<=0?"EXPIRED":n<=i*24*60*60*1e3?"SOON":"LATER"}exports.expires=u;
|
|
2
|
+
//# sourceMappingURL=expires.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expires.cjs","sources":["../../src/date/expires.ts"],"sourcesContent":["export type Expires = 'EXPIRED' | 'SOON' | 'LATER' | 'NEVER' | 'UNKNOWN';\n\n/**\n * Determines the expiry status of a given date.\n *\n * @param date - The date to check, as a string or Date object.\n * @param days - Number of days before expiry to be considered \"SOON\" (default: 7).\n * @returns\n * - 'EXPIRED' if the date is in the past,\n * - 'SOON' if the date is within the next `days`,\n * - 'LATER' if the date is further in the future,\n * - 'NEVER' if the year is >= 9999,\n * - 'UNKNOWN' if the date is invalid.\n */\nexport function expires(date: string | Date, days = 7): Expires {\n const target = typeof date === 'string' ? new Date(date) : date;\n const targetTime = target.getTime();\n\n if (Number.isNaN(targetTime)) return 'UNKNOWN';\n if (target.getFullYear() >= 9999) return 'NEVER';\n\n const now = Date.now();\n const diff = targetTime - now;\n\n if (diff <= 0) return 'EXPIRED';\n if (diff <= days * 24 * 60 * 60 * 1000) return 'SOON';\n\n return 'LATER';\n}\n"],"names":["expires","date","days","target","targetTime","now","diff"],"mappings":"gFAcO,SAASA,EAAQC,EAAqBC,EAAO,EAAY,CAC9D,MAAMC,EAAS,OAAOF,GAAS,SAAW,IAAI,KAAKA,CAAI,EAAIA,EACrDG,EAAaD,EAAO,QAAA,EAE1B,GAAI,OAAO,MAAMC,CAAU,EAAG,MAAO,UACrC,GAAID,EAAO,eAAiB,KAAM,MAAO,QAEzC,MAAME,EAAM,KAAK,IAAA,EACXC,EAAOF,EAAaC,EAE1B,OAAIC,GAAQ,EAAU,UAClBA,GAAQJ,EAAO,GAAK,GAAK,GAAK,IAAa,OAExC,OACT"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function f(e, i = 7) {
|
|
2
|
+
const t = typeof e == "string" ? new Date(e) : e, r = t.getTime();
|
|
3
|
+
if (Number.isNaN(r)) return "UNKNOWN";
|
|
4
|
+
if (t.getFullYear() >= 9999) return "NEVER";
|
|
5
|
+
const o = Date.now(), n = r - o;
|
|
6
|
+
return n <= 0 ? "EXPIRED" : n <= i * 24 * 60 * 60 * 1e3 ? "SOON" : "LATER";
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
f as expires
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=expires.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expires.js","sources":["../../src/date/expires.ts"],"sourcesContent":["export type Expires = 'EXPIRED' | 'SOON' | 'LATER' | 'NEVER' | 'UNKNOWN';\n\n/**\n * Determines the expiry status of a given date.\n *\n * @param date - The date to check, as a string or Date object.\n * @param days - Number of days before expiry to be considered \"SOON\" (default: 7).\n * @returns\n * - 'EXPIRED' if the date is in the past,\n * - 'SOON' if the date is within the next `days`,\n * - 'LATER' if the date is further in the future,\n * - 'NEVER' if the year is >= 9999,\n * - 'UNKNOWN' if the date is invalid.\n */\nexport function expires(date: string | Date, days = 7): Expires {\n const target = typeof date === 'string' ? new Date(date) : date;\n const targetTime = target.getTime();\n\n if (Number.isNaN(targetTime)) return 'UNKNOWN';\n if (target.getFullYear() >= 9999) return 'NEVER';\n\n const now = Date.now();\n const diff = targetTime - now;\n\n if (diff <= 0) return 'EXPIRED';\n if (diff <= days * 24 * 60 * 60 * 1000) return 'SOON';\n\n return 'LATER';\n}\n"],"names":["expires","date","days","target","targetTime","now","diff"],"mappings":"AAcO,SAASA,EAAQC,GAAqBC,IAAO,GAAY;AAC9D,QAAMC,IAAS,OAAOF,KAAS,WAAW,IAAI,KAAKA,CAAI,IAAIA,GACrDG,IAAaD,EAAO,QAAA;AAE1B,MAAI,OAAO,MAAMC,CAAU,EAAG,QAAO;AACrC,MAAID,EAAO,iBAAiB,KAAM,QAAO;AAEzC,QAAME,IAAM,KAAK,IAAA,GACXC,IAAOF,IAAaC;AAE1B,SAAIC,KAAQ,IAAU,YAClBA,KAAQJ,IAAO,KAAK,KAAK,KAAK,MAAa,SAExC;AACT;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../function/assert.cjs"),i=require("../typed/isDate.cjs");function w(r,c,{interval:e="D",steps:t=1,latest:a=!1}={}){const n=new Date(r),o=new Date(c);l.assert([i.isDate(n),i.isDate(o)],"Invalid date format. Use a valid Date object or ISO string.",{args:{end:c,start:r},type:TypeError});const D=[];let u=new Date(s(n,e,0));for(;u<=o;)D.push(u),u=new Date(s(u,e,t));return a&&D.length>0&&D[D.length-1]<o&&D.push(o),D}function s(r,c,e){const t=r.getFullYear(),a=r.getMonth(),n=r.getDate();switch(c){case"D":return new Date(Date.UTC(t,a,n+e));case"W":return new Date(Date.UTC(t,a,n+7*e));case"M":return new Date(Date.UTC(t,a+e,n));case"MS":return new Date(Date.UTC(t,a+e,1));case"ME":return new Date(Date.UTC(t,a+e+1,0));case"Y":return new Date(Date.UTC(t+e,a,n));case"YS":return new Date(Date.UTC(t+e,0,1));case"YE":return new Date(Date.UTC(t+e,11,31))}}exports.interval=w;
|
|
2
|
+
//# sourceMappingURL=interval.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interval.cjs","sources":["../../src/date/interval.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isDate } from '../typed/isDate';\n\ntype IntervalType = 'D' | 'W' | 'M' | 'MS' | 'ME' | 'Y' | 'YS' | 'YE';\ntype IntervalOptions = {\n interval?: IntervalType;\n steps?: number;\n latest?: boolean;\n};\n\n/**\n * Generates an array of dates between a start and end date, with a specified interval and step size.\n *\n * @example\n * ```ts\n * const options = { interval: 'D', steps: 1, latest: false };\n *\n * interval('2022-01-01', '2022-01-31', options); // Returns an array of dates for every day in January 2022\n * ```\n *\n * @param start - The start date (Date object or ISO string).\n * @param end - The end date (Date object or ISO string).\n * @param options - Options for an interval and steps.\n *\n * @returns An array of generated dates.\n */\nexport function interval(\n start: Date | string,\n end: Date | string,\n { interval = 'D', steps = 1, latest = false }: IntervalOptions = {},\n): Date[] {\n const startDate = new Date(start);\n const endDate = new Date(end);\n\n assert([isDate(startDate), isDate(endDate)], 'Invalid date format. Use a valid Date object or ISO string.', {\n args: { end, start },\n type: TypeError,\n });\n\n const dateArray: Date[] = [];\n let currentDate = new Date(incrementDate(startDate, interval, 0));\n\n while (currentDate <= endDate) {\n dateArray.push(currentDate);\n currentDate = new Date(incrementDate(currentDate, interval, steps));\n }\n\n if (latest && dateArray.length > 0 && dateArray[dateArray.length - 1] < endDate) {\n dateArray.push(endDate);\n }\n\n return dateArray;\n}\n\nfunction incrementDate(date: Date, interval: IntervalType, steps: number): Date {\n const year = date.getFullYear();\n const month = date.getMonth();\n const day = date.getDate();\n\n switch (interval) {\n case 'D':\n return new Date(Date.UTC(year, month, day + steps));\n case 'W':\n return new Date(Date.UTC(year, month, day + 7 * steps));\n case 'M':\n return new Date(Date.UTC(year, month + steps, day));\n case 'MS':\n return new Date(Date.UTC(year, month + steps, 1));\n case 'ME':\n return new Date(Date.UTC(year, month + steps + 1, 0));\n case 'Y':\n return new Date(Date.UTC(year + steps, month, day));\n case 'YS':\n return new Date(Date.UTC(year + steps, 0, 1));\n case 'YE':\n return new Date(Date.UTC(year + steps, 11, 31));\n }\n}\n"],"names":["interval","start","end","steps","latest","startDate","endDate","assert","isDate","dateArray","currentDate","incrementDate","date","year","month","day"],"mappings":"2JA0BO,SAASA,EACdC,EACAC,EACA,CAAE,SAAAF,EAAW,IAAK,MAAAG,EAAQ,EAAG,OAAAC,EAAS,EAAA,EAA2B,CAAA,EACzD,CACR,MAAMC,EAAY,IAAI,KAAKJ,CAAK,EAC1BK,EAAU,IAAI,KAAKJ,CAAG,EAE5BK,EAAAA,OAAO,CAACC,EAAAA,OAAOH,CAAS,EAAGG,EAAAA,OAAOF,CAAO,CAAC,EAAG,8DAA+D,CAC1G,KAAM,CAAE,IAAAJ,EAAK,MAAAD,CAAA,EACb,KAAM,SAAA,CACP,EAED,MAAMQ,EAAoB,CAAA,EAC1B,IAAIC,EAAc,IAAI,KAAKC,EAAcN,EAAWL,EAAU,CAAC,CAAC,EAEhE,KAAOU,GAAeJ,GACpBG,EAAU,KAAKC,CAAW,EAC1BA,EAAc,IAAI,KAAKC,EAAcD,EAAaV,EAAUG,CAAK,CAAC,EAGpE,OAAIC,GAAUK,EAAU,OAAS,GAAKA,EAAUA,EAAU,OAAS,CAAC,EAAIH,GACtEG,EAAU,KAAKH,CAAO,EAGjBG,CACT,CAEA,SAASE,EAAcC,EAAYZ,EAAwBG,EAAqB,CAC9E,MAAMU,EAAOD,EAAK,YAAA,EACZE,EAAQF,EAAK,SAAA,EACbG,EAAMH,EAAK,QAAA,EAEjB,OAAQZ,EAAAA,CACN,IAAK,IACH,OAAO,IAAI,KAAK,KAAK,IAAIa,EAAMC,EAAOC,EAAMZ,CAAK,CAAC,EACpD,IAAK,IACH,OAAO,IAAI,KAAK,KAAK,IAAIU,EAAMC,EAAOC,EAAM,EAAIZ,CAAK,CAAC,EACxD,IAAK,IACH,OAAO,IAAI,KAAK,KAAK,IAAIU,EAAMC,EAAQX,EAAOY,CAAG,CAAC,EACpD,IAAK,KACH,OAAO,IAAI,KAAK,KAAK,IAAIF,EAAMC,EAAQX,EAAO,CAAC,CAAC,EAClD,IAAK,KACH,OAAO,IAAI,KAAK,KAAK,IAAIU,EAAMC,EAAQX,EAAQ,EAAG,CAAC,CAAC,EACtD,IAAK,IACH,OAAO,IAAI,KAAK,KAAK,IAAIU,EAAOV,EAAOW,EAAOC,CAAG,CAAC,EACpD,IAAK,KACH,OAAO,IAAI,KAAK,KAAK,IAAIF,EAAOV,EAAO,EAAG,CAAC,CAAC,EAC9C,IAAK,KACH,OAAO,IAAI,KAAK,KAAK,IAAIU,EAAOV,EAAO,GAAI,EAAE,CAAC,CAAA,CAEpD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { assert as l } from "../function/assert.js";
|
|
2
|
+
import { isDate as w } from "../typed/isDate.js";
|
|
3
|
+
function U(r, c, { interval: e = "D", steps: t = 1, latest: a = !1 } = {}) {
|
|
4
|
+
const n = new Date(r), o = new Date(c);
|
|
5
|
+
l([w(n), w(o)], "Invalid date format. Use a valid Date object or ISO string.", {
|
|
6
|
+
args: { end: c, start: r },
|
|
7
|
+
type: TypeError
|
|
8
|
+
});
|
|
9
|
+
const D = [];
|
|
10
|
+
let u = new Date(i(n, e, 0));
|
|
11
|
+
for (; u <= o; )
|
|
12
|
+
D.push(u), u = new Date(i(u, e, t));
|
|
13
|
+
return a && D.length > 0 && D[D.length - 1] < o && D.push(o), D;
|
|
14
|
+
}
|
|
15
|
+
function i(r, c, e) {
|
|
16
|
+
const t = r.getFullYear(), a = r.getMonth(), n = r.getDate();
|
|
17
|
+
switch (c) {
|
|
18
|
+
case "D":
|
|
19
|
+
return new Date(Date.UTC(t, a, n + e));
|
|
20
|
+
case "W":
|
|
21
|
+
return new Date(Date.UTC(t, a, n + 7 * e));
|
|
22
|
+
case "M":
|
|
23
|
+
return new Date(Date.UTC(t, a + e, n));
|
|
24
|
+
case "MS":
|
|
25
|
+
return new Date(Date.UTC(t, a + e, 1));
|
|
26
|
+
case "ME":
|
|
27
|
+
return new Date(Date.UTC(t, a + e + 1, 0));
|
|
28
|
+
case "Y":
|
|
29
|
+
return new Date(Date.UTC(t + e, a, n));
|
|
30
|
+
case "YS":
|
|
31
|
+
return new Date(Date.UTC(t + e, 0, 1));
|
|
32
|
+
case "YE":
|
|
33
|
+
return new Date(Date.UTC(t + e, 11, 31));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
U as interval
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=interval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interval.js","sources":["../../src/date/interval.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isDate } from '../typed/isDate';\n\ntype IntervalType = 'D' | 'W' | 'M' | 'MS' | 'ME' | 'Y' | 'YS' | 'YE';\ntype IntervalOptions = {\n interval?: IntervalType;\n steps?: number;\n latest?: boolean;\n};\n\n/**\n * Generates an array of dates between a start and end date, with a specified interval and step size.\n *\n * @example\n * ```ts\n * const options = { interval: 'D', steps: 1, latest: false };\n *\n * interval('2022-01-01', '2022-01-31', options); // Returns an array of dates for every day in January 2022\n * ```\n *\n * @param start - The start date (Date object or ISO string).\n * @param end - The end date (Date object or ISO string).\n * @param options - Options for an interval and steps.\n *\n * @returns An array of generated dates.\n */\nexport function interval(\n start: Date | string,\n end: Date | string,\n { interval = 'D', steps = 1, latest = false }: IntervalOptions = {},\n): Date[] {\n const startDate = new Date(start);\n const endDate = new Date(end);\n\n assert([isDate(startDate), isDate(endDate)], 'Invalid date format. Use a valid Date object or ISO string.', {\n args: { end, start },\n type: TypeError,\n });\n\n const dateArray: Date[] = [];\n let currentDate = new Date(incrementDate(startDate, interval, 0));\n\n while (currentDate <= endDate) {\n dateArray.push(currentDate);\n currentDate = new Date(incrementDate(currentDate, interval, steps));\n }\n\n if (latest && dateArray.length > 0 && dateArray[dateArray.length - 1] < endDate) {\n dateArray.push(endDate);\n }\n\n return dateArray;\n}\n\nfunction incrementDate(date: Date, interval: IntervalType, steps: number): Date {\n const year = date.getFullYear();\n const month = date.getMonth();\n const day = date.getDate();\n\n switch (interval) {\n case 'D':\n return new Date(Date.UTC(year, month, day + steps));\n case 'W':\n return new Date(Date.UTC(year, month, day + 7 * steps));\n case 'M':\n return new Date(Date.UTC(year, month + steps, day));\n case 'MS':\n return new Date(Date.UTC(year, month + steps, 1));\n case 'ME':\n return new Date(Date.UTC(year, month + steps + 1, 0));\n case 'Y':\n return new Date(Date.UTC(year + steps, month, day));\n case 'YS':\n return new Date(Date.UTC(year + steps, 0, 1));\n case 'YE':\n return new Date(Date.UTC(year + steps, 11, 31));\n }\n}\n"],"names":["interval","start","end","steps","latest","startDate","endDate","assert","isDate","dateArray","currentDate","incrementDate","date","year","month","day"],"mappings":";;AA0BO,SAASA,EACdC,GACAC,GACA,EAAE,UAAAF,IAAW,KAAK,OAAAG,IAAQ,GAAG,QAAAC,IAAS,GAAA,IAA2B,CAAA,GACzD;AACR,QAAMC,IAAY,IAAI,KAAKJ,CAAK,GAC1BK,IAAU,IAAI,KAAKJ,CAAG;AAE5B,EAAAK,EAAO,CAACC,EAAOH,CAAS,GAAGG,EAAOF,CAAO,CAAC,GAAG,+DAA+D;AAAA,IAC1G,MAAM,EAAE,KAAAJ,GAAK,OAAAD,EAAA;AAAA,IACb,MAAM;AAAA,EAAA,CACP;AAED,QAAMQ,IAAoB,CAAA;AAC1B,MAAIC,IAAc,IAAI,KAAKC,EAAcN,GAAWL,GAAU,CAAC,CAAC;AAEhE,SAAOU,KAAeJ;AACpB,IAAAG,EAAU,KAAKC,CAAW,GAC1BA,IAAc,IAAI,KAAKC,EAAcD,GAAaV,GAAUG,CAAK,CAAC;AAGpE,SAAIC,KAAUK,EAAU,SAAS,KAAKA,EAAUA,EAAU,SAAS,CAAC,IAAIH,KACtEG,EAAU,KAAKH,CAAO,GAGjBG;AACT;AAEA,SAASE,EAAcC,GAAYZ,GAAwBG,GAAqB;AAC9E,QAAMU,IAAOD,EAAK,YAAA,GACZE,IAAQF,EAAK,SAAA,GACbG,IAAMH,EAAK,QAAA;AAEjB,UAAQZ,GAAAA;AAAAA,IACN,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIa,GAAMC,GAAOC,IAAMZ,CAAK,CAAC;AAAA,IACpD,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIU,GAAMC,GAAOC,IAAM,IAAIZ,CAAK,CAAC;AAAA,IACxD,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIU,GAAMC,IAAQX,GAAOY,CAAG,CAAC;AAAA,IACpD,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIF,GAAMC,IAAQX,GAAO,CAAC,CAAC;AAAA,IAClD,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIU,GAAMC,IAAQX,IAAQ,GAAG,CAAC,CAAC;AAAA,IACtD,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIU,IAAOV,GAAOW,GAAOC,CAAG,CAAC;AAAA,IACpD,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIF,IAAOV,GAAO,GAAG,CAAC,CAAC;AAAA,IAC9C,KAAK;AACH,aAAO,IAAI,KAAK,KAAK,IAAIU,IAAOV,GAAO,IAAI,EAAE,CAAC;AAAA,EAAA;AAEpD;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let a=["YEAR","MONTH","WEEK","DAY","HOUR","MINUTE","SECOND"];const f=1e3,c=60*f,N=60*c,e=24*N,D=7*e,_=30*e,S=365*e,R=[{ms:S,unit:"YEAR"},{ms:_,unit:"MONTH"},{ms:D,unit:"WEEK"},{ms:e,unit:"DAY"},{ms:N,unit:"HOUR"},{ms:c,unit:"MINUTE"},{ms:f,unit:"SECOND"}];function M(t,i=new Date,l=a){const o=typeof t=="string"?Date.parse(t):t.getTime(),E=typeof i=="string"?Date.parse(i):i.getTime();if(Number.isNaN(o)||Number.isNaN(E))return{unit:"INVALID_DATE",value:0};const s=R.filter(n=>l.includes(n.unit)),u=Math.abs(o-E),r=s[s.length-1]?.unit??"SECOND";if(u<=0)return{unit:r,value:0};for(const{ms:n,unit:m}of s)if(u>=n)return{unit:m,value:Math.floor(u/n)};return{unit:r,value:0}}M.defaultUnits=t=>{a=t};exports.timeDiff=M;
|
|
2
|
+
//# sourceMappingURL=timeDiff.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeDiff.cjs","sources":["../../src/date/timeDiff.ts"],"sourcesContent":["export type TimeUnit = 'YEAR' | 'MONTH' | 'WEEK' | 'DAY' | 'HOUR' | 'MINUTE' | 'SECOND' | 'INVALID_DATE';\nexport type TimeDirection = 'FUTURE' | 'PAST';\nexport type TimeResult = { unit: TimeUnit; value: number };\n\nlet defaultUnits: TimeUnit[] = ['YEAR', 'MONTH', 'WEEK', 'DAY', 'HOUR', 'MINUTE', 'SECOND'];\n\nconst MS_PER_SECOND = 1000;\nconst MS_PER_MINUTE = 60 * MS_PER_SECOND;\nconst MS_PER_HOUR = 60 * MS_PER_MINUTE;\nconst MS_PER_DAY = 24 * MS_PER_HOUR;\nconst MS_PER_WEEK = 7 * MS_PER_DAY;\nconst MS_PER_MONTH = 30 * MS_PER_DAY;\nconst MS_PER_YEAR = 365 * MS_PER_DAY;\n\nconst TIME_UNITS = [\n { ms: MS_PER_YEAR, unit: 'YEAR' as const },\n { ms: MS_PER_MONTH, unit: 'MONTH' as const },\n { ms: MS_PER_WEEK, unit: 'WEEK' as const },\n { ms: MS_PER_DAY, unit: 'DAY' as const },\n { ms: MS_PER_HOUR, unit: 'HOUR' as const },\n { ms: MS_PER_MINUTE, unit: 'MINUTE' as const },\n { ms: MS_PER_SECOND, unit: 'SECOND' as const },\n];\n\n/**\n * Calculates the remaining time until a target date.\n *\n * @example\n * ```ts\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 5)); // { value: 5, unit: 'DAY' }\n * timeDiff(new Date(Date.now() - 1000 * 60 * 60 * 24 * 3), 'past'); // { value: 3, unit: 'DAY' }\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 31)); // { value: 1, unit: 'MONTH' }\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 365)); // { value: 1, unit: 'YEAR' }\n * ```\n *\n * @param a - The target date (Date object or ISO string).\n * @param b - The target date (Date object or ISO string).\n * @param allowedUnits - (optional) array of units to filter the result. If provided, only these units will be considered.\n *\n * @returns An object containing the remaining time and its unit ('DAY', 'HOUR', or 'MINUTE').\n */\nexport function timeDiff(\n a: Date | string,\n b: Date | string = new Date(),\n allowedUnits: TimeUnit[] = defaultUnits,\n): TimeResult {\n const aDate = typeof a === 'string' ? Date.parse(a) : a.getTime();\n const bDate = typeof b === 'string' ? Date.parse(b) : b.getTime();\n\n if (Number.isNaN(aDate) || Number.isNaN(bDate)) {\n return { unit: 'INVALID_DATE', value: 0 };\n }\n\n const units = TIME_UNITS.filter((u) => allowedUnits.includes(u.unit));\n const diff = Math.abs(aDate - bDate);\n const smallestUnit = units[units.length - 1]?.unit ?? 'SECOND';\n\n if (diff <= 0) {\n return { unit: smallestUnit, value: 0 };\n }\n\n for (const { ms, unit } of units) {\n if (diff >= ms) {\n return { unit, value: Math.floor(diff / ms) };\n }\n }\n\n return { unit: smallestUnit, value: 0 };\n}\n\ntimeDiff.defaultUnits = (units: TimeUnit[]) => {\n defaultUnits = units;\n};\n"],"names":["defaultUnits","MS_PER_SECOND","MS_PER_MINUTE","MS_PER_HOUR","MS_PER_DAY","MS_PER_WEEK","MS_PER_MONTH","MS_PER_YEAR","TIME_UNITS","timeDiff","a","b","allowedUnits","aDate","bDate","units","u","diff","smallestUnit","ms","unit"],"mappings":"gFAIA,IAAIA,EAA2B,CAAC,OAAQ,QAAS,OAAQ,MAAO,OAAQ,SAAU,QAAQ,EAE1F,MAAMC,EAAgB,IAChBC,EAAgB,GAAKD,EACrBE,EAAc,GAAKD,EACnBE,EAAa,GAAKD,EAClBE,EAAc,EAAID,EAClBE,EAAe,GAAKF,EACpBG,EAAc,IAAMH,EAEpBI,EAAa,CACjB,CAAE,GAAID,EAAa,KAAM,MAAA,EACzB,CAAE,GAAID,EAAc,KAAM,OAAA,EAC1B,CAAE,GAAID,EAAa,KAAM,MAAA,EACzB,CAAE,GAAID,EAAY,KAAM,KAAA,EACxB,CAAE,GAAID,EAAa,KAAM,MAAA,EACzB,CAAE,GAAID,EAAe,KAAM,QAAA,EAC3B,CAAE,GAAID,EAAe,KAAM,QAAA,CAC7B,EAmBO,SAASQ,EACdC,EACAC,MAAuB,KACvBC,EAA2BZ,EACf,CACZ,MAAMa,EAAQ,OAAOH,GAAM,SAAW,KAAK,MAAMA,CAAC,EAAIA,EAAE,QAAA,EAClDI,EAAQ,OAAOH,GAAM,SAAW,KAAK,MAAMA,CAAC,EAAIA,EAAE,QAAA,EAExD,GAAI,OAAO,MAAME,CAAK,GAAK,OAAO,MAAMC,CAAK,EAC3C,MAAO,CAAE,KAAM,eAAgB,MAAO,CAAA,EAGxC,MAAMC,EAAQP,EAAW,OAAQQ,GAAMJ,EAAa,SAASI,EAAE,IAAI,CAAC,EAC9DC,EAAO,KAAK,IAAIJ,EAAQC,CAAK,EAC7BI,EAAeH,EAAMA,EAAM,OAAS,CAAC,GAAG,MAAQ,SAEtD,GAAIE,GAAQ,EACV,MAAO,CAAE,KAAMC,EAAc,MAAO,CAAA,EAGtC,SAAW,CAAE,GAAAC,EAAI,KAAAC,CAAA,IAAUL,EACzB,GAAIE,GAAQE,EACV,MAAO,CAAE,KAAAC,EAAM,MAAO,KAAK,MAAMH,EAAOE,CAAE,CAAA,EAI9C,MAAO,CAAE,KAAMD,EAAc,MAAO,CAAA,CACtC,CAEAT,EAAS,aAAgBM,GAAsB,CAC7Cf,EAAee,CACjB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
let R = ["YEAR", "MONTH", "WEEK", "DAY", "HOUR", "MINUTE", "SECOND"];
|
|
2
|
+
const N = [
|
|
3
|
+
{ ms: 31536e6, unit: "YEAR" },
|
|
4
|
+
{ ms: 2592e6, unit: "MONTH" },
|
|
5
|
+
{ ms: 6048e5, unit: "WEEK" },
|
|
6
|
+
{ ms: 864e5, unit: "DAY" },
|
|
7
|
+
{ ms: 36e5, unit: "HOUR" },
|
|
8
|
+
{ ms: 6e4, unit: "MINUTE" },
|
|
9
|
+
{ ms: 1e3, unit: "SECOND" }
|
|
10
|
+
];
|
|
11
|
+
function o(t, n = /* @__PURE__ */ new Date(), u = R) {
|
|
12
|
+
const e = typeof t == "string" ? Date.parse(t) : t.getTime(), i = typeof n == "string" ? Date.parse(n) : n.getTime();
|
|
13
|
+
if (Number.isNaN(e) || Number.isNaN(i))
|
|
14
|
+
return { unit: "INVALID_DATE", value: 0 };
|
|
15
|
+
const _ = N.filter((E) => u.includes(E.unit)), s = Math.abs(e - i), M = _[_.length - 1]?.unit ?? "SECOND";
|
|
16
|
+
if (s <= 0)
|
|
17
|
+
return { unit: M, value: 0 };
|
|
18
|
+
for (const { ms: E, unit: S } of _)
|
|
19
|
+
if (s >= E)
|
|
20
|
+
return { unit: S, value: Math.floor(s / E) };
|
|
21
|
+
return { unit: M, value: 0 };
|
|
22
|
+
}
|
|
23
|
+
o.defaultUnits = (t) => {
|
|
24
|
+
R = t;
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
o as timeDiff
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=timeDiff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeDiff.js","sources":["../../src/date/timeDiff.ts"],"sourcesContent":["export type TimeUnit = 'YEAR' | 'MONTH' | 'WEEK' | 'DAY' | 'HOUR' | 'MINUTE' | 'SECOND' | 'INVALID_DATE';\nexport type TimeDirection = 'FUTURE' | 'PAST';\nexport type TimeResult = { unit: TimeUnit; value: number };\n\nlet defaultUnits: TimeUnit[] = ['YEAR', 'MONTH', 'WEEK', 'DAY', 'HOUR', 'MINUTE', 'SECOND'];\n\nconst MS_PER_SECOND = 1000;\nconst MS_PER_MINUTE = 60 * MS_PER_SECOND;\nconst MS_PER_HOUR = 60 * MS_PER_MINUTE;\nconst MS_PER_DAY = 24 * MS_PER_HOUR;\nconst MS_PER_WEEK = 7 * MS_PER_DAY;\nconst MS_PER_MONTH = 30 * MS_PER_DAY;\nconst MS_PER_YEAR = 365 * MS_PER_DAY;\n\nconst TIME_UNITS = [\n { ms: MS_PER_YEAR, unit: 'YEAR' as const },\n { ms: MS_PER_MONTH, unit: 'MONTH' as const },\n { ms: MS_PER_WEEK, unit: 'WEEK' as const },\n { ms: MS_PER_DAY, unit: 'DAY' as const },\n { ms: MS_PER_HOUR, unit: 'HOUR' as const },\n { ms: MS_PER_MINUTE, unit: 'MINUTE' as const },\n { ms: MS_PER_SECOND, unit: 'SECOND' as const },\n];\n\n/**\n * Calculates the remaining time until a target date.\n *\n * @example\n * ```ts\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 5)); // { value: 5, unit: 'DAY' }\n * timeDiff(new Date(Date.now() - 1000 * 60 * 60 * 24 * 3), 'past'); // { value: 3, unit: 'DAY' }\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 31)); // { value: 1, unit: 'MONTH' }\n * timeDiff(new Date(Date.now() + 1000 * 60 * 60 * 24 * 365)); // { value: 1, unit: 'YEAR' }\n * ```\n *\n * @param a - The target date (Date object or ISO string).\n * @param b - The target date (Date object or ISO string).\n * @param allowedUnits - (optional) array of units to filter the result. If provided, only these units will be considered.\n *\n * @returns An object containing the remaining time and its unit ('DAY', 'HOUR', or 'MINUTE').\n */\nexport function timeDiff(\n a: Date | string,\n b: Date | string = new Date(),\n allowedUnits: TimeUnit[] = defaultUnits,\n): TimeResult {\n const aDate = typeof a === 'string' ? Date.parse(a) : a.getTime();\n const bDate = typeof b === 'string' ? Date.parse(b) : b.getTime();\n\n if (Number.isNaN(aDate) || Number.isNaN(bDate)) {\n return { unit: 'INVALID_DATE', value: 0 };\n }\n\n const units = TIME_UNITS.filter((u) => allowedUnits.includes(u.unit));\n const diff = Math.abs(aDate - bDate);\n const smallestUnit = units[units.length - 1]?.unit ?? 'SECOND';\n\n if (diff <= 0) {\n return { unit: smallestUnit, value: 0 };\n }\n\n for (const { ms, unit } of units) {\n if (diff >= ms) {\n return { unit, value: Math.floor(diff / ms) };\n }\n }\n\n return { unit: smallestUnit, value: 0 };\n}\n\ntimeDiff.defaultUnits = (units: TimeUnit[]) => {\n defaultUnits = units;\n};\n"],"names":["defaultUnits","TIME_UNITS","timeDiff","a","b","allowedUnits","aDate","bDate","units","u","diff","smallestUnit","ms","unit"],"mappings":"AAIA,IAAIA,IAA2B,CAAC,QAAQ,SAAS,QAAQ,OAAO,QAAQ,UAAU,QAAQ;AAU1F,MAAMC,IAAa;AAAA,EACjB,EAAE,IAAI,SAAa,MAAM,OAAA;AAAA,EACzB,EAAE,IAAI,QAAc,MAAM,QAAA;AAAA,EAC1B,EAAE,IAAI,QAAa,MAAM,OAAA;AAAA,EACzB,EAAE,IAAI,OAAY,MAAM,MAAA;AAAA,EACxB,EAAE,IAAI,MAAa,MAAM,OAAA;AAAA,EACzB,EAAE,IAAI,KAAe,MAAM,SAAA;AAAA,EAC3B,EAAE,IAAI,KAAe,MAAM,SAAA;AAC7B;AAmBO,SAASC,EACdC,GACAC,wBAAuB,KAAA,GACvBC,IAA2BL,GACf;AACZ,QAAMM,IAAQ,OAAOH,KAAM,WAAW,KAAK,MAAMA,CAAC,IAAIA,EAAE,QAAA,GAClDI,IAAQ,OAAOH,KAAM,WAAW,KAAK,MAAMA,CAAC,IAAIA,EAAE,QAAA;AAExD,MAAI,OAAO,MAAME,CAAK,KAAK,OAAO,MAAMC,CAAK;AAC3C,WAAO,EAAE,MAAM,gBAAgB,OAAO,EAAA;AAGxC,QAAMC,IAAQP,EAAW,OAAO,CAACQ,MAAMJ,EAAa,SAASI,EAAE,IAAI,CAAC,GAC9DC,IAAO,KAAK,IAAIJ,IAAQC,CAAK,GAC7BI,IAAeH,EAAMA,EAAM,SAAS,CAAC,GAAG,QAAQ;AAEtD,MAAIE,KAAQ;AACV,WAAO,EAAE,MAAMC,GAAc,OAAO,EAAA;AAGtC,aAAW,EAAE,IAAAC,GAAI,MAAAC,EAAA,KAAUL;AACzB,QAAIE,KAAQE;AACV,aAAO,EAAE,MAAAC,GAAM,OAAO,KAAK,MAAMH,IAAOE,CAAE,EAAA;AAI9C,SAAO,EAAE,MAAMD,GAAc,OAAO,EAAA;AACtC;AAEAT,EAAS,eAAe,CAACM,MAAsB;AAC7C,EAAAR,IAAeQ;AACjB;"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../logit/dist/logit.cjs");function f(e,t="Assertion failed",{type:l=Error,args:r,bypass:i=!1}={}){if(!(Array.isArray(e)?e.some(o=>!o):!e))return;const a=r?`
|
|
2
|
+
Arguments: ${JSON.stringify(r,null,2)}`:"",s=`${t}${a}`;if(i)n.Logit.warn(s);else throw new l(s)}exports.assert=f;
|
|
3
|
+
//# sourceMappingURL=assert.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.cjs","sources":["../../src/function/assert.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport type { Obj } from '../types';\n\n/**\n * Asserts that the condition is true. If the condition is false, it throws an error\n * with the provided message or logs a warning in soft mode.\n *\n * @example\n * ```ts\n * assert(Array.isArray([])); // Does nothing\n * assert(typeof foo === 'string', 'This is an error message'); // Throws an error\n * assert(x > 0, 'x must be positive', { args: { x } }); // Throws with argument details\n * ```\n *\n * @param condition - The condition to assert, or an array of conditions.\n * @param [message] - The error message to throw. Default is 'Assertion failed'.\n * @param options - Assertion options.\n * @param [options.type] - The error class to throw (default: `Error`).\n * @param [options.args] - Additional debugging information (e.g., variable values).\n * @param [options.bypass] - If `true`, logs a warning instead of throwing an error.\n *\n * @throws {Error} If the condition is false and `bypass` is not set to `true`.\n */\nexport function assert(\n condition: boolean | boolean[],\n message = 'Assertion failed',\n { type = Error, args, bypass = false }: { type?: ErrorConstructor; args?: Obj; bypass?: boolean } = {},\n): void {\n const failed = Array.isArray(condition) ? condition.some((cond) => !cond) : !condition;\n if (!failed) return;\n\n const errorDetails = args ? `\\nArguments: ${JSON.stringify(args, null, 2)}` : '';\n const fullMessage = `${message}${errorDetails}`;\n\n if (bypass) Logit.warn(fullMessage);\n else throw new type(fullMessage);\n}\n"],"names":["assert","condition","message","type","args","bypass","cond","errorDetails","fullMessage","Logit"],"mappings":"2HAuBO,SAASA,EACdC,EACAC,EAAU,mBACV,CAAE,KAAAC,EAAO,MAAO,KAAAC,EAAM,OAAAC,EAAS,EAAA,EAAqE,CAAA,EAC9F,CAEN,GAAI,EADW,MAAM,QAAQJ,CAAS,EAAIA,EAAU,KAAMK,GAAS,CAACA,CAAI,EAAI,CAACL,GAChE,OAEb,MAAMM,EAAeH,EAAO;AAAA,aAAgB,KAAK,UAAUA,EAAM,KAAM,CAAC,CAAC,GAAK,GACxEI,EAAc,GAAGN,CAAO,GAAGK,CAAY,GAE7C,GAAIF,EAAQI,EAAAA,MAAM,KAAKD,CAAW,MAC7B,OAAM,IAAIL,EAAKK,CAAW,CACjC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Logit as o } from "../logit/dist/logit.js";
|
|
2
|
+
function m(r, t = "Assertion failed", { type: a = Error, args: e, bypass: f = !1 } = {}) {
|
|
3
|
+
if (!(Array.isArray(r) ? r.some((i) => !i) : !r)) return;
|
|
4
|
+
const l = e ? `
|
|
5
|
+
Arguments: ${JSON.stringify(e, null, 2)}` : "", s = `${t}${l}`;
|
|
6
|
+
if (f) o.warn(s);
|
|
7
|
+
else throw new a(s);
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
m as assert
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","sources":["../../src/function/assert.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport type { Obj } from '../types';\n\n/**\n * Asserts that the condition is true. If the condition is false, it throws an error\n * with the provided message or logs a warning in soft mode.\n *\n * @example\n * ```ts\n * assert(Array.isArray([])); // Does nothing\n * assert(typeof foo === 'string', 'This is an error message'); // Throws an error\n * assert(x > 0, 'x must be positive', { args: { x } }); // Throws with argument details\n * ```\n *\n * @param condition - The condition to assert, or an array of conditions.\n * @param [message] - The error message to throw. Default is 'Assertion failed'.\n * @param options - Assertion options.\n * @param [options.type] - The error class to throw (default: `Error`).\n * @param [options.args] - Additional debugging information (e.g., variable values).\n * @param [options.bypass] - If `true`, logs a warning instead of throwing an error.\n *\n * @throws {Error} If the condition is false and `bypass` is not set to `true`.\n */\nexport function assert(\n condition: boolean | boolean[],\n message = 'Assertion failed',\n { type = Error, args, bypass = false }: { type?: ErrorConstructor; args?: Obj; bypass?: boolean } = {},\n): void {\n const failed = Array.isArray(condition) ? condition.some((cond) => !cond) : !condition;\n if (!failed) return;\n\n const errorDetails = args ? `\\nArguments: ${JSON.stringify(args, null, 2)}` : '';\n const fullMessage = `${message}${errorDetails}`;\n\n if (bypass) Logit.warn(fullMessage);\n else throw new type(fullMessage);\n}\n"],"names":["assert","condition","message","type","args","bypass","cond","errorDetails","fullMessage","Logit"],"mappings":";AAuBO,SAASA,EACdC,GACAC,IAAU,oBACV,EAAE,MAAAC,IAAO,OAAO,MAAAC,GAAM,QAAAC,IAAS,GAAA,IAAqE,CAAA,GAC9F;AAEN,MAAI,EADW,MAAM,QAAQJ,CAAS,IAAIA,EAAU,KAAK,CAACK,MAAS,CAACA,CAAI,IAAI,CAACL,GAChE;AAEb,QAAMM,IAAeH,IAAO;AAAA,aAAgB,KAAK,UAAUA,GAAM,MAAM,CAAC,CAAC,KAAK,IACxEI,IAAc,GAAGN,CAAO,GAAGK,CAAY;AAE7C,MAAIF,EAAQI,CAAAA,EAAM,KAAKD,CAAW;AAAA,MAC7B,OAAM,IAAIL,EAAKK,CAAW;AACjC;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./assert.cjs");function l(e,o,r,i={}){n.assert(!!e,"Missing parameters object",i);const t=o.filter(s=>e[s]===void 0||e[s]===null||e[s]==="");if(t.length>0){const s=r?` in "${r}"`:"",a=t.map(g=>`"${String(g)}"`).join(", "),c=`Missing required parameter${t.length>1?"s":""}: ${a}${s}`;n.assert(!1,c,i)}}exports.assertParams=l;
|
|
2
|
+
//# sourceMappingURL=assertParams.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertParams.cjs","sources":["../../src/function/assertParams.ts"],"sourcesContent":["import { assert } from './assert';\n\n/**\n * Asserts that the specified keys are present in the params object and are not empty strings.\n *\n * @example\n * ```ts\n * const params = { id: '123', name: '' };\n * assertParams(params, ['id']); // Does nothing\n * assertParams(params, ['id', 'name'], 'UserUpdate'); // Throws: Missing required parameter: \"name\" in \"UserUpdate\"\n * ```\n *\n * @param params - The object containing the parameters to check.\n * @param keys - An array of keys that must be present and non-empty in the params object.\n * @param [name] - An optional name for the context of the assertion (e.g., function name).\n * @param [options] - Assertion options.\n * @param [options.type] - The error class to throw (default: `Error`).\n * @param [options.bypass] - If `true`, logs a warning instead of throwing an error.\n *\n * @throws {Error} If any of the required keys are missing or are empty strings.\n */\nexport function assertParams<T extends object, K extends keyof T>(\n params: T,\n keys: K[],\n name?: string,\n options: { type?: ErrorConstructor; bypass?: boolean } = {},\n): asserts params is T & Required<Pick<T, K>> {\n assert(!!params, 'Missing parameters object', options);\n\n const missing = keys.filter((key) => params[key] === undefined || params[key] === null || params[key] === '');\n\n if (missing.length > 0) {\n const context = name ? ` in \"${name}\"` : '';\n const keysStr = missing.map((key) => `\"${String(key)}\"`).join(', ');\n const message = `Missing required parameter${missing.length > 1 ? 's' : ''}: ${keysStr}${context}`;\n\n assert(false, message, options);\n }\n}\n"],"names":["assertParams","params","keys","name","options","assert","missing","key","context","keysStr","message"],"mappings":"gHAqBO,SAASA,EACdC,EACAC,EACAC,EACAC,EAAyD,CAAA,EACb,CAC5CC,EAAAA,OAAO,CAAC,CAACJ,EAAQ,4BAA6BG,CAAO,EAErD,MAAME,EAAUJ,EAAK,OAAQK,GAAQN,EAAOM,CAAG,IAAM,QAAaN,EAAOM,CAAG,IAAM,MAAQN,EAAOM,CAAG,IAAM,EAAE,EAE5G,GAAID,EAAQ,OAAS,EAAG,CACtB,MAAME,EAAUL,EAAO,QAAQA,CAAI,IAAM,GACnCM,EAAUH,EAAQ,IAAKC,GAAQ,IAAI,OAAOA,CAAG,CAAC,GAAG,EAAE,KAAK,IAAI,EAC5DG,EAAU,6BAA6BJ,EAAQ,OAAS,EAAI,IAAM,EAAE,KAAKG,CAAO,GAAGD,CAAO,GAEhGH,SAAO,GAAOK,EAASN,CAAO,CAChC,CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { assert as r } from "./assert.js";
|
|
2
|
+
function $(s, o, i, n = {}) {
|
|
3
|
+
r(!!s, "Missing parameters object", n);
|
|
4
|
+
const e = o.filter((t) => s[t] === void 0 || s[t] === null || s[t] === "");
|
|
5
|
+
if (e.length > 0) {
|
|
6
|
+
const t = i ? ` in "${i}"` : "", c = e.map((l) => `"${String(l)}"`).join(", "), g = `Missing required parameter${e.length > 1 ? "s" : ""}: ${c}${t}`;
|
|
7
|
+
r(!1, g, n);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
$ as assertParams
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=assertParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertParams.js","sources":["../../src/function/assertParams.ts"],"sourcesContent":["import { assert } from './assert';\n\n/**\n * Asserts that the specified keys are present in the params object and are not empty strings.\n *\n * @example\n * ```ts\n * const params = { id: '123', name: '' };\n * assertParams(params, ['id']); // Does nothing\n * assertParams(params, ['id', 'name'], 'UserUpdate'); // Throws: Missing required parameter: \"name\" in \"UserUpdate\"\n * ```\n *\n * @param params - The object containing the parameters to check.\n * @param keys - An array of keys that must be present and non-empty in the params object.\n * @param [name] - An optional name for the context of the assertion (e.g., function name).\n * @param [options] - Assertion options.\n * @param [options.type] - The error class to throw (default: `Error`).\n * @param [options.bypass] - If `true`, logs a warning instead of throwing an error.\n *\n * @throws {Error} If any of the required keys are missing or are empty strings.\n */\nexport function assertParams<T extends object, K extends keyof T>(\n params: T,\n keys: K[],\n name?: string,\n options: { type?: ErrorConstructor; bypass?: boolean } = {},\n): asserts params is T & Required<Pick<T, K>> {\n assert(!!params, 'Missing parameters object', options);\n\n const missing = keys.filter((key) => params[key] === undefined || params[key] === null || params[key] === '');\n\n if (missing.length > 0) {\n const context = name ? ` in \"${name}\"` : '';\n const keysStr = missing.map((key) => `\"${String(key)}\"`).join(', ');\n const message = `Missing required parameter${missing.length > 1 ? 's' : ''}: ${keysStr}${context}`;\n\n assert(false, message, options);\n }\n}\n"],"names":["assertParams","params","keys","name","options","assert","missing","key","context","keysStr","message"],"mappings":";AAqBO,SAASA,EACdC,GACAC,GACAC,GACAC,IAAyD,CAAA,GACb;AAC5C,EAAAC,EAAO,CAAC,CAACJ,GAAQ,6BAA6BG,CAAO;AAErD,QAAME,IAAUJ,EAAK,OAAO,CAACK,MAAQN,EAAOM,CAAG,MAAM,UAAaN,EAAOM,CAAG,MAAM,QAAQN,EAAOM,CAAG,MAAM,EAAE;AAE5G,MAAID,EAAQ,SAAS,GAAG;AACtB,UAAME,IAAUL,IAAO,QAAQA,CAAI,MAAM,IACnCM,IAAUH,EAAQ,IAAI,CAACC,MAAQ,IAAI,OAAOA,CAAG,CAAC,GAAG,EAAE,KAAK,IAAI,GAC5DG,IAAU,6BAA6BJ,EAAQ,SAAS,IAAI,MAAM,EAAE,KAAKG,CAAO,GAAGD,CAAO;AAEhG,IAAAH,EAAO,IAAOK,GAASN,CAAO;AAAA,EAChC;AACF;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../logit/dist/logit.cjs"),c=require("./predict.cjs"),u=require("./retry.cjs");async function s(t,{silent:e=!1,retries:r=0,timeout:i=7e3,identifier:a=t.name||"anonymous function"}={}){try{return await u.retry(()=>c.predict(()=>t(),{timeout:i}),{times:r+1})}catch(o){e||n.Logit.error(`attempt(${a}) -> all attempts failed`,{cause:o});return}}exports.attempt=s;
|
|
2
|
+
//# sourceMappingURL=attempt.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attempt.cjs","sources":["../../src/function/attempt.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport type { Fn } from '../types';\nimport { predict } from './predict';\nimport { retry } from './retry';\n\ntype AttemptOptions = {\n identifier?: string;\n retries?: number;\n silent?: boolean;\n timeout?: number;\n};\n\n/**\n * Attempts to execute a function with advanced error handling and retry logic.\n *\n * @example\n * ```ts\n * const unreliableFunction = async () => {\n * if (Math.random() < 0.7) throw new Error ('Random failure');\n * return 'Success!';\n * };\n *\n * await attempt(\n * unreliableFunction,\n * { retries: 3, silent: false, timeout: 5000 }); // Success! (or undefined if all attempts failed)\n * ```\n *\n * @param fn - The function to be executed.\n * @param [options] - Configuration options for the attempt.\n * @param [options.identifier] - Custom identifier for logging purposes.\n * @param [options.retries=0] - Number of retry attempts if the function fails.\n * @param [options.silent=false] - If true, suppresses error logging.\n * @param [options.timeout=7000] - Timeout in milliseconds for function execution.\n *\n * @returns The result of the function or undefined if it failed.\n */\nexport async function attempt<T extends Fn, R = Awaited<ReturnType<T>>>(\n fn: T,\n { silent = false, retries = 0, timeout = 7000, identifier = fn.name || 'anonymous function' }: AttemptOptions = {},\n): Promise<R | undefined> {\n try {\n return await retry(() => predict<R>(() => fn(), { timeout }), { times: retries + 1 });\n } catch (err) {\n if (!silent) {\n Logit.error(`attempt(${identifier}) -> all attempts failed`, { cause: err });\n }\n return undefined;\n }\n}\n"],"names":["attempt","fn","silent","retries","timeout","identifier","retry","predict","err","Logit"],"mappings":"+KAoCA,eAAsBA,EACpBC,EACA,CAAE,OAAAC,EAAS,GAAO,QAAAC,EAAU,EAAG,QAAAC,EAAU,IAAM,WAAAC,EAAaJ,EAAG,MAAQ,oBAAA,EAAyC,CAAA,EACxF,CACxB,GAAI,CACF,OAAO,MAAMK,EAAAA,MAAM,IAAMC,EAAAA,QAAW,IAAMN,EAAA,EAAM,CAAE,QAAAG,CAAA,CAAS,EAAG,CAAE,MAAOD,EAAU,EAAG,CACtF,OAASK,EAAK,CACPN,GACHO,QAAM,MAAM,WAAWJ,CAAU,2BAA4B,CAAE,MAAOG,EAAK,EAE7E,MACF,CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Logit as m } from "../logit/dist/logit.js";
|
|
2
|
+
import { predict as n } from "./predict.js";
|
|
3
|
+
import { retry as p } from "./retry.js";
|
|
4
|
+
async function u(t, { silent: r = !1, retries: e = 0, timeout: a = 7e3, identifier: o = t.name || "anonymous function" } = {}) {
|
|
5
|
+
try {
|
|
6
|
+
return await p(() => n(() => t(), { timeout: a }), { times: e + 1 });
|
|
7
|
+
} catch (i) {
|
|
8
|
+
r || m.error(`attempt(${o}) -> all attempts failed`, { cause: i });
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
u as attempt
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=attempt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attempt.js","sources":["../../src/function/attempt.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport type { Fn } from '../types';\nimport { predict } from './predict';\nimport { retry } from './retry';\n\ntype AttemptOptions = {\n identifier?: string;\n retries?: number;\n silent?: boolean;\n timeout?: number;\n};\n\n/**\n * Attempts to execute a function with advanced error handling and retry logic.\n *\n * @example\n * ```ts\n * const unreliableFunction = async () => {\n * if (Math.random() < 0.7) throw new Error ('Random failure');\n * return 'Success!';\n * };\n *\n * await attempt(\n * unreliableFunction,\n * { retries: 3, silent: false, timeout: 5000 }); // Success! (or undefined if all attempts failed)\n * ```\n *\n * @param fn - The function to be executed.\n * @param [options] - Configuration options for the attempt.\n * @param [options.identifier] - Custom identifier for logging purposes.\n * @param [options.retries=0] - Number of retry attempts if the function fails.\n * @param [options.silent=false] - If true, suppresses error logging.\n * @param [options.timeout=7000] - Timeout in milliseconds for function execution.\n *\n * @returns The result of the function or undefined if it failed.\n */\nexport async function attempt<T extends Fn, R = Awaited<ReturnType<T>>>(\n fn: T,\n { silent = false, retries = 0, timeout = 7000, identifier = fn.name || 'anonymous function' }: AttemptOptions = {},\n): Promise<R | undefined> {\n try {\n return await retry(() => predict<R>(() => fn(), { timeout }), { times: retries + 1 });\n } catch (err) {\n if (!silent) {\n Logit.error(`attempt(${identifier}) -> all attempts failed`, { cause: err });\n }\n return undefined;\n }\n}\n"],"names":["attempt","fn","silent","retries","timeout","identifier","retry","predict","err","Logit"],"mappings":";;;AAoCA,eAAsBA,EACpBC,GACA,EAAE,QAAAC,IAAS,IAAO,SAAAC,IAAU,GAAG,SAAAC,IAAU,KAAM,YAAAC,IAAaJ,EAAG,QAAQ,qBAAA,IAAyC,CAAA,GACxF;AACxB,MAAI;AACF,WAAO,MAAMK,EAAM,MAAMC,EAAW,MAAMN,EAAA,GAAM,EAAE,SAAAG,EAAA,CAAS,GAAG,EAAE,OAAOD,IAAU,GAAG;AAAA,EACtF,SAASK,GAAK;AACZ,IAAKN,KACHO,EAAM,MAAM,WAAWJ,CAAU,4BAA4B,EAAE,OAAOG,GAAK;AAE7E;AAAA,EACF;AACF;"}
|