New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

daqueue

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

daqueue

A queue written in clean es5

latest
Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
5
25%
Maintainers
1
Weekly downloads
 
Created
Source

daqueue Build Status

All of the implementations of queues I found attached everything to the prototype and didn't make good of private encapsulation, getters, non-enumerable methods, etc.

This queue does not use Array#shift internally, so it keeps O(1) rather than O(n).

So here it is, a clean implementation of a queue written in straight simple es5.

API

Create a queue

var createQueue = require('daqueue');

var queue = createQueue(); // => Creates an empty queue

var queue = createQueue('hat', 'tree', 'golf'); // => Creates a queue with initial values

queue.size

The size property works exactly the same as length on Array.

var queue = createQueue(1, 2, 3);

queue.size // => 3

queue.front

A property containing the first item in the queue.

var queue = createQueue('hat', 'tree', 'golf');

queue.first // => 'hat'

queue.enqueue()

Add a new item to the queue. Returns the queue for chaining.

var queue = createQueue();

queue.enqueue('hat');
queue.enqueue('tree').enqueue('house');

// queue is => ['hat', 'tree', 'house']

queue.dequeue()

Gets the next item in the queue.

var queue = createQueue('hat', 'tree', 'golf');

queue.dequeue() // => 'hat'
// queue is => ['tree', 'golf']

queue.toString()

Get the current queue as a string.

var queue = createQueue(1, 2, 3);

queue.toString() // => "1,2,3"

queue.toArray()

Copy the current queue into a regular array.

var queue = createQueue(1, 2, 3);

queue.toArray() // => [1, 2, 3]

Keywords

queue

FAQs

Package last updated on 18 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts