atomic-fns 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,7 +21,7 @@ You may prefer this because it's:
21
21
 
22
22
  ## Get Started
23
23
 
24
- This library is available as an npm package.
24
+ This library is available as an [npm package](https://www.npmjs.com/package/atomic-fns).
25
25
 
26
26
  To install the package you need to have [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) (or [yarn](https://yarnpkg.com/getting-started/install)) and then run:
27
27
 
@@ -32,7 +32,7 @@ export interface Ordered<T> {
32
32
  * Implements an iterable that allows backward iteration.
33
33
  * @interface Reversible
34
34
  */
35
- export interface Reversible<T = unknown> {
35
+ export interface Reversible<T = any> {
36
36
  reversed: () => Iterable<T>;
37
37
  }
38
38
  /**
@@ -36,7 +36,7 @@ export interface Ordered<T> {
36
36
  * Implements an iterable that allows backward iteration.
37
37
  * @interface Reversible
38
38
  */
39
- export interface Reversible<T = unknown> {
39
+ export interface Reversible<T = any> {
40
40
  reversed: () => Iterable<T>
41
41
  }
42
42
 
@@ -2,107 +2,114 @@ import { Iteratee } from '../globals/index.js';
2
2
  import { Sequence } from './abc.js';
3
3
  /**
4
4
  * Fixed capacity double-ended queue implemented as ring deque.
5
- *
6
- * @constructor
5
+ * @template T
7
6
  */
8
- export declare class Deque<T> extends Sequence<T> {
7
+ export declare class Deque<T = any> extends Sequence<T> {
9
8
  items: T[];
10
9
  start: number;
11
10
  count: number;
12
11
  capacity: number;
13
- ArrayClass: any;
14
- constructor(ArrayClass?: T[], capacity?: number);
12
+ ArrayConstructor: any;
13
+ /**
14
+ * Creates a new `Deque` instance of a fixed size.
15
+ * @param {Array} [arrType = []] The initial elements or array type to use (accepts any kind of typed array).
16
+ * @param {number} [capacity=1024] The fixed size of the deque. Defaults to `1024`.
17
+ */
18
+ constructor(arrType?: T[], capacity?: number);
19
+ /** Returns the total number of elements in the deque. */
15
20
  get size(): number;
16
21
  /**
17
22
  * Method used to clear the structure.
18
- *
19
- * @return {undefined}
20
23
  */
21
24
  clear(): void;
22
25
  /**
23
26
  * Alias of {@link Deque.append}
24
- *
25
- * @param {any} item - Item to append.
26
- * @return {number} - Returns the new size of the deque.
27
+ * @param {T} item Item to append.
28
+ * @returns {number} Returns the new size of the deque.
27
29
  */
28
30
  add(item: any): number;
29
31
  /**
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.
32
+ * Appends a new element to the end of the deque.
33
+ * @param {T} item Item to append.
34
+ * @returns {number} Returns the new size of the deque.
34
35
  */
35
36
  append(item: any): number;
36
37
  /**
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.
38
+ * Appends a new element to the beginning of the deque.
39
+ * @param {T} item Item to prepend.
40
+ * @returns {number} Returns the new size of the deque.
41
41
  */
42
42
  appendleft(item: any): number;
43
43
  /**
44
- * Method used to pop the deque.
45
- *
46
- * @return {any} - Returns the popped item.
44
+ * Removes and returns the element at the end of the deque.
45
+ * @returns {?T} Returns the popped item.
47
46
  */
48
47
  pop(): T | undefined;
49
48
  /**
50
49
  * Alias of {@link Deque.pop}
50
+ * @returns {?T} Returns the popped item.
51
51
  */
52
52
  remove(): T | undefined;
53
53
  /**
54
- * Method used to shift the deque.
55
- *
56
- * @return {any} - Returns the shifted item.
54
+ * Removes and returns the element at the beginning of the deque.
55
+ * @returns {?T} Returns the removed deque element.
57
56
  */
58
57
  popleft(): T | undefined;
59
58
  /**
60
- * Method used to peek the first value of the deque.
61
- *
62
- * @return {any}
59
+ * Returns the element at the beginning of the deque.
60
+ * @returns {?T} The element if exists
63
61
  */
64
62
  first(): T | undefined;
65
63
  /**
66
- * Method used to get the desired value of the deque.
67
- *
68
- * @param {number} index
69
- * @return {any}
64
+ * Returns the element at a specified index position in the deque.
65
+ * @param {number} index The given index
66
+ * @returns {?T} The element if exists
70
67
  */
71
68
  get(index: any): T | undefined;
72
69
  /**
73
- * Update the value at a given `index`.
74
- * @param index The given index
75
- * @param value The new value to set at `index`.
70
+ * Update the element at a given `index`.
71
+ * @param {number} index The given index
76
72
  */
77
73
  set(index: number, value: T): void;
74
+ /**
75
+ * Check if a given element is in the deque.
76
+ * @param {T} x The value to find
77
+ * @returns {boolean} `true` if the value is found
78
+ */
78
79
  contains(x: any): boolean;
80
+ /**
81
+ * Returns the first element that matches the `iteratee` function.
82
+ * @param {Iteratee<T>} iteratee A function that will be invoked per element
83
+ * @returns {?T} The element if exists
84
+ */
79
85
  find(iteratee: Iteratee<T>): T | undefined;
80
86
  /**
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}
87
+ * Calls `iteratee` function for every element in the deque.
88
+ * @param {Iteratee<T>} iteratee A function that will be invoked per element
86
89
  */
87
90
  forEach(iteratee: any): void;
91
+ /**
92
+ * Returns a new array with all the elements in reverse order.
93
+ * @returns {Array<T>} The elements reversed
94
+ */
88
95
  reversed(): any;
89
96
  /**
90
- * Method used to convert the deque to a JavaScript array.
91
- *
92
- * @return {array}
97
+ * Returns a new array with all the elements in the order they were added to the deque.
98
+ * @returns {Array<T>} The elements array
93
99
  */
94
100
  toArray(): any;
95
101
  /**
96
- * Method used to create an iterator over the deque's values.
97
- *
98
- * @return {Iterator}
102
+ * Returns an iterator over the deque's values.
103
+ * @returns {Iterator}
99
104
  */
100
105
  values(): Iterable<T>;
106
+ /**
107
+ * Alias of {@link Deque.values}. Returns iterator of values.
108
+ */
101
109
  keys(): Iterable<T>;
102
110
  /**
103
- * Method used to create an iterator over the deque's entries.
104
- *
105
- * @return {Iterator}
111
+ * Creates an iterator of `[index, value]` pairs for all elements in the deque.
112
+ * @returns {Iterator}
106
113
  */
107
114
  entries(): Iterator<[number, T], any, undefined> & Iterable<[number, T]>;
108
115
  [Symbol.iterator](): Iterable<T>;
@@ -4,36 +4,39 @@ import { eq } from '../operators/index.js';
4
4
  import { Sequence } from './abc.js';
5
5
  /**
6
6
  * Fixed capacity double-ended queue implemented as ring deque.
7
- *
8
- * @constructor
7
+ * @template T
9
8
  */
10
9
  export class Deque extends Sequence {
11
10
  items;
12
11
  start = 0;
13
12
  count = 0;
14
13
  capacity;
15
- ArrayClass;
16
- constructor(ArrayClass = [], capacity = 1024) {
14
+ ArrayConstructor;
15
+ /**
16
+ * Creates a new `Deque` instance of a fixed size.
17
+ * @param {Array} [arrType = []] The initial elements or array type to use (accepts any kind of typed array).
18
+ * @param {number} [capacity=1024] The fixed size of the deque. Defaults to `1024`.
19
+ */
20
+ constructor(arrType = [], capacity = 1024) {
17
21
  super();
18
22
  if (typeof capacity !== 'number' || capacity <= 0)
19
23
  throw new ValueError(`Deque capacity should be a positive integer.`);
20
- this.ArrayClass = ArrayClass.constructor;
24
+ this.ArrayConstructor = arrType.constructor;
21
25
  this.capacity = capacity;
22
- this.items = new this.ArrayClass(ArrayClass.length || this.capacity);
26
+ this.items = new this.ArrayConstructor(arrType.length || this.capacity);
23
27
  this.clear();
24
- if (ArrayClass.length) {
25
- for (const item of ArrayClass) {
28
+ if (arrType.length) {
29
+ for (const item of arrType) {
26
30
  this.append(item);
27
31
  }
28
32
  }
29
33
  }
34
+ /** Returns the total number of elements in the deque. */
30
35
  get size() {
31
36
  return this.count;
32
37
  }
33
38
  /**
34
39
  * Method used to clear the structure.
35
- *
36
- * @return {undefined}
37
40
  */
38
41
  clear() {
39
42
  // Properties
@@ -42,18 +45,16 @@ export class Deque extends Sequence {
42
45
  }
43
46
  /**
44
47
  * Alias of {@link Deque.append}
45
- *
46
- * @param {any} item - Item to append.
47
- * @return {number} - Returns the new size of the deque.
48
+ * @param {T} item Item to append.
49
+ * @returns {number} Returns the new size of the deque.
48
50
  */
49
51
  add(item) {
50
52
  return this.append(item);
51
53
  }
52
54
  /**
53
- * Method used to append a value to the deque.
54
- *
55
- * @param {any} item - Item to append.
56
- * @return {number} - Returns the new size of the deque.
55
+ * Appends a new element to the end of the deque.
56
+ * @param {T} item Item to append.
57
+ * @returns {number} Returns the new size of the deque.
57
58
  */
58
59
  append(item) {
59
60
  if (this.count === this.capacity)
@@ -63,10 +64,9 @@ export class Deque extends Sequence {
63
64
  return ++this.count;
64
65
  }
65
66
  /**
66
- * Method used to prepend a value to the deque.
67
- *
68
- * @param {any} item - Item to prepend.
69
- * @return {number} - Returns the new size of the deque.
67
+ * Appends a new element to the beginning of the deque.
68
+ * @param {T} item Item to prepend.
69
+ * @returns {number} Returns the new size of the deque.
70
70
  */
71
71
  appendleft(item) {
72
72
  if (this.count === this.capacity)
@@ -79,9 +79,8 @@ export class Deque extends Sequence {
79
79
  return ++this.count;
80
80
  }
81
81
  /**
82
- * Method used to pop the deque.
83
- *
84
- * @return {any} - Returns the popped item.
82
+ * Removes and returns the element at the end of the deque.
83
+ * @returns {?T} Returns the popped item.
85
84
  */
86
85
  pop() {
87
86
  if (this.count === 0)
@@ -92,14 +91,14 @@ export class Deque extends Sequence {
92
91
  }
93
92
  /**
94
93
  * Alias of {@link Deque.pop}
94
+ * @returns {?T} Returns the popped item.
95
95
  */
96
96
  remove() {
97
97
  return this.pop();
98
98
  }
99
99
  /**
100
- * Method used to shift the deque.
101
- *
102
- * @return {any} - Returns the shifted item.
100
+ * Removes and returns the element at the beginning of the deque.
101
+ * @returns {?T} Returns the removed deque element.
103
102
  */
104
103
  popleft() {
105
104
  if (this.count === 0)
@@ -112,9 +111,8 @@ export class Deque extends Sequence {
112
111
  return this.items[index];
113
112
  }
114
113
  /**
115
- * Method used to peek the first value of the deque.
116
- *
117
- * @return {any}
114
+ * Returns the element at the beginning of the deque.
115
+ * @returns {?T} The element if exists
118
116
  */
119
117
  first() {
120
118
  if (this.count === 0)
@@ -122,10 +120,9 @@ export class Deque extends Sequence {
122
120
  return this.items[this.start];
123
121
  }
124
122
  /**
125
- * Method used to get the desired value of the deque.
126
- *
127
- * @param {number} index
128
- * @return {any}
123
+ * Returns the element at a specified index position in the deque.
124
+ * @param {number} index The given index
125
+ * @returns {?T} The element if exists
129
126
  */
130
127
  get(index) {
131
128
  if (this.count === 0)
@@ -138,9 +135,8 @@ export class Deque extends Sequence {
138
135
  return this.items[index];
139
136
  }
140
137
  /**
141
- * Update the value at a given `index`.
142
- * @param index The given index
143
- * @param value The new value to set at `index`.
138
+ * Update the element at a given `index`.
139
+ * @param {number} index The given index
144
140
  */
145
141
  set(index, value) {
146
142
  if (index < 0)
@@ -149,6 +145,11 @@ export class Deque extends Sequence {
149
145
  throw new KeyError(`Invalid index: ${index} not in Deque.`);
150
146
  this.items[index] = value;
151
147
  }
148
+ /**
149
+ * Check if a given element is in the deque.
150
+ * @param {T} x The value to find
151
+ * @returns {boolean} `true` if the value is found
152
+ */
152
153
  contains(x) {
153
154
  for (const value of this.values()) {
154
155
  if (eq(x, value))
@@ -156,6 +157,11 @@ export class Deque extends Sequence {
156
157
  }
157
158
  return false;
158
159
  }
160
+ /**
161
+ * Returns the first element that matches the `iteratee` function.
162
+ * @param {Iteratee<T>} iteratee A function that will be invoked per element
163
+ * @returns {?T} The element if exists
164
+ */
159
165
  find(iteratee) {
160
166
  for (const [key, value] of this.entries()) {
161
167
  if (iteratee(value, key, this))
@@ -163,11 +169,8 @@ export class Deque extends Sequence {
163
169
  }
164
170
  }
165
171
  /**
166
- * Method used to iterate over the deque.
167
- *
168
- * @param {function} iteratee - Function to call for each item.
169
- * @param {object} scope - Optional scope.
170
- * @return {undefined}
172
+ * Calls `iteratee` function for every element in the deque.
173
+ * @param {Iteratee<T>} iteratee A function that will be invoked per element
171
174
  */
172
175
  forEach(iteratee) {
173
176
  const c = this.capacity;
@@ -182,20 +185,23 @@ export class Deque extends Sequence {
182
185
  i = 0;
183
186
  }
184
187
  }
188
+ /**
189
+ * Returns a new array with all the elements in reverse order.
190
+ * @returns {Array<T>} The elements reversed
191
+ */
185
192
  reversed() {
186
193
  return this.toArray().reverse();
187
194
  }
188
195
  /**
189
- * Method used to convert the deque to a JavaScript array.
190
- *
191
- * @return {array}
196
+ * Returns a new array with all the elements in the order they were added to the deque.
197
+ * @returns {Array<T>} The elements array
192
198
  */
193
199
  toArray() {
194
200
  // Optimization
195
201
  const offset = this.start + this.count;
196
202
  if (offset < this.capacity)
197
203
  return this.items.slice(this.start, offset);
198
- const array = new this.ArrayClass(this.count);
204
+ const array = new this.ArrayConstructor(this.count);
199
205
  const c = this.capacity;
200
206
  const l = this.count;
201
207
  let i = this.start;
@@ -210,9 +216,8 @@ export class Deque extends Sequence {
210
216
  return array;
211
217
  }
212
218
  /**
213
- * Method used to create an iterator over the deque's values.
214
- *
215
- * @return {Iterator}
219
+ * Returns an iterator over the deque's values.
220
+ * @returns {Iterator}
216
221
  */
217
222
  values() {
218
223
  const items = this.items;
@@ -236,13 +241,15 @@ export class Deque extends Sequence {
236
241
  };
237
242
  });
238
243
  }
244
+ /**
245
+ * Alias of {@link Deque.values}. Returns iterator of values.
246
+ */
239
247
  keys() {
240
248
  return this.values();
241
249
  }
242
250
  /**
243
- * Method used to create an iterator over the deque's entries.
244
- *
245
- * @return {Iterator}
251
+ * Creates an iterator of `[index, value]` pairs for all elements in the deque.
252
+ * @returns {Iterator}
246
253
  */
247
254
  entries() {
248
255
  const items = this.items;
@@ -271,9 +278,10 @@ export class Deque extends Sequence {
271
278
  [Symbol.for('nodejs.util.inspect.custom')]() {
272
279
  return this.inspect();
273
280
  }
281
+ // This is just for debugging in nodejs
274
282
  inspect() {
275
283
  const array = this.toArray();
276
- array.type = this.ArrayClass.name;
284
+ array.type = this.ArrayConstructor.name;
277
285
  array.capacity = this.capacity;
278
286
  // Trick so that node displays the name of the constructor
279
287
  Object.defineProperty(array, 'constructor', {
@@ -5,40 +5,44 @@ import { Sequence } from './abc.js'
5
5
 
6
6
  /**
7
7
  * Fixed capacity double-ended queue implemented as ring deque.
8
- *
9
- * @constructor
8
+ * @template T
10
9
  */
11
- export class Deque<T> extends Sequence<T> {
10
+ export class Deque<T = any> extends Sequence<T> {
12
11
  items: T[]
13
12
  start: number = 0
14
13
  count: number = 0
15
14
  capacity: number
16
- ArrayClass: any
15
+ ArrayConstructor: any
17
16
 
18
- constructor(ArrayClass = [] as T[], capacity = 1024) {
17
+ /**
18
+ * Creates a new `Deque` instance of a fixed size.
19
+ * @param {Array} [arrType = []] The initial elements or array type to use (accepts any kind of typed array).
20
+ * @param {number} [capacity=1024] The fixed size of the deque. Defaults to `1024`.
21
+ */
22
+ constructor(arrType = [] as T[], capacity = 1024) {
19
23
  super()
20
24
  if (typeof capacity !== 'number' || capacity <= 0)
21
25
  throw new ValueError(`Deque capacity should be a positive integer.`)
22
26
 
23
- this.ArrayClass = ArrayClass.constructor
27
+ this.ArrayConstructor = arrType.constructor
24
28
  this.capacity = capacity
25
- this.items = new this.ArrayClass(ArrayClass.length || this.capacity)
29
+ this.items = new this.ArrayConstructor(arrType.length || this.capacity)
26
30
  this.clear()
27
- if (ArrayClass.length) {
28
- for (const item of ArrayClass) {
31
+
32
+ if (arrType.length) {
33
+ for (const item of arrType) {
29
34
  this.append(item)
30
35
  }
31
36
  }
32
37
  }
33
38
 
39
+ /** Returns the total number of elements in the deque. */
34
40
  get size() {
35
41
  return this.count
36
42
  }
37
43
 
38
44
  /**
39
45
  * Method used to clear the structure.
40
- *
41
- * @return {undefined}
42
46
  */
43
47
  clear() {
44
48
  // Properties
@@ -48,19 +52,17 @@ export class Deque<T> extends Sequence<T> {
48
52
 
49
53
  /**
50
54
  * Alias of {@link Deque.append}
51
- *
52
- * @param {any} item - Item to append.
53
- * @return {number} - Returns the new size of the deque.
55
+ * @param {T} item Item to append.
56
+ * @returns {number} Returns the new size of the deque.
54
57
  */
55
58
  add(item) {
56
59
  return this.append(item)
57
60
  }
58
61
 
59
62
  /**
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.
63
+ * Appends a new element to the end of the deque.
64
+ * @param {T} item Item to append.
65
+ * @returns {number} Returns the new size of the deque.
64
66
  */
65
67
  append(item) {
66
68
  if (this.count === this.capacity) this.popleft()
@@ -73,10 +75,9 @@ export class Deque<T> extends Sequence<T> {
73
75
  }
74
76
 
75
77
  /**
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.
78
+ * Appends a new element to the beginning of the deque.
79
+ * @param {T} item Item to prepend.
80
+ * @returns {number} Returns the new size of the deque.
80
81
  */
81
82
  appendleft(item) {
82
83
  if (this.count === this.capacity) this.pop()
@@ -92,9 +93,8 @@ export class Deque<T> extends Sequence<T> {
92
93
  }
93
94
 
94
95
  /**
95
- * Method used to pop the deque.
96
- *
97
- * @return {any} - Returns the popped item.
96
+ * Removes and returns the element at the end of the deque.
97
+ * @returns {?T} Returns the popped item.
98
98
  */
99
99
  pop() {
100
100
  if (this.count === 0) return
@@ -108,15 +108,15 @@ export class Deque<T> extends Sequence<T> {
108
108
 
109
109
  /**
110
110
  * Alias of {@link Deque.pop}
111
+ * @returns {?T} Returns the popped item.
111
112
  */
112
113
  remove() {
113
114
  return this.pop()
114
115
  }
115
116
 
116
117
  /**
117
- * Method used to shift the deque.
118
- *
119
- * @return {any} - Returns the shifted item.
118
+ * Removes and returns the element at the beginning of the deque.
119
+ * @returns {?T} Returns the removed deque element.
120
120
  */
121
121
  popleft() {
122
122
  if (this.count === 0) return
@@ -132,9 +132,8 @@ export class Deque<T> extends Sequence<T> {
132
132
  }
133
133
 
134
134
  /**
135
- * Method used to peek the first value of the deque.
136
- *
137
- * @return {any}
135
+ * Returns the element at the beginning of the deque.
136
+ * @returns {?T} The element if exists
138
137
  */
139
138
  first() {
140
139
  if (this.count === 0) return
@@ -143,10 +142,9 @@ export class Deque<T> extends Sequence<T> {
143
142
  }
144
143
 
145
144
  /**
146
- * Method used to get the desired value of the deque.
147
- *
148
- * @param {number} index
149
- * @return {any}
145
+ * Returns the element at a specified index position in the deque.
146
+ * @param {number} index The given index
147
+ * @returns {?T} The element if exists
150
148
  */
151
149
  get(index) {
152
150
  if (this.count === 0) return
@@ -160,9 +158,8 @@ export class Deque<T> extends Sequence<T> {
160
158
  }
161
159
 
162
160
  /**
163
- * Update the value at a given `index`.
164
- * @param index The given index
165
- * @param value The new value to set at `index`.
161
+ * Update the element at a given `index`.
162
+ * @param {number} index The given index
166
163
  */
167
164
  set(index: number, value: T) {
168
165
  if (index < 0) index += this.count
@@ -170,6 +167,11 @@ export class Deque<T> extends Sequence<T> {
170
167
  this.items[index] = value
171
168
  }
172
169
 
170
+ /**
171
+ * Check if a given element is in the deque.
172
+ * @param {T} x The value to find
173
+ * @returns {boolean} `true` if the value is found
174
+ */
173
175
  contains(x) {
174
176
  for (const value of this.values()) {
175
177
  if (eq(x, value)) return true
@@ -177,6 +179,11 @@ export class Deque<T> extends Sequence<T> {
177
179
  return false
178
180
  }
179
181
 
182
+ /**
183
+ * Returns the first element that matches the `iteratee` function.
184
+ * @param {Iteratee<T>} iteratee A function that will be invoked per element
185
+ * @returns {?T} The element if exists
186
+ */
180
187
  find(iteratee: Iteratee<T>) {
181
188
  for (const [key, value] of this.entries()) {
182
189
  if (iteratee(value, key, this)) return value
@@ -184,11 +191,8 @@ export class Deque<T> extends Sequence<T> {
184
191
  }
185
192
 
186
193
  /**
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}
194
+ * Calls `iteratee` function for every element in the deque.
195
+ * @param {Iteratee<T>} iteratee A function that will be invoked per element
192
196
  */
193
197
  forEach(iteratee) {
194
198
  const c = this.capacity
@@ -205,14 +209,17 @@ export class Deque<T> extends Sequence<T> {
205
209
  }
206
210
  }
207
211
 
212
+ /**
213
+ * Returns a new array with all the elements in reverse order.
214
+ * @returns {Array<T>} The elements reversed
215
+ */
208
216
  reversed() {
209
217
  return this.toArray().reverse()
210
218
  }
211
219
 
212
220
  /**
213
- * Method used to convert the deque to a JavaScript array.
214
- *
215
- * @return {array}
221
+ * Returns a new array with all the elements in the order they were added to the deque.
222
+ * @returns {Array<T>} The elements array
216
223
  */
217
224
  toArray() {
218
225
  // Optimization
@@ -220,7 +227,7 @@ export class Deque<T> extends Sequence<T> {
220
227
 
221
228
  if (offset < this.capacity) return this.items.slice(this.start, offset)
222
229
 
223
- const array = new this.ArrayClass(this.count)
230
+ const array = new this.ArrayConstructor(this.count)
224
231
  const c = this.capacity
225
232
  const l = this.count
226
233
  let i = this.start
@@ -238,9 +245,8 @@ export class Deque<T> extends Sequence<T> {
238
245
  }
239
246
 
240
247
  /**
241
- * Method used to create an iterator over the deque's values.
242
- *
243
- * @return {Iterator}
248
+ * Returns an iterator over the deque's values.
249
+ * @returns {Iterator}
244
250
  */
245
251
  values(): Iterable<T> {
246
252
  const items = this.items
@@ -269,14 +275,16 @@ export class Deque<T> extends Sequence<T> {
269
275
  })
270
276
  }
271
277
 
278
+ /**
279
+ * Alias of {@link Deque.values}. Returns iterator of values.
280
+ */
272
281
  keys() {
273
282
  return this.values()
274
283
  }
275
284
 
276
285
  /**
277
- * Method used to create an iterator over the deque's entries.
278
- *
279
- * @return {Iterator}
286
+ * Creates an iterator of `[index, value]` pairs for all elements in the deque.
287
+ * @returns {Iterator}
280
288
  */
281
289
  entries() {
282
290
  const items = this.items
@@ -312,10 +320,11 @@ export class Deque<T> extends Sequence<T> {
312
320
  return this.inspect()
313
321
  }
314
322
 
323
+ // This is just for debugging in nodejs
315
324
  inspect() {
316
325
  const array = this.toArray()
317
326
 
318
- array.type = this.ArrayClass.name
327
+ array.type = this.ArrayConstructor.name
319
328
  array.capacity = this.capacity
320
329
 
321
330
  // Trick so that node displays the name of the constructor
@@ -87,6 +87,7 @@ single(3) // => 1
87
87
  export declare function once<T>(func: Function<T>): (...args: any[]) => T;
88
88
  export declare type Maybe<T> = T | undefined;
89
89
  export declare type Result<T, E = any> = [Maybe<T>, Maybe<E>];
90
+ export declare type Optional<T> = Maybe<T>;
90
91
  /**
91
92
  * Wraps a function to catch any exceptions inside and return a `go` style error-return type {@link Result}.
92
93
  *
@@ -206,6 +206,8 @@ export type Maybe<T> = T | undefined
206
206
 
207
207
  export type Result<T, E = any> = [Maybe<T>, Maybe<E>]
208
208
 
209
+ export type Optional<T> = Maybe<T>
210
+
209
211
  /**
210
212
  * Wraps a function to catch any exceptions inside and return a `go` style error-return type {@link Result}.
211
213
  *
@@ -4,7 +4,7 @@
4
4
  * @module Globals
5
5
  */
6
6
  /** This is just a noop function. */
7
- export declare const _: () => void;
7
+ export declare const noop: () => void;
8
8
  /**
9
9
  * A generic function type with arbitrary arguments and return.
10
10
  */
@@ -4,7 +4,7 @@
4
4
  * @module Globals
5
5
  */
6
6
  /** This is just a noop function. */
7
- export const _ = () => { };
7
+ export const noop = () => { };
8
8
  /** A function that always returns `true`. */
9
9
  export const True = () => true;
10
10
  /** A function that always returns `false`. */
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  /** This is just a noop function. */
8
- export const _ = () => {}
8
+ export const noop = () => {}
9
9
 
10
10
  /**
11
11
  * A generic function type with arbitrary arguments and return.
@@ -7,7 +7,7 @@ export declare type DateParts = {
7
7
  second?: number;
8
8
  millisecond?: number;
9
9
  };
10
- export declare type DateLike = number | string | Date | DateParts;
10
+ declare type DateLike = number | string | Date | DateParts;
11
11
  /**
12
12
  * Creates a date tied to a given locale (default system locale) which can be formatted in that locale's language using the native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl Intl Apis} directly or using a formatting string compatible with `strftime`.
13
13
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl Intl Apis}
@@ -221,3 +221,4 @@ export declare function daysInMonth(year: number, month: number): number | null;
221
221
  * @returns {number}
222
222
  */
223
223
  export declare function weeksInYear(weekYear: number): 53 | 52;
224
+ export {};
@@ -22,7 +22,7 @@ export type DateParts = {
22
22
  millisecond?: number
23
23
  }
24
24
 
25
- export type DateLike = number | string | Date | DateParts
25
+ type DateLike = number | string | Date | DateParts
26
26
 
27
27
  /**
28
28
  * Creates a date tied to a given locale (default system locale) which can be formatted in that locale's language using the native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl Intl Apis} directly or using a formatting string compatible with `strftime`.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "atomic-fns",
3
3
  "description": "Like Lodash, but for ESNext and with types. Stop shipping code built for browsers from 2015.",
4
- "version": "0.3.4",
4
+ "version": "0.3.5",
5
5
  "main": "core/index.js",
6
6
  "type": "module",
7
7
  "types": "core/index.d.ts",
@@ -34,7 +34,7 @@ import {
34
34
  type,
35
35
  uniqueId,
36
36
  values,
37
- _
37
+ noop
38
38
  } from '../core/globals/index.js'
39
39
  import { enumerate } from '../core/itertools/index.js'
40
40
 
@@ -74,7 +74,7 @@ describe('globals', () => {
74
74
  assert(type(new WeakMap()) === 'WeakMap')
75
75
  assert(type(new Set()) === 'Set')
76
76
  assert(type(new WeakSet()) === 'WeakSet')
77
- assert(type(new Promise(_)) === 'Promise')
77
+ assert(type(new Promise(noop)) === 'Promise')
78
78
  assert(type(new Int8Array()) === 'Int8Array')
79
79
  assert(type(new Uint8Array()) === 'Uint8Array')
80
80
  assert(type(new Uint8ClampedArray()) === 'Uint8ClampedArray')
@@ -115,14 +115,14 @@ describe('globals', () => {
115
115
  })
116
116
 
117
117
  it('isFunction', () => {
118
- assert(isFunction(_))
118
+ assert(isFunction(noop))
119
119
  assert(!isFunction([]))
120
120
  })
121
121
 
122
122
  it('isAsyncFunction', () => {
123
123
  assert(isAsyncFunction(async function () {}))
124
124
  assert(isAsyncFunction(async () => {}))
125
- assert(!isAsyncFunction(_))
125
+ assert(!isAsyncFunction(noop))
126
126
  })
127
127
 
128
128
  it('isNaN', () => {
@@ -143,7 +143,7 @@ describe('globals', () => {
143
143
  })
144
144
 
145
145
  it('isPromise', () => {
146
- assert(isPromise(new Promise(_)))
146
+ assert(isPromise(new Promise(noop)))
147
147
  })
148
148
 
149
149
  it('isSymbol', () => {