@voiceflow/common 7.10.0 → 7.11.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/build/common/utils/functional.d.ts +4 -4
- package/build/common/utils/functional.js +38 -6
- package/build/common/utils/functional.js.map +1 -1
- package/build/esm/utils/functional.d.ts +4 -4
- package/build/esm/utils/functional.js +38 -6
- package/build/esm/utils/functional.js.map +1 -1
- package/package.json +2 -2
|
@@ -15,9 +15,9 @@ export declare const noop: VoidFunction;
|
|
|
15
15
|
export declare const identity: <T>(value: T) => T;
|
|
16
16
|
export declare const stringify: (value: any) => string;
|
|
17
17
|
declare type ChainCallback<A extends any[]> = (...args: A) => void;
|
|
18
|
-
export declare const chain: <A extends any[]>(...
|
|
19
|
-
export declare const chainVoid: (...
|
|
20
|
-
export declare const chainAsync: <A extends any[]>(...
|
|
21
|
-
export declare const chainVoidAsync: (...
|
|
18
|
+
export declare const chain: <A extends any[]>(fns_0: Nullish<ChainCallback<A>>, ...fns_1: Nullish<ChainCallback<A>>[]) => (...args: A) => void;
|
|
19
|
+
export declare const chainVoid: (fns_0: Nullish<VoidFunction>, ...fns_1: Nullish<VoidFunction>[]) => () => void;
|
|
20
|
+
export declare const chainAsync: <A extends any[]>(fns_0: Nullish<ChainCallback<A>>, ...fns_1: Nullish<ChainCallback<A>>[]) => (...args: A) => Promise<void>;
|
|
21
|
+
export declare const chainVoidAsync: (fns_0: Nullish<VoidFunction>, ...fns_1: Nullish<VoidFunction>[]) => () => Promise<void>;
|
|
22
22
|
export declare const withEffect: <T>(callback: (value: T) => void) => (value: T) => T;
|
|
23
23
|
export {};
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withEffect = exports.chainVoidAsync = exports.chainAsync = exports.chainVoid = exports.chain = exports.stringify = exports.identity = exports.noop = exports.compose = void 0;
|
|
4
|
-
const compose = (...transforms) => (value) =>
|
|
4
|
+
const compose = (...transforms) => (value) => {
|
|
5
|
+
if (transforms.length === 1) {
|
|
6
|
+
return transforms[0](value);
|
|
7
|
+
}
|
|
8
|
+
if (transforms.length === 2) {
|
|
9
|
+
return transforms[0](transforms[1](value));
|
|
10
|
+
}
|
|
11
|
+
return transforms.reduceRight((acc, transform) => transform(acc), value);
|
|
12
|
+
};
|
|
5
13
|
exports.compose = compose;
|
|
6
14
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
7
15
|
const noop = () => { };
|
|
@@ -10,15 +18,39 @@ const identity = (value) => value;
|
|
|
10
18
|
exports.identity = identity;
|
|
11
19
|
const stringify = (value) => (typeof value === 'string' ? value : String(value));
|
|
12
20
|
exports.stringify = stringify;
|
|
13
|
-
const chain = (...fns) => (...args) =>
|
|
21
|
+
const chain = (...fns) => (...args) => {
|
|
22
|
+
var _a, _b, _c;
|
|
23
|
+
// perf optimization, most of the time we have one or two functions
|
|
24
|
+
if (fns.length === 1) {
|
|
25
|
+
(_a = fns[0]) === null || _a === void 0 ? void 0 : _a.call(fns, ...args);
|
|
26
|
+
}
|
|
27
|
+
else if (fns.length === 2) {
|
|
28
|
+
(_b = fns[0]) === null || _b === void 0 ? void 0 : _b.call(fns, ...args);
|
|
29
|
+
(_c = fns[1]) === null || _c === void 0 ? void 0 : _c.call(fns, ...args);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
fns.forEach((fn) => fn === null || fn === void 0 ? void 0 : fn(...args));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
14
35
|
exports.chain = chain;
|
|
15
36
|
const chainVoid = (...fns) => () => exports.chain(...fns)();
|
|
16
37
|
exports.chainVoid = chainVoid;
|
|
17
38
|
const chainAsync = (...fns) => async (...args) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
await (
|
|
39
|
+
var _a, _b, _c;
|
|
40
|
+
// perf optimization, most of the time we have one or two functions
|
|
41
|
+
if (fns.length === 1) {
|
|
42
|
+
await ((_a = fns[0]) === null || _a === void 0 ? void 0 : _a.call(fns, ...args));
|
|
43
|
+
}
|
|
44
|
+
else if (fns.length === 2) {
|
|
45
|
+
await ((_b = fns[0]) === null || _b === void 0 ? void 0 : _b.call(fns, ...args));
|
|
46
|
+
await ((_c = fns[1]) === null || _c === void 0 ? void 0 : _c.call(fns, ...args));
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
50
|
+
for (const fn of fns) {
|
|
51
|
+
// eslint-disable-next-line no-await-in-loop
|
|
52
|
+
await (fn === null || fn === void 0 ? void 0 : fn(...args));
|
|
53
|
+
}
|
|
22
54
|
}
|
|
23
55
|
};
|
|
24
56
|
exports.chainAsync = chainAsync;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functional.js","sourceRoot":"","sources":["../../../src/utils/functional.ts"],"names":[],"mappings":";;;AAwBO,MAAM,OAAO,GAClB,CAAC,GAAG,UAAuB,EAAE,EAAE,CAC/B,CAAmB,KAAQ,EAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"functional.js","sourceRoot":"","sources":["../../../src/utils/functional.ts"],"names":[],"mappings":";;;AAwBO,MAAM,OAAO,GAClB,CAAC,GAAG,UAAuB,EAAE,EAAE,CAC/B,CAAmB,KAAQ,EAAK,EAAE;IAChC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3B,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;KAC7B;IAED,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3B,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;KAC5C;IAED,OAAO,UAAU,CAAC,WAAW,CAAC,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAA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,GACrB,CAAkB,GAAG,GAAqE,EAAE,EAAE,CAC9F,KAAK,EAAE,GAAG,IAAO,EAAiB,EAAE;;IAClC,mEAAmE;IACnE,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE;QACpB,MAAM,CAAA,MAAA,GAAG,CAAC,CAAC,CAAC,+CAAN,GAAG,EAAM,GAAG,IAAI,CAAC,CAAA,CAAC;KACzB;SAAM,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3B,MAAM,CAAA,MAAA,GAAG,CAAC,CAAC,CAAC,+CAAN,GAAG,EAAM,GAAG,IAAI,CAAC,CAAA,CAAC;QACxB,MAAM,CAAA,MAAA,GAAG,CAAC,CAAC,CAAC,+CAAN,GAAG,EAAM,GAAG,IAAI,CAAC,CAAA,CAAC;KACzB;SAAM;QACL,gDAAgD;QAChD,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE;YACpB,4CAA4C;YAC5C,MAAM,CAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAG,GAAG,IAAI,CAAC,CAAA,CAAC;SACrB;KACF;AACH,CAAC,CAAC;AAhBS,QAAA,UAAU,cAgBnB;AAEG,MAAM,cAAc,GACzB,CAAC,GAAG,GAA6D,EAAE,EAAE,CACrE,GAAkB,EAAE,CAClB,kBAAU,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC;AAHZ,QAAA,cAAc,kBAGF;AAElB,MAAM,UAAU,GACrB,CAAI,QAA4B,EAAE,EAAE,CACpC,CAAC,KAAQ,EAAK,EAAE;IACd,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEhB,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AANS,QAAA,UAAU,cAMnB"}
|
|
@@ -15,9 +15,9 @@ export declare const noop: VoidFunction;
|
|
|
15
15
|
export declare const identity: <T>(value: T) => T;
|
|
16
16
|
export declare const stringify: (value: any) => string;
|
|
17
17
|
declare type ChainCallback<A extends any[]> = (...args: A) => void;
|
|
18
|
-
export declare const chain: <A extends any[]>(...
|
|
19
|
-
export declare const chainVoid: (...
|
|
20
|
-
export declare const chainAsync: <A extends any[]>(...
|
|
21
|
-
export declare const chainVoidAsync: (...
|
|
18
|
+
export declare const chain: <A extends any[]>(fns_0: Nullish<ChainCallback<A>>, ...fns_1: Nullish<ChainCallback<A>>[]) => (...args: A) => void;
|
|
19
|
+
export declare const chainVoid: (fns_0: Nullish<VoidFunction>, ...fns_1: Nullish<VoidFunction>[]) => () => void;
|
|
20
|
+
export declare const chainAsync: <A extends any[]>(fns_0: Nullish<ChainCallback<A>>, ...fns_1: Nullish<ChainCallback<A>>[]) => (...args: A) => Promise<void>;
|
|
21
|
+
export declare const chainVoidAsync: (fns_0: Nullish<VoidFunction>, ...fns_1: Nullish<VoidFunction>[]) => () => Promise<void>;
|
|
22
22
|
export declare const withEffect: <T>(callback: (value: T) => void) => (value: T) => T;
|
|
23
23
|
export {};
|
|
@@ -1,15 +1,47 @@
|
|
|
1
|
-
export const compose = (...transforms) => (value) =>
|
|
1
|
+
export const compose = (...transforms) => (value) => {
|
|
2
|
+
if (transforms.length === 1) {
|
|
3
|
+
return transforms[0](value);
|
|
4
|
+
}
|
|
5
|
+
if (transforms.length === 2) {
|
|
6
|
+
return transforms[0](transforms[1](value));
|
|
7
|
+
}
|
|
8
|
+
return transforms.reduceRight((acc, transform) => transform(acc), value);
|
|
9
|
+
};
|
|
2
10
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
3
11
|
export const noop = () => { };
|
|
4
12
|
export const identity = (value) => value;
|
|
5
13
|
export const stringify = (value) => (typeof value === 'string' ? value : String(value));
|
|
6
|
-
export const chain = (...fns) => (...args) =>
|
|
14
|
+
export const chain = (...fns) => (...args) => {
|
|
15
|
+
var _a, _b, _c;
|
|
16
|
+
// perf optimization, most of the time we have one or two functions
|
|
17
|
+
if (fns.length === 1) {
|
|
18
|
+
(_a = fns[0]) === null || _a === void 0 ? void 0 : _a.call(fns, ...args);
|
|
19
|
+
}
|
|
20
|
+
else if (fns.length === 2) {
|
|
21
|
+
(_b = fns[0]) === null || _b === void 0 ? void 0 : _b.call(fns, ...args);
|
|
22
|
+
(_c = fns[1]) === null || _c === void 0 ? void 0 : _c.call(fns, ...args);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
fns.forEach((fn) => fn === null || fn === void 0 ? void 0 : fn(...args));
|
|
26
|
+
}
|
|
27
|
+
};
|
|
7
28
|
export const chainVoid = (...fns) => () => chain(...fns)();
|
|
8
29
|
export const chainAsync = (...fns) => async (...args) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
await (
|
|
30
|
+
var _a, _b, _c;
|
|
31
|
+
// perf optimization, most of the time we have one or two functions
|
|
32
|
+
if (fns.length === 1) {
|
|
33
|
+
await ((_a = fns[0]) === null || _a === void 0 ? void 0 : _a.call(fns, ...args));
|
|
34
|
+
}
|
|
35
|
+
else if (fns.length === 2) {
|
|
36
|
+
await ((_b = fns[0]) === null || _b === void 0 ? void 0 : _b.call(fns, ...args));
|
|
37
|
+
await ((_c = fns[1]) === null || _c === void 0 ? void 0 : _c.call(fns, ...args));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
41
|
+
for (const fn of fns) {
|
|
42
|
+
// eslint-disable-next-line no-await-in-loop
|
|
43
|
+
await (fn === null || fn === void 0 ? void 0 : fn(...args));
|
|
44
|
+
}
|
|
13
45
|
}
|
|
14
46
|
};
|
|
15
47
|
export const chainVoidAsync = (...fns) => () => chainAsync(...fns)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functional.js","sourceRoot":"","sources":["../../../src/utils/functional.ts"],"names":[],"mappings":"AAwBA,MAAM,CAAC,MAAM,OAAO,GAClB,CAAC,GAAG,UAAuB,EAAE,EAAE,CAC/B,CAAmB,KAAQ,EAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"functional.js","sourceRoot":"","sources":["../../../src/utils/functional.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AG,GAAG,CAAC,EAAE,CAAC;AAEzB,MAAM,CAAC,MAAM,UAAU,GACrB,CAAI,QAA4B,EAAE,EAAE,CACpC,CAAC,KAAQ,EAAK,EAAE;IACd,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEhB,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voiceflow/common",
|
|
3
3
|
"description": "Junk drawer of utility functions",
|
|
4
|
-
"version": "7.
|
|
4
|
+
"version": "7.11.0",
|
|
5
5
|
"author": "Voiceflow",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/voiceflow/libs/issues"
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"test:single": "NODE_ENV=test ts-mocha --paths --config config/tests/mocharc.yml",
|
|
74
74
|
"test:unit": "NODE_ENV=test nyc --report-dir=nyc_coverage_unit ts-mocha --paths --config config/tests/mocharc.yml 'tests/**/*.unit.ts'"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "e63ccf954d8f6949d9e654e2cf85030c799f0a66"
|
|
77
77
|
}
|