p-ratelimit
Version:
Promise-based utility to make sure you don’t call rate-limited APIs too quickly.
85 lines • 1.96 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Dequeue = void 0;
class Dequeue {
constructor() {
this._length = 0;
this.head = undefined;
this.tail = undefined;
}
get length() {
return this._length;
}
clear() {
this.head = this.tail = undefined;
this._length = 0;
}
push(value) {
const newNode = {
value,
prev: this.tail,
next: undefined
};
if (this._length) {
this.tail.next = newNode;
this.tail = newNode;
}
else {
this.head = this.tail = newNode;
}
this._length++;
}
pop() {
if (!this._length) {
return undefined;
}
const result = this.tail;
this.tail = this.tail.prev;
this._length--;
if (!this._length) {
this.head = this.tail = undefined;
}
return result.value;
}
unshift(value) {
const newNode = {
value,
prev: undefined,
next: this.head
};
if (this._length) {
this.head.prev = newNode;
this.head = newNode;
}
else {
this.head = this.tail = newNode;
}
this._length++;
}
shift() {
if (!this._length) {
return undefined;
}
const result = this.head;
this.head = this.head.next;
this._length--;
if (!this._length) {
this.head = this.tail = undefined;
}
return result.value;
}
peekFront() {
if (this._length) {
return this.head.value;
}
return undefined;
}
peekBack() {
if (this._length) {
return this.tail.value;
}
return undefined;
}
}
exports.Dequeue = Dequeue;
//# sourceMappingURL=dequeue.js.map