UNPKG

gle

Version:

Global Log Engine: Environment-agnostic debugging & logging utility

1 lines 6.04 kB
var e={455:e=>{e.exports=e=>{if("number"!=typeof e)throw new TypeError("Expected a number");const t=e>0?Math.floor:Math.ceil;return{days:t(e/864e5),hours:t(e/36e5)%24,minutes:t(e/6e4)%60,seconds:t(e/1e3)%60,milliseconds:t(e)%1e3,microseconds:t(1e3*e)%1e3,nanoseconds:t(1e6*e)%1e3}}},258:(e,t,o)=>{const n=o(455);e.exports=(e,t={})=>{if(!Number.isFinite(e))throw new TypeError("Expected a finite number");t.colonNotation&&(t.compact=!1,t.formatSubMilliseconds=!1,t.separateMilliseconds=!1,t.verbose=!1),t.compact&&(t.secondsDecimalDigits=0,t.millisecondsDecimalDigits=0);const o=[],i=(e,n,i,r)=>{if(!(0!==o.length&&t.colonNotation||0!==e||t.colonNotation&&"m"===i))return;let s,c;if(r=(r||e||"0").toString(),t.colonNotation){s=o.length>0?":":"",c="";const e=r.includes(".")?r.split(".")[0].length:r.length,t=o.length>0?2:1;r="0".repeat(Math.max(0,t-e))+r}else s="",c=t.verbose?" "+(a=n,1===e?a:`${a}s`):i;var a;o.push(s+r+c)},r=n(e);if(i(Math.trunc(r.days/365),"year","y"),i(r.days%365,"day","d"),i(r.hours,"hour","h"),i(r.minutes,"minute","m"),t.separateMilliseconds||t.formatSubMilliseconds||!t.colonNotation&&e<1e3)if(i(r.seconds,"second","s"),t.formatSubMilliseconds)i(r.milliseconds,"millisecond","ms"),i(r.microseconds,"microsecond","µs"),i(r.nanoseconds,"nanosecond","ns");else{const e=r.milliseconds+r.microseconds/1e3+r.nanoseconds/1e6,o="number"==typeof t.millisecondsDecimalDigits?t.millisecondsDecimalDigits:0,n=e>=1?Math.round(e):Math.ceil(e),s=o?e.toFixed(o):n;i(Number.parseFloat(s,10),"millisecond","ms",s)}else{const o=((e,t)=>{const o=Math.floor(e*10**t+1e-7);return(Math.round(o)/10**t).toFixed(t)})(e/1e3%60,"number"==typeof t.secondsDecimalDigits?t.secondsDecimalDigits:1),n=t.keepDecimalsOnWholeSeconds?o:o.replace(/\.0+$/,"");i(Number.parseFloat(n,10),"second","s",n)}if(0===o.length)return"0"+(t.verbose?" milliseconds":"ms");if(t.compact)return o[0];if("number"==typeof t.unitCount){const e=t.colonNotation?"":" ";return o.slice(0,Math.max(t.unitCount,1)).join(e)}return t.colonNotation?o.join(""):o.join(" ")}},196:e=>{var t=/(\*|\?)/g;function o(e,t){this.text=e=e||"",this.hasWild=e.indexOf("*")>=0,this.separator=t,this.parts=e.split(t).map(this.classifyPart.bind(this))}o.prototype.match=function(e){var t,o,n=!0,i=this.parts,r=i.length;if("string"==typeof e||e instanceof String)if(this.hasWild||this.text==e){for(o=(e||"").split(this.separator),t=0;n&&t<r;t++)"*"!==i[t]&&(n=t<o.length&&(i[t]instanceof RegExp?i[t].test(o[t]):i[t]===o[t]));n=n&&o}else n=!1;else if("function"==typeof e.splice)for(n=[],t=e.length;t--;)this.match(e[t])&&(n[n.length]=e[t]);else if("object"==typeof e)for(var s in n={},e)this.match(s)&&(n[s]=e[s]);return n},o.prototype.classifyPart=function(e){return"*"===e?e:e.indexOf("*")>=0||e.indexOf("?")>=0?new RegExp(e.replace(t,".$1")):e},e.exports=function(e,t,n){var i=new o(e,n||/[\/\.]/);return void 0!==t?i.match(t):i}},246:()=>{}},t={};function o(n){var i=t[n];if(void 0!==i)return i.exports;var r=t[n]={exports:{}};return e[n](r,r.exports,o),r.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var n={};(()=>{o.d(n,{xN:()=>M,Iq:()=>m,cM:()=>w,bp:()=>g,Y9:()=>$});var e=o(196),t=o.n(e),i=o(258),r=o.n(i);const s=["#a0937d","#a7c5eb","#bdd2b6","#cc7351","#d35d6e","#e08f62","#fbc6a4","#f4a9a8","#ce97b0","#5aa469","#70af85","#8b5e83","#8f4068","#9dad7f","#94d0cc","#949cdf"];let c=null;function a(){c||(c=[...s],function(e){for(let t=e.length-1;t>0;t-=1){const o=Math.floor(Math.random()*(t+1));[e[t],e[o]]=[e[o],e[t]]}}(c));const e=c.shift();return c.push(e),e}var l=o(246),u=o.n(l);function d(){if("undefined"!=typeof window)return window;if(void 0!==o.g)return o.g;if("undefined"!=typeof self)return self;throw new Error("Unable to determine global context")}function f(e,t){return e.map((e=>Array.isArray(e)?`[${f(e,", ")}]`:e&&"object"==typeof e&&"function"==typeof e.toString||"function"==typeof e?e.toString():`${e}`)).join(t)}function p(...e){console.log(...e)}let h=p;function m(){return h}function g(e){h=e||p}let b=null,v={};const y={},x={};function M(e){if(!E(e))return(...e)=>{};const t=y[e]=y[e]||a();return function(...o){D(e,o,t)}}function w(e,...t){E(e)&&D(e,t,y[e]=y[e]||a())}function D(e,t,o){const n=x[e]?x[e]:Date.now(),i=x[e]=Date.now(),s=Math.max(0,i-n),c=function(e,t,o,n){var i,r,s;const c=d();if(!0===(null===(r=null===(i=c.process)||void 0===i?void 0:i.stdout)||void 0===r?void 0:r.isTTY)){const i=u().color.ansi16m(...u().hexToRgb(n));return[`${i}${e}${u().color.close}`,t,`${i}${o}${u().color.close}`]}return(null===(s=c.navigator)||void 0===s?void 0:s.userAgent)?[`%c${e} %c${t} %c${o}`,`color:${n}`,"",`color:${n}`]:[e,t,o]}(e,f(t," "),`+${r()(s,{compact:!0})}`,o);m()(...c)}function E(e){if(b||(b=function(){var e,t,o;const n=d(),i=new Set;return function(e){let t;try{t=e.localStorage;const o="__storage_test__";return t.setItem(o,o),t.removeItem(o),!0}catch(e){return"undefined"!=typeof DOMException&&e instanceof DOMException&&(22===e.code||1014===e.code||"QuotaExceededError"===e.name||"NS_ERROR_DOM_QUOTA_REACHED"===e.name)&&t&&0!==t.length}}(n)&&"string"==typeof(null===(e=n.localStorage)||void 0===e?void 0:e.debug)&&n.localStorage.debug.split(",").forEach((e=>i.add(e))),"string"==typeof(null===(o=null===(t=n.process)||void 0===t?void 0:t.env)||void 0===o?void 0:o.DEBUG)&&n.process.env.DEBUG.split(",").forEach((e=>i.add(e))),[...i]}().reduce(((e,t)=>{let o=t.trim(),n=!0;return/^-/.test(o)&&(o=o.substring(1),n=!1),!1!==e[o]&&(e[o]=n),e}),{})),void 0===v[e])for(const o in b)if(t()(o,e)&&(v[e]=!!b[o],!v[e]))break;return v[e]}function $(e,t){v[e]=t}})();var i=n.xN,r=n.Iq,s=n.cM,c=n.bp,a=n.Y9;export{i as createLog,r as getLogRenderer,s as log,c as setLogRenderer,a as toggleContext};