{"_id":"@atom8/await-to-js","name":"@atom8/await-to-js","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@atom8/await-to-js","version":"0.0.1","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/AtoMeight/await-to-js#readme","author":{"name":"zhiyingzhou"},"repository":{"type":"git","url":"git+https://github.com/AtoMeight/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 --entryPointStrategy src/await-to-js.ts --out dist/docs --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":"^29.5.7","@types/node":"^20.8.10","axios":"^1.6.0","colors":"^1.4.0","commitizen":"^4.3.0","coveralls":"^3.1.1","cross-env":"^7.0.3","cz-conventional-changelog":"^3.3.0","husky":"^8.0.3","jest":"^29.7.0","lint-staged":"^15.0.2","lodash.camelcase":"^4.3.0","prompt":"^1.3.0","replace-in-file":"^7.0.2","rimraf":"^5.0.5","rollup":"^2.79.1","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-node-resolve":"^5.2.0","rollup-plugin-sourcemaps":"^0.6.3","semantic-release":"^22.0.7","ts-jest":"^29.1.1","ts-node":"^10.9.1","tslint":"^5.20.1","tslint-config-standard":"^9.0.0","typedoc":"^0.25.3","typescript":"^5.2.2","validate-commit-msg":"^2.14.0"},"_id":"@atom8/await-to-js@0.0.1","gitHead":"43f457b89f2b1cb4c0e578d900dd4813c9ec8a14","bugs":{"url":"https://github.com/AtoMeight/await-to-js/issues"},"_nodeVersion":"22.9.0","_npmVersion":"10.8.3","dist":{"integrity":"sha512-iIMvNlr4PKCijCmhgUUbPQ/fblnvBYh/nk5hOlz18sAPq7+X7xPNYpcPfuQjhoIOP8vcWeO9M/1WpdM866YgwQ==","shasum":"4da1160b666760459a994b7fe4a618defc844c9e","tarball":"https://registry.npmjs.org/@atom8/await-to-js/-/await-to-js-0.0.1.tgz","fileCount":6,"unpackedSize":8898,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD2jlzqwGSp3hVSiBeKXgtG0zY63fqOTAvw/pAw/qXJ6QIgaNRJWpkm4fZ7XnS/oCvtNYaK1FBt3kZPSs/B5MjvaBM="}]},"_npmUser":{"name":"zhiyingzzhou","email":"zhiyingzzhou@gmail.com"},"directories":{},"maintainers":[{"name":"zhiyingzzhou","email":"zhiyingzzhou@gmail.com"},{"name":"zhiyingzhou-atom","email":"Zhiying.zhou@atom8-tech.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/await-to-js_0.0.1_1729491861436_0.488529067059045"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-21T06:24:21.317Z","0.0.1":"2024-10-21T06:24:21.600Z","modified":"2024-10-21T06:24:21.885Z"},"maintainers":[{"name":"zhiyingzzhou","email":"zhiyingzzhou@gmail.com"},{"name":"zhiyingzhou-atom","email":"Zhiying.zhou@atom8-tech.com"}],"description":"Async/await wrapper for easy error handling in js","homepage":"https://github.com/AtoMeight/await-to-js#readme","keywords":["node","async","await","async await"],"repository":{"type":"git","url":"git+https://github.com/AtoMeight/await-to-js.git"},"author":{"name":"zhiyingzhou"},"bugs":{"url":"https://github.com/AtoMeight/await-to-js/issues"},"license":"MIT","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\n<div align=\"center\">\n\tSupported by:\n  </div><div align=\"center\">\n\t\t<a href=\"https://github.com/novuhq/novu\">\n\t\t\t<img src=\"https://user-images.githubusercontent.com/8872447/165779274-22a190da-3284-487e-bd1e-14983df12cbb.png\" width=\"200\">\n\t\t</a>\n    </div>\n    <div align=\"center\">  <sup>The open-source notification infrastructure</sup>\n</div>\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 @atom/await-to-js --save\n```\n\n## Usage\n\n```js\nimport to from '@atom/await-to-js';\n// If you use CommonJS (i.e NodeJS environment), it should be:\n// const to = require('@atom/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\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","readmeFilename":"README.md"}