Socket
Socket
Sign inDemoInstall

p-try

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.1.0

index.d.ts

7

index.js
'use strict';
module.exports = (callback, ...args) => new Promise(resolve => {
resolve(callback(...args));
const pTry = (fn, ...arguments_) => new Promise(resolve => {
resolve(fn(...arguments_));
});
module.exports = pTry;
module.exports.default = pTry;
{
"name": "p-try",
"version": "2.0.0",
"version": "2.1.0",
"description": "`Start a promise chain",

@@ -16,6 +16,7 @@ "license": "MIT",

"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd-check"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],

@@ -38,5 +39,6 @@ "keywords": [

"devDependencies": {
"ava": "*",
"xo": "*"
"ava": "^1.3.1",
"tsd-check": "^0.5.0",
"xo": "^0.24.0"
}
}

@@ -20,9 +20,12 @@ # p-try [![Build Status](https://travis-ci.org/sindresorhus/p-try.svg?branch=master)](https://travis-ci.org/sindresorhus/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);
}
})();
```

@@ -33,9 +36,17 @@

### pTry(fn, ...args)
### pTry(fn, ...arguments)
Returns a `Promise` resolved with the value of calling `fn(...args)`. If the function throws an error, the returned `Promise` will be rejected with that error.
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

@@ -42,0 +53,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc