@voiceflow/common 8.2.7 → 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.
Files changed (188) hide show
  1. package/build/cjs/constants/environment.js +1 -1
  2. package/build/cjs/constants/regexp.d.ts +5 -5
  3. package/build/cjs/constants/regexp.d.ts.map +1 -1
  4. package/build/cjs/crypto/hex2abc.d.ts.map +1 -1
  5. package/build/cjs/types.d.ts +26 -26
  6. package/build/cjs/types.d.ts.map +1 -1
  7. package/build/cjs/utils/array.d.ts +3 -3
  8. package/build/cjs/utils/array.d.ts.map +1 -1
  9. package/build/cjs/utils/array.js +2 -3
  10. package/build/cjs/utils/emails.d.ts.map +1 -1
  11. package/build/cjs/utils/functional.d.ts +4 -4
  12. package/build/cjs/utils/functional.d.ts.map +1 -1
  13. package/build/cjs/utils/functional.js +0 -1
  14. package/build/cjs/utils/id.d.ts +1 -1
  15. package/build/cjs/utils/id.d.ts.map +1 -1
  16. package/build/cjs/utils/intent.d.ts +6 -6
  17. package/build/cjs/utils/intent.d.ts.map +1 -1
  18. package/build/cjs/utils/intent.js +4 -2
  19. package/build/cjs/utils/mathjs.js +1 -1
  20. package/build/cjs/utils/normalized.d.ts +5 -5
  21. package/build/cjs/utils/normalized.d.ts.map +1 -1
  22. package/build/cjs/utils/number.d.ts.map +1 -1
  23. package/build/cjs/utils/object/common.d.ts +1 -1
  24. package/build/cjs/utils/object/common.d.ts.map +1 -1
  25. package/build/cjs/utils/object/deepMap.d.ts +1 -1
  26. package/build/cjs/utils/object/deepMap.d.ts.map +1 -1
  27. package/build/cjs/utils/object/deepMap.js +0 -2
  28. package/build/cjs/utils/object/diff.d.ts +1 -1
  29. package/build/cjs/utils/object/diff.d.ts.map +1 -1
  30. package/build/cjs/utils/object/keys.d.ts +2 -1
  31. package/build/cjs/utils/object/keys.d.ts.map +1 -1
  32. package/build/cjs/utils/promise.d.ts.map +1 -1
  33. package/build/cjs/utils/protocol.d.ts +2 -2
  34. package/build/cjs/utils/protocol.d.ts.map +1 -1
  35. package/build/cjs/utils/slot.d.ts.map +1 -1
  36. package/build/cjs/utils/typeguard.d.ts +2 -2
  37. package/build/cjs/utils/typeguard.d.ts.map +1 -1
  38. package/build/cjs/utils/variables.d.ts +2 -2
  39. package/build/cjs/utils/variables.d.ts.map +1 -1
  40. package/build/esm/constants/regexp.d.ts +5 -5
  41. package/build/esm/constants/regexp.d.ts.map +1 -1
  42. package/build/esm/crypto/hex2abc.d.ts.map +1 -1
  43. package/build/esm/types.d.ts +26 -26
  44. package/build/esm/types.d.ts.map +1 -1
  45. package/build/esm/utils/array.d.ts +3 -3
  46. package/build/esm/utils/array.d.ts.map +1 -1
  47. package/build/esm/utils/array.js +2 -3
  48. package/build/esm/utils/emails.d.ts.map +1 -1
  49. package/build/esm/utils/functional.d.ts +4 -4
  50. package/build/esm/utils/functional.d.ts.map +1 -1
  51. package/build/esm/utils/functional.js +0 -1
  52. package/build/esm/utils/id.d.ts +1 -1
  53. package/build/esm/utils/id.d.ts.map +1 -1
  54. package/build/esm/utils/intent.d.ts +6 -6
  55. package/build/esm/utils/intent.d.ts.map +1 -1
  56. package/build/esm/utils/intent.js +4 -2
  57. package/build/esm/utils/mathjs.js +1 -1
  58. package/build/esm/utils/normalized.d.ts +5 -5
  59. package/build/esm/utils/normalized.d.ts.map +1 -1
  60. package/build/esm/utils/number.d.ts.map +1 -1
  61. package/build/esm/utils/object/common.d.ts +1 -1
  62. package/build/esm/utils/object/common.d.ts.map +1 -1
  63. package/build/esm/utils/object/deepMap.d.ts +1 -1
  64. package/build/esm/utils/object/deepMap.d.ts.map +1 -1
  65. package/build/esm/utils/object/deepMap.js +0 -2
  66. package/build/esm/utils/object/diff.d.ts +1 -1
  67. package/build/esm/utils/object/diff.d.ts.map +1 -1
  68. package/build/esm/utils/object/keys.d.ts +2 -1
  69. package/build/esm/utils/object/keys.d.ts.map +1 -1
  70. package/build/esm/utils/promise.d.ts.map +1 -1
  71. package/build/esm/utils/protocol.d.ts +2 -2
  72. package/build/esm/utils/protocol.d.ts.map +1 -1
  73. package/build/esm/utils/slot.d.ts.map +1 -1
  74. package/build/esm/utils/typeguard.d.ts +2 -2
  75. package/build/esm/utils/typeguard.d.ts.map +1 -1
  76. package/build/esm/utils/variables.d.ts +2 -2
  77. package/build/esm/utils/variables.d.ts.map +1 -1
  78. package/package.json +48 -47
  79. package/build/cjs/crypto/hex2abc.test.d.ts +0 -2
  80. package/build/cjs/crypto/hex2abc.test.d.ts.map +0 -1
  81. package/build/cjs/crypto/hex2abc.test.js +0 -12
  82. package/build/cjs/crypto/murmurhash.test.d.ts +0 -2
  83. package/build/cjs/crypto/murmurhash.test.d.ts.map +0 -1
  84. package/build/cjs/crypto/murmurhash.test.js +0 -23
  85. package/build/cjs/utils/__fixtures__/name.json +0 -64
  86. package/build/cjs/utils/array.test.d.ts +0 -2
  87. package/build/cjs/utils/array.test.d.ts.map +0 -1
  88. package/build/cjs/utils/array.test.js +0 -237
  89. package/build/cjs/utils/email.test.d.ts +0 -2
  90. package/build/cjs/utils/email.test.d.ts.map +0 -1
  91. package/build/cjs/utils/email.test.js +0 -22
  92. package/build/cjs/utils/functional.test.d.ts +0 -2
  93. package/build/cjs/utils/functional.test.d.ts.map +0 -1
  94. package/build/cjs/utils/functional.test.js +0 -139
  95. package/build/cjs/utils/id.test.d.ts +0 -2
  96. package/build/cjs/utils/id.test.d.ts.map +0 -1
  97. package/build/cjs/utils/id.test.js +0 -66
  98. package/build/cjs/utils/intent.test.d.ts +0 -2
  99. package/build/cjs/utils/intent.test.d.ts.map +0 -1
  100. package/build/cjs/utils/intent.test.js +0 -100
  101. package/build/cjs/utils/map.test.d.ts +0 -2
  102. package/build/cjs/utils/map.test.d.ts.map +0 -1
  103. package/build/cjs/utils/map.test.js +0 -22
  104. package/build/cjs/utils/object/common.test.d.ts +0 -2
  105. package/build/cjs/utils/object/common.test.d.ts.map +0 -1
  106. package/build/cjs/utils/object/common.test.js +0 -175
  107. package/build/cjs/utils/object/deepMap.test.d.ts +0 -2
  108. package/build/cjs/utils/object/deepMap.test.d.ts.map +0 -1
  109. package/build/cjs/utils/object/deepMap.test.js +0 -114
  110. package/build/cjs/utils/object/diff.test.d.ts +0 -2
  111. package/build/cjs/utils/object/diff.test.d.ts.map +0 -1
  112. package/build/cjs/utils/object/diff.test.js +0 -19
  113. package/build/cjs/utils/object/keys.test.d.ts +0 -2
  114. package/build/cjs/utils/object/keys.test.d.ts.map +0 -1
  115. package/build/cjs/utils/object/keys.test.js +0 -15
  116. package/build/cjs/utils/promise.test.d.ts +0 -2
  117. package/build/cjs/utils/promise.test.d.ts.map +0 -1
  118. package/build/cjs/utils/promise.test.js +0 -25
  119. package/build/cjs/utils/protocol.test.d.ts +0 -2
  120. package/build/cjs/utils/protocol.test.d.ts.map +0 -1
  121. package/build/cjs/utils/protocol.test.js +0 -40
  122. package/build/cjs/utils/slot.test.d.ts +0 -2
  123. package/build/cjs/utils/slot.test.d.ts.map +0 -1
  124. package/build/cjs/utils/slot.test.js +0 -38
  125. package/build/cjs/utils/string.test.d.ts +0 -2
  126. package/build/cjs/utils/string.test.d.ts.map +0 -1
  127. package/build/cjs/utils/string.test.js +0 -53
  128. package/build/cjs/utils/timezones.test.d.ts +0 -2
  129. package/build/cjs/utils/timezones.test.d.ts.map +0 -1
  130. package/build/cjs/utils/timezones.test.js +0 -12
  131. package/build/cjs/utils/typeguard.test.d.ts +0 -2
  132. package/build/cjs/utils/typeguard.test.d.ts.map +0 -1
  133. package/build/cjs/utils/typeguard.test.js +0 -55
  134. package/build/esm/crypto/hex2abc.test.d.ts +0 -2
  135. package/build/esm/crypto/hex2abc.test.d.ts.map +0 -1
  136. package/build/esm/crypto/hex2abc.test.js +0 -10
  137. package/build/esm/crypto/murmurhash.test.d.ts +0 -2
  138. package/build/esm/crypto/murmurhash.test.d.ts.map +0 -1
  139. package/build/esm/crypto/murmurhash.test.js +0 -21
  140. package/build/esm/utils/__fixtures__/name.json +0 -64
  141. package/build/esm/utils/array.test.d.ts +0 -2
  142. package/build/esm/utils/array.test.d.ts.map +0 -1
  143. package/build/esm/utils/array.test.js +0 -235
  144. package/build/esm/utils/email.test.d.ts +0 -2
  145. package/build/esm/utils/email.test.d.ts.map +0 -1
  146. package/build/esm/utils/email.test.js +0 -20
  147. package/build/esm/utils/functional.test.d.ts +0 -2
  148. package/build/esm/utils/functional.test.d.ts.map +0 -1
  149. package/build/esm/utils/functional.test.js +0 -137
  150. package/build/esm/utils/id.test.d.ts +0 -2
  151. package/build/esm/utils/id.test.d.ts.map +0 -1
  152. package/build/esm/utils/id.test.js +0 -64
  153. package/build/esm/utils/intent.test.d.ts +0 -2
  154. package/build/esm/utils/intent.test.d.ts.map +0 -1
  155. package/build/esm/utils/intent.test.js +0 -75
  156. package/build/esm/utils/map.test.d.ts +0 -2
  157. package/build/esm/utils/map.test.d.ts.map +0 -1
  158. package/build/esm/utils/map.test.js +0 -20
  159. package/build/esm/utils/object/common.test.d.ts +0 -2
  160. package/build/esm/utils/object/common.test.d.ts.map +0 -1
  161. package/build/esm/utils/object/common.test.js +0 -173
  162. package/build/esm/utils/object/deepMap.test.d.ts +0 -2
  163. package/build/esm/utils/object/deepMap.test.d.ts.map +0 -1
  164. package/build/esm/utils/object/deepMap.test.js +0 -109
  165. package/build/esm/utils/object/diff.test.d.ts +0 -2
  166. package/build/esm/utils/object/diff.test.d.ts.map +0 -1
  167. package/build/esm/utils/object/diff.test.js +0 -17
  168. package/build/esm/utils/object/keys.test.d.ts +0 -2
  169. package/build/esm/utils/object/keys.test.d.ts.map +0 -1
  170. package/build/esm/utils/object/keys.test.js +0 -13
  171. package/build/esm/utils/promise.test.d.ts +0 -2
  172. package/build/esm/utils/promise.test.d.ts.map +0 -1
  173. package/build/esm/utils/promise.test.js +0 -23
  174. package/build/esm/utils/protocol.test.d.ts +0 -2
  175. package/build/esm/utils/protocol.test.d.ts.map +0 -1
  176. package/build/esm/utils/protocol.test.js +0 -38
  177. package/build/esm/utils/slot.test.d.ts +0 -2
  178. package/build/esm/utils/slot.test.d.ts.map +0 -1
  179. package/build/esm/utils/slot.test.js +0 -13
  180. package/build/esm/utils/string.test.d.ts +0 -2
  181. package/build/esm/utils/string.test.d.ts.map +0 -1
  182. package/build/esm/utils/string.test.js +0 -51
  183. package/build/esm/utils/timezones.test.d.ts +0 -2
  184. package/build/esm/utils/timezones.test.d.ts.map +0 -1
  185. package/build/esm/utils/timezones.test.js +0 -10
  186. package/build/esm/utils/typeguard.test.d.ts +0 -2
  187. package/build/esm/utils/typeguard.test.d.ts.map +0 -1
  188. package/build/esm/utils/typeguard.test.js +0 -53
@@ -1,137 +0,0 @@
1
- import { chain, chainAsync, chainVoid, chainVoidAsync, compose, identity, isFunction, noop, stringify, withEffect } from './functional.js';
2
- import { delay } from './promise.js';
3
- describe('Utils | functional', () => {
4
- describe('isFunction()', () => {
5
- it('checks if the provided argument is a function', () => {
6
- expect(isFunction(null)).toBe(false);
7
- expect(isFunction({})).toBe(false);
8
- expect(isFunction(() => null)).toBe(true);
9
- });
10
- });
11
- describe('compose()', () => {
12
- it('composes from right-to-left', () => {
13
- const add = (x) => x + 1;
14
- const div = (x) => x / 3;
15
- const mult = (x) => x * 2;
16
- expect(compose(mult, div, add)(5)).toBe(4);
17
- expect(compose(add, mult, div)(9)).toBe(7);
18
- expect(compose(mult, add)(6)).toBe(14);
19
- expect(compose(mult)(6)).toBe(12);
20
- });
21
- });
22
- describe('noop()', () => {
23
- it('does nothing', () => {
24
- expect(noop()).toBeUndefined();
25
- });
26
- });
27
- describe('identity()', () => {
28
- it('returns the input', () => {
29
- const input = () => null;
30
- expect(identity(input)).toEqual(input);
31
- });
32
- });
33
- describe('stringify()', () => {
34
- it('returns the input as a string', () => {
35
- expect(stringify('foo')).toBe('foo');
36
- expect(stringify(123)).toBe('123');
37
- });
38
- });
39
- describe('chain()', () => {
40
- it('chains multiple function calls from left to right', () => {
41
- let result = 5;
42
- const outerArgs = ['a', false, -3];
43
- const add = (...args) => {
44
- expect(args).toEqual(outerArgs);
45
- result += 1;
46
- };
47
- const div = (...args) => {
48
- expect(args).toEqual(outerArgs);
49
- result /= 3;
50
- };
51
- const mult = (...args) => {
52
- expect(args).toEqual(outerArgs);
53
- result *= 2;
54
- };
55
- chain(add, div, mult)(...outerArgs);
56
- expect(result).toBe(4);
57
- result = 5;
58
- chain(add, mult)(...outerArgs);
59
- expect(result).toBe(12);
60
- result = 5;
61
- chain(add)(...outerArgs);
62
- expect(result).toBe(6);
63
- });
64
- });
65
- describe('chainVoid()', () => {
66
- it('chains multiple function calls from left to right', () => {
67
- let result = 5;
68
- const add = () => {
69
- result += 1;
70
- };
71
- const div = () => {
72
- result /= 3;
73
- };
74
- const mult = () => {
75
- result *= 2;
76
- };
77
- chainVoid(add, div, mult)();
78
- expect(result).toBe(4);
79
- });
80
- });
81
- describe('chainAsync()', () => {
82
- it('chains multiple async function calls in sequence from left to right', async () => {
83
- let result = 5;
84
- const outerArgs = ['a', false, -3];
85
- const add = async (...args) => {
86
- expect(args).toEqual(outerArgs);
87
- await delay(1);
88
- result += 1;
89
- };
90
- const div = async (...args) => {
91
- expect(args).toEqual(outerArgs);
92
- await delay(1);
93
- result /= 3;
94
- };
95
- const mult = async (...args) => {
96
- expect(args).toEqual(outerArgs);
97
- await delay(1);
98
- result *= 2;
99
- };
100
- await chainAsync(add, div, mult)(...outerArgs);
101
- expect(result).toBe(4);
102
- result = 5;
103
- await chainAsync(add, mult)(...outerArgs);
104
- expect(result).toBe(12);
105
- result = 5;
106
- await chainAsync(add)(...outerArgs);
107
- expect(result).toBe(6);
108
- });
109
- });
110
- describe('chainVoidAsync()', () => {
111
- it('chains multiple async function calls in sequence from left to right', async () => {
112
- let result = 5;
113
- const add = async () => {
114
- await delay(1);
115
- result += 1;
116
- };
117
- const div = async () => {
118
- await delay(1);
119
- result /= 3;
120
- };
121
- const mult = async () => {
122
- await delay(1);
123
- result *= 2;
124
- };
125
- await chainVoidAsync(add, div, mult)();
126
- expect(result).toBe(4);
127
- });
128
- });
129
- describe('withEffect()', () => {
130
- it('apply effect to a value and return the value', () => {
131
- const input = 4;
132
- const spy = jest.fn();
133
- withEffect(spy)(input);
134
- expect(spy).toHaveBeenCalledWith(4);
135
- });
136
- });
137
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=id.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"id.test.d.ts","sourceRoot":"","sources":["../../../src/utils/id.test.ts"],"names":[],"mappings":""}
@@ -1,64 +0,0 @@
1
- import { remapObjectIDs } from './id.js';
2
- // sample ObjectIds
3
- const Sample = {
4
- A: 'aaaaaaaaaaaaaaaaaaaaaaaa',
5
- B: 'bbbbbbbbbbbbbbbbbbbbbbbb',
6
- C: 'cccccccccccccccccccccccc',
7
- REAL: '61dcebb839fc80002d048dbd',
8
- };
9
- describe('Utils | id', () => {
10
- describe('remapObjectIDs()', () => {
11
- it('shallow nested', () => {
12
- const map = { [Sample.A]: Sample.B };
13
- expect(remapObjectIDs({ cool: Sample.A }, map)).toEqual({ cool: Sample.B });
14
- });
15
- it('converts string', () => {
16
- const map = { [Sample.A]: Sample.B };
17
- expect(remapObjectIDs(Sample.A, map)).toBe(Sample.B);
18
- });
19
- it('converts multiple', () => {
20
- const map = { [Sample.A]: Sample.B, [Sample.REAL]: Sample.C };
21
- expect(remapObjectIDs({ 1: Sample.A, 2: Sample.REAL }, map)).toEqual({ 1: Sample.B, 2: Sample.C });
22
- expect(remapObjectIDs({ 1: { 2: { 3: Sample.A, 4: [Sample.REAL] } } }, map)).toEqual({ 1: { 2: { 3: Sample.B, 4: [Sample.C] } } });
23
- });
24
- it('converts multiple maps', () => {
25
- const map = new Map([
26
- [Sample.A, Sample.B],
27
- [Sample.REAL, Sample.C],
28
- ]);
29
- expect(remapObjectIDs({ 1: Sample.A, 2: Sample.REAL }, map)).toEqual({ 1: Sample.B, 2: Sample.C });
30
- expect(remapObjectIDs({ 1: { 2: { 3: Sample.A, 4: [Sample.REAL] } } }, map)).toEqual({ 1: { 2: { 3: Sample.B, 4: [Sample.C] } } });
31
- });
32
- it('converts very nested', () => {
33
- const object = {
34
- a: { b: { c: { d: { e: 'id1' } } } },
35
- id1: {
36
- id2: {
37
- id3: {
38
- id4: ['id5'],
39
- },
40
- },
41
- b: 'id2',
42
- },
43
- };
44
- const map = {
45
- id1: 'new1',
46
- id2: 'new2',
47
- id3: 'new3',
48
- id4: 'new4',
49
- id5: 'new5',
50
- };
51
- expect(remapObjectIDs(object, map)).toEqual({
52
- a: { b: { c: { d: { e: 'new1' } } } },
53
- new1: {
54
- new2: {
55
- new3: {
56
- new4: ['new5'],
57
- },
58
- },
59
- b: 'new2',
60
- },
61
- });
62
- });
63
- });
64
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=intent.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"intent.test.d.ts","sourceRoot":"","sources":["../../../src/utils/intent.test.ts"],"names":[],"mappings":""}
@@ -1,75 +0,0 @@
1
- import * as data from './__fixtures__/name.json';
2
- import { injectUtteranceSpaces, utteranceEntityPermutations } from './intent.js';
3
- describe('utteranceEntityPermutations unit tests', () => {
4
- it('works correctly', async () => {
5
- const utterances = data.intents[0].inputs.map(({ text }) => text);
6
- const entitiesByID = Object.fromEntries(data.slots.map((slot) => [slot.key, slot]));
7
- const key = '4i3h3mmi';
8
- const luisUtterances = utteranceEntityPermutations({ utterances, entitiesByID });
9
- expect(luisUtterances.length).toBe(Math.min(entitiesByID[key].inputs.length, 22));
10
- // Check that each slot value is within one of the utterances
11
- entitiesByID[key].inputs.forEach((input, i) => {
12
- if (i < 22) {
13
- expect(luisUtterances.filter((utt) => utt.text?.includes(input)).length).toBeGreaterThan(0);
14
- }
15
- });
16
- // Check that a fake name is not within the utterances
17
- expect(luisUtterances.filter((utt) => utt.text?.includes('fakeName')).length).toBe(0);
18
- });
19
- it('with replacer', async () => {
20
- const utterances = [
21
- '{{[slot].4i3h3mmi}} testing {{[slotmans].4i3h3mmi}} {{[third].third}}',
22
- 'close {{[slotmans].4i3h3mmi}}{{[third].third}} together',
23
- ];
24
- const entitiesByID = {
25
- '4i3h3mmi': { name: 'slotmans', inputs: ['value1', 'value_super_long', 'v3'] },
26
- third: { name: 'third', inputs: ['thirdvalue'] },
27
- };
28
- // this generates the rasa format
29
- const replacer = (sample, entityID) => {
30
- return `[${sample}](${entitiesByID[entityID].name})`;
31
- };
32
- const replacedUtterances = utteranceEntityPermutations({ utterances, entitiesByID, replacer });
33
- expect(replacedUtterances.map(({ text }) => text)).toEqual([
34
- '[value1](slotmans) testing [value_super_long](slotmans) [thirdvalue](third)',
35
- 'close [v3](slotmans)[thirdvalue](third) together',
36
- ]);
37
- });
38
- });
39
- describe('injectUtteranceSpaces', () => {
40
- const testUtterances = [
41
- '',
42
- '{{[slot].4i3h3mmi}}',
43
- '{{[slot].4i3h3mmi}}{{[slotmans].4i3h3mmi}}',
44
- 'hello there {{[slotmans].4i3h3mma}}',
45
- 'hello there {{[slotmans].4i3h3mmb}} words',
46
- 'hello there{{[slotmans].4i3h3mmc}} words',
47
- 'hello there {{[slotmans].4i3h3mmd}}words',
48
- 'hello there{{[slotmans].4i3h3mme}}words',
49
- 'hello there {{[slotmans].4i3h3mmf}}, words',
50
- 'hello there:{{[slotmans].4i3h3mmg}},words',
51
- '{{[slot].4i3h3mmi}}and{{[third].third}}',
52
- '{{[slot].4i3h3mmi}}{{[slotmans].4i3h3mmi}}{{[third].third}}',
53
- 'multiple{{[slotmans].4i3h3mmi}}slots{{[slotmans].4i3h3mmi}}words{{[slotmans].4i3h3mmi}}',
54
- ];
55
- const expectedResults = [
56
- '',
57
- '{{[slot].4i3h3mmi}}',
58
- '{{[slot].4i3h3mmi}} {{[slotmans].4i3h3mmi}}',
59
- 'hello there {{[slotmans].4i3h3mma}}',
60
- 'hello there {{[slotmans].4i3h3mmb}} words',
61
- 'hello there {{[slotmans].4i3h3mmc}} words',
62
- 'hello there {{[slotmans].4i3h3mmd}} words',
63
- 'hello there {{[slotmans].4i3h3mme}} words',
64
- 'hello there {{[slotmans].4i3h3mmf}}, words',
65
- 'hello there:{{[slotmans].4i3h3mmg}},words',
66
- '{{[slot].4i3h3mmi}} and {{[third].third}}',
67
- '{{[slot].4i3h3mmi}} {{[slotmans].4i3h3mmi}} {{[third].third}}',
68
- 'multiple {{[slotmans].4i3h3mmi}} slots {{[slotmans].4i3h3mmi}} words {{[slotmans].4i3h3mmi}}',
69
- ];
70
- it('add spaces around slots if needed', () => {
71
- for (let i = 0; i < testUtterances.length; ++i) {
72
- expect(injectUtteranceSpaces(testUtterances[i])).toBe(expectedResults[i]);
73
- }
74
- });
75
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=map.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"map.test.d.ts","sourceRoot":"","sources":["../../../src/utils/map.test.ts"],"names":[],"mappings":""}
@@ -1,20 +0,0 @@
1
- import { getOrDefault } from './map.js';
2
- describe('Utils | map', () => {
3
- describe('getOrDefault', () => {
4
- it('returns the value at the given key if it exists in the map', () => {
5
- const map = new Map([['key', 'value']]);
6
- const value = getOrDefault(map, 'key', 'other');
7
- expect(value).toBe('value');
8
- });
9
- it('inserts and returns the default value if key does not exist in the map', () => {
10
- const map = new Map();
11
- const value = getOrDefault(map, 'key', 'other');
12
- expect(value).toBe('other');
13
- });
14
- it('inserts and returns the result of the default value function if key does not exist in the map', () => {
15
- const map = new Map();
16
- const value = getOrDefault(map, 'key', () => 'other');
17
- expect(value).toBe('other');
18
- });
19
- });
20
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=common.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/object/common.test.ts"],"names":[],"mappings":""}
@@ -1,173 +0,0 @@
1
- import { hasProperty, isObject, mapEntry, mapValue, omit, omitBy, pick, pickBy, selectField, selectID, selectKey, selectValue, shallowPartialEquals, } from './common.js';
2
- describe('Utils | object | common', () => {
3
- describe('selectField()', () => {
4
- it('creates function', () => {
5
- expect(typeof selectField('field')).toBe('function');
6
- });
7
- it('works', () => {
8
- expect(selectField('field')({ field: 1 })).toBe(1);
9
- expect(selectField('field2')({ field1: 1, field2: 2 })).toBe(2);
10
- });
11
- });
12
- describe('selectID()', () => {
13
- it('works', () => {
14
- expect(selectID({ id: '1' })).toBe('1');
15
- expect(selectID({ id: 0 })).toBe(0);
16
- });
17
- });
18
- describe('selectKey()', () => {
19
- it('works', () => {
20
- expect(selectKey({ key: '1' })).toBe('1');
21
- expect(selectKey({ key: 0 })).toBe(0);
22
- });
23
- });
24
- describe('selectValue()', () => {
25
- it('works', () => {
26
- expect(selectValue({ value: '1' })).toBe('1');
27
- expect(selectValue({ value: 0 })).toBe(0);
28
- });
29
- });
30
- describe('isObject()', () => {
31
- it('works positive', () => {
32
- expect(isObject({})).toBe(true);
33
- expect(isObject({})).toBe(true);
34
- expect(isObject([])).toBe(true);
35
- // eslint-disable-next-line no-new-wrappers
36
- expect(isObject(new Number(1))).toBe(true);
37
- });
38
- it('works negative', () => {
39
- expect(isObject(null)).toBe(false);
40
- expect(isObject(undefined)).toBe(false);
41
- expect(isObject('')).toBe(false);
42
- expect(isObject('lorem')).toBe(false);
43
- expect(isObject(0)).toBe(false);
44
- expect(isObject(Symbol('s'))).toBe(false);
45
- });
46
- });
47
- describe('hasProperty()', () => {
48
- it('works', () => {
49
- expect(hasProperty({ value: '1' }, 'value')).toBe(true);
50
- expect(hasProperty({}, 'key')).toBe(false);
51
- });
52
- });
53
- describe('omit()', () => {
54
- it('works with 0-3 keys', () => {
55
- expect(omit({ value1: '1' }, [])).toEqual({ value1: '1' });
56
- expect(omit({ value1: '1' }, ['value1'])).toEqual({});
57
- expect(omit({ value1: '1', value2: '2', value3: 3 }, ['value1', 'value2'])).toEqual({ value3: 3 });
58
- expect(omit({ value1: '1', value2: '2', value3: 3, value4: 4 }, ['value1', 'value2', 'value3'])).toEqual({ value4: 4 });
59
- });
60
- it('works with 3+ keys', () => {
61
- expect(omit({ value1: '1', value2: '2', value3: 3 }, ['value1', 'value2', 'value3'])).toEqual({});
62
- expect(omit({ value1: '1', value2: '2', value3: 3, value4: undefined, value5: null }, ['value1', 'value2', 'value3', 'value5'])).toEqual({
63
- value4: undefined,
64
- });
65
- });
66
- });
67
- describe('pick()', () => {
68
- it('works with 0-3 keys', () => {
69
- expect(pick({ value1: '1' }, [])).toEqual({});
70
- expect(pick({ value1: '1' }, ['value1'])).toEqual({ value1: '1' });
71
- expect(pick({ value1: '1', value2: '2', value3: 3 }, ['value1', 'value2'])).toEqual({ value1: '1', value2: '2' });
72
- expect(pick({ value1: '1', value2: '2', value3: 3, value4: 4 }, ['value1', 'value2', 'value3'])).toEqual({
73
- value1: '1',
74
- value2: '2',
75
- value3: 3,
76
- });
77
- });
78
- it('works with 3+ keys', () => {
79
- expect(pick({ value1: '1', value2: '2', value3: 3 }, ['value1', 'value2', 'value3'])).toEqual({ value1: '1', value2: '2', value3: 3 });
80
- expect(pick({ value1: '1', value2: '2', value3: 3, value4: undefined, value5: null }, ['value1', 'value2', 'value3', 'value5'])).toEqual({
81
- value1: '1',
82
- value2: '2',
83
- value3: 3,
84
- value5: null,
85
- });
86
- });
87
- it('works with undefined keys', () => {
88
- expect(pick({ value1: '1', value2: '2' }, ['value1', 'value2', 'value3'])).toEqual({ value1: '1', value2: '2' });
89
- });
90
- });
91
- describe('omitBy()', () => {
92
- it('works', () => {
93
- const keys = new Set(['value1', 'value2', 'value5']);
94
- expect(omitBy({ value1: '1' }, () => false)).toEqual({ value1: '1' });
95
- expect(omitBy({ value1: '1' }, (key) => keys.has(key))).toEqual({});
96
- expect(omitBy({ value1: '1', value2: '2', value3: 3 }, (key) => keys.has(key))).toEqual({ value3: 3 });
97
- expect(omitBy({ value1: '1', value2: '2', value3: 3 }, (key) => key === 'value3' || keys.has(key))).toEqual({});
98
- expect(omitBy({ value1: '1', value2: '2', value3: 3, value4: undefined, value5: null }, (key) => keys.has(key))).toEqual({
99
- value3: 3,
100
- value4: undefined,
101
- });
102
- });
103
- });
104
- describe('pickBy()', () => {
105
- it('works', () => {
106
- const keys = new Set(['value1', 'value2', 'value5']);
107
- expect(pickBy({ value1: '1' }, () => false)).toEqual({});
108
- expect(pickBy({ value1: '1' }, (key) => keys.has(key))).toEqual({ value1: '1' });
109
- expect(pickBy({ value1: '1', value2: '2', value3: 3 }, (key) => keys.has(key))).toEqual({
110
- value1: '1',
111
- value2: '2',
112
- });
113
- expect(pickBy({ value1: '1', value2: '2', value3: 3 }, (key) => key === 'value3' || keys.has(key))).toEqual({
114
- value1: '1',
115
- value2: '2',
116
- value3: 3,
117
- });
118
- expect(pickBy({ value1: '1', value2: '2', value3: 3, value4: undefined, value5: null }, (key) => keys.has(key))).toEqual({
119
- value1: '1',
120
- value2: '2',
121
- value5: null,
122
- });
123
- });
124
- });
125
- describe('mapValue()', () => {
126
- it('works', () => {
127
- const objects = {
128
- a: { id: 1 },
129
- b: { id: 2 },
130
- c: { id: 3 },
131
- };
132
- expect(mapValue(objects, ({ id }) => id)).toEqual({ a: 1, b: 2, c: 3 });
133
- });
134
- });
135
- describe('mapEntry()', () => {
136
- it('works', () => {
137
- const objects = {
138
- a: { id: 1 },
139
- b: { id: 2 },
140
- c: { id: 3 },
141
- };
142
- expect(mapEntry(objects, ([key, { id }]) => [`new_${key}`, id])).toEqual({ new_a: 1, new_b: 2, new_c: 3 });
143
- });
144
- });
145
- describe('shallowPartialEquals()', () => {
146
- it('works', () => {
147
- const obj1 = {
148
- a: 1,
149
- b: 2,
150
- };
151
- const obj1Update = {
152
- a: 1,
153
- c: undefined,
154
- };
155
- expect(shallowPartialEquals(obj1, obj1Update)).toBe(false);
156
- const obj2 = {
157
- a: 1,
158
- b: 2,
159
- };
160
- const obj2Update = {
161
- a: 1,
162
- };
163
- expect(shallowPartialEquals(obj2, obj2Update)).toBe(true);
164
- const obj3 = {
165
- a: 1,
166
- };
167
- const obj3Update = {
168
- b: 1,
169
- };
170
- expect(shallowPartialEquals(obj3, obj3Update)).toBe(false);
171
- });
172
- });
173
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=deepMap.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deepMap.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/object/deepMap.test.ts"],"names":[],"mappings":""}
@@ -1,109 +0,0 @@
1
- import ObjectID from 'bson-objectid';
2
- import { deepMap, deepMapKeys } from './deepMap.js';
3
- describe('Utils | object | deepMap', () => {
4
- describe('deepMap()', () => {
5
- const transform = (n) => (typeof n === 'number' ? n ** 2 : Number(n) ** 2);
6
- it('transforms simple object', () => {
7
- expect(deepMap({ two: 2, three: '3' }, transform)).toEqual({ two: 4, three: 9 });
8
- });
9
- it('transforms simple array', () => {
10
- expect(deepMap(['2', 3], transform)).toEqual([4, 9]);
11
- });
12
- it("don't change non plain objects", () => {
13
- const transform = (n) => (typeof n === 'string' ? Number(n) ** 2 : n);
14
- const date = new Date();
15
- expect(deepMap(['2', date], transform)).toEqual([4, date]);
16
- });
17
- it('transform objectID', () => {
18
- const originalID = new ObjectID();
19
- const transformedID = new ObjectID();
20
- const transform = (n) => (n === originalID ? transformedID : n);
21
- const date = new Date();
22
- expect(deepMap(['2', date, originalID], transform)).toEqual(['2', date, transformedID]);
23
- });
24
- it('transforms object with nested objects/arrays', () => {
25
- expect(deepMap({ two: '2', obj: { three: '3', four: 4 }, arr: [5, '6'] }, transform)).toEqual({
26
- two: 4,
27
- obj: { three: 9, four: 16 },
28
- arr: [25, 36],
29
- });
30
- });
31
- it('transforms array with nested objects/arrays', () => {
32
- expect(deepMap([2, { three: 3, four: 4 }, [5, 6]], transform)).toEqual([4, { three: 9, four: 16 }, [25, 36]]);
33
- });
34
- it('transforms an object with circular references', () => {
35
- const obj = { two: 2, arr: [3, 4], self: null, arr2: null };
36
- obj.self = obj;
37
- obj.arr2 = obj.arr;
38
- const exp = { two: 4, arr: [9, 16], self: null, arr2: null };
39
- exp.self = exp;
40
- exp.arr2 = exp.arr;
41
- expect(deepMap(obj, transform)).toEqual(exp);
42
- });
43
- it('transforms object in place', () => {
44
- const arr = [3];
45
- const obj = { two: 2, arr };
46
- const result = deepMap(obj, transform, { inPlace: true });
47
- expect(result).toEqual({ two: 4, arr: [9] });
48
- expect(result).toEqual(obj);
49
- });
50
- it('transforms sub-objects/sub-arrays in place', () => {
51
- const arr = [3];
52
- const obj = { two: 2, arr };
53
- expect(deepMap(obj, transform, { inPlace: true }).arr).toEqual(arr);
54
- });
55
- it('defaults to false', () => {
56
- const arr = [3];
57
- const obj = { two: 2, arr };
58
- expect(deepMap(obj, transform)).not.toEqual(obj);
59
- });
60
- it('mapFunction is called once per primitive value', () => {
61
- const square = jest.fn(transform);
62
- deepMap({ two: 2, obj: { three: 3 }, arr: [4] }, square);
63
- expect(square).toHaveBeenCalledTimes(3);
64
- });
65
- it('mapFunction is called with value and key', () => {
66
- const square = jest.fn(transform);
67
- deepMap({ two: 2, arr: [3, 6] }, square);
68
- expect(square).toHaveBeenNthCalledWith(1, 2, 'two');
69
- expect(square).toHaveBeenNthCalledWith(2, 3, 0);
70
- expect(square).toHaveBeenNthCalledWith(3, 6, 1);
71
- });
72
- });
73
- describe('deepMapKeys()', () => {
74
- const transform = (key) => key.toUpperCase();
75
- it('transforms keys of simple object', () => {
76
- expect(deepMapKeys({ one: 1, two: 2 }, transform)).toEqual({ ONE: 1, TWO: 2 });
77
- });
78
- it('transforms keys of object with nested objects/arrays', () => {
79
- expect(deepMapKeys({ one: 1, obj: { two: 2, three: 3 }, arr: [4, 5] }, transform)).toEqual({
80
- ONE: 1,
81
- OBJ: { TWO: 2, THREE: 3 },
82
- ARR: [4, 5],
83
- });
84
- });
85
- it('transforms keys of array with nested object/array', () => {
86
- expect(deepMapKeys([1, { two: 2, three: 3, arr: [4, { five: 5 }] }], transform)).toEqual([1, { TWO: 2, THREE: 3, ARR: [4, { FIVE: 5 }] }]);
87
- });
88
- it('transforms an object with circular references', () => {
89
- const obj = { one: 1, arr: [2, 3], self: null, arr2: [] };
90
- obj.self = obj;
91
- obj.arr2 = obj.arr;
92
- const exp = { ONE: 1, ARR: [2, 3], SELF: null, ARR2: [] };
93
- exp.SELF = exp;
94
- exp.ARR2 = exp.ARR;
95
- expect(deepMapKeys(obj, transform)).toEqual(exp);
96
- });
97
- it('mapFunction is called once per object property', () => {
98
- const caps = jest.fn(transform);
99
- deepMapKeys({ one: 1, obj: { two: 2, three: 3 }, arr: [4, 5] }, caps);
100
- expect(caps).toHaveBeenCalledTimes(5);
101
- });
102
- it('mapFunction is called with key and value', () => {
103
- const caps = jest.fn(transform);
104
- deepMapKeys({ one: 1, arr: [2, 3] }, caps);
105
- expect(caps).toHaveBeenNthCalledWith(1, 'one', 1);
106
- expect(caps).toHaveBeenNthCalledWith(2, 'arr', [2, 3]);
107
- });
108
- });
109
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=diff.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"diff.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/object/diff.test.ts"],"names":[],"mappings":""}
@@ -1,17 +0,0 @@
1
- import { getTopLevelDiff } from './diff.js';
2
- describe('Utils | object | diff', () => {
3
- describe('getTopLevelDiff()', () => {
4
- it('gets diff of arrays', () => {
5
- expect(getTopLevelDiff(['foo', 'bar', 'fuzz'], ['fizz', 'buzz', 'fuzz'])).toEqual(['foo', 'bar']);
6
- });
7
- it('gets diff of objects', () => {
8
- expect(getTopLevelDiff({ foo: 1, bar: 2, fuzz: 3 }, { fizz: 4, buzz: 5, fuzz: 3 })).toEqual({ foo: 1, bar: 2 });
9
- });
10
- it('gets diff of objects with custom compare', () => {
11
- expect(getTopLevelDiff({ foo: 1, bar: 2, fuzz: 6 }, { fizz: 4, buzz: 5, fuzz: 9 }, (lhs, rhs) => typeof lhs === typeof rhs)).toEqual({
12
- foo: 1,
13
- bar: 2,
14
- });
15
- });
16
- });
17
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=keys.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keys.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/object/keys.test.ts"],"names":[],"mappings":""}