await-to-js
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
export declare function to<T, U = any>(promise: Promise<T>, errorExt?: object): Promise<[U | null, T | undefined]>; | ||
export declare function to<T, U = Error>(promise: any, errorExt?: object): Promise<[U, T]>; | ||
export default to; |
{ | ||
"name": "await-to-js", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Async/await wrapper for easy error handling in js", | ||
@@ -44,3 +44,2 @@ "keywords": [ | ||
"{src,test}/**/*.ts": [ | ||
"prettier --write --no-semi", | ||
"git add" | ||
@@ -93,3 +92,2 @@ ] | ||
"lodash.camelcase": "^4.3.0", | ||
"prettier": "^1.4.4", | ||
"prompt": "^1.0.0", | ||
@@ -106,3 +104,2 @@ "replace-in-file": "^3.0.0-beta.2", | ||
"tslint": "^5.4.3", | ||
"tslint-config-prettier": "^1.1.0", | ||
"tslint-config-standard": "^6.0.0", | ||
@@ -109,0 +106,0 @@ "typedoc": "^0.8.0", |
@@ -22,5 +22,7 @@ # await-to-js | ||
import to from 'await-to-js'; | ||
// If you use CommonJS (i.e NodeJS environment), it should be: | ||
// const to = require('await-to-js').default; | ||
async function asyncTask(cb) { | ||
let err, user, savedUser, notification; | ||
async function asyncTaskWithCb(cb) { | ||
let err, user, savedTask, notification; | ||
@@ -45,5 +47,11 @@ [ err, user ] = await to(UserModel.findById(1)); | ||
} | ||
async function asyncFunctionWithThrow() { | ||
const [err, user] = await to(UserModel.findById(1)); | ||
if (!user) throw new Error('User not found'); | ||
} | ||
``` | ||
## Type script usage | ||
## TypeScript usage | ||
```javascript | ||
@@ -50,0 +58,0 @@ interface ServerResponse { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
1157670
26
83