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

queue.io

v2.3.0

Published

An events based queue iteration JavaScript module

Downloads

30

Readme

queue.io

Actual version published on NPM npm module downloads per month npm module dependencies

An events based queue iteration JavaScript module, under the MIT license.

This tool is useful when in combination of your asynchronous operations, when you need to wait the entire queue to create some iterators on it.

queue.io offers a way to make it simply, to create some iterators after and/or before the queue is entire and you can invert the iteration direction, before/after too (separately, for each iterator, for a same queue)

Install :

npm install queue.io

Reference :

Queue([eventEmitter], [eventName = 'value']) :

var queue;

queue = Queue();

Notes :

  • The eventEmitter, first argument of Queue(eventEmitter, [eventName = 'value']), awaits 2 event types :
    • eventName to fill the queue
    • done (once) to indicate a done state to all the queue iterators
  • When eventEmitter receives the done event, it removes the value listeners and starts the iterations, on each iterator, if any
  • Queue.from(arrayLike) creates an auto-done queue, it must be an array-like object (Array, DOM NodeList, ...)
  • An error event sent to the eventEmitter is relayed on the queue itself
  • A queue created without eventEmitter is empty and auto-dones at the next tick if no queues are joined by intercept/listen/append

Queue.from(iterable, [eventName = 'value']) :

var queue;

queue = Queue.from([1, 2, 3]);
queue = Queue.from('test');
queue = Queue.from(document.getElementsByTagName('*'));

Directions :

  • Queue.NEXT : used to indicate the direction to the current iterator, first -> last
  • Queue.PREV : used to indicate the direction to the current iterator, last -> first

queue.iterate([direction = Queue.NEXT]) :

var iterator;

iterator = queue.iterate();

Iterator events :

  • eventName :

    • `value' : the current value
    • next : a method to jump to the next iteration
    • queue : the current queue
  • done :

    • queue : the current queue

Note :

  • eventName is related to the eventName passed at the queue creation (default : 'value')

Fill a queue :

var EventEmitter,
    Queue,
    eventName,
    eventEmitter,
    queue;

EventEmitter = require('events').EventEmitter;
Queue = require('queue.io');

eventName = 'value'; // the default event name
eventEmitter = new EventEmitter();
queue = Queue(eventEmitter, eventName);

eventEmitter.emit(eventName, 1);
eventEmitter.emit(eventName, 2);
eventEmitter.emit(eventName, 3);

eventEmitter.emit('done');

queue.append(queue, [event = 'value'], [direction = Queue.NEXT]) :

Appends a queue to an another, after its last value

var queue;

queue = Queue.from([1, 2, 3]);

queue.append(Queue.from([4, 5, 6]));
queue.append(Queue.from([7, 8, 9]));

/* queue values :
1, 2, 3, 4, 5, 6, 7, 8, 9
*/

queue.listen(queue, [event = 'value'], [direction = Queue.NEXT]) :

Same as queue.append but this method adds its values FIFO

var queue;

queue = Queue.from([1, 2, 3]);

queue.listen(Queue.from([4, 5, 6]));
queue.append(Queue.from([7, 8, 9]));

/* queue values :
1, 2, 3, 4, 7, 5, 8, 6, 9
*/

queue.intercept(callback, [event = 'value'], [direction = Queue.NEXT]) :

This method sends a callback based async function response to the callback argument

If that function returns an error, queue.intercept sends the error to the queue itself

var fs,
    queue;

fs = require('fs');

queue = Queue();

fs.readdir('.', queue.intercept(queue.append)); // sends the values to the current queue like queue.append
fs.readdir('.', queue.intercept(queue.listen)); // sends the values to the current queue like queue.listen

queue.on('error', function (error) {
    // fired if no readable directory
});

The iteration :

var iterator;

iterator = queue.iterate();

iterator.on(eventName, function onvalue(value, next, queue) {
    console.log('Iteration value = %d on :', value, queue);

    next();
});

iterator.on('done', function (queue) {
    console.log('Iterator done on :', queue);
});

Note :

  • The iterator creation isn't dependent to the queue state, then you can create them before and/or after the queue done state

Requirements :

  • ES5 support

Browser-side :

Simply use the browserified version

<script src="https://raw.githubusercontent.com/Lcfvs/queue.io/master/queue.io.browserified.js"></script>
<script>
var EventEmitter,
    Queue;

EventEmitter = require('events').EventEmitter;
Queue = require('queue.io');

// ...
</script>