makepromise
Advanced tools
Comparing version 3.1.0 to 3.1.1
let erotic = require('erotic'); if (erotic && erotic.__esModule) erotic = erotic.default; | ||
function checkArgumentIndex(length, i) { | ||
/** | ||
* @param {number} length | ||
* @param {number} i | ||
* @param {!Function} fn | ||
*/ | ||
function checkArgumentIndex(length, i, fn) { | ||
if (i > length - 2) { | ||
throw new Error('Function does not accept that many arguments.') | ||
throw new Error(`Function${fn.name ? ` ${fn.name}` : ''} does not accept that many arguments (max ${length - 1} + callback).`) | ||
} | ||
@@ -16,5 +21,5 @@ } | ||
*/ | ||
async function makePromise(fn, args, resolveValue) { | ||
async function makePromise(fn, args, resolveValue) { | ||
const er = erotic(true) | ||
if (typeof fn !== 'function') { | ||
if (typeof fn != 'function') { | ||
throw new Error('Function must be passed.') | ||
@@ -24,3 +29,3 @@ } | ||
if (!fnLength) { | ||
throw new Error('Function does not accept any arguments.') | ||
throw new Error(`Function${fn.name ? ` ${fn.name}` : ''} does not accept any arguments.`) | ||
} | ||
@@ -41,7 +46,7 @@ | ||
args.forEach((arg, i) => { | ||
checkArgumentIndex(fnLength, i) | ||
checkArgumentIndex(fnLength, i, fn) | ||
}) | ||
allArgs = [...args, cb] | ||
} else if (Array.from(arguments).length > 1) { // args passed as a single argument, not array | ||
checkArgumentIndex(fnLength, 0) | ||
checkArgumentIndex(fnLength, 0, fn) | ||
allArgs = [args, cb] | ||
@@ -48,0 +53,0 @@ } |
@@ -0,1 +1,7 @@ | ||
## 3 February 2020 | ||
### [3.1.0](git+https://github.com/artdecocode/makepromise/compare/v3.1.0...v3.1.1) | ||
- [fix] Better error messages. | ||
## 10 April 2019 | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "makepromise", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "Make a Promise from a function with a callback and preserve its error stack.", | ||
@@ -43,3 +43,3 @@ "main": "build/index.js", | ||
}, | ||
"homepage": "https://github.com/artdecocode/makepromise#readme", | ||
"homepage": "https://www.artd.eco", | ||
"devDependencies": { | ||
@@ -50,3 +50,3 @@ "alamode": "^1.9.2", | ||
"wrote": "^1.4.0", | ||
"yarn-s": "1.1.0", | ||
"yarn-s": "1.2.2", | ||
"zoroaster": "^3.11.4" | ||
@@ -53,0 +53,0 @@ }, |
import erotic from 'erotic' | ||
function checkArgumentIndex(length, i) { | ||
/** | ||
* @param {number} length | ||
* @param {number} i | ||
* @param {!Function} fn | ||
*/ | ||
function checkArgumentIndex(length, i, fn) { | ||
if (i > length - 2) { | ||
throw new Error('Function does not accept that many arguments.') | ||
throw new Error(`Function${fn.name ? ` ${fn.name}` : ''} does not accept that many arguments (max ${length - 1} + callback).`) | ||
} | ||
@@ -18,3 +23,3 @@ } | ||
const er = erotic(true) | ||
if (typeof fn !== 'function') { | ||
if (typeof fn != 'function') { | ||
throw new Error('Function must be passed.') | ||
@@ -24,3 +29,3 @@ } | ||
if (!fnLength) { | ||
throw new Error('Function does not accept any arguments.') | ||
throw new Error(`Function${fn.name ? ` ${fn.name}` : ''} does not accept any arguments.`) | ||
} | ||
@@ -41,7 +46,7 @@ | ||
args.forEach((arg, i) => { | ||
checkArgumentIndex(fnLength, i) | ||
checkArgumentIndex(fnLength, i, fn) | ||
}) | ||
allArgs = [...args, cb] | ||
} else if (Array.from(arguments).length > 1) { // args passed as a single argument, not array | ||
checkArgumentIndex(fnLength, 0) | ||
checkArgumentIndex(fnLength, 0, fn) | ||
allArgs = [args, cb] | ||
@@ -48,0 +53,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
No website
QualityPackage does not have a website.
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
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
12211
97