Comparing version 3.0.2 to 4.0.2
44
index.js
@@ -5,3 +5,36 @@ 'use strict' | ||
function avowify(fn) { | ||
const messageArgumentIndex = { | ||
// assert(value[, message]) | ||
undefined: 1, | ||
// assert.deepEqual(actual, expected[, message]) | ||
deepEqual: 2, | ||
// assert.deepStrictEqual(actual, expected[, message]) | ||
deepStrictEqual: 2, | ||
// assert.doesNotThrow(block[, error][, message]) | ||
doesNotThrow: 2, | ||
// assert.equal(actual, expected[, message]) | ||
equal: 2, | ||
// Ignoring "fail" expecting message as third argument | ||
// assert.fail(message) | ||
// assert.fail(actual, expected[, message[, operator[, stackStartFunction]]]) | ||
fail: 0, | ||
// assert.ifError(value) | ||
ifError: Infinity, | ||
// assert.notDeepEqual(actual, expected[, message]) | ||
notDeepEqual: 2, | ||
// assert.notDeepStrictEqual(actual, expected[, message]) | ||
notDeepStrictEqual: 2, | ||
// assert.notEqual(actual, expected[, message]) | ||
notEqual: 2, | ||
// assert.notStrictEqual(actual, expected[, message]) | ||
notStrictEqual: 2, | ||
// assert.ok(value[, message]) | ||
ok: 1, | ||
// assert.strictEqual(actual, expected[, message]) | ||
strictEqual: 2, | ||
// assert.throws(block[, error][, message]) | ||
throws: 2, | ||
} | ||
function avowify(fn, methodName) { | ||
return function (...args) { | ||
@@ -23,4 +56,5 @@ try { fn(...args) } | ||
*/ | ||
const lastArg = args[args.length - 1] | ||
if (lastArg instanceof Error) throw lastArg | ||
const index = messageArgumentIndex[methodName] | ||
const message = index && args[index] | ||
if (message) throw message | ||
throw e | ||
@@ -33,5 +67,5 @@ } | ||
// e.g. avow.equal(...) | ||
get: (target, method) => avowify(target[method]), | ||
get: (target, methodName) => avowify(target[methodName], methodName), | ||
// e.g. avow(...) | ||
apply: (target, thisArg, args) => avowify(target).apply(thisArg, args) | ||
apply: (target, thisArg, args) => avowify(target, undefined).apply(thisArg, args) | ||
} | ||
@@ -38,0 +72,0 @@ |
{ | ||
"name": "avow", | ||
"version": "3.0.2", | ||
"version": "4.0.2", | ||
"description": "Proxy for assert that accepts custom Errors", | ||
@@ -10,3 +10,4 @@ "engines": { | ||
"scripts": { | ||
"test": "ava test" | ||
"test": "ava test", | ||
"test-watch": "ava -w test" | ||
}, | ||
@@ -28,5 +29,5 @@ "repository": { | ||
"devDependencies": { | ||
"ava": "^0.18.2", | ||
"ava": "^0.22.0", | ||
"eslint": "^3.18.0" | ||
} | ||
} | ||
} |
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
116902
6
66