Comparing version 1.0.0 to 1.0.1
21
after.js
@@ -0,12 +1,14 @@ | ||
const sliced = require('sliced') | ||
module.exports = { | ||
sync, | ||
async | ||
sync: sync, | ||
async: async | ||
} | ||
function sync (fn, hook) { | ||
return (...args) => { | ||
const errOrValue = fn(...args) | ||
return function () { | ||
const errOrValue = fn.apply(this, arguments) | ||
return errOrValue instanceof Error | ||
? errOrValue | ||
: hook(errOrValue) | ||
: hook.call(this, errOrValue) | ||
} | ||
@@ -16,10 +18,11 @@ } | ||
function async (fn, hook) { | ||
return (...args) => { | ||
return function () { | ||
const args = sliced(arguments) | ||
const cb = args.pop() | ||
fn(...[...args, (err, value) => { | ||
fn.apply(this, args.concat([function (err, value) { | ||
if (err) cb(err) | ||
else hook(value, cb) | ||
}]) | ||
else hook.call(this, value, cb) | ||
}.bind(this)])) | ||
} | ||
} | ||
@@ -0,9 +1,12 @@ | ||
const sliced = require('sliced') | ||
module.exports = { | ||
sync, | ||
async | ||
sync: sync, | ||
async: async | ||
} | ||
function sync (fn, hook) { | ||
return (...args) => { | ||
return hook(fn, args) | ||
return function () { | ||
const args = sliced(arguments) | ||
return hook.call(this, fn, args) | ||
} | ||
@@ -13,6 +16,7 @@ } | ||
function async (fn, hook) { | ||
return (...args) => { | ||
return function () { | ||
const args = sliced(arguments) | ||
const cb = args.pop() | ||
hook(fn, args, cb) | ||
hook.call(this, fn, args, cb) | ||
} | ||
} |
@@ -0,12 +1,15 @@ | ||
const sliced = require('sliced') | ||
module.exports = { | ||
sync, | ||
async | ||
sync: sync, | ||
async: async | ||
} | ||
function sync (fn, hook) { | ||
return (...args) => { | ||
const err = hook(args) | ||
return function () { | ||
const args = sliced(arguments) | ||
const err = hook.call(this, args) | ||
if (err instanceof Error) return err | ||
const newArgs = err | ||
return fn(...newArgs) | ||
return fn.apply(this, newArgs) | ||
} | ||
@@ -16,9 +19,10 @@ } | ||
function async (fn, hook) { | ||
return (...args) => { | ||
return function () { | ||
const args = sliced(arguments) | ||
const cb = args.pop() | ||
hook(args, (err, newArgs) => { | ||
hook.call(this, args, function (err, newArgs) { | ||
if (err) cb(err) | ||
else fn(...[...newArgs, cb]) | ||
}) | ||
else fn.apply(this, newArgs.concat([cb])) | ||
}.bind(this)) | ||
} | ||
} |
@@ -6,5 +6,5 @@ const before = require('./before') | ||
module.exports = { | ||
before, | ||
after, | ||
around, | ||
before: before, | ||
after: after, | ||
around: around, | ||
@@ -11,0 +11,0 @@ sync: { |
{ | ||
"name": "aspects", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "before, after, and around hooks for sync and sync functions", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "standard && tape test/*.js" | ||
"test:deps": "dependency-check . && dependency-check . --extra --no-dev", | ||
"test:lint": "standard", | ||
"test:node": "NODE_ENV=test tape test/index.js", | ||
"test:coverage": "NODE_ENV=test istanbul cover test", | ||
"test": "npm-run-all -s test:deps test:lint test:node" | ||
}, | ||
@@ -22,6 +26,11 @@ "repository": { | ||
"cat-names": "^1.0.2", | ||
"dependency-check": "^2.6.0", | ||
"istanbul": "^0.4.4", | ||
"npm-run-all": "^2.3.0", | ||
"standard": "^7.1.2", | ||
"tape": "^4.5.1" | ||
}, | ||
"dependencies": {} | ||
"dependencies": { | ||
"sliced": "^1.0.1" | ||
} | ||
} |
@@ -1,2 +0,4 @@ | ||
# aspects | ||
# aspects [![stability][stability-badge]][stability-url] | ||
[![npm version][version-badge]][version-url] [![test status][test-badge]][test-url] [![test coverage][coverage-badge]][coverage-url] | ||
[![downloads][downloads-badge]][downloads-url] [![standard style][standard-badge]][standard-url] | ||
@@ -7,6 +9,4 @@ before, after, and around hooks for sync and async functions | ||
**work in progress** | ||
```shell | ||
npm install --save ahdinosaur/aspects | ||
npm install --save aspects | ||
``` | ||
@@ -128,1 +128,14 @@ | ||
limitations under the License. | ||
[stability-badge]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square | ||
[stability-url]: https://nodejs.org/api/documentation.html#documentation_stability_index | ||
[version-badge]: https://img.shields.io/npm/v/aspects.svg?style=flat-square | ||
[version-url]: https://npmjs.org/package/aspects | ||
[test-badge]: https://img.shields.io/travis/ahdinosaur/aspects/master.svg?style=flat-square | ||
[test-url]: https://travis-ci.org/ahdinosaur/aspects | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/ahdinosaur/aspects/master.svg?style=flat-square | ||
[coverage-url]: https://codecov.io/github/ahdinosaur/aspects | ||
[downloads-badge]: http://img.shields.io/npm/dm/aspects.svg?style=flat-square | ||
[downloads-url]: https://npmjs.org/package/aspects | ||
[standard-badge]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square | ||
[standard-url]: https://github.com/feross/standard |
@@ -14,1 +14,5 @@ const test = require('tape') | ||
}) | ||
require('./before') | ||
require('./after') | ||
require('./around') |
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
13995
13
349
140
1
6
+ Addedsliced@^1.0.1
+ Addedsliced@1.0.1(transitive)