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

aah

v1.1.2

Published

A library of async/await helpers

Downloads

20

Readme

aah

A JavaScript library of async/await helpers

aah : object

Kind: global namespace


aah.Callbackify ⇒ function

	const task = Callbackify(
		async (i) => i + 1
	);

	// logs 'res 1', eventually
	task(
		(err, res) => console.log('res', res),
		0
	);

Kind: static property of aah
Returns: function - a callback-expecting function
Params

  • task function - an async function

aah.CatchError ⇒ function

  let task = CatchError(task);

  const { error, result } = await task(request);

Kind: static property of aah
Returns: function - an async wrapper function around the task
Params

  • task function - an async function to wrap around with a catch wrapper.

aah.Delay ⇒ function

	const task = Delay(1000);

	const result = await task(1); // result is 1, after 1 second

Kind: static property of aah
Returns: function - an async function
Params

  • time number - the time to delay

aah.InOrder ⇒ function

	const task = InOrder(
		async (i) => i + 1,
		async (i) => i + 1,
		async (i) => i + 1
	);

	const results = await task(0); // results is 3

Kind: static property of aah
Returns: function - an async wrapper function that runs all of the tasks in order, calling each one with original request
Params

  • ...tasks function - any number of async tasks.

aah.InParallel ⇒ function

	const task = InParallel(
		async (i) => i + 1,
		async (i) => i + 2,
		async (i) => i + 3
	);

	const results = await task(0); // results is [1, 2, 3]

Kind: static property of aah
Returns: function - an async wrapper function that runs all the tasks in parallel, and returns an array of results
Params

  • ...tasks function - any number of async tasks.

aah.InSeries ⇒ function

	const task = InSeries(
		async (i) => i + 1,
		async (i) => i + 1,
		async (i) => i + 1
	);

	const results = await task(0); // results is 3

Kind: static property of aah
Returns: function - an async wrapper function that runs all of the tasks in series, calling each one with the results of the previous one
Params

  • ...tasks function - any number of async tasks.

aah.ParallelFilter ⇒ function

	const task = ParallelFilter(
		async (val, i) => val % 2 === 0
	);

	const results = await task([0, 1, 2]); // results is [0, 2]

Kind: static property of aah
Returns: function - an async wrapper function that takes in an array of requests, runs the task in parallel, once for each input in the array, and returns an array of results
Params

  • task function - the filtering task

aah.ParallelMap ⇒ function

	const task = ParallelMap(
		async (val, i) => val + 1
	);

	const results = await task([0, 1, 2]); // results is [1, 2, 3]

Kind: static property of aah
Returns: function - an async wrapper function that takes in an array of requests, runs the task in parallel, once for each input in the array, and returns an array of results
Params

  • task function - the mapping task

aah.PassThrough

	const task = PassThrough;

	const results = await task(0); // results is 0

PassThrough does nothing, just passes the request through as the result

Kind: static property of aah


aah.Promisify ⇒ function

	const task = Promisify(
		(onDone, i) => onDone(
			i === 0 ? new Error('i cant be 0') : null,
			i + 1
		),
	);

	const results = await task(1); // results is 2
	const results2 = await taks(0); // throws 'i cant be 0 Error

Kind: static property of aah
Returns: function - an async function
Params

  • task function - a callback-expecting function

aah.Race ⇒ function

	const task = Race(
		async (i) => i + 1,
		async (i) => i + 2,
	);

	const result = await task(1); // 2

Kind: static property of aah
Returns: function - an async task that resolves or rejects as soon as the first one of its "children" resolves or rejects
Params

  • ...tasks function - any number of async tasks

aah.TimeIn ⇒ function

	const task = TimeIn(async (i) => i + 1, 1000);

	const result = await task(1); // result1 = 2, after 1000 ms

Kind: static property of aah
Returns: function - an async task
Params

  • task function - an async task
  • timeIn function - the minimum time the task can take

aah.TimeOut ⇒ function

	const task1 = TimeOut( Delay(100), 1000);
	const task2 = TimeOut( Delay(1000), 100);

	const result1 = await task1(1); // result1 = 1, after 100 ms
	const result2 = await task2(1); // throws a timeout error after 100 ms

Kind: static property of aah
Returns: function - an async task
Params

  • task function - an async tasks
  • timeOut function - the number of ms before throwing an error

aah.Assert(validator, message) ⇒ taskFunction

Builds an async assertion task. When called, if the arguments do not match the validator functions,

Kind: static method of aah
Returns: taskFunction - an assertion task
Params

  • validator function - a function that checks the request.
  • message string - an optional error message to throw if the assertion fails, or a message builder function.

aah.Logging(...statements) ⇒ function

A logging utility. It passes the request received into all the statements, collects the results, and pushes them into console.log

Kind: static method of aah
Returns: function - a logging task
Params

  • ...statements * - any number of logging values. Functions are called with the calling request, everything else is passed directly to