summaryrefslogtreecommitdiff
path: root/node_modules/pify
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-08-30 17:21:18 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-08-30 17:21:18 +0800
commitefbc2ffe6a1ee5ec38a4396305561d6515d0943e (patch)
tree2b4c94f18f2c792dfda813050755d5c0273fae22 /node_modules/pify
parent43acceb75957c880a5ba5a31aae221394a36d5f6 (diff)
node fixes, updates
Diffstat (limited to 'node_modules/pify')
-rw-r--r--node_modules/pify/index.js102
-rw-r--r--node_modules/pify/license20
-rw-r--r--node_modules/pify/package.json95
-rw-r--r--node_modules/pify/readme.md78
4 files changed, 156 insertions, 139 deletions
diff --git a/node_modules/pify/index.js b/node_modules/pify/index.js
index 7c720ebe..df56221d 100644
--- a/node_modules/pify/index.js
+++ b/node_modules/pify/index.js
@@ -1,68 +1,68 @@
'use strict';
-var processFn = function (fn, P, opts) {
- return function () {
- var that = this;
- var args = new Array(arguments.length);
-
- for (var i = 0; i < arguments.length; i++) {
- args[i] = arguments[i];
- }
-
- return new P(function (resolve, reject) {
- args.push(function (err, result) {
- if (err) {
- reject(err);
- } else if (opts.multiArgs) {
- var results = new Array(arguments.length - 1);
-
- for (var i = 1; i < arguments.length; i++) {
- results[i - 1] = arguments[i];
+const processFn = (fn, options) => function (...args) {
+ const P = options.promiseModule;
+
+ return new P((resolve, reject) => {
+ if (options.multiArgs) {
+ args.push((...result) => {
+ if (options.errorFirst) {
+ if (result[0]) {
+ reject(result);
+ } else {
+ result.shift();
+ resolve(result);
}
-
- resolve(results);
} else {
resolve(result);
}
});
+ } else if (options.errorFirst) {
+ args.push((error, result) => {
+ if (error) {
+ reject(error);
+ } else {
+ resolve(result);
+ }
+ });
+ } else {
+ args.push(resolve);
+ }
- fn.apply(that, args);
- });
- };
+ fn.apply(this, args);
+ });
};
-var pify = module.exports = function (obj, P, opts) {
- if (typeof P !== 'function') {
- opts = P;
- P = Promise;
- }
-
- opts = opts || {};
- opts.exclude = opts.exclude || [/.+Sync$/];
+module.exports = (input, options) => {
+ options = Object.assign({
+ exclude: [/.+(Sync|Stream)$/],
+ errorFirst: true,
+ promiseModule: Promise
+ }, options);
- var filter = function (key) {
- var match = function (pattern) {
- return typeof pattern === 'string' ? key === pattern : pattern.test(key);
- };
+ const objType = typeof input;
+ if (!(input !== null && (objType === 'object' || objType === 'function'))) {
+ throw new TypeError(`Expected \`input\` to be a \`Function\` or \`Object\`, got \`${input === null ? 'null' : objType}\``);
+ }
- return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
+ const filter = key => {
+ const match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);
+ return options.include ? options.include.some(match) : !options.exclude.some(match);
};
- var ret = typeof obj === 'function' ? function () {
- if (opts.excludeMain) {
- return obj.apply(this, arguments);
- }
-
- return processFn(obj, P, opts).apply(this, arguments);
- } : {};
-
- return Object.keys(obj).reduce(function (ret, key) {
- var x = obj[key];
+ let ret;
+ if (objType === 'function') {
+ ret = function (...args) {
+ return options.excludeMain ? input(...args) : processFn(input, options).apply(this, args);
+ };
+ } else {
+ ret = Object.create(Object.getPrototypeOf(input));
+ }
- ret[key] = typeof x === 'function' && filter(key) ? processFn(x, P, opts) : x;
+ for (const key in input) { // eslint-disable-line guard-for-in
+ const property = input[key];
+ ret[key] = typeof property === 'function' && filter(key) ? processFn(property, options) : property;
+ }
- return ret;
- }, ret);
+ return ret;
};
-
-pify.all = pify;
diff --git a/node_modules/pify/license b/node_modules/pify/license
index 654d0bfe..e7af2f77 100644
--- a/node_modules/pify/license
+++ b/node_modules/pify/license
@@ -1,21 +1,9 @@
-The MIT License (MIT)
+MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/node_modules/pify/package.json b/node_modules/pify/package.json
index 311d1982..a5468cd2 100644
--- a/node_modules/pify/package.json
+++ b/node_modules/pify/package.json
@@ -1,48 +1,51 @@
{
- "name": "pify",
- "version": "2.3.0",
- "description": "Promisify a callback-style function",
- "license": "MIT",
- "repository": "sindresorhus/pify",
- "author": {
- "name": "Sindre Sorhus",
- "email": "sindresorhus@gmail.com",
- "url": "sindresorhus.com"
- },
- "engines": {
- "node": ">=0.10.0"
- },
- "scripts": {
- "test": "xo && ava && npm run optimization-test",
- "optimization-test": "node --allow-natives-syntax optimization-test.js"
- },
- "files": [
- "index.js"
- ],
- "keywords": [
- "promise",
- "promises",
- "promisify",
- "denodify",
- "denodeify",
- "callback",
- "cb",
- "node",
- "then",
- "thenify",
- "convert",
- "transform",
- "wrap",
- "wrapper",
- "bind",
- "to",
- "async",
- "es2015"
- ],
- "devDependencies": {
- "ava": "*",
- "pinkie-promise": "^1.0.0",
- "v8-natives": "0.0.2",
- "xo": "*"
- }
+ "name": "pify",
+ "version": "4.0.1",
+ "description": "Promisify a callback-style function",
+ "license": "MIT",
+ "repository": "sindresorhus/pify",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=6"
+ },
+ "scripts": {
+ "test": "xo && ava",
+ "optimization-test": "node --allow-natives-syntax optimization-test.js"
+ },
+ "files": [
+ "index.js"
+ ],
+ "keywords": [
+ "promise",
+ "promises",
+ "promisify",
+ "all",
+ "denodify",
+ "denodeify",
+ "callback",
+ "cb",
+ "node",
+ "then",
+ "thenify",
+ "convert",
+ "transform",
+ "wrap",
+ "wrapper",
+ "bind",
+ "to",
+ "async",
+ "await",
+ "es2015",
+ "bluebird"
+ ],
+ "devDependencies": {
+ "ava": "^0.25.0",
+ "pinkie-promise": "^2.0.0",
+ "v8-natives": "^1.1.0",
+ "xo": "^0.23.0"
+ }
}
diff --git a/node_modules/pify/readme.md b/node_modules/pify/readme.md
index c79ca8bf..7ae3f1c5 100644
--- a/node_modules/pify/readme.md
+++ b/node_modules/pify/readme.md
@@ -2,11 +2,25 @@
> Promisify a callback-style function
+---
+
+<div align="center">
+ <b>
+ <a href="https://tidelift.com/subscription/pkg/npm-pify?utm_source=npm-pify&utm_medium=referral&utm_campaign=readme">Get professional support for 'pify' with a Tidelift subscription</a>
+ </b>
+ <br>
+ <sub>
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
+ </sub>
+</div>
+
+---
+
## Install
```
-$ npm install --save pify
+$ npm install pify
```
@@ -16,15 +30,13 @@ $ npm install --save pify
const fs = require('fs');
const pify = require('pify');
-// promisify a single function
-
+// Promisify a single function
pify(fs.readFile)('package.json', 'utf8').then(data => {
console.log(JSON.parse(data).name);
//=> 'pify'
});
-// or promisify all methods in a module
-
+// Promisify all methods in a module
pify(fs).readFile('package.json', 'utf8').then(data => {
console.log(JSON.parse(data).name);
//=> 'pify'
@@ -34,32 +46,24 @@ pify(fs).readFile('package.json', 'utf8').then(data => {
## API
-### pify(input, [promiseModule], [options])
+### pify(input, [options])
-Returns a promise wrapped version of the supplied function or module.
+Returns a `Promise` wrapped version of the supplied function or module.
#### input
-Type: `function`, `object`
+Type: `Function` `Object`
Callback-style function or module whose methods you want to promisify.
-#### promiseModule
-
-Type: `function`
-
-Custom promise module to use instead of the native one.
-
-Check out [`pinkie-promise`](https://github.com/floatdrop/pinkie-promise) if you need a tiny promise polyfill.
-
#### options
##### multiArgs
-Type: `boolean`
+Type: `boolean`<br>
Default: `false`
-By default, the promisified function will only return the second argument from the callback, which works fine for most APIs. This option can be useful for modules like `request` that return multiple arguments. Turning this on will make it return an array of all arguments from the callback, excluding the error argument, instead of just the second argument.
+By default, the promisified function will only return the second argument from the callback, which works fine for most APIs. This option can be useful for modules like `request` that return multiple arguments. Turning this on will make it return an array of all arguments from the callback, excluding the error argument, instead of just the second argument. This also applies to rejections, where it returns an array of all the callback arguments, including the error.
```js
const request = require('request');
@@ -72,23 +76,23 @@ pify(request, {multiArgs: true})('https://sindresorhus.com').then(result => {
##### include
-Type: `array` of (`string`|`regex`)
+Type: `string[]` `RegExp[]`
Methods in a module to promisify. Remaining methods will be left untouched.
##### exclude
-Type: `array` of (`string`|`regex`)
-Default: `[/.+Sync$/]`
+Type: `string[]` `RegExp[]`<br>
+Default: `[/.+(Sync|Stream)$/]`
Methods in a module **not** to promisify. Methods with names ending with `'Sync'` are excluded by default.
##### excludeMain
-Type: `boolean`
+Type: `boolean`<br>
Default: `false`
-By default, if given module is a function itself, this function will be promisified. Turn this option on if you want to promisify only methods of the module.
+If given module is a function itself, it will be promisified. Turn this option on if you want to promisify only methods of the module.
```js
const pify = require('pify');
@@ -99,11 +103,11 @@ function fn() {
fn.method = (data, callback) => {
setImmediate(() => {
- callback(data, null);
+ callback(null, data);
});
};
-// promisify methods but not fn()
+// Promisify methods but not `fn()`
const promiseFn = pify(fn, {excludeMain: true});
if (promiseFn()) {
@@ -113,7 +117,29 @@ if (promiseFn()) {
}
```
+##### errorFirst
+
+Type: `boolean`<br>
+Default: `true`
+
+Whether the callback has an error as the first argument. You'll want to set this to `false` if you're dealing with an API that doesn't have an error as the first argument, like `fs.exists()`, some browser APIs, Chrome Extension APIs, etc.
+
+##### promiseModule
+
+Type: `Function`
+
+Custom promise module to use instead of the native one.
+
+Check out [`pinkie-promise`](https://github.com/floatdrop/pinkie-promise) if you need a tiny promise polyfill.
+
+
+## Related
+
+- [p-event](https://github.com/sindresorhus/p-event) - Promisify an event by waiting for it to be emitted
+- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
+- [More…](https://github.com/sindresorhus/promise-fun)
+
## License
-MIT © [Sindre Sorhus](http://sindresorhus.com)
+MIT © [Sindre Sorhus](https://sindresorhus.com)