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

step-flow

v1.1.1

Published

step flow

Downloads

1,211

Readme

step-flow

step-flow is a lightweight(without any libraries and less than 200 lines) business processes control library that allows to easily manage business logic by step. step-flow using the syntax of middleware which is similar to express. It provides process control, step jumps, and unified error handling.

中文版文档

Build Status Build status codecov js-semistandard-style Node.js version license

Features

  • Simple and lightweight
  • Code coverage 100%
  • Support step name
  • Support step jump
  • Support asynchronous step flow
  • Supports error handling
  • Support context

Install

npm install --save step-flow

Usage

1. require step-flow

var Flow = require('step-flow');

2. create a flow

var flow = new Flow();

3. add step function

one step with multiple functions:

flow.use(
  'step1',
  function fn1 (ctx, next) {
    ctx.fn1 = true;
    next();
  },
  function fn11 (ctx, next) {
    ctx.fn11 = true;
    next();
  }
);

one step with one function:

flow
  .use('step2', function fn2 (ctx, next) {
    ctx.fn2 = true;
    // next();
  })
  .use(function fn3 (ctx, next) {
    ctx.fn3 = true;
  });

4. error handling

flow.catch(function (err) {
  console.log('flow error:', err);
});

5. run

var context = {};

flow.run(context)

API

StepFlow()

stepFlow.use([stepName]) ⇒ StepFlow

Add the steps and the corresponding function. If the specified steps already exist, these functions will be appended to this step. If it does not exist, create a new one.

Each function added here will receive the parameters (context, next, nextTo, data):

  • context: context object.
  • next(err[,data]): Execute the next function in step, and if it is not called, the next function will not be executed.
  • nextTo(step[,data]): Call this method and pass the step name, you can jump to the corresponding steps.
  • data: the data that the next(null, data) pass.

Only call next() will continue to execute the next function in the step. If a non-empty parameter err is passed, and the subsequent functions will not be executed. The error handling function set with catch(fn) will be executed. If you call next()/nextTo(), and passing the parameter data, the next function will receive this data. However, the functions that after the 'next function' will not receive this data, unless the 'next function' call next()/nextTo() and pass the data.

| Param | Type | Default | Description | | --- | --- | --- | --- | | [stepName] | String | 'default' | The step name, if you omit this parameter, the default use is default |

stepFlow.catch(fn) ⇒ StepFlow

Add error handling functions that will be executed when next (err) is called and a non-null err arguments are passed.

In addition, if an error occurs while running the method specified by the use() method, fn will also be executed and the error object will be passed to fn.

The fn will accept the parameter(err),err for the error message.

| Param | Type | Description | | --- | --- | --- | | fn | function | Error handling function |

stepFlow.run(context, stepName) ⇒ StepFlow

Start to run the step functions. If the step name is specified, it will be executed from the corresponding step. If it is not specified, it will be executed from the first step.

| Param | Type | Description | | --- | --- | --- | | context | Any | Context object, the function of each step will accept this parameter| | stepName | String |Start step name, starting from the first step by default |

Running tests

npm test

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

  • zdying - HTML/JavaScript/CSS/Node.js developer zdying

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details