@common.js/yocto-queue 1.0.0 β†’ 1.1.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.
package/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  The [yocto-queue](https://www.npmjs.com/package/yocto-queue) package exported as CommonJS modules.
4
4
 
5
- Exported from [yocto-queue@1.0.0](https://www.npmjs.com/package/yocto-queue/v/1.0.0) using https://github.com/etienne-martin/common.js.
5
+ Exported from [yocto-queue@1.1.1](https://www.npmjs.com/package/yocto-queue/v/1.1.1) using https://github.com/etienne-martin/common.js.
package/index.d.ts CHANGED
@@ -47,6 +47,13 @@ export default class Queue<ValueType> implements Iterable<ValueType> {
47
47
  */
48
48
  dequeue(): ValueType | undefined;
49
49
 
50
+ /**
51
+ Get the next value in the queue without removing it.
52
+
53
+ @returns The value or `undefined` if the queue is empty.
54
+ */
55
+ peek(): ValueType | undefined;
56
+
50
57
  /**
51
58
  Clear the queue.
52
59
  */
package/index.js CHANGED
@@ -256,6 +256,17 @@ var Queue = /*#__PURE__*/ function() {
256
256
  return current.value;
257
257
  }
258
258
  },
259
+ {
260
+ key: "peek",
261
+ value: function peek() {
262
+ if (!_classPrivateFieldGet(this, _head)) {
263
+ return;
264
+ }
265
+ return _classPrivateFieldGet(this, _head).value;
266
+ // TODO: Node.js 18.
267
+ // return this.#head?.value;
268
+ }
269
+ },
259
270
  {
260
271
  key: "clear",
261
272
  value: function clear() {
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@common.js/yocto-queue",
3
- "version": "1.0.0",
4
- "description": "Tiny queue data structure",
3
+ "version": "1.1.1",
4
+ "description": "yocto-queue package exported as CommonJS modules",
5
5
  "license": "MIT",
6
6
  "repository": "etienne-martin/common.js",
7
7
  "funding": "https://github.com/sponsors/sindresorhus",
8
8
  "type": "commonjs",
9
+ "types": "./index.d.ts",
10
+ "sideEffects": false,
9
11
  "engines": {
10
12
  "node": ">=12.20"
11
13
  },
package/readme.md DELETED
@@ -1,64 +0,0 @@
1
- # yocto-queue [![](https://badgen.net/bundlephobia/minzip/yocto-queue)](https://bundlephobia.com/result?p=yocto-queue)
2
-
3
- > Tiny queue data structure
4
-
5
- You should use this package instead of an array if you do a lot of `Array#push()` and `Array#shift()` on large arrays, since `Array#shift()` has [linear time complexity](https://medium.com/@ariel.salem1989/an-easy-to-use-guide-to-big-o-time-complexity-5dcf4be8a444#:~:text=O(N)%E2%80%94Linear%20Time) *O(n)* while `Queue#dequeue()` has [constant time complexity](https://medium.com/@ariel.salem1989/an-easy-to-use-guide-to-big-o-time-complexity-5dcf4be8a444#:~:text=O(1)%20%E2%80%94%20Constant%20Time) *O(1)*. That makes a huge difference for large arrays.
6
-
7
- > A [queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) is an ordered list of elements where an element is inserted at the end of the queue and is removed from the front of the queue. A queue works based on the first-in, first-out ([FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics))) principle.
8
-
9
- ## Install
10
-
11
- ```
12
- $ npm install yocto-queue
13
- ```
14
-
15
- ## Usage
16
-
17
- ```js
18
- import Queue from 'yocto-queue';
19
-
20
- const queue = new Queue();
21
-
22
- queue.enqueue('πŸ¦„');
23
- queue.enqueue('🌈');
24
-
25
- console.log(queue.size);
26
- //=> 2
27
-
28
- console.log(...queue);
29
- //=> 'πŸ¦„ 🌈'
30
-
31
- console.log(queue.dequeue());
32
- //=> 'πŸ¦„'
33
-
34
- console.log(queue.dequeue());
35
- //=> '🌈'
36
- ```
37
-
38
- ## API
39
-
40
- ### `queue = new Queue()`
41
-
42
- The instance is an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols), which means you can iterate over the queue front to back with a β€œfor…of” loop, or use spreading to convert the queue to an array. Don't do this unless you really need to though, since it's slow.
43
-
44
- #### `.enqueue(value)`
45
-
46
- Add a value to the queue.
47
-
48
- #### `.dequeue()`
49
-
50
- Remove the next value in the queue.
51
-
52
- Returns the removed value or `undefined` if the queue is empty.
53
-
54
- #### `.clear()`
55
-
56
- Clear the queue.
57
-
58
- #### `.size`
59
-
60
- The size of the queue.
61
-
62
- ## Related
63
-
64
- - [quick-lru](https://github.com/sindresorhus/quick-lru) - Simple β€œLeast Recently Used” (LRU) cache