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

@google-cloud/promisify

Package Overview
Dependencies
Maintainers
4
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/promisify - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

26

build/src/index.d.ts

@@ -34,2 +34,11 @@ /**

}
export interface CallbackifyAllOptions {
/**
* Array of methods to ignore when callbackifying.
*/
exclude?: string[];
}
export interface CallbackMethod extends Function {
callbackified_?: boolean;
}
/**

@@ -52,1 +61,18 @@ * Wraps a callback style function to conditionally return a promise.

export declare function promisifyAll(Class: Function, options?: PromisifyAllOptions): void;
/**
* Wraps a promisy type function to conditionally call a callback function.
*
* @param {function} originalMethod - The method to callbackify.
* @param {object=} options - Callback options.
* @param {boolean} options.singular - Pass to the callback a single arg instead of an array.
* @return {function} wrapped
*/
export declare function callbackify(originalMethod: CallbackMethod): CallbackMethod;
/**
* Callbackifies certain Class methods. This will not callbackify private or
* streaming methods.
*
* @param {module:common/service} Class - Service class.
* @param {object=} options - Configuration object.
*/
export declare function callbackifyAll(Class: Function, options?: CallbackifyAllOptions): void;

@@ -104,2 +104,60 @@ "use strict";

exports.promisifyAll = promisifyAll;
/**
* Wraps a promisy type function to conditionally call a callback function.
*
* @param {function} originalMethod - The method to callbackify.
* @param {object=} options - Callback options.
* @param {boolean} options.singular - Pass to the callback a single arg instead of an array.
* @return {function} wrapped
*/
function callbackify(originalMethod) {
if (originalMethod.callbackified_) {
return originalMethod;
}
// tslint:disable-next-line:no-any
const wrapper = function () {
const context = this;
if (typeof arguments[arguments.length - 1] !== 'function') {
return originalMethod.apply(context, arguments);
}
const cb = Array.prototype.pop.call(arguments);
originalMethod
.apply(context, arguments)
// tslint:disable-next-line:no-any
.then((res) => {
res = Array.isArray(res) ? res : [res];
cb(null, ...res);
}, (err) => cb(err));
};
wrapper.callbackified_ = true;
return wrapper;
}
exports.callbackify = callbackify;
/**
* Callbackifies certain Class methods. This will not callbackify private or
* streaming methods.
*
* @param {module:common/service} Class - Service class.
* @param {object=} options - Configuration object.
*/
function callbackifyAll(
// tslint:disable-next-line:variable-name
Class, options) {
const exclude = (options && options.exclude) || [];
const ownPropertyNames = Object.getOwnPropertyNames(Class.prototype);
const methods = ownPropertyNames.filter((methodName) => {
// clang-format off
return (typeof Class.prototype[methodName] === 'function' && // is it a function?
!/^_|(Stream|_)|^constructor$/.test(methodName) && // is it callbackifyable?
exclude.indexOf(methodName) === -1); // is it blacklisted?
// clang-format on
});
methods.forEach((methodName) => {
const originalMethod = Class.prototype[methodName];
if (!originalMethod.callbackified_) {
Class.prototype[methodName] = exports.callbackify(originalMethod);
}
});
}
exports.callbackifyAll = callbackifyAll;
//# sourceMappingURL=index.js.map

@@ -7,2 +7,57 @@ # Changelog

## v0.4.0
02-12-2019 19:44 PST
### New features
- feat: add callbackify() and callbackifyAll() methods ([#82](https://github.com/googleapis/nodejs-promisify/pull/82))
### Documentation
- docs: update contributing path in README ([#86](https://github.com/googleapis/nodejs-promisify/pull/86))
- chore: move CONTRIBUTING.md to root ([#85](https://github.com/googleapis/nodejs-promisify/pull/85))
- docs: add lint/fix example to contributing guide ([#83](https://github.com/googleapis/nodejs-promisify/pull/83))
### Internal / Testing Changes
- build: create docs test npm scripts ([#88](https://github.com/googleapis/nodejs-promisify/pull/88))
- build: test using @grpc/grpc-js in CI ([#87](https://github.com/googleapis/nodejs-promisify/pull/87))
- build: ignore googleapis.com in doc link check ([#81](https://github.com/googleapis/nodejs-promisify/pull/81))
- build: check broken links in generated docs ([#79](https://github.com/googleapis/nodejs-promisify/pull/79))
- chore(deps): update dependency @types/sinon to v7 ([#78](https://github.com/googleapis/nodejs-promisify/pull/78))
- chore(build): inject yoshi automation key ([#77](https://github.com/googleapis/nodejs-promisify/pull/77))
- chore: update nyc and eslint configs ([#76](https://github.com/googleapis/nodejs-promisify/pull/76))
- chore: fix publish.sh permission +x ([#74](https://github.com/googleapis/nodejs-promisify/pull/74))
- fix(build): fix Kokoro release script ([#73](https://github.com/googleapis/nodejs-promisify/pull/73))
- build: add Kokoro configs for autorelease ([#72](https://github.com/googleapis/nodejs-promisify/pull/72))
- chore: always nyc report before calling codecov ([#69](https://github.com/googleapis/nodejs-promisify/pull/69))
- chore: nyc ignore build/test by default ([#68](https://github.com/googleapis/nodejs-promisify/pull/68))
- chore(build): update prettier config ([#66](https://github.com/googleapis/nodejs-promisify/pull/66))
- fix: get the build passing ([#65](https://github.com/googleapis/nodejs-promisify/pull/65))
- chore: update license file ([#64](https://github.com/googleapis/nodejs-promisify/pull/64))
- fix(build): fix system key decryption ([#60](https://github.com/googleapis/nodejs-promisify/pull/60))
- chore(deps): update dependency @types/sinon to v5.0.7 ([#58](https://github.com/googleapis/nodejs-promisify/pull/58))
- fix: Pin @types/sinon to last compatible version ([#57](https://github.com/googleapis/nodejs-promisify/pull/57))
- chore: add synth.metadata
- chore(deps): update dependency gts to ^0.9.0 ([#54](https://github.com/googleapis/nodejs-promisify/pull/54))
- chore: update eslintignore config ([#53](https://github.com/googleapis/nodejs-promisify/pull/53))
- chore: use latest npm on Windows ([#52](https://github.com/googleapis/nodejs-promisify/pull/52))
- chore: update CircleCI config ([#51](https://github.com/googleapis/nodejs-promisify/pull/51))
- chore: include build in eslintignore ([#48](https://github.com/googleapis/nodejs-promisify/pull/48))
- chore: update issue templates ([#44](https://github.com/googleapis/nodejs-promisify/pull/44))
- chore: remove old issue template ([#42](https://github.com/googleapis/nodejs-promisify/pull/42))
- build: run tests on node11 ([#41](https://github.com/googleapis/nodejs-promisify/pull/41))
- chores(build): do not collect sponge.xml from windows builds ([#40](https://github.com/googleapis/nodejs-promisify/pull/40))
- chores(build): run codecov on continuous builds ([#39](https://github.com/googleapis/nodejs-promisify/pull/39))
- chore: update new issue template ([#38](https://github.com/googleapis/nodejs-promisify/pull/38))
- chore(deps): update dependency sinon to v7 ([#33](https://github.com/googleapis/nodejs-promisify/pull/33))
- build: fix codecov uploading on Kokoro ([#34](https://github.com/googleapis/nodejs-promisify/pull/34))
- Update kokoro config ([#30](https://github.com/googleapis/nodejs-promisify/pull/30))
- Update CI config ([#28](https://github.com/googleapis/nodejs-promisify/pull/28))
- Don't publish sourcemaps ([#26](https://github.com/googleapis/nodejs-promisify/pull/26))
- Update kokoro config ([#24](https://github.com/googleapis/nodejs-promisify/pull/24))
- test: remove appveyor config ([#23](https://github.com/googleapis/nodejs-promisify/pull/23))
- Update CI config ([#22](https://github.com/googleapis/nodejs-promisify/pull/22))
- Enable prefer-const in the eslint config ([#21](https://github.com/googleapis/nodejs-promisify/pull/21))
- Enable no-var in eslint ([#19](https://github.com/googleapis/nodejs-promisify/pull/19))
- Update CI config ([#18](https://github.com/googleapis/nodejs-promisify/pull/18))
## v0.3.1

@@ -9,0 +64,0 @@

30

package.json
{
"name": "@google-cloud/promisify",
"version": "0.3.1",
"version": "0.4.0",
"description": "A simple utility for promisifying functions and classes.",

@@ -9,5 +9,3 @@ "main": "build/src/index.js",

"scripts": {
"test": "npm run test-only",
"test-only": "nyc mocha build/test",
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json",
"test": "nyc mocha build/test",
"lint": "gts check",

@@ -20,10 +18,13 @@ "clean": "gts clean",

"posttest": "npm run lint",
"docs": "echo no docs 👻",
"docs": "compodoc src/",
"presystem-test": "npm run compile",
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
"system-test": "mocha build/system-test"
"system-test": "mocha build/system-test",
"docs-test": "blcl docs -r --exclude www.googleapis.com",
"predocs-test": "npm run docs"
},
"keywords": [],
"files": [
"build/src"
"build/src",
"!build/src/**/*.map"
],

@@ -33,7 +34,8 @@ "author": "Google Inc.",

"devDependencies": {
"@compodoc/compodoc": "^1.1.7",
"@types/mocha": "^5.2.4",
"@types/node": "^10.5.2",
"@types/sinon": "^5.0.1",
"@types/sinon": "^7.0.0",
"codecov": "^3.0.4",
"gts": "^0.8.0",
"gts": "^0.9.0",
"hard-rejection": "^1.0.0",

@@ -43,11 +45,7 @@ "intelli-espower-loader": "^1.0.1",

"nyc": "^13.0.0",
"sinon": "^6.1.3",
"sinon": "^7.0.0",
"source-map-support": "^0.5.6",
"typescript": "^3.0.0"
},
"nyc": {
"exclude": [
"build/test"
]
"typescript": "^3.0.0",
"broken-link-checker-local": "^0.2.0"
}
}
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
# @google-cloud/promisify
> A simple utility for promisifying functions and classes.
> A simple utility for promisifying and callbackifying functions and classes.

@@ -34,3 +34,3 @@ Google Cloud Common node.js module contains stuff used by other Cloud API modules.

Contributions welcome! See the [Contributing Guide](https://github.com/googlecloudplatform/google-cloud-node/blob/master/.github/CONTRIBUTING.md).
Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/nodejs-promisify/blob/master/CONTRIBUTING.md).

@@ -37,0 +37,0 @@ ## License

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