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
- Host: GitHub
- URL: https://github.com/imcuttle/run-seq
- Owner: imcuttle
- License: mit
- Created: 2019-12-05T15:30:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T02:23:33.000Z (over 3 years ago)
- Last Synced: 2025-10-19T01:54:15.465Z (8 months ago)
- Language: JavaScript
- Size: 2.04 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: License
Awesome Lists containing this project
README
# run-seq
[](https://travis-ci.org/imcuttle/run-seq)
[](https://codecov.io/github/imcuttle/run-seq?branch=master)
[](https://www.npmjs.com/package/run-seq)
[](https://www.npmjs.com/package/run-seq)
[](https://prettier.io/)
[](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) 🐟