UNPKG

pretty-print-error

Version:

Formats errors as nice strings with colors

1 lines 2.49 kB
(function(e){function t(){var e={"src/index.ts":function(e,t,n,r,o,i){"use strict";function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}Object.defineProperty(e,"__esModule",{value:!0}),e.formatError=l;var c=!1;try{c=null!=process.argv0}catch(e){}var u={red:function(e){return e},gray:function(e){return e},magenta:function(e){return e}},s=u;if(c)try{s=eval("require")("kleur")}catch(e){}var f={};if(c)try{f=eval("require")("util")}catch(e){}function l(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.color,r=void 0===n||n,o=t.lineFilter,i=void 0===o?function(e){return!/\(node:/.test(e)}:o,c=r?s:u,p=String(e);if("object"===a(e)&&null!=e&&"string"==typeof e.name&&"string"==typeof e.message&&"string"==typeof e.stack){var d=e;p=c.red(d.name)+": "+d.message.replace(new RegExp("^".concat(d.name,"[: ]*")),"")+"\n"+(d.stack||"").split("\n").map((function(e){return e.trim()})).filter(i).map((function(e){return e.startsWith(d.name+": "+d.message)?null:e.startsWith("at")?" "+c.gray(e):e})).filter(Boolean).join("\n")}if("object"===a(e)&&null!=e){var y=Object.getOwnPropertyNames(e).filter((function(e){return"stack"!==e&&"message"!==e}));if(y.length>0){var m,h={};if(y.forEach((function(t){h[t]=e[t]})),"function"==typeof f.inspect)m=f.inspect(h,{depth:1/0,colors:r});else try{m=JSON.stringify(h)}catch(e){m=["{"," the properties object couldn't be converted to JSON :(",""," the error that happened while stringifying it was:",l(e).split("\n").map((function(e){return" "+e})).join("\n"),"}"].join("\n")}p+=c.magenta("\nThe above error also had these properties on it:\n")+m}}return p}}},t={basedir:"string"==typeof __dirname?__dirname:"",cache:{},runModule:function(e,n){var r={},o={id:e,exports:r};t.cache[e]=o;var i=function(e){return t.cache[e]||t.runModule(e,!1),t.cache[e].exports};i.cache=t.cache,n&&(i.main=o);var a=t.basedir+"/"+e,c=t.basedir+"/"+e.split("/").slice(0,-1).join("/");return t.modules[e](r,i,o,a,c),o.exports},modules:e};return t.runModule("src/index.ts",!0)}"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):e.PrettyPrintError=t()})("undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"object"==typeof this?this:new Function("return this")());