Comparing version 0.1.2 to 0.1.3
@@ -1,41 +0,24 @@ | ||
;(function() { | ||
drainpipe.unwrap = unwrap | ||
drainpipe.unwrap = unwrap | ||
function drainpipe(x) { | ||
var curr = unwrap(x) | ||
self._drainpipe_chain = true | ||
function drainpipe(x) { | ||
var curr = unwrap(x) | ||
self._drainpipe_chain = true | ||
function self(fn) { | ||
if (!arguments.length) return curr | ||
function self(fn) { | ||
if (!arguments.length) return curr | ||
var args = Array.prototype.slice.call(arguments, 1) | ||
args.unshift(curr) | ||
curr = unwrap(fn.apply(fn, args)) | ||
var args = Array.prototype.slice.call(arguments, 1) | ||
args.unshift(curr) | ||
curr = unwrap(fn.apply(fn, args)) | ||
return self | ||
} | ||
return self | ||
} | ||
return self | ||
} | ||
function unwrap(x) { | ||
return (x || 0)._drainpipe_chain | ||
? x() | ||
: x | ||
} | ||
function unwrap(x) { | ||
return (x || 0)._drainpipe_chain ? x() : x | ||
} | ||
if (typeof module != 'undefined') { | ||
module.exports = drainpipe | ||
} | ||
else if (typeof define == 'function' && define.amd) { | ||
define(function() { | ||
return drainpipe | ||
}) | ||
} | ||
else { | ||
this.vv = drainpipe | ||
} | ||
}).call(this); | ||
module.exports = drainpipe |
{ | ||
"name": "drainpipe", | ||
"version": "0.1.2", | ||
"description": "pipe a value through a chain of functions", | ||
"version": "0.1.3", | ||
"description": "utility for piping a value through a chain of functions", | ||
"homepage": "https://github.com/justinvdm/drainpipe", | ||
"main": "drainpipe.js", | ||
"main": "./drainpipe.js", | ||
"type": "commonjs", | ||
"exports": { | ||
"import": "./drainpipe.mjs", | ||
"require": "./drainpipe.js" | ||
}, | ||
"types": "./drainpipe.d.ts", | ||
"files": [ | ||
"drainpipe.js", | ||
"drainpipe.d.ts", | ||
"dist" | ||
], | ||
"scripts": { | ||
"test": "mocha -R spec drainpipe.test.js" | ||
"build": "otr build drainpipe.js", | ||
"lint": "otr lint", | ||
"format": "otr format", | ||
"test": "otr test", | ||
"release": "otr release", | ||
"typetest": "otr typetest", | ||
"checks": "yarn lint && yarn typetest && yarn test" | ||
}, | ||
@@ -18,5 +35,14 @@ "author": "justinvdm", | ||
], | ||
"oftherivier": { | ||
"type": "es5", | ||
"src": "index.js", | ||
"libName": "vv" | ||
}, | ||
"renovate": { | ||
"extends": [ | ||
"github>oftherivier/tools" | ||
] | ||
}, | ||
"devDependencies": { | ||
"chai": "^1.9.1", | ||
"mocha": "^1.21.4" | ||
"@oftherivier/tools": "0.1.37" | ||
}, | ||
@@ -23,0 +49,0 @@ "repository": { |
@@ -5,31 +5,13 @@ # drainpipe | ||
pipe a value through a chain of functions | ||
utility for piping a value through a chain of functions | ||
```javascript | ||
```js | ||
vv(23) | ||
(function(v) { return v * 2 }) | ||
(function(v) { return v + 2 }) | ||
(function(v) { console.log(v) }) // 48 | ||
(v => v * 2) | ||
(v => v + 2) | ||
(v => console.log(v)) | ||
// => | ||
48 | ||
``` | ||
## install | ||
node: | ||
``` | ||
$ npm install drainpipe | ||
``` | ||
browser: | ||
``` | ||
$ bower install drainpipe | ||
``` | ||
```html | ||
<script src="/bower_components/drainpipe/drainpipe.js"></script> | ||
``` | ||
## api | ||
@@ -39,9 +21,11 @@ | ||
Takes in a value and starts a drainpipe chain. | ||
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. | ||
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. | ||
```javascript | ||
```js | ||
function add(a, b) { | ||
@@ -51,7 +35,6 @@ return a + b | ||
vv(23) | ||
(add, 1) | ||
(add, 3) | ||
(function(v) { console.log(v) }) // 27 | ||
(v => console.log(v)) // 27 | ||
``` | ||
@@ -63,9 +46,42 @@ | ||
```javascript | ||
```js | ||
var x = vv(23) | ||
(function(v) { return v * 2 }) | ||
(function(v) { return v + 2 }) | ||
(v => v * 2) | ||
(v => v + 2) | ||
() | ||
console.log(x) // 48 | ||
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 `<script>`: | ||
```html | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/drainpipe/dist/umd/drainpipe.js" | ||
></script> | ||
<script> | ||
vv(23)(v => console.log(v)) | ||
</script> | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
84
4307
6
26