An open API service indexing awesome lists of open source software.

https://github.com/imcuttle/run-seq

run a series of tasks with next controller
https://github.com/imcuttle/run-seq

Last synced: 5 months ago
JSON representation

run a series of tasks with next controller

Awesome Lists containing this project

README

          

# run-seq

[![Build status](https://img.shields.io/travis/imcuttle/run-seq/master.svg?style=flat-square)](https://travis-ci.org/imcuttle/run-seq)
[![Test coverage](https://img.shields.io/codecov/c/github/imcuttle/run-seq.svg?style=flat-square)](https://codecov.io/github/imcuttle/run-seq?branch=master)
[![NPM version](https://img.shields.io/npm/v/run-seq.svg?style=flat-square)](https://www.npmjs.com/package/run-seq)
[![NPM Downloads](https://img.shields.io/npm/dm/run-seq.svg?style=flat-square&maxAge=43200)](https://www.npmjs.com/package/run-seq)
[![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://prettier.io/)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=flat-square)](https://conventionalcommits.org)

> run a series of tasks with next controller
>
> It's useful for splitting multiple related tasks.

## Installation

```bash
npm install run-seq
# or use yarn
yarn add run-seq
```

## Usage

```javascript
import runSeq from 'run-seq'
const tree = {
tagName: 'p',
nodes: [
{
tagName: 'img',
data: {
src: './img.png'
}
},
{
tagName: 'text',
text: 'lalalala'
},
{
tagName: 'p',
nodes: [
{
tagName: 'img',
data: {
src: './img.png'
}
},
{
tagName: 'text',
text: 'lalalala'
}
]
}
]
}

const html = runSeq(
[
// 0
(node, next) => {
if (!node) return ''
if (!Array.isArray(node)) {
node = [node]
}

return node.map(node => next(node)).join('\n')
},
// 1
(node, next) => {
switch (node.tagName) {
case 'img':
return ``
case 'p':
// `next.all` is processing the all sequence (0-3)
return `

${next.all(node.nodes)}

`
}
// `next` is processing the next task (2)
return next(node)
},
// 2
(node, next) => {
switch (node.tagName) {
case 'text':
return node.text
}
return next(node)
},
// 3
node => ''
],
[tree]
)

html // =>

lalalala

lalalala


```

## Contributing

- Fork it!
- Create your new branch:
`git checkout -b feature-new` or `git checkout -b fix-which-bug`
- Start your magic work now
- Make sure npm test passes
- Commit your changes:
`git commit -am 'feat: some description (close #123)'` or `git commit -am 'fix: some description (fix #123)'`
- Push to the branch: `git push`
- Submit a pull request :)

## Authors

This library is written and maintained by imcuttle, moyuyc95@gmail.com.

## License

MIT - [imcuttle](https://github.com/imcuttle) 🐟