@common-utilities/compose
Advanced tools
Comparing version 0.0.1 to 0.0.4
@@ -10,2 +10,3 @@ /** | ||
*/ | ||
export declare const compose: (...fns: any[]) => (patchedValue: any) => any; | ||
export declare const compose: (...fns: unknown[]) => (patchedValue: unknown) => unknown; | ||
export default compose; |
@@ -13,2 +13,3 @@ "use strict"; | ||
exports.compose = (...fns) => (patchedValue) => fns.reduceRight((fnVal, fn) => fn(fnVal), patchedValue); | ||
exports.default = exports.compose; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@common-utilities/compose", | ||
"version": "0.0.1", | ||
"description": "A basic implementation of the common utility function, Compose", | ||
"version": "0.0.4", | ||
"description": "A basic implementation of the common utility function, Compose 🚂", | ||
"main": "dist/index.js", | ||
"module": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"license": "MIT", | ||
@@ -19,3 +21,18 @@ "publishConfig": { | ||
}, | ||
"gitHead": "77dbb6ad0f4a0bd139159fec0c32f04b46422198" | ||
"jest": { | ||
"name": "@common-utilities/compose", | ||
"projects": [ | ||
"<rootDir>/packages/*" | ||
], | ||
"resetMocks": true, | ||
"rootDir": "./", | ||
"roots": [ | ||
"<rootDir>/src" | ||
], | ||
"testEnvironment": "node", | ||
"transform": { | ||
"^.+\\.(ts)$": "ts-jest" | ||
} | ||
}, | ||
"gitHead": "6a7e5b4c5a9cee469b6da45ab024189c2ba60447" | ||
} |
@@ -1,16 +0,32 @@ | ||
# @common-utilities/compose | ||
# @common-utilities/compose 🧰 🚂 | ||
A common function that take the output from one function and automatically patches it to the input of the next function until it spits out the final value. | ||
A common function composed of function arguments which returns their value to the next function until returning a final value. | ||
## Install | ||
```bash | ||
yarn add @common-utilities/compose -D | ||
``` | ||
## Function | ||
```javascript | ||
const compose = (...fns) => patchedValue => | ||
fns.reduceRight((fnVal, fn) => fn(fnVal), patchedValue); | ||
const compose = (...fns) => (val) => fns.reduceRight((fnVal, fn) => fn(fnVal), val) | ||
``` | ||
```typescript | ||
const compose = (...fns: Function[]) => (val: any) => fns.reduceRight((fnVal: any, fn: Function) => fn(fnVal), val) | ||
``` | ||
## Usage | ||
```javascript | ||
compose(add(2), subtract(3), multiple(5)); | ||
const add1 = (val = val + 1) | ||
const subtract2 = (val = val - 2) | ||
const multiplyBy3 = (val = val * 3) | ||
compose(add1, subtract2, multiplyBy3) | ||
``` | ||
--- | ||
View other [common utilities](../../README.md). |
@@ -7,7 +7,9 @@ /** | ||
* until it spits out the final value | ||
* ---- | ||
* @param {fns} an array of functions | ||
* @returns the next/final value | ||
*/ | ||
export const compose = (...fns: any[]) => | ||
(patchedValue: any) => | ||
fns.reduceRight((fnVal: any, fn: any) => fn(fnVal), patchedValue) | ||
export const compose = (...fns: unknown[]) => (patchedValue: unknown): unknown => | ||
fns.reduceRight((fnVal: unknown, fn: Function) => fn(fnVal), patchedValue) | ||
export default compose |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4871
55
33