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/deque

v2.0.0

Published

Double Ended Queue data structure

Downloads

10

Readme

Deque

Deque provides a simple, JavaScript-native implementation of the double-ended queue (deque) data structure.

Installation

Using npm:

$ npm install @bletchley-tech/deque

Usage

Deque provides a JavaScript-native implementation of the double-ended queue (deque) data structure designed for use in a synchronous Node.js environment.

The package provides a single class, Deque, which is a simple deque data structure. To use it, follow the steps below:

  1. Import/Require the package:

    // ES6+
    import Deque from '@bletchley-tech/deque';

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

  2. Create a new instance of Deque:

    const deque = new Deque();

    This will create a new instance of Deque and store it in the deque variable.

  3. Use the deque:

    deque.enqueueFront('a'); // Enqueue 'a' to the front
    deque.enqueueBack('b'); // Enqueue 'b' to the back
    deque.deque; // "a - b"

    This will enqueue 'a' to the front of the deque, enqueue 'b' to the back of the deque, and then print the deque.

Deque Class

The Deque class has only one property, deque, which is an array of values. The specific functionality of the Deque data structure is provided through class methods.

The Deque class takes advantage of the new private class properties/methods JavaScript feature introduced in ES2022. This means that once the Deque 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 Deque data structure was defined to only accept one data type within itself to enforce data consistency. This was done to prevent the Deque from being used to store mixed data types.


Constructor

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

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

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

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

const Deque2 = new Deque(Deque); // Create a new Deque (Deque2) with the same values as Deque

Class Methods

enqueueFront(value)

The enqueueFront method adds a value to the front of the queue.

deque.enqueueFront('a'); // Enqueue 'a' to the front

enqueueBack(value)

The enqueueBack method adds a value to the back of the queue.

deque.enqueueBack('b'); // Enqueue 'b' to the back

enqueueMultipleFront(values)

The enqueueMultipleFront method adds multiple values to the front of the queue.

deque.enqueueMultipleFront('a', 'b'); // Enqueue 'a' and 'b' to the front

enqueueMultipleBack(values)

The enqueueMultipleBack method adds multiple values to the back of the queue.

deque.enqueueMultipleBack('a', 'b'); // Enqueue 'a' and 'b' to the back

dequeueFront()

The dequeueFront method removes the front value from the queue.

deque.dequeueFront(); // Dequeue 'a' from the front

dequeueBack()

The dequeueBack method removes the back value from the queue.

deque.dequeueBack(); // Dequeue 'b' from the back

Class Attributes

size

deque.size; // 4

This will return the size of the deque.

isEmpty

deque.isEmpty; // false

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

front

deque.front; // 'a'

This will return the front value of the deque.

back

deque.back; // 'a'

This will return the back value of the deque.

deque

deque.deque; // 'a - a - b - a'

This will return the deque as a string.

type

deque.type; // 'string'

License

Deque is licensed under the MIT License (see the LICENSE file for more information).