universalify
Advanced tools
Comparing version 0.2.0 to 1.0.0
26
index.js
'use strict' | ||
exports.fromCallback = function (fn) { | ||
return Object.defineProperty(function () { | ||
if (typeof arguments[arguments.length - 1] === 'function') fn.apply(this, arguments) | ||
return Object.defineProperty(function (...args) { | ||
if (typeof args[args.length - 1] === 'function') fn.apply(this, args) | ||
else { | ||
return new Promise((resolve, reject) => { | ||
arguments[arguments.length] = (err, res) => { | ||
if (err) return reject(err) | ||
resolve(res) | ||
} | ||
arguments.length++ | ||
fn.apply(this, arguments) | ||
fn.apply( | ||
this, | ||
args.concat([(err, res) => err ? reject(err) : resolve(res)]) | ||
) | ||
}) | ||
@@ -20,11 +18,7 @@ } | ||
exports.fromPromise = function (fn) { | ||
return Object.defineProperty(function () { | ||
const cb = arguments[arguments.length - 1] | ||
if (typeof cb !== 'function') return fn.apply(this, arguments) | ||
else { | ||
delete arguments[arguments.length - 1] | ||
arguments.length-- | ||
fn.apply(this, arguments).then(r => cb(null, r), cb) | ||
} | ||
return Object.defineProperty(function (...args) { | ||
const cb = args[args.length - 1] | ||
if (typeof cb !== 'function') return fn.apply(this, args) | ||
else fn.apply(this, args.slice(0, -1)).then(r => cb(null, r), cb) | ||
}, 'name', { value: fn.name }) | ||
} |
{ | ||
"name": "universalify", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "Make a callback- or promise-based function support both promises and callbacks.", | ||
@@ -27,9 +27,9 @@ "keywords": [ | ||
"coveralls": "^3.0.1", | ||
"nyc": "^10.2.0", | ||
"standard": "^10.0.1", | ||
"nyc": "^15.0.0", | ||
"standard": "^14.3.1", | ||
"tape": "^4.6.3" | ||
}, | ||
"engines": { | ||
"node": ">= 4.0.0" | ||
"node": ">= 10.0.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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
4626
21