ramda-adjunct 2.34.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/.nvmrc +1 -0
- package/CHANGELOG.md +973 -0
- package/LICENSE.md +25 -0
- package/README.md +297 -0
- package/SECURITY.md +43 -0
- package/dist/RA.node.js +11172 -0
- package/dist/RA.node.min.js +2 -0
- package/dist/RA.node.min.js.LICENSE.txt +22 -0
- package/dist/RA.web.js +11172 -0
- package/dist/RA.web.min.js +2 -0
- package/dist/RA.web.min.js.LICENSE.txt +22 -0
- package/dist/RA.web.standalone.js +27797 -0
- package/dist/RA.web.standalone.min.js +2 -0
- package/dist/RA.web.standalone.min.js.LICENSE.txt +22 -0
- package/es/Y.js +38 -0
- package/es/allEqual.js +25 -0
- package/es/allEqualTo.js +26 -0
- package/es/allIdentical.js +24 -0
- package/es/allIdenticalTo.js +26 -0
- package/es/allP.js +26 -0
- package/es/allSettledP.js +29 -0
- package/es/allUnique.js +23 -0
- package/es/anyP.js +28 -0
- package/es/appendFlipped.js +23 -0
- package/es/argsPass.js +38 -0
- package/es/async.js +57 -0
- package/es/cata.js +101 -0
- package/es/catchP.js +24 -0
- package/es/ceil.js +26 -0
- package/es/compact.js +21 -0
- package/es/concatAll.js +30 -0
- package/es/concatRight.js +29 -0
- package/es/contained.js +29 -0
- package/es/curryRight.js +24 -0
- package/es/curryRightN.js +32 -0
- package/es/defaultWhen.js +25 -0
- package/es/delayP.js +44 -0
- package/es/dispatch.js +75 -0
- package/es/divideNum.js +19 -0
- package/es/dropArgs.js +22 -0
- package/es/ensureArray.js +22 -0
- package/es/escapeRegExp.js +20 -0
- package/es/fantasy-land/Identity.js +309 -0
- package/es/fantasy-land/mapping.js +20 -0
- package/es/fantasy-land/traits.js +41 -0
- package/es/fantasy-land/util.js +11 -0
- package/es/filterIndexed.js +27 -0
- package/es/findOr.js +28 -0
- package/es/flattenDepth.js +50 -0
- package/es/flattenPath.js +27 -0
- package/es/flattenProp.js +28 -0
- package/es/floor.js +25 -0
- package/es/fnull.js +37 -0
- package/es/hasPath.js +38 -0
- package/es/inRange.js +29 -0
- package/es/index.js +252 -0
- package/es/internal/ap.js +20 -0
- package/es/internal/compareLength.js +5 -0
- package/es/internal/isOfTypeObject.js +7 -0
- package/es/internal/makeFlat.js +46 -0
- package/es/internal/ponyfills/Array.from.js +40 -0
- package/es/internal/ponyfills/Math.sign.js +5 -0
- package/es/internal/ponyfills/Math.trunc.js +14 -0
- package/es/internal/ponyfills/Number.MAX_SAFE_INTEGER.js +2 -0
- package/es/internal/ponyfills/Number.MIN_SAFE_INTEGER.js +2 -0
- package/es/internal/ponyfills/Number.isFinite.js +5 -0
- package/es/internal/ponyfills/Number.isInteger.js +4 -0
- package/es/internal/ponyfills/Number.isNaN.js +5 -0
- package/es/internal/ponyfills/Number.isSafeInteger.js +7 -0
- package/es/internal/ponyfills/Promise.allSettled.js +38 -0
- package/es/internal/ponyfills/Promise.any.js +77 -0
- package/es/internal/ponyfills/String.padEnd.js +24 -0
- package/es/internal/ponyfills/String.padStart.js +26 -0
- package/es/internal/ponyfills/String.repeat.js +46 -0
- package/es/internal/ponyfills/String.replaceAll.js +34 -0
- package/es/internal/ponyfills/String.trimEnd.js +3 -0
- package/es/internal/ponyfills/String.trimStart.js +3 -0
- package/es/invoke.js +20 -0
- package/es/invokeArgs.js +30 -0
- package/es/isArray.js +22 -0
- package/es/isArrayLike.js +87 -0
- package/es/isAsyncFunction.js +22 -0
- package/es/isBigInt.js +23 -0
- package/es/isBoolean.js +21 -0
- package/es/isDate.js +20 -0
- package/es/isEmptyArray.js +26 -0
- package/es/isEmptyString.js +27 -0
- package/es/isError.js +20 -0
- package/es/isEven.js +29 -0
- package/es/isFalse.js +29 -0
- package/es/isFalsy.js +26 -0
- package/es/isFinite.js +33 -0
- package/es/isFloat.js +34 -0
- package/es/isFunction.js +26 -0
- package/es/isGeneratorFunction.js +33 -0
- package/es/isIndexed.js +21 -0
- package/es/isInteger.js +35 -0
- package/es/isInteger32.js +28 -0
- package/es/isIterable.js +33 -0
- package/es/isMap.js +23 -0
- package/es/isNaN.js +41 -0
- package/es/isNaturalNumber.js +25 -0
- package/es/isNegative.js +25 -0
- package/es/isNegativeZero.js +22 -0
- package/es/isNilOrEmpty.js +25 -0
- package/es/isNonEmptyArray.js +27 -0
- package/es/isNonEmptyString.js +30 -0
- package/es/isNonNegative.js +28 -0
- package/es/isNonPositive.js +28 -0
- package/es/isNotArray.js +22 -0
- package/es/isNotArrayLike.js +24 -0
- package/es/isNotAsyncFunction.js +27 -0
- package/es/isNotBoolean.js +22 -0
- package/es/isNotDate.js +21 -0
- package/es/isNotEmpty.js +25 -0
- package/es/isNotFinite.js +29 -0
- package/es/isNotFloat.js +33 -0
- package/es/isNotFunction.js +29 -0
- package/es/isNotGeneratorFunction.js +27 -0
- package/es/isNotInteger.js +34 -0
- package/es/isNotMap.js +24 -0
- package/es/isNotNaN.js +35 -0
- package/es/isNotNil.js +22 -0
- package/es/isNotNilOrEmpty.js +26 -0
- package/es/isNotNull.js +22 -0
- package/es/isNotNumber.js +23 -0
- package/es/isNotObj.js +29 -0
- package/es/isNotObjLike.js +29 -0
- package/es/isNotPair.js +25 -0
- package/es/isNotPlainObj.js +35 -0
- package/es/isNotPrimitive.js +22 -0
- package/es/isNotRegExp.js +22 -0
- package/es/isNotSet.js +23 -0
- package/es/isNotString.js +21 -0
- package/es/isNotUndefined.js +22 -0
- package/es/isNotValidDate.js +22 -0
- package/es/isNotValidNumber.js +25 -0
- package/es/isNull.js +21 -0
- package/es/isNumber.js +23 -0
- package/es/isObj.js +31 -0
- package/es/isObjLike.js +30 -0
- package/es/isOdd.js +24 -0
- package/es/isPair.js +25 -0
- package/es/isPlainObj.js +52 -0
- package/es/isPositive.js +24 -0
- package/es/isPositiveZero.js +22 -0
- package/es/isPrimitive.js +31 -0
- package/es/isPromise.js +27 -0
- package/es/isPrototypeOf.js +34 -0
- package/es/isRegExp.js +21 -0
- package/es/isSafeInteger.js +34 -0
- package/es/isSentinelValue.js +26 -0
- package/es/isSet.js +22 -0
- package/es/isSparseArray.js +30 -0
- package/es/isString.js +20 -0
- package/es/isSymbol.js +27 -0
- package/es/isThenable.js +26 -0
- package/es/isTrue.js +25 -0
- package/es/isTruthy.js +27 -0
- package/es/isUndefined.js +22 -0
- package/es/isValidDate.js +26 -0
- package/es/isValidNumber.js +26 -0
- package/es/lastP.js +63 -0
- package/es/lengthEq.js +22 -0
- package/es/lengthGt.js +22 -0
- package/es/lengthGte.js +24 -0
- package/es/lengthLt.js +22 -0
- package/es/lengthLte.js +23 -0
- package/es/lengthNotEq.js +22 -0
- package/es/lensEq.js +27 -0
- package/es/lensIso.js +55 -0
- package/es/lensNotEq.js +26 -0
- package/es/lensNotSatisfy.js +28 -0
- package/es/lensSatisfies.js +31 -0
- package/es/lensTraverse.js +42 -0
- package/es/liftF.js +37 -0
- package/es/liftFN.js +47 -0
- package/es/list.js +19 -0
- package/es/mapIndexed.js +26 -0
- package/es/mergePath.js +30 -0
- package/es/mergePaths.js +27 -0
- package/es/mergeProp.js +30 -0
- package/es/mergeProps.js +26 -0
- package/es/mergeRight.js +26 -0
- package/es/move.js +25 -0
- package/es/nand.js +27 -0
- package/es/neither.js +39 -0
- package/es/noneP.js +28 -0
- package/es/nonePass.js +31 -0
- package/es/noop.js +19 -0
- package/es/nor.js +28 -0
- package/es/notAllPass.js +31 -0
- package/es/notAllUnique.js +23 -0
- package/es/notBoth.js +39 -0
- package/es/notEqual.js +30 -0
- package/es/omitBy.js +26 -0
- package/es/omitIndexes.js +27 -0
- package/es/overlaps.js +29 -0
- package/es/padCharsEnd.js +31 -0
- package/es/padCharsStart.js +29 -0
- package/es/padEnd.js +24 -0
- package/es/padStart.js +22 -0
- package/es/pathNotEq.js +32 -0
- package/es/pathOrLazy.js +25 -0
- package/es/paths.js +27 -0
- package/es/pickIndexes.js +30 -0
- package/es/propNotEq.js +29 -0
- package/es/rangeStep.js +36 -0
- package/es/reduceIndexed.js +30 -0
- package/es/reduceP.js +111 -0
- package/es/reduceRightP.js +117 -0
- package/es/rejectP.js +23 -0
- package/es/renameKeyWith.js +28 -0
- package/es/renameKeys.js +42 -0
- package/es/renameKeysWith.js +26 -0
- package/es/repeatStr.js +24 -0
- package/es/replaceAll.js +29 -0
- package/es/resolveP.js +29 -0
- package/es/round.js +24 -0
- package/es/seq.js +44 -0
- package/es/sign.js +27 -0
- package/es/skipTake.js +22 -0
- package/es/sliceFrom.js +22 -0
- package/es/sliceTo.js +22 -0
- package/es/sortByProps.js +52 -0
- package/es/spreadPath.js +25 -0
- package/es/spreadProp.js +25 -0
- package/es/stubArray.js +19 -0
- package/es/stubNull.js +18 -0
- package/es/stubObj.js +20 -0
- package/es/stubString.js +18 -0
- package/es/stubUndefined.js +19 -0
- package/es/subtractNum.js +19 -0
- package/es/thenCatchP.js +26 -0
- package/es/thenP.js +28 -0
- package/es/toArray.js +27 -0
- package/es/toInteger32.js +24 -0
- package/es/toUinteger32.js +26 -0
- package/es/trimCharsEnd.js +22 -0
- package/es/trimCharsStart.js +22 -0
- package/es/trimEnd.js +23 -0
- package/es/trimStart.js +22 -0
- package/es/trunc.js +27 -0
- package/es/unzipObjWith.js +26 -0
- package/es/viewOr.js +30 -0
- package/es/weave.js +36 -0
- package/es/weaveLazy.js +38 -0
- package/es/zipObjWith.js +26 -0
- package/lib/Y.js +44 -0
- package/lib/allEqual.js +35 -0
- package/lib/allEqualTo.js +32 -0
- package/lib/allIdentical.js +33 -0
- package/lib/allIdenticalTo.js +32 -0
- package/lib/allP.js +32 -0
- package/lib/allSettledP.js +41 -0
- package/lib/allUnique.js +32 -0
- package/lib/anyP.js +47 -0
- package/lib/appendFlipped.js +29 -0
- package/lib/argsPass.js +48 -0
- package/lib/async.js +67 -0
- package/lib/cata.js +110 -0
- package/lib/catchP.js +30 -0
- package/lib/ceil.js +32 -0
- package/lib/compact.js +30 -0
- package/lib/concatAll.js +40 -0
- package/lib/concatRight.js +35 -0
- package/lib/contained.js +35 -0
- package/lib/curryRight.js +33 -0
- package/lib/curryRightN.js +38 -0
- package/lib/defaultWhen.js +31 -0
- package/lib/delayP.js +54 -0
- package/lib/dispatch.js +50 -0
- package/lib/divideNum.js +25 -0
- package/lib/dropArgs.js +28 -0
- package/lib/ensureArray.js +31 -0
- package/lib/escapeRegExp.js +29 -0
- package/lib/fantasy-land/Identity.js +323 -0
- package/lib/fantasy-land/mapping.js +44 -0
- package/lib/fantasy-land/traits.js +77 -0
- package/lib/fantasy-land/util.js +21 -0
- package/lib/filterIndexed.js +33 -0
- package/lib/findOr.js +34 -0
- package/lib/flattenDepth.js +58 -0
- package/lib/flattenPath.js +33 -0
- package/lib/flattenProp.js +37 -0
- package/lib/floor.js +31 -0
- package/lib/fnull.js +47 -0
- package/lib/hasPath.js +47 -0
- package/lib/inRange.js +37 -0
- package/lib/index.js +863 -0
- package/lib/internal/ap.js +37 -0
- package/lib/internal/compareLength.js +12 -0
- package/lib/internal/isOfTypeObject.js +13 -0
- package/lib/internal/makeFlat.js +54 -0
- package/lib/internal/ponyfills/Array.from.js +52 -0
- package/lib/internal/ponyfills/Math.sign.js +11 -0
- package/lib/internal/ponyfills/Math.trunc.js +22 -0
- package/lib/internal/ponyfills/Number.MAX_SAFE_INTEGER.js +7 -0
- package/lib/internal/ponyfills/Number.MIN_SAFE_INTEGER.js +7 -0
- package/lib/internal/ponyfills/Number.isFinite.js +15 -0
- package/lib/internal/ponyfills/Number.isInteger.js +14 -0
- package/lib/internal/ponyfills/Number.isNaN.js +15 -0
- package/lib/internal/ponyfills/Number.isSafeInteger.js +18 -0
- package/lib/internal/ponyfills/Promise.allSettled.js +48 -0
- package/lib/internal/ponyfills/Promise.any.js +89 -0
- package/lib/internal/ponyfills/String.padEnd.js +34 -0
- package/lib/internal/ponyfills/String.padStart.js +36 -0
- package/lib/internal/ponyfills/String.repeat.js +55 -0
- package/lib/internal/ponyfills/String.replaceAll.js +44 -0
- package/lib/internal/ponyfills/String.trimEnd.js +10 -0
- package/lib/internal/ponyfills/String.trimStart.js +10 -0
- package/lib/invoke.js +29 -0
- package/lib/invokeArgs.js +40 -0
- package/lib/isArray.js +31 -0
- package/lib/isArrayLike.js +98 -0
- package/lib/isAsyncFunction.js +28 -0
- package/lib/isBigInt.js +29 -0
- package/lib/isBoolean.js +27 -0
- package/lib/isDate.js +26 -0
- package/lib/isEmptyArray.js +35 -0
- package/lib/isEmptyString.js +33 -0
- package/lib/isError.js +26 -0
- package/lib/isEven.js +39 -0
- package/lib/isFalse.js +35 -0
- package/lib/isFalsy.js +35 -0
- package/lib/isFinite.js +46 -0
- package/lib/isFloat.js +44 -0
- package/lib/isFunction.js +36 -0
- package/lib/isGeneratorFunction.js +40 -0
- package/lib/isIndexed.js +31 -0
- package/lib/isInteger.js +47 -0
- package/lib/isInteger32.js +37 -0
- package/lib/isIterable.js +42 -0
- package/lib/isMap.js +29 -0
- package/lib/isNaN.js +54 -0
- package/lib/isNaturalNumber.js +35 -0
- package/lib/isNegative.js +34 -0
- package/lib/isNegativeZero.js +28 -0
- package/lib/isNilOrEmpty.js +31 -0
- package/lib/isNonEmptyArray.js +37 -0
- package/lib/isNonEmptyString.js +41 -0
- package/lib/isNonNegative.js +37 -0
- package/lib/isNonPositive.js +37 -0
- package/lib/isNotArray.js +31 -0
- package/lib/isNotArrayLike.js +33 -0
- package/lib/isNotAsyncFunction.js +36 -0
- package/lib/isNotBoolean.js +31 -0
- package/lib/isNotDate.js +30 -0
- package/lib/isNotEmpty.js +31 -0
- package/lib/isNotFinite.js +38 -0
- package/lib/isNotFloat.js +42 -0
- package/lib/isNotFunction.js +38 -0
- package/lib/isNotGeneratorFunction.js +36 -0
- package/lib/isNotInteger.js +43 -0
- package/lib/isNotMap.js +33 -0
- package/lib/isNotNaN.js +44 -0
- package/lib/isNotNil.js +28 -0
- package/lib/isNotNilOrEmpty.js +35 -0
- package/lib/isNotNull.js +31 -0
- package/lib/isNotNumber.js +32 -0
- package/lib/isNotObj.js +38 -0
- package/lib/isNotObjLike.js +38 -0
- package/lib/isNotPair.js +34 -0
- package/lib/isNotPlainObj.js +44 -0
- package/lib/isNotPrimitive.js +31 -0
- package/lib/isNotRegExp.js +31 -0
- package/lib/isNotSet.js +32 -0
- package/lib/isNotString.js +30 -0
- package/lib/isNotUndefined.js +31 -0
- package/lib/isNotValidDate.js +31 -0
- package/lib/isNotValidNumber.js +34 -0
- package/lib/isNull.js +27 -0
- package/lib/isNumber.js +29 -0
- package/lib/isObj.js +42 -0
- package/lib/isObjLike.js +40 -0
- package/lib/isOdd.js +33 -0
- package/lib/isPair.js +34 -0
- package/lib/isPlainObj.js +64 -0
- package/lib/isPositive.js +33 -0
- package/lib/isPositiveZero.js +28 -0
- package/lib/isPrimitive.js +47 -0
- package/lib/isPromise.js +36 -0
- package/lib/isPrototypeOf.js +43 -0
- package/lib/isRegExp.js +27 -0
- package/lib/isSafeInteger.js +46 -0
- package/lib/isSentinelValue.js +35 -0
- package/lib/isSet.js +28 -0
- package/lib/isSparseArray.js +39 -0
- package/lib/isString.js +26 -0
- package/lib/isSymbol.js +33 -0
- package/lib/isThenable.js +35 -0
- package/lib/isTrue.js +31 -0
- package/lib/isTruthy.js +33 -0
- package/lib/isUndefined.js +31 -0
- package/lib/isValidDate.js +36 -0
- package/lib/isValidNumber.js +36 -0
- package/lib/lastP.js +76 -0
- package/lib/lengthEq.js +31 -0
- package/lib/lengthGt.js +31 -0
- package/lib/lengthGte.js +33 -0
- package/lib/lengthLt.js +31 -0
- package/lib/lengthLte.js +32 -0
- package/lib/lengthNotEq.js +31 -0
- package/lib/lensEq.js +33 -0
- package/lib/lensIso.js +62 -0
- package/lib/lensNotEq.js +35 -0
- package/lib/lensNotSatisfy.js +37 -0
- package/lib/lensSatisfies.js +40 -0
- package/lib/lensTraverse.js +51 -0
- package/lib/liftF.js +46 -0
- package/lib/liftFN.js +56 -0
- package/lib/list.js +25 -0
- package/lib/mapIndexed.js +32 -0
- package/lib/mergePath.js +39 -0
- package/lib/mergePaths.js +36 -0
- package/lib/mergeProp.js +39 -0
- package/lib/mergeProps.js +32 -0
- package/lib/mergeRight.js +32 -0
- package/lib/move.js +31 -0
- package/lib/nand.js +33 -0
- package/lib/neither.js +45 -0
- package/lib/noneP.js +39 -0
- package/lib/nonePass.js +37 -0
- package/lib/noop.js +28 -0
- package/lib/nor.js +34 -0
- package/lib/notAllPass.js +37 -0
- package/lib/notAllUnique.js +32 -0
- package/lib/notBoth.js +45 -0
- package/lib/notEqual.js +36 -0
- package/lib/omitBy.js +32 -0
- package/lib/omitIndexes.js +34 -0
- package/lib/overlaps.js +38 -0
- package/lib/padCharsEnd.js +44 -0
- package/lib/padCharsStart.js +42 -0
- package/lib/padEnd.js +32 -0
- package/lib/padStart.js +30 -0
- package/lib/pathNotEq.js +38 -0
- package/lib/pathOrLazy.js +31 -0
- package/lib/paths.js +33 -0
- package/lib/pickIndexes.js +37 -0
- package/lib/propNotEq.js +35 -0
- package/lib/rangeStep.js +45 -0
- package/lib/reduceIndexed.js +36 -0
- package/lib/reduceP.js +122 -0
- package/lib/reduceRightP.js +129 -0
- package/lib/rejectP.js +29 -0
- package/lib/renameKeyWith.js +37 -0
- package/lib/renameKeys.js +51 -0
- package/lib/renameKeysWith.js +32 -0
- package/lib/repeatStr.js +37 -0
- package/lib/replaceAll.js +42 -0
- package/lib/resolveP.js +35 -0
- package/lib/round.js +30 -0
- package/lib/seq.js +50 -0
- package/lib/sign.js +39 -0
- package/lib/skipTake.js +28 -0
- package/lib/sliceFrom.js +28 -0
- package/lib/sliceTo.js +28 -0
- package/lib/sortByProps.js +58 -0
- package/lib/spreadPath.js +31 -0
- package/lib/spreadProp.js +34 -0
- package/lib/stubArray.js +25 -0
- package/lib/stubNull.js +24 -0
- package/lib/stubObj.js +26 -0
- package/lib/stubString.js +24 -0
- package/lib/stubUndefined.js +25 -0
- package/lib/subtractNum.js +25 -0
- package/lib/thenCatchP.js +33 -0
- package/lib/thenP.js +34 -0
- package/lib/toArray.js +40 -0
- package/lib/toInteger32.js +30 -0
- package/lib/toUinteger32.js +32 -0
- package/lib/trimCharsEnd.js +31 -0
- package/lib/trimCharsStart.js +31 -0
- package/lib/trimEnd.js +36 -0
- package/lib/trimStart.js +35 -0
- package/lib/trunc.js +39 -0
- package/lib/unzipObjWith.js +35 -0
- package/lib/viewOr.js +36 -0
- package/lib/weave.js +42 -0
- package/lib/weaveLazy.js +44 -0
- package/lib/zipObjWith.js +32 -0
- package/package.json +204 -0
- package/src/Y.js +32 -0
- package/src/allEqual.js +28 -0
- package/src/allEqualTo.js +25 -0
- package/src/allIdentical.js +26 -0
- package/src/allIdenticalTo.js +25 -0
- package/src/allP.js +27 -0
- package/src/allSettledP.js +34 -0
- package/src/allUnique.js +25 -0
- package/src/anyP.js +33 -0
- package/src/appendFlipped.js +24 -0
- package/src/argsPass.js +40 -0
- package/src/async.js +60 -0
- package/src/cata.js +86 -0
- package/src/catchP.js +25 -0
- package/src/ceil.js +28 -0
- package/src/compact.js +23 -0
- package/src/concatAll.js +34 -0
- package/src/concatRight.js +30 -0
- package/src/contained.js +30 -0
- package/src/curryRight.js +26 -0
- package/src/curryRightN.js +29 -0
- package/src/defaultWhen.js +26 -0
- package/src/delayP.js +45 -0
- package/src/dispatch.js +74 -0
- package/src/divideNum.js +20 -0
- package/src/dropArgs.js +23 -0
- package/src/ensureArray.js +24 -0
- package/src/escapeRegExp.js +22 -0
- package/src/fantasy-land/Identity.js +270 -0
- package/src/fantasy-land/mapping.js +20 -0
- package/src/fantasy-land/traits.js +57 -0
- package/src/fantasy-land/util.js +23 -0
- package/src/filterIndexed.js +28 -0
- package/src/findOr.js +30 -0
- package/src/flattenDepth.js +39 -0
- package/src/flattenPath.js +26 -0
- package/src/flattenProp.js +28 -0
- package/src/floor.js +27 -0
- package/src/fnull.js +38 -0
- package/src/hasPath.js +40 -0
- package/src/inRange.js +34 -0
- package/src/index.js +241 -0
- package/src/internal/ap.js +30 -0
- package/src/internal/compareLength.js +7 -0
- package/src/internal/isOfTypeObject.js +3 -0
- package/src/internal/makeFlat.js +42 -0
- package/src/internal/ponyfills/Array.from.js +34 -0
- package/src/internal/ponyfills/Math.sign.js +3 -0
- package/src/internal/ponyfills/Math.trunc.js +14 -0
- package/src/internal/ponyfills/Number.MAX_SAFE_INTEGER.js +3 -0
- package/src/internal/ponyfills/Number.MIN_SAFE_INTEGER.js +3 -0
- package/src/internal/ponyfills/Number.isFinite.js +8 -0
- package/src/internal/ponyfills/Number.isInteger.js +10 -0
- package/src/internal/ponyfills/Number.isNaN.js +8 -0
- package/src/internal/ponyfills/Number.isSafeInteger.js +11 -0
- package/src/internal/ponyfills/Promise.allSettled.js +18 -0
- package/src/internal/ponyfills/Promise.any.js +29 -0
- package/src/internal/ponyfills/String.padEnd.js +25 -0
- package/src/internal/ponyfills/String.padStart.js +27 -0
- package/src/internal/ponyfills/String.repeat.js +49 -0
- package/src/internal/ponyfills/String.replaceAll.js +44 -0
- package/src/internal/ponyfills/String.trimEnd.js +5 -0
- package/src/internal/ponyfills/String.trimStart.js +5 -0
- package/src/invoke.js +22 -0
- package/src/invokeArgs.js +36 -0
- package/src/isArray.js +27 -0
- package/src/isArrayLike.js +79 -0
- package/src/isAsyncFunction.js +23 -0
- package/src/isBigInt.js +24 -0
- package/src/isBoolean.js +22 -0
- package/src/isDate.js +21 -0
- package/src/isEmptyArray.js +28 -0
- package/src/isEmptyString.js +28 -0
- package/src/isError.js +21 -0
- package/src/isEven.js +31 -0
- package/src/isFalse.js +31 -0
- package/src/isFalsy.js +28 -0
- package/src/isFinite.js +37 -0
- package/src/isFloat.js +36 -0
- package/src/isFunction.js +32 -0
- package/src/isGeneratorFunction.js +43 -0
- package/src/isIndexed.js +24 -0
- package/src/isInteger.js +40 -0
- package/src/isInteger32.js +28 -0
- package/src/isIterable.js +37 -0
- package/src/isMap.js +25 -0
- package/src/isNaN.js +45 -0
- package/src/isNaturalNumber.js +28 -0
- package/src/isNegative.js +27 -0
- package/src/isNegativeZero.js +23 -0
- package/src/isNilOrEmpty.js +26 -0
- package/src/isNonEmptyArray.js +29 -0
- package/src/isNonEmptyString.js +32 -0
- package/src/isNonNegative.js +30 -0
- package/src/isNonPositive.js +30 -0
- package/src/isNotArray.js +24 -0
- package/src/isNotArrayLike.js +26 -0
- package/src/isNotAsyncFunction.js +27 -0
- package/src/isNotBoolean.js +24 -0
- package/src/isNotDate.js +23 -0
- package/src/isNotEmpty.js +26 -0
- package/src/isNotFinite.js +31 -0
- package/src/isNotFloat.js +35 -0
- package/src/isNotFunction.js +29 -0
- package/src/isNotGeneratorFunction.js +27 -0
- package/src/isNotInteger.js +36 -0
- package/src/isNotMap.js +27 -0
- package/src/isNotNaN.js +37 -0
- package/src/isNotNil.js +23 -0
- package/src/isNotNilOrEmpty.js +28 -0
- package/src/isNotNull.js +24 -0
- package/src/isNotNumber.js +25 -0
- package/src/isNotObj.js +29 -0
- package/src/isNotObjLike.js +29 -0
- package/src/isNotPair.js +27 -0
- package/src/isNotPlainObj.js +35 -0
- package/src/isNotPrimitive.js +25 -0
- package/src/isNotRegExp.js +24 -0
- package/src/isNotSet.js +26 -0
- package/src/isNotString.js +23 -0
- package/src/isNotUndefined.js +24 -0
- package/src/isNotValidDate.js +24 -0
- package/src/isNotValidNumber.js +27 -0
- package/src/isNull.js +22 -0
- package/src/isNumber.js +24 -0
- package/src/isObj.js +31 -0
- package/src/isObjLike.js +30 -0
- package/src/isOdd.js +29 -0
- package/src/isPair.js +27 -0
- package/src/isPlainObj.js +65 -0
- package/src/isPositive.js +26 -0
- package/src/isPositiveZero.js +23 -0
- package/src/isPrimitive.js +45 -0
- package/src/isPromise.js +32 -0
- package/src/isPrototypeOf.js +36 -0
- package/src/isRegExp.js +22 -0
- package/src/isSafeInteger.js +40 -0
- package/src/isSentinelValue.js +26 -0
- package/src/isSet.js +24 -0
- package/src/isSparseArray.js +43 -0
- package/src/isString.js +21 -0
- package/src/isSymbol.js +29 -0
- package/src/isThenable.js +28 -0
- package/src/isTrue.js +27 -0
- package/src/isTruthy.js +28 -0
- package/src/isUndefined.js +24 -0
- package/src/isValidDate.js +29 -0
- package/src/isValidNumber.js +28 -0
- package/src/lastP.js +54 -0
- package/src/lengthEq.js +24 -0
- package/src/lengthGt.js +24 -0
- package/src/lengthGte.js +26 -0
- package/src/lengthLt.js +24 -0
- package/src/lengthLte.js +25 -0
- package/src/lengthNotEq.js +24 -0
- package/src/lensEq.js +28 -0
- package/src/lensIso.js +51 -0
- package/src/lensNotEq.js +28 -0
- package/src/lensNotSatisfy.js +30 -0
- package/src/lensSatisfies.js +33 -0
- package/src/lensTraverse.js +44 -0
- package/src/liftF.js +37 -0
- package/src/liftFN.js +45 -0
- package/src/list.js +20 -0
- package/src/mapIndexed.js +27 -0
- package/src/mergePath.js +32 -0
- package/src/mergePaths.js +29 -0
- package/src/mergeProp.js +30 -0
- package/src/mergeProps.js +27 -0
- package/src/mergeRight.js +27 -0
- package/src/move.js +26 -0
- package/src/nand.js +27 -0
- package/src/neither.js +38 -0
- package/src/noneP.js +35 -0
- package/src/nonePass.js +32 -0
- package/src/noop.js +21 -0
- package/src/nor.js +28 -0
- package/src/notAllPass.js +32 -0
- package/src/notAllUnique.js +25 -0
- package/src/notBoth.js +38 -0
- package/src/notEqual.js +31 -0
- package/src/omitBy.js +25 -0
- package/src/omitIndexes.js +27 -0
- package/src/overlaps.js +32 -0
- package/src/padCharsEnd.js +37 -0
- package/src/padCharsStart.js +35 -0
- package/src/padEnd.js +25 -0
- package/src/padStart.js +23 -0
- package/src/pathNotEq.js +31 -0
- package/src/pathOrLazy.js +30 -0
- package/src/paths.js +26 -0
- package/src/pickIndexes.js +30 -0
- package/src/propNotEq.js +30 -0
- package/src/rangeStep.js +37 -0
- package/src/reduceIndexed.js +31 -0
- package/src/reduceP.js +96 -0
- package/src/reduceRightP.js +101 -0
- package/src/rejectP.js +24 -0
- package/src/renameKeyWith.js +30 -0
- package/src/renameKeys.js +40 -0
- package/src/renameKeysWith.js +27 -0
- package/src/repeatStr.js +30 -0
- package/src/replaceAll.js +35 -0
- package/src/resolveP.js +28 -0
- package/src/round.js +26 -0
- package/src/seq.js +38 -0
- package/src/sign.js +33 -0
- package/src/skipTake.js +33 -0
- package/src/sliceFrom.js +23 -0
- package/src/sliceTo.js +23 -0
- package/src/sortByProps.js +31 -0
- package/src/spreadPath.js +26 -0
- package/src/spreadProp.js +25 -0
- package/src/stubArray.js +18 -0
- package/src/stubNull.js +19 -0
- package/src/stubObj.js +19 -0
- package/src/stubString.js +19 -0
- package/src/stubUndefined.js +19 -0
- package/src/subtractNum.js +20 -0
- package/src/thenCatchP.js +27 -0
- package/src/thenP.js +29 -0
- package/src/toArray.js +32 -0
- package/src/toInteger32.js +22 -0
- package/src/toUinteger32.js +26 -0
- package/src/trimCharsEnd.js +25 -0
- package/src/trimCharsStart.js +25 -0
- package/src/trimEnd.js +30 -0
- package/src/trimStart.js +29 -0
- package/src/trunc.js +33 -0
- package/src/unzipObjWith.js +40 -0
- package/src/viewOr.js +32 -0
- package/src/weave.js +35 -0
- package/src/weaveLazy.js +37 -0
- package/src/zipObjWith.js +27 -0
- package/tonicExample.js +4 -0
- package/types/index.d.ts +1553 -0
package/es/reduceP.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
+
|
|
9
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
import { curryN, reduce, length } from 'ramda';
|
|
14
|
+
import isUndefined from './isUndefined';
|
|
15
|
+
import resolveP from './resolveP';
|
|
16
|
+
import allP from './allP';
|
|
17
|
+
/* eslint-disable max-len */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Given an `Iterable`(arrays are `Iterable`), or a promise of an `Iterable`,
|
|
21
|
+
* which produces promises (or a mix of promises and values),
|
|
22
|
+
* iterate over all the values in the `Iterable` into an array and
|
|
23
|
+
* reduce the array to a value using the given iterator function.
|
|
24
|
+
*
|
|
25
|
+
* If the iterator function returns a promise, then the result of the promise is awaited,
|
|
26
|
+
* before continuing with next iteration. If any promise in the array is rejected or a promise
|
|
27
|
+
* returned by the iterator function is rejected, the result is rejected as well.
|
|
28
|
+
*
|
|
29
|
+
* If `initialValue` is `undefined` (or a promise that resolves to `undefined`) and
|
|
30
|
+
* the `Iterable` contains only 1 item, the callback will not be called and
|
|
31
|
+
* the `Iterable's` single item is returned. If the `Iterable` is empty, the callback
|
|
32
|
+
* will not be called and `initialValue` is returned (which may be undefined).
|
|
33
|
+
*
|
|
34
|
+
* This function is basically equivalent to {@link http://bluebirdjs.com/docs/api/promise.reduce.html|bluebird.reduce}.
|
|
35
|
+
*
|
|
36
|
+
* @func reduceP
|
|
37
|
+
* @memberOf RA
|
|
38
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/1.13.0|v1.13.0}
|
|
39
|
+
* @category List
|
|
40
|
+
* @typedef MaybePromise = Promise.<*> | *
|
|
41
|
+
* @sig ((Promise a, MaybePromise b) -> Promise a) -> MaybePromise a -> MaybePromise [MaybePromise b] -> Promise a
|
|
42
|
+
* @param {Function} fn The iterator function. Receives two values, the accumulator and the current element from the list
|
|
43
|
+
* @param {*|Promise.<*>} acc The accumulator value
|
|
44
|
+
* @param {Array.<*>|Promise.<Array<*|Promise.<*>>>} list The list to iterate over
|
|
45
|
+
* @return {Promise} The final, accumulated value
|
|
46
|
+
* @see {@link http://ramdajs.com/docs/#reduce|R.reduce}, {@link RA.reduceRightP|reduceRightP}, {@link http://bluebirdjs.com/docs/api/promise.reduce.html|bluebird.reduce}
|
|
47
|
+
* @example
|
|
48
|
+
*
|
|
49
|
+
* RA.reduceP(
|
|
50
|
+
* (total, fileName) => fs
|
|
51
|
+
* .readFileAsync(fileName, 'utf8')
|
|
52
|
+
* .then(contents => total + parseInt(contents, 10)),
|
|
53
|
+
* 0,
|
|
54
|
+
* ['file1.txt', 'file2.txt', 'file3.txt']
|
|
55
|
+
* ); // => Promise(10)
|
|
56
|
+
*
|
|
57
|
+
* RA.reduceP(
|
|
58
|
+
* (total, fileName) => fs
|
|
59
|
+
* .readFileAsync(fileName, 'utf8')
|
|
60
|
+
* .then(contents => total + parseInt(contents, 10)),
|
|
61
|
+
* Promise.resolve(0),
|
|
62
|
+
* ['file1.txt', 'file2.txt', 'file3.txt']
|
|
63
|
+
* ); // => Promise(10)
|
|
64
|
+
*
|
|
65
|
+
* RA.reduceP(
|
|
66
|
+
* (total, fileName) => fs
|
|
67
|
+
* .readFileAsync(fileName, 'utf8')
|
|
68
|
+
* .then(contents => total + parseInt(contents, 10)),
|
|
69
|
+
* 0,
|
|
70
|
+
* [Promise.resolve('file1.txt'), 'file2.txt', 'file3.txt']
|
|
71
|
+
* ); // => Promise(10)
|
|
72
|
+
*
|
|
73
|
+
* RA.reduceP(
|
|
74
|
+
* (total, fileName) => fs
|
|
75
|
+
* .readFileAsync(fileName, 'utf8')
|
|
76
|
+
* .then(contents => total + parseInt(contents, 10)),
|
|
77
|
+
* 0,
|
|
78
|
+
* Promise.resolve([Promise.resolve('file1.txt'), 'file2.txt', 'file3.txt'])
|
|
79
|
+
* ); // => Promise(10)
|
|
80
|
+
*
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/* esline-enable max-len */
|
|
84
|
+
|
|
85
|
+
var reduceP = curryN(3, function (fn, acc, list) {
|
|
86
|
+
return resolveP(list).then(function (iterable) {
|
|
87
|
+
var listLength = length(iterable);
|
|
88
|
+
|
|
89
|
+
if (listLength === 0) {
|
|
90
|
+
return acc;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
var reducer = reduce(function (accP, currentValueP) {
|
|
94
|
+
return accP.then(function (previousValue) {
|
|
95
|
+
return allP([previousValue, currentValueP]);
|
|
96
|
+
}).then(function (_ref) {
|
|
97
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
98
|
+
previousValue = _ref2[0],
|
|
99
|
+
currentValue = _ref2[1];
|
|
100
|
+
|
|
101
|
+
if (isUndefined(previousValue) && listLength === 1) {
|
|
102
|
+
return currentValue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return fn(previousValue, currentValue);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
return reducer(resolveP(acc), iterable);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
export default reduceP;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
+
|
|
9
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
import { curryN, pipe, equals, reduceRight, length, concat } from 'ramda';
|
|
14
|
+
import isUndefined from './isUndefined';
|
|
15
|
+
import resolveP from './resolveP';
|
|
16
|
+
import allP from './allP'; // in older ramda versions the order of the arguments is flipped
|
|
17
|
+
|
|
18
|
+
var flipArgs = pipe(reduceRight(concat, ''), equals('ba'))(['a', 'b']);
|
|
19
|
+
/* eslint-disable max-len */
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Given an `Iterable`(arrays are `Iterable`), or a promise of an `Iterable`,
|
|
23
|
+
* which produces promises (or a mix of promises and values),
|
|
24
|
+
* iterate over all the values in the `Iterable` into an array and
|
|
25
|
+
* reduce the array to a value using the given iterator function.
|
|
26
|
+
*
|
|
27
|
+
* Similar to {@link RA.reduceP|reduceP} except moves through the input list from the right to the left.
|
|
28
|
+
* The iterator function receives two values: (value, acc),
|
|
29
|
+
* while the arguments' order of reduceP's iterator function is (acc, value).
|
|
30
|
+
*
|
|
31
|
+
* @func reduceRightP
|
|
32
|
+
* @memberOf RA
|
|
33
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/1.13.0|v1.13.0}
|
|
34
|
+
* @category List
|
|
35
|
+
* @typedef MaybePromise = Promise.<*> | *
|
|
36
|
+
* @sig ((MaybePromise b, Promise a) -> Promise a) -> MaybePromise a -> MaybePromise [MaybePromise b] -> Promise a
|
|
37
|
+
* @param {Function} fn The iterator function. Receives two values, the current element from the list and the accumulator
|
|
38
|
+
* @param {*|Promise.<*>} acc The accumulator value
|
|
39
|
+
* @param {Array.<*>|Promise.<Array<*|Promise.<*>>>} list The list to iterate over
|
|
40
|
+
* @return {Promise} The final, accumulated value
|
|
41
|
+
* @see {@link RA.reduceP|reduceP}, {@link http://bluebirdjs.com/docs/api/promise.reduce.html|bluebird.reduce}
|
|
42
|
+
* @example
|
|
43
|
+
*
|
|
44
|
+
* RA.reduceRightP(
|
|
45
|
+
* (fileName, total) => fs
|
|
46
|
+
* .readFileAsync(fileName, 'utf8')
|
|
47
|
+
* .then(contents => total + parseInt(contents, 10)),
|
|
48
|
+
* 0,
|
|
49
|
+
* ['file1.txt', 'file2.txt', 'file3.txt']
|
|
50
|
+
* ); // => Promise(10)
|
|
51
|
+
*
|
|
52
|
+
* RA.reduceRightP(
|
|
53
|
+
* (fileName, total) => fs
|
|
54
|
+
* .readFileAsync(fileName, 'utf8')
|
|
55
|
+
* .then(contents => total + parseInt(contents, 10)),
|
|
56
|
+
* Promise.resolve(0),
|
|
57
|
+
* ['file1.txt', 'file2.txt', 'file3.txt']
|
|
58
|
+
* ); // => Promise(10)
|
|
59
|
+
*
|
|
60
|
+
* RA.reduceRightP(
|
|
61
|
+
* (fileName, total) => fs
|
|
62
|
+
* .readFileAsync(fileName, 'utf8')
|
|
63
|
+
* .then(contents => total + parseInt(contents, 10)),
|
|
64
|
+
* 0,
|
|
65
|
+
* [Promise.resolve('file1.txt'), 'file2.txt', 'file3.txt']
|
|
66
|
+
* ); // => Promise(10)
|
|
67
|
+
*
|
|
68
|
+
* RA.reduceRightP(
|
|
69
|
+
* (fileName, total) => fs
|
|
70
|
+
* .readFileAsync(fileName, 'utf8')
|
|
71
|
+
* .then(contents => total + parseInt(contents, 10)),
|
|
72
|
+
* 0,
|
|
73
|
+
* Promise.resolve([Promise.resolve('file1.txt'), 'file2.txt', 'file3.txt'])
|
|
74
|
+
* ); // => Promise(10)
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/* esline-enable max-len */
|
|
79
|
+
|
|
80
|
+
var reduceRightP = curryN(3, function (fn, acc, list) {
|
|
81
|
+
return resolveP(list).then(function (iterable) {
|
|
82
|
+
var listLength = length(iterable);
|
|
83
|
+
|
|
84
|
+
if (listLength === 0) {
|
|
85
|
+
return acc;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
var reducer = reduceRight(function (arg1, arg2) {
|
|
89
|
+
var accP;
|
|
90
|
+
var currentValueP;
|
|
91
|
+
|
|
92
|
+
if (flipArgs) {
|
|
93
|
+
accP = arg1;
|
|
94
|
+
currentValueP = arg2;
|
|
95
|
+
} else {
|
|
96
|
+
accP = arg2;
|
|
97
|
+
currentValueP = arg1;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return accP.then(function (previousValue) {
|
|
101
|
+
return allP([previousValue, currentValueP]);
|
|
102
|
+
}).then(function (_ref) {
|
|
103
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
104
|
+
previousValue = _ref2[0],
|
|
105
|
+
currentValue = _ref2[1];
|
|
106
|
+
|
|
107
|
+
if (isUndefined(previousValue) && listLength === 1) {
|
|
108
|
+
return currentValue;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return fn(currentValue, previousValue);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
return reducer(resolveP(acc), iterable);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
export default reduceRightP;
|
package/es/rejectP.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { bind } from 'ramda';
|
|
2
|
+
/**
|
|
3
|
+
* Composable shortcut for `Promise.reject`.
|
|
4
|
+
*
|
|
5
|
+
* Returns a Promise object that is rejected with the given reason.
|
|
6
|
+
*
|
|
7
|
+
* @func rejectP
|
|
8
|
+
* @memberOf RA
|
|
9
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/1.16.0|v1.16.0}
|
|
10
|
+
* @category Function
|
|
11
|
+
* @sig a -> Promise a
|
|
12
|
+
* @param {*} [reason=undefined] Reason why this Promise rejected
|
|
13
|
+
* @return {Promise} A Promise that is rejected with the given reason
|
|
14
|
+
* @see {@link RA.resolveP|resolveP}
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* RA.rejectP(); //=> Promise(undefined)
|
|
18
|
+
* RA.rejectP('a'); //=> Promise('a')
|
|
19
|
+
* RA.rejectP([1, 2, 3]); //=> Promise([1, 2, 3])
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
var rejectP = bind(Promise.reject, Promise);
|
|
23
|
+
export default rejectP;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { curry, equals, when } from 'ramda';
|
|
2
|
+
import renameKeysWith from './renameKeysWith';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new object with the own properties of the provided object, but the
|
|
5
|
+
* key `key` renamed according to logic of renaming function.
|
|
6
|
+
*
|
|
7
|
+
* Keep in mind that in case the new key name already existed on the object,
|
|
8
|
+
* the behaviour is undefined and the result may vary between various JS engines!
|
|
9
|
+
*
|
|
10
|
+
* @func renameKeyWith
|
|
11
|
+
* @memberOf RA
|
|
12
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.29.0|v2.29.0}
|
|
13
|
+
* @category Object
|
|
14
|
+
* @sig (k -> k) -> k -> {k: v} -> {k: v}
|
|
15
|
+
* @param {Function} fn Function that renames the keys
|
|
16
|
+
* @param {!string} key Key to rename
|
|
17
|
+
* @param {!Object} obj Provided object
|
|
18
|
+
* @return {!Object} New object with renamed key
|
|
19
|
+
* @see {@link RA.renameKeysWith|renameKeysWith}
|
|
20
|
+
* @example
|
|
21
|
+
*
|
|
22
|
+
* RA.renameKeyWith(R.concat('a'), 'A', { A: 1 }) //=> { aA: 1 }
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
var renameKeyWith = curry(function (fn, key, obj) {
|
|
26
|
+
return renameKeysWith(when(equals(key), fn), obj);
|
|
27
|
+
});
|
|
28
|
+
export default renameKeyWith;
|
package/es/renameKeys.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { curry, has } from 'ramda';
|
|
2
|
+
import renameKeysWith from './renameKeysWith';
|
|
3
|
+
|
|
4
|
+
var valueOrKey = function valueOrKey(keysMap) {
|
|
5
|
+
return function (key) {
|
|
6
|
+
if (has(key, keysMap)) {
|
|
7
|
+
return keysMap[key];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return key;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new object with the own properties of the provided object, but the
|
|
15
|
+
* keys renamed according to the keysMap object as `{oldKey: newKey}`.
|
|
16
|
+
* When some key is not found in the keysMap, then it's passed as-is.
|
|
17
|
+
*
|
|
18
|
+
* Keep in mind that in the case of keys conflict is behaviour undefined and
|
|
19
|
+
* the result may vary between various JS engines!
|
|
20
|
+
*
|
|
21
|
+
* @func renameKeys
|
|
22
|
+
* @memberOf RA
|
|
23
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/1.5.0|v1.5.0}
|
|
24
|
+
* @category Object
|
|
25
|
+
* @sig {a: b} -> {a: *} -> {b: *}
|
|
26
|
+
* @param {!Object} keysMap
|
|
27
|
+
* @param {!Object} obj
|
|
28
|
+
* @return {!Object} New object with renamed keys
|
|
29
|
+
* @see {@link https://github.com/ramda/ramda/wiki/Cookbook#rename-keys-of-an-object|Ramda Cookbook}, {@link RA.renameKeysWith|renameKeysWith}
|
|
30
|
+
* @example
|
|
31
|
+
*
|
|
32
|
+
* const input = { firstName: 'Elisia', age: 22, type: 'human' };
|
|
33
|
+
*
|
|
34
|
+
* RA.renameKeys({ firstName: 'name', type: 'kind', foo: 'bar' })(input);
|
|
35
|
+
* //=> { name: 'Elisia', age: 22, kind: 'human' }
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
var renameKeys = curry(function (keysMap, obj) {
|
|
40
|
+
return renameKeysWith(valueOrKey(keysMap), obj);
|
|
41
|
+
});
|
|
42
|
+
export default renameKeys;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { curry, toPairs, pipe, map, over, lensIndex, fromPairs } from 'ramda';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new object with the own properties of the provided object, but the
|
|
4
|
+
* keys renamed according to logic of renaming function.
|
|
5
|
+
*
|
|
6
|
+
* Keep in mind that in the case of keys conflict is behaviour undefined and
|
|
7
|
+
* the result may vary between various JS engines!
|
|
8
|
+
*
|
|
9
|
+
* @func renameKeysWith
|
|
10
|
+
* @memberOf RA
|
|
11
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/1.5.0|v1.5.0}
|
|
12
|
+
* @category Object
|
|
13
|
+
* @sig (a -> b) -> {a: *} -> {b: *}
|
|
14
|
+
* @param {Function} fn Function that renames the keys
|
|
15
|
+
* @param {!Object} obj Provided object
|
|
16
|
+
* @return {!Object} New object with renamed keys
|
|
17
|
+
* @see {@link https://github.com/ramda/ramda/wiki/Cookbook#rename-keys-of-an-object-by-a-function|Ramda Cookbook}, {@link RA.renameKeys|renameKeys}
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* RA.renameKeysWith(R.concat('a'), { A: 1, B: 2, C: 3 }) //=> { aA: 1, aB: 2, aC: 3 }
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
var renameKeysWith = curry(function (fn, obj) {
|
|
24
|
+
return pipe(toPairs, map(over(lensIndex(0), fn)), fromPairs)(obj);
|
|
25
|
+
});
|
|
26
|
+
export default renameKeysWith;
|
package/es/repeatStr.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { curry, invoker, flip } from 'ramda';
|
|
2
|
+
import ponyfill from './internal/ponyfills/String.repeat';
|
|
3
|
+
import isFunction from './isFunction';
|
|
4
|
+
export var repeatStrPonyfill = curry(ponyfill);
|
|
5
|
+
export var repeatStrInvoker = flip(invoker(1, 'repeat'));
|
|
6
|
+
/**
|
|
7
|
+
* Constructs and returns a new string which contains the specified
|
|
8
|
+
* number of copies of the string on which it was called, concatenated together.
|
|
9
|
+
*
|
|
10
|
+
* @func repeatStr
|
|
11
|
+
* @memberOf RA
|
|
12
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.11.0|v2.11.0}
|
|
13
|
+
* @category List
|
|
14
|
+
* @sig String -> Number -> String
|
|
15
|
+
* @param {string} value String value to be repeated
|
|
16
|
+
* @param {number} count An integer between 0 and +∞: [0, +∞), indicating the number of times to repeat the string in the newly-created string that is to be returned
|
|
17
|
+
* @return {string} A new string containing the specified number of copies of the given string
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* RA.repeatStr('a', 3); //=> 'aaa'
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
var repeatStr = isFunction(String.prototype.repeat) ? repeatStrInvoker : repeatStrPonyfill;
|
|
24
|
+
export default repeatStr;
|
package/es/replaceAll.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { curryN, invoker } from 'ramda';
|
|
2
|
+
import isFunction from './isFunction';
|
|
3
|
+
import ponyfill from './internal/ponyfills/String.replaceAll';
|
|
4
|
+
export var replaceAllPonyfill = curryN(3, ponyfill);
|
|
5
|
+
export var replaceAllInvoker = invoker(2, 'replaceAll');
|
|
6
|
+
/**
|
|
7
|
+
* Replaces all substring matches in a string with a replacement.
|
|
8
|
+
*
|
|
9
|
+
* @func replaceAll
|
|
10
|
+
* @memberOf RA
|
|
11
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.17.0|v2.17.0}
|
|
12
|
+
* @category String
|
|
13
|
+
* @sig String -> String -> String -> String
|
|
14
|
+
* @param {string} searchValue The substring or a global RegExp to match
|
|
15
|
+
* @param {string} replaceValue The string to replace the matches with
|
|
16
|
+
* @param {string} str The String to do the search and replacement in
|
|
17
|
+
* @return {string} A new string containing all the `searchValue` replaced with the `replaceValue`
|
|
18
|
+
* @throws {TypeError} When invalid arguments provided
|
|
19
|
+
* @see {@link http://ramdajs.com/docs/#replace|R.replace}, {@link https://github.com/tc39/proposal-string-replaceall|TC39 proposal}
|
|
20
|
+
* @example
|
|
21
|
+
*
|
|
22
|
+
* RA.replaceAll('ac', 'ef', 'ac ab ac ab'); //=> 'ef ab ef ab'
|
|
23
|
+
* RA.replaceAll('', '_', 'xxx'); //=> '_x_x_x_'
|
|
24
|
+
* RA.replaceAll(/x/g, 'v', 'xxx'); //=> 'vvv'
|
|
25
|
+
* RA.replaceAll(/x/, 'v', 'xxx'); //=> TypeError
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
var replaceAll = isFunction(String.prototype.replaceAll) ? replaceAllInvoker : replaceAllPonyfill;
|
|
29
|
+
export default replaceAll;
|
package/es/resolveP.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { bind } from 'ramda';
|
|
2
|
+
/* eslint-disable max-len */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Composable shortcut for `Promise.resolve`.
|
|
6
|
+
*
|
|
7
|
+
* Returns a Promise object that is resolved with the given value.
|
|
8
|
+
* If the value is a thenable (i.e. has a "then" method), the returned promise will
|
|
9
|
+
* "follow" that thenable, adopting its eventual state.
|
|
10
|
+
*
|
|
11
|
+
* @func resolveP
|
|
12
|
+
* @memberOf RA
|
|
13
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/1.16.0|v1.16.0}
|
|
14
|
+
* @category Function
|
|
15
|
+
* @sig a -> Promise a
|
|
16
|
+
* @param {*} [value=undefined] Argument to be resolved by this Promise. Can also be a Promise or a thenable to resolve
|
|
17
|
+
* @return {Promise} A Promise that is resolved with the given value, or the promise passed as value, if the value was a promise object
|
|
18
|
+
* @see {@link RA.rejectP|rejectP}
|
|
19
|
+
* @example
|
|
20
|
+
*
|
|
21
|
+
* RA.resolveP(); //=> Promise(undefined)
|
|
22
|
+
* RA.resolveP('a'); //=> Promise('a')
|
|
23
|
+
* RA.resolveP([1, 2, 3]); //=> Promise([1, 2, 3])
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/* eslint-enable max-len */
|
|
27
|
+
|
|
28
|
+
var resolveP = bind(Promise.resolve, Promise);
|
|
29
|
+
export default resolveP;
|
package/es/round.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { bind, curryN } from 'ramda';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the value of a number rounded to the nearest integer.
|
|
4
|
+
*
|
|
5
|
+
* @func round
|
|
6
|
+
* @memberOf RA
|
|
7
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.15.0|v2.15.0}
|
|
8
|
+
* @category Math
|
|
9
|
+
* @sig Number -> Number
|
|
10
|
+
* @param {number} number The number to round
|
|
11
|
+
* @return {number} The value of the given number rounded to the nearest integer
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* RA.round(0.9); //=> 1
|
|
15
|
+
* RA.round(5.95); //=> 6
|
|
16
|
+
* RA.round(5.5); //=> 6
|
|
17
|
+
* RA.round(5.05); //=> 5
|
|
18
|
+
* RA.round(-5.05); //=> -5
|
|
19
|
+
* RA.round(-5.5); //=> -5
|
|
20
|
+
* RA.round(-5.95); //=> -6
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
var round = curryN(1, bind(Math.round, Math));
|
|
24
|
+
export default round;
|
package/es/seq.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { curry, map, tap } from 'ramda';
|
|
2
|
+
/* eslint-disable max-len */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Runs the given list of functions in order with the supplied object, then returns the object.
|
|
6
|
+
* Also known as the normal order sequencing combinator.
|
|
7
|
+
*
|
|
8
|
+
* Acts as a transducer if a transformer is given as second parameter.
|
|
9
|
+
*
|
|
10
|
+
* @func seq
|
|
11
|
+
* @aliases sequencing
|
|
12
|
+
* @memberOf RA
|
|
13
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.3.0|v2.3.0}
|
|
14
|
+
* @category Function
|
|
15
|
+
* @sig [(a -> *), (a -> *), ...] -> a -> a
|
|
16
|
+
* @param {Array} fns The list of functions to call in order with `x` whose return values will be thrown away
|
|
17
|
+
* @param {*} x
|
|
18
|
+
* @return {*} `x`
|
|
19
|
+
* @see {@link http://ramdajs.com/docs/#tap|R.tap}, {@link http://www.cs.rpi.edu/academics/courses/spring11/proglang/handouts/lambda-calculus-chapter.pdf|sequencing combinator explained}
|
|
20
|
+
* @example
|
|
21
|
+
*
|
|
22
|
+
* RA.seq([console.info, console.log])('foo'); //=> prints 'foo' via info then log
|
|
23
|
+
*
|
|
24
|
+
* // usage in composition
|
|
25
|
+
* R.pipe(
|
|
26
|
+
* R.concat('prefix '),
|
|
27
|
+
* RA.seq([
|
|
28
|
+
* console.info, //=> prints 'prefix test'
|
|
29
|
+
* console.log //=> prints 'prefix test'
|
|
30
|
+
* ]),
|
|
31
|
+
* R.toUpper
|
|
32
|
+
* )('test'); //=> 'PREFIX TEST'
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/* eslint-enable max-len */
|
|
36
|
+
|
|
37
|
+
var seq = curry(function (fns, x) {
|
|
38
|
+
return tap(function (tx) {
|
|
39
|
+
return map(function (fn) {
|
|
40
|
+
return fn(tx);
|
|
41
|
+
})(fns);
|
|
42
|
+
})(x);
|
|
43
|
+
});
|
|
44
|
+
export default seq;
|
package/es/sign.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { bind, curryN } from 'ramda';
|
|
2
|
+
import isFunction from './isFunction';
|
|
3
|
+
import ponyfill from './internal/ponyfills/Math.sign';
|
|
4
|
+
export var signPonyfill = curryN(1, ponyfill);
|
|
5
|
+
/**
|
|
6
|
+
* Returns the sign of a number, indicating whether the number is positive, negative or zero.
|
|
7
|
+
*
|
|
8
|
+
* @func sign
|
|
9
|
+
* @memberOf RA
|
|
10
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.15.0|v2.15.0}
|
|
11
|
+
* @category Math
|
|
12
|
+
* @sig Number | String -> Number
|
|
13
|
+
* @param {number} number A number
|
|
14
|
+
* @return {number} A number representing the sign of the given argument. If the argument is a positive number, negative number, positive zero or negative zero, the function will return 1, -1, 0 or -0 respectively. Otherwise, NaN is returned
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* RA.sign(3); // 1
|
|
18
|
+
* RA.sign(-3); // -1
|
|
19
|
+
* RA.sign('-3'); // -1
|
|
20
|
+
* RA.sign(0); // 0
|
|
21
|
+
* RA.sign(-0); // -0
|
|
22
|
+
* RA.sign(NaN); // NaN
|
|
23
|
+
* RA.sign('foo'); // NaN
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
var sign = isFunction(Math.sign) ? curryN(1, bind(Math.sign, Math)) : signPonyfill;
|
|
27
|
+
export default sign;
|
package/es/skipTake.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { curry, addIndex, filter, pipe, modulo, identical, nthArg, __ } from 'ramda';
|
|
2
|
+
/**
|
|
3
|
+
* When given a number n and an array, returns an array containing every nth element.
|
|
4
|
+
*
|
|
5
|
+
* @func skipTake
|
|
6
|
+
* @memberOf RA
|
|
7
|
+
* @category List
|
|
8
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.26.0|v2.26.0}
|
|
9
|
+
* @sig Number -> [a] -> [a]
|
|
10
|
+
* @param {number} the nth element to extract
|
|
11
|
+
* @param {Array} value the input array
|
|
12
|
+
* @return {Array} An array containing every nth element
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* RA.skipTake(2, [1,2,3,4]) //=> [1, 3]
|
|
16
|
+
* RA.skipTake(3, R.range(0, 20)); //=> [0, 3, 6, 9, 12, 15, 18]
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
var skipTake = curry(function (n, list) {
|
|
20
|
+
return addIndex(filter)(pipe(nthArg(1), modulo(__, n), identical(0)))(list);
|
|
21
|
+
});
|
|
22
|
+
export default skipTake;
|
package/es/sliceFrom.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { __, slice } from 'ramda';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the elements of the given list or string (or object with a slice method)
|
|
4
|
+
* from fromIndex (inclusive).
|
|
5
|
+
* Dispatches to the slice method of the second argument, if present.
|
|
6
|
+
*
|
|
7
|
+
* @func sliceFrom
|
|
8
|
+
* @memberOf RA
|
|
9
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/1.16.0|v1.16.0}
|
|
10
|
+
* @category List
|
|
11
|
+
* @sig Number -> [a] -> [a]
|
|
12
|
+
* @param {number} fromIndex The start index (inclusive)
|
|
13
|
+
* @param {Array|string} list The list or string to slice
|
|
14
|
+
* @return {Array|string} The sliced list or string
|
|
15
|
+
* @see {@link http://ramdajs.com/docs/#slice|R.slice}, {@link RA.sliceTo|sliceTo}
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* RA.sliceFrom(1, [1, 2, 3]); //=> [2, 3]
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
var sliceFrom = slice(__, Infinity);
|
|
22
|
+
export default sliceFrom;
|
package/es/sliceTo.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { slice } from 'ramda';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the elements of the given list or string (or object with a slice method)
|
|
4
|
+
* to toIndex (exclusive).
|
|
5
|
+
* Dispatches to the slice method of the second argument, if present.
|
|
6
|
+
*
|
|
7
|
+
* @func sliceTo
|
|
8
|
+
* @memberOf RA
|
|
9
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/1.16.0|v1.16.0}
|
|
10
|
+
* @category List
|
|
11
|
+
* @sig Number -> [a] -> [a]
|
|
12
|
+
* @param {number} toIndex The end index (exclusive)
|
|
13
|
+
* @param {Array|string} list The list or string to slice
|
|
14
|
+
* @return {Array|string} The sliced list or string
|
|
15
|
+
* @see {@link http://ramdajs.com/docs/#slice|R.slice}, {@link RA.sliceFrom|sliceFrom}
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* RA.sliceTo(2, [1, 2, 3]); //=> [1, 2]
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
var sliceTo = slice(0);
|
|
22
|
+
export default sliceTo;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
|
2
|
+
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
+
|
|
9
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
import { reduce, either, curry, prop, sort, comparator, map, lt } from 'ramda';
|
|
14
|
+
/**
|
|
15
|
+
* Sort a list of objects by a list of props (if first prop value is equivalent, sort by second, etc).
|
|
16
|
+
*
|
|
17
|
+
* @func sortByProps
|
|
18
|
+
* @memberOf RA
|
|
19
|
+
* @since {@link https://char0n.github.io/ramda-adjunct/2.26.0|v2.26.0}
|
|
20
|
+
* @category List
|
|
21
|
+
* @sig [k] -> [{k: v}] -> [{k: v}]
|
|
22
|
+
* @param {Array.<string>} props A list of properties in the list param to sort by
|
|
23
|
+
* @param {Array.<object>} list A list of objects to be sorted
|
|
24
|
+
* @return {Array.<object>} A new list sorted by the properties in the props param
|
|
25
|
+
* @example
|
|
26
|
+
*
|
|
27
|
+
* sortByProps(['num'], [{num: 3}, {num: 2}, {num: 1}])
|
|
28
|
+
* //=> [{num: 1}, {num: 2} {num: 3}]
|
|
29
|
+
* sortByProps(['letter', 'num'], [{num: 3, letter: 'a'}, {num: 2, letter: 'a'} {num: 1, letter: 'z'}])
|
|
30
|
+
* //=> [ {num: 2, letter: 'a'}, {num: 3, letter: 'a'}, {num: 1, letter: 'z'}]
|
|
31
|
+
* sortByProps(['name', 'num'], [{num: 3}, {num: 2}, {num: 1}])
|
|
32
|
+
* //=> [{num: 1}, {num: 2}, {num: 3}]
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
var sortByProps = curry(function (props, list) {
|
|
36
|
+
var firstTruthy = function firstTruthy(_ref) {
|
|
37
|
+
var _ref2 = _toArray(_ref),
|
|
38
|
+
head = _ref2[0],
|
|
39
|
+
tail = _ref2.slice(1);
|
|
40
|
+
|
|
41
|
+
return reduce(either, head, tail);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
var makeComparator = function makeComparator(propName) {
|
|
45
|
+
return comparator(function (a, b) {
|
|
46
|
+
return lt(prop(propName, a), prop(propName, b));
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return sort(firstTruthy(map(makeComparator, props)), list);
|
|
51
|
+
});
|
|
52
|
+
export default sortByProps;
|