@sapphire-sh/utils 1.13.0 → 1.14.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.
- package/lib/queue.d.ts +5 -3
- package/lib/queue.js +12 -5
- package/package.json +1 -1
package/lib/queue.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
declare type Value = object | number | string | boolean;
|
|
2
|
+
export declare class Queue<T extends Value> {
|
|
2
3
|
private head;
|
|
3
4
|
private tail;
|
|
4
5
|
private _size;
|
|
5
6
|
constructor();
|
|
6
|
-
enqueue(
|
|
7
|
+
enqueue(value: T): void;
|
|
7
8
|
dequeue(): T | undefined;
|
|
8
9
|
get size(): number;
|
|
9
10
|
isEmpty(): boolean;
|
|
10
11
|
peek(): T | undefined;
|
|
11
|
-
has(
|
|
12
|
+
has(value: T | ((value: T) => boolean)): boolean;
|
|
12
13
|
}
|
|
14
|
+
export {};
|
package/lib/queue.js
CHANGED
|
@@ -19,8 +19,8 @@ class Queue {
|
|
|
19
19
|
this.tail = null;
|
|
20
20
|
this._size = 0;
|
|
21
21
|
}
|
|
22
|
-
enqueue(
|
|
23
|
-
const newNode = new QueueNode(
|
|
22
|
+
enqueue(value) {
|
|
23
|
+
const newNode = new QueueNode(value);
|
|
24
24
|
if (this.isEmpty() || !this.tail) {
|
|
25
25
|
this.head = newNode;
|
|
26
26
|
this.tail = newNode;
|
|
@@ -53,11 +53,18 @@ class Queue {
|
|
|
53
53
|
var _a;
|
|
54
54
|
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
|
|
55
55
|
}
|
|
56
|
-
has(
|
|
56
|
+
has(value) {
|
|
57
57
|
let node = this.head;
|
|
58
58
|
while (node !== null) {
|
|
59
|
-
if (
|
|
60
|
-
|
|
59
|
+
if (typeof value === 'function') {
|
|
60
|
+
if (value(node.value)) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
if (node.value === value) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
61
68
|
}
|
|
62
69
|
node = node.next;
|
|
63
70
|
}
|