Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/supercharge/queue-datastructure
A queue data structure for Node.js
https://github.com/supercharge/queue-datastructure
data-structure data-structures datastructure nodejs queue supercharge
Last synced: 3 months ago
JSON representation
A queue data structure for Node.js
- Host: GitHub
- URL: https://github.com/supercharge/queue-datastructure
- Owner: supercharge
- License: mit
- Created: 2019-07-04T11:31:10.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-11-06T04:17:13.000Z (about 1 year ago)
- Last Synced: 2024-10-04T00:36:05.829Z (4 months ago)
- Topics: data-structure, data-structures, datastructure, nodejs, queue, supercharge
- Language: JavaScript
- Homepage:
- Size: 85 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Queue Datastructure
A queue data structure for Node.js and JavaScript.
Installation ·
Usage ·
API
Follow @marcuspoehls and @superchargejs for updates!
---
## Installation
```
npm i @supercharge/queue-datastructure
```## Notice
This package is ESM-only.## Usage
Using the queue data structure is pretty straightforward. The library exposes a `Queue` class that you can use to create a queue instance. You can create a queue from existing data or an empty one:```js
import { Queue } from '@supercharge/queue-datastructure'// create a queue from an existing array
const queue = new Queue([ 1, 2, 3 ])// or, create a queue from individual items
const queue = new Queue(1, 2, 3)// or, create an empty queue
const queue = new Queue()
```## API
#### `.enqueue(items)`
Push new `items` to the end of the queue.```js
queue
.enqueue(1)
.enqueue(2, 3)
.enqueue([ 4, 5, 6])// Queue: 1, 2, 3, 4, 5, 6
```#### `.dequeue()`
Remove and return the item which is up for processing. Returns `undefined` if the queue is empty.```js
queue.enqueue(1, 2, 3)
queue.size() // 3queue.dequeue() // 1
queue.size() // 2
```#### `.peek()`
Returns the first item without removing it from the queue. Returns `undefined` if the queue is empty.```js
queue.enqueue(1, 2, 3)
queue.peek() // 1
```#### `.size()`
Returns the number of items in the queue.```js
queue.size() // 0
queue.enqueue(1, 2)
queue.size() // 2
```#### `.isEmpty()`
Returns `true` if there are no items in the queue, `false` otherwise.```js
queue.isEmpty() // true
queue.enqueue(1)
queue.isEmpty() // false
```#### `.isNotEmpty()`
Returns `true` if there are items in the queue, `false` when the queue is empty.```js
queue.isNotEmpty() // false
queue.enqueue(1)
queue.isNotEmpty() // true
```#### `.clear()`
Removes all items from the queue.```js
queue.clear()
queue.size() // 0
```## Contributing
1. Create a fork
2. Create your feature branch: `git checkout -b my-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request 🚀## License
MIT © [Supercharge](https://superchargejs.com)---
> [superchargejs.com](https://superchargejs.com) ·
> GitHub [@supercharge](https://github.com/supercharge) ·
> Twitter [@superchargejs](https://twitter.com/superchargejs)