@voiceflow/common
Advanced tools
Comparing version 7.10.0 to 7.11.0
@@ -18,7 +18,7 @@ import { Nullish } from '../types'; | ||
declare type ChainCallback<A extends any[]> = (...args: A) => void; | ||
export declare const chain: <A extends any[]>(...fns: Nullish<ChainCallback<A>>[]) => (...args: A) => void; | ||
export declare const chainVoid: (...fns: Array<Nullish<VoidFunction>>) => () => void; | ||
export declare const chainAsync: <A extends any[]>(...fns: Nullish<ChainCallback<A>>[]) => (...args: A) => Promise<void>; | ||
export declare const chainVoidAsync: (...fns: Array<Nullish<VoidFunction>>) => () => Promise<void>; | ||
export declare const chain: <A extends any[]>(fns_0: Nullish<ChainCallback<A>>, ...fns_1: Nullish<ChainCallback<A>>[]) => (...args: A) => void; | ||
export declare const chainVoid: (fns_0: Nullish<VoidFunction>, ...fns_1: Nullish<VoidFunction>[]) => () => void; | ||
export declare const chainAsync: <A extends any[]>(fns_0: Nullish<ChainCallback<A>>, ...fns_1: Nullish<ChainCallback<A>>[]) => (...args: A) => Promise<void>; | ||
export declare const chainVoidAsync: (fns_0: Nullish<VoidFunction>, ...fns_1: Nullish<VoidFunction>[]) => () => Promise<void>; | ||
export declare const withEffect: <T>(callback: (value: T) => void) => (value: T) => T; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.withEffect = exports.chainVoidAsync = exports.chainAsync = exports.chainVoid = exports.chain = exports.stringify = exports.identity = exports.noop = exports.compose = void 0; | ||
const compose = (...transforms) => (value) => [...transforms].reverse().reduce((acc, transform) => transform(acc), value); | ||
const compose = (...transforms) => (value) => { | ||
if (transforms.length === 1) { | ||
return transforms[0](value); | ||
} | ||
if (transforms.length === 2) { | ||
return transforms[0](transforms[1](value)); | ||
} | ||
return transforms.reduceRight((acc, transform) => transform(acc), value); | ||
}; | ||
exports.compose = compose; | ||
@@ -13,3 +21,16 @@ // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
exports.stringify = stringify; | ||
const chain = (...fns) => (...args) => fns.forEach((fn) => fn === null || fn === void 0 ? void 0 : fn(...args)); | ||
const chain = (...fns) => (...args) => { | ||
var _a, _b, _c; | ||
// perf optimization, most of the time we have one or two functions | ||
if (fns.length === 1) { | ||
(_a = fns[0]) === null || _a === void 0 ? void 0 : _a.call(fns, ...args); | ||
} | ||
else if (fns.length === 2) { | ||
(_b = fns[0]) === null || _b === void 0 ? void 0 : _b.call(fns, ...args); | ||
(_c = fns[1]) === null || _c === void 0 ? void 0 : _c.call(fns, ...args); | ||
} | ||
else { | ||
fns.forEach((fn) => fn === null || fn === void 0 ? void 0 : fn(...args)); | ||
} | ||
}; | ||
exports.chain = chain; | ||
@@ -19,7 +40,18 @@ const chainVoid = (...fns) => () => exports.chain(...fns)(); | ||
const chainAsync = (...fns) => async (...args) => { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const fn of fns) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await (fn === null || fn === void 0 ? void 0 : fn(...args)); | ||
var _a, _b, _c; | ||
// perf optimization, most of the time we have one or two functions | ||
if (fns.length === 1) { | ||
await ((_a = fns[0]) === null || _a === void 0 ? void 0 : _a.call(fns, ...args)); | ||
} | ||
else if (fns.length === 2) { | ||
await ((_b = fns[0]) === null || _b === void 0 ? void 0 : _b.call(fns, ...args)); | ||
await ((_c = fns[1]) === null || _c === void 0 ? void 0 : _c.call(fns, ...args)); | ||
} | ||
else { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const fn of fns) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await (fn === null || fn === void 0 ? void 0 : fn(...args)); | ||
} | ||
} | ||
}; | ||
@@ -26,0 +58,0 @@ exports.chainAsync = chainAsync; |
@@ -18,7 +18,7 @@ import { Nullish } from '../types'; | ||
declare type ChainCallback<A extends any[]> = (...args: A) => void; | ||
export declare const chain: <A extends any[]>(...fns: Nullish<ChainCallback<A>>[]) => (...args: A) => void; | ||
export declare const chainVoid: (...fns: Array<Nullish<VoidFunction>>) => () => void; | ||
export declare const chainAsync: <A extends any[]>(...fns: Nullish<ChainCallback<A>>[]) => (...args: A) => Promise<void>; | ||
export declare const chainVoidAsync: (...fns: Array<Nullish<VoidFunction>>) => () => Promise<void>; | ||
export declare const chain: <A extends any[]>(fns_0: Nullish<ChainCallback<A>>, ...fns_1: Nullish<ChainCallback<A>>[]) => (...args: A) => void; | ||
export declare const chainVoid: (fns_0: Nullish<VoidFunction>, ...fns_1: Nullish<VoidFunction>[]) => () => void; | ||
export declare const chainAsync: <A extends any[]>(fns_0: Nullish<ChainCallback<A>>, ...fns_1: Nullish<ChainCallback<A>>[]) => (...args: A) => Promise<void>; | ||
export declare const chainVoidAsync: (fns_0: Nullish<VoidFunction>, ...fns_1: Nullish<VoidFunction>[]) => () => Promise<void>; | ||
export declare const withEffect: <T>(callback: (value: T) => void) => (value: T) => T; | ||
export {}; |
@@ -1,2 +0,10 @@ | ||
export const compose = (...transforms) => (value) => [...transforms].reverse().reduce((acc, transform) => transform(acc), value); | ||
export const compose = (...transforms) => (value) => { | ||
if (transforms.length === 1) { | ||
return transforms[0](value); | ||
} | ||
if (transforms.length === 2) { | ||
return transforms[0](transforms[1](value)); | ||
} | ||
return transforms.reduceRight((acc, transform) => transform(acc), value); | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
@@ -6,10 +14,34 @@ export const noop = () => { }; | ||
export const stringify = (value) => (typeof value === 'string' ? value : String(value)); | ||
export const chain = (...fns) => (...args) => fns.forEach((fn) => fn === null || fn === void 0 ? void 0 : fn(...args)); | ||
export const chain = (...fns) => (...args) => { | ||
var _a, _b, _c; | ||
// perf optimization, most of the time we have one or two functions | ||
if (fns.length === 1) { | ||
(_a = fns[0]) === null || _a === void 0 ? void 0 : _a.call(fns, ...args); | ||
} | ||
else if (fns.length === 2) { | ||
(_b = fns[0]) === null || _b === void 0 ? void 0 : _b.call(fns, ...args); | ||
(_c = fns[1]) === null || _c === void 0 ? void 0 : _c.call(fns, ...args); | ||
} | ||
else { | ||
fns.forEach((fn) => fn === null || fn === void 0 ? void 0 : fn(...args)); | ||
} | ||
}; | ||
export const chainVoid = (...fns) => () => chain(...fns)(); | ||
export const chainAsync = (...fns) => async (...args) => { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const fn of fns) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await (fn === null || fn === void 0 ? void 0 : fn(...args)); | ||
var _a, _b, _c; | ||
// perf optimization, most of the time we have one or two functions | ||
if (fns.length === 1) { | ||
await ((_a = fns[0]) === null || _a === void 0 ? void 0 : _a.call(fns, ...args)); | ||
} | ||
else if (fns.length === 2) { | ||
await ((_b = fns[0]) === null || _b === void 0 ? void 0 : _b.call(fns, ...args)); | ||
await ((_c = fns[1]) === null || _c === void 0 ? void 0 : _c.call(fns, ...args)); | ||
} | ||
else { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const fn of fns) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await (fn === null || fn === void 0 ? void 0 : fn(...args)); | ||
} | ||
} | ||
}; | ||
@@ -16,0 +48,0 @@ export const chainVoidAsync = (...fns) => () => chainAsync(...fns)(); |
{ | ||
"name": "@voiceflow/common", | ||
"description": "Junk drawer of utility functions", | ||
"version": "7.10.0", | ||
"version": "7.11.0", | ||
"author": "Voiceflow", | ||
@@ -76,3 +76,3 @@ "bugs": { | ||
}, | ||
"gitHead": "03cbd927fe8c49cd9715289fdd10046eab913820" | ||
"gitHead": "e63ccf954d8f6949d9e654e2cf85030c799f0a66" | ||
} |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
340711
6259
0