Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/p-try')
-rw-r--r--node_modules/p-try/index.d.ts39
-rw-r--r--node_modules/p-try/index.js9
-rw-r--r--node_modules/p-try/license20
-rw-r--r--node_modules/p-try/package.json39
-rw-r--r--node_modules/p-try/readme.md38
5 files changed, 98 insertions, 47 deletions
diff --git a/node_modules/p-try/index.d.ts b/node_modules/p-try/index.d.ts
new file mode 100644
index 000000000..2a7319ec2
--- /dev/null
+++ b/node_modules/p-try/index.d.ts
@@ -0,0 +1,39 @@
+declare const pTry: {
+ /**
+ Start a promise chain.
+
+ @param fn - The function to run to start the promise chain.
+ @param arguments - Arguments to pass to `fn`.
+ @returns The value of calling `fn(...arguments)`. If the function throws an error, the returned `Promise` will be rejected with that error.
+
+ @example
+ ```
+ import pTry = require('p-try');
+
+ (async () => {
+ try {
+ const value = await pTry(() => {
+ return synchronousFunctionThatMightThrow();
+ });
+ console.log(value);
+ } catch (error) {
+ console.error(error);
+ }
+ })();
+ ```
+ */
+ <ValueType, ArgumentsType extends unknown[]>(
+ fn: (...arguments: ArgumentsType) => PromiseLike<ValueType> | ValueType,
+ ...arguments: ArgumentsType
+ ): Promise<ValueType>;
+
+ // TODO: remove this in the next major version, refactor the whole definition to:
+ // declare function pTry<ValueType, ArgumentsType extends unknown[]>(
+ // fn: (...arguments: ArgumentsType) => PromiseLike<ValueType> | ValueType,
+ // ...arguments: ArgumentsType
+ // ): Promise<ValueType>;
+ // export = pTry;
+ default: typeof pTry;
+};
+
+export = pTry;
diff --git a/node_modules/p-try/index.js b/node_modules/p-try/index.js
index efa2f7433..db858da29 100644
--- a/node_modules/p-try/index.js
+++ b/node_modules/p-try/index.js
@@ -1,4 +1,9 @@
'use strict';
-module.exports = cb => new Promise(resolve => {
- resolve(cb());
+
+const pTry = (fn, ...arguments_) => new Promise(resolve => {
+ resolve(fn(...arguments_));
});
+
+module.exports = pTry;
+// TODO: remove this in the next major version
+module.exports.default = pTry;
diff --git a/node_modules/p-try/license b/node_modules/p-try/license
index 654d0bfe9..e7af2f771 100644
--- a/node_modules/p-try/license
+++ b/node_modules/p-try/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/p-try/package.json b/node_modules/p-try/package.json
index e394d884d..0cd1ba8a5 100644
--- a/node_modules/p-try/package.json
+++ b/node_modules/p-try/package.json
@@ -1,27 +1,27 @@
{
- "_from": "p-try@^1.0.0",
- "_id": "p-try@1.0.0",
+ "_from": "p-try@^2.0.0",
+ "_id": "p-try@2.2.0",
"_inBundle": false,
- "_integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=",
+ "_integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==",
"_location": "/p-try",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
- "raw": "p-try@^1.0.0",
+ "raw": "p-try@^2.0.0",
"name": "p-try",
"escapedName": "p-try",
- "rawSpec": "^1.0.0",
+ "rawSpec": "^2.0.0",
"saveSpec": null,
- "fetchSpec": "^1.0.0"
+ "fetchSpec": "^2.0.0"
},
"_requiredBy": [
"/p-limit"
],
- "_resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz",
- "_shasum": "cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3",
- "_spec": "p-try@^1.0.0",
- "_where": "/Users/rebecca/code/npm/node_modules/p-limit",
+ "_resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
+ "_shasum": "cb2868540e313d61de58fafbe35ce9004d5540e6",
+ "_spec": "p-try@^2.0.0",
+ "_where": "/Users/isaacs/dev/npm/cli/node_modules/p-limit",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
@@ -32,16 +32,18 @@
},
"bundleDependencies": false,
"deprecated": false,
- "description": "`Promise#try()` ponyfill - Starts a promise chain",
+ "description": "`Start a promise chain",
"devDependencies": {
- "ava": "*",
- "xo": "*"
+ "ava": "^1.4.1",
+ "tsd": "^0.7.1",
+ "xo": "^0.24.0"
},
"engines": {
- "node": ">=4"
+ "node": ">=6"
},
"files": [
- "index.js"
+ "index.js",
+ "index.d.ts"
],
"homepage": "https://github.com/sindresorhus/p-try#readme",
"keywords": [
@@ -66,10 +68,7 @@
"url": "git+https://github.com/sindresorhus/p-try.git"
},
"scripts": {
- "test": "xo && ava"
+ "test": "xo && ava && tsd"
},
- "version": "1.0.0",
- "xo": {
- "esnext": true
- }
+ "version": "2.2.0"
}
diff --git a/node_modules/p-try/readme.md b/node_modules/p-try/readme.md
index 8e5fdddbe..4d7bd64df 100644
--- a/node_modules/p-try/readme.md
+++ b/node_modules/p-try/readme.md
@@ -1,6 +1,6 @@
# p-try [![Build Status](https://travis-ci.org/sindresorhus/p-try.svg?branch=master)](https://travis-ci.org/sindresorhus/p-try)
-> [`Promise#try()`](https://github.com/ljharb/proposal-promise-try) [ponyfill](https://ponyfill.com) - Starts a promise chain
+> Start a promise chain
[How is it useful?](http://cryto.net/~joepie91/blog/2016/05/11/what-is-promise-try-and-why-does-it-matter/)
@@ -8,7 +8,7 @@
## Install
```
-$ npm install --save p-try
+$ npm install p-try
```
@@ -17,16 +17,36 @@ $ npm install --save p-try
```js
const pTry = require('p-try');
-pTry(() => {
- return synchronousFunctionThatMightThrow();
-}).then(value => {
- console.log(value);
-}).catch(error => {
- console.error(error);
-});
+(async () => {
+ try {
+ const value = await pTry(() => {
+ return synchronousFunctionThatMightThrow();
+ });
+ console.log(value);
+ } catch (error) {
+ console.error(error);
+ }
+})();
```
+## API
+
+### pTry(fn, ...arguments)
+
+Returns a `Promise` resolved with the value of calling `fn(...arguments)`. If the function throws an error, the returned `Promise` will be rejected with that error.
+
+Support for passing arguments on to the `fn` is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a *lot* of functions.
+
+#### fn
+
+The function to run to start the promise chain.
+
+#### arguments
+
+Arguments to pass to `fn`.
+
+
## Related
- [p-finally](https://github.com/sindresorhus/p-finally) - `Promise#finally()` ponyfill - Invoked when the promise is settled regardless of outcome