UNPKG

conway-errors

Version:

A convenient primitive for creating, structing and throwing errors

3 lines (2 loc) 3.36 kB
!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r||self).conwayErrors={})}(this,function(r){function t(){return t=Object.assign?Object.assign.bind():function(r){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var e in n)({}).hasOwnProperty.call(n,e)&&(r[e]=n[e])}return r},t.apply(null,arguments)}function n(r){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(r){return r.__proto__||Object.getPrototypeOf(r)},n(r)}function e(r,t){r.prototype=Object.create(t.prototype),r.prototype.constructor=r,i(r,t)}function o(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(r){}return(o=function(){return!!r})()}function i(r,t){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,t){return r.__proto__=t,r},i(r,t)}function u(r){var t="function"==typeof Map?new Map:void 0;return u=function(r){if(null===r||!function(r){try{return-1!==Function.toString.call(r).indexOf("[native code]")}catch(t){return"function"==typeof r}}(r))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(r))return t.get(r);t.set(r,e)}function e(){return function(r,t,n){if(o())return Reflect.construct.apply(null,arguments);var e=[null];e.push.apply(e,t);var u=new(r.bind.apply(r,e));return n&&i(u,n.prototype),u}(r,arguments,n(this).constructor)}return e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),i(e,r)},u(r)}var a=/*#__PURE__*/function(r){function t(t,n,e,o,i,u,a){var c;return(c=r.call(this,o)||this).rootContext=void 0,c.contextsChunk=void 0,c.originalError=void 0,c.extendedParams=void 0,c.feature="",c.emit=void 0,c.name=t,c.rootContext=n,c.contextsChunk=e,c.originalError=u,c.emit=i,c.extendedParams=a,c}return e(t,r),t}(/*#__PURE__*/u(Error));function c(r,t){/*#__PURE__*/return function(n){function o(e,o,i,u,a){return n.call(this,r,t,e,o,i,u,a)||this}return e(o,n),o}(a)}var f={handleEmit:function(r){console.error(r)},extendedParams:{}};r.createError=function(r,n){var e,o=t({},f,n),i=null!=(e=null==n?void 0:n.extendedParams)?e:{};return function(n,e){void 0===e&&(e={});var u=t({},i,e),a=Array.isArray(r)?r.reduce(function(r,t){var e=t.errorType,o=t.createMessagePostfix;return r[e]={errorClass:c(e,n),createMessagePostfix:o},r},{}):{},f=c("UnknownError",n),l=function(r,n){return function(e,o){void 0===o&&(o={});var i=t({},n,o);return s(r+"/"+e,i)}};function s(r,n){return void 0===n&&(n=u),{__brand:r,subcontext:l(r,n),feature:function(e,i){void 0===i&&(i={});var u=t({},n,i);return function(r,n,e){void 0===e&&(e={});var i=function(i,u,c){var l,s=a[i],d=null!=c&&c.originalError&&null!=s&&s.createMessagePostfix?s.createMessagePostfix(null==c?void 0:c.originalError):"",p=new(null!=(l=null==s?void 0:s.errorClass)?l:f)(n,function(r,t,n){return r+"/"+t+": "+n}(n,r,u+d),function(r){void 0===r&&(r={});var n=t({},e,null==c?void 0:c.extendedParams,r);null==o.handleEmit||o.handleEmit(p,n)},null==c?void 0:c.originalError,null==c?void 0:c.extendedParams);return p.feature=r,p};return Object.assign(i,{__brand:n+"/"+r}),i}(e,r,u)}}}return s(n)}},r.isConwayError=function(r){return"object"==typeof r&&r instanceof a}}); //# sourceMappingURL=index.umd.js.map