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

api-chain

v0.0.8

Published

A light and easy to use interface for creating fluent, chainable javascript APIs in Node.js or PhantomJs

Downloads

35

Readme

api-chain


When performing many asynchronous operations in javascript, nested callbacks can become difficult to read and maintain. Api-chain is a very light and easy to use interface for creating a fluent synchronous style API for control flow of asynchronous javascript. It is packaged as a commonJS module through NPM but not only works with Node.js, but has been tested and works with PhantomJS as well.

Methods can pass values down the chain by invoking next with them, e.g. next(null, value). Node.js callback style methods will be wrapped automatically so as to pass the results down the chain.

installation

npm install api-chain

example

// require api-chain module
var api = require('api-chain');

// define your api by passing methods to create
var fs = api.create({
    read: require('fs').readFile,
    toString: function (data, next) {
        next(null, data.toString());
    },
    view: function (contents) {
        console.log(contents);
    }
});

// example using the chainable 'fs' API as created above
fs.read('./index.js')
  .toString()
  .view();

For more examples look in the examples subdirectory.

options

| name | type | default | description | |:---------------|:-----|:------------|:----------------------------------------------------------------| | onError | fn | undefined | called when error is emitted unless error method is overwritten | | throwErrors | bool | true | whether to throw unhandled errors (ignored if onError exists) | | continueErrors | bool | false | whether to resume execution of commands after errors occur |

built in chainable methods

api.wait(n) - pause execution flow for n milliseconds

api.until(fn) - wait until callback fn returns true before continuing execution flow

api.chain(fn) - add callback fn to be executed next in the control flow stack.

  • callback signature: fn([arg1,] [arg2,] ... [arg n,] [next])

api.set(name, value, [immediate]) - set api object property name to value

  • if the immediate flag is set, the value will be set immediately rather than within the control flow

immediate methods

The following methods execute immediately (rather than within the control flow) and always return the api object

api.setOption(option, value) - set option to value

api.setOptions(options) - set several options at once based on options collection of key/value pairs

testing

to test you will need the dev dependencies installed. Just cd to the directory api-chain is installed in and type

npm install

when installation of the dependencies completes, type

npm test

license

MIT Style License - see license.txt