@voiceflow/common 8.2.8 → 8.3.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/cjs/constants/environment.js +1 -1
- package/build/cjs/constants/regexp.d.ts +5 -5
- package/build/cjs/constants/regexp.d.ts.map +1 -1
- package/build/cjs/crypto/hex2abc.d.ts.map +1 -1
- package/build/cjs/types.d.ts +26 -26
- package/build/cjs/types.d.ts.map +1 -1
- package/build/cjs/utils/array.d.ts +3 -3
- package/build/cjs/utils/array.d.ts.map +1 -1
- package/build/cjs/utils/array.js +2 -3
- package/build/cjs/utils/emails.d.ts.map +1 -1
- package/build/cjs/utils/functional.d.ts +4 -4
- package/build/cjs/utils/functional.d.ts.map +1 -1
- package/build/cjs/utils/functional.js +0 -1
- package/build/cjs/utils/id.d.ts +1 -1
- package/build/cjs/utils/id.d.ts.map +1 -1
- package/build/cjs/utils/intent.d.ts +6 -6
- package/build/cjs/utils/intent.d.ts.map +1 -1
- package/build/cjs/utils/intent.js +4 -2
- package/build/cjs/utils/mathjs.js +1 -1
- package/build/cjs/utils/normalized.d.ts +5 -5
- package/build/cjs/utils/normalized.d.ts.map +1 -1
- package/build/cjs/utils/number.d.ts.map +1 -1
- package/build/cjs/utils/object/common.d.ts +1 -1
- package/build/cjs/utils/object/common.d.ts.map +1 -1
- package/build/cjs/utils/object/deepMap.d.ts +1 -1
- package/build/cjs/utils/object/deepMap.d.ts.map +1 -1
- package/build/cjs/utils/object/deepMap.js +0 -2
- package/build/cjs/utils/object/diff.d.ts +1 -1
- package/build/cjs/utils/object/diff.d.ts.map +1 -1
- package/build/cjs/utils/object/keys.d.ts +2 -1
- package/build/cjs/utils/object/keys.d.ts.map +1 -1
- package/build/cjs/utils/promise.d.ts.map +1 -1
- package/build/cjs/utils/protocol.d.ts +2 -2
- package/build/cjs/utils/protocol.d.ts.map +1 -1
- package/build/cjs/utils/slot.d.ts.map +1 -1
- package/build/cjs/utils/typeguard.d.ts +2 -2
- package/build/cjs/utils/typeguard.d.ts.map +1 -1
- package/build/cjs/utils/variables.d.ts +2 -2
- package/build/cjs/utils/variables.d.ts.map +1 -1
- package/build/esm/constants/regexp.d.ts +5 -5
- package/build/esm/constants/regexp.d.ts.map +1 -1
- package/build/esm/crypto/hex2abc.d.ts.map +1 -1
- package/build/esm/types.d.ts +26 -26
- package/build/esm/types.d.ts.map +1 -1
- package/build/esm/utils/array.d.ts +3 -3
- package/build/esm/utils/array.d.ts.map +1 -1
- package/build/esm/utils/array.js +2 -3
- package/build/esm/utils/emails.d.ts.map +1 -1
- package/build/esm/utils/functional.d.ts +4 -4
- package/build/esm/utils/functional.d.ts.map +1 -1
- package/build/esm/utils/functional.js +0 -1
- package/build/esm/utils/id.d.ts +1 -1
- package/build/esm/utils/id.d.ts.map +1 -1
- package/build/esm/utils/intent.d.ts +6 -6
- package/build/esm/utils/intent.d.ts.map +1 -1
- package/build/esm/utils/intent.js +4 -2
- package/build/esm/utils/mathjs.js +1 -1
- package/build/esm/utils/normalized.d.ts +5 -5
- package/build/esm/utils/normalized.d.ts.map +1 -1
- package/build/esm/utils/number.d.ts.map +1 -1
- package/build/esm/utils/object/common.d.ts +1 -1
- package/build/esm/utils/object/common.d.ts.map +1 -1
- package/build/esm/utils/object/deepMap.d.ts +1 -1
- package/build/esm/utils/object/deepMap.d.ts.map +1 -1
- package/build/esm/utils/object/deepMap.js +0 -2
- package/build/esm/utils/object/diff.d.ts +1 -1
- package/build/esm/utils/object/diff.d.ts.map +1 -1
- package/build/esm/utils/object/keys.d.ts +2 -1
- package/build/esm/utils/object/keys.d.ts.map +1 -1
- package/build/esm/utils/promise.d.ts.map +1 -1
- package/build/esm/utils/protocol.d.ts +2 -2
- package/build/esm/utils/protocol.d.ts.map +1 -1
- package/build/esm/utils/slot.d.ts.map +1 -1
- package/build/esm/utils/typeguard.d.ts +2 -2
- package/build/esm/utils/typeguard.d.ts.map +1 -1
- package/build/esm/utils/variables.d.ts +2 -2
- package/build/esm/utils/variables.d.ts.map +1 -1
- package/package.json +46 -48
- package/build/cjs/crypto/hex2abc.test.d.ts +0 -2
- package/build/cjs/crypto/hex2abc.test.d.ts.map +0 -1
- package/build/cjs/crypto/hex2abc.test.js +0 -12
- package/build/cjs/crypto/murmurhash.test.d.ts +0 -2
- package/build/cjs/crypto/murmurhash.test.d.ts.map +0 -1
- package/build/cjs/crypto/murmurhash.test.js +0 -23
- package/build/cjs/utils/__fixtures__/name.json +0 -64
- package/build/cjs/utils/array.test.d.ts +0 -2
- package/build/cjs/utils/array.test.d.ts.map +0 -1
- package/build/cjs/utils/array.test.js +0 -237
- package/build/cjs/utils/email.test.d.ts +0 -2
- package/build/cjs/utils/email.test.d.ts.map +0 -1
- package/build/cjs/utils/email.test.js +0 -22
- package/build/cjs/utils/functional.test.d.ts +0 -2
- package/build/cjs/utils/functional.test.d.ts.map +0 -1
- package/build/cjs/utils/functional.test.js +0 -139
- package/build/cjs/utils/id.test.d.ts +0 -2
- package/build/cjs/utils/id.test.d.ts.map +0 -1
- package/build/cjs/utils/id.test.js +0 -66
- package/build/cjs/utils/intent.test.d.ts +0 -2
- package/build/cjs/utils/intent.test.d.ts.map +0 -1
- package/build/cjs/utils/intent.test.js +0 -100
- package/build/cjs/utils/map.test.d.ts +0 -2
- package/build/cjs/utils/map.test.d.ts.map +0 -1
- package/build/cjs/utils/map.test.js +0 -22
- package/build/cjs/utils/object/common.test.d.ts +0 -2
- package/build/cjs/utils/object/common.test.d.ts.map +0 -1
- package/build/cjs/utils/object/common.test.js +0 -175
- package/build/cjs/utils/object/deepMap.test.d.ts +0 -2
- package/build/cjs/utils/object/deepMap.test.d.ts.map +0 -1
- package/build/cjs/utils/object/deepMap.test.js +0 -114
- package/build/cjs/utils/object/diff.test.d.ts +0 -2
- package/build/cjs/utils/object/diff.test.d.ts.map +0 -1
- package/build/cjs/utils/object/diff.test.js +0 -19
- package/build/cjs/utils/object/keys.test.d.ts +0 -2
- package/build/cjs/utils/object/keys.test.d.ts.map +0 -1
- package/build/cjs/utils/object/keys.test.js +0 -15
- package/build/cjs/utils/promise.test.d.ts +0 -2
- package/build/cjs/utils/promise.test.d.ts.map +0 -1
- package/build/cjs/utils/promise.test.js +0 -25
- package/build/cjs/utils/protocol.test.d.ts +0 -2
- package/build/cjs/utils/protocol.test.d.ts.map +0 -1
- package/build/cjs/utils/protocol.test.js +0 -40
- package/build/cjs/utils/slot.test.d.ts +0 -2
- package/build/cjs/utils/slot.test.d.ts.map +0 -1
- package/build/cjs/utils/slot.test.js +0 -38
- package/build/cjs/utils/string.test.d.ts +0 -2
- package/build/cjs/utils/string.test.d.ts.map +0 -1
- package/build/cjs/utils/string.test.js +0 -53
- package/build/cjs/utils/timezones.test.d.ts +0 -2
- package/build/cjs/utils/timezones.test.d.ts.map +0 -1
- package/build/cjs/utils/timezones.test.js +0 -12
- package/build/cjs/utils/typeguard.test.d.ts +0 -2
- package/build/cjs/utils/typeguard.test.d.ts.map +0 -1
- package/build/cjs/utils/typeguard.test.js +0 -55
- package/build/esm/crypto/hex2abc.test.d.ts +0 -2
- package/build/esm/crypto/hex2abc.test.d.ts.map +0 -1
- package/build/esm/crypto/hex2abc.test.js +0 -10
- package/build/esm/crypto/murmurhash.test.d.ts +0 -2
- package/build/esm/crypto/murmurhash.test.d.ts.map +0 -1
- package/build/esm/crypto/murmurhash.test.js +0 -21
- package/build/esm/utils/__fixtures__/name.json +0 -64
- package/build/esm/utils/array.test.d.ts +0 -2
- package/build/esm/utils/array.test.d.ts.map +0 -1
- package/build/esm/utils/array.test.js +0 -235
- package/build/esm/utils/email.test.d.ts +0 -2
- package/build/esm/utils/email.test.d.ts.map +0 -1
- package/build/esm/utils/email.test.js +0 -20
- package/build/esm/utils/functional.test.d.ts +0 -2
- package/build/esm/utils/functional.test.d.ts.map +0 -1
- package/build/esm/utils/functional.test.js +0 -137
- package/build/esm/utils/id.test.d.ts +0 -2
- package/build/esm/utils/id.test.d.ts.map +0 -1
- package/build/esm/utils/id.test.js +0 -64
- package/build/esm/utils/intent.test.d.ts +0 -2
- package/build/esm/utils/intent.test.d.ts.map +0 -1
- package/build/esm/utils/intent.test.js +0 -75
- package/build/esm/utils/map.test.d.ts +0 -2
- package/build/esm/utils/map.test.d.ts.map +0 -1
- package/build/esm/utils/map.test.js +0 -20
- package/build/esm/utils/object/common.test.d.ts +0 -2
- package/build/esm/utils/object/common.test.d.ts.map +0 -1
- package/build/esm/utils/object/common.test.js +0 -173
- package/build/esm/utils/object/deepMap.test.d.ts +0 -2
- package/build/esm/utils/object/deepMap.test.d.ts.map +0 -1
- package/build/esm/utils/object/deepMap.test.js +0 -109
- package/build/esm/utils/object/diff.test.d.ts +0 -2
- package/build/esm/utils/object/diff.test.d.ts.map +0 -1
- package/build/esm/utils/object/diff.test.js +0 -17
- package/build/esm/utils/object/keys.test.d.ts +0 -2
- package/build/esm/utils/object/keys.test.d.ts.map +0 -1
- package/build/esm/utils/object/keys.test.js +0 -13
- package/build/esm/utils/promise.test.d.ts +0 -2
- package/build/esm/utils/promise.test.d.ts.map +0 -1
- package/build/esm/utils/promise.test.js +0 -23
- package/build/esm/utils/protocol.test.d.ts +0 -2
- package/build/esm/utils/protocol.test.d.ts.map +0 -1
- package/build/esm/utils/protocol.test.js +0 -38
- package/build/esm/utils/slot.test.d.ts +0 -2
- package/build/esm/utils/slot.test.d.ts.map +0 -1
- package/build/esm/utils/slot.test.js +0 -13
- package/build/esm/utils/string.test.d.ts +0 -2
- package/build/esm/utils/string.test.d.ts.map +0 -1
- package/build/esm/utils/string.test.js +0 -51
- package/build/esm/utils/timezones.test.d.ts +0 -2
- package/build/esm/utils/timezones.test.d.ts.map +0 -1
- package/build/esm/utils/timezones.test.js +0 -10
- package/build/esm/utils/typeguard.test.d.ts +0 -2
- package/build/esm/utils/typeguard.test.d.ts.map +0 -1
- package/build/esm/utils/typeguard.test.js +0 -53
package/package.json
CHANGED
|
@@ -1,66 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voiceflow/common",
|
|
3
|
+
"version": "8.3.0",
|
|
3
4
|
"description": "Junk drawer of utility functions",
|
|
4
|
-
"version": "8.2.8",
|
|
5
|
-
"author": "Voiceflow",
|
|
6
|
-
"bugs": {
|
|
7
|
-
"url": "https://github.com/voiceflow/libs/issues"
|
|
8
|
-
},
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"@types/crypto-js": "^4.0.2",
|
|
11
|
-
"@types/shallowequal": "^1.1.1",
|
|
12
|
-
"bson-objectid": "^2.0.1",
|
|
13
|
-
"crypto-js": "^4.2.0",
|
|
14
|
-
"cuid": "^2.1.8",
|
|
15
|
-
"dayjs": "1.10.7",
|
|
16
|
-
"lodash": "^4.17.21",
|
|
17
|
-
"murmurhash-wasm": "^1.3.0",
|
|
18
|
-
"number-to-words": "^1.2.4",
|
|
19
|
-
"shallowequal": "^1.1.0",
|
|
20
|
-
"typescript-fsa": "3.0.0"
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@types/lodash": "^4.14.176",
|
|
24
|
-
"@types/number-to-words": "1.2.0",
|
|
25
|
-
"@voiceflow-meta/jest-config": "1.0.2",
|
|
26
|
-
"@voiceflow-meta/typescript-config": "1.0.2"
|
|
27
|
-
},
|
|
28
|
-
"files": [
|
|
29
|
-
"build"
|
|
30
|
-
],
|
|
31
|
-
"homepage": "https://github.com/voiceflow/libs#readme",
|
|
32
5
|
"keywords": [
|
|
33
6
|
"voiceflow"
|
|
34
7
|
],
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
"publishConfig": {
|
|
39
|
-
"access": "public"
|
|
8
|
+
"homepage": "https://github.com/voiceflow/libs#readme",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/voiceflow/libs/issues"
|
|
40
11
|
},
|
|
41
12
|
"repository": {
|
|
42
13
|
"type": "git",
|
|
43
14
|
"url": "git+https://github.com/voiceflow/libs.git"
|
|
44
15
|
},
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"author": "Voiceflow",
|
|
18
|
+
"main": "build/cjs/index.js",
|
|
19
|
+
"module": "build/esm/index.js",
|
|
20
|
+
"types": "build/cjs/index.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"build"
|
|
23
|
+
],
|
|
45
24
|
"scripts": {
|
|
46
|
-
"build": "yarn
|
|
47
|
-
"build:cjs": "yarn g:
|
|
48
|
-
"build:
|
|
25
|
+
"build": "yarn g:turbo run build:cmd --filter=@voiceflow/common...",
|
|
26
|
+
"build:cjs": "yarn g:build:pkg cjs",
|
|
27
|
+
"build:cmd": "yarn g:run-p build:cjs build:esm",
|
|
28
|
+
"build:esm": "yarn g:build:pkg esm",
|
|
49
29
|
"clean": "yarn g:rimraf build",
|
|
50
|
-
"
|
|
51
|
-
"lint": "yarn g:eslint
|
|
52
|
-
"lint:fix": "yarn lint --fix",
|
|
53
|
-
"lint:
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"test:
|
|
59
|
-
|
|
30
|
+
"lint": "yarn g:run-p -c lint:eslint lint:prettier",
|
|
31
|
+
"lint:eslint": "yarn g:eslint",
|
|
32
|
+
"lint:fix": "yarn g:run-p -c \"lint:eslint --fix\" \"lint:prettier --write\"",
|
|
33
|
+
"lint:prettier": "yarn g:prettier --check",
|
|
34
|
+
"tdd": "yarn g:vitest",
|
|
35
|
+
"test": "yarn g:run-p -c test:dependencies test:types test:unit",
|
|
36
|
+
"test:dependencies": "yarn g:depcruise",
|
|
37
|
+
"test:types": "yarn g:tsc --noEmit",
|
|
38
|
+
"test:unit": "yarn g:vitest run --coverage"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@types/crypto-js": "4.1.0",
|
|
42
|
+
"@types/shallowequal": "1.1.1",
|
|
43
|
+
"bson-objectid": "2.0.2",
|
|
44
|
+
"crypto-js": "4.2.0",
|
|
45
|
+
"cuid": "2.1.8",
|
|
46
|
+
"dayjs": "1.10.7",
|
|
47
|
+
"lodash": "4.17.21",
|
|
48
|
+
"murmurhash-wasm": "1.3.0",
|
|
49
|
+
"number-to-words": "1.2.4",
|
|
50
|
+
"shallowequal": "1.1.0",
|
|
51
|
+
"typescript-fsa": "3.0.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/lodash": "4.14.178",
|
|
55
|
+
"@types/number-to-words": "1.2.0"
|
|
60
56
|
},
|
|
61
|
-
"types": "build/cjs/index.d.ts",
|
|
62
57
|
"volta": {
|
|
63
58
|
"extends": "../../package.json"
|
|
64
59
|
},
|
|
65
|
-
"
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
},
|
|
63
|
+
"gitHead": "82c3c81b9012f5e64c4bec3cd031af220ad26572"
|
|
66
64
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hex2abc.test.d.ts","sourceRoot":"","sources":["../../../src/crypto/hex2abc.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const hex2abc_1 = require("./hex2abc");
|
|
4
|
-
describe('hex2abc()', () => {
|
|
5
|
-
it('works', () => {
|
|
6
|
-
expect((0, hex2abc_1.hex2abc)('abcdef')).toBe('abcdef');
|
|
7
|
-
expect((0, hex2abc_1.hex2abc)('0123456789')).toBe('ghijklmnop');
|
|
8
|
-
});
|
|
9
|
-
it('works with 0x prefixes', () => {
|
|
10
|
-
expect((0, hex2abc_1.hex2abc)('0xabc123')).toBe('gxabchij');
|
|
11
|
-
});
|
|
12
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"murmurhash.test.d.ts","sourceRoot":"","sources":["../../../src/crypto/murmurhash.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const murmurhash_1 = require("./murmurhash");
|
|
4
|
-
// for second test check (4 byte chunk)
|
|
5
|
-
// const buf_left = Buffer.of(0xff, 0xff, 0xff, 0xff);
|
|
6
|
-
// const buf_right = Buffer.of(0x76, 0x29, 0x3b, 0x50);
|
|
7
|
-
// for third test check (correct endian order)
|
|
8
|
-
// const buf_left_two = Buffer.of(0x21, 0x43, 0x65, 0x87);
|
|
9
|
-
// const buf_right_two = Buffer.of(0xf5, 0x5b, 0x51, 0x6b);
|
|
10
|
-
describe('hash()', () => {
|
|
11
|
-
it('return a 32-bit hash resulting from the murmurhash3 algorithm', () => {
|
|
12
|
-
expect(murmurhash_1.MurmurHash.hash('hello', 0)).toBe('lokkdakm');
|
|
13
|
-
expect(murmurhash_1.MurmurHash.hash('hello world', 0)).toBe('kkehkpgl');
|
|
14
|
-
expect(murmurhash_1.MurmurHash.hash('helloworld', 0)).toBe('holkilfm');
|
|
15
|
-
expect(murmurhash_1.MurmurHash.hash('HELLOWORLD', 0)).toBe('dohkopda');
|
|
16
|
-
expect(murmurhash_1.MurmurHash.hash('', 0)).toBe('g'); // not sure why '0000 0000' fails as a test
|
|
17
|
-
expect(murmurhash_1.MurmurHash.hash('abc', 0)).toBe('bjddpjfa');
|
|
18
|
-
expect(murmurhash_1.MurmurHash.hash('ABC', 0)).toBe('kjchcljl');
|
|
19
|
-
// from https://github.com/jonahsnider/murmurhash-wasm/blob/main/test/murmur-hash3/hash-32.test.ts
|
|
20
|
-
// expect(MurmurHash.hash(buf_left.toString('hex'), 0)).to.eql(buf_right.toString('hex'));
|
|
21
|
-
// expect(MurmurHash.hash(buf_left_two.toString('hex'), 0)).to.eql(buf_right_two.toString('hex'));
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"slots": [
|
|
3
|
-
{
|
|
4
|
-
"key": "4i3h3mmi",
|
|
5
|
-
"name": "slotmans",
|
|
6
|
-
"type": {
|
|
7
|
-
"value": "custom"
|
|
8
|
-
},
|
|
9
|
-
"color": "#4F9ED1",
|
|
10
|
-
"inputs": ["tyler", "john", "scott", "michael", "william", "andy", "peter", "frank", "igor", "steven", "jessica"]
|
|
11
|
-
}
|
|
12
|
-
],
|
|
13
|
-
"intents": [
|
|
14
|
-
{
|
|
15
|
-
"key": "3sb53sup",
|
|
16
|
-
"name": "name_intent",
|
|
17
|
-
"slots": [
|
|
18
|
-
{
|
|
19
|
-
"id": "4i3h3mmi",
|
|
20
|
-
"dialog": {
|
|
21
|
-
"prompt": [
|
|
22
|
-
{
|
|
23
|
-
"text": "",
|
|
24
|
-
"slots": []
|
|
25
|
-
}
|
|
26
|
-
],
|
|
27
|
-
"confirm": [
|
|
28
|
-
{
|
|
29
|
-
"text": "",
|
|
30
|
-
"slots": []
|
|
31
|
-
}
|
|
32
|
-
],
|
|
33
|
-
"utterances": [
|
|
34
|
-
{
|
|
35
|
-
"text": "{{[name].4i3h3mmi}} ",
|
|
36
|
-
"slots": ["4i3h3mmi"]
|
|
37
|
-
}
|
|
38
|
-
],
|
|
39
|
-
"confirmEnabled": false
|
|
40
|
-
},
|
|
41
|
-
"required": false
|
|
42
|
-
}
|
|
43
|
-
],
|
|
44
|
-
"inputs": [
|
|
45
|
-
{
|
|
46
|
-
"text": "It's {{[slotmans].4i3h3mmi}}",
|
|
47
|
-
"slots": ["4i3h3mmi"]
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"text": "I'm {{[slotmans].4i3h3mmi}}",
|
|
51
|
-
"slots": ["4i3h3mmi"]
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
"text": "{{[slotmans].4i3h3mmi}}",
|
|
55
|
-
"slots": ["4i3h3mmi"]
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
"text": "my name is {{[slotmans].4i3h3mmi}}",
|
|
59
|
-
"slots": ["4i3h3mmi"]
|
|
60
|
-
}
|
|
61
|
-
]
|
|
62
|
-
}
|
|
63
|
-
]
|
|
64
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"array.test.d.ts","sourceRoot":"","sources":["../../../src/utils/array.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const array_1 = require("./array");
|
|
4
|
-
describe('Utils | array', () => {
|
|
5
|
-
describe('unique()', () => {
|
|
6
|
-
it('return an array containing one instance of each value from the array passed to it', () => {
|
|
7
|
-
expect((0, array_1.unique)([1, 1, 2, 0, 1, 4, 3, 1, 9, 9, 2])).toEqual([1, 2, 0, 4, 3, 9]);
|
|
8
|
-
});
|
|
9
|
-
});
|
|
10
|
-
describe('without()', () => {
|
|
11
|
-
it('return an array containing every value from the array passed to it except for the value at the provided index', () => {
|
|
12
|
-
expect((0, array_1.without)([], -1)).toEqual([]);
|
|
13
|
-
expect((0, array_1.without)([], 0)).toEqual([]);
|
|
14
|
-
expect((0, array_1.without)(['a', 'b', 'c', 'd'], -1)).toEqual(['a', 'b', 'c', 'd']);
|
|
15
|
-
expect((0, array_1.without)(['a', 'b', 'c', 'd'], 0)).toEqual(['b', 'c', 'd']);
|
|
16
|
-
expect((0, array_1.without)(['a', 'b', 'c', 'd'], 2)).toEqual(['a', 'b', 'd']);
|
|
17
|
-
expect((0, array_1.without)(['a', 'b', 'c', 'd'], 4)).toEqual(['a', 'b', 'c', 'd']);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
describe('withoutValue()', () => {
|
|
21
|
-
it('return an array containing every value from the array passed to it except for first value that is directly equal to the provided value', () => {
|
|
22
|
-
expect((0, array_1.withoutValue)([], 'd')).toEqual([]);
|
|
23
|
-
expect((0, array_1.withoutValue)(['a', 'b', 'c', 'd'], 'g')).toEqual(['a', 'b', 'c', 'd']);
|
|
24
|
-
expect((0, array_1.withoutValue)(['a', 'b', 'c', 'd'], 'b')).toEqual(['a', 'c', 'd']);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
describe('withoutValues()', () => {
|
|
28
|
-
it('return an array containing every value from the array passed to it except for values from a second provided array', () => {
|
|
29
|
-
expect((0, array_1.withoutValues)(['a', 'b', 'c', 'd'], [])).toEqual(['a', 'b', 'c', 'd']);
|
|
30
|
-
expect((0, array_1.withoutValues)([], ['g', 'c', 'b', 'e'])).toEqual([]);
|
|
31
|
-
expect((0, array_1.withoutValues)(['a', 'b', 'c', 'd'], ['g', 'c', 'b', 5])).toEqual(['a', 'd']);
|
|
32
|
-
expect((0, array_1.withoutValues)(['a', 'b', 'c', 'd'], ['g', 'e'])).toEqual(['a', 'b', 'c', 'd']);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
describe('replace()', () => {
|
|
36
|
-
it('return an array where the value at the provided index has been replaced with the new value', () => {
|
|
37
|
-
expect((0, array_1.insert)([], 8, 'f')).toEqual(['f']);
|
|
38
|
-
expect((0, array_1.replace)(['a', 'b', 'c', 'd'], -1, 'f')).toEqual(['a', 'b', 'c', 'd']);
|
|
39
|
-
expect((0, array_1.replace)(['a', 'b', 'c', 'd'], 8, 'f')).toEqual(['a', 'b', 'c', 'd', 'f']);
|
|
40
|
-
expect((0, array_1.replace)(['a', 'b', 'c', 'd'], 2, 'f')).toEqual(['a', 'b', 'f', 'd']);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
describe('insert()', () => {
|
|
44
|
-
it('return an array where the provided value has been inserted at the provided index', () => {
|
|
45
|
-
expect((0, array_1.insert)([], 8, 'f')).toEqual(['f']);
|
|
46
|
-
expect((0, array_1.insert)(['a', 'b', 'c', 'd'], -1, 'f')).toEqual(['f', 'a', 'b', 'c', 'd']);
|
|
47
|
-
expect((0, array_1.insert)(['a', 'b', 'c', 'd'], 2, 'f')).toEqual(['a', 'b', 'f', 'c', 'd']);
|
|
48
|
-
expect((0, array_1.insert)(['a', 'b', 'c', 'd'], 8, 'f')).toEqual(['a', 'b', 'c', 'd', 'f']);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
describe('insertAll()', () => {
|
|
52
|
-
it('return an array where the provided array of values has been inserted at the provided index', () => {
|
|
53
|
-
expect((0, array_1.insertAll)([], 8, ['f', 'g', 'h'])).toEqual(['f', 'g', 'h']);
|
|
54
|
-
expect((0, array_1.insertAll)(['a', 'b', 'c', 'd'], -1, ['f', 'g', 'h'])).toEqual(['f', 'g', 'h', 'a', 'b', 'c', 'd']);
|
|
55
|
-
expect((0, array_1.insertAll)(['a', 'b', 'c', 'd'], 2, ['f', 'g', 'h'])).toEqual(['a', 'b', 'f', 'g', 'h', 'c', 'd']);
|
|
56
|
-
expect((0, array_1.insertAll)(['a', 'b', 'c', 'd'], 8, ['f', 'g', 'h'])).toEqual(['a', 'b', 'c', 'd', 'f', 'g', 'h']);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
describe('append()', () => {
|
|
60
|
-
it('return an array with the provided value appended, does not add if already exists', () => {
|
|
61
|
-
expect((0, array_1.append)([], 'f')).toEqual(['f']);
|
|
62
|
-
expect((0, array_1.append)(['a', 'b', 'c', 'd'], 'f')).toEqual(['a', 'b', 'c', 'd', 'f']);
|
|
63
|
-
expect((0, array_1.append)(['a', 'b', 'c'], 'c')).toEqual(['a', 'b', 'c']);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
describe('toggleMembership()', () => {
|
|
67
|
-
it('return an array with the provided value included or excluded, the opposite of the current state', () => {
|
|
68
|
-
expect((0, array_1.toggleMembership)(['a', 'b', 'c'], 'f')).toEqual(['a', 'b', 'c', 'f']);
|
|
69
|
-
expect((0, array_1.toggleMembership)(['a', 'b', 'c', 'f'], 'f')).toEqual(['a', 'b', 'c']);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
describe('head()', () => {
|
|
73
|
-
it('return the item at the head of the array and an array containing the remaining elements as a tuple pair', () => {
|
|
74
|
-
expect((0, array_1.head)(['a', 'b', 'c', 'd'])).toEqual(['a', ['b', 'c', 'd']]);
|
|
75
|
-
expect((0, array_1.head)(['a'])).toEqual(['a', []]);
|
|
76
|
-
expect((0, array_1.head)([])).toEqual([undefined, []]);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
describe('tail()', () => {
|
|
80
|
-
it('return the item at the end of the array and an array containing the remaining elements as a tuple pair', () => {
|
|
81
|
-
expect((0, array_1.tail)(['a', 'b', 'c', 'd'])).toEqual([['a', 'b', 'c'], 'd']);
|
|
82
|
-
expect((0, array_1.tail)(['a'])).toEqual([[], 'a']);
|
|
83
|
-
expect((0, array_1.tail)([])).toEqual([[], undefined]);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
describe('filterOutNullish()', () => {
|
|
87
|
-
it('filters nullish values', () => {
|
|
88
|
-
expect((0, array_1.filterOutNullish)([undefined, 1, null])).toEqual([1]);
|
|
89
|
-
expect((0, array_1.filterOutNullish)([undefined, null])).toEqual([]);
|
|
90
|
-
expect((0, array_1.filterOutNullish)([1])).toEqual([1]);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
describe('isNullish()', () => {
|
|
94
|
-
it('works', () => {
|
|
95
|
-
expect((0, array_1.isNullish)(null)).toBe(true);
|
|
96
|
-
expect((0, array_1.isNullish)(undefined)).toBe(true);
|
|
97
|
-
expect((0, array_1.isNullish)(0)).toBe(false);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
describe('isNotNullish()', () => {
|
|
101
|
-
it('works', () => {
|
|
102
|
-
expect((0, array_1.isNotNullish)(null)).toBe(false);
|
|
103
|
-
expect((0, array_1.isNotNullish)(undefined)).toBe(false);
|
|
104
|
-
expect((0, array_1.isNotNullish)(0)).toBe(true);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
describe('toArray()', () => {
|
|
108
|
-
it('works with arrays', () => {
|
|
109
|
-
const value = [1];
|
|
110
|
-
expect((0, array_1.toArray)(value)).toEqual([1]);
|
|
111
|
-
});
|
|
112
|
-
it('works with non-arrays', () => {
|
|
113
|
-
const value = 1;
|
|
114
|
-
expect((0, array_1.toArray)(value)).toEqual([1]);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
describe('reorder()', () => {
|
|
118
|
-
it('should do nothing if from index goes outside array', () => {
|
|
119
|
-
const array = [1, 2, 3];
|
|
120
|
-
expect((0, array_1.reorder)(array, -1, 1)).toEqual(array);
|
|
121
|
-
expect((0, array_1.reorder)(array, 3, 1)).toEqual(array);
|
|
122
|
-
});
|
|
123
|
-
it('should set as first item if toIndex is zero or lower than 0', () => {
|
|
124
|
-
const array = [1, 2, 3];
|
|
125
|
-
expect((0, array_1.reorder)(array, 2, -1)).toEqual([3, 1, 2]);
|
|
126
|
-
expect((0, array_1.reorder)(array, 2, 0)).toEqual([3, 1, 2]);
|
|
127
|
-
});
|
|
128
|
-
it('should set as last item if toIndex is the last or greater than last', () => {
|
|
129
|
-
const array = [1, 2, 3];
|
|
130
|
-
expect((0, array_1.reorder)(array, 0, 2)).toEqual([2, 3, 1]);
|
|
131
|
-
expect((0, array_1.reorder)(array, 0, 3)).toEqual([2, 3, 1]);
|
|
132
|
-
});
|
|
133
|
-
it('should reorder moving forward or backward', () => {
|
|
134
|
-
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
135
|
-
expect((0, array_1.reorder)(array, 1, 2)).toEqual([1, 3, 2, 4, 5, 6, 7, 8, 9, 10]);
|
|
136
|
-
expect((0, array_1.reorder)(array, 2, 3)).toEqual([1, 2, 4, 3, 5, 6, 7, 8, 9, 10]);
|
|
137
|
-
expect((0, array_1.reorder)(array, 2, 8)).toEqual([1, 2, 4, 5, 6, 7, 8, 9, 3, 10]);
|
|
138
|
-
expect((0, array_1.reorder)(array, 8, 1)).toEqual([1, 9, 2, 3, 4, 5, 6, 7, 8, 10]);
|
|
139
|
-
expect((0, array_1.reorder)(array, 7, 2)).toEqual([1, 2, 8, 3, 4, 5, 6, 7, 9, 10]);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
describe('separate()', () => {
|
|
143
|
-
it('separates items that pass and fail a predicate', () => {
|
|
144
|
-
const [passes, fails] = (0, array_1.separate)([20, 1, -3, 15, 8, 23, 40, 3], (x) => x > 10);
|
|
145
|
-
expect(passes).toEqual([20, 15, 23, 40]);
|
|
146
|
-
expect(fails).toEqual([1, -3, 8, 3]);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
describe('createEntries()', () => {
|
|
150
|
-
it('creates entries by extracting a key for each item in an array', () => {
|
|
151
|
-
const entries = (0, array_1.createEntries)([{ index: 1 }, { index: 3 }, { index: 5 }], ({ index }) => String(index));
|
|
152
|
-
expect(entries).toEqual([
|
|
153
|
-
['1', { index: 1 }],
|
|
154
|
-
['3', { index: 3 }],
|
|
155
|
-
['5', { index: 5 }],
|
|
156
|
-
]);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
describe('createMap()', () => {
|
|
160
|
-
it('creates object by extracting a key for each item in an array', () => {
|
|
161
|
-
const obj = (0, array_1.createMap)([{ index: 1 }, { index: 3 }, { index: 5 }], ({ index }) => String(index));
|
|
162
|
-
expect(obj).toEqual({
|
|
163
|
-
1: { index: 1 },
|
|
164
|
-
3: { index: 3 },
|
|
165
|
-
5: { index: 5 },
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
describe('findUnion()', () => {
|
|
170
|
-
it('finds the overlap between two lists', () => {
|
|
171
|
-
const { lhsOnly, rhsOnly, union } = (0, array_1.findUnion)([20, 1, -3, 15], [1, 8, 23, -3, 40, 3]);
|
|
172
|
-
expect(lhsOnly).toEqual([20, 15]);
|
|
173
|
-
expect(rhsOnly).toEqual([8, 23, 40, 3]);
|
|
174
|
-
expect(union).toEqual([1, -3]);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
describe('diff()', () => {
|
|
178
|
-
it('finds items that only occur in one of two lists', () => {
|
|
179
|
-
expect((0, array_1.diff)([20, 1, -3, 15], [1, 8, 23, -3, 40, 3])).toEqual([20, 15, 8, 23, 40, 3]);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
describe('hasIdenticalMembers()', () => {
|
|
183
|
-
it('returns false if lists have different lengths', () => {
|
|
184
|
-
expect((0, array_1.hasIdenticalMembers)([1, 2, 3], [3, 3, 2, 2, 1])).toBe(false);
|
|
185
|
-
});
|
|
186
|
-
it('returns false if either list has a unique member', () => {
|
|
187
|
-
expect((0, array_1.hasIdenticalMembers)([1, 2, 3], [2, 3])).toBe(false);
|
|
188
|
-
});
|
|
189
|
-
it('returns true if both lists contain the same members', () => {
|
|
190
|
-
expect((0, array_1.hasIdenticalMembers)([1, 2, 3], [3, 1, 2])).toBe(true);
|
|
191
|
-
});
|
|
192
|
-
it('returns true if both lists are empty', () => {
|
|
193
|
-
expect((0, array_1.hasIdenticalMembers)([], [])).toBe(true);
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
describe('filterAndGetLastRemovedValue()', () => {
|
|
197
|
-
it('returns the last item which did not pass the filter predicate', () => {
|
|
198
|
-
expect((0, array_1.filterAndGetLastRemovedValue)([1, 2, 3], () => true)).toEqual([[1, 2, 3], null]);
|
|
199
|
-
expect((0, array_1.filterAndGetLastRemovedValue)([], () => false)).toEqual([[], null]);
|
|
200
|
-
expect((0, array_1.filterAndGetLastRemovedValue)([1, 2, 3], (x) => x !== 2)).toEqual([[1, 3], 2]);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
describe('mergeByIdentifier()', () => {
|
|
204
|
-
it('test', () => {
|
|
205
|
-
const array1 = [
|
|
206
|
-
{
|
|
207
|
-
key: 1,
|
|
208
|
-
value: [1, 2],
|
|
209
|
-
},
|
|
210
|
-
];
|
|
211
|
-
const array2 = [
|
|
212
|
-
{
|
|
213
|
-
key: 1,
|
|
214
|
-
value: [3],
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
key: 2,
|
|
218
|
-
value: [4, 5],
|
|
219
|
-
},
|
|
220
|
-
];
|
|
221
|
-
const result = (0, array_1.mergeByIdentifier)(array1, array2, (x) => x.key.toString(), (a, b) => ({
|
|
222
|
-
...a,
|
|
223
|
-
value: [...a.value, ...b.value],
|
|
224
|
-
}));
|
|
225
|
-
expect(result).toEqual([
|
|
226
|
-
{
|
|
227
|
-
key: 1,
|
|
228
|
-
value: [1, 2, 3],
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
key: 2,
|
|
232
|
-
value: [4, 5],
|
|
233
|
-
},
|
|
234
|
-
]);
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"email.test.d.ts","sourceRoot":"","sources":["../../../src/utils/email.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const emails_1 = require("./emails");
|
|
4
|
-
describe('Utils | email', () => {
|
|
5
|
-
describe('isValid()', () => {
|
|
6
|
-
it('should be valid', () => {
|
|
7
|
-
const validEmails = ['joe.doe@test.com', 'john.-last@sub.domain.com', 'test+@voiceflow.com', 't-est+34@voice-flow.com'];
|
|
8
|
-
validEmails.forEach((email) => expect((0, emails_1.isValidEmail)(email)).toBe(true));
|
|
9
|
-
});
|
|
10
|
-
it('should be invalid', () => {
|
|
11
|
-
const invalidEmails = ['joe@.com', 'joe@', '@voiceflow.com', '', 'voiceflow.com'];
|
|
12
|
-
invalidEmails.forEach((email) => expect((0, emails_1.isValidEmail)(email)).toBe(false));
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
describe('getEmailDomain()', () => {
|
|
16
|
-
it('works', () => {
|
|
17
|
-
expect((0, emails_1.getEmailDomain)('test@voiceflow.com')).toBe('voiceflow.com');
|
|
18
|
-
expect((0, emails_1.getEmailDomain)('')).toBe('');
|
|
19
|
-
expect((0, emails_1.getEmailDomain)('totally@invalid@voiceflow.com')).toBe('voiceflow.com');
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"functional.test.d.ts","sourceRoot":"","sources":["../../../src/utils/functional.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const functional_1 = require("./functional");
|
|
4
|
-
const promise_1 = require("./promise");
|
|
5
|
-
describe('Utils | functional', () => {
|
|
6
|
-
describe('isFunction()', () => {
|
|
7
|
-
it('checks if the provided argument is a function', () => {
|
|
8
|
-
expect((0, functional_1.isFunction)(null)).toBe(false);
|
|
9
|
-
expect((0, functional_1.isFunction)({})).toBe(false);
|
|
10
|
-
expect((0, functional_1.isFunction)(() => null)).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
describe('compose()', () => {
|
|
14
|
-
it('composes from right-to-left', () => {
|
|
15
|
-
const add = (x) => x + 1;
|
|
16
|
-
const div = (x) => x / 3;
|
|
17
|
-
const mult = (x) => x * 2;
|
|
18
|
-
expect((0, functional_1.compose)(mult, div, add)(5)).toBe(4);
|
|
19
|
-
expect((0, functional_1.compose)(add, mult, div)(9)).toBe(7);
|
|
20
|
-
expect((0, functional_1.compose)(mult, add)(6)).toBe(14);
|
|
21
|
-
expect((0, functional_1.compose)(mult)(6)).toBe(12);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
describe('noop()', () => {
|
|
25
|
-
it('does nothing', () => {
|
|
26
|
-
expect((0, functional_1.noop)()).toBeUndefined();
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
describe('identity()', () => {
|
|
30
|
-
it('returns the input', () => {
|
|
31
|
-
const input = () => null;
|
|
32
|
-
expect((0, functional_1.identity)(input)).toEqual(input);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
describe('stringify()', () => {
|
|
36
|
-
it('returns the input as a string', () => {
|
|
37
|
-
expect((0, functional_1.stringify)('foo')).toBe('foo');
|
|
38
|
-
expect((0, functional_1.stringify)(123)).toBe('123');
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
describe('chain()', () => {
|
|
42
|
-
it('chains multiple function calls from left to right', () => {
|
|
43
|
-
let result = 5;
|
|
44
|
-
const outerArgs = ['a', false, -3];
|
|
45
|
-
const add = (...args) => {
|
|
46
|
-
expect(args).toEqual(outerArgs);
|
|
47
|
-
result += 1;
|
|
48
|
-
};
|
|
49
|
-
const div = (...args) => {
|
|
50
|
-
expect(args).toEqual(outerArgs);
|
|
51
|
-
result /= 3;
|
|
52
|
-
};
|
|
53
|
-
const mult = (...args) => {
|
|
54
|
-
expect(args).toEqual(outerArgs);
|
|
55
|
-
result *= 2;
|
|
56
|
-
};
|
|
57
|
-
(0, functional_1.chain)(add, div, mult)(...outerArgs);
|
|
58
|
-
expect(result).toBe(4);
|
|
59
|
-
result = 5;
|
|
60
|
-
(0, functional_1.chain)(add, mult)(...outerArgs);
|
|
61
|
-
expect(result).toBe(12);
|
|
62
|
-
result = 5;
|
|
63
|
-
(0, functional_1.chain)(add)(...outerArgs);
|
|
64
|
-
expect(result).toBe(6);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
describe('chainVoid()', () => {
|
|
68
|
-
it('chains multiple function calls from left to right', () => {
|
|
69
|
-
let result = 5;
|
|
70
|
-
const add = () => {
|
|
71
|
-
result += 1;
|
|
72
|
-
};
|
|
73
|
-
const div = () => {
|
|
74
|
-
result /= 3;
|
|
75
|
-
};
|
|
76
|
-
const mult = () => {
|
|
77
|
-
result *= 2;
|
|
78
|
-
};
|
|
79
|
-
(0, functional_1.chainVoid)(add, div, mult)();
|
|
80
|
-
expect(result).toBe(4);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
describe('chainAsync()', () => {
|
|
84
|
-
it('chains multiple async function calls in sequence from left to right', async () => {
|
|
85
|
-
let result = 5;
|
|
86
|
-
const outerArgs = ['a', false, -3];
|
|
87
|
-
const add = async (...args) => {
|
|
88
|
-
expect(args).toEqual(outerArgs);
|
|
89
|
-
await (0, promise_1.delay)(1);
|
|
90
|
-
result += 1;
|
|
91
|
-
};
|
|
92
|
-
const div = async (...args) => {
|
|
93
|
-
expect(args).toEqual(outerArgs);
|
|
94
|
-
await (0, promise_1.delay)(1);
|
|
95
|
-
result /= 3;
|
|
96
|
-
};
|
|
97
|
-
const mult = async (...args) => {
|
|
98
|
-
expect(args).toEqual(outerArgs);
|
|
99
|
-
await (0, promise_1.delay)(1);
|
|
100
|
-
result *= 2;
|
|
101
|
-
};
|
|
102
|
-
await (0, functional_1.chainAsync)(add, div, mult)(...outerArgs);
|
|
103
|
-
expect(result).toBe(4);
|
|
104
|
-
result = 5;
|
|
105
|
-
await (0, functional_1.chainAsync)(add, mult)(...outerArgs);
|
|
106
|
-
expect(result).toBe(12);
|
|
107
|
-
result = 5;
|
|
108
|
-
await (0, functional_1.chainAsync)(add)(...outerArgs);
|
|
109
|
-
expect(result).toBe(6);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
describe('chainVoidAsync()', () => {
|
|
113
|
-
it('chains multiple async function calls in sequence from left to right', async () => {
|
|
114
|
-
let result = 5;
|
|
115
|
-
const add = async () => {
|
|
116
|
-
await (0, promise_1.delay)(1);
|
|
117
|
-
result += 1;
|
|
118
|
-
};
|
|
119
|
-
const div = async () => {
|
|
120
|
-
await (0, promise_1.delay)(1);
|
|
121
|
-
result /= 3;
|
|
122
|
-
};
|
|
123
|
-
const mult = async () => {
|
|
124
|
-
await (0, promise_1.delay)(1);
|
|
125
|
-
result *= 2;
|
|
126
|
-
};
|
|
127
|
-
await (0, functional_1.chainVoidAsync)(add, div, mult)();
|
|
128
|
-
expect(result).toBe(4);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
describe('withEffect()', () => {
|
|
132
|
-
it('apply effect to a value and return the value', () => {
|
|
133
|
-
const input = 4;
|
|
134
|
-
const spy = jest.fn();
|
|
135
|
-
(0, functional_1.withEffect)(spy)(input);
|
|
136
|
-
expect(spy).toHaveBeenCalledWith(4);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|