denque
Advanced tools
Comparing version 1.5.1 to 2.0.0
@@ -0,1 +1,11 @@ | ||
## 2.0.0 | ||
- fix!: `push` & `unshift` now accept `undefined` values to match behaviour of `Array` (fixes #25) (#35) | ||
- This is only a **BREAKING** change if you are currently expecting `push(undefined)` and `unshift(undefined)` to do | ||
nothing - the new behaviour now correctly adds undefined values to the queue. | ||
- **Note**: behaviour of `push()` & `unshift()` (no arguments) remains unchanged (nothing gets added to the queue). | ||
- **Note**: If you need to differentiate between `undefined` values in the queue and the return value of `pop()` then | ||
check the queue `.length` before popping. | ||
- fix: incorrect methods in types definition file | ||
## 1.5.1 | ||
@@ -2,0 +12,0 @@ |
declare class Denque<T = any> { | ||
length: number; | ||
constructor(); | ||
constructor(array: T[]); | ||
constructor(array: T[], options: IDenqueOptions); | ||
push(item: T): number; | ||
unshift(item: T): number; | ||
pop(): T | undefined; | ||
removeBack(): T | undefined; | ||
shift(): T | undefined; | ||
peekBack(): T | undefined; | ||
peekFront(): T | undefined; | ||
peekAt(index: number): T | undefined; | ||
get(index: number): T | undefined; | ||
remove(index: number, count: number): T[]; | ||
removeOne(index: number): T | undefined; | ||
splice(index: number, count: number, ...item: T[]): T[] | undefined; | ||
isEmpty(): boolean; | ||
clear(): void; | ||
size(): void; | ||
toString(): string; | ||
toArray(): T[]; | ||
length: number; | ||
} | ||
@@ -26,0 +42,0 @@ |
@@ -20,3 +20,3 @@ 'use strict'; | ||
/** | ||
* ------------- | ||
* -------------- | ||
* PUBLIC API | ||
@@ -106,3 +106,3 @@ * ------------- | ||
Denque.prototype.unshift = function unshift(item) { | ||
if (item === undefined) return this.size(); | ||
if (arguments.length === 0) return this.size(); | ||
var len = this._list.length; | ||
@@ -137,3 +137,3 @@ this._head = (this._head - 1 + len) & this._capacityMask; | ||
Denque.prototype.push = function push(item) { | ||
if (item === undefined) return this.size(); | ||
if (arguments.length === 0) return this.size(); | ||
var tail = this._tail; | ||
@@ -196,3 +196,3 @@ this._list[tail] = item; | ||
for (k = size - 1 - index; k > 0; k--) { | ||
this._list[i] = this._list[i = ( i + 1 + len) & this._capacityMask]; | ||
this._list[i] = this._list[i = (i + 1 + len) & this._capacityMask]; | ||
} | ||
@@ -199,0 +199,0 @@ this._list[i] = void 0; |
{ | ||
"name": "denque", | ||
"version": "1.5.1", | ||
"version": "2.0.0", | ||
"description": "The fastest javascript implementation of a double-ended queue. Used by the official Redis, MongoDB, MariaDB & MySQL libraries for Node.js and many other libraries. Maintains compatability with deque.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
18127