{"name":"await-to-js","version":"3.0.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":"2a1d39623f7ef40786ae51ebf6f7799ad4d84ff2","bugs":{"url":"https://github.com/scopsy/await-to-js/issues"},"_id":"await-to-js@3.0.0","_nodeVersion":"15.11.0","_npmVersion":"7.6.0","dist":{"integrity":"sha512-zJAaP9zxTcvTHRlejau3ZOY4V7SRpiByf3/dxx2uyKxxor19tpmpV2QRsTKikckwhaPmr2dVpxxMr7jOCYVp5g==","shasum":"70929994185616f4675a91af6167eb61cc92868f","tarball":"http://registry-npm.ywwl.com/await-to-js/download/await-to-js-3.0.0.tgz","fileCount":19,"unpackedSize":1158633,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgR5hWCRA9TVsSAnZWagAACcAP/i5vzMYiH8FHLdMaaIH/\n0Q0c+Ktz2PHCCDgCnl8L/vPDTbFTIoVCXKoq0VpMsizEr3v4se+0pUuSeBQ7\nV5pA/2fIXGNKp5o49K5P7dBTlv/3FdktGa+7P1J/AC7guPdtOyTI5QzlVteo\nHykTl+w+8tovPcWj64gILfs46O3/N7z4Qzgqg8EQu+pLHqAfBlJVfmKuwR6G\n97+OH1emeikpYWSmuJchpDtnHsJnWz0F8jP8cy8U/CNmj2QzlFM0CyuvHLOi\nxo5xKDFGtvLNzfXlu7e5tra//Mak9OuxJB4eEJ9R/Lb0+SyCKbXwD2tBVmgS\ngS8CyICft6SRu0YvYj6OOZ/MsulamApmbjLdCZXAHLH9SGQcB3yefYHJ6TWE\nDitfdZJbyopel59B3jxlkeKBhj2QK/q6+aOZOnJXJOlau0yGOfeV4iPWb5SY\nqniru9VZnlB+Lfr59nGl7bXw84GMI0ZoB1/bo+1tEnbFI1BpgOXOVlUxo3uO\nmpPP9hES54VRU5lZrWb+T2MvmM0lz6swaVTO781ns0rjF0xUSnXo4fahiiAd\no/LBTjg8WUrg+S6CerRlr6B2p8oR3UD0drpQdaQaQMnkXhGpXaYQhwwFFv/8\npONz2XQwdusICFCDap+Pq4pix4TvAvyBexazWaVNZXpBaoz3FLD2nKnauaV5\n665s\r\n=7hui\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBx7pir71V0QhMFetn2K/F+qFb7uuTyM0wf59YQq56kOAiA+/1RQBz3eXgPrsMofGD/tz8HsYqouO45OTMKnWe/6Og=="}],"size":406175,"noattachment":false,"key":"/await-to-js/-/await-to-js-3.0.0.tgz"},"_npmUser":{"name":"scopsy","email":"dima@grossman.io"},"directories":{},"maintainers":[{"name":"scopsy","email":"dima@grossman.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/await-to-js_3.0.0_1615304789630_0.4693241353750588"},"_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":1615304789827,"_cnpm_publish_time":1615304789827,"dist-tags":{"latest":"3.0.0"}}