{"name":"await-to-js","version":"2.1.0","description":"Async/await wrapper for easy error handling in js","keywords":["node","async","await","async await"],"main":"dist/await-to-js.umd.js","module":"dist/await-to-js.es5.js","typings":"dist/types/await-to-js.d.ts","homepage":"https://github.com/scopsy/await-to-js#readme","author":{"name":"Dima Grossman","email":"dima@grossman.io"},"repository":{"type":"git","url":"git+https://github.com/scopsy/await-to-js.git"},"license":"MIT","engines":{"node":">=6.0.0"},"scripts":{"lint":"tslint -t codeFrame 'src/**/*.ts' 'test/**/*.ts'","prebuild":"rimraf dist","build":"tsc && rollup -c && rimraf compiled && typedoc --out dist/docs --target es6 --theme minimal src","start":"tsc -w & rollup -c -w","test":"jest","test:watch":"jest --watch","test:prod":"npm run lint && npm run test -- --coverage --no-cache","deploy-docs":"ts-node tools/gh-pages-publish","report-coverage":"cat ./coverage/lcov.info | coveralls","commit":"git-cz","semantic-release":"semantic-release pre && npm publish && semantic-release post","semantic-release-prepare":"ts-node tools/semantic-release-prepare","precommit":"lint-staged"},"lint-staged":{"{src,test}/**/*.ts":["git add"]},"config":{"commitizen":{"path":"node_modules/cz-conventional-changelog"},"validate-commit-msg":{"types":"conventional-commit-types","helpMessage":"Use \"npm run commit\" instead, we use conventional-changelog format :) (https://github.com/commitizen/cz-cli)"}},"jest":{"transform":{".(ts|tsx)":"<rootDir>/node_modules/ts-jest/preprocessor.js"},"testRegex":"(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$","moduleFileExtensions":["ts","tsx","js"],"coveragePathIgnorePatterns":["/node_modules/","/test/"],"coverageThreshold":{"global":{"branches":90,"functions":95,"lines":95,"statements":95}}},"devDependencies":{"@types/jest":"^21.1.0","@types/node":"^8.0.0","colors":"^1.1.2","commitizen":"^2.9.6","coveralls":"^2.13.1","cross-env":"^5.0.1","cz-conventional-changelog":"^2.0.0","husky":"^0.14.0","jest":"^21.0.0","lint-staged":"^4.0.0","lodash.camelcase":"^4.3.0","prompt":"^1.0.0","replace-in-file":"^3.0.0-beta.2","rimraf":"^2.6.1","rollup":"^0.50.0","rollup-plugin-commonjs":"^8.0.2","rollup-plugin-node-resolve":"^3.0.0","rollup-plugin-sourcemaps":"^0.4.2","semantic-release":"^8.0.0","ts-jest":"^21.0.0","ts-node":"^3.0.6","tslint":"^5.4.3","tslint-config-standard":"^6.0.0","typedoc":"^0.8.0","typescript":"^2.3.4","validate-commit-msg":"^2.12.2"},"gitHead":"721dfd67cc8aaa9966a8896535be7fb0e07302d2","bugs":{"url":"https://github.com/scopsy/await-to-js/issues"},"_id":"await-to-js@2.1.0","_npmVersion":"6.2.0","_nodeVersion":"10.9.0","_npmUser":{"name":"scopsy","email":"dima@grossman.io"},"dist":{"integrity":"sha512-Bu/KoRTlkYxAlaRX/cqtodBGNH3Yg0hQXX6rpFttXjXJlslpZHQoDokCT+PZstC5q6+4x/YYC/DL+FFFo8InuA==","shasum":"6391fce43f66ecb09895d934b695f7e104b150f4","tarball":"http://registry-npm.ywwl.com/await-to-js/download/await-to-js-2.1.0.tgz","fileCount":19,"unpackedSize":1157670,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb9efICRA9TVsSAnZWagAA8ocQAKCU3kpgPjqYGeoUhLqW\n6M66zbT9Z+OpsnP73wCaPtRvV9Aw2ov/6gbtWEv6CqRbdTzY0ezuGHZ5QQ06\nHCTU5oZwbBzORWN6nEux8v/6XyNcu+JDit1yXL1XgnkGzRaCUUp2Kq/1MsqW\nZJER+h5c2urIhWXFL6Htb1lwxf39EvZGbXyxTYJaSqLzXeeeDkoB6CDrB/8/\n41SQbYK/u3h/6OgWQQlaq3Me4qN3OuN/oImQ88/WYCdYZIEIbthUL29ITFmP\nATaR7fO6vwejM40Qsar7auE3zx86EkwJv8ri0MqOx8zEwQsSyOkf23dfTGyX\nXWIhVRWbz00c4AzRWNtHfuU1MIFp8WiQId7XUq6G1ycITa9NjDduNXhuJsdV\n26mbi74W7N+Fpbf3fjumweobgq28vmRp08Q1hvLtCewkBeQW2SRs5RAijh78\nbHYWWtsrEg0Gt2rXbmO0THgxNoJeqGEmKcmbPSEHXB3cyL2ypjDBJdAQ31Lp\nt+IZKmHKUplG1clieYYHpPLXq9el8A8HcE80JF66Tg5alWhdCGTSdalgJvO/\nv4noQevCIfle8j9NCymkFTUKD+7d5qerh/kVvEPe8pz+S/F75DY71WKGSq6g\nDSk6ShY5kvV/fwrroulxbOt7lIykpv+ngwLFBe1VLtwEYKw4n0chvzw40d3S\nvPca\r\n=hpC4\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCOM3lWvyygVKe8cljMF4eQwMxw1eTOq2qj0G/Osy96pwIgMv+M1tcj1jm/cQpnRc0wmWMyFMvcItc675pevZnAKwY="}],"size":406002,"noattachment":false,"key":"/await-to-js/-/await-to-js-2.1.0.tgz"},"maintainers":[{"name":"scopsy","email":"dima@grossman.io"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/await-to-js_2.1.0_1542842312295_0.4698457199201209"},"_hasShrinkwrap":false,"readme":"# await-to-js\n\n[![NPM version][npm-image]][npm-url]\n[![Downloads][download-badge]][npm-url]\n\n> Async await wrapper for easy error handling\n\n## Pre-requisites\nYou need to use Node 7.6 (or later) or an ES7 transpiler in order to use async/await functionality.\nYou can use babel or typescript for that.\n\n## Install\n\n```sh\nnpm i await-to-js --save\n```\n\n## Usage\n\n```js\nimport to from 'await-to-js';\n// If you use CommonJS (i.e NodeJS environment), it should be:\n// const to = require('await-to-js').default;\n\nasync function asyncTaskWithCb(cb) {\n     let err, user, savedTask, notification;\n\n     [ err, user ] = await to(UserModel.findById(1));\n     if(!user) return cb('No user found');\n\n     [ err, savedTask ] = await to(TaskModel({userId: user.id, name: 'Demo Task'}));\n     if(err) return cb('Error occurred while saving task');\n\n    if(user.notificationsEnabled) {\n       [ err ] = await to(NotificationService.sendNotification(user.id, 'Task Created'));\n       if(err) return cb('Error while sending notification');\n    }\n\n    if(savedTask.assignedUser.id !== user.id) {\n       [ err, notification ] = await to(NotificationService.sendNotification(savedTask.assignedUser.id, 'Task was created for you'));\n       if(err) return cb('Error while sending notification');\n    }\n\n    cb(null, savedTask);\n}\n\nasync function asyncFunctionWithThrow() {\n  const [err, user] = await to(UserModel.findById(1));\n  if (!user) throw new Error('User not found');\n  \n}\n```\n\n## TypeScript usage\n```javascript\ninterface ServerResponse {\n  test: number;\n}\n\nconst p = Promise.resolve({test: 123});\n\nconst [err, data] = await to<ServerResponse>(p);\nconsole.log(data.test);\n```\n\n## License\n\nMIT © [Dima Grossman](http://blog.grossman.io) && Tomer Barnea\n\n[npm-url]: https://npmjs.org/package/await-to-js\n[npm-image]: https://img.shields.io/npm/v/await-to-js.svg?style=flat-square\n\n[travis-url]: https://travis-ci.org/scopsy/await-to-js\n[travis-image]: https://img.shields.io/travis/scopsy/await-to-js.svg?style=flat-square\n\n[coveralls-url]: https://coveralls.io/r/scopsy/await-to-js\n[coveralls-image]: https://img.shields.io/coveralls/scopsy/await-to-js.svg?style=flat-square\n\n[depstat-url]: https://david-dm.org/scopsy/await-to-js\n[depstat-image]: https://david-dm.org/scopsy/await-to-js.svg?style=flat-square\n\n[download-badge]: http://img.shields.io/npm/dm/await-to-js.svg?style=flat-square\n","publish_time":1542842312469,"_cnpm_publish_time":1542842312469,"dist-tags":{"latest":"3.0.0"}}