UNPKG

apr-intercept

Version:

Intercepts errors, the Go way!

1 lines 1.05 kB
{"version":3,"file":"apr-intercept.modern.mjs","sources":["../index.js"],"sourcesContent":["/**\n * <a id=\"intercept\"></a>\n * Intercepts errors, the Go way!\n *\n * [![](https://img.shields.io/npm/v/apr-intercept.svg?style=flat-square)](https://www.npmjs.com/package/apr-intercept) [![](https://img.shields.io/npm/l/apr-intercept.svg?style=flat-square)](https://www.npmjs.com/package/apr-intercept)\n *\n * @kind function\n * @name intercept\n * @param {Promise} input\n * @returns {Promise}\n *\n * @example\n * import ctch from 'apr-intercept';\n *\n * const [err1, res1] = await ctch(fn(1));\n * const [err2, res2] = await ctch(fn(1));\n * const [, res3] = await ctch(fn(3));\n */\nexport default p => {\n return new Promise(resolve => {\n return p.then(\n (...res) => resolve([null, ...res]),\n err => resolve([err, undefined]),\n );\n });\n};\n"],"names":["p","Promise","resolve","then","res","err","undefined"],"mappings":"eAkBeA,OACFC,QAAQC,GACVF,EAAEG,KACP,sCAAIC,2BAAAA,yBAAQF,EAAQ,CAAC,QAASE,KAC9BC,GAAOH,EAAQ,CAACG,OAAKC"}