1.1.1 • Published 5 years ago

@truck/queue v1.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Build Status Coverage Status semantic-release

Queue

A JavaScript Queue data structure.

A Queue follows a FIFO (First-In-First-Out) methodology, just like the queue at the shopping mall.

Installation

Install @truck/queue via npm:

$ npm install --save @truck/queue

Methods

Methods > constructor(maximumLength?: int)

Build a new queue. Pass an optional maximumLength which will limit the Queue length, the default is 65535.

Methods > dequeue(): any (O(1))

Removes the bottom (first inserted) value from the Queue and returns it.

Methods > enqueue(value: any): void (O(1))

Adds a value to the top of the Queue. Throws a RangeError when the addition exceeds the maximum length allowed (defined in the constructor).

Methods > isEmpty(): boolean (O(1))

Checks whether the Queue is empty.

Methods > isFull(): boolean (O(1))

Checks whether the Queue is full.

Methods > peek(): any (O(1))

Get the item at the front of the Queue without removing it.

Methods > toArray(): any[] (O(n))

Returns the Queue as an array.

Properties

Properties > .length: number

Returns the current length of the Queue.

Examples

A Queue is a standard class which can be instantiated with the new keyword:

// Build a new Queue with a maximum length of 10 values
const queue = new Queue(10);
// Get the length of the Queue
let length = Queue.length; // 0
// Add some values to the Queue
queue.enqueue(1);
queue.enqueue('two');
queue.enqueue({ three: 'three' });
queue.enqueue(false);
// Check if the Queue is full
if (!queue.isFull()) {
  queue.enqueue('FIVE');
}
// Get the length of the Queue
length = Queue.length; // 5
// Get the Queue as an array
const queueAsArray = queue.toArray(); // [1, 'two', { three: 'three' }, false, 'FIVE']
// Remove the values from the Queue
queue.dequeue(); // 1
queue.dequeue(); // 'two'
queue.dequeue(); // { three: 'three' }
queue.dequeue(); // false
// Check if the Queue is empty
if (!queue.isEmpty()) {
  queue.dequeue(); // 'FIVE'
}
// Get the length of the Queue
length = Queue.length; // 0

Testing

Use the following command to run all the tests described below together:

$ docker-compose run --rm app npm test

Testing > Commit messages

Commit messages are linted through the use of husky and @commitlint/cli using the @commitlint/config-conventional commit convention.

Please read through the AngularJS Git Commit Message Conventions to get a better understanding of how commit messages are formatted.

After doing an npm install the required git hooks wil be added automatically and commit messages will be linted automatically.

Testing > Linting

Linting is done using eslint using the eslint-config-airbnb-base configuration with very few alterations, all of which can be seen in the .eslintrc file in the root of this repository.

Linting can be run in isolation through the command:

$ docker-compose run --rm app npm run test:lint

Testing > Auditing

Auditing of dependencies is done through the npm audit command-line tool.

Auditing can be run in isolation through the command:

$ docker-compose run --rm app npm run test:vulnerabilities

Testing > Unit testing

Unit testing is done with jest. The test file for each file to be tested is to be placed alongside the file in testing and marked with the .test.js extension.

Unit testing can be run in isolation through the command:

$ docker-compose run --rm app npm run test:scripts

Contributing

Contributions are always welcome, just submit a PR to get the conversation going. Please make sure all tests pass before submitting a PR.

Contributing > Releases

The moment a PR is merged into the master branch semantic-release will kick-off a new release, thus the importance of clear commit messages.