{"_id":"p-reflect","_rev":"3290635","name":"p-reflect","description":"Make a promise always fulfill with its actual fulfillment value or rejection reason","dist-tags":{"latest":"3.1.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2024-05-23T06:49:58.000Z","created":"2016-11-26T05:25:26.154Z","3.1.0":"2022-07-25T16:51:33.393Z","3.0.0":"2021-04-08T18:25:17.026Z","2.1.0":"2019-04-03T05:24:06.813Z","2.0.0":"2019-03-18T16:51:45.331Z","1.0.0":"2016-11-26T05:25:26.154Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reflect.git"},"versions":{"3.1.0":{"name":"p-reflect","version":"3.1.0","description":"Make a promise always fulfill with its actual fulfillment value or rejection reason","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reflect.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":">=12"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","reflect","inspect","debug","fulfill","reject","fulfilled","rejected","error","async","await","promises","bluebird"],"devDependencies":{"ava":"^3.15.0","tsd":"^0.14.0","xo":"^0.38.2"},"types":"./index.d.ts","gitHead":"504690bc03ebf9996f85433e8d08957ced880ab9","bugs":{"url":"https://github.com/sindresorhus/p-reflect/issues"},"homepage":"https://github.com/sindresorhus/p-reflect#readme","_id":"p-reflect@3.1.0","_nodeVersion":"14.19.3","_npmVersion":"8.3.2","dist":{"shasum":"bba22747439b5fc50a7f626e8e909dc9b888218d","size":2631,"noattachment":false,"key":"/p-reflect/-/p-reflect-3.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/p-reflect/download/p-reflect-3.1.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-reflect_3.1.0_1658767893165_0.5925878106167497"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-07-25T16:54:23.707Z","publish_time":1658767893393,"_cnpm_publish_time":1658767893393},"3.0.0":{"name":"p-reflect","version":"3.0.0","description":"Make a promise always fulfill with its actual fulfillment value or rejection reason","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reflect.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":">=12"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","reflect","inspect","debug","fulfill","reject","fulfilled","rejected","error","async","await","promises","bluebird"],"devDependencies":{"ava":"^3.15.0","tsd":"^0.14.0","xo":"^0.38.2"},"gitHead":"180058ffbe18d2df8475ccb454db0ddbcad31771","bugs":{"url":"https://github.com/sindresorhus/p-reflect/issues"},"homepage":"https://github.com/sindresorhus/p-reflect#readme","_id":"p-reflect@3.0.0","_nodeVersion":"15.12.0","_npmVersion":"6.14.10","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"2473a6f9ee0376a27723b18efd24911db8e92573","size":2199,"noattachment":false,"key":"/p-reflect/-/p-reflect-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/p-reflect/download/p-reflect-3.0.0.tgz"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-reflect_3.0.0_1617906316916_0.42553299052979554"},"_hasShrinkwrap":false,"publish_time":1617906317026,"_cnpm_publish_time":1617906317026},"2.1.0":{"name":"p-reflect","version":"2.1.0","description":"Make a promise always fulfill with its actual fulfillment value or rejection reason","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reflect.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","reflect","inspect","debug","fulfill","reject","fulfilled","rejected","error","async","await","promises","bluebird"],"devDependencies":{"ava":"^1.4.1","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"d0141ac1dd4319cd6eda7f88b6fa73384dded212","bugs":{"url":"https://github.com/sindresorhus/p-reflect/issues"},"homepage":"https://github.com/sindresorhus/p-reflect#readme","_id":"p-reflect@2.1.0","_nodeVersion":"8.15.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"5d67c7b3c577c4e780b9451fc9129675bd99fe67","size":2479,"noattachment":false,"key":"/p-reflect/-/p-reflect-2.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/p-reflect/download/p-reflect-2.1.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-reflect_2.1.0_1554269046665_0.8621619656430015"},"_hasShrinkwrap":false,"publish_time":1554269046813,"_cnpm_publish_time":1554269046813},"2.0.0":{"name":"p-reflect","version":"2.0.0","description":"Make a promise always fulfill with its actual fulfillment value or rejection reason","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reflect.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd-check"},"keywords":["promise","reflect","inspect","debug","fulfill","reject","fulfilled","rejected","error","async","await","promises","bluebird"],"devDependencies":{"ava":"^1.3.1","tsd-check":"^0.5.0","xo":"^0.24.0"},"gitHead":"e78fbc51dd0cdc571ccaa603d65f60a2b179658f","bugs":{"url":"https://github.com/sindresorhus/p-reflect/issues"},"homepage":"https://github.com/sindresorhus/p-reflect#readme","_id":"p-reflect@2.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.1","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"71768ac35af2cb055aeb1edf14bd4d6c4c450674","size":2283,"noattachment":false,"key":"/p-reflect/-/p-reflect-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/p-reflect/download/p-reflect-2.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-reflect_2.0.0_1552927905217_0.18195580185057691"},"_hasShrinkwrap":false,"publish_time":1552927905331,"_cnpm_publish_time":1552927905331},"1.0.0":{"name":"p-reflect","version":"1.0.0","description":"Make a promise always fulfill with its actual fulfillment value or rejection reason","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reflect.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["promise","reflect","inspect","debug","fulfill","reject","fulfilled","rejected","error","async","await","promises","bluebird"],"devDependencies":{"ava":"*","xo":"*"},"xo":{"esnext":true},"gitHead":"3a34b40964d98e33afdd6656bcf5addcf4219a96","bugs":{"url":"https://github.com/sindresorhus/p-reflect/issues"},"homepage":"https://github.com/sindresorhus/p-reflect#readme","_id":"p-reflect@1.0.0","_shasum":"f4fa1ee1bb546d8eb3ec0321148dfe0a79137bb8","_from":".","_npmVersion":"2.15.11","_nodeVersion":"4.6.2","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"f4fa1ee1bb546d8eb3ec0321148dfe0a79137bb8","size":2021,"noattachment":false,"key":"/p-reflect/-/p-reflect-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/p-reflect/download/p-reflect-1.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/p-reflect-1.0.0.tgz_1480137925930_0.7492805134970695"},"directories":{},"publish_time":1480137926154,"_cnpm_publish_time":1480137926154,"_hasShrinkwrap":false}},"readme":"# p-reflect\n\n> Make a promise always fulfill with its actual fulfillment value or rejection reason\n\nUseful when you want a promise to fulfill no matter what and would rather handle the actual state afterwards.\n\n## Install\n\n```\n$ npm install p-reflect\n```\n\n## Usage\n\nHere, `Promise.all` would normally fail early because one of the promises rejects, but by using `p-reflect`, we can ignore the rejection and handle it later on.\n\n```js\nimport pReflect from 'p-reflect';\n\nconst promises = [\n\tgetPromise(),\n\tgetPromiseThatRejects(),\n\tgetPromise()\n];\n\nconst results = await Promise.all(promises.map(pReflect));\n\nconsole.log(results);\n/*\n[\n\t{\n\t\tstatus: 'fulfilled',\n\t\tvalue: '????'\n\t\tisFulfilled: true,\n\t\tisRejected: false\n\t},\n\t{\n\t\tstatus: 'rejected',\n\t\treason: [Error: ????]\n\t\tisFulfilled: false,\n\t\tisRejected: true\n\t},\n\t{\n\t\tstatus: 'fulfilled',\n\t\tvalue: '????'\n\t\tisFulfilled: true,\n\t\tisRejected: false\n\t}\n]\n*/\n\nconst resolvedString = results\n\t.filter(result => result.isFulfilled)\n\t.map(result => result.value)\n\t.join('');\n\nconsole.log(resolvedString);\n//=> '????????'\n```\n\nThe above is just an example. Use [`p-settle`](https://github.com/sindresorhus/p-settle) if you need exactly that.\n\n## API\n\n### pReflect(promise)\n\nReturns a `Promise<Object>`.\n\nThe object has the following properties:\n\n- `status` *(`'fulfilled'` or `'rejected'`, depending on how the promise resolved)*\n- `value` or `reason` *(Depending on whether the promise fulfilled or rejected)*\n- `isFulfilled`\n- `isRejected`\n\n#### promise\n\nType: `Promise`\n\nA promise to reflect upon.\n\n### isFulfilled(object)\n\nThis is a type guard for TypeScript users.\n\nReturns `true` if the object has the property `value`, `false` otherwise.\n\nThis is useful since `await pReflect(promise)` always returns a `PromiseResult`. This function can be used to determine whether `PromiseResult` is `PromiseFulfilledResult` or `PromiseRejectedResult`.\n\nThis is a workaround for [microsoft/TypeScript#32399](https://github.com/microsoft/TypeScript/issues/32399)\n- reference documentation [Using type predicates](https://www.typescriptlang.org/docs/handbook/2/narrowing.html)\n\n### isRejected(object)\n\nThis is a type guard for TypeScript users.\n\nReturns `true` if the object has the property `reason`, `false` otherwise.\n\nThis is useful since `await pReflect(promise)` always returns a `PromiseResult`. This function can be used to determine whether `PromiseResult` is `PromiseRejectedResult` or `PromiseFulfilledResult`.\n\n## Related\n\n- [p-settle](https://github.com/sindresorhus/p-settle) - Settle promises concurrently and get their fulfillment value or rejection reason\n- [More…](https://github.com/sindresorhus/promise-fun)\n","_attachments":{},"homepage":"https://github.com/sindresorhus/p-reflect#readme","bugs":{"url":"https://github.com/sindresorhus/p-reflect/issues"},"license":"MIT"}