ordu
Version:
Execute functions in a configurable order, modifying a shared data structure.
86 lines (58 loc) • 2.47 kB
Markdown
[![npm version][npm-badge]][npm-url]
[![Build Status][travis-badge]][travis-url]
[![Coverage Status][coveralls-badge]][coveralls-url]
[![Dependency Status][david-badge]][david-url]
[](https://deepscan.io/dashboard#view=project&tid=5016&pid=11434&bid=170370)
[](https://codeclimate.com/github/rjrodger/ordu/maintainability)
Task functions are executed in order of addition, and passed a shared
context, and a modifiable data structure. Execution is
synchronous. You can exit early by returning a non-null value from a
task function.
You can tag task functions, and restrict execution to the subset of
task functions with matching tags.
This module is used by the [Seneca](http://senecajs.org) framework to
provide configurable extension hooks.
```js
var Ordu = require('ordu')
var w = Ordu()
w.add(function first (ctxt, data) {
if (null == data.foo) {
return {kind: 'error', why: 'no foo'}
}
data.foo = data.foo.substring(0, ctxt.len)
})
w.add({tags: ['upper']}, function second (ctxt, data) {
data.foo = data.foo.toUpperCase()
})
var ctxt = {len: 3}
var data = {foo: 'green'}
w.process(ctxt, data)
console.log(data.foo) // prints 'GRE' (first, second)
data = {foo: 'blue'}
w.process({tags: ['upper']}, ctxt, data)
console.log(data.foo) // prints 'BLUE' (second)
data = []
var res = w.process(ctxt, data)
console.log(res) // prints {kind: 'error', why: 'no foo', ... introspection ...}
```
```sh
npm install ordu
```
From the Irish ordú: [instruction](http://www.focloir.ie/en/dictionary/ei/instruction). Pronounced _or-doo_.
Copyright (c) 2014-2020, Richard Rodger and other contributors.
Licensed under [MIT][].
[]: ./LICENSE
[]: https://travis-ci.org/rjrodger/ordu.svg
[]: https://travis-ci.org/rjrodger/ordu
[]: https://img.shields.io/npm/v/ordu.svg
[]: https://npmjs.com/package/ordu
[]: https://david-dm.org/rjrodger/ordu.svg
[]: https://david-dm.org/rjrodger/ordu
[]: https://coveralls.io/repos/github/rjrodger/ordu/badge.svg?branch=master
[]: https://coveralls.io/github/rjrodger/ordu?branch=master