@voiceflow/common 8.2.8 → 8.3.1

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 (206) 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/base64.js +4 -4
  5. package/build/cjs/crypto/hex2abc.d.ts.map +1 -1
  6. package/build/cjs/crypto/synchronous.d.ts +1 -1
  7. package/build/cjs/crypto/synchronous.d.ts.map +1 -1
  8. package/build/cjs/crypto/synchronous.js +2 -2
  9. package/build/cjs/types.d.ts +26 -26
  10. package/build/cjs/types.d.ts.map +1 -1
  11. package/build/cjs/utils/array.d.ts +3 -3
  12. package/build/cjs/utils/array.d.ts.map +1 -1
  13. package/build/cjs/utils/array.js +2 -3
  14. package/build/cjs/utils/emails.d.ts.map +1 -1
  15. package/build/cjs/utils/functional.d.ts +4 -4
  16. package/build/cjs/utils/functional.d.ts.map +1 -1
  17. package/build/cjs/utils/functional.js +0 -1
  18. package/build/cjs/utils/id.d.ts +1 -1
  19. package/build/cjs/utils/id.d.ts.map +1 -1
  20. package/build/cjs/utils/intent.d.ts +6 -6
  21. package/build/cjs/utils/intent.d.ts.map +1 -1
  22. package/build/cjs/utils/intent.js +5 -3
  23. package/build/cjs/utils/mathjs.js +1 -1
  24. package/build/cjs/utils/normalized.d.ts +5 -5
  25. package/build/cjs/utils/normalized.d.ts.map +1 -1
  26. package/build/cjs/utils/number.d.ts.map +1 -1
  27. package/build/cjs/utils/number.js +2 -2
  28. package/build/cjs/utils/object/common.d.ts +1 -1
  29. package/build/cjs/utils/object/common.d.ts.map +1 -1
  30. package/build/cjs/utils/object/common.js +2 -2
  31. package/build/cjs/utils/object/deepMap.d.ts +1 -1
  32. package/build/cjs/utils/object/deepMap.d.ts.map +1 -1
  33. package/build/cjs/utils/object/deepMap.js +0 -2
  34. package/build/cjs/utils/object/diff.d.ts +1 -1
  35. package/build/cjs/utils/object/diff.d.ts.map +1 -1
  36. package/build/cjs/utils/object/diff.js +2 -2
  37. package/build/cjs/utils/object/keys.d.ts +2 -1
  38. package/build/cjs/utils/object/keys.d.ts.map +1 -1
  39. package/build/cjs/utils/promise.d.ts.map +1 -1
  40. package/build/cjs/utils/protocol.d.ts +2 -2
  41. package/build/cjs/utils/protocol.d.ts.map +1 -1
  42. package/build/cjs/utils/slot.d.ts.map +1 -1
  43. package/build/cjs/utils/slot.js +2 -2
  44. package/build/cjs/utils/time.js +14 -14
  45. package/build/cjs/utils/typeguard.d.ts +2 -2
  46. package/build/cjs/utils/typeguard.d.ts.map +1 -1
  47. package/build/cjs/utils/variables.d.ts +2 -2
  48. package/build/cjs/utils/variables.d.ts.map +1 -1
  49. package/build/esm/constants/regexp.d.ts +5 -5
  50. package/build/esm/constants/regexp.d.ts.map +1 -1
  51. package/build/esm/crypto/base64.js +2 -2
  52. package/build/esm/crypto/hex2abc.d.ts.map +1 -1
  53. package/build/esm/crypto/synchronous.d.ts +1 -1
  54. package/build/esm/crypto/synchronous.d.ts.map +1 -1
  55. package/build/esm/crypto/synchronous.js +1 -1
  56. package/build/esm/types.d.ts +26 -26
  57. package/build/esm/types.d.ts.map +1 -1
  58. package/build/esm/utils/array.d.ts +3 -3
  59. package/build/esm/utils/array.d.ts.map +1 -1
  60. package/build/esm/utils/array.js +2 -3
  61. package/build/esm/utils/emails.d.ts.map +1 -1
  62. package/build/esm/utils/functional.d.ts +4 -4
  63. package/build/esm/utils/functional.d.ts.map +1 -1
  64. package/build/esm/utils/functional.js +0 -1
  65. package/build/esm/utils/id.d.ts +1 -1
  66. package/build/esm/utils/id.d.ts.map +1 -1
  67. package/build/esm/utils/intent.d.ts +6 -6
  68. package/build/esm/utils/intent.d.ts.map +1 -1
  69. package/build/esm/utils/intent.js +5 -3
  70. package/build/esm/utils/mathjs.js +1 -1
  71. package/build/esm/utils/normalized.d.ts +5 -5
  72. package/build/esm/utils/normalized.d.ts.map +1 -1
  73. package/build/esm/utils/number.d.ts.map +1 -1
  74. package/build/esm/utils/number.js +1 -1
  75. package/build/esm/utils/object/common.d.ts +1 -1
  76. package/build/esm/utils/object/common.d.ts.map +1 -1
  77. package/build/esm/utils/object/common.js +1 -1
  78. package/build/esm/utils/object/deepMap.d.ts +1 -1
  79. package/build/esm/utils/object/deepMap.d.ts.map +1 -1
  80. package/build/esm/utils/object/deepMap.js +0 -2
  81. package/build/esm/utils/object/diff.d.ts +1 -1
  82. package/build/esm/utils/object/diff.d.ts.map +1 -1
  83. package/build/esm/utils/object/diff.js +1 -1
  84. package/build/esm/utils/object/keys.d.ts +2 -1
  85. package/build/esm/utils/object/keys.d.ts.map +1 -1
  86. package/build/esm/utils/promise.d.ts.map +1 -1
  87. package/build/esm/utils/protocol.d.ts +2 -2
  88. package/build/esm/utils/protocol.d.ts.map +1 -1
  89. package/build/esm/utils/slot.d.ts.map +1 -1
  90. package/build/esm/utils/slot.js +1 -1
  91. package/build/esm/utils/time.js +7 -7
  92. package/build/esm/utils/typeguard.d.ts +2 -2
  93. package/build/esm/utils/typeguard.d.ts.map +1 -1
  94. package/build/esm/utils/variables.d.ts +2 -2
  95. package/build/esm/utils/variables.d.ts.map +1 -1
  96. package/package.json +46 -48
  97. package/build/cjs/crypto/hex2abc.test.d.ts +0 -2
  98. package/build/cjs/crypto/hex2abc.test.d.ts.map +0 -1
  99. package/build/cjs/crypto/hex2abc.test.js +0 -12
  100. package/build/cjs/crypto/murmurhash.test.d.ts +0 -2
  101. package/build/cjs/crypto/murmurhash.test.d.ts.map +0 -1
  102. package/build/cjs/crypto/murmurhash.test.js +0 -23
  103. package/build/cjs/utils/__fixtures__/name.json +0 -64
  104. package/build/cjs/utils/array.test.d.ts +0 -2
  105. package/build/cjs/utils/array.test.d.ts.map +0 -1
  106. package/build/cjs/utils/array.test.js +0 -237
  107. package/build/cjs/utils/email.test.d.ts +0 -2
  108. package/build/cjs/utils/email.test.d.ts.map +0 -1
  109. package/build/cjs/utils/email.test.js +0 -22
  110. package/build/cjs/utils/functional.test.d.ts +0 -2
  111. package/build/cjs/utils/functional.test.d.ts.map +0 -1
  112. package/build/cjs/utils/functional.test.js +0 -139
  113. package/build/cjs/utils/id.test.d.ts +0 -2
  114. package/build/cjs/utils/id.test.d.ts.map +0 -1
  115. package/build/cjs/utils/id.test.js +0 -66
  116. package/build/cjs/utils/intent.test.d.ts +0 -2
  117. package/build/cjs/utils/intent.test.d.ts.map +0 -1
  118. package/build/cjs/utils/intent.test.js +0 -100
  119. package/build/cjs/utils/map.test.d.ts +0 -2
  120. package/build/cjs/utils/map.test.d.ts.map +0 -1
  121. package/build/cjs/utils/map.test.js +0 -22
  122. package/build/cjs/utils/object/common.test.d.ts +0 -2
  123. package/build/cjs/utils/object/common.test.d.ts.map +0 -1
  124. package/build/cjs/utils/object/common.test.js +0 -175
  125. package/build/cjs/utils/object/deepMap.test.d.ts +0 -2
  126. package/build/cjs/utils/object/deepMap.test.d.ts.map +0 -1
  127. package/build/cjs/utils/object/deepMap.test.js +0 -114
  128. package/build/cjs/utils/object/diff.test.d.ts +0 -2
  129. package/build/cjs/utils/object/diff.test.d.ts.map +0 -1
  130. package/build/cjs/utils/object/diff.test.js +0 -19
  131. package/build/cjs/utils/object/keys.test.d.ts +0 -2
  132. package/build/cjs/utils/object/keys.test.d.ts.map +0 -1
  133. package/build/cjs/utils/object/keys.test.js +0 -15
  134. package/build/cjs/utils/promise.test.d.ts +0 -2
  135. package/build/cjs/utils/promise.test.d.ts.map +0 -1
  136. package/build/cjs/utils/promise.test.js +0 -25
  137. package/build/cjs/utils/protocol.test.d.ts +0 -2
  138. package/build/cjs/utils/protocol.test.d.ts.map +0 -1
  139. package/build/cjs/utils/protocol.test.js +0 -40
  140. package/build/cjs/utils/slot.test.d.ts +0 -2
  141. package/build/cjs/utils/slot.test.d.ts.map +0 -1
  142. package/build/cjs/utils/slot.test.js +0 -38
  143. package/build/cjs/utils/string.test.d.ts +0 -2
  144. package/build/cjs/utils/string.test.d.ts.map +0 -1
  145. package/build/cjs/utils/string.test.js +0 -53
  146. package/build/cjs/utils/timezones.test.d.ts +0 -2
  147. package/build/cjs/utils/timezones.test.d.ts.map +0 -1
  148. package/build/cjs/utils/timezones.test.js +0 -12
  149. package/build/cjs/utils/typeguard.test.d.ts +0 -2
  150. package/build/cjs/utils/typeguard.test.d.ts.map +0 -1
  151. package/build/cjs/utils/typeguard.test.js +0 -55
  152. package/build/esm/crypto/hex2abc.test.d.ts +0 -2
  153. package/build/esm/crypto/hex2abc.test.d.ts.map +0 -1
  154. package/build/esm/crypto/hex2abc.test.js +0 -10
  155. package/build/esm/crypto/murmurhash.test.d.ts +0 -2
  156. package/build/esm/crypto/murmurhash.test.d.ts.map +0 -1
  157. package/build/esm/crypto/murmurhash.test.js +0 -21
  158. package/build/esm/utils/__fixtures__/name.json +0 -64
  159. package/build/esm/utils/array.test.d.ts +0 -2
  160. package/build/esm/utils/array.test.d.ts.map +0 -1
  161. package/build/esm/utils/array.test.js +0 -235
  162. package/build/esm/utils/email.test.d.ts +0 -2
  163. package/build/esm/utils/email.test.d.ts.map +0 -1
  164. package/build/esm/utils/email.test.js +0 -20
  165. package/build/esm/utils/functional.test.d.ts +0 -2
  166. package/build/esm/utils/functional.test.d.ts.map +0 -1
  167. package/build/esm/utils/functional.test.js +0 -137
  168. package/build/esm/utils/id.test.d.ts +0 -2
  169. package/build/esm/utils/id.test.d.ts.map +0 -1
  170. package/build/esm/utils/id.test.js +0 -64
  171. package/build/esm/utils/intent.test.d.ts +0 -2
  172. package/build/esm/utils/intent.test.d.ts.map +0 -1
  173. package/build/esm/utils/intent.test.js +0 -75
  174. package/build/esm/utils/map.test.d.ts +0 -2
  175. package/build/esm/utils/map.test.d.ts.map +0 -1
  176. package/build/esm/utils/map.test.js +0 -20
  177. package/build/esm/utils/object/common.test.d.ts +0 -2
  178. package/build/esm/utils/object/common.test.d.ts.map +0 -1
  179. package/build/esm/utils/object/common.test.js +0 -173
  180. package/build/esm/utils/object/deepMap.test.d.ts +0 -2
  181. package/build/esm/utils/object/deepMap.test.d.ts.map +0 -1
  182. package/build/esm/utils/object/deepMap.test.js +0 -109
  183. package/build/esm/utils/object/diff.test.d.ts +0 -2
  184. package/build/esm/utils/object/diff.test.d.ts.map +0 -1
  185. package/build/esm/utils/object/diff.test.js +0 -17
  186. package/build/esm/utils/object/keys.test.d.ts +0 -2
  187. package/build/esm/utils/object/keys.test.d.ts.map +0 -1
  188. package/build/esm/utils/object/keys.test.js +0 -13
  189. package/build/esm/utils/promise.test.d.ts +0 -2
  190. package/build/esm/utils/promise.test.d.ts.map +0 -1
  191. package/build/esm/utils/promise.test.js +0 -23
  192. package/build/esm/utils/protocol.test.d.ts +0 -2
  193. package/build/esm/utils/protocol.test.d.ts.map +0 -1
  194. package/build/esm/utils/protocol.test.js +0 -38
  195. package/build/esm/utils/slot.test.d.ts +0 -2
  196. package/build/esm/utils/slot.test.d.ts.map +0 -1
  197. package/build/esm/utils/slot.test.js +0 -13
  198. package/build/esm/utils/string.test.d.ts +0 -2
  199. package/build/esm/utils/string.test.d.ts.map +0 -1
  200. package/build/esm/utils/string.test.js +0 -51
  201. package/build/esm/utils/timezones.test.d.ts +0 -2
  202. package/build/esm/utils/timezones.test.d.ts.map +0 -1
  203. package/build/esm/utils/timezones.test.js +0 -10
  204. package/build/esm/utils/typeguard.test.d.ts +0 -2
  205. package/build/esm/utils/typeguard.test.d.ts.map +0 -1
  206. package/build/esm/utils/typeguard.test.js +0 -53
@@ -1,235 +0,0 @@
1
- import { append, createEntries, createMap, diff, filterAndGetLastRemovedValue, filterOutNullish, findUnion, hasIdenticalMembers, head, insert, insertAll, isNotNullish, isNullish, mergeByIdentifier, reorder, replace, separate, tail, toArray, toggleMembership, unique, without, withoutValue, withoutValues, } from './array.js';
2
- describe('Utils | array', () => {
3
- describe('unique()', () => {
4
- it('return an array containing one instance of each value from the array passed to it', () => {
5
- expect(unique([1, 1, 2, 0, 1, 4, 3, 1, 9, 9, 2])).toEqual([1, 2, 0, 4, 3, 9]);
6
- });
7
- });
8
- describe('without()', () => {
9
- it('return an array containing every value from the array passed to it except for the value at the provided index', () => {
10
- expect(without([], -1)).toEqual([]);
11
- expect(without([], 0)).toEqual([]);
12
- expect(without(['a', 'b', 'c', 'd'], -1)).toEqual(['a', 'b', 'c', 'd']);
13
- expect(without(['a', 'b', 'c', 'd'], 0)).toEqual(['b', 'c', 'd']);
14
- expect(without(['a', 'b', 'c', 'd'], 2)).toEqual(['a', 'b', 'd']);
15
- expect(without(['a', 'b', 'c', 'd'], 4)).toEqual(['a', 'b', 'c', 'd']);
16
- });
17
- });
18
- describe('withoutValue()', () => {
19
- 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', () => {
20
- expect(withoutValue([], 'd')).toEqual([]);
21
- expect(withoutValue(['a', 'b', 'c', 'd'], 'g')).toEqual(['a', 'b', 'c', 'd']);
22
- expect(withoutValue(['a', 'b', 'c', 'd'], 'b')).toEqual(['a', 'c', 'd']);
23
- });
24
- });
25
- describe('withoutValues()', () => {
26
- it('return an array containing every value from the array passed to it except for values from a second provided array', () => {
27
- expect(withoutValues(['a', 'b', 'c', 'd'], [])).toEqual(['a', 'b', 'c', 'd']);
28
- expect(withoutValues([], ['g', 'c', 'b', 'e'])).toEqual([]);
29
- expect(withoutValues(['a', 'b', 'c', 'd'], ['g', 'c', 'b', 5])).toEqual(['a', 'd']);
30
- expect(withoutValues(['a', 'b', 'c', 'd'], ['g', 'e'])).toEqual(['a', 'b', 'c', 'd']);
31
- });
32
- });
33
- describe('replace()', () => {
34
- it('return an array where the value at the provided index has been replaced with the new value', () => {
35
- expect(insert([], 8, 'f')).toEqual(['f']);
36
- expect(replace(['a', 'b', 'c', 'd'], -1, 'f')).toEqual(['a', 'b', 'c', 'd']);
37
- expect(replace(['a', 'b', 'c', 'd'], 8, 'f')).toEqual(['a', 'b', 'c', 'd', 'f']);
38
- expect(replace(['a', 'b', 'c', 'd'], 2, 'f')).toEqual(['a', 'b', 'f', 'd']);
39
- });
40
- });
41
- describe('insert()', () => {
42
- it('return an array where the provided value has been inserted at the provided index', () => {
43
- expect(insert([], 8, 'f')).toEqual(['f']);
44
- expect(insert(['a', 'b', 'c', 'd'], -1, 'f')).toEqual(['f', 'a', 'b', 'c', 'd']);
45
- expect(insert(['a', 'b', 'c', 'd'], 2, 'f')).toEqual(['a', 'b', 'f', 'c', 'd']);
46
- expect(insert(['a', 'b', 'c', 'd'], 8, 'f')).toEqual(['a', 'b', 'c', 'd', 'f']);
47
- });
48
- });
49
- describe('insertAll()', () => {
50
- it('return an array where the provided array of values has been inserted at the provided index', () => {
51
- expect(insertAll([], 8, ['f', 'g', 'h'])).toEqual(['f', 'g', 'h']);
52
- expect(insertAll(['a', 'b', 'c', 'd'], -1, ['f', 'g', 'h'])).toEqual(['f', 'g', 'h', 'a', 'b', 'c', 'd']);
53
- expect(insertAll(['a', 'b', 'c', 'd'], 2, ['f', 'g', 'h'])).toEqual(['a', 'b', 'f', 'g', 'h', 'c', 'd']);
54
- expect(insertAll(['a', 'b', 'c', 'd'], 8, ['f', 'g', 'h'])).toEqual(['a', 'b', 'c', 'd', 'f', 'g', 'h']);
55
- });
56
- });
57
- describe('append()', () => {
58
- it('return an array with the provided value appended, does not add if already exists', () => {
59
- expect(append([], 'f')).toEqual(['f']);
60
- expect(append(['a', 'b', 'c', 'd'], 'f')).toEqual(['a', 'b', 'c', 'd', 'f']);
61
- expect(append(['a', 'b', 'c'], 'c')).toEqual(['a', 'b', 'c']);
62
- });
63
- });
64
- describe('toggleMembership()', () => {
65
- it('return an array with the provided value included or excluded, the opposite of the current state', () => {
66
- expect(toggleMembership(['a', 'b', 'c'], 'f')).toEqual(['a', 'b', 'c', 'f']);
67
- expect(toggleMembership(['a', 'b', 'c', 'f'], 'f')).toEqual(['a', 'b', 'c']);
68
- });
69
- });
70
- describe('head()', () => {
71
- it('return the item at the head of the array and an array containing the remaining elements as a tuple pair', () => {
72
- expect(head(['a', 'b', 'c', 'd'])).toEqual(['a', ['b', 'c', 'd']]);
73
- expect(head(['a'])).toEqual(['a', []]);
74
- expect(head([])).toEqual([undefined, []]);
75
- });
76
- });
77
- describe('tail()', () => {
78
- it('return the item at the end of the array and an array containing the remaining elements as a tuple pair', () => {
79
- expect(tail(['a', 'b', 'c', 'd'])).toEqual([['a', 'b', 'c'], 'd']);
80
- expect(tail(['a'])).toEqual([[], 'a']);
81
- expect(tail([])).toEqual([[], undefined]);
82
- });
83
- });
84
- describe('filterOutNullish()', () => {
85
- it('filters nullish values', () => {
86
- expect(filterOutNullish([undefined, 1, null])).toEqual([1]);
87
- expect(filterOutNullish([undefined, null])).toEqual([]);
88
- expect(filterOutNullish([1])).toEqual([1]);
89
- });
90
- });
91
- describe('isNullish()', () => {
92
- it('works', () => {
93
- expect(isNullish(null)).toBe(true);
94
- expect(isNullish(undefined)).toBe(true);
95
- expect(isNullish(0)).toBe(false);
96
- });
97
- });
98
- describe('isNotNullish()', () => {
99
- it('works', () => {
100
- expect(isNotNullish(null)).toBe(false);
101
- expect(isNotNullish(undefined)).toBe(false);
102
- expect(isNotNullish(0)).toBe(true);
103
- });
104
- });
105
- describe('toArray()', () => {
106
- it('works with arrays', () => {
107
- const value = [1];
108
- expect(toArray(value)).toEqual([1]);
109
- });
110
- it('works with non-arrays', () => {
111
- const value = 1;
112
- expect(toArray(value)).toEqual([1]);
113
- });
114
- });
115
- describe('reorder()', () => {
116
- it('should do nothing if from index goes outside array', () => {
117
- const array = [1, 2, 3];
118
- expect(reorder(array, -1, 1)).toEqual(array);
119
- expect(reorder(array, 3, 1)).toEqual(array);
120
- });
121
- it('should set as first item if toIndex is zero or lower than 0', () => {
122
- const array = [1, 2, 3];
123
- expect(reorder(array, 2, -1)).toEqual([3, 1, 2]);
124
- expect(reorder(array, 2, 0)).toEqual([3, 1, 2]);
125
- });
126
- it('should set as last item if toIndex is the last or greater than last', () => {
127
- const array = [1, 2, 3];
128
- expect(reorder(array, 0, 2)).toEqual([2, 3, 1]);
129
- expect(reorder(array, 0, 3)).toEqual([2, 3, 1]);
130
- });
131
- it('should reorder moving forward or backward', () => {
132
- const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
133
- expect(reorder(array, 1, 2)).toEqual([1, 3, 2, 4, 5, 6, 7, 8, 9, 10]);
134
- expect(reorder(array, 2, 3)).toEqual([1, 2, 4, 3, 5, 6, 7, 8, 9, 10]);
135
- expect(reorder(array, 2, 8)).toEqual([1, 2, 4, 5, 6, 7, 8, 9, 3, 10]);
136
- expect(reorder(array, 8, 1)).toEqual([1, 9, 2, 3, 4, 5, 6, 7, 8, 10]);
137
- expect(reorder(array, 7, 2)).toEqual([1, 2, 8, 3, 4, 5, 6, 7, 9, 10]);
138
- });
139
- });
140
- describe('separate()', () => {
141
- it('separates items that pass and fail a predicate', () => {
142
- const [passes, fails] = separate([20, 1, -3, 15, 8, 23, 40, 3], (x) => x > 10);
143
- expect(passes).toEqual([20, 15, 23, 40]);
144
- expect(fails).toEqual([1, -3, 8, 3]);
145
- });
146
- });
147
- describe('createEntries()', () => {
148
- it('creates entries by extracting a key for each item in an array', () => {
149
- const entries = createEntries([{ index: 1 }, { index: 3 }, { index: 5 }], ({ index }) => String(index));
150
- expect(entries).toEqual([
151
- ['1', { index: 1 }],
152
- ['3', { index: 3 }],
153
- ['5', { index: 5 }],
154
- ]);
155
- });
156
- });
157
- describe('createMap()', () => {
158
- it('creates object by extracting a key for each item in an array', () => {
159
- const obj = createMap([{ index: 1 }, { index: 3 }, { index: 5 }], ({ index }) => String(index));
160
- expect(obj).toEqual({
161
- 1: { index: 1 },
162
- 3: { index: 3 },
163
- 5: { index: 5 },
164
- });
165
- });
166
- });
167
- describe('findUnion()', () => {
168
- it('finds the overlap between two lists', () => {
169
- const { lhsOnly, rhsOnly, union } = findUnion([20, 1, -3, 15], [1, 8, 23, -3, 40, 3]);
170
- expect(lhsOnly).toEqual([20, 15]);
171
- expect(rhsOnly).toEqual([8, 23, 40, 3]);
172
- expect(union).toEqual([1, -3]);
173
- });
174
- });
175
- describe('diff()', () => {
176
- it('finds items that only occur in one of two lists', () => {
177
- expect(diff([20, 1, -3, 15], [1, 8, 23, -3, 40, 3])).toEqual([20, 15, 8, 23, 40, 3]);
178
- });
179
- });
180
- describe('hasIdenticalMembers()', () => {
181
- it('returns false if lists have different lengths', () => {
182
- expect(hasIdenticalMembers([1, 2, 3], [3, 3, 2, 2, 1])).toBe(false);
183
- });
184
- it('returns false if either list has a unique member', () => {
185
- expect(hasIdenticalMembers([1, 2, 3], [2, 3])).toBe(false);
186
- });
187
- it('returns true if both lists contain the same members', () => {
188
- expect(hasIdenticalMembers([1, 2, 3], [3, 1, 2])).toBe(true);
189
- });
190
- it('returns true if both lists are empty', () => {
191
- expect(hasIdenticalMembers([], [])).toBe(true);
192
- });
193
- });
194
- describe('filterAndGetLastRemovedValue()', () => {
195
- it('returns the last item which did not pass the filter predicate', () => {
196
- expect(filterAndGetLastRemovedValue([1, 2, 3], () => true)).toEqual([[1, 2, 3], null]);
197
- expect(filterAndGetLastRemovedValue([], () => false)).toEqual([[], null]);
198
- expect(filterAndGetLastRemovedValue([1, 2, 3], (x) => x !== 2)).toEqual([[1, 3], 2]);
199
- });
200
- });
201
- describe('mergeByIdentifier()', () => {
202
- it('test', () => {
203
- const array1 = [
204
- {
205
- key: 1,
206
- value: [1, 2],
207
- },
208
- ];
209
- const array2 = [
210
- {
211
- key: 1,
212
- value: [3],
213
- },
214
- {
215
- key: 2,
216
- value: [4, 5],
217
- },
218
- ];
219
- const result = mergeByIdentifier(array1, array2, (x) => x.key.toString(), (a, b) => ({
220
- ...a,
221
- value: [...a.value, ...b.value],
222
- }));
223
- expect(result).toEqual([
224
- {
225
- key: 1,
226
- value: [1, 2, 3],
227
- },
228
- {
229
- key: 2,
230
- value: [4, 5],
231
- },
232
- ]);
233
- });
234
- });
235
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=email.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"email.test.d.ts","sourceRoot":"","sources":["../../../src/utils/email.test.ts"],"names":[],"mappings":""}
@@ -1,20 +0,0 @@
1
- import { getEmailDomain, isValidEmail } from './emails.js';
2
- describe('Utils | email', () => {
3
- describe('isValid()', () => {
4
- it('should be valid', () => {
5
- const validEmails = ['joe.doe@test.com', 'john.-last@sub.domain.com', 'test+@voiceflow.com', 't-est+34@voice-flow.com'];
6
- validEmails.forEach((email) => expect(isValidEmail(email)).toBe(true));
7
- });
8
- it('should be invalid', () => {
9
- const invalidEmails = ['joe@.com', 'joe@', '@voiceflow.com', '', 'voiceflow.com'];
10
- invalidEmails.forEach((email) => expect(isValidEmail(email)).toBe(false));
11
- });
12
- });
13
- describe('getEmailDomain()', () => {
14
- it('works', () => {
15
- expect(getEmailDomain('test@voiceflow.com')).toBe('voiceflow.com');
16
- expect(getEmailDomain('')).toBe('');
17
- expect(getEmailDomain('totally@invalid@voiceflow.com')).toBe('voiceflow.com');
18
- });
19
- });
20
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=functional.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"functional.test.d.ts","sourceRoot":"","sources":["../../../src/utils/functional.test.ts"],"names":[],"mappings":""}
@@ -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":""}