Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promise-callbacks

Package Overview
Dependencies
Maintainers
16
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-callbacks - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

2

.eslintrc.json
{
"extends": "mixmax/node"
}
}
## Release History
* 3.1.0 Add `promisify.method` convenience method
* 3.0.0 Add waitOn, wrapAsync

@@ -4,0 +5,0 @@ Remove copyAll option from promisifyAll

{
"name": "promise-callbacks",
"version": "3.0.0",
"version": "3.1.0",
"description": "Utilities to help convert a callback-using codebase to promises.",

@@ -30,11 +30,15 @@ "engines": {

"devDependencies": {
"eslint": "^4.0.0",
"eslint-config-mixmax": "^0.2.0",
"eslint": ">=3",
"eslint-config-mixmax": "^0.6.0",
"express": "^4.15.2",
"jasmine": "^2.5.3",
"jasmine-promises": "github:mixmaxhq/jasmine-promises#working_in_node"
"jasmine-promises": "github:mixmaxhq/jasmine-promises#working_in_node",
"pre-commit": "^1.2.2"
},
"dependencies": {
"object.getownpropertydescriptors": "2.0.3"
}
},
"pre-commit": [
"lint"
]
}

@@ -144,2 +144,9 @@ # promise-callbacks

// If you just care about one method, a less verbose option you can use is promisify.method:
const readFileAsync = promisify.method(fs, 'readFile');
readFileAsync('input')
.then((content) => writeFile('output', content))
.catch((err) => console.error('err', err));
// If you know all the methods of the object are asynchronous, use promisify.all:

@@ -146,0 +153,0 @@ const api = {

{
"extends": "mixmax/node/spec"
}
}

@@ -16,3 +16,3 @@ const deferred = require('../src/deferred');

await promise;
} catch(e) {
} catch (e) {
err = e;

@@ -19,0 +19,0 @@ }

@@ -66,7 +66,27 @@ const promisify = require('../src/promisify');

describe('method', function() {
it('should promisify the given method', async function() {
const api = {
beepSound: 'boop',
beep(done) {
process.nextTick(() => done(null, this.beepSound));
}
};
const newBeepSound = 'beep';
api.beepSound = newBeepSound;
const origBeep = api.beep;
const beepPromiseAPI = promisify.method(api, 'beep');
expect(api.beep).toBe(origBeep);
expect(await beepPromiseAPI()).toBe(newBeepSound);
});
});
describe('methods', function() {
it('should promisify the given methods', async function() {
const api = {
beepSound: 'boop',
beep(done) {
process.nextTick(() => done(null, 8));
process.nextTick(() => done(null, this.beepSound));
},

@@ -78,4 +98,5 @@ noot() {

const newBeepSound = 'beep';
api.beepSound = newBeepSound;
const origBeep = api.beep;
const promiseAPI = promisify.methods(api, ['beep']);

@@ -87,3 +108,3 @@

expect(promiseAPI.noot).toBeUndefined();
expect(await promiseAPI.beep()).toBe(8);
expect(await promiseAPI.beep()).toBe(newBeepSound);
});

@@ -90,0 +111,0 @@ });

@@ -23,2 +23,3 @@ 'use strict';

promisify,
promisifyMethod: promisify.method,
promisifyMethods: promisify.methods,

@@ -25,0 +26,0 @@ promisifyAll: promisify.all,

@@ -81,2 +81,18 @@ 'use strict';

/**
* Promisify the given name on the given object, and create a copy of the object.
*
* @param {*} obj A value that can have properties.
* @param {String} methodName The method to promisify.
* @param {Boolean|String[]} options.variadic See the documentation for promisify.
* @return {Object} The promisified object.
*/
function promisifyMethod(obj, methodName, options) {
if (!obj) {
// This object could be anything, including a function, a real object, or an array.
throw new TypeError('promisify.method requires a truthy value');
}
return promisify(obj[methodName].bind(obj), options);
}
/**
* Promisify the given names on the given object, and create a copy of the object.

@@ -131,2 +147,3 @@ *

promisify.all = promisifyAll;
promisify.method = promisifyMethod;
promisify.methods = promisifyMethods;

@@ -133,0 +150,0 @@ promisify.promisifyAll = promisifyAll;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc