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

chaining

v0.3.2

Published

Yet Another Chaining Library

Downloads

21

Readme

Build Status Coverage Version Dependencies Dev Dependencies Coverage Graph

Yet Another Javascript Chaining Library

Make callbacks simple, easy and readable.

Goals

  • Strong error handling, keep Zalgo chained
  • Deadly simple
  • Complient with common deferred methods (node convention, promise standard and browser style)

Install

npm install chaining

You also need a es6 Promise library:

With when

require('chaining/src/es6/when');

With Q

require('chaining/src/es6/q');

Examples


var chain = new Chain();

chain.next(promiseForStuff());

chain.next(function (stuff) {
    return promiseSomethingElse(stuff);
});

chain.process().then(function () {
    console.log('end of process');
});

With parallelism and data flow:


var chain = new Chain();

chain.next(function () {
    this.json = {};
}).fork([
    'file1.json',
    'file2.json',
    'file3.json'
]).next(function (file, done) {
    fs.readFile(file, done);
]).next(function (content) {
    _.extend(this.json, JSON.pase(content));
});

chain.process().then(function () {
    console.log('all files processed');
});

var chain = new Chain(function (id) {
    return db.users.findOne({id: id});
})
.next(function (user) {
    this.user = user;
    return db.roles.find({user: this.user});

})
.next(function (roles) {
    this.roles = roles;

    if ('admin' in roles) {
        this.user.admin = true;
    }
    return this.user.save();
});

chain.process(123);
var manager = new PackageManager();

var installer = new Chain();


installer.fork(function (depndencies) {
    return this.depndencies;
})
.next(function (package) {
    this.package = package;
    return manager.preinstall(this.package);
})
.next(function () {
    return manager.install(this.package);
})
.next(function () {
    return manager.postinstall(this.package);
});

exports.install = function (depndencies) {

    installer.process(depndencies).then(function () {
        console.log('All installation completed');
    }, function (err) {
        console.error('Somethings went wrong...');
    }, function (dep) {
        console.log('Install ended for', dep.name);
    });
};

API

Constructor()

Make a new chain.

.next(step)

Add a step to the sequence. step can be:

  • a function that return a value
  • a function that retrun a promise
  • an async function that take a done callback
  • a value
  • a promise (non sens ? promise can be resolve only once...)

.fork(iterable)

Fork and continue the sequence in parallel for each iterable item.

.join()

Wait for all forks and continue as a sigle sequence.

.process(value)

Start the sequence of steps with value as initial value. All steps are called in sequence after the previous step succeed and will share the same context (this). The sequence will be suspend when step raise an exception or when step return an rejected promise.

TODO

  • Make it works in browser and publish on Bower
  • Limit concurent forks
  • add index for fork
  • Progress notification for forks or steps ?
  • Accept a node style callback for process
  • Test fork with generators
  • Error handling
  • propate the number of arguments given by previous step (currently fixed to one)