Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justinvdm/drainpipe
pipe a value through a chain of functions
https://github.com/justinvdm/drainpipe
Last synced: 10 days ago
JSON representation
pipe a value through a chain of functions
- Host: GitHub
- URL: https://github.com/justinvdm/drainpipe
- Owner: justinvdm
- License: mit
- Created: 2014-12-21T19:39:52.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-04-24T18:10:46.000Z (over 2 years ago)
- Last Synced: 2024-10-05T03:50:02.284Z (about 1 month ago)
- Language: JavaScript
- Size: 1.78 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: readme.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# drainpipe
![Build Status](https://api.travis-ci.org/justinvdm/drainpipe.png)
utility for piping a value through a chain of functions
```js
vv(23)
(v => v * 2)
(v => v + 2)
(v => console.log(v))
// =>
48
```## api
### `vv(x)`
Takes in a value and starts a chain.
### `vv(x)(fn[, arg1[, arg2[, ...]]])`
Takes in a function and optional extra arguments, calls the function with the
current value in the drainpipe chain and stores its result as the new value in
the drainpipe chain.```js
function add(a, b) {
return a + b
}vv(23)
(add, 1)
(add, 3)
(v => console.log(v)) // 27
```### `vv(x)()`
Returns the current value in the drainpipe chain
```js
var x = vv(23)
(v => v * 2)
(v => v + 2)
()console.log(x) // 48
```## install
You can use this library as the npm package `drainpipe`:
```
npm i drainpipe
# or
yarn add drainpipe
```It can be used in both es-module-aware and commonjs bundlers/environments.
```js
// es module
import vv from 'drainpipe'// commonjs
const vv = require('drainpipe')
```It can also be used a ``:
```html
<script
crossorigin
src="https://unpkg.com/drainpipe/dist/umd/drainpipe.js"
>vv(23)(v => console.log(v))
```