Comparing version 2.0.0 to 2.1.0
12
index.js
'use strict' | ||
exports.fromCallback = function (callback) { | ||
var queueTick = require('queue-tick') | ||
exports.fromCallback = function (callback, symbol) { | ||
if (callback === undefined) { | ||
@@ -12,3 +14,5 @@ var promise = new Promise(function (resolve, reject) { | ||
callback.promise = promise | ||
callback[symbol !== undefined ? symbol : 'promise'] = promise | ||
} else if (typeof callback !== 'function') { | ||
throw new TypeError('Callback must be a function') | ||
} | ||
@@ -23,4 +27,4 @@ | ||
promise | ||
.then(function (res) { process.nextTick(callback, null, res) }) | ||
.catch(function (err) { process.nextTick(callback, err) }) | ||
.then(function (res) { queueTick(() => callback(null, res)) }) | ||
.catch(function (err) { queueTick(() => callback(err)) }) | ||
} |
{ | ||
"name": "catering", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Simple utility to allow your module to be consumed with a callback or promise", | ||
@@ -10,9 +10,13 @@ "license": "MIT", | ||
}, | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"dependencies": {}, | ||
"dependencies": { | ||
"queue-tick": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"standard": "^14.0.0", | ||
"tape": "^4.10.1" | ||
"tape": "^5.0.0" | ||
}, | ||
@@ -19,0 +23,0 @@ "keywords": [ |
# catering | ||
> **Cater to callback and promise crowds.** | ||
> Simple utility to allow your module to be consumed with a callback or promise. | ||
**Cater to callback and promise crowds.** | ||
Simple utility to allow your module to be consumed with a callback or promise. For Node.js and browsers. | ||
@@ -10,3 +10,2 @@ [![npm status](http://img.shields.io/npm/v/catering.svg)](https://www.npmjs.org/package/catering) | ||
[![AppVeyor build status](https://img.shields.io/appveyor/ci/vweevers/catering.svg?label=appveyor)](https://ci.appveyor.com/project/vweevers/catering) | ||
[![Dependency status](https://img.shields.io/david/vweevers/catering.svg)](https://david-dm.org/vweevers/catering) | ||
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
@@ -20,7 +19,8 @@ | ||
const { fromCallback } = require('catering') | ||
const kPromise = Symbol('promise') | ||
module.exports = function (callback) { | ||
callback = fromCallback(callback) | ||
process.nextTick(callback, null, 'example') | ||
return callback.promise | ||
callback = fromCallback(callback, kPromise) | ||
queueMicrotask(() => callback(null, 'example')) | ||
return callback[kPromise] | ||
} | ||
@@ -27,0 +27,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
4794
5
29
1
+ Addedqueue-tick@^1.0.0
+ Addedqueue-tick@1.0.1(transitive)