@google-cloud/promisify
Advanced tools
Comparing version 0.4.0 to 1.0.0
@@ -89,3 +89,3 @@ "use strict"; | ||
const ownPropertyNames = Object.getOwnPropertyNames(Class.prototype); | ||
const methods = ownPropertyNames.filter((methodName) => { | ||
const methods = ownPropertyNames.filter(methodName => { | ||
// clang-format off | ||
@@ -97,3 +97,3 @@ return (typeof Class.prototype[methodName] === 'function' && // is it a function? | ||
}); | ||
methods.forEach((methodName) => { | ||
methods.forEach(methodName => { | ||
const originalMethod = Class.prototype[methodName]; | ||
@@ -125,6 +125,5 @@ if (!originalMethod.promisified_) { | ||
const cb = Array.prototype.pop.call(arguments); | ||
originalMethod | ||
.apply(context, arguments) | ||
// tslint:disable-next-line:no-any | ||
.then((res) => { | ||
originalMethod.apply(context, arguments).then( | ||
// tslint:disable-next-line:no-any | ||
(res) => { | ||
res = Array.isArray(res) ? res : [res]; | ||
@@ -150,3 +149,3 @@ cb(null, ...res); | ||
const ownPropertyNames = Object.getOwnPropertyNames(Class.prototype); | ||
const methods = ownPropertyNames.filter((methodName) => { | ||
const methods = ownPropertyNames.filter(methodName => { | ||
// clang-format off | ||
@@ -158,3 +157,3 @@ return (typeof Class.prototype[methodName] === 'function' && // is it a function? | ||
}); | ||
methods.forEach((methodName) => { | ||
methods.forEach(methodName => { | ||
const originalMethod = Class.prototype[methodName]; | ||
@@ -161,0 +160,0 @@ if (!originalMethod.callbackified_) { |
@@ -7,2 +7,14 @@ # Changelog | ||
## [1.0.0](https://www.github.com/googleapis/nodejs-promisify/compare/v0.4.0...v1.0.0) (2019-05-02) | ||
### Build System | ||
* upgrade engines field to >=8.10.0 ([#108](https://www.github.com/googleapis/nodejs-promisify/issues/108)) ([78ab89c](https://www.github.com/googleapis/nodejs-promisify/commit/78ab89c)) | ||
### BREAKING CHANGES | ||
* upgrade engines field to >=8.10.0 (#108) | ||
## v0.4.0 | ||
@@ -79,2 +91,1 @@ | ||
- chore(deps): lock file maintenance (#2) | ||
{ | ||
"name": "@google-cloud/promisify", | ||
"version": "0.4.0", | ||
"version": "1.0.0", | ||
"description": "A simple utility for promisifying functions and classes.", | ||
@@ -21,3 +21,3 @@ "main": "build/src/index.js", | ||
"system-test": "mocha build/system-test", | ||
"docs-test": "blcl docs -r --exclude www.googleapis.com", | ||
"docs-test": "linkinator docs -r --skip www.googleapis.com", | ||
"predocs-test": "npm run docs" | ||
@@ -33,3 +33,3 @@ }, | ||
"devDependencies": { | ||
"@compodoc/compodoc": "^1.1.7", | ||
"@compodoc/compodoc": "^1.1.9", | ||
"@types/mocha": "^5.2.4", | ||
@@ -39,12 +39,15 @@ "@types/node": "^10.5.2", | ||
"codecov": "^3.0.4", | ||
"gts": "^0.9.0", | ||
"hard-rejection": "^1.0.0", | ||
"gts": "^1.0.0", | ||
"hard-rejection": "^2.0.0", | ||
"intelli-espower-loader": "^1.0.1", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.0.0", | ||
"linkinator": "^1.1.2", | ||
"mocha": "^6.0.0", | ||
"nyc": "^14.0.0", | ||
"sinon": "^7.0.0", | ||
"source-map-support": "^0.5.6", | ||
"typescript": "^3.0.0", | ||
"broken-link-checker-local": "^0.2.0" | ||
"typescript": "~3.4.0" | ||
}, | ||
"engines": { | ||
"node": ">=8.10.0" | ||
} | ||
} |
102
README.md
@@ -0,10 +1,21 @@ | ||
[//]: # "This README.md file is auto-generated, all changes to this file will be lost." | ||
[//]: # "To regenerate it, use `python -m synthtool`." | ||
<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 and callbackifying functions and classes. | ||
# [Google Cloud Common Promisify: Node.js Client](https://github.com/googleapis/nodejs-promisify) | ||
Google Cloud Common node.js module contains stuff used by other Cloud API modules. | ||
[![release level](https://img.shields.io/badge/release%20level-general%20availability%20%28GA%29-brightgreen.svg?style=flat)](https://cloud.google.com/terms/launch-stages) | ||
[![npm version](https://img.shields.io/npm/v/@google-cloud/promisify.svg)](https://www.npmjs.org/package/@google-cloud/promisify) | ||
[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-promisify/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-promisify) | ||
* [github.com/googlecloudplatform/google-cloud-node](https://github.com/googlecloudplatform/google-cloud-node) | ||
A simple utility for promisifying functions and classes. | ||
* [github.com/googleapis/nodejs-promisify](https://github.com/googleapis/nodejs-promisify) | ||
Read more about the client libraries for Cloud APIs, including the older | ||
@@ -15,7 +26,65 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained]. | ||
### Installing the package | ||
**Table of contents:** | ||
* [Quickstart](#quickstart) | ||
* [Installing the client library](#installing-the-client-library) | ||
* [Using the client library](#using-the-client-library) | ||
* [Samples](#samples) | ||
* [Versioning](#versioning) | ||
* [Contributing](#contributing) | ||
* [License](#license) | ||
## Quickstart | ||
### Installing the client library | ||
```bash | ||
npm install @google-cloud/promisify | ||
``` | ||
### Using the client library | ||
```javascript | ||
const {promisify} = require('@google-cloud/promisify'); | ||
/** | ||
* This is a very basic example function that accepts a callback. | ||
*/ | ||
function someCallbackFunction(name, callback) { | ||
if (!name) { | ||
callback(new Error('Name is required!')); | ||
} else { | ||
callback(null, `Well hello there, ${name}!`); | ||
} | ||
} | ||
// let's promisify it! | ||
const somePromiseFunction = promisify(someCallbackFunction); | ||
async function quickstart() { | ||
// now we can just `await` the function to use it like a promisified method | ||
const [result] = await somePromiseFunction('nodestronaut'); | ||
console.log(result); | ||
} | ||
quickstart(); | ||
``` | ||
It's unlikely you will need to install this package directly, as it will be | ||
installed as a dependency when you install other `@google-cloud` packages. | ||
## Samples | ||
Samples are in the [`samples/`](https://github.com/googleapis/nodejs-promisify/tree/master/samples) directory. The samples' `README.md` | ||
has instructions for running the samples. | ||
| Sample | Source Code | Try it | | ||
| --------------------------- | --------------------------------- | ------ | | ||
| Quickstart | [source code](https://github.com/googleapis/nodejs-promisify/blob/master/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-promisify&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) | | ||
## Versioning | ||
@@ -25,6 +94,13 @@ | ||
This library is considered to be in **alpha**. This means it is still a | ||
work-in-progress and under active development. Any release is subject to | ||
backwards-incompatible changes at any time. | ||
This library is considered to be **General Availability (GA)**. This means it | ||
is stable; the code surface will not change in backwards-incompatible ways | ||
unless absolutely necessary (e.g. because of critical security issues) or with | ||
an extensive deprecation period. Issues and requests against **GA** libraries | ||
are addressed with the highest priority. | ||
More Information: [Google Cloud Platform Launch Stages][launch_stages] | ||
@@ -42,2 +118,10 @@ | ||
See [LICENSE](https://github.com/googlecloudplatform/google-cloud-node/blob/master/LICENSE) | ||
See [LICENSE](https://github.com/googleapis/nodejs-promisify/blob/master/LICENSE) | ||
[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png | ||
[projects]: https://console.cloud.google.com/project | ||
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing | ||
[auth]: https://cloud.google.com/docs/authentication/getting-started |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
31635
1
124
236
1