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

liar

v0.6.0

Published

A modular collection of tools for asynchronous programing via promises

Downloads

18

Readme

liar

A modular collection of tools for asynchronous programing via promises, all tools are available as a bundle here or standalone in their own repo.

API

npm install liar
var promise = require('liar');

###basic promise

promise(function(resolve,reject){
    resolve(value);
    //or
    reject(reason);
});

a shortcut to my library lie. You need to give it a function which takes 2 arguments, a function to call on success and one to call on failure.

###all

promise.all(array (or promise for an array) of promises)

returns a promise for an array of all the responses, returns an error if any of the promises throw errors. Returned values are in the same order as the input array.

###some

promise.some(array (or promise for an array) of promises)

Similar to all but will only throw an error if all of the promises throw errors, otherwise returns an array of whichever values succeeded in the order that they completed, on error returns an array of errors.

###map

promise.map(array (or promise for an array) of promises, function)

Takes the array of values, applies function to them, and returns a promise for all the values. Function will be called with a value (not a promise) and may return either a promise or a value, array can filled with promises or values or a mixture.

###race

promise.race(array (or promise for an array) of promises)

resolved with whatever value or error that resolves first.

###cast

promise.cast(value or promise)

If it's a promise, returns it, if it's a value, returns a promise that resolves to it.

###use

promise.use(value or promise, function)

If the value is a promise, apply the function to the value it resolves into and return a promise for that, otherwise apply the function to the value and return the result.

###resolve

promise.resolve(value)

create a promise that is resolved with this value.

###reject

promise.reject(value)

create a promise that is rejected with this value.

###denodify

promise.denodify(function)

takes as an argument a function which has a callback as it's last argument, returns a function that acts identically except it returns a promise instead of taking a callback.

###fold left

promise.lfold(array (or promise for an array) of things,function,accumulator)

like Array.prototype.reduce, but the array may include promises or values and the function may return a promise or a value. promise.lfold always return a promise.

###fold right

promise.rfold(array (or promise for an array) of things,function,accumulator)

like Array.prototype.reduceRight, but the array may include promises or values and the function may return a promise or a value. promise.rfold always return a promise.

in other words it's like fold left but starts at the right

###fold

promise.fold(array (or promise for an array) of things,function,accumulator)

like Array.prototype.reduce, but the array may include promises or values and the function may return a promise or a value. promise.fold always return a promise.

unlike lfold and rfold fold calls the values in the order the promises resolve.

###apply

promise.apply(function, one or more values or promises)

calls the function with the values or promises once they all resolve, returns the result.

###zip

promise.zip(one or more arrays of things (or promises for arrays))

promise.zips the 2 or more arrays up such that zip([1,2],['a','b']) returns [[1,'a'],[2,'b']];. When called with one array it is equivalent to lie-map called with the function(a){return [a]}.

###zipwith

promise.zipwith(function,one or more arrays of things (or promises for arrays)

zips the 2 or more arrays up with a function 'func' such that zip(func(1,2),func('a','b')) returns [func(1,'a'),func(2,'b')];. When called with one array it is equivalent to lie-map (with the arguments in reverse order).

###filter

promise.filter(array (or promise for an array), function)

returns an array filtered based on the function, aka only truthy values are returned.

###every

promise.every(array (or promise for an array)[, function])

Applies the function the the array of promise or values (or mix) and returns true if they are all truthy.

It is lazy and will resolve as soon as the first falsy value is encountered.

If the function is omitted then it tests the truthiness of the values.

###any

promise.any(array (or promise for an array)[, function])

Applies the function the the array of promise or values (or mix) and returns true if at least one value is truthy.

It is lazy and will resolve as soon as one value returns true, if the function is omitted then it tests the truthiness of the array.

###iter

promise.iter(array of values or promises (or promise for such)[, function])

call the function on each value waiting for it to resolve before calling the next one. Returns an array of the values produced or the first error. If function is omitted it just resolves the promises sequentially (aka default function is function(a){return a})

###parallel

promise.parallel(array of values or promises (or promise for such)[, number, function])

A cross between lie-iter and lie-map, resolves the promises in parallel but only n of them at a time. Omitting the number is equivalent to map and setting it to 1 is the equivalent of lie-iter. Returns an array of the values produced or the first error. If function is omitted it just resolves the promises sequentially (aka default function is function(a){return a})

License

MIT