https://github.com/azer/new-chain
Create chaining APIs from functions
https://github.com/azer/new-chain
Last synced: 11 months ago
JSON representation
Create chaining APIs from functions
- Host: GitHub
- URL: https://github.com/azer/new-chain
- Owner: azer
- Created: 2013-04-23T20:22:57.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2013-07-24T01:09:21.000Z (almost 13 years ago)
- Last Synced: 2025-07-07T01:51:54.122Z (12 months ago)
- Language: JavaScript
- Size: 117 KB
- Stars: 11
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## new-chain [](https://travis-ci.org/azer/new-chain)
Create chaining APIs from functions
## Install
```bash
$ npm install new-chain
```
## Usage
```js
Num(3).sum(10).sub(5).mul(2).val()
// => 16
function Num(x){
var x = 0
var chain = newChain(sum, sub, mul) // or: { alias: mul, mul:mul } or: newChain({ alias: mul }, mul)
chain.val = val
return chain
function mul(n){
x *= n
}
function sum(n){
x += n
}
function sub(n){
x -= n
}
function val(n){
return x
}
}
```
### `from`
```js
x = [1, 2, 3]
val = newChain.from(x)(foo, bar)
val
// => [1, 2, 3]
val.foo().bar()
// => [1, 2, 3]
```
