@depup/remeda 2.33.6-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/changes.json +5 -0
- package/dist/add.cjs +2 -0
- package/dist/add.cjs.map +1 -0
- package/dist/add.js +2 -0
- package/dist/add.js.map +1 -0
- package/dist/addProp.cjs +2 -0
- package/dist/addProp.cjs.map +1 -0
- package/dist/addProp.js +2 -0
- package/dist/addProp.js.map +1 -0
- package/dist/allPass.cjs +2 -0
- package/dist/allPass.cjs.map +1 -0
- package/dist/allPass.js +2 -0
- package/dist/allPass.js.map +1 -0
- package/dist/anyPass.cjs +2 -0
- package/dist/anyPass.cjs.map +1 -0
- package/dist/anyPass.js +2 -0
- package/dist/anyPass.js.map +1 -0
- package/dist/binarySearchCutoffIndex-CLQRwIY1.js +2 -0
- package/dist/binarySearchCutoffIndex-CLQRwIY1.js.map +1 -0
- package/dist/binarySearchCutoffIndex-DdLPjZiy.cjs +2 -0
- package/dist/binarySearchCutoffIndex-DdLPjZiy.cjs.map +1 -0
- package/dist/capitalize.cjs +2 -0
- package/dist/capitalize.cjs.map +1 -0
- package/dist/capitalize.js +2 -0
- package/dist/capitalize.js.map +1 -0
- package/dist/ceil.cjs +2 -0
- package/dist/ceil.cjs.map +1 -0
- package/dist/ceil.js +2 -0
- package/dist/ceil.js.map +1 -0
- package/dist/chunk.cjs +2 -0
- package/dist/chunk.cjs.map +1 -0
- package/dist/chunk.js +2 -0
- package/dist/chunk.js.map +1 -0
- package/dist/clamp.cjs +2 -0
- package/dist/clamp.cjs.map +1 -0
- package/dist/clamp.js +2 -0
- package/dist/clamp.js.map +1 -0
- package/dist/clone.cjs +2 -0
- package/dist/clone.cjs.map +1 -0
- package/dist/clone.js +2 -0
- package/dist/clone.js.map +1 -0
- package/dist/concat.cjs +2 -0
- package/dist/concat.cjs.map +1 -0
- package/dist/concat.js +2 -0
- package/dist/concat.js.map +1 -0
- package/dist/conditional.cjs +2 -0
- package/dist/conditional.cjs.map +1 -0
- package/dist/conditional.js +2 -0
- package/dist/conditional.js.map +1 -0
- package/dist/constant.cjs +2 -0
- package/dist/constant.cjs.map +1 -0
- package/dist/constant.js +2 -0
- package/dist/constant.js.map +1 -0
- package/dist/countBy.cjs +2 -0
- package/dist/countBy.cjs.map +1 -0
- package/dist/countBy.js +2 -0
- package/dist/countBy.js.map +1 -0
- package/dist/debounce.cjs +2 -0
- package/dist/debounce.cjs.map +1 -0
- package/dist/debounce.js +2 -0
- package/dist/debounce.js.map +1 -0
- package/dist/defaultTo.cjs +2 -0
- package/dist/defaultTo.cjs.map +1 -0
- package/dist/defaultTo.js +2 -0
- package/dist/defaultTo.js.map +1 -0
- package/dist/difference.cjs +2 -0
- package/dist/difference.cjs.map +1 -0
- package/dist/difference.js +2 -0
- package/dist/difference.js.map +1 -0
- package/dist/differenceWith.cjs +2 -0
- package/dist/differenceWith.cjs.map +1 -0
- package/dist/differenceWith.js +2 -0
- package/dist/differenceWith.js.map +1 -0
- package/dist/divide.cjs +2 -0
- package/dist/divide.cjs.map +1 -0
- package/dist/divide.js +2 -0
- package/dist/divide.js.map +1 -0
- package/dist/doNothing.cjs +2 -0
- package/dist/doNothing.cjs.map +1 -0
- package/dist/doNothing.js +2 -0
- package/dist/doNothing.js.map +1 -0
- package/dist/drop.cjs +2 -0
- package/dist/drop.cjs.map +1 -0
- package/dist/drop.js +2 -0
- package/dist/drop.js.map +1 -0
- package/dist/dropFirstBy.cjs +2 -0
- package/dist/dropFirstBy.cjs.map +1 -0
- package/dist/dropFirstBy.js +2 -0
- package/dist/dropFirstBy.js.map +1 -0
- package/dist/dropLast.cjs +2 -0
- package/dist/dropLast.cjs.map +1 -0
- package/dist/dropLast.js +2 -0
- package/dist/dropLast.js.map +1 -0
- package/dist/dropLastWhile.cjs +2 -0
- package/dist/dropLastWhile.cjs.map +1 -0
- package/dist/dropLastWhile.js +2 -0
- package/dist/dropLastWhile.js.map +1 -0
- package/dist/dropWhile.cjs +2 -0
- package/dist/dropWhile.cjs.map +1 -0
- package/dist/dropWhile.js +2 -0
- package/dist/dropWhile.js.map +1 -0
- package/dist/endsWith.cjs +2 -0
- package/dist/endsWith.cjs.map +1 -0
- package/dist/endsWith.js +2 -0
- package/dist/endsWith.js.map +1 -0
- package/dist/entries.cjs +2 -0
- package/dist/entries.cjs.map +1 -0
- package/dist/entries.js +2 -0
- package/dist/entries.js.map +1 -0
- package/dist/evolve.cjs +2 -0
- package/dist/evolve.cjs.map +1 -0
- package/dist/evolve.js +2 -0
- package/dist/evolve.js.map +1 -0
- package/dist/filter.cjs +2 -0
- package/dist/filter.cjs.map +1 -0
- package/dist/filter.js +2 -0
- package/dist/filter.js.map +1 -0
- package/dist/find.cjs +2 -0
- package/dist/find.cjs.map +1 -0
- package/dist/find.js +2 -0
- package/dist/find.js.map +1 -0
- package/dist/findIndex.cjs +2 -0
- package/dist/findIndex.cjs.map +1 -0
- package/dist/findIndex.js +2 -0
- package/dist/findIndex.js.map +1 -0
- package/dist/findLast.cjs +2 -0
- package/dist/findLast.cjs.map +1 -0
- package/dist/findLast.js +2 -0
- package/dist/findLast.js.map +1 -0
- package/dist/findLastIndex.cjs +2 -0
- package/dist/findLastIndex.cjs.map +1 -0
- package/dist/findLastIndex.js +2 -0
- package/dist/findLastIndex.js.map +1 -0
- package/dist/first.cjs +2 -0
- package/dist/first.cjs.map +1 -0
- package/dist/first.js +2 -0
- package/dist/first.js.map +1 -0
- package/dist/firstBy.cjs +2 -0
- package/dist/firstBy.cjs.map +1 -0
- package/dist/firstBy.js +2 -0
- package/dist/firstBy.js.map +1 -0
- package/dist/flat.cjs +2 -0
- package/dist/flat.cjs.map +1 -0
- package/dist/flat.js +2 -0
- package/dist/flat.js.map +1 -0
- package/dist/flatMap.cjs +2 -0
- package/dist/flatMap.cjs.map +1 -0
- package/dist/flatMap.js +2 -0
- package/dist/flatMap.js.map +1 -0
- package/dist/floor.cjs +2 -0
- package/dist/floor.cjs.map +1 -0
- package/dist/floor.js +2 -0
- package/dist/floor.js.map +1 -0
- package/dist/forEach.cjs +2 -0
- package/dist/forEach.cjs.map +1 -0
- package/dist/forEach.js +2 -0
- package/dist/forEach.js.map +1 -0
- package/dist/forEachObj.cjs +2 -0
- package/dist/forEachObj.cjs.map +1 -0
- package/dist/forEachObj.js +2 -0
- package/dist/forEachObj.js.map +1 -0
- package/dist/fromEntries.cjs +2 -0
- package/dist/fromEntries.cjs.map +1 -0
- package/dist/fromEntries.js +2 -0
- package/dist/fromEntries.js.map +1 -0
- package/dist/fromKeys.cjs +2 -0
- package/dist/fromKeys.cjs.map +1 -0
- package/dist/fromKeys.js +2 -0
- package/dist/fromKeys.js.map +1 -0
- package/dist/funnel.cjs +2 -0
- package/dist/funnel.cjs.map +1 -0
- package/dist/funnel.js +2 -0
- package/dist/funnel.js.map +1 -0
- package/dist/groupBy.cjs +2 -0
- package/dist/groupBy.cjs.map +1 -0
- package/dist/groupBy.js +2 -0
- package/dist/groupBy.js.map +1 -0
- package/dist/groupByProp.cjs +2 -0
- package/dist/groupByProp.cjs.map +1 -0
- package/dist/groupByProp.js +2 -0
- package/dist/groupByProp.js.map +1 -0
- package/dist/hasAtLeast.cjs +2 -0
- package/dist/hasAtLeast.cjs.map +1 -0
- package/dist/hasAtLeast.js +2 -0
- package/dist/hasAtLeast.js.map +1 -0
- package/dist/hasSubObject.cjs +2 -0
- package/dist/hasSubObject.cjs.map +1 -0
- package/dist/hasSubObject.js +2 -0
- package/dist/hasSubObject.js.map +1 -0
- package/dist/heap-14xVkDB1.cjs +2 -0
- package/dist/heap-14xVkDB1.cjs.map +1 -0
- package/dist/heap-OOe_F8_z.js +2 -0
- package/dist/heap-OOe_F8_z.js.map +1 -0
- package/dist/identity.cjs +2 -0
- package/dist/identity.cjs.map +1 -0
- package/dist/identity.js +2 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +11948 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +11948 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/indexBy.cjs +2 -0
- package/dist/indexBy.cjs.map +1 -0
- package/dist/indexBy.js +2 -0
- package/dist/indexBy.js.map +1 -0
- package/dist/intersection.cjs +2 -0
- package/dist/intersection.cjs.map +1 -0
- package/dist/intersection.js +2 -0
- package/dist/intersection.js.map +1 -0
- package/dist/intersectionWith.cjs +2 -0
- package/dist/intersectionWith.cjs.map +1 -0
- package/dist/intersectionWith.js +2 -0
- package/dist/intersectionWith.js.map +1 -0
- package/dist/invert.cjs +2 -0
- package/dist/invert.cjs.map +1 -0
- package/dist/invert.js +2 -0
- package/dist/invert.js.map +1 -0
- package/dist/isArray.cjs +2 -0
- package/dist/isArray.cjs.map +1 -0
- package/dist/isArray.js +2 -0
- package/dist/isArray.js.map +1 -0
- package/dist/isBigInt.cjs +2 -0
- package/dist/isBigInt.cjs.map +1 -0
- package/dist/isBigInt.js +2 -0
- package/dist/isBigInt.js.map +1 -0
- package/dist/isBoolean.cjs +2 -0
- package/dist/isBoolean.cjs.map +1 -0
- package/dist/isBoolean.js +2 -0
- package/dist/isBoolean.js.map +1 -0
- package/dist/isDate.cjs +2 -0
- package/dist/isDate.cjs.map +1 -0
- package/dist/isDate.js +2 -0
- package/dist/isDate.js.map +1 -0
- package/dist/isDeepEqual.cjs +2 -0
- package/dist/isDeepEqual.cjs.map +1 -0
- package/dist/isDeepEqual.js +2 -0
- package/dist/isDeepEqual.js.map +1 -0
- package/dist/isDefined.cjs +2 -0
- package/dist/isDefined.cjs.map +1 -0
- package/dist/isDefined.js +2 -0
- package/dist/isDefined.js.map +1 -0
- package/dist/isEmpty.cjs +2 -0
- package/dist/isEmpty.cjs.map +1 -0
- package/dist/isEmpty.js +2 -0
- package/dist/isEmpty.js.map +1 -0
- package/dist/isEmptyish.cjs +2 -0
- package/dist/isEmptyish.cjs.map +1 -0
- package/dist/isEmptyish.js +2 -0
- package/dist/isEmptyish.js.map +1 -0
- package/dist/isError.cjs +2 -0
- package/dist/isError.cjs.map +1 -0
- package/dist/isError.js +2 -0
- package/dist/isError.js.map +1 -0
- package/dist/isFunction.cjs +2 -0
- package/dist/isFunction.cjs.map +1 -0
- package/dist/isFunction.js +2 -0
- package/dist/isFunction.js.map +1 -0
- package/dist/isIncludedIn.cjs +2 -0
- package/dist/isIncludedIn.cjs.map +1 -0
- package/dist/isIncludedIn.js +2 -0
- package/dist/isIncludedIn.js.map +1 -0
- package/dist/isNonNull.cjs +2 -0
- package/dist/isNonNull.cjs.map +1 -0
- package/dist/isNonNull.js +2 -0
- package/dist/isNonNull.js.map +1 -0
- package/dist/isNonNullish.cjs +2 -0
- package/dist/isNonNullish.cjs.map +1 -0
- package/dist/isNonNullish.js +2 -0
- package/dist/isNonNullish.js.map +1 -0
- package/dist/isNot.cjs +2 -0
- package/dist/isNot.cjs.map +1 -0
- package/dist/isNot.js +2 -0
- package/dist/isNot.js.map +1 -0
- package/dist/isNullish.cjs +2 -0
- package/dist/isNullish.cjs.map +1 -0
- package/dist/isNullish.js +2 -0
- package/dist/isNullish.js.map +1 -0
- package/dist/isNumber.cjs +2 -0
- package/dist/isNumber.cjs.map +1 -0
- package/dist/isNumber.js +2 -0
- package/dist/isNumber.js.map +1 -0
- package/dist/isObjectType.cjs +2 -0
- package/dist/isObjectType.cjs.map +1 -0
- package/dist/isObjectType.js +2 -0
- package/dist/isObjectType.js.map +1 -0
- package/dist/isPlainObject.cjs +2 -0
- package/dist/isPlainObject.cjs.map +1 -0
- package/dist/isPlainObject.js +2 -0
- package/dist/isPlainObject.js.map +1 -0
- package/dist/isPromise.cjs +2 -0
- package/dist/isPromise.cjs.map +1 -0
- package/dist/isPromise.js +2 -0
- package/dist/isPromise.js.map +1 -0
- package/dist/isShallowEqual.cjs +2 -0
- package/dist/isShallowEqual.cjs.map +1 -0
- package/dist/isShallowEqual.js +2 -0
- package/dist/isShallowEqual.js.map +1 -0
- package/dist/isStrictEqual.cjs +2 -0
- package/dist/isStrictEqual.cjs.map +1 -0
- package/dist/isStrictEqual.js +2 -0
- package/dist/isStrictEqual.js.map +1 -0
- package/dist/isString.cjs +2 -0
- package/dist/isString.cjs.map +1 -0
- package/dist/isString.js +2 -0
- package/dist/isString.js.map +1 -0
- package/dist/isSymbol.cjs +2 -0
- package/dist/isSymbol.cjs.map +1 -0
- package/dist/isSymbol.js +2 -0
- package/dist/isSymbol.js.map +1 -0
- package/dist/isTruthy.cjs +2 -0
- package/dist/isTruthy.cjs.map +1 -0
- package/dist/isTruthy.js +2 -0
- package/dist/isTruthy.js.map +1 -0
- package/dist/join.cjs +2 -0
- package/dist/join.cjs.map +1 -0
- package/dist/join.js +2 -0
- package/dist/join.js.map +1 -0
- package/dist/keys.cjs +2 -0
- package/dist/keys.cjs.map +1 -0
- package/dist/keys.js +2 -0
- package/dist/keys.js.map +1 -0
- package/dist/last.cjs +2 -0
- package/dist/last.cjs.map +1 -0
- package/dist/last.js +2 -0
- package/dist/last.js.map +1 -0
- package/dist/lazyDataLastImpl-DdpJofHC.cjs +2 -0
- package/dist/lazyDataLastImpl-DdpJofHC.cjs.map +1 -0
- package/dist/lazyDataLastImpl-DtF3cihj.js +2 -0
- package/dist/lazyDataLastImpl-DtF3cihj.js.map +1 -0
- package/dist/length.cjs +2 -0
- package/dist/length.cjs.map +1 -0
- package/dist/length.js +2 -0
- package/dist/length.js.map +1 -0
- package/dist/map.cjs +2 -0
- package/dist/map.cjs.map +1 -0
- package/dist/map.js +2 -0
- package/dist/map.js.map +1 -0
- package/dist/mapKeys.cjs +2 -0
- package/dist/mapKeys.cjs.map +1 -0
- package/dist/mapKeys.js +2 -0
- package/dist/mapKeys.js.map +1 -0
- package/dist/mapToObj.cjs +2 -0
- package/dist/mapToObj.cjs.map +1 -0
- package/dist/mapToObj.js +2 -0
- package/dist/mapToObj.js.map +1 -0
- package/dist/mapValues.cjs +2 -0
- package/dist/mapValues.cjs.map +1 -0
- package/dist/mapValues.js +2 -0
- package/dist/mapValues.js.map +1 -0
- package/dist/mapWithFeedback.cjs +2 -0
- package/dist/mapWithFeedback.cjs.map +1 -0
- package/dist/mapWithFeedback.js +2 -0
- package/dist/mapWithFeedback.js.map +1 -0
- package/dist/mean.cjs +2 -0
- package/dist/mean.cjs.map +1 -0
- package/dist/mean.js +2 -0
- package/dist/mean.js.map +1 -0
- package/dist/meanBy.cjs +2 -0
- package/dist/meanBy.cjs.map +1 -0
- package/dist/meanBy.js +2 -0
- package/dist/meanBy.js.map +1 -0
- package/dist/median.cjs +2 -0
- package/dist/median.cjs.map +1 -0
- package/dist/median.js +2 -0
- package/dist/median.js.map +1 -0
- package/dist/merge.cjs +2 -0
- package/dist/merge.cjs.map +1 -0
- package/dist/merge.js +2 -0
- package/dist/merge.js.map +1 -0
- package/dist/mergeAll.cjs +2 -0
- package/dist/mergeAll.cjs.map +1 -0
- package/dist/mergeAll.js +2 -0
- package/dist/mergeAll.js.map +1 -0
- package/dist/mergeDeep.cjs +2 -0
- package/dist/mergeDeep.cjs.map +1 -0
- package/dist/mergeDeep.js +2 -0
- package/dist/mergeDeep.js.map +1 -0
- package/dist/multiply.cjs +2 -0
- package/dist/multiply.cjs.map +1 -0
- package/dist/multiply.js +2 -0
- package/dist/multiply.js.map +1 -0
- package/dist/nthBy.cjs +2 -0
- package/dist/nthBy.cjs.map +1 -0
- package/dist/nthBy.js +2 -0
- package/dist/nthBy.js.map +1 -0
- package/dist/objOf.cjs +2 -0
- package/dist/objOf.cjs.map +1 -0
- package/dist/objOf.js +2 -0
- package/dist/objOf.js.map +1 -0
- package/dist/omit.cjs +2 -0
- package/dist/omit.cjs.map +1 -0
- package/dist/omit.js +2 -0
- package/dist/omit.js.map +1 -0
- package/dist/omitBy.cjs +2 -0
- package/dist/omitBy.cjs.map +1 -0
- package/dist/omitBy.js +2 -0
- package/dist/omitBy.js.map +1 -0
- package/dist/once.cjs +2 -0
- package/dist/once.cjs.map +1 -0
- package/dist/once.js +2 -0
- package/dist/once.js.map +1 -0
- package/dist/only.cjs +2 -0
- package/dist/only.cjs.map +1 -0
- package/dist/only.js +2 -0
- package/dist/only.js.map +1 -0
- package/dist/partialBind.cjs +2 -0
- package/dist/partialBind.cjs.map +1 -0
- package/dist/partialBind.js +2 -0
- package/dist/partialBind.js.map +1 -0
- package/dist/partialLastBind.cjs +2 -0
- package/dist/partialLastBind.cjs.map +1 -0
- package/dist/partialLastBind.js +2 -0
- package/dist/partialLastBind.js.map +1 -0
- package/dist/partition.cjs +2 -0
- package/dist/partition.cjs.map +1 -0
- package/dist/partition.js +2 -0
- package/dist/partition.js.map +1 -0
- package/dist/pathOr.cjs +2 -0
- package/dist/pathOr.cjs.map +1 -0
- package/dist/pathOr.js +2 -0
- package/dist/pathOr.js.map +1 -0
- package/dist/pick.cjs +2 -0
- package/dist/pick.cjs.map +1 -0
- package/dist/pick.js +2 -0
- package/dist/pick.js.map +1 -0
- package/dist/pickBy.cjs +2 -0
- package/dist/pickBy.cjs.map +1 -0
- package/dist/pickBy.js +2 -0
- package/dist/pickBy.js.map +1 -0
- package/dist/pipe.cjs +2 -0
- package/dist/pipe.cjs.map +1 -0
- package/dist/pipe.js +2 -0
- package/dist/pipe.js.map +1 -0
- package/dist/piped.cjs +2 -0
- package/dist/piped.cjs.map +1 -0
- package/dist/piped.js +2 -0
- package/dist/piped.js.map +1 -0
- package/dist/product.cjs +2 -0
- package/dist/product.cjs.map +1 -0
- package/dist/product.js +2 -0
- package/dist/product.js.map +1 -0
- package/dist/prop.cjs +2 -0
- package/dist/prop.cjs.map +1 -0
- package/dist/prop.js +2 -0
- package/dist/prop.js.map +1 -0
- package/dist/pullObject.cjs +2 -0
- package/dist/pullObject.cjs.map +1 -0
- package/dist/pullObject.js +2 -0
- package/dist/pullObject.js.map +1 -0
- package/dist/purry.cjs +2 -0
- package/dist/purry.cjs.map +1 -0
- package/dist/purry.js +2 -0
- package/dist/purry.js.map +1 -0
- package/dist/purryFromLazy-B-_oTxzb.js +2 -0
- package/dist/purryFromLazy-B-_oTxzb.js.map +1 -0
- package/dist/purryFromLazy-CwB5T8yd.cjs +2 -0
- package/dist/purryFromLazy-CwB5T8yd.cjs.map +1 -0
- package/dist/purryOn-D4wFIFMT.js +2 -0
- package/dist/purryOn-D4wFIFMT.js.map +1 -0
- package/dist/purryOn-DdnETb-0.cjs +2 -0
- package/dist/purryOn-DdnETb-0.cjs.map +1 -0
- package/dist/purryOrderRules-4JgY6z4X.js +2 -0
- package/dist/purryOrderRules-4JgY6z4X.js.map +1 -0
- package/dist/purryOrderRules-B8pzD03D.cjs +2 -0
- package/dist/purryOrderRules-B8pzD03D.cjs.map +1 -0
- package/dist/quickSelect-B4eZ0JeB.js +2 -0
- package/dist/quickSelect-B4eZ0JeB.js.map +1 -0
- package/dist/quickSelect-BwH5h4uh.cjs +2 -0
- package/dist/quickSelect-BwH5h4uh.cjs.map +1 -0
- package/dist/randomBigInt.cjs +2 -0
- package/dist/randomBigInt.cjs.map +1 -0
- package/dist/randomBigInt.js +2 -0
- package/dist/randomBigInt.js.map +1 -0
- package/dist/randomInteger.cjs +2 -0
- package/dist/randomInteger.cjs.map +1 -0
- package/dist/randomInteger.js +2 -0
- package/dist/randomInteger.js.map +1 -0
- package/dist/randomString.cjs +2 -0
- package/dist/randomString.cjs.map +1 -0
- package/dist/randomString.js +2 -0
- package/dist/randomString.js.map +1 -0
- package/dist/range.cjs +2 -0
- package/dist/range.cjs.map +1 -0
- package/dist/range.js +2 -0
- package/dist/range.js.map +1 -0
- package/dist/rankBy.cjs +2 -0
- package/dist/rankBy.cjs.map +1 -0
- package/dist/rankBy.js +2 -0
- package/dist/rankBy.js.map +1 -0
- package/dist/reduce.cjs +2 -0
- package/dist/reduce.cjs.map +1 -0
- package/dist/reduce.js +2 -0
- package/dist/reduce.js.map +1 -0
- package/dist/reverse.cjs +2 -0
- package/dist/reverse.cjs.map +1 -0
- package/dist/reverse.js +2 -0
- package/dist/reverse.js.map +1 -0
- package/dist/round.cjs +2 -0
- package/dist/round.cjs.map +1 -0
- package/dist/round.js +2 -0
- package/dist/round.js.map +1 -0
- package/dist/sample.cjs +2 -0
- package/dist/sample.cjs.map +1 -0
- package/dist/sample.js +2 -0
- package/dist/sample.js.map +1 -0
- package/dist/set.cjs +2 -0
- package/dist/set.cjs.map +1 -0
- package/dist/set.js +2 -0
- package/dist/set.js.map +1 -0
- package/dist/setPath.cjs +2 -0
- package/dist/setPath.cjs.map +1 -0
- package/dist/setPath.js +2 -0
- package/dist/setPath.js.map +1 -0
- package/dist/shuffle.cjs +2 -0
- package/dist/shuffle.cjs.map +1 -0
- package/dist/shuffle.js +2 -0
- package/dist/shuffle.js.map +1 -0
- package/dist/sliceString.cjs +2 -0
- package/dist/sliceString.cjs.map +1 -0
- package/dist/sliceString.js +2 -0
- package/dist/sliceString.js.map +1 -0
- package/dist/sort.cjs +2 -0
- package/dist/sort.cjs.map +1 -0
- package/dist/sort.js +2 -0
- package/dist/sort.js.map +1 -0
- package/dist/sortBy.cjs +2 -0
- package/dist/sortBy.cjs.map +1 -0
- package/dist/sortBy.js +2 -0
- package/dist/sortBy.js.map +1 -0
- package/dist/sortedIndex.cjs +2 -0
- package/dist/sortedIndex.cjs.map +1 -0
- package/dist/sortedIndex.js +2 -0
- package/dist/sortedIndex.js.map +1 -0
- package/dist/sortedIndexBy.cjs +2 -0
- package/dist/sortedIndexBy.cjs.map +1 -0
- package/dist/sortedIndexBy.js +2 -0
- package/dist/sortedIndexBy.js.map +1 -0
- package/dist/sortedIndexWith.cjs +2 -0
- package/dist/sortedIndexWith.cjs.map +1 -0
- package/dist/sortedIndexWith.js +2 -0
- package/dist/sortedIndexWith.js.map +1 -0
- package/dist/sortedLastIndex.cjs +2 -0
- package/dist/sortedLastIndex.cjs.map +1 -0
- package/dist/sortedLastIndex.js +2 -0
- package/dist/sortedLastIndex.js.map +1 -0
- package/dist/sortedLastIndexBy.cjs +2 -0
- package/dist/sortedLastIndexBy.cjs.map +1 -0
- package/dist/sortedLastIndexBy.js +2 -0
- package/dist/sortedLastIndexBy.js.map +1 -0
- package/dist/splice.cjs +2 -0
- package/dist/splice.cjs.map +1 -0
- package/dist/splice.js +2 -0
- package/dist/splice.js.map +1 -0
- package/dist/split.cjs +2 -0
- package/dist/split.cjs.map +1 -0
- package/dist/split.js +2 -0
- package/dist/split.js.map +1 -0
- package/dist/splitAt.cjs +2 -0
- package/dist/splitAt.cjs.map +1 -0
- package/dist/splitAt.js +2 -0
- package/dist/splitAt.js.map +1 -0
- package/dist/splitWhen.cjs +2 -0
- package/dist/splitWhen.cjs.map +1 -0
- package/dist/splitWhen.js +2 -0
- package/dist/splitWhen.js.map +1 -0
- package/dist/startsWith.cjs +2 -0
- package/dist/startsWith.cjs.map +1 -0
- package/dist/startsWith.js +2 -0
- package/dist/startsWith.js.map +1 -0
- package/dist/stringToPath.cjs +2 -0
- package/dist/stringToPath.cjs.map +1 -0
- package/dist/stringToPath.js +2 -0
- package/dist/stringToPath.js.map +1 -0
- package/dist/subtract.cjs +2 -0
- package/dist/subtract.cjs.map +1 -0
- package/dist/subtract.js +2 -0
- package/dist/subtract.js.map +1 -0
- package/dist/sum.cjs +2 -0
- package/dist/sum.cjs.map +1 -0
- package/dist/sum.js +2 -0
- package/dist/sum.js.map +1 -0
- package/dist/sumBy.cjs +2 -0
- package/dist/sumBy.cjs.map +1 -0
- package/dist/sumBy.js +2 -0
- package/dist/sumBy.js.map +1 -0
- package/dist/swapInPlace-BrVgf3c3.js +2 -0
- package/dist/swapInPlace-BrVgf3c3.js.map +1 -0
- package/dist/swapInPlace-IOnMIay9.cjs +2 -0
- package/dist/swapInPlace-IOnMIay9.cjs.map +1 -0
- package/dist/swapIndices.cjs +2 -0
- package/dist/swapIndices.cjs.map +1 -0
- package/dist/swapIndices.js +2 -0
- package/dist/swapIndices.js.map +1 -0
- package/dist/swapProps.cjs +2 -0
- package/dist/swapProps.cjs.map +1 -0
- package/dist/swapProps.js +2 -0
- package/dist/swapProps.js.map +1 -0
- package/dist/take.cjs +2 -0
- package/dist/take.cjs.map +1 -0
- package/dist/take.js +2 -0
- package/dist/take.js.map +1 -0
- package/dist/takeFirstBy.cjs +2 -0
- package/dist/takeFirstBy.cjs.map +1 -0
- package/dist/takeFirstBy.js +2 -0
- package/dist/takeFirstBy.js.map +1 -0
- package/dist/takeLast.cjs +2 -0
- package/dist/takeLast.cjs.map +1 -0
- package/dist/takeLast.js +2 -0
- package/dist/takeLast.js.map +1 -0
- package/dist/takeLastWhile.cjs +2 -0
- package/dist/takeLastWhile.cjs.map +1 -0
- package/dist/takeLastWhile.js +2 -0
- package/dist/takeLastWhile.js.map +1 -0
- package/dist/takeWhile.cjs +2 -0
- package/dist/takeWhile.cjs.map +1 -0
- package/dist/takeWhile.js +2 -0
- package/dist/takeWhile.js.map +1 -0
- package/dist/tap.cjs +2 -0
- package/dist/tap.cjs.map +1 -0
- package/dist/tap.js +2 -0
- package/dist/tap.js.map +1 -0
- package/dist/times.cjs +2 -0
- package/dist/times.cjs.map +1 -0
- package/dist/times.js +2 -0
- package/dist/times.js.map +1 -0
- package/dist/toCamelCase.cjs +2 -0
- package/dist/toCamelCase.cjs.map +1 -0
- package/dist/toCamelCase.js +2 -0
- package/dist/toCamelCase.js.map +1 -0
- package/dist/toKebabCase.cjs +2 -0
- package/dist/toKebabCase.cjs.map +1 -0
- package/dist/toKebabCase.js +2 -0
- package/dist/toKebabCase.js.map +1 -0
- package/dist/toLowerCase.cjs +2 -0
- package/dist/toLowerCase.cjs.map +1 -0
- package/dist/toLowerCase.js +2 -0
- package/dist/toLowerCase.js.map +1 -0
- package/dist/toSingle-qs9PC5sP.js +2 -0
- package/dist/toSingle-qs9PC5sP.js.map +1 -0
- package/dist/toSingle-z9yHVHGr.cjs +2 -0
- package/dist/toSingle-z9yHVHGr.cjs.map +1 -0
- package/dist/toSnakeCase.cjs +2 -0
- package/dist/toSnakeCase.cjs.map +1 -0
- package/dist/toSnakeCase.js +2 -0
- package/dist/toSnakeCase.js.map +1 -0
- package/dist/toTitleCase.cjs +2 -0
- package/dist/toTitleCase.cjs.map +1 -0
- package/dist/toTitleCase.js +2 -0
- package/dist/toTitleCase.js.map +1 -0
- package/dist/toUpperCase.cjs +2 -0
- package/dist/toUpperCase.cjs.map +1 -0
- package/dist/toUpperCase.js +2 -0
- package/dist/toUpperCase.js.map +1 -0
- package/dist/truncate.cjs +2 -0
- package/dist/truncate.cjs.map +1 -0
- package/dist/truncate.js +2 -0
- package/dist/truncate.js.map +1 -0
- package/dist/uncapitalize.cjs +2 -0
- package/dist/uncapitalize.cjs.map +1 -0
- package/dist/uncapitalize.js +2 -0
- package/dist/uncapitalize.js.map +1 -0
- package/dist/unique.cjs +2 -0
- package/dist/unique.cjs.map +1 -0
- package/dist/unique.js +2 -0
- package/dist/unique.js.map +1 -0
- package/dist/uniqueBy.cjs +2 -0
- package/dist/uniqueBy.cjs.map +1 -0
- package/dist/uniqueBy.js +2 -0
- package/dist/uniqueBy.js.map +1 -0
- package/dist/uniqueWith.cjs +2 -0
- package/dist/uniqueWith.cjs.map +1 -0
- package/dist/uniqueWith.js +2 -0
- package/dist/uniqueWith.js.map +1 -0
- package/dist/utilityEvaluators-BQqW5Ir5.js +2 -0
- package/dist/utilityEvaluators-BQqW5Ir5.js.map +1 -0
- package/dist/utilityEvaluators-CW0M8vMV.cjs +2 -0
- package/dist/utilityEvaluators-CW0M8vMV.cjs.map +1 -0
- package/dist/values.cjs +2 -0
- package/dist/values.cjs.map +1 -0
- package/dist/values.js +2 -0
- package/dist/values.js.map +1 -0
- package/dist/when.cjs +2 -0
- package/dist/when.cjs.map +1 -0
- package/dist/when.js +2 -0
- package/dist/when.js.map +1 -0
- package/dist/withPrecision-CDZ-Oor7.js +2 -0
- package/dist/withPrecision-CDZ-Oor7.js.map +1 -0
- package/dist/withPrecision-DED4FjDo.cjs +2 -0
- package/dist/withPrecision-DED4FjDo.cjs.map +1 -0
- package/dist/words-CDCUnuNz.cjs +3 -0
- package/dist/words-CDCUnuNz.cjs.map +1 -0
- package/dist/words-Dv8LmnKC.js +3 -0
- package/dist/words-Dv8LmnKC.js.map +1 -0
- package/dist/zip.cjs +2 -0
- package/dist/zip.cjs.map +1 -0
- package/dist/zip.js +2 -0
- package/dist/zip.js.map +1 -0
- package/dist/zipWith.cjs +2 -0
- package/dist/zipWith.cjs.map +1 -0
- package/dist/zipWith.js +2 -0
- package/dist/zipWith.js.map +1 -0
- package/package.json +104 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.js","names":[],"sources":["../src/product.ts"],"sourcesContent":["import type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport { purry } from \"./purry\";\n\ntype Product<T extends IterableContainer<bigint> | IterableContainer<number>> =\n // Empty arrays would always result in a product of (a non-bigint) 1\n T extends readonly []\n ? 1\n : // Non-empty bigint arrays will always result in a bigint product.\n T extends readonly [bigint, ...(readonly unknown[])]\n ? bigint\n : // But an empty bigint array would result in a non-bigint 1.\n T[number] extends bigint\n ? bigint | 1\n : // Non-bigint arrays are always handled correctly.\n number;\n\n/**\n * Compute the product of the numbers in the array, or return 1 for an empty\n * array.\n *\n * Works for both `number` and `bigint` arrays, but not arrays that contain both\n * types.\n *\n * IMPORTANT: The result for empty arrays would be 1 (`number`) regardless of\n * the type of the array; to avoid adding this to the return type for cases\n * where the array is known to be non-empty you can use `hasAtLeast` or\n * `isEmpty` to guard against this case.\n *\n * @param data - The array of numbers.\n * @signature\n * product(data);\n * @example\n * product([1, 2, 3]); // => 6\n * product([1n, 2n, 3n]); // => 6n\n * product([]); // => 1\n * @dataFirst\n * @category Number\n */\nexport function product<\n T extends IterableContainer<bigint> | IterableContainer<number>,\n>(data: T): Product<T>;\n\n/**\n * Compute the product of the numbers in the array, or return 1 for an empty\n * array.\n *\n * Works for both `number` and `bigint` arrays, but not arrays that contain both\n * types.\n *\n * IMPORTANT: The result for empty arrays would be 1 (`number`) regardless of\n * the type of the array; to avoid adding this to the return type for cases\n * where the array is known to be non-empty you can use `hasAtLeast` or\n * `isEmpty` to guard against this case.\n *\n * @signature\n * product()(data);\n * @example\n * pipe([1, 2, 3], product()); // => 6\n * pipe([1n, 2n, 3n], product()); // => 6n\n * pipe([], product()); // => 1\n * @dataLast\n * @category Number\n */\nexport function product(): <\n T extends IterableContainer<bigint> | IterableContainer<number>,\n>(\n data: T,\n) => Product<T>;\n\nexport function product(...args: readonly unknown[]): unknown {\n return purry(productImplementation, args);\n}\n\nfunction productImplementation<\n T extends IterableContainer<bigint> | IterableContainer<number>,\n>(data: T): T[number] {\n // eslint-disable-next-line @typescript-eslint/no-magic-numbers -- The rule differentiates 1 and 1n :(\n let out = typeof data[0] === \"bigint\" ? 1n : 1;\n for (const value of data) {\n // @ts-expect-error [ts2365] -- Typescript can't infer that all elements will be a number of the same type.\n out *= value;\n }\n return out;\n}\n"],"mappings":"mCAqEA,SAAgB,EAAQ,GAAG,EAAmC,CAC5D,OAAO,EAAM,EAAuB,EAAK,CAG3C,SAAS,EAEP,EAAoB,CAEpB,IAAI,EAAM,OAAO,EAAK,IAAO,SAAW,GAAK,EAC7C,IAAK,IAAM,KAAS,EAElB,GAAO,EAET,OAAO"}
|
package/dist/prop.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e,...n){return typeof e==`string`||typeof e==`number`||typeof e==`symbol`?r=>t(r,e,...n):t(e,...n)}function t(e,...t){let n=e;for(let e of t){if(n==null)return;n=n[e]}return n}exports.prop=e;
|
|
2
|
+
//# sourceMappingURL=prop.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prop.cjs","names":[],"sources":["../src/prop.ts"],"sourcesContent":["import type { KeysOfUnion } from \"type-fest\";\nimport type { ArrayAt } from \"./internal/types/ArrayAt\";\n\n// Computes all possible keys of `T` at `Path` spread over unions, allowing\n// keys from any of the results, not just those **shared** by all of them.\ntype KeysDeep<T, Path extends readonly unknown[]> = KeysOfUnion<\n PropDeep<T, Path>\n>;\n\n// Recursively run `Prop` over `Path` to extract the deeply nested type.\ntype PropDeep<T, Path extends readonly unknown[]> = Path extends readonly [\n infer Key,\n ...infer Rest,\n]\n ? PropDeep<Prop<T, Key>, Rest>\n : // Keys is a fixed tuple so we know we reach here only when we've reached\n // the output object.\n T;\n\n// Expanding on the built-in `T[Key]` operator to support arrays and unions.\ntype Prop<T, Key> =\n // Distribute the union to support unions of keys.\n T extends unknown\n ? // In a distributed union some of the union members might not be keys of a\n // specific object within a union of objects, those cases don't contribute\n // to the output type.\n Key extends keyof T\n ? T extends readonly unknown[]\n ? ArrayAt<T, Key>\n : T[Key]\n : undefined\n : never;\n\n// Currying relies on us being able to differentiate between data-first and\n// data-last invocations at runtime, but because the function takes a variadic\n// array of keys we can't rely on it's shape or length to do that. Instead, we\n// can limit the types we accept for `data` so that looking at the first\n// parameter's type is enough to make the call. From a practical standpoint\n// this means we accept in any `object`, `null,` or `undefined`, and that we\n// don't accept `string`. All other types (`boolean` and `bigint`) don't\n// have properties, so are incompatible with our `key` parameters anyway.\ntype NonPropertyKey = object | null | undefined;\n\n/**\n * Gets the value of the given property from an object. Nested properties can\n * be accessed by providing a variadic array of keys that define the path from\n * the root to the desired property. Arrays can be accessed by using numeric\n * keys. Unions and optional properties are handled gracefully by returning\n * `undefined` early for any non-existing property on the path. Paths are\n * validated against the object type to provide stronger type safety, better\n * compile-time errors, and to enable autocompletion in IDEs.\n *\n * @param data - The object or array to access.\n * @param key - The key(s) for the property to extract.\n * @signature\n * prop(data, ...keys);\n * @example\n * prop({ foo: { bar: 'baz' } }, 'foo'); //=> { bar: 'baz' }\n * prop({ foo: { bar: 'baz' } }, 'foo', 'bar'); //=> 'baz'\n * prop([\"cat\", \"dog\"], 1); //=> 'dog'\n * @dataFirst\n * @category Object\n */\nexport function prop<T extends NonPropertyKey, Key extends KeysDeep<T, []>>(\n data: T,\n key: Key,\n): NoInfer<Prop<T, Key>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n>(data: T, key0: Key0, key1: Key1): NoInfer<PropDeep<T, [Key0, Key1]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n): NoInfer<PropDeep<T, [Key0, Key1, Key2]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>,\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n key7: Key7,\n): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>,\n Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>,\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n key7: Key7,\n key8: Key8,\n): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>,\n Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>,\n Key9 extends KeysDeep<\n T,\n [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8]\n >,\n AdditionalKeys extends readonly PropertyKey[] = [],\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n key7: Key7,\n key8: Key8,\n key9: Key9,\n ...additionalKeys: AdditionalKeys\n): NoInfer<\n PropDeep<\n T,\n [\n Key0,\n Key1,\n Key2,\n Key3,\n Key4,\n Key5,\n Key6,\n Key7,\n Key8,\n Key9,\n ...AdditionalKeys,\n ]\n >\n>;\n\n/**\n * Gets the value of the given property from an object. Nested properties can\n * be accessed by providing a variadic array of keys that define the path from\n * the root to the desired property. Arrays can be accessed by using numeric\n * keys. Unions and optional properties are handled gracefully by returning\n * `undefined` early for any non-existing property on the path. Paths are\n * validated against the object type to provide stronger type safety, better\n * compile-time errors, and to enable autocompletion in IDEs.\n *\n * @param key - The key(s) for the property to extract.\n * @signature\n * prop(...keys)(data);\n * @example\n * pipe({ foo: { bar: 'baz' } }, prop('foo')); //=> { bar: 'baz' }\n * pipe({ foo: { bar: 'baz' } }, prop('foo', 'bar')); //=> 'baz'\n * pipe([\"cat\", \"dog\"], prop(1)); //=> 'dog'\n * @dataLast\n * @category Object\n */\nexport function prop<T extends NonPropertyKey, Key extends KeysOfUnion<T>>(\n key: Key,\n): (data: T) => NoInfer<Prop<T, Key>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n>(key0: Key0, key1: Key1): (data: T) => NoInfer<PropDeep<T, [Key0, Key1]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n): (\n data: T,\n) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>,\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n key7: Key7,\n): (\n data: T,\n) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>,\n Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>,\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n key7: Key7,\n key8: Key8,\n): (\n data: T,\n) => NoInfer<\n PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8]>\n>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>,\n Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>,\n Key9 extends KeysDeep<\n T,\n [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8]\n >,\n AdditionalKeys extends readonly PropertyKey[] = [],\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n key7: Key7,\n key8: Key8,\n key9: Key9,\n ...additionalKeys: AdditionalKeys\n): (\n data: T,\n) => NoInfer<\n PropDeep<\n T,\n [\n Key0,\n Key1,\n Key2,\n Key3,\n Key4,\n Key5,\n Key6,\n Key7,\n Key8,\n Key9,\n ...AdditionalKeys,\n ]\n >\n>;\n\nexport function prop<K extends PropertyKey>(\n key: K,\n): <T extends Partial<Record<K, unknown>>>(data: T) => T[K];\n\nexport function prop(\n maybeData: NonPropertyKey | PropertyKey,\n ...args: readonly PropertyKey[]\n): unknown {\n return typeof maybeData === \"string\" ||\n typeof maybeData === \"number\" ||\n typeof maybeData === \"symbol\"\n ? (data: NonPropertyKey) => propImplementation(data, maybeData, ...args)\n : propImplementation(maybeData, ...args);\n}\n\nfunction propImplementation(\n data: NonPropertyKey,\n ...keys: readonly PropertyKey[]\n): unknown {\n let output: unknown = data;\n for (const key of keys) {\n if (output === undefined || output === null) {\n return undefined;\n }\n // @ts-expect-error [ts7053] -- This is fine, the types are really dynamic\n // here and TypeScript doesn't have a chance to infer them correctly.\n output = output[key];\n }\n return output;\n}\n"],"mappings":"mEAubA,SAAgB,EACd,EACA,GAAG,EACM,CACT,OAAO,OAAO,GAAc,UAC1B,OAAO,GAAc,UACrB,OAAO,GAAc,SAClB,GAAyB,EAAmB,EAAM,EAAW,GAAG,EAAK,CACtE,EAAmB,EAAW,GAAG,EAAK,CAG5C,SAAS,EACP,EACA,GAAG,EACM,CACT,IAAI,EAAkB,EACtB,IAAK,IAAM,KAAO,EAAM,CACtB,GAAI,GAAmC,KACrC,OAIF,EAAS,EAAO,GAElB,OAAO"}
|
package/dist/prop.js
ADDED
package/dist/prop.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prop.js","names":[],"sources":["../src/prop.ts"],"sourcesContent":["import type { KeysOfUnion } from \"type-fest\";\nimport type { ArrayAt } from \"./internal/types/ArrayAt\";\n\n// Computes all possible keys of `T` at `Path` spread over unions, allowing\n// keys from any of the results, not just those **shared** by all of them.\ntype KeysDeep<T, Path extends readonly unknown[]> = KeysOfUnion<\n PropDeep<T, Path>\n>;\n\n// Recursively run `Prop` over `Path` to extract the deeply nested type.\ntype PropDeep<T, Path extends readonly unknown[]> = Path extends readonly [\n infer Key,\n ...infer Rest,\n]\n ? PropDeep<Prop<T, Key>, Rest>\n : // Keys is a fixed tuple so we know we reach here only when we've reached\n // the output object.\n T;\n\n// Expanding on the built-in `T[Key]` operator to support arrays and unions.\ntype Prop<T, Key> =\n // Distribute the union to support unions of keys.\n T extends unknown\n ? // In a distributed union some of the union members might not be keys of a\n // specific object within a union of objects, those cases don't contribute\n // to the output type.\n Key extends keyof T\n ? T extends readonly unknown[]\n ? ArrayAt<T, Key>\n : T[Key]\n : undefined\n : never;\n\n// Currying relies on us being able to differentiate between data-first and\n// data-last invocations at runtime, but because the function takes a variadic\n// array of keys we can't rely on it's shape or length to do that. Instead, we\n// can limit the types we accept for `data` so that looking at the first\n// parameter's type is enough to make the call. From a practical standpoint\n// this means we accept in any `object`, `null,` or `undefined`, and that we\n// don't accept `string`. All other types (`boolean` and `bigint`) don't\n// have properties, so are incompatible with our `key` parameters anyway.\ntype NonPropertyKey = object | null | undefined;\n\n/**\n * Gets the value of the given property from an object. Nested properties can\n * be accessed by providing a variadic array of keys that define the path from\n * the root to the desired property. Arrays can be accessed by using numeric\n * keys. Unions and optional properties are handled gracefully by returning\n * `undefined` early for any non-existing property on the path. Paths are\n * validated against the object type to provide stronger type safety, better\n * compile-time errors, and to enable autocompletion in IDEs.\n *\n * @param data - The object or array to access.\n * @param key - The key(s) for the property to extract.\n * @signature\n * prop(data, ...keys);\n * @example\n * prop({ foo: { bar: 'baz' } }, 'foo'); //=> { bar: 'baz' }\n * prop({ foo: { bar: 'baz' } }, 'foo', 'bar'); //=> 'baz'\n * prop([\"cat\", \"dog\"], 1); //=> 'dog'\n * @dataFirst\n * @category Object\n */\nexport function prop<T extends NonPropertyKey, Key extends KeysDeep<T, []>>(\n data: T,\n key: Key,\n): NoInfer<Prop<T, Key>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n>(data: T, key0: Key0, key1: Key1): NoInfer<PropDeep<T, [Key0, Key1]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n): NoInfer<PropDeep<T, [Key0, Key1, Key2]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>,\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n key7: Key7,\n): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>,\n Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>,\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n key7: Key7,\n key8: Key8,\n): NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>,\n Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>,\n Key9 extends KeysDeep<\n T,\n [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8]\n >,\n AdditionalKeys extends readonly PropertyKey[] = [],\n>(\n data: T,\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n key7: Key7,\n key8: Key8,\n key9: Key9,\n ...additionalKeys: AdditionalKeys\n): NoInfer<\n PropDeep<\n T,\n [\n Key0,\n Key1,\n Key2,\n Key3,\n Key4,\n Key5,\n Key6,\n Key7,\n Key8,\n Key9,\n ...AdditionalKeys,\n ]\n >\n>;\n\n/**\n * Gets the value of the given property from an object. Nested properties can\n * be accessed by providing a variadic array of keys that define the path from\n * the root to the desired property. Arrays can be accessed by using numeric\n * keys. Unions and optional properties are handled gracefully by returning\n * `undefined` early for any non-existing property on the path. Paths are\n * validated against the object type to provide stronger type safety, better\n * compile-time errors, and to enable autocompletion in IDEs.\n *\n * @param key - The key(s) for the property to extract.\n * @signature\n * prop(...keys)(data);\n * @example\n * pipe({ foo: { bar: 'baz' } }, prop('foo')); //=> { bar: 'baz' }\n * pipe({ foo: { bar: 'baz' } }, prop('foo', 'bar')); //=> 'baz'\n * pipe([\"cat\", \"dog\"], prop(1)); //=> 'dog'\n * @dataLast\n * @category Object\n */\nexport function prop<T extends NonPropertyKey, Key extends KeysOfUnion<T>>(\n key: Key,\n): (data: T) => NoInfer<Prop<T, Key>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n>(key0: Key0, key1: Key1): (data: T) => NoInfer<PropDeep<T, [Key0, Key1]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n): (data: T) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n): (\n data: T,\n) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>,\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n key7: Key7,\n): (\n data: T,\n) => NoInfer<PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>,\n Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>,\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n key7: Key7,\n key8: Key8,\n): (\n data: T,\n) => NoInfer<\n PropDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8]>\n>;\nexport function prop<\n T extends NonPropertyKey,\n Key0 extends KeysDeep<T, []>,\n Key1 extends KeysDeep<T, [Key0]>,\n Key2 extends KeysDeep<T, [Key0, Key1]>,\n Key3 extends KeysDeep<T, [Key0, Key1, Key2]>,\n Key4 extends KeysDeep<T, [Key0, Key1, Key2, Key3]>,\n Key5 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4]>,\n Key6 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5]>,\n Key7 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6]>,\n Key8 extends KeysDeep<T, [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7]>,\n Key9 extends KeysDeep<\n T,\n [Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8]\n >,\n AdditionalKeys extends readonly PropertyKey[] = [],\n>(\n key0: Key0,\n key1: Key1,\n key2: Key2,\n key3: Key3,\n key4: Key4,\n key5: Key5,\n key6: Key6,\n key7: Key7,\n key8: Key8,\n key9: Key9,\n ...additionalKeys: AdditionalKeys\n): (\n data: T,\n) => NoInfer<\n PropDeep<\n T,\n [\n Key0,\n Key1,\n Key2,\n Key3,\n Key4,\n Key5,\n Key6,\n Key7,\n Key8,\n Key9,\n ...AdditionalKeys,\n ]\n >\n>;\n\nexport function prop<K extends PropertyKey>(\n key: K,\n): <T extends Partial<Record<K, unknown>>>(data: T) => T[K];\n\nexport function prop(\n maybeData: NonPropertyKey | PropertyKey,\n ...args: readonly PropertyKey[]\n): unknown {\n return typeof maybeData === \"string\" ||\n typeof maybeData === \"number\" ||\n typeof maybeData === \"symbol\"\n ? (data: NonPropertyKey) => propImplementation(data, maybeData, ...args)\n : propImplementation(maybeData, ...args);\n}\n\nfunction propImplementation(\n data: NonPropertyKey,\n ...keys: readonly PropertyKey[]\n): unknown {\n let output: unknown = data;\n for (const key of keys) {\n if (output === undefined || output === null) {\n return undefined;\n }\n // @ts-expect-error [ts7053] -- This is fine, the types are really dynamic\n // here and TypeScript doesn't have a chance to infer them correctly.\n output = output[key];\n }\n return output;\n}\n"],"mappings":"AAubA,SAAgB,EACd,EACA,GAAG,EACM,CACT,OAAO,OAAO,GAAc,UAC1B,OAAO,GAAc,UACrB,OAAO,GAAc,SAClB,GAAyB,EAAmB,EAAM,EAAW,GAAG,EAAK,CACtE,EAAmB,EAAW,GAAG,EAAK,CAG5C,SAAS,EACP,EACA,GAAG,EACM,CACT,IAAI,EAAkB,EACtB,IAAK,IAAM,KAAO,EAAM,CACtB,GAAI,GAAmC,KACrC,OAIF,EAAS,EAAO,GAElB,OAAO"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./purry.cjs`);function t(...t){return e.purry(n,t)}function n(e,t,n){let r={};for(let[i,a]of e.entries()){let o=t(a,i,e);r[o]=n(a,i,e)}return r}exports.pullObject=t;
|
|
2
|
+
//# sourceMappingURL=pullObject.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pullObject.cjs","names":["purry"],"sources":["../src/pullObject.ts"],"sourcesContent":["import type { BoundedPartial } from \"./internal/types/BoundedPartial\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport { purry } from \"./purry\";\n\n/**\n * Creates an object that maps the result of `valueExtractor` with a key\n * resulting from running `keyExtractor` on each item in `data`. Duplicate keys\n * are overwritten, guaranteeing that the extractor functions are run on each\n * item in `data`.\n *\n * There are several other functions that could be used to build an object from\n * an array:\n * * `fromKeys` - Builds an object from an array of *keys* and a mapper for values.\n * * `indexBy` - Builds an object from an array of *values* and a mapper for keys.\n * * `fromEntries` - Builds an object from an array of key-value pairs.\n * Refer to the docs for more details.\n *\n * @param data - The items used to pull/extract the keys and values from.\n * @param keyExtractor - Computes the key for item.\n * @param valueExtractor - Computes the value for the item.\n * @signature\n * pullObject(data, keyExtractor, valueExtractor);\n * @example\n * pullObject(\n * [\n * { name: \"john\", email: \"john@remedajs.com\" },\n * { name: \"jane\", email: \"jane@remedajs.com\" }\n * ],\n * prop(\"name\"),\n * prop(\"email\"),\n * ); // => { john: \"john@remedajs.com\", jane: \"jane@remedajs.com\" }\n * @dataFirst\n * @category Object\n */\nexport function pullObject<\n T extends IterableContainer,\n K extends PropertyKey,\n V,\n>(\n data: T,\n keyExtractor: (item: T[number], index: number, data: T) => K,\n valueExtractor: (item: T[number], index: number, data: T) => V,\n): BoundedPartial<Record<K, V>>;\n\n/**\n * Creates an object that maps the result of `valueExtractor` with a key\n * resulting from running `keyExtractor` on each item in `data`. Duplicate keys\n * are overwritten, guaranteeing that the extractor functions are run on each\n * item in `data`.\n *\n * There are several other functions that could be used to build an object from\n * an array:\n * * `fromKeys` - Builds an object from an array of *keys* and a mapper for values.\n * * `indexBy` - Builds an object from an array of *values* and a mapper for keys.\n * * `fromEntries` - Builds an object from an array of key-value pairs.\n * Refer to the docs for more details.\n *\n * @param keyExtractor - Computes the key for item.\n * @param valueExtractor - Computes the value for the item.\n * @signature\n * pullObject(keyExtractor, valueExtractor)(data);\n * @example\n * pipe(\n * [\n * { name: \"john\", email: \"john@remedajs.com\" },\n * { name: \"jane\", email: \"jane@remedajs.com\" }\n * ],\n * pullObject(prop(\"name\"), prop(\"email\")),\n * ); // => { john: \"john@remedajs.com\", jane: \"jane@remedajs.com\" }\n * @dataLast\n * @category Object\n */\nexport function pullObject<\n T extends IterableContainer,\n K extends PropertyKey,\n V,\n>(\n keyExtractor: (item: T[number], index: number, data: T) => K,\n valueExtractor: (item: T[number], index: number, data: T) => V,\n): (data: T) => BoundedPartial<Record<K, V>>;\n\nexport function pullObject(...args: readonly unknown[]): unknown {\n return purry(pullObjectImplementation, args);\n}\n\nfunction pullObjectImplementation<\n T extends IterableContainer,\n K extends PropertyKey,\n V,\n>(\n data: T,\n keyExtractor: (item: T[number], index: number, data: T) => K,\n valueExtractor: (item: T[number], index: number, data: T) => V,\n): Partial<Record<K, V>> {\n const result: Partial<Record<K, V>> = {};\n\n for (const [index, item] of data.entries()) {\n const key = keyExtractor(item, index, data);\n const value = valueExtractor(item, index, data);\n result[key] = value;\n }\n\n return result;\n}\n"],"mappings":"kGAiFA,SAAgB,EAAW,GAAG,EAAmC,CAC/D,OAAOA,EAAAA,MAAM,EAA0B,EAAK,CAG9C,SAAS,EAKP,EACA,EACA,EACuB,CACvB,IAAM,EAAgC,EAAE,CAExC,IAAK,GAAM,CAAC,EAAO,KAAS,EAAK,SAAS,CAAE,CAC1C,IAAM,EAAM,EAAa,EAAM,EAAO,EAAK,CAE3C,EAAO,GADO,EAAe,EAAM,EAAO,EAAK,CAIjD,OAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pullObject.js","names":[],"sources":["../src/pullObject.ts"],"sourcesContent":["import type { BoundedPartial } from \"./internal/types/BoundedPartial\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport { purry } from \"./purry\";\n\n/**\n * Creates an object that maps the result of `valueExtractor` with a key\n * resulting from running `keyExtractor` on each item in `data`. Duplicate keys\n * are overwritten, guaranteeing that the extractor functions are run on each\n * item in `data`.\n *\n * There are several other functions that could be used to build an object from\n * an array:\n * * `fromKeys` - Builds an object from an array of *keys* and a mapper for values.\n * * `indexBy` - Builds an object from an array of *values* and a mapper for keys.\n * * `fromEntries` - Builds an object from an array of key-value pairs.\n * Refer to the docs for more details.\n *\n * @param data - The items used to pull/extract the keys and values from.\n * @param keyExtractor - Computes the key for item.\n * @param valueExtractor - Computes the value for the item.\n * @signature\n * pullObject(data, keyExtractor, valueExtractor);\n * @example\n * pullObject(\n * [\n * { name: \"john\", email: \"john@remedajs.com\" },\n * { name: \"jane\", email: \"jane@remedajs.com\" }\n * ],\n * prop(\"name\"),\n * prop(\"email\"),\n * ); // => { john: \"john@remedajs.com\", jane: \"jane@remedajs.com\" }\n * @dataFirst\n * @category Object\n */\nexport function pullObject<\n T extends IterableContainer,\n K extends PropertyKey,\n V,\n>(\n data: T,\n keyExtractor: (item: T[number], index: number, data: T) => K,\n valueExtractor: (item: T[number], index: number, data: T) => V,\n): BoundedPartial<Record<K, V>>;\n\n/**\n * Creates an object that maps the result of `valueExtractor` with a key\n * resulting from running `keyExtractor` on each item in `data`. Duplicate keys\n * are overwritten, guaranteeing that the extractor functions are run on each\n * item in `data`.\n *\n * There are several other functions that could be used to build an object from\n * an array:\n * * `fromKeys` - Builds an object from an array of *keys* and a mapper for values.\n * * `indexBy` - Builds an object from an array of *values* and a mapper for keys.\n * * `fromEntries` - Builds an object from an array of key-value pairs.\n * Refer to the docs for more details.\n *\n * @param keyExtractor - Computes the key for item.\n * @param valueExtractor - Computes the value for the item.\n * @signature\n * pullObject(keyExtractor, valueExtractor)(data);\n * @example\n * pipe(\n * [\n * { name: \"john\", email: \"john@remedajs.com\" },\n * { name: \"jane\", email: \"jane@remedajs.com\" }\n * ],\n * pullObject(prop(\"name\"), prop(\"email\")),\n * ); // => { john: \"john@remedajs.com\", jane: \"jane@remedajs.com\" }\n * @dataLast\n * @category Object\n */\nexport function pullObject<\n T extends IterableContainer,\n K extends PropertyKey,\n V,\n>(\n keyExtractor: (item: T[number], index: number, data: T) => K,\n valueExtractor: (item: T[number], index: number, data: T) => V,\n): (data: T) => BoundedPartial<Record<K, V>>;\n\nexport function pullObject(...args: readonly unknown[]): unknown {\n return purry(pullObjectImplementation, args);\n}\n\nfunction pullObjectImplementation<\n T extends IterableContainer,\n K extends PropertyKey,\n V,\n>(\n data: T,\n keyExtractor: (item: T[number], index: number, data: T) => K,\n valueExtractor: (item: T[number], index: number, data: T) => V,\n): Partial<Record<K, V>> {\n const result: Partial<Record<K, V>> = {};\n\n for (const [index, item] of data.entries()) {\n const key = keyExtractor(item, index, data);\n const value = valueExtractor(item, index, data);\n result[key] = value;\n }\n\n return result;\n}\n"],"mappings":"mCAiFA,SAAgB,EAAW,GAAG,EAAmC,CAC/D,OAAO,EAAM,EAA0B,EAAK,CAG9C,SAAS,EAKP,EACA,EACA,EACuB,CACvB,IAAM,EAAgC,EAAE,CAExC,IAAK,GAAM,CAAC,EAAO,KAAS,EAAK,SAAS,CAAE,CAC1C,IAAM,EAAM,EAAa,EAAM,EAAO,EAAK,CAE3C,EAAO,GADO,EAAe,EAAM,EAAO,EAAK,CAIjD,OAAO"}
|
package/dist/purry.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./lazyDataLastImpl-DdpJofHC.cjs`);function t(t,n,r){let i=t.length-n.length;if(i===0)return t(...n);if(i===1)return e.t(t,n,r);throw Error(`Wrong number of arguments`)}exports.purry=t;
|
|
2
|
+
//# sourceMappingURL=purry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"purry.cjs","names":["lazyDataLastImpl"],"sources":["../src/purry.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { lazyDataLastImpl } from \"./internal/lazyDataLastImpl\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport type { StrictFunction } from \"./internal/types/StrictFunction\";\n\n/**\n * Creates a function with `dataFirst` and `dataLast` signatures.\n *\n * `purry` is a dynamic function and it's not type safe. It should be wrapped by\n * a function that have proper typings. Refer to the example below for correct\n * usage.\n *\n * !IMPORTANT: functions that simply call `purry` and return the result (like\n * almost all functions in this library) should return `unknown` themselves if\n * an explicit return type is required. This is because we currently don't\n * provide a generic return type that is built from the input function, and\n * crafting one manually isn't worthwhile as we rely on function declaration\n * overloading to combine the types for dataFirst and dataLast invocations!\n *\n * @param fn - The function to purry.\n * @param args - The arguments.\n * @param lazy - A lazy version of the function to purry.\n * @signature purry(fn, args);\n * @example\n * function _findIndex(array, fn) {\n * for (let i = 0; i < array.length; i++) {\n * if (fn(array[i])) {\n * return i;\n * }\n * }\n * return -1;\n * }\n *\n * // data-first\n * function findIndex<T>(array: T[], fn: (item: T) => boolean): number;\n *\n * // data-last\n * function findIndex<T>(fn: (item: T) => boolean): (array: T[]) => number;\n *\n * function findIndex(...args: unknown[]) {\n * return purry(_findIndex, args);\n * }\n * @category Function\n */\nexport function purry(\n fn: StrictFunction,\n args: readonly unknown[],\n lazy?: (...args: any) => LazyEvaluator,\n): unknown {\n const diff = fn.length - args.length;\n if (diff === 0) {\n // @ts-expect-error [ts2345] -- This error is accurate because we don't know\n // anything about `fn` so can't ensure that we are passing the correct\n // arguments to it, we just have to trust that the caller knows what they\n // are doing.\n return fn(...args);\n }\n\n if (diff === 1) {\n return lazyDataLastImpl(fn, args, lazy);\n }\n\n throw new Error(\"Wrong number of arguments\");\n}\n"],"mappings":"sHA6CA,SAAgB,EACd,EACA,EACA,EACS,CACT,IAAM,EAAO,EAAG,OAAS,EAAK,OAC9B,GAAI,IAAS,EAKX,OAAO,EAAG,GAAG,EAAK,CAGpB,GAAI,IAAS,EACX,OAAOA,EAAAA,EAAiB,EAAI,EAAM,EAAK,CAGzC,MAAU,MAAM,4BAA4B"}
|
package/dist/purry.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"purry.js","names":[],"sources":["../src/purry.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { lazyDataLastImpl } from \"./internal/lazyDataLastImpl\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport type { StrictFunction } from \"./internal/types/StrictFunction\";\n\n/**\n * Creates a function with `dataFirst` and `dataLast` signatures.\n *\n * `purry` is a dynamic function and it's not type safe. It should be wrapped by\n * a function that have proper typings. Refer to the example below for correct\n * usage.\n *\n * !IMPORTANT: functions that simply call `purry` and return the result (like\n * almost all functions in this library) should return `unknown` themselves if\n * an explicit return type is required. This is because we currently don't\n * provide a generic return type that is built from the input function, and\n * crafting one manually isn't worthwhile as we rely on function declaration\n * overloading to combine the types for dataFirst and dataLast invocations!\n *\n * @param fn - The function to purry.\n * @param args - The arguments.\n * @param lazy - A lazy version of the function to purry.\n * @signature purry(fn, args);\n * @example\n * function _findIndex(array, fn) {\n * for (let i = 0; i < array.length; i++) {\n * if (fn(array[i])) {\n * return i;\n * }\n * }\n * return -1;\n * }\n *\n * // data-first\n * function findIndex<T>(array: T[], fn: (item: T) => boolean): number;\n *\n * // data-last\n * function findIndex<T>(fn: (item: T) => boolean): (array: T[]) => number;\n *\n * function findIndex(...args: unknown[]) {\n * return purry(_findIndex, args);\n * }\n * @category Function\n */\nexport function purry(\n fn: StrictFunction,\n args: readonly unknown[],\n lazy?: (...args: any) => LazyEvaluator,\n): unknown {\n const diff = fn.length - args.length;\n if (diff === 0) {\n // @ts-expect-error [ts2345] -- This error is accurate because we don't know\n // anything about `fn` so can't ensure that we are passing the correct\n // arguments to it, we just have to trust that the caller knows what they\n // are doing.\n return fn(...args);\n }\n\n if (diff === 1) {\n return lazyDataLastImpl(fn, args, lazy);\n }\n\n throw new Error(\"Wrong number of arguments\");\n}\n"],"mappings":"mDA6CA,SAAgB,EACd,EACA,EACA,EACS,CACT,IAAM,EAAO,EAAG,OAAS,EAAK,OAC9B,GAAI,IAAS,EAKX,OAAO,EAAG,GAAG,EAAK,CAGpB,GAAI,IAAS,EACX,OAAO,EAAiB,EAAI,EAAM,EAAK,CAGzC,MAAU,MAAM,4BAA4B"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{pipe as e}from"./pipe.js";function t(t,n){let r=n.length-t.length;if(r===1){let[r,...i]=n;return e(r,{lazy:t,lazyArgs:i})}if(r===0){let r={lazy:t,lazyArgs:n};return Object.assign(t=>e(t,r),r)}throw Error(`Wrong number of arguments`)}export{t};
|
|
2
|
+
//# sourceMappingURL=purryFromLazy-B-_oTxzb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"purryFromLazy-B-_oTxzb.js","names":[],"sources":["../src/internal/purryFromLazy.ts"],"sourcesContent":["import { pipe } from \"../pipe\";\nimport type { LazyDefinition } from \"./types/LazyDefinition\";\nimport type { LazyEvaluator } from \"./types/LazyEvaluator\";\n\n/**\n * A version of `purry` for cases where the only meaningful implementation is a\n * lazy one. This is useful for functions that don't have a built-in\n * implementation already, and that can't be optimized to take advantage of\n * having the complete array upfront.\n *\n * Under the hood the function uses `pipe` to utilize it's built-in lazy logic\n * and wraps the pipe with the required invocations to allow using the function\n * outside of pipes too.\n *\n * @param lazy - The main lazy implementation, it assumes that data is an\n * iterable (array-like).\n * @param args - The arguments passed to the overloaded invocation.\n * @see purry\n * @see pipe\n */\nexport function purryFromLazy(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n lazy: (...args: any) => LazyEvaluator,\n args: readonly unknown[],\n): unknown {\n const diff = args.length - lazy.length;\n\n if (diff === 1) {\n // dataFirst\n const [data, ...rest] = args;\n const lazyDefinition = { lazy, lazyArgs: rest } satisfies LazyDefinition;\n\n // @ts-expect-error [ts2353] - Pipe expects a function which *might* also have a lazy definition. We are tricking pipe here to take our lazyDefinition without any function attached to it.\n return pipe(data, lazyDefinition);\n }\n\n if (diff === 0) {\n const lazyDefinition = { lazy, lazyArgs: args } satisfies LazyDefinition;\n\n // @ts-expect-error [ts2353] - Pipe expects a function which *might* also have a lazy definition. We are tricking pipe here to take our lazyDefinition without any function attached to it.\n const dataLast = (data: unknown): unknown => pipe(data, lazyDefinition);\n return Object.assign(dataLast, lazyDefinition);\n }\n\n throw new Error(\"Wrong number of arguments\");\n}\n"],"mappings":"iCAoBA,SAAgB,EAEd,EACA,EACS,CACT,IAAM,EAAO,EAAK,OAAS,EAAK,OAEhC,GAAI,IAAS,EAAG,CAEd,GAAM,CAAC,EAAM,GAAG,GAAQ,EAIxB,OAAO,EAAK,EAHW,CAAE,OAAM,SAAU,EAAM,CAGd,CAGnC,GAAI,IAAS,EAAG,CACd,IAAM,EAAiB,CAAE,OAAM,SAAU,EAAM,CAI/C,OAAO,OAAO,OADI,GAA2B,EAAK,EAAM,EAAe,CACxC,EAAe,CAGhD,MAAU,MAAM,4BAA4B"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`./pipe.cjs`);function t(t,n){let r=n.length-t.length;if(r===1){let[r,...i]=n;return e.pipe(r,{lazy:t,lazyArgs:i})}if(r===0){let r={lazy:t,lazyArgs:n};return Object.assign(t=>e.pipe(t,r),r)}throw Error(`Wrong number of arguments`)}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|
|
2
|
+
//# sourceMappingURL=purryFromLazy-CwB5T8yd.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"purryFromLazy-CwB5T8yd.cjs","names":["pipe"],"sources":["../src/internal/purryFromLazy.ts"],"sourcesContent":["import { pipe } from \"../pipe\";\nimport type { LazyDefinition } from \"./types/LazyDefinition\";\nimport type { LazyEvaluator } from \"./types/LazyEvaluator\";\n\n/**\n * A version of `purry` for cases where the only meaningful implementation is a\n * lazy one. This is useful for functions that don't have a built-in\n * implementation already, and that can't be optimized to take advantage of\n * having the complete array upfront.\n *\n * Under the hood the function uses `pipe` to utilize it's built-in lazy logic\n * and wraps the pipe with the required invocations to allow using the function\n * outside of pipes too.\n *\n * @param lazy - The main lazy implementation, it assumes that data is an\n * iterable (array-like).\n * @param args - The arguments passed to the overloaded invocation.\n * @see purry\n * @see pipe\n */\nexport function purryFromLazy(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n lazy: (...args: any) => LazyEvaluator,\n args: readonly unknown[],\n): unknown {\n const diff = args.length - lazy.length;\n\n if (diff === 1) {\n // dataFirst\n const [data, ...rest] = args;\n const lazyDefinition = { lazy, lazyArgs: rest } satisfies LazyDefinition;\n\n // @ts-expect-error [ts2353] - Pipe expects a function which *might* also have a lazy definition. We are tricking pipe here to take our lazyDefinition without any function attached to it.\n return pipe(data, lazyDefinition);\n }\n\n if (diff === 0) {\n const lazyDefinition = { lazy, lazyArgs: args } satisfies LazyDefinition;\n\n // @ts-expect-error [ts2353] - Pipe expects a function which *might* also have a lazy definition. We are tricking pipe here to take our lazyDefinition without any function attached to it.\n const dataLast = (data: unknown): unknown => pipe(data, lazyDefinition);\n return Object.assign(dataLast, lazyDefinition);\n }\n\n throw new Error(\"Wrong number of arguments\");\n}\n"],"mappings":"8BAoBA,SAAgB,EAEd,EACA,EACS,CACT,IAAM,EAAO,EAAK,OAAS,EAAK,OAEhC,GAAI,IAAS,EAAG,CAEd,GAAM,CAAC,EAAM,GAAG,GAAQ,EAIxB,OAAOA,EAAAA,KAAK,EAHW,CAAE,OAAM,SAAU,EAAM,CAGd,CAGnC,GAAI,IAAS,EAAG,CACd,IAAM,EAAiB,CAAE,OAAM,SAAU,EAAM,CAI/C,OAAO,OAAO,OADI,GAA2BA,EAAAA,KAAK,EAAM,EAAe,CACxC,EAAe,CAGhD,MAAU,MAAM,4BAA4B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"purryOn-D4wFIFMT.js","names":[],"sources":["../src/internal/purryOn.ts"],"sourcesContent":["/**\n * Utility for purrying functions based on a predicate for the first argument.\n *\n * This is useful for purrying functions with a variadic argument list.\n */\nexport function purryOn<T>(\n isArg: (firstArg: unknown) => firstArg is T,\n implementation: (\n data: unknown,\n firstArg: T,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Function inference in typescript relies on `any` to work, it doesn't work with `unknown`\n ...args: any\n ) => unknown,\n args: readonly unknown[],\n): unknown {\n return isArg(args[0])\n ? // @ts-expect-error [ts2556] - This is a low-level function that assumes the function declaration and setup is correct and won't result in typing issues when called dynamically.\n (data: unknown) => implementation(data, ...args)\n : // @ts-expect-error [ts2556] - This is a low-level function that assumes the function declaration and setup is correct and won't result in typing issues when called dynamically.\n implementation(...args);\n}\n"],"mappings":"AAKA,SAAgB,EACd,EACA,EAMA,EACS,CACT,OAAO,EAAM,EAAK,GAAG,CAEhB,GAAkB,EAAe,EAAM,GAAG,EAAK,CAEhD,EAAe,GAAG,EAAK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"purryOn-DdnETb-0.cjs","names":[],"sources":["../src/internal/purryOn.ts"],"sourcesContent":["/**\n * Utility for purrying functions based on a predicate for the first argument.\n *\n * This is useful for purrying functions with a variadic argument list.\n */\nexport function purryOn<T>(\n isArg: (firstArg: unknown) => firstArg is T,\n implementation: (\n data: unknown,\n firstArg: T,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Function inference in typescript relies on `any` to work, it doesn't work with `unknown`\n ...args: any\n ) => unknown,\n args: readonly unknown[],\n): unknown {\n return isArg(args[0])\n ? // @ts-expect-error [ts2556] - This is a low-level function that assumes the function declaration and setup is correct and won't result in typing issues when called dynamically.\n (data: unknown) => implementation(data, ...args)\n : // @ts-expect-error [ts2556] - This is a low-level function that assumes the function declaration and setup is correct and won't result in typing issues when called dynamically.\n implementation(...args);\n}\n"],"mappings":"AAKA,SAAgB,EACd,EACA,EAMA,EACS,CACT,OAAO,EAAM,EAAK,GAAG,CAEhB,GAAkB,EAAe,EAAM,GAAG,EAAK,CAEhD,EAAe,GAAG,EAAK"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e={asc:(e,t)=>e>t,desc:(e,t)=>e<t};function t(e,t){let[n,...a]=t;if(!i(n))return e(n,r(...a));let o=r(n,...a);return t=>e(t,o)}function n(e,[n,r,...a]){let o,s;return i(r)?(o=n,s=[r,...a]):(o=r,s=[n,...a]),t((...t)=>e(...t,o),s)}function r(t,n,...i){let a=typeof t==`function`?t:t[0],o=typeof t==`function`?`asc`:t[1],{[o]:s}=e,c=n===void 0?void 0:r(n,...i);return(e,t)=>{let n=a(e),r=a(t);return s(n,r)?1:s(r,n)?-1:c?.(e,t)??0}}function i(t){if(a(t))return!0;if(typeof t!=`object`||!Array.isArray(t))return!1;let[n,r,...i]=t;return a(n)&&typeof r==`string`&&r in e&&i.length===0}const a=e=>typeof e==`function`&&e.length===1;export{n,t};
|
|
2
|
+
//# sourceMappingURL=purryOrderRules-4JgY6z4X.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"purryOrderRules-4JgY6z4X.js","names":[],"sources":["../src/internal/purryOrderRules.ts"],"sourcesContent":["import type { CompareFunction } from \"./types/CompareFunction\";\nimport type { NonEmptyArray } from \"./types/NonEmptyArray\";\n\n// We define the comparators in a global const so that they are only\n// instantiated once, and so we can couple a label (string) for them that could\n// be used in runtime to refer to them (e.g. \"asc\", \"desc\").\nconst COMPARATORS = {\n asc: <T>(x: T, y: T) => x > y,\n desc: <T>(x: T, y: T) => x < y,\n} as const;\n\n/**\n * An order rule defines a projection/extractor that returns a comparable from\n * the data being compared. It would be run on each item being compared, and a\n * comparator would then be used on the results to determine the order.\n *\n * There are 2 forms of the order rule, a simple one which only provides the\n * projection function and assumes ordering is ascending, and a 2-tuple where\n * the first element is the projection function and the second is the direction;\n * this allows changing the direction without defining a more complex projection\n * to simply negate the value (e.g. `(x) => -x`).\n *\n * We rely on the javascript implementation of `<` and `>` for comparison, which\n * will attempt to transform both operands into a primitive comparable value via\n * the built in `valueOf` function (and then `toString`). It's up to the caller\n * to make sure that the projection is returning a value that makes sense for\n * this logic.\n *\n * It's important to note that there is no built-in caching/memoization of\n * projection function and therefore no guarantee that it would only be called\n * once.\n */\nexport type OrderRule<T> =\n | Projection<T>\n | readonly [projection: Projection<T>, direction: keyof typeof COMPARATORS];\n\ntype Projection<T> = (x: T) => Comparable;\n\n// We define the Comparable based on how JS coerces values into primitives when\n// used with the `<` and `>` operators.\n// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#type_coercion\ntype Comparable =\n | ComparablePrimitive\n | { [Symbol.toPrimitive]: (hint: string) => ComparablePrimitive }\n | { toString: () => string }\n | { valueOf: () => ComparablePrimitive };\n\n// Notice that `boolean` is special in that it is coerced as a number (0 for\n// `false`, 1 for `true`) implicitly.\ntype ComparablePrimitive = bigint | boolean | number | string;\n\n/**\n * Allows functions that want to handle a variadic number of order rules a\n * a simplified API that hides most of the implementation details. The only\n * thing users of this function need to do is provide a function that would take\n * the data, and a compare function that can be used to determine the order\n * between the items of the array.\n * This functions takes care of the rest; it will parse rules, built the\n * comparer, and manage the purrying of the input arguments.\n */\nexport function purryOrderRules<T>(\n func: (data: readonly T[], compareFn: CompareFunction<T>) => unknown,\n inputArgs: readonly unknown[],\n): unknown {\n // We rely on casting blindly here, but we rely on casting blindly everywhere\n // else when we call purry so it's fine...\n const [dataOrRule, ...rules] = inputArgs as\n | Readonly<NonEmptyArray<OrderRule<T>>>\n | [\n data: OrderRule<T> | readonly T[],\n ...rules: Readonly<NonEmptyArray<OrderRule<T>>>,\n ];\n\n if (!isOrderRule<T>(dataOrRule)) {\n // dataFirst!\n\n // @ts-expect-error [ts2556]: Typescript is failing to infer the type of rules\n // correctly here after the type refinement above, rules should be non-empty\n // when we get here.\n const compareFn = orderRuleComparer(...rules);\n return func(dataOrRule, compareFn);\n }\n\n // dataLast!\n\n // Important: initialize the comparer outside of the returned function so it\n // it's constructed and shared everywhere (it's stateless so should be safe\n // if used multiple times).\n const compareFn = orderRuleComparer(dataOrRule, ...rules);\n return (data: readonly T[]) => func(data, compareFn);\n}\n\n/**\n * Some functions need an extra number argument, this helps facilitate that.\n */\nexport function purryOrderRulesWithArgument(\n func: <T>(\n data: readonly T[],\n compareFn: CompareFunction<T>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Function inference in typescript relies on `any` to work, it doesn't work with `unknown`\n arg: any,\n ) => unknown,\n [first, second, ...rest]: readonly unknown[],\n): unknown {\n // We need to pull the `n` argument out to make it work with purryOrderRules.\n let arg: unknown;\n let argRemoved: readonly unknown[];\n if (isOrderRule(second)) {\n // dataLast!\n arg = first;\n argRemoved = [second, ...rest];\n } else {\n // dataFirst!\n arg = second;\n argRemoved = [first, ...rest];\n }\n\n return purryOrderRules((...args) => func(...args, arg), argRemoved);\n}\n\nfunction orderRuleComparer<T>(\n primaryRule: OrderRule<T>,\n secondaryRule?: OrderRule<T>,\n ...otherRules: readonly OrderRule<T>[]\n): (a: T, b: T) => number {\n const projector =\n typeof primaryRule === \"function\" ? primaryRule : primaryRule[0];\n\n const direction = typeof primaryRule === \"function\" ? \"asc\" : primaryRule[1];\n const { [direction]: comparator } = COMPARATORS;\n\n const nextComparer =\n secondaryRule === undefined\n ? undefined\n : orderRuleComparer(secondaryRule, ...otherRules);\n\n return (a, b) => {\n const projectedA = projector(a);\n const projectedB = projector(b);\n\n if (comparator(projectedA, projectedB)) {\n return 1;\n }\n\n if (comparator(projectedB, projectedA)) {\n return -1;\n }\n\n // The elements are equal base on the current comparator and projection. So\n // we need to check the elements using the next comparer, if one exists,\n // otherwise we consider them as true equal (returning 0).\n return nextComparer?.(a, b) ?? 0;\n };\n}\n\nfunction isOrderRule<T>(x: unknown): x is OrderRule<T> {\n if (isProjection(x)) {\n return true;\n }\n\n if (typeof x !== \"object\" || !Array.isArray(x)) {\n return false;\n }\n\n const [maybeProjection, maybeDirection, ...rest] = x as readonly unknown[];\n\n return (\n isProjection(maybeProjection) &&\n typeof maybeDirection === \"string\" &&\n maybeDirection in COMPARATORS &&\n // Has to be a 2-tuple\n rest.length === 0\n );\n}\n\nconst isProjection = <T>(x: unknown): x is Projection<T> =>\n typeof x === \"function\" && x.length === 1;\n"],"mappings":"AAMA,MAAM,EAAc,CAClB,KAAS,EAAM,IAAS,EAAI,EAC5B,MAAU,EAAM,IAAS,EAAI,EAC9B,CAmDD,SAAgB,EACd,EACA,EACS,CAGT,GAAM,CAAC,EAAY,GAAG,GAAS,EAO/B,GAAI,CAAC,EAAe,EAAW,CAO7B,OAAO,EAAK,EADM,EAAkB,GAAG,EAAM,CACX,CAQpC,IAAM,EAAY,EAAkB,EAAY,GAAG,EAAM,CACzD,MAAQ,IAAuB,EAAK,EAAM,EAAU,CAMtD,SAAgB,EACd,EAMA,CAAC,EAAO,EAAQ,GAAG,GACV,CAET,IAAI,EACA,EAWJ,OAVI,EAAY,EAAO,EAErB,EAAM,EACN,EAAa,CAAC,EAAQ,GAAG,EAAK,GAG9B,EAAM,EACN,EAAa,CAAC,EAAO,GAAG,EAAK,EAGxB,GAAiB,GAAG,IAAS,EAAK,GAAG,EAAM,EAAI,CAAE,EAAW,CAGrE,SAAS,EACP,EACA,EACA,GAAG,EACqB,CACxB,IAAM,EACJ,OAAO,GAAgB,WAAa,EAAc,EAAY,GAE1D,EAAY,OAAO,GAAgB,WAAa,MAAQ,EAAY,GACpE,EAAG,GAAY,GAAe,EAE9B,EACJ,IAAkB,IAAA,GACd,IAAA,GACA,EAAkB,EAAe,GAAG,EAAW,CAErD,OAAQ,EAAG,IAAM,CACf,IAAM,EAAa,EAAU,EAAE,CACzB,EAAa,EAAU,EAAE,CAa/B,OAXI,EAAW,EAAY,EAAW,CAC7B,EAGL,EAAW,EAAY,EAAW,CAC7B,GAMF,IAAe,EAAG,EAAE,EAAI,GAInC,SAAS,EAAe,EAA+B,CACrD,GAAI,EAAa,EAAE,CACjB,MAAO,GAGT,GAAI,OAAO,GAAM,UAAY,CAAC,MAAM,QAAQ,EAAE,CAC5C,MAAO,GAGT,GAAM,CAAC,EAAiB,EAAgB,GAAG,GAAQ,EAEnD,OACE,EAAa,EAAgB,EAC7B,OAAO,GAAmB,UAC1B,KAAkB,GAElB,EAAK,SAAW,EAIpB,MAAM,EAAmB,GACvB,OAAO,GAAM,YAAc,EAAE,SAAW"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e={asc:(e,t)=>e>t,desc:(e,t)=>e<t};function t(e,t){let[n,...a]=t;if(!i(n))return e(n,r(...a));let o=r(n,...a);return t=>e(t,o)}function n(e,[n,r,...a]){let o,s;return i(r)?(o=n,s=[r,...a]):(o=r,s=[n,...a]),t((...t)=>e(...t,o),s)}function r(t,n,...i){let a=typeof t==`function`?t:t[0],o=typeof t==`function`?`asc`:t[1],{[o]:s}=e,c=n===void 0?void 0:r(n,...i);return(e,t)=>{let n=a(e),r=a(t);return s(n,r)?1:s(r,n)?-1:c?.(e,t)??0}}function i(t){if(a(t))return!0;if(typeof t!=`object`||!Array.isArray(t))return!1;let[n,r,...i]=t;return a(n)&&typeof r==`string`&&r in e&&i.length===0}const a=e=>typeof e==`function`&&e.length===1;Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|
|
2
|
+
//# sourceMappingURL=purryOrderRules-B8pzD03D.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"purryOrderRules-B8pzD03D.cjs","names":[],"sources":["../src/internal/purryOrderRules.ts"],"sourcesContent":["import type { CompareFunction } from \"./types/CompareFunction\";\nimport type { NonEmptyArray } from \"./types/NonEmptyArray\";\n\n// We define the comparators in a global const so that they are only\n// instantiated once, and so we can couple a label (string) for them that could\n// be used in runtime to refer to them (e.g. \"asc\", \"desc\").\nconst COMPARATORS = {\n asc: <T>(x: T, y: T) => x > y,\n desc: <T>(x: T, y: T) => x < y,\n} as const;\n\n/**\n * An order rule defines a projection/extractor that returns a comparable from\n * the data being compared. It would be run on each item being compared, and a\n * comparator would then be used on the results to determine the order.\n *\n * There are 2 forms of the order rule, a simple one which only provides the\n * projection function and assumes ordering is ascending, and a 2-tuple where\n * the first element is the projection function and the second is the direction;\n * this allows changing the direction without defining a more complex projection\n * to simply negate the value (e.g. `(x) => -x`).\n *\n * We rely on the javascript implementation of `<` and `>` for comparison, which\n * will attempt to transform both operands into a primitive comparable value via\n * the built in `valueOf` function (and then `toString`). It's up to the caller\n * to make sure that the projection is returning a value that makes sense for\n * this logic.\n *\n * It's important to note that there is no built-in caching/memoization of\n * projection function and therefore no guarantee that it would only be called\n * once.\n */\nexport type OrderRule<T> =\n | Projection<T>\n | readonly [projection: Projection<T>, direction: keyof typeof COMPARATORS];\n\ntype Projection<T> = (x: T) => Comparable;\n\n// We define the Comparable based on how JS coerces values into primitives when\n// used with the `<` and `>` operators.\n// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#type_coercion\ntype Comparable =\n | ComparablePrimitive\n | { [Symbol.toPrimitive]: (hint: string) => ComparablePrimitive }\n | { toString: () => string }\n | { valueOf: () => ComparablePrimitive };\n\n// Notice that `boolean` is special in that it is coerced as a number (0 for\n// `false`, 1 for `true`) implicitly.\ntype ComparablePrimitive = bigint | boolean | number | string;\n\n/**\n * Allows functions that want to handle a variadic number of order rules a\n * a simplified API that hides most of the implementation details. The only\n * thing users of this function need to do is provide a function that would take\n * the data, and a compare function that can be used to determine the order\n * between the items of the array.\n * This functions takes care of the rest; it will parse rules, built the\n * comparer, and manage the purrying of the input arguments.\n */\nexport function purryOrderRules<T>(\n func: (data: readonly T[], compareFn: CompareFunction<T>) => unknown,\n inputArgs: readonly unknown[],\n): unknown {\n // We rely on casting blindly here, but we rely on casting blindly everywhere\n // else when we call purry so it's fine...\n const [dataOrRule, ...rules] = inputArgs as\n | Readonly<NonEmptyArray<OrderRule<T>>>\n | [\n data: OrderRule<T> | readonly T[],\n ...rules: Readonly<NonEmptyArray<OrderRule<T>>>,\n ];\n\n if (!isOrderRule<T>(dataOrRule)) {\n // dataFirst!\n\n // @ts-expect-error [ts2556]: Typescript is failing to infer the type of rules\n // correctly here after the type refinement above, rules should be non-empty\n // when we get here.\n const compareFn = orderRuleComparer(...rules);\n return func(dataOrRule, compareFn);\n }\n\n // dataLast!\n\n // Important: initialize the comparer outside of the returned function so it\n // it's constructed and shared everywhere (it's stateless so should be safe\n // if used multiple times).\n const compareFn = orderRuleComparer(dataOrRule, ...rules);\n return (data: readonly T[]) => func(data, compareFn);\n}\n\n/**\n * Some functions need an extra number argument, this helps facilitate that.\n */\nexport function purryOrderRulesWithArgument(\n func: <T>(\n data: readonly T[],\n compareFn: CompareFunction<T>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Function inference in typescript relies on `any` to work, it doesn't work with `unknown`\n arg: any,\n ) => unknown,\n [first, second, ...rest]: readonly unknown[],\n): unknown {\n // We need to pull the `n` argument out to make it work with purryOrderRules.\n let arg: unknown;\n let argRemoved: readonly unknown[];\n if (isOrderRule(second)) {\n // dataLast!\n arg = first;\n argRemoved = [second, ...rest];\n } else {\n // dataFirst!\n arg = second;\n argRemoved = [first, ...rest];\n }\n\n return purryOrderRules((...args) => func(...args, arg), argRemoved);\n}\n\nfunction orderRuleComparer<T>(\n primaryRule: OrderRule<T>,\n secondaryRule?: OrderRule<T>,\n ...otherRules: readonly OrderRule<T>[]\n): (a: T, b: T) => number {\n const projector =\n typeof primaryRule === \"function\" ? primaryRule : primaryRule[0];\n\n const direction = typeof primaryRule === \"function\" ? \"asc\" : primaryRule[1];\n const { [direction]: comparator } = COMPARATORS;\n\n const nextComparer =\n secondaryRule === undefined\n ? undefined\n : orderRuleComparer(secondaryRule, ...otherRules);\n\n return (a, b) => {\n const projectedA = projector(a);\n const projectedB = projector(b);\n\n if (comparator(projectedA, projectedB)) {\n return 1;\n }\n\n if (comparator(projectedB, projectedA)) {\n return -1;\n }\n\n // The elements are equal base on the current comparator and projection. So\n // we need to check the elements using the next comparer, if one exists,\n // otherwise we consider them as true equal (returning 0).\n return nextComparer?.(a, b) ?? 0;\n };\n}\n\nfunction isOrderRule<T>(x: unknown): x is OrderRule<T> {\n if (isProjection(x)) {\n return true;\n }\n\n if (typeof x !== \"object\" || !Array.isArray(x)) {\n return false;\n }\n\n const [maybeProjection, maybeDirection, ...rest] = x as readonly unknown[];\n\n return (\n isProjection(maybeProjection) &&\n typeof maybeDirection === \"string\" &&\n maybeDirection in COMPARATORS &&\n // Has to be a 2-tuple\n rest.length === 0\n );\n}\n\nconst isProjection = <T>(x: unknown): x is Projection<T> =>\n typeof x === \"function\" && x.length === 1;\n"],"mappings":"AAMA,MAAM,EAAc,CAClB,KAAS,EAAM,IAAS,EAAI,EAC5B,MAAU,EAAM,IAAS,EAAI,EAC9B,CAmDD,SAAgB,EACd,EACA,EACS,CAGT,GAAM,CAAC,EAAY,GAAG,GAAS,EAO/B,GAAI,CAAC,EAAe,EAAW,CAO7B,OAAO,EAAK,EADM,EAAkB,GAAG,EAAM,CACX,CAQpC,IAAM,EAAY,EAAkB,EAAY,GAAG,EAAM,CACzD,MAAQ,IAAuB,EAAK,EAAM,EAAU,CAMtD,SAAgB,EACd,EAMA,CAAC,EAAO,EAAQ,GAAG,GACV,CAET,IAAI,EACA,EAWJ,OAVI,EAAY,EAAO,EAErB,EAAM,EACN,EAAa,CAAC,EAAQ,GAAG,EAAK,GAG9B,EAAM,EACN,EAAa,CAAC,EAAO,GAAG,EAAK,EAGxB,GAAiB,GAAG,IAAS,EAAK,GAAG,EAAM,EAAI,CAAE,EAAW,CAGrE,SAAS,EACP,EACA,EACA,GAAG,EACqB,CACxB,IAAM,EACJ,OAAO,GAAgB,WAAa,EAAc,EAAY,GAE1D,EAAY,OAAO,GAAgB,WAAa,MAAQ,EAAY,GACpE,EAAG,GAAY,GAAe,EAE9B,EACJ,IAAkB,IAAA,GACd,IAAA,GACA,EAAkB,EAAe,GAAG,EAAW,CAErD,OAAQ,EAAG,IAAM,CACf,IAAM,EAAa,EAAU,EAAE,CACzB,EAAa,EAAU,EAAE,CAa/B,OAXI,EAAW,EAAY,EAAW,CAC7B,EAGL,EAAW,EAAY,EAAW,CAC7B,GAMF,IAAe,EAAG,EAAE,EAAI,GAInC,SAAS,EAAe,EAA+B,CACrD,GAAI,EAAa,EAAE,CACjB,MAAO,GAGT,GAAI,OAAO,GAAM,UAAY,CAAC,MAAM,QAAQ,EAAE,CAC5C,MAAO,GAGT,GAAM,CAAC,EAAiB,EAAgB,GAAG,GAAQ,EAEnD,OACE,EAAa,EAAgB,EAC7B,OAAO,GAAmB,UAC1B,KAAkB,GAElB,EAAK,SAAW,EAIpB,MAAM,EAAmB,GACvB,OAAO,GAAM,YAAc,EAAE,SAAW"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{t as e}from"./swapInPlace-BrVgf3c3.js";const t=(e,t,r)=>t<0||t>=e.length?void 0:n([...e],0,e.length-1,t,r);function n(e,t,i,a,o){if(t===i)return e[t];let s=r(e,t,i,o);return a===s?e[a]:n(e,a<s?t:s+1,a<s?s-1:i,a,o)}function r(t,n,r,i){let a=t[r],o=n;for(let s=n;s<r;s++)i(t[s],a)<0&&(e(t,o,s),o+=1);return e(t,o,r),o}export{t};
|
|
2
|
+
//# sourceMappingURL=quickSelect-B4eZ0JeB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickSelect-B4eZ0JeB.js","names":[],"sources":["../src/internal/quickSelect.ts"],"sourcesContent":["/**\n * A simple implementation of the *QuickSelect* algorithm.\n *\n * @see https://en.wikipedia.org/wiki/Quickselect\n */\n\nimport { swapInPlace } from \"./swapInPlace\";\nimport type { CompareFunction } from \"./types/CompareFunction\";\n\n/**\n * Perform QuickSelect on the given data. Notice that the data would be cloned\n * shallowly so that it could be mutated in-place, and then discarded once the\n * algorithm is done. This means that running this function multiple times on\n * the same array might be slower then sorting the array before.\n *\n * @param data - The data to perform the selection on.\n * @param index - The index of the item we are looking for.\n * @param compareFn - The compare function to use for sorting.\n * @returns The item at the given index, or `undefined` if the index is out-of-\n * bounds.\n */\nexport const quickSelect = <T>(\n data: readonly T[],\n index: number,\n compareFn: CompareFunction<T>,\n): T | undefined =>\n index < 0 || index >= data.length\n ? // Quickselect doesn't work with out-of-bound indices\n undefined\n : quickSelectImplementation(\n // We need to clone the array because quickSelect mutates it in-place.\n [...data],\n 0 /* left */,\n data.length - 1 /* right */,\n index,\n compareFn,\n );\n\n/**\n * The actual implementation, called recursively.\n */\nfunction quickSelectImplementation<T>(\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- Intentional!\n data: T[],\n left: number,\n right: number,\n index: number,\n compareFn: CompareFunction<T>,\n): T {\n if (left === right) {\n return data[left]!;\n }\n\n const pivotIndex = partition(data, left, right, compareFn);\n\n return index === pivotIndex\n ? // Once a pivot is chosen it's location is final, so if it matches the\n // index we found out item!\n data[index]!\n : quickSelectImplementation(\n data,\n // We continue by recursing into the partition where index would be\n index < pivotIndex ? left : pivotIndex + 1,\n index < pivotIndex ? pivotIndex - 1 : right,\n index,\n compareFn,\n );\n}\n\nfunction partition<T>(\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- Intentional!\n data: T[],\n left: number,\n right: number,\n compareFn: CompareFunction<T>,\n): number {\n const pivot = data[right]!;\n\n let i = left;\n for (let j = left; j < right; j++) {\n if (compareFn(data[j]!, pivot) < 0) {\n // Move items smaller then the pivot to the start of the array.\n swapInPlace(data, i, j);\n i += 1;\n }\n }\n\n swapInPlace(data, i, right);\n\n // The location of the pivot by the end of the partition function.\n return i;\n}\n"],"mappings":"8CAqBA,MAAa,GACX,EACA,EACA,IAEA,EAAQ,GAAK,GAAS,EAAK,OAEvB,IAAA,GACA,EAEE,CAAC,GAAG,EAAK,CACT,EACA,EAAK,OAAS,EACd,EACA,EACD,CAKP,SAAS,EAEP,EACA,EACA,EACA,EACA,EACG,CACH,GAAI,IAAS,EACX,OAAO,EAAK,GAGd,IAAM,EAAa,EAAU,EAAM,EAAM,EAAO,EAAU,CAE1D,OAAO,IAAU,EAGb,EAAK,GACL,EACE,EAEA,EAAQ,EAAa,EAAO,EAAa,EACzC,EAAQ,EAAa,EAAa,EAAI,EACtC,EACA,EACD,CAGP,SAAS,EAEP,EACA,EACA,EACA,EACQ,CACR,IAAM,EAAQ,EAAK,GAEf,EAAI,EACR,IAAK,IAAI,EAAI,EAAM,EAAI,EAAO,IACxB,EAAU,EAAK,GAAK,EAAM,CAAG,IAE/B,EAAY,EAAM,EAAG,EAAE,CACvB,GAAK,GAOT,OAHA,EAAY,EAAM,EAAG,EAAM,CAGpB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`./swapInPlace-IOnMIay9.cjs`),t=(e,t,r)=>t<0||t>=e.length?void 0:n([...e],0,e.length-1,t,r);function n(e,t,i,a,o){if(t===i)return e[t];let s=r(e,t,i,o);return a===s?e[a]:n(e,a<s?t:s+1,a<s?s-1:i,a,o)}function r(t,n,r,i){let a=t[r],o=n;for(let s=n;s<r;s++)i(t[s],a)<0&&(e.t(t,o,s),o+=1);return e.t(t,o,r),o}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t}});
|
|
2
|
+
//# sourceMappingURL=quickSelect-BwH5h4uh.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickSelect-BwH5h4uh.cjs","names":[],"sources":["../src/internal/quickSelect.ts"],"sourcesContent":["/**\n * A simple implementation of the *QuickSelect* algorithm.\n *\n * @see https://en.wikipedia.org/wiki/Quickselect\n */\n\nimport { swapInPlace } from \"./swapInPlace\";\nimport type { CompareFunction } from \"./types/CompareFunction\";\n\n/**\n * Perform QuickSelect on the given data. Notice that the data would be cloned\n * shallowly so that it could be mutated in-place, and then discarded once the\n * algorithm is done. This means that running this function multiple times on\n * the same array might be slower then sorting the array before.\n *\n * @param data - The data to perform the selection on.\n * @param index - The index of the item we are looking for.\n * @param compareFn - The compare function to use for sorting.\n * @returns The item at the given index, or `undefined` if the index is out-of-\n * bounds.\n */\nexport const quickSelect = <T>(\n data: readonly T[],\n index: number,\n compareFn: CompareFunction<T>,\n): T | undefined =>\n index < 0 || index >= data.length\n ? // Quickselect doesn't work with out-of-bound indices\n undefined\n : quickSelectImplementation(\n // We need to clone the array because quickSelect mutates it in-place.\n [...data],\n 0 /* left */,\n data.length - 1 /* right */,\n index,\n compareFn,\n );\n\n/**\n * The actual implementation, called recursively.\n */\nfunction quickSelectImplementation<T>(\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- Intentional!\n data: T[],\n left: number,\n right: number,\n index: number,\n compareFn: CompareFunction<T>,\n): T {\n if (left === right) {\n return data[left]!;\n }\n\n const pivotIndex = partition(data, left, right, compareFn);\n\n return index === pivotIndex\n ? // Once a pivot is chosen it's location is final, so if it matches the\n // index we found out item!\n data[index]!\n : quickSelectImplementation(\n data,\n // We continue by recursing into the partition where index would be\n index < pivotIndex ? left : pivotIndex + 1,\n index < pivotIndex ? pivotIndex - 1 : right,\n index,\n compareFn,\n );\n}\n\nfunction partition<T>(\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- Intentional!\n data: T[],\n left: number,\n right: number,\n compareFn: CompareFunction<T>,\n): number {\n const pivot = data[right]!;\n\n let i = left;\n for (let j = left; j < right; j++) {\n if (compareFn(data[j]!, pivot) < 0) {\n // Move items smaller then the pivot to the start of the array.\n swapInPlace(data, i, j);\n i += 1;\n }\n }\n\n swapInPlace(data, i, right);\n\n // The location of the pivot by the end of the partition function.\n return i;\n}\n"],"mappings":"8CAqBa,GACX,EACA,EACA,IAEA,EAAQ,GAAK,GAAS,EAAK,OAEvB,IAAA,GACA,EAEE,CAAC,GAAG,EAAK,CACT,EACA,EAAK,OAAS,EACd,EACA,EACD,CAKP,SAAS,EAEP,EACA,EACA,EACA,EACA,EACG,CACH,GAAI,IAAS,EACX,OAAO,EAAK,GAGd,IAAM,EAAa,EAAU,EAAM,EAAM,EAAO,EAAU,CAE1D,OAAO,IAAU,EAGb,EAAK,GACL,EACE,EAEA,EAAQ,EAAa,EAAO,EAAa,EACzC,EAAQ,EAAa,EAAa,EAAI,EACtC,EACA,EACD,CAGP,SAAS,EAEP,EACA,EACA,EACA,EACQ,CACR,IAAM,EAAQ,EAAK,GAEf,EAAI,EACR,IAAK,IAAI,EAAI,EAAM,EAAI,EAAO,IACxB,EAAU,EAAK,GAAK,EAAM,CAAG,IAE/B,EAAA,EAAY,EAAM,EAAG,EAAE,CACvB,GAAK,GAOT,OAHA,EAAA,EAAY,EAAM,EAAG,EAAM,CAGpB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e,r){if(r<e)throw RangeError(`randomBigInt: The range [${e.toString()},${r.toString()}] is empty.`);let i=r-e,{length:a}=i.toString(2),o=Math.ceil(a/8),s=BigInt(8-a%8);for(;;){let r=t(n(o))>>s;if(r<=i)return r+e}}function t(e){let t=0n;for(let n of e)t=(t<<8n)+BigInt(n);return t}function n(e){let t=new Uint8Array(e);if(typeof crypto>`u`)for(let n=0;n<e;n+=1)t[n]=Math.floor(Math.random()*256);else crypto.getRandomValues(t);return t}exports.randomBigInt=e;
|
|
2
|
+
//# sourceMappingURL=randomBigInt.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"randomBigInt.cjs","names":[],"sources":["../src/randomBigInt.ts"],"sourcesContent":["/* eslint-disable no-bitwise, @typescript-eslint/no-magic-numbers --\n * We randomize the bigint using randomized bitmaps, we have to use bitwise\n * operations to manipulate them.\n */\n\n/**\n * Generate a random `bigint` between `from` and `to` (inclusive).\n *\n * ! Important: In most environments this function uses\n * [`crypto.getRandomValues()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues)\n * under-the-hood which **is** cryptographically strong. When the WebCrypto API\n * isn't available (Node 18) we fallback to an implementation that uses\n * [`Math.random()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)\n * which is **NOT** cryptographically secure.\n *\n * @param from - The minimum value.\n * @param to - The maximum value.\n * @returns The random integer.\n * @signature\n * randomBigInt(from, to)\n * @example\n * randomBigInt(1n, 10n) // => 5n\n * @dataFirst\n * @category Number\n */\nexport function randomBigInt(from: bigint, to: bigint): bigint {\n if (to < from) {\n throw new RangeError(\n `randomBigInt: The range [${from.toString()},${to.toString()}] is empty.`,\n );\n }\n\n const range = to - from;\n\n // Get the max number of bits needed to encode the result. We will generate\n // this number of random bits. A radix of 2 would give us the binary\n // representation of the number.\n const { length: maxBits } = range.toString(2 /* radix */);\n\n // We can only generate random data in bytes, not bits, so we need to generate\n // enough bytes to cover the required number of bits.\n const maxBytes = Math.ceil(maxBits / 8);\n\n // The number of bits we need to ignore in the random bitmap we generate.\n const excessBits = BigInt(8 - (maxBits % 8));\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- It's more readable than using a do..while loop.\n while (true) {\n // We use `crypto` for our RNG, it should be supported in all modern\n // environments we support.\n const randomBytes = random(maxBytes);\n\n const raw = asBigInt(randomBytes);\n\n // Shift the number back to our range, this effectively sets the excess bits\n // to 0.\n const result = raw >> excessBits;\n\n // The generated number might overflow when `range < 2 ** maxBits - 1`, so\n // it can't be returned. To ensure that all possible results have the same\n // probability, we ignore the value entirely and try again (instead of\n // trying to adapt it to the output range somehow).\n if (result <= range) {\n return result + from;\n }\n }\n}\n\nfunction asBigInt(bytes: Iterable<number>): bigint {\n let result = 0n;\n for (const byte of bytes) {\n // We build the bigint by shifting the current value by a byte, and putting\n // the next byte in that \"slot\".\n result = (result << 8n) + BigInt(byte);\n }\n return result;\n}\n\nfunction random(numBytes: number): Uint8Array {\n const output = new Uint8Array(numBytes);\n\n if (typeof crypto === \"undefined\") {\n // Polyfill for environments without `crypto` support. The only env which\n // requires this and we support is Node 18; once we drop support for it we\n // can drop the polyfill.\n for (let index = 0; index < numBytes; index += 1) {\n output[index] = Math.floor(Math.random() * 256);\n }\n } else {\n crypto.getRandomValues(output);\n }\n\n return output;\n}\n"],"mappings":"mEAyBA,SAAgB,EAAa,EAAc,EAAoB,CAC7D,GAAI,EAAK,EACP,MAAU,WACR,4BAA4B,EAAK,UAAU,CAAC,GAAG,EAAG,UAAU,CAAC,aAC9D,CAGH,IAAM,EAAQ,EAAK,EAKb,CAAE,OAAQ,GAAY,EAAM,SAAS,EAAc,CAInD,EAAW,KAAK,KAAK,EAAU,EAAE,CAGjC,EAAa,OAAO,EAAK,EAAU,EAAG,CAG5C,OAAa,CASX,IAAM,EAJM,EAFQ,EAAO,EAAS,CAEH,EAIX,EAMtB,GAAI,GAAU,EACZ,OAAO,EAAS,GAKtB,SAAS,EAAS,EAAiC,CACjD,IAAI,EAAS,GACb,IAAK,IAAM,KAAQ,EAGjB,GAAU,GAAU,IAAM,OAAO,EAAK,CAExC,OAAO,EAGT,SAAS,EAAO,EAA8B,CAC5C,IAAM,EAAS,IAAI,WAAW,EAAS,CAEvC,GAAI,OAAO,OAAW,IAIpB,IAAK,IAAI,EAAQ,EAAG,EAAQ,EAAU,GAAS,EAC7C,EAAO,GAAS,KAAK,MAAM,KAAK,QAAQ,CAAG,IAAI,MAGjD,OAAO,gBAAgB,EAAO,CAGhC,OAAO"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e,r){if(r<e)throw RangeError(`randomBigInt: The range [${e.toString()},${r.toString()}] is empty.`);let i=r-e,{length:a}=i.toString(2),o=Math.ceil(a/8),s=BigInt(8-a%8);for(;;){let r=t(n(o))>>s;if(r<=i)return r+e}}function t(e){let t=0n;for(let n of e)t=(t<<8n)+BigInt(n);return t}function n(e){let t=new Uint8Array(e);if(typeof crypto>`u`)for(let n=0;n<e;n+=1)t[n]=Math.floor(Math.random()*256);else crypto.getRandomValues(t);return t}export{e as randomBigInt};
|
|
2
|
+
//# sourceMappingURL=randomBigInt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"randomBigInt.js","names":[],"sources":["../src/randomBigInt.ts"],"sourcesContent":["/* eslint-disable no-bitwise, @typescript-eslint/no-magic-numbers --\n * We randomize the bigint using randomized bitmaps, we have to use bitwise\n * operations to manipulate them.\n */\n\n/**\n * Generate a random `bigint` between `from` and `to` (inclusive).\n *\n * ! Important: In most environments this function uses\n * [`crypto.getRandomValues()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues)\n * under-the-hood which **is** cryptographically strong. When the WebCrypto API\n * isn't available (Node 18) we fallback to an implementation that uses\n * [`Math.random()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)\n * which is **NOT** cryptographically secure.\n *\n * @param from - The minimum value.\n * @param to - The maximum value.\n * @returns The random integer.\n * @signature\n * randomBigInt(from, to)\n * @example\n * randomBigInt(1n, 10n) // => 5n\n * @dataFirst\n * @category Number\n */\nexport function randomBigInt(from: bigint, to: bigint): bigint {\n if (to < from) {\n throw new RangeError(\n `randomBigInt: The range [${from.toString()},${to.toString()}] is empty.`,\n );\n }\n\n const range = to - from;\n\n // Get the max number of bits needed to encode the result. We will generate\n // this number of random bits. A radix of 2 would give us the binary\n // representation of the number.\n const { length: maxBits } = range.toString(2 /* radix */);\n\n // We can only generate random data in bytes, not bits, so we need to generate\n // enough bytes to cover the required number of bits.\n const maxBytes = Math.ceil(maxBits / 8);\n\n // The number of bits we need to ignore in the random bitmap we generate.\n const excessBits = BigInt(8 - (maxBits % 8));\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- It's more readable than using a do..while loop.\n while (true) {\n // We use `crypto` for our RNG, it should be supported in all modern\n // environments we support.\n const randomBytes = random(maxBytes);\n\n const raw = asBigInt(randomBytes);\n\n // Shift the number back to our range, this effectively sets the excess bits\n // to 0.\n const result = raw >> excessBits;\n\n // The generated number might overflow when `range < 2 ** maxBits - 1`, so\n // it can't be returned. To ensure that all possible results have the same\n // probability, we ignore the value entirely and try again (instead of\n // trying to adapt it to the output range somehow).\n if (result <= range) {\n return result + from;\n }\n }\n}\n\nfunction asBigInt(bytes: Iterable<number>): bigint {\n let result = 0n;\n for (const byte of bytes) {\n // We build the bigint by shifting the current value by a byte, and putting\n // the next byte in that \"slot\".\n result = (result << 8n) + BigInt(byte);\n }\n return result;\n}\n\nfunction random(numBytes: number): Uint8Array {\n const output = new Uint8Array(numBytes);\n\n if (typeof crypto === \"undefined\") {\n // Polyfill for environments without `crypto` support. The only env which\n // requires this and we support is Node 18; once we drop support for it we\n // can drop the polyfill.\n for (let index = 0; index < numBytes; index += 1) {\n output[index] = Math.floor(Math.random() * 256);\n }\n } else {\n crypto.getRandomValues(output);\n }\n\n return output;\n}\n"],"mappings":"AAyBA,SAAgB,EAAa,EAAc,EAAoB,CAC7D,GAAI,EAAK,EACP,MAAU,WACR,4BAA4B,EAAK,UAAU,CAAC,GAAG,EAAG,UAAU,CAAC,aAC9D,CAGH,IAAM,EAAQ,EAAK,EAKb,CAAE,OAAQ,GAAY,EAAM,SAAS,EAAc,CAInD,EAAW,KAAK,KAAK,EAAU,EAAE,CAGjC,EAAa,OAAO,EAAK,EAAU,EAAG,CAG5C,OAAa,CASX,IAAM,EAJM,EAFQ,EAAO,EAAS,CAEH,EAIX,EAMtB,GAAI,GAAU,EACZ,OAAO,EAAS,GAKtB,SAAS,EAAS,EAAiC,CACjD,IAAI,EAAS,GACb,IAAK,IAAM,KAAQ,EAGjB,GAAU,GAAU,IAAM,OAAO,EAAK,CAExC,OAAO,EAGT,SAAS,EAAO,EAA8B,CAC5C,IAAM,EAAS,IAAI,WAAW,EAAS,CAEvC,GAAI,OAAO,OAAW,IAIpB,IAAK,IAAI,EAAQ,EAAG,EAAQ,EAAU,GAAS,EAC7C,EAAO,GAAS,KAAK,MAAM,KAAK,QAAQ,CAAG,IAAI,MAGjD,OAAO,gBAAgB,EAAO,CAGhC,OAAO"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e,t){let n=Math.ceil(e),r=Math.floor(t);if(r<n)throw RangeError(`randomInteger: The range [${e.toString()},${t.toString()}] contains no integer`);return Math.floor(Math.random()*(r-n+1)+n)}exports.randomInteger=e;
|
|
2
|
+
//# sourceMappingURL=randomInteger.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"randomInteger.cjs","names":[],"sources":["../src/randomInteger.ts"],"sourcesContent":["import type {\n GreaterThan,\n GreaterThanOrEqual,\n IsEqual,\n IsNever,\n NonNegativeInteger,\n Or,\n} from \"type-fest\";\nimport type { IntRangeInclusive } from \"./internal/types/IntRangeInclusive\";\n\n// This limitation is defined by type-fest\ntype MaxLiteral = 1000;\n\ntype RandomInteger<From extends number, To extends number> =\n Or<\n IsNever<NonNegativeInteger<From>>,\n IsNever<NonNegativeInteger<To>>\n > extends true\n ? number\n : IsEqual<From, To> extends true\n ? From\n : GreaterThan<From, To> extends true\n ? never\n : GreaterThanOrEqual<To, MaxLiteral> extends true\n ? number\n : IntRangeInclusive<From, To>;\n\n/**\n * Generate a random integer between `from` and `to` (inclusive).\n *\n * !Important: This function uses [`Math.random()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) under-the-hood, which has two major limitations:\n * 1. It generates 2^52 possible values, so the bigger the range, the less\n * uniform the distribution of values would be, and at ranges larger than that\n * some values would never come up.\n * 2. It is not cryptographically secure and should not be used for security\n * scenarios.\n *\n * @param from - The minimum value.\n * @param to - The maximum value.\n * @returns The random integer.\n * @signature\n * randomInteger(from, to)\n * @example\n * randomInteger(1, 10) // => 5\n * randomInteger(1.5, 2.6) // => 2\n * @dataFirst\n * @category Number\n */\nexport function randomInteger<From extends number, To extends number>(\n from: From,\n to: To,\n): RandomInteger<From, To> {\n const fromCeiled = Math.ceil(from);\n const toFloored = Math.floor(to);\n\n if (toFloored < fromCeiled) {\n throw new RangeError(\n `randomInteger: The range [${from.toString()},${to.toString()}] contains no integer`,\n );\n }\n\n return Math.floor(\n Math.random() * (toFloored - fromCeiled + 1) + fromCeiled,\n ) as RandomInteger<From, To>;\n}\n"],"mappings":"mEAgDA,SAAgB,EACd,EACA,EACyB,CACzB,IAAM,EAAa,KAAK,KAAK,EAAK,CAC5B,EAAY,KAAK,MAAM,EAAG,CAEhC,GAAI,EAAY,EACd,MAAU,WACR,6BAA6B,EAAK,UAAU,CAAC,GAAG,EAAG,UAAU,CAAC,uBAC/D,CAGH,OAAO,KAAK,MACV,KAAK,QAAQ,EAAI,EAAY,EAAa,GAAK,EAChD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"randomInteger.js","names":[],"sources":["../src/randomInteger.ts"],"sourcesContent":["import type {\n GreaterThan,\n GreaterThanOrEqual,\n IsEqual,\n IsNever,\n NonNegativeInteger,\n Or,\n} from \"type-fest\";\nimport type { IntRangeInclusive } from \"./internal/types/IntRangeInclusive\";\n\n// This limitation is defined by type-fest\ntype MaxLiteral = 1000;\n\ntype RandomInteger<From extends number, To extends number> =\n Or<\n IsNever<NonNegativeInteger<From>>,\n IsNever<NonNegativeInteger<To>>\n > extends true\n ? number\n : IsEqual<From, To> extends true\n ? From\n : GreaterThan<From, To> extends true\n ? never\n : GreaterThanOrEqual<To, MaxLiteral> extends true\n ? number\n : IntRangeInclusive<From, To>;\n\n/**\n * Generate a random integer between `from` and `to` (inclusive).\n *\n * !Important: This function uses [`Math.random()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) under-the-hood, which has two major limitations:\n * 1. It generates 2^52 possible values, so the bigger the range, the less\n * uniform the distribution of values would be, and at ranges larger than that\n * some values would never come up.\n * 2. It is not cryptographically secure and should not be used for security\n * scenarios.\n *\n * @param from - The minimum value.\n * @param to - The maximum value.\n * @returns The random integer.\n * @signature\n * randomInteger(from, to)\n * @example\n * randomInteger(1, 10) // => 5\n * randomInteger(1.5, 2.6) // => 2\n * @dataFirst\n * @category Number\n */\nexport function randomInteger<From extends number, To extends number>(\n from: From,\n to: To,\n): RandomInteger<From, To> {\n const fromCeiled = Math.ceil(from);\n const toFloored = Math.floor(to);\n\n if (toFloored < fromCeiled) {\n throw new RangeError(\n `randomInteger: The range [${from.toString()},${to.toString()}] contains no integer`,\n );\n }\n\n return Math.floor(\n Math.random() * (toFloored - fromCeiled + 1) + fromCeiled,\n ) as RandomInteger<From, To>;\n}\n"],"mappings":"AAgDA,SAAgB,EACd,EACA,EACyB,CACzB,IAAM,EAAa,KAAK,KAAK,EAAK,CAC5B,EAAY,KAAK,MAAM,EAAG,CAEhC,GAAI,EAAY,EACd,MAAU,WACR,6BAA6B,EAAK,UAAU,CAAC,GAAG,EAAG,UAAU,CAAC,uBAC/D,CAGH,OAAO,KAAK,MACV,KAAK,QAAQ,EAAI,EAAY,EAAa,GAAK,EAChD"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./purry.cjs`);function t(...t){return e.purry(n,t)}function n(e){let t=[];for(let n=0;n<e;n++){let e=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`[Math.floor(Math.random()*62)];t.push(e)}return t.join(``)}exports.randomString=t;
|
|
2
|
+
//# sourceMappingURL=randomString.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"randomString.cjs","names":["purry"],"sources":["../src/randomString.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\nconst ALPHABET =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n\n/**\n * A [pseudo-random](https://en.wikipedia.org/wiki/Pseudorandom_number_generator) [alpha-numeric](https://en.wikipedia.org/wiki/Alphanumericals)\n * [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String).\n *\n * It is not [cryptographically secure](https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator)!\n *\n * @param length - The length of the random string.\n * @returns The random string.\n * @signature\n * randomString(length)\n * @example\n * randomString(5) // => aB92J\n * @dataFirst\n * @category String\n */\nexport function randomString(length: number): string;\n\n/**\n * A [pseudo-random](https://en.wikipedia.org/wiki/Pseudorandom_number_generator) [alpha-numeric](https://en.wikipedia.org/wiki/Alphanumericals)\n * [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String).\n *\n * It is not [cryptographically secure](https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator)!\n *\n * @returns The random string.\n * @signature\n * randomString()(length)\n * @example\n * pipe(5, randomString()) // => aB92J\n * @dataLast\n * @category String\n */\nexport function randomString(): (length: number) => string;\n\nexport function randomString(...args: readonly unknown[]): unknown {\n return purry(randomStringImplementation, args);\n}\n\nfunction randomStringImplementation(length: number): string {\n const out: string[] = [];\n for (let iteration = 0; iteration < length; iteration++) {\n const randomChar = ALPHABET[Math.floor(Math.random() * ALPHABET.length)]!;\n out.push(randomChar);\n }\n return out.join(\"\");\n}\n"],"mappings":"kGAsCA,SAAgB,EAAa,GAAG,EAAmC,CACjE,OAAOA,EAAAA,MAAM,EAA4B,EAAK,CAGhD,SAAS,EAA2B,EAAwB,CAC1D,IAAM,EAAgB,EAAE,CACxB,IAAK,IAAI,EAAY,EAAG,EAAY,EAAQ,IAAa,CACvD,IAAM,EAAa,iEAAS,KAAK,MAAM,KAAK,QAAQ,CAAG,GAAgB,EACvE,EAAI,KAAK,EAAW,CAEtB,OAAO,EAAI,KAAK,GAAG"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{purry as e}from"./purry.js";function t(...t){return e(n,t)}function n(e){let t=[];for(let n=0;n<e;n++){let e=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`[Math.floor(Math.random()*62)];t.push(e)}return t.join(``)}export{t as randomString};
|
|
2
|
+
//# sourceMappingURL=randomString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"randomString.js","names":[],"sources":["../src/randomString.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\nconst ALPHABET =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n\n/**\n * A [pseudo-random](https://en.wikipedia.org/wiki/Pseudorandom_number_generator) [alpha-numeric](https://en.wikipedia.org/wiki/Alphanumericals)\n * [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String).\n *\n * It is not [cryptographically secure](https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator)!\n *\n * @param length - The length of the random string.\n * @returns The random string.\n * @signature\n * randomString(length)\n * @example\n * randomString(5) // => aB92J\n * @dataFirst\n * @category String\n */\nexport function randomString(length: number): string;\n\n/**\n * A [pseudo-random](https://en.wikipedia.org/wiki/Pseudorandom_number_generator) [alpha-numeric](https://en.wikipedia.org/wiki/Alphanumericals)\n * [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String).\n *\n * It is not [cryptographically secure](https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator)!\n *\n * @returns The random string.\n * @signature\n * randomString()(length)\n * @example\n * pipe(5, randomString()) // => aB92J\n * @dataLast\n * @category String\n */\nexport function randomString(): (length: number) => string;\n\nexport function randomString(...args: readonly unknown[]): unknown {\n return purry(randomStringImplementation, args);\n}\n\nfunction randomStringImplementation(length: number): string {\n const out: string[] = [];\n for (let iteration = 0; iteration < length; iteration++) {\n const randomChar = ALPHABET[Math.floor(Math.random() * ALPHABET.length)]!;\n out.push(randomChar);\n }\n return out.join(\"\");\n}\n"],"mappings":"mCAsCA,SAAgB,EAAa,GAAG,EAAmC,CACjE,OAAO,EAAM,EAA4B,EAAK,CAGhD,SAAS,EAA2B,EAAwB,CAC1D,IAAM,EAAgB,EAAE,CACxB,IAAK,IAAI,EAAY,EAAG,EAAY,EAAQ,IAAa,CACvD,IAAM,EAAa,iEAAS,KAAK,MAAM,KAAK,QAAQ,CAAG,GAAgB,EACvE,EAAI,KAAK,EAAW,CAEtB,OAAO,EAAI,KAAK,GAAG"}
|
package/dist/range.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range.cjs","names":["purry"],"sources":["../src/range.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\n/**\n * Returns a list of numbers from `start` (inclusive) to `end` (exclusive).\n *\n * @param start - The start number.\n * @param end - The end number.\n * @signature range(start, end)\n * @example\n * range(1, 5) // => [1, 2, 3, 4]\n * @dataFirst\n * @category Array\n */\nexport function range(start: number, end: number): number[];\n\n/**\n * Returns a list of numbers from `start` (inclusive) to `end` (exclusive).\n *\n * @param end - The end number.\n * @signature range(end)(start)\n * @example\n * range(5)(1) // => [1, 2, 3, 4]\n * @dataLast\n * @category Array\n */\nexport function range(end: number): (start: number) => number[];\n\nexport function range(...args: readonly unknown[]): unknown {\n return purry(rangeImplementation, args);\n}\n\nfunction rangeImplementation(start: number, end: number): number[] {\n const ret: number[] = [];\n for (let i = start; i < end; i++) {\n ret.push(i);\n }\n return ret;\n}\n"],"mappings":"kGA2BA,SAAgB,EAAM,GAAG,EAAmC,CAC1D,OAAOA,EAAAA,MAAM,EAAqB,EAAK,CAGzC,SAAS,EAAoB,EAAe,EAAuB,CACjE,IAAM,EAAgB,EAAE,CACxB,IAAK,IAAI,EAAI,EAAO,EAAI,EAAK,IAC3B,EAAI,KAAK,EAAE,CAEb,OAAO"}
|
package/dist/range.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range.js","names":[],"sources":["../src/range.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\n/**\n * Returns a list of numbers from `start` (inclusive) to `end` (exclusive).\n *\n * @param start - The start number.\n * @param end - The end number.\n * @signature range(start, end)\n * @example\n * range(1, 5) // => [1, 2, 3, 4]\n * @dataFirst\n * @category Array\n */\nexport function range(start: number, end: number): number[];\n\n/**\n * Returns a list of numbers from `start` (inclusive) to `end` (exclusive).\n *\n * @param end - The end number.\n * @signature range(end)(start)\n * @example\n * range(5)(1) // => [1, 2, 3, 4]\n * @dataLast\n * @category Array\n */\nexport function range(end: number): (start: number) => number[];\n\nexport function range(...args: readonly unknown[]): unknown {\n return purry(rangeImplementation, args);\n}\n\nfunction rangeImplementation(start: number, end: number): number[] {\n const ret: number[] = [];\n for (let i = start; i < end; i++) {\n ret.push(i);\n }\n return ret;\n}\n"],"mappings":"mCA2BA,SAAgB,EAAM,GAAG,EAAmC,CAC1D,OAAO,EAAM,EAAqB,EAAK,CAGzC,SAAS,EAAoB,EAAe,EAAuB,CACjE,IAAM,EAAgB,EAAE,CACxB,IAAK,IAAI,EAAI,EAAO,EAAI,EAAK,IAC3B,EAAI,KAAK,EAAE,CAEb,OAAO"}
|
package/dist/rankBy.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rankBy.cjs","names":["purryOrderRulesWithArgument"],"sources":["../src/rankBy.ts"],"sourcesContent":["import {\n purryOrderRulesWithArgument,\n type OrderRule,\n} from \"./internal/purryOrderRules\";\nimport type { CompareFunction } from \"./internal/types/CompareFunction\";\nimport type { NonEmptyArray } from \"./internal/types/NonEmptyArray\";\n\n/**\n * Calculates the rank of an item in an array based on `rules`. The rank is the position where the item would appear in the sorted array. This function provides an efficient way to determine the rank in *O(n)* time, compared to *O(nlogn)* for the equivalent `sortedIndex(sortBy(data, ...rules), item)`.\n *\n * @param data - The input array.\n * @param item - The item whose rank is to be determined.\n * @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, \"desc\"]` for descending order.\n * @returns The rank of the item in the sorted array in the range [0..data.length].\n * @signature\n * rankBy(data, item, ...rules)\n * @example\n * const DATA = [{ a: 5 }, { a: 1 }, { a: 3 }] as const;\n * rankBy(DATA, 0, prop('a')) // => 0\n * rankBy(DATA, 1, prop('a')) // => 1\n * rankBy(DATA, 2, prop('a')) // => 1\n * rankBy(DATA, 3, prop('a')) // => 2\n * @dataFirst\n * @category Array\n */\nexport function rankBy<T>(\n data: readonly T[],\n item: T,\n ...rules: Readonly<NonEmptyArray<OrderRule<T>>>\n): number;\n\n/**\n * Calculates the rank of an item in an array based on `rules`. The rank is the position where the item would appear in the sorted array. This function provides an efficient way to determine the rank in *O(n)* time, compared to *O(nlogn)* for the equivalent `sortedIndex(sortBy(data, ...rules), item)`.\n *\n * @param item - The item whose rank is to be determined.\n * @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, \"desc\"]` for descending order.\n * @returns The rank of the item in the sorted array in the range [0..data.length].\n * @signature\n * rankBy(item, ...rules)(data)\n * @example\n * const DATA = [{ a: 5 }, { a: 1 }, { a: 3 }] as const;\n * pipe(DATA, rankBy(0, prop('a'))) // => 0\n * pipe(DATA, rankBy(1, prop('a'))) // => 1\n * pipe(DATA, rankBy(2, prop('a'))) // => 1\n * pipe(DATA, rankBy(3, prop('a'))) // => 2\n * @dataLast\n * @category Array\n */\nexport function rankBy<T>(\n item: T,\n ...rules: Readonly<NonEmptyArray<OrderRule<T>>>\n): (data: readonly T[]) => number;\n\nexport function rankBy(...args: readonly unknown[]): unknown {\n return purryOrderRulesWithArgument(rankByImplementation, args);\n}\n\nfunction rankByImplementation<T>(\n data: readonly T[],\n compareFn: CompareFunction<T>,\n targetItem: T,\n): number {\n let rank = 0;\n for (const item of data) {\n if (compareFn(targetItem, item) > 0) {\n // The rank of the item is equivalent to the number of items that would\n // come before it if the array was sorted. We assume that the\n rank += 1;\n }\n }\n return rank;\n}\n"],"mappings":"qHAqDA,SAAgB,EAAO,GAAG,EAAmC,CAC3D,OAAOA,EAAAA,EAA4B,EAAsB,EAAK,CAGhE,SAAS,EACP,EACA,EACA,EACQ,CACR,IAAI,EAAO,EACX,IAAK,IAAM,KAAQ,EACb,EAAU,EAAY,EAAK,CAAG,IAGhC,GAAQ,GAGZ,OAAO"}
|
package/dist/rankBy.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rankBy.js","names":[],"sources":["../src/rankBy.ts"],"sourcesContent":["import {\n purryOrderRulesWithArgument,\n type OrderRule,\n} from \"./internal/purryOrderRules\";\nimport type { CompareFunction } from \"./internal/types/CompareFunction\";\nimport type { NonEmptyArray } from \"./internal/types/NonEmptyArray\";\n\n/**\n * Calculates the rank of an item in an array based on `rules`. The rank is the position where the item would appear in the sorted array. This function provides an efficient way to determine the rank in *O(n)* time, compared to *O(nlogn)* for the equivalent `sortedIndex(sortBy(data, ...rules), item)`.\n *\n * @param data - The input array.\n * @param item - The item whose rank is to be determined.\n * @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, \"desc\"]` for descending order.\n * @returns The rank of the item in the sorted array in the range [0..data.length].\n * @signature\n * rankBy(data, item, ...rules)\n * @example\n * const DATA = [{ a: 5 }, { a: 1 }, { a: 3 }] as const;\n * rankBy(DATA, 0, prop('a')) // => 0\n * rankBy(DATA, 1, prop('a')) // => 1\n * rankBy(DATA, 2, prop('a')) // => 1\n * rankBy(DATA, 3, prop('a')) // => 2\n * @dataFirst\n * @category Array\n */\nexport function rankBy<T>(\n data: readonly T[],\n item: T,\n ...rules: Readonly<NonEmptyArray<OrderRule<T>>>\n): number;\n\n/**\n * Calculates the rank of an item in an array based on `rules`. The rank is the position where the item would appear in the sorted array. This function provides an efficient way to determine the rank in *O(n)* time, compared to *O(nlogn)* for the equivalent `sortedIndex(sortBy(data, ...rules), item)`.\n *\n * @param item - The item whose rank is to be determined.\n * @param rules - A variadic array of order rules defining the sorting criteria. Each order rule is a projection function that extracts a comparable value from the data. Sorting is based on these extracted values using the native `<` and `>` operators. Earlier rules take precedence over later ones. Use the syntax `[projection, \"desc\"]` for descending order.\n * @returns The rank of the item in the sorted array in the range [0..data.length].\n * @signature\n * rankBy(item, ...rules)(data)\n * @example\n * const DATA = [{ a: 5 }, { a: 1 }, { a: 3 }] as const;\n * pipe(DATA, rankBy(0, prop('a'))) // => 0\n * pipe(DATA, rankBy(1, prop('a'))) // => 1\n * pipe(DATA, rankBy(2, prop('a'))) // => 1\n * pipe(DATA, rankBy(3, prop('a'))) // => 2\n * @dataLast\n * @category Array\n */\nexport function rankBy<T>(\n item: T,\n ...rules: Readonly<NonEmptyArray<OrderRule<T>>>\n): (data: readonly T[]) => number;\n\nexport function rankBy(...args: readonly unknown[]): unknown {\n return purryOrderRulesWithArgument(rankByImplementation, args);\n}\n\nfunction rankByImplementation<T>(\n data: readonly T[],\n compareFn: CompareFunction<T>,\n targetItem: T,\n): number {\n let rank = 0;\n for (const item of data) {\n if (compareFn(targetItem, item) > 0) {\n // The rank of the item is equivalent to the number of items that would\n // come before it if the array was sorted. We assume that the\n rank += 1;\n }\n }\n return rank;\n}\n"],"mappings":"kDAqDA,SAAgB,EAAO,GAAG,EAAmC,CAC3D,OAAO,EAA4B,EAAsB,EAAK,CAGhE,SAAS,EACP,EACA,EACA,EACQ,CACR,IAAI,EAAO,EACX,IAAK,IAAM,KAAQ,EACb,EAAU,EAAY,EAAK,CAAG,IAGhC,GAAQ,GAGZ,OAAO"}
|
package/dist/reduce.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reduce.cjs","names":["purry"],"sources":["../src/reduce.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\n/**\n * Executes a user-supplied \"reducer\" callback function on each element of the\n * array, in order, passing in the return value from the calculation on the\n * preceding element. The final result of running the reducer across all\n * elements of the array is a single value. Equivalent to\n * `Array.prototype.reduce`.\n *\n * @param data - The items to reduce.\n * @param callbackfn - A function to execute for each element in the array. Its\n * return value becomes the value of the accumulator parameter on the next\n * invocation of callbackFn. For the last invocation, the return value becomes\n * the return value of reduce().\n * @param initialValue - A value to which accumulator is initialized the first\n * time the callback is called. CallbackFn starts executing with the first value\n * in the array as currentValue.\n * @returns The value that results from running the \"reducer\" callback function\n * to completion over the entire array.\n * @signature\n * reduce(data, callbackfn, initialValue)\n * @example\n * reduce([1, 2, 3, 4, 5], (acc, x) => acc + x, 100) // => 115\n * @dataFirst\n * @category Array\n */\nexport function reduce<T, U>(\n data: readonly T[],\n callbackfn: (\n previousValue: U,\n currentValue: T,\n currentIndex: number,\n data: readonly T[],\n ) => U,\n initialValue: U,\n): U;\n\n/**\n * Executes a user-supplied \"reducer\" callback function on each element of the\n * array, in order, passing in the return value from the calculation on the\n * preceding element. The final result of running the reducer across all\n * elements of the array is a single value. Equivalent to\n * `Array.prototype.reduce`.\n *\n * @param callbackfn - A function to execute for each element in the array. Its\n * return value becomes the value of the accumulator parameter on the next\n * invocation of callbackFn. For the last invocation, the return value becomes\n * the return value of reduce().\n * @param initialValue - A value to which accumulator is initialized the first\n * time the callback is called. CallbackFn starts executing with the first value\n * in the array as currentValue.\n * @returns The value that results from running the \"reducer\" callback function\n * to completion over the entire array.\n * @signature\n * reduce(fn, initialValue)(array)\n * @example\n * pipe([1, 2, 3, 4, 5], reduce((acc, x) => acc + x, 100)) // => 115\n * @dataLast\n * @category Array\n */\nexport function reduce<T, U>(\n callbackfn: (\n previousValue: U,\n currentValue: T,\n currentIndex: number,\n data: readonly T[],\n ) => U,\n initialValue: U,\n): (data: readonly T[]) => U;\n\nexport function reduce(...args: readonly unknown[]): unknown {\n return purry(reduceImplementation, args);\n}\n\nconst reduceImplementation = <T, U>(\n data: readonly T[],\n callbackfn: (\n previousValue: U,\n currentValue: T,\n currentIndex: number,\n data: readonly T[],\n ) => U,\n initialValue: U,\n): U =>\n // eslint-disable-next-line unicorn/no-array-reduce -- Our function wraps the built-in reduce.\n data.reduce(callbackfn, initialValue);\n"],"mappings":"kGAsEA,SAAgB,EAAO,GAAG,EAAmC,CAC3D,OAAOA,EAAAA,MAAM,EAAsB,EAAK,CAG1C,MAAM,GACJ,EACA,EAMA,IAGA,EAAK,OAAO,EAAY,EAAa"}
|
package/dist/reduce.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reduce.js","names":[],"sources":["../src/reduce.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\n/**\n * Executes a user-supplied \"reducer\" callback function on each element of the\n * array, in order, passing in the return value from the calculation on the\n * preceding element. The final result of running the reducer across all\n * elements of the array is a single value. Equivalent to\n * `Array.prototype.reduce`.\n *\n * @param data - The items to reduce.\n * @param callbackfn - A function to execute for each element in the array. Its\n * return value becomes the value of the accumulator parameter on the next\n * invocation of callbackFn. For the last invocation, the return value becomes\n * the return value of reduce().\n * @param initialValue - A value to which accumulator is initialized the first\n * time the callback is called. CallbackFn starts executing with the first value\n * in the array as currentValue.\n * @returns The value that results from running the \"reducer\" callback function\n * to completion over the entire array.\n * @signature\n * reduce(data, callbackfn, initialValue)\n * @example\n * reduce([1, 2, 3, 4, 5], (acc, x) => acc + x, 100) // => 115\n * @dataFirst\n * @category Array\n */\nexport function reduce<T, U>(\n data: readonly T[],\n callbackfn: (\n previousValue: U,\n currentValue: T,\n currentIndex: number,\n data: readonly T[],\n ) => U,\n initialValue: U,\n): U;\n\n/**\n * Executes a user-supplied \"reducer\" callback function on each element of the\n * array, in order, passing in the return value from the calculation on the\n * preceding element. The final result of running the reducer across all\n * elements of the array is a single value. Equivalent to\n * `Array.prototype.reduce`.\n *\n * @param callbackfn - A function to execute for each element in the array. Its\n * return value becomes the value of the accumulator parameter on the next\n * invocation of callbackFn. For the last invocation, the return value becomes\n * the return value of reduce().\n * @param initialValue - A value to which accumulator is initialized the first\n * time the callback is called. CallbackFn starts executing with the first value\n * in the array as currentValue.\n * @returns The value that results from running the \"reducer\" callback function\n * to completion over the entire array.\n * @signature\n * reduce(fn, initialValue)(array)\n * @example\n * pipe([1, 2, 3, 4, 5], reduce((acc, x) => acc + x, 100)) // => 115\n * @dataLast\n * @category Array\n */\nexport function reduce<T, U>(\n callbackfn: (\n previousValue: U,\n currentValue: T,\n currentIndex: number,\n data: readonly T[],\n ) => U,\n initialValue: U,\n): (data: readonly T[]) => U;\n\nexport function reduce(...args: readonly unknown[]): unknown {\n return purry(reduceImplementation, args);\n}\n\nconst reduceImplementation = <T, U>(\n data: readonly T[],\n callbackfn: (\n previousValue: U,\n currentValue: T,\n currentIndex: number,\n data: readonly T[],\n ) => U,\n initialValue: U,\n): U =>\n // eslint-disable-next-line unicorn/no-array-reduce -- Our function wraps the built-in reduce.\n data.reduce(callbackfn, initialValue);\n"],"mappings":"mCAsEA,SAAgB,EAAO,GAAG,EAAmC,CAC3D,OAAO,EAAM,EAAsB,EAAK,CAG1C,MAAM,GACJ,EACA,EAMA,IAGA,EAAK,OAAO,EAAY,EAAa"}
|
package/dist/reverse.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reverse.cjs","names":["purry"],"sources":["../src/reverse.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\ntype Reverse<\n T extends readonly unknown[],\n R extends readonly unknown[] = [],\n> = ReturnType<\n T extends IsNoTuple<T>\n ? () => [...T, ...R]\n : T extends readonly [infer F, ...infer L]\n ? () => Reverse<L, [F, ...R]>\n : () => R\n>;\n\ntype IsNoTuple<T> = T extends readonly [unknown, ...unknown[]] ? never : T;\n\n/**\n * Reverses array.\n *\n * @param array - The array.\n * @signature\n * reverse(arr);\n * @example\n * reverse([1, 2, 3]) // [3, 2, 1]\n * @dataFirst\n * @category Array\n */\nexport function reverse<T extends readonly unknown[]>(array: T): Reverse<T>;\n\n/**\n * Reverses array.\n *\n * @signature\n * reverse()(array);\n * @example\n * reverse()([1, 2, 3]) // [3, 2, 1]\n * @dataLast\n * @category Array\n */\nexport function reverse<T extends readonly unknown[]>(): (\n array: T,\n) => Reverse<T>;\n\nexport function reverse(...args: readonly unknown[]): unknown {\n return purry(reverseImplementation, args);\n}\n\nfunction reverseImplementation<T>(array: readonly T[]): T[] {\n // TODO [>2]: When node 18 reaches end-of-life bump target lib to ES2023+ and use `Array.prototype.toReversed` here.\n // eslint-disable-next-line unicorn/no-array-reverse -- See TODO above.\n return [...array].reverse();\n}\n"],"mappings":"kGA0CA,SAAgB,EAAQ,GAAG,EAAmC,CAC5D,OAAOA,EAAAA,MAAM,EAAuB,EAAK,CAG3C,SAAS,EAAyB,EAA0B,CAG1D,MAAO,CAAC,GAAG,EAAM,CAAC,SAAS"}
|
package/dist/reverse.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reverse.js","names":[],"sources":["../src/reverse.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\ntype Reverse<\n T extends readonly unknown[],\n R extends readonly unknown[] = [],\n> = ReturnType<\n T extends IsNoTuple<T>\n ? () => [...T, ...R]\n : T extends readonly [infer F, ...infer L]\n ? () => Reverse<L, [F, ...R]>\n : () => R\n>;\n\ntype IsNoTuple<T> = T extends readonly [unknown, ...unknown[]] ? never : T;\n\n/**\n * Reverses array.\n *\n * @param array - The array.\n * @signature\n * reverse(arr);\n * @example\n * reverse([1, 2, 3]) // [3, 2, 1]\n * @dataFirst\n * @category Array\n */\nexport function reverse<T extends readonly unknown[]>(array: T): Reverse<T>;\n\n/**\n * Reverses array.\n *\n * @signature\n * reverse()(array);\n * @example\n * reverse()([1, 2, 3]) // [3, 2, 1]\n * @dataLast\n * @category Array\n */\nexport function reverse<T extends readonly unknown[]>(): (\n array: T,\n) => Reverse<T>;\n\nexport function reverse(...args: readonly unknown[]): unknown {\n return purry(reverseImplementation, args);\n}\n\nfunction reverseImplementation<T>(array: readonly T[]): T[] {\n // TODO [>2]: When node 18 reaches end-of-life bump target lib to ES2023+ and use `Array.prototype.toReversed` here.\n // eslint-disable-next-line unicorn/no-array-reverse -- See TODO above.\n return [...array].reverse();\n}\n"],"mappings":"mCA0CA,SAAgB,EAAQ,GAAG,EAAmC,CAC5D,OAAO,EAAM,EAAuB,EAAK,CAG3C,SAAS,EAAyB,EAA0B,CAG1D,MAAO,CAAC,GAAG,EAAM,CAAC,SAAS"}
|
package/dist/round.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"round.cjs","names":["purry","withPrecision"],"sources":["../src/round.ts"],"sourcesContent":["import { withPrecision } from \"./internal/withPrecision\";\nimport { purry } from \"./purry\";\n\n/**\n * Rounds a given number to a specific precision.\n * If you'd like to round to an integer (i.e. use this function with constant `precision === 0`),\n * use `Math.round` instead, as it won't incur the additional library overhead.\n *\n * @param value - The number to round.\n * @param precision - The precision to round to. Must be an integer between -15 and 15.\n * @signature\n * round(value, precision);\n * @example\n * round(123.9876, 3) // => 123.988\n * round(483.22243, 1) // => 483.2\n * round(8541, -1) // => 8540\n * round(456789, -3) // => 457000\n * @dataFirst\n * @category Number\n */\nexport function round(value: number, precision: number): number;\n\n/**\n * Rounds a given number to a specific precision.\n * If you'd like to round to an integer (i.e. use this function with constant `precision === 0`),\n * use `Math.round` instead, as it won't incur the additional library overhead.\n *\n * @param precision - The precision to round to. Must be an integer between -15 and 15.\n * @signature\n * round(precision)(value);\n * @example\n * round(3)(123.9876) // => 123.988\n * round(1)(483.22243) // => 483.2\n * round(-1)(8541) // => 8540\n * round(-3)(456789) // => 457000\n * @dataLast\n * @category Number\n */\nexport function round(precision: number): (value: number) => number;\n\nexport function round(...args: readonly unknown[]): unknown {\n return purry(withPrecision(Math.round), args);\n}\n"],"mappings":"4IAwCA,SAAgB,EAAM,GAAG,EAAmC,CAC1D,OAAOA,EAAAA,MAAMC,EAAAA,EAAc,KAAK,MAAM,CAAE,EAAK"}
|
package/dist/round.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"round.js","names":[],"sources":["../src/round.ts"],"sourcesContent":["import { withPrecision } from \"./internal/withPrecision\";\nimport { purry } from \"./purry\";\n\n/**\n * Rounds a given number to a specific precision.\n * If you'd like to round to an integer (i.e. use this function with constant `precision === 0`),\n * use `Math.round` instead, as it won't incur the additional library overhead.\n *\n * @param value - The number to round.\n * @param precision - The precision to round to. Must be an integer between -15 and 15.\n * @signature\n * round(value, precision);\n * @example\n * round(123.9876, 3) // => 123.988\n * round(483.22243, 1) // => 483.2\n * round(8541, -1) // => 8540\n * round(456789, -3) // => 457000\n * @dataFirst\n * @category Number\n */\nexport function round(value: number, precision: number): number;\n\n/**\n * Rounds a given number to a specific precision.\n * If you'd like to round to an integer (i.e. use this function with constant `precision === 0`),\n * use `Math.round` instead, as it won't incur the additional library overhead.\n *\n * @param precision - The precision to round to. Must be an integer between -15 and 15.\n * @signature\n * round(precision)(value);\n * @example\n * round(3)(123.9876) // => 123.988\n * round(1)(483.22243) // => 483.2\n * round(-1)(8541) // => 8540\n * round(-3)(456789) // => 457000\n * @dataLast\n * @category Number\n */\nexport function round(precision: number): (value: number) => number;\n\nexport function round(...args: readonly unknown[]): unknown {\n return purry(withPrecision(Math.round), args);\n}\n"],"mappings":"8EAwCA,SAAgB,EAAM,GAAG,EAAmC,CAC1D,OAAO,EAAM,EAAc,KAAK,MAAM,CAAE,EAAK"}
|
package/dist/sample.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./purry.cjs`);function t(...t){return e.purry(n,t)}function n(e,t){if(t<=0)return[];if(t>=e.length)return[...e];let n=Math.min(t,e.length-t),r=new Set;for(;r.size<n;){let t=Math.floor(Math.random()*e.length);r.add(t)}return t===n?[...r].sort((e,t)=>e-t).map(t=>e[t]):e.filter((e,t)=>!r.has(t))}exports.sample=t;
|
|
2
|
+
//# sourceMappingURL=sample.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sample.cjs","names":["purry"],"sources":["../src/sample.ts"],"sourcesContent":["import type {\n FixedLengthArray,\n IsEqual,\n IsNever,\n NonNegativeInteger,\n Or,\n Writable,\n} from \"type-fest\";\nimport type { CoercedArray } from \"./internal/types/CoercedArray\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { NTuple } from \"./internal/types/NTuple\";\nimport type { PartialArray } from \"./internal/types/PartialArray\";\nimport type { TupleParts } from \"./internal/types/TupleParts\";\nimport { purry } from \"./purry\";\n\ntype Sampled<T extends IterableContainer, N extends number> =\n Or<IsEqual<N, 0>, IsEqual<T[\"length\"], 0>> extends true\n ? // Short-circuit on trivial inputs.\n []\n : IsNever<NonNegativeInteger<N>> extends true\n ? SampledPrimitive<T>\n : IsLongerThan<T, N> extends true\n ? SampledLiteral<T, N>\n : // If our tuple can never fulfil the sample size the only valid sample\n // is the whole input tuple. Because it's a shallow clone we also\n // strip any readonly-ness.\n Writable<T>;\n\n/**\n * When N is not a non-negative integer **literal** we can't use it in our\n * reconstructing logic so we fallback to a simpler definition of the output of\n * sample, which is any sub-tuple shape of T, of **any length**.\n */\ntype SampledPrimitive<T extends IterableContainer> = [\n ...FixedSubTuples<TupleParts<T>[\"required\"]>,\n // TODO: This might be accurate, but We currently have no tests that check optional elements!\n ...PartialArray<FixedSubTuples<TupleParts<T>[\"optional\"]>>,\n ...CoercedArray<TupleParts<T>[\"item\"]>,\n ...FixedSubTuples<TupleParts<T>[\"suffix\"]>,\n];\n\n/**\n * Knowing N is a non-negative literal integer we can construct all sub-tuples\n * of T that are exactly N elements long.\n */\ntype SampledLiteral<T extends IterableContainer, N extends number> =\n | Extract<\n FixedSubTuples<\n [\n ...TupleParts<T>[\"required\"],\n // TODO: This deliberately ignores optional elements which we don't have tests for either. In order to handle optional elements we can treat the \"optional\" tuple-part as more required elements.\n // We add N elements of the `item` type to the tuple so that we\n // consider any combination possible of elements of the prefix items,\n // any amount of rest items, and suffix items.\n ...(IsNever<TupleParts<T>[\"item\"]> extends true\n ? []\n : NTuple<TupleParts<T>[\"item\"], N>),\n ...TupleParts<T>[\"suffix\"],\n ]\n >,\n // This is just [unknown, unknown, ..., unknown] with N elements.\n FixedLengthArray<unknown, N>\n >\n // In addition to all sub-tuples of length N, we also need to consider all\n // tuples where the input is shorter than N. This will contribute exactly\n // one sub-tuple at each length from the minimum length of T and up to N-1.\n | SubSampled<\n TupleParts<T>[\"required\"],\n // TODO: This deliberately ignores optional elements which we don't have tests for either. In order to handle optional elements we can treat the \"optional\" tuple-part as more required elements.\n TupleParts<T>[\"item\"],\n TupleParts<T>[\"suffix\"],\n N\n >;\n\n// We want to create a union of all sub-tuples where we incrementally add an\n// additional element of the type of the rest element in the middle between the\n// prefix and suffix until we \"fill\" the tuple to size N.\ntype SubSampled<\n Prefix extends readonly unknown[],\n Item,\n Suffix extends readonly unknown[],\n N extends number,\n> =\n IsLongerThan<[...Prefix, ...Suffix], N> extends true\n ? // We need to prevent overflows in case Prefix and Suffix are already long\n // enough\n never\n : [...Prefix, ...Suffix][\"length\"] extends N\n ? never\n : [...Prefix, ...Suffix] | SubSampled<[...Prefix, Item], Item, Suffix, N>;\n\ntype IsLongerThan<T extends readonly unknown[], N extends number> =\n // Checking for `undefined` is a neat trick to avoid needing to compare\n // integer literals because if N overflows the tuple then the type for that\n // element will be `undefined`. This only works for fixed tuples!\n IsEqual<T[N], undefined> extends true ? false : true;\n\n// Assuming T is a fixed tuple we build all it's possible sub-tuples.\ntype FixedSubTuples<T> = T extends readonly [infer Head, ...infer Rest]\n ? // For each element we either take it or skip it, and recurse over the rest.\n FixedSubTuples<Rest> | [Head, ...FixedSubTuples<Rest>]\n : [];\n\n/**\n * Returns a random subset of size `sampleSize` from `array`.\n *\n * Maintains and infers most of the typing information that could be passed\n * along to the output. This means that when using tuples, the output will be\n * a tuple too, and when using literals, those literals would be preserved.\n *\n * The items in the result are kept in the same order as they are in the input.\n * If you need to get a shuffled response you can pipe the shuffle function\n * after this one.\n *\n * @param data - The array.\n * @param sampleSize - The number of elements to take.\n * @signature\n * sample(array, sampleSize)\n * @example\n * sample([\"hello\", \"world\"], 1); // => [\"hello\"] // typed string[]\n * sample([\"hello\", \"world\"] as const, 1); // => [\"world\"] // typed [\"hello\" | \"world\"]\n * @dataFirst\n * @category Array\n */\nexport function sample<const T extends IterableContainer, N extends number>(\n data: T,\n sampleSize: N,\n): Sampled<T, N>;\n\n/**\n * Returns a random subset of size `sampleSize` from `array`.\n *\n * Maintains and infers most of the typing information that could be passed\n * along to the output. This means that when using tuples, the output will be\n * a tuple too, and when using literals, those literals would be preserved.\n *\n * The items in the result are kept in the same order as they are in the input.\n * If you need to get a shuffled response you can pipe the shuffle function\n * after this one.\n *\n * @param sampleSize - The number of elements to take.\n * @signature\n * sample(sampleSize)(array)\n * @example\n * sample(1)([\"hello\", \"world\"]); // => [\"hello\"] // typed string[]\n * sample(1)([\"hello\", \"world\"] as const); // => [\"world\"] // typed [\"hello\" | \"world\"]\n * @dataLast\n * @category Array\n */\nexport function sample<const T extends IterableContainer, N extends number>(\n sampleSize: N,\n): (data: T) => Sampled<T, N>;\n\nexport function sample(...args: readonly unknown[]): unknown {\n return purry(sampleImplementation, args);\n}\n\nfunction sampleImplementation<T>(data: readonly T[], sampleSize: number): T[] {\n if (sampleSize <= 0) {\n // Trivial\n return [];\n }\n\n if (sampleSize >= data.length) {\n // Trivial\n return [...data];\n }\n\n // We have 2 modes of sampling, depending on the size of the sample requested.\n // 1. If sampleSize is _small_, we generate indices that we then use to\n // *EXTRACT* individual elements from the array.\n // 2. If sampleSize is _large_, we instead generate indices to *EXCLUDE* from\n // a full scan of the input array (via filtering).\n //\n // This allows us 2 optimizations that are the core of how this function\n // works:\n // 1. It is hard to generate a large number of unique indices, as the more\n // indices we generate the more likely we are to generate one that is already\n // in the set, which would require more iterations of the generation loop.\n // Capping our effective sampleSize at n/2 would put an upper limit to the\n // average number of iterations required (as a function of n).\n // 2. If sample size is small enough, we never need to actually iterate over\n // the full input array at all; instead we simply project the values we need\n // via random access into the array. This means that for sampleSize (K) less\n // than n/2, we run at O(klogk). For large sampleSize we need to iterate over\n // the full input array, but we don't need to sort the indices because we can\n // use the Set's 'has' method, so we effectively run at O(n).\n const actualSampleSize = Math.min(sampleSize, data.length - sampleSize);\n\n const sampleIndices = new Set<number>();\n while (sampleIndices.size < actualSampleSize) {\n const randomIndex = Math.floor(Math.random() * data.length);\n sampleIndices.add(randomIndex);\n }\n\n if (sampleSize === actualSampleSize) {\n return [...sampleIndices]\n .sort((a, b) => a - b)\n .map((index) => data[index]!);\n }\n\n return data.filter((_, index) => !sampleIndices.has(index));\n}\n"],"mappings":"kGAyJA,SAAgB,EAAO,GAAG,EAAmC,CAC3D,OAAOA,EAAAA,MAAM,EAAsB,EAAK,CAG1C,SAAS,EAAwB,EAAoB,EAAyB,CAC5E,GAAI,GAAc,EAEhB,MAAO,EAAE,CAGX,GAAI,GAAc,EAAK,OAErB,MAAO,CAAC,GAAG,EAAK,CAsBlB,IAAM,EAAmB,KAAK,IAAI,EAAY,EAAK,OAAS,EAAW,CAEjE,EAAgB,IAAI,IAC1B,KAAO,EAAc,KAAO,GAAkB,CAC5C,IAAM,EAAc,KAAK,MAAM,KAAK,QAAQ,CAAG,EAAK,OAAO,CAC3D,EAAc,IAAI,EAAY,CAShC,OANI,IAAe,EACV,CAAC,GAAG,EAAc,CACtB,MAAM,EAAG,IAAM,EAAI,EAAE,CACrB,IAAK,GAAU,EAAK,GAAQ,CAG1B,EAAK,QAAQ,EAAG,IAAU,CAAC,EAAc,IAAI,EAAM,CAAC"}
|
package/dist/sample.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{purry as e}from"./purry.js";function t(...t){return e(n,t)}function n(e,t){if(t<=0)return[];if(t>=e.length)return[...e];let n=Math.min(t,e.length-t),r=new Set;for(;r.size<n;){let t=Math.floor(Math.random()*e.length);r.add(t)}return t===n?[...r].sort((e,t)=>e-t).map(t=>e[t]):e.filter((e,t)=>!r.has(t))}export{t as sample};
|
|
2
|
+
//# sourceMappingURL=sample.js.map
|