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 🙏

© 2026 – Pkg Stats / Ryan Hefner

asyncator

v1.0.2

Published

Class to easily play with asynchronous tasks through member methods, for browser and Node.js.

Readme

asyncator

Class to be extended to fastly concatenate asynchronous tasks in parallel or series.

1. Installation

~$ npm install --save asyncator

2. Import package

a) Via browsers:

< script src="node_modules/asyncator/dist/asyncator.js" >< /script >

And then, in your JavaScript:

const { Asyncator } = AsyncatorAPI;

Note: in browser environments, you need to load async library before Asyncator class.

b) Via Node.js:

const { Asyncator } = require("asyncator");

3. Usage

1. Create a new instance (providing the new methods, if any):

const asyncSet = Asyncator.from({
 a: (done) => done(null, 10),
 b: (done) => done(null, 20),
 c: (done) => done(null, 30)
});

// You can provide no parameters too, and initiate the instance with the `new` constructor:
const asyncSet = new Asyncator();

// Or:
const asyncSet = Asyncator.from();

2. Start running tasks asynchronously:

asyncSet
 .parallel(["a","b","c", (done) => setTimeout(done, 1000)])
 .then((data) => console.log("Ok..."))
 .catch((error) => console.log("Error"));

asyncSet
 .series(["a","b","c", (done) => setTimeout(done, 1000)])
 .then((data) => console.log("Ok..."))
 .catch((error) => console.log("Error"));

asyncSet
 .each(["hola","que","tal"], (value, key, done) => {
   console.log("Item:", item);
   done();
 })
 .then((data) => console.log("Ok..."))
 .catch((error) => console.log("Error"));

Note: if you pass a string instead of a function as the task, it will be replaced by the method of that Asyncator instance with that same name.

4. API Reference


AsyncatorAPI = require("asyncator")

Type: {Object}

Description: Object that contains the whole Asyncator API. Note that in browser environments, this object is accessible via the global window.AsyncatorAPI, while in Node.js you need to import the asyncator node_module to have access to it.


Asyncator = AsyncatorAPI.Asyncator

Type: {Class}

Description: Main class of the API. This class is used to define the asycnhronous operations we want to have access to as member methods that do asynchronous tasks (as async node module) expects.


new Asyncator(Object:propsAndMethods = {})

Type: {Class constructor}

Description: It creates new Asyncator instances. You pass an object with all the new properties and methods you want the class to have, and it will add them to the instance itself. The same can be done through the static method Asyncator.from(...), where the same passed parameters are passed to the class constructor too.

Parameter: {Object} propsAndMethods. Object containing all the properties and methods to be added to the current Asyncator instance.

Returns: {Object:Asyncator}


Asyncator#series(Object|Array:methodNamesAndFunctions = {})

Type: {Member method}

Description: It runs multiple tasks in serie. You can provide functions as async node_module expects, or strings referring to member method names (that are defined as async node_module functions.

Parameter: {Object | Array} methodNamesAndFunctions. Array or object of strings (with names of member methods) or functions (that must work well for async node_module) containing the callbacks of the current asynchronous operation. Note that you can pass objects or arrays. This is because async.series(...) node_module method can receive any of them, and when the success callback is called, the data is returned in the same format and with the same keys, either object or array.

Returns: {Object:Promise}. Once you call this method, you can set the success and error callbacks of a typical Promise.

Example: This is an example:

Asyncator
 .from({a: (done) => done(null, 50)})
 .series({a: "a"})
 .then((data) => console.log(data.a + " is 50"))
 .catch((error) => console.log("There were errors:", error))

This is another example, but with arrays now:

Asyncator
 .from({a: (done) => done(null, 50)})
 .series(["a"])
 .then((data) => console.log(data[0] + " is 50"))
 .catch((error) => console.log("There were errors:", error))

Asyncator#parallel(Object|Array:methodNamesAndFunctions = {})

Type: {Member method}

Description: It works exactly the same as Asyncator#series(...), but instead of running the tasks in serie, they are run parallelly.

Parameter: {Object | Array} methodNamesAndFunctions. The same as Asyncator#series.

Returns: {Object:Promise}. The same as Asyncator#series.


Asyncator#get(String:properties, Any:defaultValue=undefined, String|RegExp:separator="." )

Type: {Member method}

Description: It retrieves property values from the Asyncator instance easierly, or returns the defaultValue, and using the separator to separate the name of each property. So, for example, if I wanted to get a value placed in asyncator.my.inner.properties.firstProperty, all you need to do is:

asyncator.get("my/inner/properties/firstProperty", 800, "/");

Or simply:

asyncator.get("my.inner.properties.firstProperty"). 

Both codes will do the same, except that the first, if it cannot retrieve the specified property, it will return 800.

Parameter: {String} properties. Name of the keys we want to access to retrieve our value, separated, by default, by a ".". The separator parameter dictates which character should split the names.

Parameter: {Any} defaultValue. When there are problems to retrieve the specified property, it will return this value.

Parameter: {String|RegExp} separator. Used by String#split(~) to separate the provided names of properties.

Returns: {Any}. It returns the retrieved property, or the defaultValue provided.

Asyncator#mapSeries(Object|Array:items, String|Function:iterator)

Type: {Member method}

Description: It maps an iterable piece of data (Object or Array) through an asynchronous iterator callback, or the name of a member method (which is coded as an async function). The iteration is made one after the other.

Parameter: {Object | Array} items. The piece of data you want to iterate.

Parameter: {Function} callback. The asynchronous iterator applied for each item. The callback works exactly as the typical async callbacks, but receiving the item which is iterated before the done callback

Returns: {Object:Promise}. The same as Asyncator#series or Asyncator#parallel.

Asyncator#mapParallel(Object|Array:items, String|Function:iterator)

Type: {Member method}

Description: It maps an iterable piece of data (Object or Array) through an asynchronous iterator callback, or the name of a member method (which is coded as an async function). The iteration is made in parallel.

Parameter: {Object | Array} items. The piece of data you want to iterate.

Parameter: {Function} callback. The asynchronous iterator applied for each item. The callback works exactly as the typical async callbacks, but receiving the item which is iterated before the done callback.

Returns: {Object:Promise}. The same as Asyncator#series or Asyncator#parallel.

5. Commands

1. To build the project source code:

~$ npm run build

2. To generate the documentation:

~$ npm run docs

3. To run tests:

~$ npm run test

4. To generate the coverage documentation:

~$ npm run coverage

6. Conclusion

Simple class to ease the asynchronous code of your programs.