atomic-fns 0.3.4 → 0.4.2

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 (106) hide show
  1. package/README.md +3 -3
  2. package/{core → dist}/collections/BTree.d.ts +6 -6
  3. package/{core → dist}/collections/BTree.js +17 -17
  4. package/{core → dist}/collections/Heap.d.ts +3 -3
  5. package/{core → dist}/collections/Heap.js +0 -0
  6. package/dist/collections/LRUCache.d.ts +80 -0
  7. package/dist/collections/LRUCache.js +126 -0
  8. package/{core → dist}/collections/SortedMap.d.ts +2 -2
  9. package/{core → dist}/collections/SortedMap.js +0 -0
  10. package/{core → dist}/collections/SortedSet.d.ts +3 -3
  11. package/{core → dist}/collections/SortedSet.js +1 -1
  12. package/{core → dist}/collections/SortedTree.d.ts +3 -3
  13. package/{core → dist}/collections/SortedTree.js +1 -1
  14. package/{core → dist}/collections/SplayTree.d.ts +5 -5
  15. package/{core → dist}/collections/SplayTree.js +0 -0
  16. package/{core → dist}/collections/abc.d.ts +1 -1
  17. package/{core → dist}/collections/abc.js +0 -0
  18. package/dist/collections/deque.d.ts +117 -0
  19. package/{core → dist}/collections/deque.js +61 -53
  20. package/{core → dist}/collections/frozenset.d.ts +0 -0
  21. package/{core → dist}/collections/frozenset.js +3 -6
  22. package/{core → dist}/collections/index.d.ts +4 -4
  23. package/{core → dist}/collections/index.js +0 -0
  24. package/{core → dist}/functools/index.d.ts +28 -13
  25. package/{core → dist}/functools/index.js +34 -12
  26. package/{core → dist}/globals/index.d.ts +8 -11
  27. package/{core → dist}/globals/index.js +8 -15
  28. package/dist/i18n/date/index.d.ts +204 -0
  29. package/dist/i18n/date/index.js +530 -0
  30. package/dist/i18n/date/utils.d.ts +65 -0
  31. package/dist/i18n/date/utils.js +312 -0
  32. package/dist/i18n/duration.d.ts +112 -0
  33. package/dist/i18n/duration.js +392 -0
  34. package/dist/i18n/format.d.ts +26 -0
  35. package/dist/i18n/format.js +495 -0
  36. package/{core → dist}/i18n/index.d.ts +1 -1
  37. package/{core → dist}/i18n/index.js +1 -1
  38. package/{core → dist}/index.d.ts +0 -0
  39. package/{core → dist}/index.js +0 -0
  40. package/{core → dist}/itertools/index.d.ts +27 -27
  41. package/{core → dist}/itertools/index.js +24 -24
  42. package/{core → dist}/math/index.d.ts +3 -3
  43. package/{core → dist}/math/index.js +0 -0
  44. package/{core → dist}/operators/index.d.ts +2 -2
  45. package/{core → dist}/operators/index.js +2 -2
  46. package/{core → dist}/random/index.d.ts +1 -1
  47. package/{core → dist}/random/index.js +3 -3
  48. package/package.json +28 -42
  49. package/.editorconfig +0 -12
  50. package/.esdoc.json +0 -27
  51. package/.eslintignore +0 -1
  52. package/.eslintrc.json +0 -35
  53. package/.firebaserc +0 -5
  54. package/.prettierrc +0 -19
  55. package/core/collections/BTree.ts +0 -1340
  56. package/core/collections/Heap.ts +0 -189
  57. package/core/collections/LRUCache.d.ts +0 -152
  58. package/core/collections/LRUCache.js +0 -409
  59. package/core/collections/LRUCache.ts +0 -486
  60. package/core/collections/SortedMap.ts +0 -146
  61. package/core/collections/SortedSet.ts +0 -110
  62. package/core/collections/SortedTree.ts +0 -160
  63. package/core/collections/SplayTree.ts +0 -354
  64. package/core/collections/abc.ts +0 -176
  65. package/core/collections/deque.d.ts +0 -110
  66. package/core/collections/deque.ts +0 -329
  67. package/core/collections/frozenset.ts +0 -37
  68. package/core/collections/index.ts +0 -1024
  69. package/core/collections/test.html +0 -10
  70. package/core/collections/typedArrays.d.ts +0 -31
  71. package/core/collections/typedArrays.js +0 -143
  72. package/core/collections/typedArrays.ts +0 -163
  73. package/core/functools/index.ts +0 -258
  74. package/core/globals/index.ts +0 -481
  75. package/core/i18n/date/format.d.ts +0 -16
  76. package/core/i18n/date/format.js +0 -307
  77. package/core/i18n/date/format.ts +0 -343
  78. package/core/i18n/date/index.d.ts +0 -223
  79. package/core/i18n/date/index.js +0 -387
  80. package/core/i18n/date/index.ts +0 -471
  81. package/core/i18n/date/test.html +0 -67
  82. package/core/i18n/index.ts +0 -8
  83. package/core/index.ts +0 -8
  84. package/core/itertools/index.ts +0 -494
  85. package/core/math/index.ts +0 -152
  86. package/core/operators/index.ts +0 -310
  87. package/core/random/index.ts +0 -66
  88. package/firebase.json +0 -10
  89. package/jasmine.json +0 -14
  90. package/tests/BTree.spec.ts +0 -143
  91. package/tests/Cache.spec.ts +0 -161
  92. package/tests/Heap.spec.ts +0 -66
  93. package/tests/SortedMap.spec.ts +0 -144
  94. package/tests/SortedSet.spec.ts +0 -84
  95. package/tests/SortedTree.spec.ts +0 -164
  96. package/tests/SplayTree.spec.ts +0 -121
  97. package/tests/collections.spec.ts +0 -288
  98. package/tests/deque.spec.ts +0 -107
  99. package/tests/globals.spec.ts +0 -270
  100. package/tests/itertools.spec.ts +0 -266
  101. package/tests/math.spec.ts +0 -25
  102. package/tests/operators.spec.ts +0 -40
  103. package/tests/random.spec.ts +0 -46
  104. package/tsconfig.json +0 -126
  105. package/tsconfig.node.json +0 -18
  106. package/tsconfig.xo.json +0 -9
@@ -1,176 +0,0 @@
1
- /**
2
- * A container type that provides contains().
3
- *
4
- *
5
- * @interface Container
6
- */
7
- export interface Container {
8
- contains: (x) => boolean
9
- }
10
-
11
- /**
12
- * Implements an equality check between two values.
13
- * @interface Ordered
14
- */
15
- export interface Equals {
16
- eq: (other) => boolean
17
- }
18
-
19
- /**
20
- * Implements an iterable that allows comparing two elements to determine ordering.
21
- * @interface Ordered
22
- */
23
- export interface Comparable {
24
- compare: (other) => number
25
- }
26
-
27
- /**
28
- * Implements an iterable that allows sorting elements.
29
- * @interface Ordered
30
- */
31
- export interface Ordered<T> {
32
- lt: (other) => boolean
33
- }
34
-
35
- /**
36
- * Implements an iterable that allows backward iteration.
37
- * @interface Reversible
38
- */
39
- export interface Reversible<T = unknown> {
40
- reversed: () => Iterable<T>
41
- }
42
-
43
- /**
44
- * A `Collection` is an iterable {@link Container} type.
45
- * This is an abstract base class for user-defined collection types.
46
- *
47
- *
48
- * @abstract
49
- * @class Collection
50
- * @implements {Container}
51
- */
52
- export abstract class Collection implements Container {
53
- /**
54
- * Adds a new item to the collection.
55
- * @param item - The item to add to the collection.
56
- */
57
- abstract add(item): any
58
-
59
- /**
60
- * Checks if item is present in the collection.
61
- * @param item - The item to search for in the collection.
62
- * @returns `true` when the element is found, else `false`
63
- */
64
- abstract contains(item): boolean
65
-
66
- /**
67
- * Remove all items from the collection
68
- */
69
- abstract clear()
70
-
71
- /**
72
- * Returns the total number of elements in the collection.
73
- */
74
- abstract get size(): number
75
-
76
- get length() {
77
- return this.size
78
- }
79
-
80
- /**
81
- * Check if there are no items.
82
- * @returns {boolean} `true` if is empty.
83
- */
84
- empty() {
85
- return !this.size
86
- }
87
- }
88
-
89
- /**
90
- * A sequence is an iterable {@link Collection} type with efficient index-based access.
91
- * @abstract
92
- * @class Sequence
93
- * @extends {Collection}
94
- * @template V
95
- */
96
- export abstract class Sequence<V = any, K = any> extends Collection {
97
- /**
98
- * Return the item at the given key or index
99
- * @param {K} key
100
- * @memberof Sequence
101
- */
102
- abstract get(key: K)
103
-
104
- /**
105
- * Set a new value at the given key or index
106
- *
107
- * @param {K} key
108
- * @param {V} value
109
- * @memberof Sequence
110
- */
111
- abstract set(key: K, value: V)
112
-
113
- /**
114
- * Adds a new item to the end of the sequence. Alias of {@link Collection.add}.
115
- *
116
- * @param {V} x
117
- * @memberof Sequence
118
- */
119
- abstract append(x: V | Iterable<V>)
120
-
121
- /**
122
- * Remove a given value from the collection if exists.
123
- * @returns the value that was removed or `undefined`.
124
- */
125
- abstract remove(x: V)
126
-
127
- /**
128
- * Returns an iterator of all the `keys` in order.
129
- */
130
- abstract keys(): Iterable<K>
131
- /**
132
- * Returns an iterator of all the `values` in order.
133
- */
134
- abstract values(): Iterable<V>
135
-
136
- /**
137
- * Returns an iterator of all the `[key, value]` pairs in order.
138
- */
139
- abstract entries(): Iterable<[K, V]>
140
- }
141
-
142
- /**
143
- * A mapping is a {@link Collection} indexed by keys that may have associated values.
144
- * @abstract
145
- * @class Mapping
146
- * @extends {Collection}
147
- * @template K, V
148
- */
149
- export abstract class Mapping<K, V> extends Collection {
150
- /**
151
- * Returns the value for the given key, or return `defaults` if not found.
152
- * @param {K} key
153
- * @param {*} [defaults]
154
- */
155
- abstract get(key: K, defaults?): V | undefined
156
-
157
- /**
158
- * Sets the value for the given key.
159
- * @param {K} key
160
- */
161
- abstract set(key: K, value: V)
162
-
163
- /**
164
- * Returns an iterator of all the `keys` in the map.
165
- */
166
- abstract keys(): Iterable<K>
167
- /**
168
- * Returns an iterator of all the `values` in the map.
169
- */
170
- abstract values(): Iterable<V>
171
-
172
- /**
173
- * Returns an iterator of all the `[key, value]` pairs in the map.
174
- */
175
- abstract entries(): Iterable<[K, V]>
176
- }
@@ -1,110 +0,0 @@
1
- import { Iteratee } from '../globals/index.js';
2
- import { Sequence } from './abc.js';
3
- /**
4
- * Fixed capacity double-ended queue implemented as ring deque.
5
- *
6
- * @constructor
7
- */
8
- export declare class Deque<T> extends Sequence<T> {
9
- items: T[];
10
- start: number;
11
- count: number;
12
- capacity: number;
13
- ArrayClass: any;
14
- constructor(ArrayClass?: T[], capacity?: number);
15
- get size(): number;
16
- /**
17
- * Method used to clear the structure.
18
- *
19
- * @return {undefined}
20
- */
21
- clear(): void;
22
- /**
23
- * Alias of {@link Deque.append}
24
- *
25
- * @param {any} item - Item to append.
26
- * @return {number} - Returns the new size of the deque.
27
- */
28
- add(item: any): number;
29
- /**
30
- * Method used to append a value to the deque.
31
- *
32
- * @param {any} item - Item to append.
33
- * @return {number} - Returns the new size of the deque.
34
- */
35
- append(item: any): number;
36
- /**
37
- * Method used to prepend a value to the deque.
38
- *
39
- * @param {any} item - Item to prepend.
40
- * @return {number} - Returns the new size of the deque.
41
- */
42
- appendleft(item: any): number;
43
- /**
44
- * Method used to pop the deque.
45
- *
46
- * @return {any} - Returns the popped item.
47
- */
48
- pop(): T | undefined;
49
- /**
50
- * Alias of {@link Deque.pop}
51
- */
52
- remove(): T | undefined;
53
- /**
54
- * Method used to shift the deque.
55
- *
56
- * @return {any} - Returns the shifted item.
57
- */
58
- popleft(): T | undefined;
59
- /**
60
- * Method used to peek the first value of the deque.
61
- *
62
- * @return {any}
63
- */
64
- first(): T | undefined;
65
- /**
66
- * Method used to get the desired value of the deque.
67
- *
68
- * @param {number} index
69
- * @return {any}
70
- */
71
- get(index: any): T | undefined;
72
- /**
73
- * Update the value at a given `index`.
74
- * @param index The given index
75
- * @param value The new value to set at `index`.
76
- */
77
- set(index: number, value: T): void;
78
- contains(x: any): boolean;
79
- find(iteratee: Iteratee<T>): T | undefined;
80
- /**
81
- * Method used to iterate over the deque.
82
- *
83
- * @param {function} iteratee - Function to call for each item.
84
- * @param {object} scope - Optional scope.
85
- * @return {undefined}
86
- */
87
- forEach(iteratee: any): void;
88
- reversed(): any;
89
- /**
90
- * Method used to convert the deque to a JavaScript array.
91
- *
92
- * @return {array}
93
- */
94
- toArray(): any;
95
- /**
96
- * Method used to create an iterator over the deque's values.
97
- *
98
- * @return {Iterator}
99
- */
100
- values(): Iterable<T>;
101
- keys(): Iterable<T>;
102
- /**
103
- * Method used to create an iterator over the deque's entries.
104
- *
105
- * @return {Iterator}
106
- */
107
- entries(): Iterator<[number, T], any, undefined> & Iterable<[number, T]>;
108
- [Symbol.iterator](): Iterable<T>;
109
- inspect(): any;
110
- }
@@ -1,329 +0,0 @@
1
- import { Iteratee, KeyError, ValueError } from '../globals/index.js'
2
- import { IterableIterator } from '../itertools/index.js'
3
- import { eq } from '../operators/index.js'
4
- import { Sequence } from './abc.js'
5
-
6
- /**
7
- * Fixed capacity double-ended queue implemented as ring deque.
8
- *
9
- * @constructor
10
- */
11
- export class Deque<T> extends Sequence<T> {
12
- items: T[]
13
- start: number = 0
14
- count: number = 0
15
- capacity: number
16
- ArrayClass: any
17
-
18
- constructor(ArrayClass = [] as T[], capacity = 1024) {
19
- super()
20
- if (typeof capacity !== 'number' || capacity <= 0)
21
- throw new ValueError(`Deque capacity should be a positive integer.`)
22
-
23
- this.ArrayClass = ArrayClass.constructor
24
- this.capacity = capacity
25
- this.items = new this.ArrayClass(ArrayClass.length || this.capacity)
26
- this.clear()
27
- if (ArrayClass.length) {
28
- for (const item of ArrayClass) {
29
- this.append(item)
30
- }
31
- }
32
- }
33
-
34
- get size() {
35
- return this.count
36
- }
37
-
38
- /**
39
- * Method used to clear the structure.
40
- *
41
- * @return {undefined}
42
- */
43
- clear() {
44
- // Properties
45
- this.start = 0
46
- this.count = 0
47
- }
48
-
49
- /**
50
- * Alias of {@link Deque.append}
51
- *
52
- * @param {any} item - Item to append.
53
- * @return {number} - Returns the new size of the deque.
54
- */
55
- add(item) {
56
- return this.append(item)
57
- }
58
-
59
- /**
60
- * Method used to append a value to the deque.
61
- *
62
- * @param {any} item - Item to append.
63
- * @return {number} - Returns the new size of the deque.
64
- */
65
- append(item) {
66
- if (this.count === this.capacity) this.popleft()
67
-
68
- const index = (this.start + this.count) % this.capacity
69
-
70
- this.items[index] = item
71
-
72
- return ++this.count
73
- }
74
-
75
- /**
76
- * Method used to prepend a value to the deque.
77
- *
78
- * @param {any} item - Item to prepend.
79
- * @return {number} - Returns the new size of the deque.
80
- */
81
- appendleft(item) {
82
- if (this.count === this.capacity) this.pop()
83
-
84
- let index = this.start - 1
85
-
86
- if (this.start === 0) index = this.capacity - 1
87
-
88
- this.items[index] = item
89
- this.start = index
90
-
91
- return ++this.count
92
- }
93
-
94
- /**
95
- * Method used to pop the deque.
96
- *
97
- * @return {any} - Returns the popped item.
98
- */
99
- pop() {
100
- if (this.count === 0) return
101
-
102
- const index = (this.start + this.count - 1) % this.capacity
103
-
104
- this.count--
105
-
106
- return this.items[index]
107
- }
108
-
109
- /**
110
- * Alias of {@link Deque.pop}
111
- */
112
- remove() {
113
- return this.pop()
114
- }
115
-
116
- /**
117
- * Method used to shift the deque.
118
- *
119
- * @return {any} - Returns the shifted item.
120
- */
121
- popleft() {
122
- if (this.count === 0) return
123
-
124
- const index = this.start
125
-
126
- this.count--
127
- this.start++
128
-
129
- if (this.start === this.capacity) this.start = 0
130
-
131
- return this.items[index]
132
- }
133
-
134
- /**
135
- * Method used to peek the first value of the deque.
136
- *
137
- * @return {any}
138
- */
139
- first() {
140
- if (this.count === 0) return
141
-
142
- return this.items[this.start]
143
- }
144
-
145
- /**
146
- * Method used to get the desired value of the deque.
147
- *
148
- * @param {number} index
149
- * @return {any}
150
- */
151
- get(index) {
152
- if (this.count === 0) return
153
-
154
- index = this.start + index
155
- if (index < 0) index += this.count
156
-
157
- if (index > this.capacity) index -= this.capacity
158
-
159
- return this.items[index]
160
- }
161
-
162
- /**
163
- * Update the value at a given `index`.
164
- * @param index The given index
165
- * @param value The new value to set at `index`.
166
- */
167
- set(index: number, value: T) {
168
- if (index < 0) index += this.count
169
- if (index > this.count) throw new KeyError(`Invalid index: ${index} not in Deque.`)
170
- this.items[index] = value
171
- }
172
-
173
- contains(x) {
174
- for (const value of this.values()) {
175
- if (eq(x, value)) return true
176
- }
177
- return false
178
- }
179
-
180
- find(iteratee: Iteratee<T>) {
181
- for (const [key, value] of this.entries()) {
182
- if (iteratee(value, key, this)) return value
183
- }
184
- }
185
-
186
- /**
187
- * Method used to iterate over the deque.
188
- *
189
- * @param {function} iteratee - Function to call for each item.
190
- * @param {object} scope - Optional scope.
191
- * @return {undefined}
192
- */
193
- forEach(iteratee) {
194
- const c = this.capacity
195
- const l = this.count
196
- let i = this.start
197
- let j = 0
198
-
199
- while (j < l) {
200
- iteratee(this.items[i], j, this)
201
- i++
202
- j++
203
-
204
- if (i === c) i = 0
205
- }
206
- }
207
-
208
- reversed() {
209
- return this.toArray().reverse()
210
- }
211
-
212
- /**
213
- * Method used to convert the deque to a JavaScript array.
214
- *
215
- * @return {array}
216
- */
217
- toArray() {
218
- // Optimization
219
- const offset = this.start + this.count
220
-
221
- if (offset < this.capacity) return this.items.slice(this.start, offset)
222
-
223
- const array = new this.ArrayClass(this.count)
224
- const c = this.capacity
225
- const l = this.count
226
- let i = this.start
227
- let j = 0
228
-
229
- while (j < l) {
230
- array[j] = this.items[i]
231
- i++
232
- j++
233
-
234
- if (i === c) i = 0
235
- }
236
-
237
- return array
238
- }
239
-
240
- /**
241
- * Method used to create an iterator over the deque's values.
242
- *
243
- * @return {Iterator}
244
- */
245
- values(): Iterable<T> {
246
- const items = this.items
247
- const c = this.capacity
248
- const l = this.count
249
- let i = this.start
250
- let j = 0
251
-
252
- return IterableIterator(() => {
253
- if (j >= l)
254
- return {
255
- done: true
256
- }
257
-
258
- const value = items[i]
259
-
260
- i++
261
- j++
262
-
263
- if (i === c) i = 0
264
-
265
- return {
266
- value,
267
- done: false
268
- }
269
- })
270
- }
271
-
272
- keys() {
273
- return this.values()
274
- }
275
-
276
- /**
277
- * Method used to create an iterator over the deque's entries.
278
- *
279
- * @return {Iterator}
280
- */
281
- entries() {
282
- const items = this.items
283
- const c = this.capacity
284
- const l = this.count
285
- let i = this.start
286
- let j = 0
287
-
288
- return IterableIterator<[number, T]>(() => {
289
- if (j >= l)
290
- return {
291
- done: true
292
- }
293
-
294
- const value = items[i]
295
-
296
- i++
297
-
298
- if (i === c) i = 0
299
-
300
- return {
301
- value: [j++, value],
302
- done: false
303
- }
304
- })
305
- }
306
-
307
- [Symbol.iterator]() {
308
- return this.values()
309
- }
310
-
311
- [Symbol.for('nodejs.util.inspect.custom')]() {
312
- return this.inspect()
313
- }
314
-
315
- inspect() {
316
- const array = this.toArray()
317
-
318
- array.type = this.ArrayClass.name
319
- array.capacity = this.capacity
320
-
321
- // Trick so that node displays the name of the constructor
322
- Object.defineProperty(array, 'constructor', {
323
- value: Deque,
324
- enumerable: false
325
- })
326
-
327
- return array
328
- }
329
- }
@@ -1,37 +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 class FrozenSet<T = any> extends Set<T> {
10
- constructor(iterable: Iterable<T>) {
11
- super(iterable)
12
- return this.freeze()
13
- }
14
-
15
- /** @private */
16
- add() {
17
- throw TypeError('FrozenSet cannot be modified.')
18
- return this // eslint-disable-line
19
- }
20
-
21
- /** @private */
22
- delete() {
23
- throw TypeError('FrozenSet cannot be modified.')
24
- return false // eslint-disable-line
25
- }
26
-
27
- /** @private */
28
- clear() {
29
- throw TypeError('FrozenSet cannot be modified.')
30
- return this // eslint-disable-line
31
- }
32
-
33
- /** @private */
34
- freeze() {
35
- return Object.freeze(this)
36
- }
37
- }