{"_id":"wrap-promise","_rev":"323054","name":"wrap-promise","description":"Like new Promise(), but prevents implicit rejection","dist-tags":{"latest":"1.0.1"},"maintainers":[{"name":"shinnn","email":"snnskwtnb@gmail.com"}],"time":{"modified":"2021-06-04T01:34:41.000Z","created":"2014-12-13T09:09:13.667Z","1.0.1":"2015-06-13T07:15:48.260Z","1.0.0":"2014-12-13T09:19:43.583Z","0.0.0":"2014-12-13T09:09:13.667Z"},"users":{"jslite":true},"author":{"name":"Shinnosuke Watanabe","url":"https://github.com/shinnn"},"repository":{"type":"git","url":"git+https://github.com/shinnn/wrap-promise.git"},"versions":{"1.0.1":{"name":"wrap-promise","version":"1.0.1","description":"Like new Promise(), but prevents implicit rejection","repository":{"type":"git","url":"git+https://github.com/shinnn/wrap-promise.git"},"author":{"name":"Shinnosuke Watanabe","url":"https://github.com/shinnn"},"scripts":{"pretest":"eslint --config node_modules/@shinnn/eslintrc/rc.json --ignore-path .gitignore .","test":"node test.js | tap-spec","coverage":"istanbul cover test.js","coveralls":"${npm_package_scripts_coverage} && istanbul-coveralls"},"license":"MIT","main":"wrap-promise-cjs.js","files":["no-fallback.js","wrap-promise-cjs.js"],"keywords":["promise","constructor","then","thenable","throw","error","wrapper","explicit","browser","client-side"],"dependencies":{"es6-promise":"^2.3.0"},"devDependencies":{"@shinnn/eslintrc":"^1.0.0","eslint":"^0.22.1","istanbul":"^0.3.15","istanbul-coveralls":"^1.0.3","require-uncached":"^1.0.2","tap-spec":"^4.0.0","tape":"^4.0.0"},"gitHead":"d36de978d0ccf93f38d38e7c9464b32995265527","bugs":{"url":"https://github.com/shinnn/wrap-promise/issues"},"homepage":"https://github.com/shinnn/wrap-promise#readme","_id":"wrap-promise@1.0.1","_shasum":"b019f4236ccbf1fb560921b4b4870b7bda2f5255","_from":".","_npmVersion":"2.11.2","_nodeVersion":"2.2.1","_npmUser":{"name":"shinnn","email":"snnskwtnb@gmail.com"},"maintainers":[{"name":"shinnn","email":"snnskwtnb@gmail.com"}],"dist":{"shasum":"b019f4236ccbf1fb560921b4b4870b7bda2f5255","size":3117,"noattachment":false,"key":"/wrap-promise/-/wrap-promise-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/wrap-promise/download/wrap-promise-1.0.1.tgz"},"directories":{},"publish_time":1434179748260,"_cnpm_publish_time":1434179748260,"_hasShrinkwrap":false},"1.0.0":{"name":"wrap-promise","version":"1.0.0","description":"Like new Promise(), but prevents implicit rejection","repository":{"type":"git","url":"https://github.com/shinnn/wrap-promise"},"author":{"name":"Shinnosuke Watanabe","url":"https://github.com/shinnn"},"scripts":{"pretest":"jscs *.js && eslint *.js","test":"node test.js | tap-spec","coverage":"istanbul cover test.js","coveralls":"${npm_package_scripts_coverage} && istanbul-coveralls"},"licenses":[{"type":"MIT","url":"https://github.com/shinnn/wrap-promise/blob/master/LICENSE"}],"main":"wrap-promise-cjs.js","files":["LICENSE","no-fallback.js","wrap-promise-cjs.js"],"keywords":["promise","constructor","then","thenable","throw","error","wrapper","explicit","browser","client-side"],"dependencies":{"es6-promise":"^2.0.1"},"devDependencies":{"eslint":"^0.10.2","istanbul":"^0.3.5","istanbul-coveralls":"^1.0.1","jscs":"^1.8.1","require-uncached":"^1.0.2","tap-spec":"^2.1.1","tape":"^3.0.3"},"jscsConfig":{"preset":"google","maximumLineLength":98,"validateLineBreaks":"LF"},"gitHead":"cf1be2ed0eb61d369614db2110b19f357ab6eca1","bugs":{"url":"https://github.com/shinnn/wrap-promise/issues"},"homepage":"https://github.com/shinnn/wrap-promise","_id":"wrap-promise@1.0.0","_shasum":"2fa39b4b4fe6b06c079947f06b79da5cedbb4706","_from":".","_npmVersion":"2.1.11","_nodeVersion":"0.10.33","_npmUser":{"name":"shinnn","email":"snnskwtnb@gmail.com"},"maintainers":[{"name":"shinnn","email":"snnskwtnb@gmail.com"}],"dist":{"shasum":"2fa39b4b4fe6b06c079947f06b79da5cedbb4706","size":3083,"noattachment":false,"key":"/wrap-promise/-/wrap-promise-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/wrap-promise/download/wrap-promise-1.0.0.tgz"},"directories":{},"publish_time":1418462383583,"_cnpm_publish_time":1418462383583,"_hasShrinkwrap":false},"0.0.0":{"name":"wrap-promise","version":"0.0.0","description":"Like new Promise(), but prevents implicit rejection","repository":{"type":"git","url":"https://github.com/shinnn/wrap-promise"},"author":{"name":"Shinnosuke Watanabe","url":"https://github.com/shinnn"},"scripts":{"pretest":"jscs *.js && eslint *.js","test":"node test.js | tap-spec","coverage":"istanbul cover test.js","coveralls":"${npm_package_scripts_coverage} && istanbul-coveralls"},"licenses":[{"type":"MIT","url":"https://github.com/shinnn/wrap-promise/blob/master/LICENSE"}],"main":"wrap-promise-cjs.js","files":["wrap-promise-cjs.js","LICENSE"],"keywords":["promise","constructor","then","thenable","throw","error","wrapper","explicit","browser","client-side"],"dependencies":{"es6-promise":"^2.0.1"},"devDependencies":{"eslint":"^0.10.2","istanbul":"^0.3.5","istanbul-coveralls":"^1.0.1","jscs":"^1.8.1","require-uncached":"^1.0.2","tap-spec":"^2.1.1","tape":"^3.0.3"},"jscsConfig":{"preset":"google","maximumLineLength":98,"validateLineBreaks":"LF"},"gitHead":"0f466a3a3cf404073fe30a81714011b920bfd3fa","bugs":{"url":"https://github.com/shinnn/wrap-promise/issues"},"homepage":"https://github.com/shinnn/wrap-promise","_id":"wrap-promise@0.0.0","_shasum":"ca868f10c620dc13c99cb50594ed8c4e696787c7","_from":".","_npmVersion":"2.1.11","_nodeVersion":"0.10.33","_npmUser":{"name":"shinnn","email":"snnskwtnb@gmail.com"},"maintainers":[{"name":"shinnn","email":"snnskwtnb@gmail.com"}],"dist":{"shasum":"ca868f10c620dc13c99cb50594ed8c4e696787c7","size":2993,"noattachment":false,"key":"/wrap-promise/-/wrap-promise-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/wrap-promise/download/wrap-promise-0.0.0.tgz"},"directories":{},"publish_time":1418461753667,"_cnpm_publish_time":1418461753667,"_hasShrinkwrap":false}},"readme":"# wrap-promise\n\n[![NPM version](https://img.shields.io/npm/v/wrap-promise.svg)](https://www.npmjs.com/package/wrap-promise)\n[![Bower version](https://img.shields.io/bower/v/wrap-promise.svg)](https://github.com/shinnn/wrap-promise/releases)\n[![Build Status](https://travis-ci.org/shinnn/wrap-promise.svg?branch=master)](https://travis-ci.org/shinnn/wrap-promise)\n[![Build status](https://ci.appveyor.com/api/projects/status/hs2fbpxk34gbteub?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/wrap-promise)\n[![Coverage Status](https://img.shields.io/coveralls/shinnn/wrap-promise.svg?label=cov)](https://coveralls.io/r/shinnn/wrap-promise)\n[![Dependency Status](https://img.shields.io/david/shinnn/wrap-promise.svg?label=deps)](https://david-dm.org/shinnn/wrap-promise)\n[![devDependency Status](https://img.shields.io/david/dev/shinnn/wrap-promise.svg?label=devDeps)](https://david-dm.org/shinnn/wrap-promise#info=devDependencies)\n\nLike `new Promise()`, but prevents implicit rejection\n\n## Comparison\n\n### Using the native `new Promise()`\n\n```javascript\nconst fs = require('fs');\n\nnew Promise((resolve, reject) => {\n  // Node's fs.readFile throws a type error when the first argument is not a string.\n\n  fs.readFile(123, (err, buf) => { // doesn't throw, but calls `onRejected` function\n    if (err) {\n      reject(err);\n      return;\n    }\n    resolve(buf);\n  });\n}).catch(() => console.log('This function should be called.'));\n```\n\n### Using *wrap-promise*\n\n```javascript\nconst fs = require('fs');\nconst wrapPromise = require('wrap-promise');\n\nwrapPromise((resolve, reject) => {\n  fs.readFile(123, (err, buf) => { // doesn't call `onRejected` but throws immediately\n    if (err) {\n      reject(err);\n      return;\n    }\n    resolve(buf);\n  });\n}).catch(() => console.log('This function should not be called.'));\n```\n\n[According to the Promise specification](https://github.com/domenic/promises-unwrapping/blob/2a942729249c2490507a1ae6c9a24f8fa11a98e4/reference-implementation/lib/testable-implementation.js#L293-L297), a `promise` will [be rejected implicitly when an error is thrown in the constructor callback](http://www.html5rocks.com/en/tutorials/es6/promises/#toc-exceptions-and-promises). The only (and the biggest) difference is that *wrap-promise* immediately throws an error in such a case.\n\n## Installation\n\n### Package managers\n\n#### [npm](https://www.npmjs.com/)\n\n```\nnpm install wrap-promise\n```\n\n#### [Bower](http://bower.io/)\n\n```\nbower install wrap-promise\n```\n\n#### [Duo](http://duojs.org/)\n\n```javascript\nconst wrapPromise = require('shinnn/wrap-promise');\n```\n\n### Standalone\n\n[Download the script file directly.](https://raw.githubusercontent.com/shinnn/wrap-promise/master/wrap-promise.js)\n\n## API\n\n### wrapPromise(*fn*)\n\n*fn*: `Function`  \nReturn: `Object` ([Promise](https://promisesaplus.com/))\n\nIt can be used in the same way as `new Promise()` but [`new` operator](http://www.ecma-international.org/ecma-262/5.1/#sec-11.2.2) is not needed.\n\n### wrapPromise.Promise\n\nType: `Function`  \nDefault: global `Promise` or [`require('es6-promise').Promise`](https://github.com/jakearchibald/es6-promise#nodejs)\n\nThe `Promise` constructor used in `wrapPromise` function.\n\n#### On [CommonJS](http://www.commonjs.org/)-based environment (e.g. [Node](https://nodejs.org/))\n\nBy default it uses the global `Promise` constructor if available, otherwise it [`require`](http://nodejs.org/api/globals.html#globals_require)s [es6-promise](https://github.com/jakearchibald/es6-promise) and use its [`Promise` property](https://github.com/jakearchibald/es6-promise#nodejs).\n\nIf you don't need the fallback, use [`no-fallback.js`](https://github.com/shinnn/wrap-promise/blob/master/no-fallback.js) instead. (Useful for [Browserify](http://browserify.org/))\n\n```javascript\nconst wrapPromise = require('wrap-promise/no-fallback');\n```\n\n#### On non-CommonJS environment\n\nIt uses the global `Promise` constructor without any fallbacks. Before using `wrapPromise`, you must load `Promise` polyfill if `Promise` doesn't exist by default.\n\n## License\n\nCopyright (c) 2014 - 2015 [Shinnosuke Watanabe](https://github.com/shinnn)\n\nLicensed under [the MIT License](./LICENSE).\n","_attachments":{},"homepage":"https://github.com/shinnn/wrap-promise#readme","bugs":{"url":"https://github.com/shinnn/wrap-promise/issues"},"license":"MIT"}