npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bletchley-tech/queue

v2.0.0

Published

A native JavaScript implementation of the Queue data structure

Downloads

2

Readme

Queue

Queue provides a simple JavaScript-native implementation of the queue data structure.

Installation

Using npm:

$ npm install @bletchley-tech/queue

Usage

Queue provides a JavaScript-native implementation of the queue data structure designed for use in a synchronous Node.js environment.

The package provides a single class, Queue, which is a simple queue data structure. To use it, follow the next steps:

  1. Import/Require the package:

    // CommonJS
    const Queue = require('queue');
    
    // ES6+
    import Queue from 'queue';

    This will load the Queue class into the global namespace and allow you to create new instances of Queue.

  2. Create a new instance of Queue:

    const queue = new Queue();

    This will create a new instance of Queue and store it in the queue variable.

  3. Use the queue:

    queue.enqueue(1); // Enqueue 1
    queue.size; // 1
    queue.isEmpty; // false
    queue.queue; // '1'

    This will enqueue 1. Enqueueing a value will add it to the end of the queue, and automatically update the size.

Queue Class

The Queue class has only one property, queue, which is an array of values. The specific functinoality of the Queue data structure is provided through class methods.

The Queue class takes advantage of the new private class properties/methods JavaScript feature introduced in ES2022. This means that once the Queue is initialized, it will not be able to be changed except by the class' own methods.


Version 2.0.0 Update

For version 2.0.0, the Queue data structure was defined to only accept one data type within itself to enforce data consistency. This was done to prevent the Queue from being used to store mixed data types.


Constructor

The Queue class has a constructor that takes either one or no arguments.

If no arguments are passed, the constructor returns a new, empty Queue instance.

If one argument is passed, the constructor acts as a copy constructor. This means the passed argument must be an instance of Queue, to be copied into a new instance which will be returned by the constructor.

const queue = new Queue(); // Create a new empty Queue
queue.enqueueMany(5, 1, 9); // Enqueue 5, 1, 9

const queue2 = new Queue(queue); // Create a new Queue (queue2) with the same values as queue

Class Methods

enqueue(value)

The enqueue method adds a value to the end of the queue.

queue.enqueue(1); // Enqueue 1

enqueueMany(values)

The enqueueMany method adds multiple values to the end of the queue.

queue.enqueueMany(1, 2, 3); // Enqueue 1, 2, 3

dequeue()

The dequeue method removes the value at the front of the queue.

queue.dequeue(); // Dequeue 1

Class Attributes

size

queue.size; // 2

This will return the size of the queue.

isEmpty

queue.isEmpty; // false

This will return true if the queue is empty, false otherwise.

front

queue.front; // 2

This will return the value at the front of the queue.

queue

queue.queue; // '2 - 3'

This will return the queue as a string.

type

queue.type; // 'number'

License

Queue is licensed under the MIT license (see the LICENSE file for more information).