atomic-fns 1.1.7 → 2.0.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 (216) hide show
  1. package/README.md +405 -60
  2. package/dist/array/index.d.ts +9 -0
  3. package/dist/array/index.js +9 -0
  4. package/dist/array/list.d.ts +99 -0
  5. package/dist/array/list.js +133 -0
  6. package/dist/array/sets.d.ts +130 -0
  7. package/dist/array/sets.js +213 -0
  8. package/dist/async/index.d.ts +6 -0
  9. package/dist/async/index.js +6 -0
  10. package/dist/async/retry.d.ts +38 -0
  11. package/dist/async/retry.js +56 -0
  12. package/dist/async/sleep.d.ts +42 -0
  13. package/dist/async/sleep.js +76 -0
  14. package/dist/collections/bisect.d.ts +103 -0
  15. package/dist/collections/bisect.js +157 -0
  16. package/dist/collections/deque.d.ts +67 -97
  17. package/dist/collections/deque.js +197 -249
  18. package/dist/collections/entries.d.ts +89 -0
  19. package/dist/collections/entries.js +131 -0
  20. package/dist/collections/frozen-set.d.ts +42 -0
  21. package/dist/collections/frozen-set.js +64 -0
  22. package/dist/collections/group.d.ts +141 -0
  23. package/dist/collections/group.js +241 -0
  24. package/dist/collections/heap.d.ts +64 -0
  25. package/dist/collections/heap.js +205 -0
  26. package/dist/collections/index.d.ts +15 -642
  27. package/dist/collections/index.js +14 -716
  28. package/dist/collections/internal/arrayKeys.d.ts +19 -0
  29. package/dist/collections/internal/arrayKeys.js +83 -0
  30. package/dist/collections/internal/invariants.d.ts +4 -0
  31. package/dist/collections/internal/invariants.js +12 -0
  32. package/dist/collections/internal/iterable.d.ts +25 -0
  33. package/dist/collections/internal/iterable.js +62 -0
  34. package/dist/collections/iterate.d.ts +162 -0
  35. package/dist/collections/iterate.js +188 -0
  36. package/dist/collections/lru-cache.d.ts +58 -0
  37. package/dist/collections/lru-cache.js +164 -0
  38. package/dist/collections/order.d.ts +19 -0
  39. package/dist/collections/order.js +38 -0
  40. package/dist/collections/shape.d.ts +32 -0
  41. package/dist/collections/shape.js +86 -0
  42. package/dist/collections/sorted-map.d.ts +171 -0
  43. package/dist/collections/sorted-map.js +845 -0
  44. package/dist/collections/sorted-set.d.ts +103 -0
  45. package/dist/collections/sorted-set.js +147 -0
  46. package/dist/collections/splay-tree.d.ts +82 -0
  47. package/dist/collections/splay-tree.js +354 -0
  48. package/dist/collections/trie.d.ts +58 -0
  49. package/dist/collections/trie.js +196 -0
  50. package/dist/decimal/currency.d.ts +211 -0
  51. package/dist/decimal/currency.js +321 -0
  52. package/dist/decimal/decimal.d.ts +299 -0
  53. package/dist/decimal/decimal.js +660 -0
  54. package/dist/decimal/index.d.ts +11 -145
  55. package/dist/decimal/index.js +10 -374
  56. package/dist/decimal/internal/bits.d.ts +2 -0
  57. package/dist/decimal/internal/bits.js +7 -0
  58. package/dist/decimal/internal/echo.d.ts +4 -0
  59. package/dist/decimal/internal/echo.js +6 -0
  60. package/dist/decimal/internal/isqrt.d.ts +9 -0
  61. package/dist/decimal/internal/isqrt.js +34 -0
  62. package/dist/decimal/internal/locale.d.ts +7 -0
  63. package/dist/decimal/internal/locale.js +24 -0
  64. package/dist/decimal/internal/minor-units.d.ts +2 -0
  65. package/dist/decimal/internal/minor-units.js +33 -0
  66. package/dist/decimal/internal/pow10.d.ts +24 -0
  67. package/dist/decimal/internal/pow10.js +96 -0
  68. package/dist/encoding/base64.d.ts +39 -0
  69. package/dist/encoding/base64.js +53 -0
  70. package/dist/encoding/hex.d.ts +23 -0
  71. package/dist/encoding/hex.js +34 -0
  72. package/dist/encoding/index.d.ts +6 -0
  73. package/dist/encoding/index.js +6 -0
  74. package/dist/function/debounce.d.ts +68 -0
  75. package/dist/function/debounce.js +203 -0
  76. package/dist/function/index.d.ts +6 -0
  77. package/dist/function/index.js +6 -0
  78. package/dist/function/shared.d.ts +2 -0
  79. package/dist/function/shared.js +5 -0
  80. package/dist/function/wrap.d.ts +130 -0
  81. package/dist/function/wrap.js +113 -0
  82. package/dist/hash/digest.d.ts +18 -0
  83. package/dist/hash/digest.js +26 -0
  84. package/dist/hash/hash.d.ts +22 -0
  85. package/dist/hash/hash.js +252 -0
  86. package/dist/hash/hashString.d.ts +13 -0
  87. package/dist/hash/hashString.js +53 -0
  88. package/dist/hash/index.d.ts +8 -0
  89. package/dist/hash/index.js +8 -0
  90. package/dist/hash/stableStringify.d.ts +19 -0
  91. package/dist/hash/stableStringify.js +102 -0
  92. package/dist/id/index.d.ts +7 -0
  93. package/dist/id/index.js +7 -0
  94. package/dist/id/nanoid.d.ts +16 -0
  95. package/dist/id/nanoid.js +65 -0
  96. package/dist/id/uniqueId.d.ts +14 -0
  97. package/dist/id/uniqueId.js +20 -0
  98. package/dist/id/uuid.d.ts +25 -0
  99. package/dist/id/uuid.js +64 -0
  100. package/dist/index.d.ts +15 -8
  101. package/dist/index.js +15 -8
  102. package/dist/internal/bytes.d.ts +11 -0
  103. package/dist/internal/bytes.js +33 -0
  104. package/dist/internal/codec.d.ts +11 -0
  105. package/dist/internal/codec.js +84 -0
  106. package/dist/internal/compare.d.ts +10 -0
  107. package/dist/internal/compare.js +26 -0
  108. package/dist/internal/crypto.d.ts +5 -0
  109. package/dist/internal/crypto.js +11 -0
  110. package/dist/internal/keys.d.ts +12 -0
  111. package/dist/internal/keys.js +23 -0
  112. package/dist/internal/kind.d.ts +44 -0
  113. package/dist/internal/kind.js +139 -0
  114. package/dist/internal/sparse.d.ts +51 -0
  115. package/dist/internal/sparse.js +104 -0
  116. package/dist/internal/text.d.ts +7 -0
  117. package/dist/internal/text.js +15 -0
  118. package/dist/internal/timer.d.ts +10 -0
  119. package/dist/internal/timer.js +17 -0
  120. package/dist/internal/truncate.d.ts +10 -0
  121. package/dist/internal/truncate.js +22 -0
  122. package/dist/internal/walk.d.ts +47 -0
  123. package/dist/internal/walk.js +100 -0
  124. package/dist/is/index.d.ts +8 -0
  125. package/dist/is/index.js +8 -0
  126. package/dist/is/isArrayLike.d.ts +18 -0
  127. package/dist/is/isArrayLike.js +25 -0
  128. package/dist/is/isError.d.ts +13 -0
  129. package/dist/is/isError.js +18 -0
  130. package/dist/is/isNil.d.ts +12 -0
  131. package/dist/is/isNil.js +14 -0
  132. package/dist/is/isPlainObject.d.ts +15 -0
  133. package/dist/is/isPlainObject.js +34 -0
  134. package/dist/number/index.d.ts +7 -0
  135. package/dist/number/index.js +7 -0
  136. package/dist/number/round.d.ts +86 -0
  137. package/dist/number/round.js +130 -0
  138. package/dist/number/stats.d.ts +52 -0
  139. package/dist/number/stats.js +115 -0
  140. package/dist/object/cloneDeep.d.ts +28 -0
  141. package/dist/object/cloneDeep.js +200 -0
  142. package/dist/object/index.d.ts +14 -0
  143. package/dist/object/index.js +13 -0
  144. package/dist/object/isEqual.d.ts +64 -0
  145. package/dist/object/isEqual.js +289 -0
  146. package/dist/object/matches.d.ts +40 -0
  147. package/dist/object/matches.js +284 -0
  148. package/dist/object/merge.d.ts +66 -0
  149. package/dist/object/merge.js +272 -0
  150. package/dist/object/parsePath.d.ts +22 -0
  151. package/dist/object/parsePath.js +111 -0
  152. package/dist/object/path.d.ts +85 -0
  153. package/dist/object/path.js +208 -0
  154. package/dist/object/pick.d.ts +91 -0
  155. package/dist/object/pick.js +180 -0
  156. package/dist/object/reshape.d.ts +73 -0
  157. package/dist/object/reshape.js +144 -0
  158. package/dist/random/index.d.ts +96 -32
  159. package/dist/random/index.js +215 -50
  160. package/dist/string/case.d.ts +71 -0
  161. package/dist/string/case.js +152 -0
  162. package/dist/string/fold.d.ts +35 -0
  163. package/dist/string/fold.js +100 -0
  164. package/dist/string/index.d.ts +6 -187
  165. package/dist/string/index.js +6 -226
  166. package/dist/string/truncate.d.ts +25 -0
  167. package/dist/string/truncate.js +44 -0
  168. package/dist/string/words.d.ts +27 -0
  169. package/dist/string/words.js +241 -0
  170. package/package.json +101 -58
  171. package/dist/collections/BTree.d.ts +0 -229
  172. package/dist/collections/BTree.js +0 -1165
  173. package/dist/collections/Heap.d.ts +0 -69
  174. package/dist/collections/Heap.js +0 -181
  175. package/dist/collections/LRUCache.d.ts +0 -80
  176. package/dist/collections/LRUCache.js +0 -126
  177. package/dist/collections/SortedMap.d.ts +0 -92
  178. package/dist/collections/SortedMap.js +0 -131
  179. package/dist/collections/SortedSet.d.ts +0 -69
  180. package/dist/collections/SortedSet.js +0 -99
  181. package/dist/collections/SortedTree.d.ts +0 -103
  182. package/dist/collections/SortedTree.js +0 -141
  183. package/dist/collections/SplayTree.d.ts +0 -105
  184. package/dist/collections/SplayTree.js +0 -338
  185. package/dist/collections/Trie.d.ts +0 -42
  186. package/dist/collections/Trie.js +0 -104
  187. package/dist/collections/abc.d.ts +0 -152
  188. package/dist/collections/abc.js +0 -39
  189. package/dist/collections/frozenset.d.ts +0 -19
  190. package/dist/collections/frozenset.js +0 -30
  191. package/dist/functools/index.d.ts +0 -130
  192. package/dist/functools/index.js +0 -235
  193. package/dist/globals/index.d.ts +0 -285
  194. package/dist/globals/index.js +0 -463
  195. package/dist/i18n/currency.d.ts +0 -24
  196. package/dist/i18n/currency.js +0 -85
  197. package/dist/i18n/date/index.d.ts +0 -203
  198. package/dist/i18n/date/index.js +0 -531
  199. package/dist/i18n/date/utils.d.ts +0 -65
  200. package/dist/i18n/date/utils.js +0 -290
  201. package/dist/i18n/duration.d.ts +0 -112
  202. package/dist/i18n/duration.js +0 -392
  203. package/dist/i18n/format.d.ts +0 -31
  204. package/dist/i18n/format.js +0 -506
  205. package/dist/i18n/index.d.ts +0 -8
  206. package/dist/i18n/index.js +0 -8
  207. package/dist/itertools/index.d.ts +0 -255
  208. package/dist/itertools/index.js +0 -437
  209. package/dist/math/index.d.ts +0 -96
  210. package/dist/math/index.js +0 -98
  211. package/dist/mod.d.ts +0 -1
  212. package/dist/mod.js +0 -1
  213. package/dist/operators/index.d.ts +0 -152
  214. package/dist/operators/index.js +0 -305
  215. package/dist/types.d.ts +0 -19
  216. package/dist/types.js +0 -1
@@ -1,338 +0,0 @@
1
- import { compare, eq } from '../operators/index.js';
2
- import { Mapping } from './abc.js';
3
- /**
4
- * Base SplayTree node class.
5
- * @private
6
- */
7
- class Node {
8
- key;
9
- value;
10
- left;
11
- right;
12
- constructor(key, value) {
13
- this.key = key;
14
- this.value = value;
15
- }
16
- get height() {
17
- if (this.left && this.right)
18
- return 1 + Math.max(this.right.height, this.left.height);
19
- if (this.right)
20
- return 1 + this.right.height;
21
- if (this.left)
22
- return 1 + this.left.height;
23
- return 0;
24
- }
25
- }
26
- // In-order traversal of a tree
27
- function* traverse(node) {
28
- while (node) {
29
- yield* traverse(node.left);
30
- yield node;
31
- node = node.right;
32
- }
33
- }
34
- /**
35
- * A splay tree is a *self-balancing binary* search tree with the additional property that recently accessed elements are quick to access again.
36
- * Insertion, look-up and removal in O(log n) *amortized* time.
37
- * For many patterns of non-random operations splay trees can take better than logarithmic time, without requiring advance knowledge of the pattern.
38
- * @see {@link https://en.wikipedia.org/wiki/Splay_tree Splay tree}
39
- * @see {@link https://web.archive.org/web/20220930173835/http://www14.in.tum.de/personen/albers/papers/ipl02.pdf Randomized Splay Trees}
40
- * @template K, V
41
- */
42
- export class SplayTree extends Mapping {
43
- root;
44
- cmp;
45
- randSplay;
46
- count;
47
- /**
48
- * Create a new randomized Splay Tree
49
- * @param compareFn
50
- * @param p When an element is accessed, with probability `p` splay the tree. With probability `1 - p`, leave the tree as it is.
51
- */
52
- constructor(compareFn, p = 0.5) {
53
- super();
54
- this.cmp = compareFn ?? compare;
55
- this.count = 0;
56
- this.randSplay = p;
57
- }
58
- top() {
59
- return this.root?.key;
60
- }
61
- get size() {
62
- return this.count;
63
- }
64
- empty() {
65
- return !this.root;
66
- }
67
- get height() {
68
- if (!this.root)
69
- return 0;
70
- return this.root.height;
71
- }
72
- /**
73
- * Returns the value for `key` or `undefined` if the key is not found.
74
- * @param key The key to find.
75
- * @returns {?V} The value for the key or `undefined`.
76
- */
77
- get(key) {
78
- if (!this.root)
79
- return;
80
- // Note: deterministic splaying (always moves key to front):
81
- // this.splay(key)
82
- // if (this.cmp(key, this.root.key) === 0) return this.root.value
83
- // Randomized Splay Trees https://doi.org/10.1016%2Fs0020-0190%2801%2900230-7
84
- // The randomized idea is only moving accessed keys with a certain probability `p`.
85
- // Values of `p` closer to 1 tend to perform well.
86
- if (Math.random() <= this.randSplay) {
87
- this.splay(key);
88
- if (this.cmp(key, this.root.key) === 0)
89
- return this.root.value;
90
- else
91
- return undefined;
92
- }
93
- // Lookup the node down the tree
94
- let current = this.root;
95
- while (current) {
96
- const rank = this.cmp(key, current.key);
97
- if (rank === 0)
98
- return current.value;
99
- if (rank < 0)
100
- current = current.left;
101
- else
102
- current = current.right;
103
- }
104
- }
105
- /**
106
- * Inserts the `key` and `value` in the tree if the `key` does not exist.
107
- * @param {K} key A key which can be any comparable value
108
- * @param {V} value A value associated with the key
109
- * @returns
110
- */
111
- set(key, value) {
112
- if (!this.root) {
113
- this.root = new Node(key, value);
114
- this.count += 1;
115
- return;
116
- }
117
- // Splay on the key to move the last node on the search path for
118
- // the key to the root of the tree.
119
- this.splay(key);
120
- const rank = this.cmp(key, this.root.key);
121
- if (rank === 0) {
122
- // Update the value
123
- this.root.value = value;
124
- return;
125
- }
126
- const node = new Node(key, value);
127
- if (rank > 0) {
128
- node.left = this.root;
129
- node.right = this.root.right;
130
- this.root.right = undefined;
131
- }
132
- else {
133
- node.right = this.root;
134
- node.left = this.root.left;
135
- this.root.left = undefined;
136
- }
137
- this.root = node;
138
- this.count += 1;
139
- }
140
- /**
141
- * Removes a specified key if it exists in the tree. The removed value is returned or `undefined` if not found.
142
- * @param {K} key The key to remove.
143
- * @returns {?V} The removed value associated with `key`.
144
- */
145
- remove(key) {
146
- if (!this.root) {
147
- return;
148
- }
149
- this.splay(key);
150
- if (!eq(key, this.root.key)) {
151
- return;
152
- }
153
- const removed = this.root;
154
- if (!this.root.left) {
155
- this.root = this.root.right;
156
- }
157
- else {
158
- const right = this.root.right;
159
- this.root = this.root.left;
160
- //
161
- // Splay to make sure that the new root has an empty right child.
162
- //
163
- this.splay(key);
164
- //
165
- // Insert the original right child as the right child of the new
166
- // root.
167
- //
168
- this.root.right = right;
169
- }
170
- this.count -= 1;
171
- return removed.value;
172
- }
173
- //
174
- // function find(key)
175
- // @param {number} key Key to find in the tree.
176
- // @return {SplayTree.Node} Node having the specified key.
177
- //
178
- //
179
- /**
180
- * Returns the minimum key in the tree or subtree.
181
- * @returns The minimum key.
182
- */
183
- min(root = this.root) {
184
- if (!root)
185
- return;
186
- while (root.left) {
187
- root = root.left;
188
- }
189
- return root.key;
190
- }
191
- /**
192
- * Returns the maximum key in the tree or subtree.
193
- * @returns The maximum key.
194
- */
195
- max(root = this.root) {
196
- if (!root)
197
- return;
198
- while (root.right) {
199
- root = root.right;
200
- }
201
- return root.key;
202
- }
203
- /**
204
- * Returns the largest key that is less than a given key.
205
- * @param key The given key
206
- * @returns {?K} The largest key found or `undefined`.
207
- */
208
- lowerBound(key) {
209
- if (!this.root)
210
- return;
211
- // Splay on the key to move the node with the given key or the last
212
- // node on the search path to the top of the tree.
213
- this.splay(key);
214
- // Now the result is either the root node or the greatest node in
215
- // the left subtree.
216
- if (this.cmp(this.root.key, key) < 0) {
217
- return this.root.key;
218
- }
219
- else if (this.root.left) {
220
- return this.max(this.root.left);
221
- }
222
- }
223
- /**
224
- * This is the simplified top-down splaying method proposed by Sleator and Tarjan in {@link https://doi.org/10.1145%2F3828.3835 Self-Adjusting Binary Search Trees}.
225
- * @param key
226
- * @see {@link https://doi.org/10.1145%2F3828.3835 Self-Adjusting Binary Search Trees}
227
- */
228
- splay(key) {
229
- if (!this.root)
230
- return;
231
- let stub, left, right;
232
- // eslint-disable-next-line
233
- stub = left = right = new Node(null, null);
234
- let root = this.root;
235
- while (true) {
236
- const rank = this.cmp(key, root.key);
237
- if (rank < 0) {
238
- if (!root.left) {
239
- break;
240
- }
241
- if (this.cmp(key, root.left.key) < 0) {
242
- // Rotate right.
243
- const tmp = root.left;
244
- root.left = tmp.right;
245
- tmp.right = root;
246
- root = tmp;
247
- if (!root.left) {
248
- break;
249
- }
250
- }
251
- // Link right.
252
- right.left = root;
253
- right = root;
254
- root = root.left;
255
- }
256
- else if (rank > 0) {
257
- if (!root.right) {
258
- break;
259
- }
260
- if (this.cmp(key, root.right.key) > 0) {
261
- // Rotate left.
262
- const tmp = root.right;
263
- root.right = tmp.left;
264
- tmp.left = root;
265
- root = tmp;
266
- if (!root.right) {
267
- break;
268
- }
269
- }
270
- // Link left.
271
- left.right = root;
272
- left = root;
273
- root = root.right;
274
- }
275
- else {
276
- break;
277
- }
278
- }
279
- // Assemble.
280
- left.right = root.left;
281
- right.left = root.right;
282
- root.left = stub.right;
283
- root.right = stub.left;
284
- this.root = root;
285
- }
286
- add(key) {
287
- return this.set(key, null);
288
- }
289
- /**
290
- * Returns `true` if the given key is in the tree.
291
- * @param {K} key The key to find.
292
- * @returns `true` if found.
293
- */
294
- contains(key) {
295
- return this.get(key) !== undefined;
296
- }
297
- /** Alias of remove but just returns `true` instead of the deleted value. */
298
- delete(key) {
299
- // since remove throws, this will throw too
300
- this.remove(key);
301
- return true;
302
- }
303
- clear() {
304
- if (!this.root)
305
- return;
306
- this.root.left = undefined;
307
- this.root.right = undefined;
308
- this.root = undefined;
309
- this.count = 0;
310
- }
311
- /**
312
- * Returns an ordered iterable of all the keys in the tree.
313
- * @returns {Iterable<K>} An iterable of keys in-order.
314
- */
315
- *keys() {
316
- for (const node of traverse(this.root)) {
317
- yield node.key;
318
- }
319
- }
320
- /**
321
- * Returns an ordered iterable of all the keys and values in the tree.
322
- * @returns {Iterable<[K,V]>} A iterable of `[key, value]` pairs sorted by key.
323
- */
324
- *entries() {
325
- for (const node of traverse(this.root)) {
326
- yield [node.key, node.value];
327
- }
328
- }
329
- /**
330
- * Returns an ordered iterable of all the keys and values in the tree.
331
- * @returns {Iterable<V>} A iterable of `[key, value]` pairs sorted by key.
332
- */
333
- *values() {
334
- for (const node of traverse(this.root)) {
335
- yield node.value;
336
- }
337
- }
338
- }
@@ -1,42 +0,0 @@
1
- import { Collection } from './abc.js';
2
- /**
3
- * A Trie is a tree for efficient storing and retrieval of strings such as words in a dictionary. They are useful for checking all the strings that have a common prefix.
4
- * Insertions, lookups and removals in `O(s)` where `s` is the search term.
5
- * @see {@link https://en.wikipedia.org/wiki/Trie Trie}
6
- */
7
- export declare class Trie extends Collection {
8
- private root;
9
- private count;
10
- constructor(words?: string[]);
11
- /**
12
- * Adds the given string to the tree.
13
- * @param word A string
14
- */
15
- add(word: string): this;
16
- /**
17
- * Removes the given string from the tree.
18
- * @param word The string to remove
19
- * @returns {boolean} Returns `true` if the string was found and removed.
20
- */
21
- remove(word: string): boolean;
22
- private findNode;
23
- /**
24
- * Generates all results that start with the given string.
25
- * @param word A prefix string
26
- * @param {number} [limit=20] The number of results to return.
27
- */
28
- matches: (word: string, limit?: number) => Generator<string>;
29
- /**
30
- * Returns `true` if the given string is found in the tree.
31
- * @param {string} word
32
- */
33
- contains(word: string): boolean;
34
- /**
35
- * Removes all strings from the tree.
36
- */
37
- clear(): void;
38
- /**
39
- * Returns the total number of strings in the tree.
40
- */
41
- get size(): number;
42
- }
@@ -1,104 +0,0 @@
1
- import { Collection } from './abc.js';
2
- function* traverse(node, path, total = 20, count = 0) {
3
- if (node.isWord) {
4
- count++;
5
- yield path;
6
- }
7
- for (const key of Object.keys(node)) {
8
- yield* traverse(node[key], path + key, total, count);
9
- }
10
- }
11
- /**
12
- * A Trie is a tree for efficient storing and retrieval of strings such as words in a dictionary. They are useful for checking all the strings that have a common prefix.
13
- * Insertions, lookups and removals in `O(s)` where `s` is the search term.
14
- * @see {@link https://en.wikipedia.org/wiki/Trie Trie}
15
- */
16
- export class Trie extends Collection {
17
- root = {};
18
- count = 0;
19
- constructor(words) {
20
- super();
21
- if (words) {
22
- for (const word of words) {
23
- this.add(word);
24
- }
25
- }
26
- }
27
- /**
28
- * Adds the given string to the tree.
29
- * @param word A string
30
- */
31
- add(word) {
32
- let current = this.root;
33
- for (let i = 0; i < word.length; i++) {
34
- const c = word[i];
35
- if (!current[c])
36
- current[c] = {};
37
- current = current[c];
38
- }
39
- // Set as end of the word
40
- Object.defineProperty(current, 'isWord', {
41
- value: true,
42
- enumerable: false,
43
- writable: true
44
- });
45
- this.count++;
46
- return this;
47
- }
48
- /**
49
- * Removes the given string from the tree.
50
- * @param word The string to remove
51
- * @returns {boolean} Returns `true` if the string was found and removed.
52
- */
53
- remove(word) {
54
- for (let i = 0, node = this.root; i < word.length && node; i++) {
55
- node = node[word[i]];
56
- if (i === word.length - 1 && node.isWord) {
57
- node.isWord = false;
58
- this.count--;
59
- return true;
60
- }
61
- }
62
- return false;
63
- }
64
- findNode(word) {
65
- let node = this.root;
66
- for (let i = 0; i < word.length && node; i++) {
67
- const letter = word[i];
68
- node = node[letter];
69
- }
70
- return node;
71
- }
72
- /**
73
- * Generates all results that start with the given string.
74
- * @param word A prefix string
75
- * @param {number} [limit=20] The number of results to return.
76
- */
77
- matches = function* (word, limit = 20) {
78
- const node = this.findNode(word);
79
- if (node) {
80
- yield* traverse(node, word, limit);
81
- }
82
- };
83
- /**
84
- * Returns `true` if the given string is found in the tree.
85
- * @param {string} word
86
- */
87
- contains(word) {
88
- const node = this.findNode(word);
89
- return node?.isWord;
90
- }
91
- /**
92
- * Removes all strings from the tree.
93
- */
94
- clear() {
95
- this.root = {};
96
- this.count = 0;
97
- }
98
- /**
99
- * Returns the total number of strings in the tree.
100
- */
101
- get size() {
102
- return this.count;
103
- }
104
- }
@@ -1,152 +0,0 @@
1
- /**
2
- * A container type that provides contains().
3
- *
4
- *
5
- * @interface Container
6
- */
7
- export interface Container {
8
- contains: (x: any) => boolean;
9
- }
10
- /**
11
- * Implements an equality check between two values.
12
- * @interface Ordered
13
- */
14
- export interface Equals {
15
- eq: (other: any) => boolean;
16
- }
17
- /**
18
- * Implements an iterable that allows comparing two elements to determine ordering.
19
- * @interface Ordered
20
- */
21
- export interface Comparable {
22
- compare: (other: any) => number;
23
- }
24
- /**
25
- * Implements an iterable that allows sorting elements.
26
- * @interface Ordered
27
- */
28
- export interface Ordered<T> {
29
- lt: (other: any) => boolean;
30
- }
31
- /**
32
- * Implements an iterable that allows backward iteration.
33
- * @interface Reversible
34
- */
35
- export interface Reversible<T = any> {
36
- reversed: () => Iterable<T>;
37
- }
38
- /**
39
- * A `Collection` is an iterable {@link Container} type.
40
- * This is an abstract base class for user-defined collection types.
41
- *
42
- *
43
- * @abstract
44
- * @class Collection
45
- * @implements {Container}
46
- */
47
- export declare abstract class Collection implements Container {
48
- /**
49
- * Adds a new item to the collection.
50
- * @param item - The item to add to the collection.
51
- */
52
- abstract add(item: any): any;
53
- /**
54
- * Checks if item is present in the collection.
55
- * @param item - The item to search for in the collection.
56
- * @returns `true` when the element is found, else `false`
57
- */
58
- abstract contains(item: any): boolean;
59
- /**
60
- * Remove all items from the collection
61
- */
62
- abstract clear(): any;
63
- /**
64
- * Returns the total number of elements in the collection.
65
- */
66
- abstract get size(): number;
67
- get length(): number;
68
- /**
69
- * Check if there are no items.
70
- * @returns {boolean} `true` if is empty.
71
- */
72
- empty(): boolean;
73
- }
74
- /**
75
- * A sequence is an iterable {@link Collection} type with efficient index-based access.
76
- * @abstract
77
- * @class Sequence
78
- * @extends {Collection}
79
- * @template V
80
- */
81
- export declare abstract class Sequence<V = any, K = any> extends Collection {
82
- /**
83
- * Return the item at the given key or index
84
- * @param {K} key
85
- * @memberof Sequence
86
- */
87
- abstract get(key: K): any;
88
- /**
89
- * Set a new value at the given key or index
90
- *
91
- * @param {K} key
92
- * @param {V} value
93
- * @memberof Sequence
94
- */
95
- abstract set(key: K, value: V): any;
96
- /**
97
- * Adds a new item to the end of the sequence. Alias of {@link Collection.add}.
98
- *
99
- * @param {V} x
100
- * @memberof Sequence
101
- */
102
- abstract append(x: V | Iterable<V>): any;
103
- /**
104
- * Remove a given value from the collection if exists.
105
- * @returns the value that was removed or `undefined`.
106
- */
107
- abstract remove(x: V): any;
108
- /**
109
- * Returns an iterator of all the `keys` in order.
110
- */
111
- abstract keys(): Iterable<K>;
112
- /**
113
- * Returns an iterator of all the `values` in order.
114
- */
115
- abstract values(): Iterable<V>;
116
- /**
117
- * Returns an iterator of all the `[key, value]` pairs in order.
118
- */
119
- abstract entries(): Iterable<[K, V]>;
120
- }
121
- /**
122
- * A mapping is a {@link Collection} indexed by keys that may have associated values.
123
- * @abstract
124
- * @class Mapping
125
- * @extends {Collection}
126
- * @template K, V
127
- */
128
- export declare abstract class Mapping<K, V> extends Collection {
129
- /**
130
- * Returns the value for the given key, or return `defaults` if not found.
131
- * @param {K} key
132
- * @param {*} [defaults]
133
- */
134
- abstract get(key: K, defaults?: any): V | undefined;
135
- /**
136
- * Sets the value for the given key.
137
- * @param {K} key
138
- */
139
- abstract set(key: K, value: V): any;
140
- /**
141
- * Returns an iterator of all the `keys` in the map.
142
- */
143
- abstract keys(): Iterable<K>;
144
- /**
145
- * Returns an iterator of all the `values` in the map.
146
- */
147
- abstract values(): Iterable<V>;
148
- /**
149
- * Returns an iterator of all the `[key, value]` pairs in the map.
150
- */
151
- abstract entries(): Iterable<[K, V]>;
152
- }
@@ -1,39 +0,0 @@
1
- /**
2
- * A `Collection` is an iterable {@link Container} type.
3
- * This is an abstract base class for user-defined collection types.
4
- *
5
- *
6
- * @abstract
7
- * @class Collection
8
- * @implements {Container}
9
- */
10
- export class Collection {
11
- get length() {
12
- return this.size;
13
- }
14
- /**
15
- * Check if there are no items.
16
- * @returns {boolean} `true` if is empty.
17
- */
18
- empty() {
19
- return !this.size;
20
- }
21
- }
22
- /**
23
- * A sequence is an iterable {@link Collection} type with efficient index-based access.
24
- * @abstract
25
- * @class Sequence
26
- * @extends {Collection}
27
- * @template V
28
- */
29
- export class Sequence extends Collection {
30
- }
31
- /**
32
- * A mapping is a {@link Collection} indexed by keys that may have associated values.
33
- * @abstract
34
- * @class Mapping
35
- * @extends {Collection}
36
- * @template K, V
37
- */
38
- export class Mapping extends Collection {
39
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * Returns a new immutable Set object with elements from `iterable`. Its contents cannot be altered after it's created.
3
- *
4
- *
5
- * @class FrozenSet
6
- * @extends {Set<T>}
7
- * @template T
8
- */
9
- export declare class FrozenSet<T = any> extends Set<T> {
10
- constructor(iterable: Iterable<T>);
11
- /** @private */
12
- add(): this;
13
- /** @private */
14
- delete(): boolean;
15
- /** @private */
16
- clear(): this;
17
- /** @private */
18
- freeze(): Readonly<this>;
19
- }