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

@jsweb/asyncs

v4.0.2

Published

Simple JS module for Promise and Fetch APIs, with some useful abstraction

Downloads

6

Readme

@jsweb/asyncs

Simple JS module for Promise and Fetch APIs, with some useful abstraction.

npm-package es6-module tests-mocha

See tests at https://asyncs.jsweb.app

New in v4.0.0

Now, its a full ES module, there is no UMD or CommonJS version.

In modern JS development ES modules are the pattern, already supported in newer versions of Node.js and modern borwsers natively.

Backward compatibility is not a concern here. If you use a module bundler (like Webpack or Rollup) to transpile your code, the result will be compatible according to your setup.


Methods

exec(fn, ...args) ⇒ Promise

Excute any function asyncronously with any number of arguments.

Returns: Promise - Promise

| Param | Type | | --- | --- | | fn | function | | ...args | arguments |

asap(fn, ...args) ⇒ *

Execute any function asyncronously As Soon As Possible with any number of arguments. This method tries to use setImmediate (if available) or emulate it.

| Param | Type | | --- | --- | | fn | function | | ...args | arguments |

task(input, ...args) ⇒ Promise

Turn any input in a Promise to use it on asyncronous threads

Returns: Promise - Promise

| Param | Type | | --- | --- | | input | * | | ...args | arguments |

execAll(...args) ⇒ Promise

Turn any number of arguments into asyncronous group to resolve only if all threads resolve.

Returns: Promise - Promise

| Param | Type | | --- | --- | | ...args | arguments |

execRace(...args) ⇒ Promise

Turn any number of arguments into asyncronous race to resolve or reject with the fastest thread.

Returns: Promise - Promise

| Param | Type | | --- | --- | | ...args | arguments |

request(url, cfg) ⇒ Promise

Execute asyncronous HTTP requests with configurable options.

This method uses Fetch API with some useful abstractions.

To send parameters on request, just add a body in cfg containing the object for any HTTP method request.

GET requests (default), will serialize parameters into a query string.

Other methods will convert parameters into FormData object if necessary.

So you can also send HTML Form or FormData object for non GET requests.

It is also possible to send JSON content. Just set content-type to application/json at cfg.headers.

Then your cfg.body literal object will be serialized using JSON.stringify.

The promise returned also checks HTTP response. Any status >= 300 will cause a Promise.reject.

Returns: Promise - Promise

| Param | Type | | --- | --- | | url | String | | cfg | RequestInit |

requestAll(urls, cfg, resp) ⇒ Promise

Use execAll to make a request for each urls using the same cfg and resp type for all.

The result Promise resolves only if all requests resolve.

If any request fails, it will cause an entire Promise.reject.

Possible response types are: response (default), json, text, blob, boolean, number, xml and html.

Returns: Promise - Promise

| Param | Type | Default | | --- | --- | --- | | urls | Array.<String> | | | cfg | RequestInit | | | resp | String | response |

requestRace(urls, cfg, resp) ⇒ Promise

Use execRace to make a request race with all urls using the same cfg and resp type for all.

The result Promise resolves or rejects with the fastest request.

Possible response types are: response (default), json, text, blob, boolean, number, xml and html.

Returns: Promise - Promise

| Param | Type | Default | | --- | --- | --- | | urls | Array.<String> | | | cfg | RequestInit | | | resp | String | response |

requestJSON(url, cfg) ⇒ Promise

Execute a request expecting for a valid JSON response.

HTTP errors or invalid JSON response will cause a Promise.reject.

Returns: Promise - Promise

| Param | Type | | --- | --- | | url | String | | cfg | RequestInit |

requestText(url, cfg) ⇒ Promise

Execute a request expecting for any response and get it as text.

HTTP errors will cause a Promise.reject.

Returns: Promise - Promise

| Param | Type | | --- | --- | | url | String | | cfg | RequestInit |

requestBlob(url, cfg) ⇒ Promise

Execute a request expecting for a valid Blob response.

HTTP errors or not readable Blob response will cause a Promise.reject.

Returns: Promise - Promise

| Param | Type | | --- | --- | | url | String | | cfg | RequestInit |

requestBoolean(url, cfg) ⇒ Promise

Execute a request expecting for any response and get it as boolean.

HTTP errors will cause a Promise.reject.

Returns: Promise - Promise

| Param | Type | | --- | --- | | url | String | | cfg | RequestInit |

requestNumber(url, cfg) ⇒ Promise

Execute a request expecting for a valid Number response.

The response can be number, string or any value that can be parsed as Number.

Invalid values will resolve as NaN (not a number).

HTTP errors will cause a Promise.reject.

Returns: Promise - Promise

| Param | Type | | --- | --- | | url | String | | cfg | RequestInit |

requestXML(url, cfg) ⇒ Promise

Execute a request expecting for a valid XML document response.

HTTP errors response will cause a Promise.reject.

Returns: Promise - Promise

| Param | Type | | --- | --- | | url | String | | cfg | RequestInit |

requestHTML(url, cfg) ⇒ Promise

Execute a request expecting for any response and get it as HTML.

HTTP errors response will cause a Promise.reject.

Returns: Promise - Promise

| Param | Type | | --- | --- | | url | String | | cfg | RequestInit |