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 🙏

© 2026 – Pkg Stats / Ryan Hefner

StaceFlow

v0.0.11

Published

Stace is a flow control library to help facilitate sequential promise/function execution

Readme

Stace Flow

Stace is a flow control library to help facilitate sequential promise/function execution. Api Reference is here: https://reallistic.github.io/staceflow/

Build Status

Rationale

Normally when working in frameworks like React, EventEmitters and state are used to facilitate business logic throughout the lifecycle of components and flux-like libraries. This library seeks to bring that functionality and more to any and all facets of Javascript. Stace can be used to take a collection of promises and give you back an event emitter. It can also be used to facilitate composable flows such as OAuth. Or, it can be used to flatten out a promise.

Installation

npm install StaceFlow
// or
yarn add StaceFlow

Examples

Simple Example

Without Stace:

function foo() {
    return service1.foo().then(data => {
        return service2.foo(data.param).then(moreData => {
            return service3.foo(data.param2, moreData.parm).then(() => data);
        });
    });
}

With Stace:

import { StartFlow, Constants } from 'StaceFlow';

function dataRetreiver(id) {
    let flow = CreateFlow(
        flow => {
            service1.foo().then(data => {
                flow.setState({data});
                flow.gotoNextStep();
            },
            error => {
                flow.setState({error});
                flow.failCurrentStep();
            });
        },
        flow => {
            service2.foo(flow.getState('data').param).then(moreData => {
                flow.setState({moreData});
                flow.gotoNextStep();
            },
            error => {
                flow.setState({error});
                flow.failCurrentStep();
            });
        },
        flow => {
            let data = flow.getState('data');
            let moreData = flow.getState('moreData');
            service3.foo(data.param2, moreData.param).then(() => {
                flow.gotoNextStep();
            },
            error => {
                flow.setState({error});
                flow.failCurrentStep();
            });
        });
    return new Promise((resolve, reject) => {
        flow.on(Constants.States.FINISHED, () => resolve(flow.getState('data')));
        flow.on(Constants.States.FAILED, (step) => reject(flow.getState('error')));
        flow.start();
    });
}

Thats not very helpful. We just added more code....

Composing flows

But then again what if we need to know which step failed?

function callService1(flow) {
    service1.foo().then(data => {
        flow.setState({data});
        flow.gotoNextStep();
    },
    error => {
        flow.setState({error});
        flow.failCurrentStep();
    });
}


function callService2(flow) {
    service2.foo(flow.getState('data').param).then(moreData => {
        flow.setState({moreData});
        flow.gotoNextStep();
    },
    error => {
        flow.setState({error});
        flow.failCurrentStep();
    });
}


function callService3(flow) {
    let data = flow.getState('data');
    let moreData = flow.getState('moreData');
    service3.foo(data.param2, moreData.param).then(() => {
        flow.gotoNextStep();
    },
    error => {
        flow.setState({error});
        flow.failCurrentStep();
    });
}


function dataRetreiver(id) {
    let flow = CreateFlow(
        callService1,
        callService2,
        callService3
    );
    return new Promise((resolve, reject) => {
        flow.on(Constants.States.FINISHED, () => resolve(flow.getState('data')));
        flow.on(Constants.States.FAILED, (step) => {
            if (step === callService3) {
                console.error('someone should check out service3', flow.getState('error'));
                resolve(flow.getState('data'));
            }
            else {
                reject(flow.getState('error'))
            }
        });
        flow.start();
    });
}

Thats a little more useful.

Reusing flows

Sometimes, all of them need not be called:

const Flow1 = [callService1, callService3];
const Flow2 = [callService1, callService2, callService3];

function dataRetreiver(opt_knownData) {
    let flow;
    if (opt_knownData) {
        flow = CreateFlow.apply(null, Flow1);
        flow.setState({moreData: opt_knownData});
    }
    else {
        flow = CreateFlow.apply(null, Flow2);
    }
    flow.start();
    return flow;
}

Adding steps

You can also add steps after the current one if needed:

function assertUser(flow) {
    if (flow.getState('authenticated')) {
        flow.gotoNextStep();
    }
    else {
        flow.addNextStep(authenticateUser);
        flow.gotoNextStep();
    }
}

or at the end of the flow:

function parseData(flow) {
    if (detectAnomaly(flow.getState('data'))) {
        flow.addStep(logResult);
    }
}