@libp2p/logger
Advanced tools
Comparing version 5.0.4 to 5.1.0
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PLogger = factory()}(typeof self !== 'undefined' ? self : this, function () { | ||
"use strict";var Libp2PLogger=(()=>{var L=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var Y=(e,t)=>{for(var r in t)L(e,r,{get:t[r],enumerable:!0})},H=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of _(t))!W.call(e,s)&&s!==r&&L(e,s,{get:()=>t[s],enumerable:!(o=Q(t,s))||o.enumerable});return e};var ee=e=>H(L({},"__esModule",{value:!0}),e);var Ee={};Y(Ee,{defaultLogger:()=>ye,disable:()=>Fe,enable:()=>Ae,enabled:()=>ve,logger:()=>I,peerLogger:()=>xe,prefixLogger:()=>K});var Se=new Uint8Array(0);function R(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function re(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),o=0;o<r.length;o++)r[o]=255;for(var s=0;s<e.length;s++){var p=e.charAt(s),g=p.charCodeAt(0);if(r[g]!==255)throw new TypeError(p+" is ambiguous");r[g]=s}var u=e.length,w=e.charAt(0),S=Math.log(u)/Math.log(256),n=Math.log(256)/Math.log(u);function i(a){if(a instanceof Uint8Array||(ArrayBuffer.isView(a)?a=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):Array.isArray(a)&&(a=Uint8Array.from(a))),!(a instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(a.length===0)return"";for(var c=0,d=0,l=0,C=a.length;l!==C&&a[l]===0;)l++,c++;for(var y=(C-l)*n+1>>>0,h=new Uint8Array(y);l!==C;){for(var v=a[l],F=0,x=y-1;(v!==0||F<d)&&x!==-1;x--,F++)v+=256*h[x]>>>0,h[x]=v%u>>>0,v=v/u>>>0;if(v!==0)throw new Error("Non-zero carry");d=F,l++}for(var A=y-d;A!==y&&h[A]===0;)A++;for(var U=w.repeat(c);A<y;++A)U+=e.charAt(h[A]);return U}function f(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var c=0;if(a[c]!==" "){for(var d=0,l=0;a[c]===w;)d++,c++;for(var C=(a.length-c)*S+1>>>0,y=new Uint8Array(C);a[c];){var h=r[a.charCodeAt(c)];if(h===255)return;for(var v=0,F=C-1;(h!==0||v<l)&&F!==-1;F--,v++)h+=u*y[F]>>>0,y[F]=h%256>>>0,h=h/256>>>0;if(h!==0)throw new Error("Non-zero carry");l=v,c++}if(a[c]!==" "){for(var x=C-l;x!==C&&y[x]===0;)x++;for(var A=new Uint8Array(d+(C-x)),U=d;x!==C;)A[U++]=y[x++];return A}}}function E(a){var c=f(a);if(c)return c;throw new Error(`Non-${t} character`)}return{encode:i,decodeUnsafe:f,decode:E}}var te=re,ne=te,T=ne;var M=class{name;prefix;baseEncode;constructor(t,r,o){this.name=t,this.prefix=r,this.baseEncode=o}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},N=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,o){this.name=t,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=o}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return V(this,t)}},O=class{decoders;constructor(t){this.decoders=t}or(t){return V(this,t)}decode(t){let r=t[0],o=this.decoders[r];if(o!=null)return o.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function V(e,t){return new O({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var P=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,o,s){this.name=t,this.prefix=r,this.baseEncode=o,this.baseDecode=s,this.encoder=new M(t,r,o),this.decoder=new N(t,r,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function B({name:e,prefix:t,encode:r,decode:o}){return new P(e,t,r,o)}function j({name:e,prefix:t,alphabet:r}){let{encode:o,decode:s}=T(r,e);return B({prefix:t,name:e,encode:o,decode:p=>R(s(p))})}function oe(e,t,r,o){let s={};for(let n=0;n<t.length;++n)s[t[n]]=n;let p=e.length;for(;e[p-1]==="=";)--p;let g=new Uint8Array(p*r/8|0),u=0,w=0,S=0;for(let n=0;n<p;++n){let i=s[e[n]];if(i===void 0)throw new SyntaxError(`Non-${o} character`);w=w<<r|i,u+=r,u>=8&&(u-=8,g[S++]=255&w>>u)}if(u>=r||255&w<<8-u)throw new SyntaxError("Unexpected end of data");return g}function se(e,t,r){let o=t[t.length-1]==="=",s=(1<<r)-1,p="",g=0,u=0;for(let w=0;w<e.length;++w)for(u=u<<8|e[w],g+=8;g>r;)g-=r,p+=t[s&u>>g];if(g!==0&&(p+=t[s&u<<r-g]),o)for(;p.length*r&7;)p+="=";return p}function m({name:e,prefix:t,bitsPerChar:r,alphabet:o}){return B({prefix:t,name:e,encode(s){return se(s,o,r)},decode(s){return oe(s,o,r,e)}})}var J=m({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Oe=m({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Pe=m({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),je=m({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),De=m({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ie=m({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Re=m({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Te=m({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ve=m({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var q=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),qe=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var G=m({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ze=m({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ke=m({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Qe=m({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function ie(e,t){try{if(typeof e=="string"&&e.length>0)return ae(e);if(typeof e=="number"&&isFinite(e))return t?.long?fe(e):ce(e);throw new Error("Value is not a string or number.")}catch(r){let o=ue(r)?`${r.message}. value=${JSON.stringify(e)}`:"An unknown error has occured.";throw new Error(o)}}function ae(e){if(e=String(e),e.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return NaN;let r=parseFloat(t[1]),o=(t[2]||"ms").toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return r*315576e5;case"weeks":case"week":case"w":return r*6048e5;case"days":case"day":case"d":return r*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return r*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return r*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return r*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:throw new Error(`The unit ${o} was matched, but no matching case exists.`)}}var k=ie;function ce(e){let t=Math.abs(e);return t>=864e5?`${Math.round(e/864e5)}d`:t>=36e5?`${Math.round(e/36e5)}h`:t>=6e4?`${Math.round(e/6e4)}m`:t>=1e3?`${Math.round(e/1e3)}s`:`${e}ms`}function fe(e){let t=Math.abs(e);return t>=864e5?$(e,t,864e5,"day"):t>=36e5?$(e,t,36e5,"hour"):t>=6e4?$(e,t,6e4,"minute"):t>=1e3?$(e,t,1e3,"second"):`${e} ms`}function $(e,t,r,o){let s=t>=r*1.5;return`${Math.round(e/r)} ${o}${s?"s":""}`}function ue(e){return typeof e=="object"&&e!==null&&"message"in e}function D(e){r.debug=r,r.default=r,r.coerce=w,r.disable=p,r.enable=s,r.enabled=g,r.humanize=k,r.destroy=S,Object.keys(e).forEach(n=>{r[n]=e[n]}),r.names=[],r.skips=[],r.formatters={};function t(n){let i=0;for(let f=0;f<n.length;f++)i=(i<<5)-i+n.charCodeAt(f),i|=0;return r.colors[Math.abs(i)%r.colors.length]}r.selectColor=t;function r(n){let i,f=null,E,a;function c(...d){if(!c.enabled)return;let l=c,C=Number(new Date),y=C-(i||C);l.diff=y,l.prev=i,l.curr=C,i=C,d[0]=r.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let h=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(F,x)=>{if(F==="%%")return"%";h++;let A=r.formatters[x];if(typeof A=="function"){let U=d[h];F=A.call(l,U),d.splice(h,1),h--}return F}),r.formatArgs.call(l,d),(l.log||r.log).apply(l,d)}return c.namespace=n,c.useColors=r.useColors(),c.color=r.selectColor(n),c.extend=o,c.destroy=r.destroy,Object.defineProperty(c,"enabled",{enumerable:!0,configurable:!1,get:()=>f!==null?f:(E!==r.namespaces&&(E=r.namespaces,a=r.enabled(n)),a),set:d=>{f=d}}),typeof r.init=="function"&&r.init(c),c}function o(n,i){let f=r(this.namespace+(typeof i>"u"?":":i)+n);return f.log=this.log,f}function s(n){r.save(n),r.namespaces=n,r.names=[],r.skips=[];let i,f=(typeof n=="string"?n:"").split(/[\s,]+/),E=f.length;for(i=0;i<E;i++)f[i]&&(n=f[i].replace(/\*/g,".*?"),n[0]==="-"?r.skips.push(new RegExp("^"+n.substr(1)+"$")):r.names.push(new RegExp("^"+n+"$")))}function p(){let n=[...r.names.map(u),...r.skips.map(u).map(i=>"-"+i)].join(",");return r.enable(""),n}function g(n){if(n[n.length-1]==="*")return!0;let i,f;for(i=0,f=r.skips.length;i<f;i++)if(r.skips[i].test(n))return!1;for(i=0,f=r.names.length;i<f;i++)if(r.names[i].test(n))return!0;return!1}function u(n){return n.toString().substring(2,n.toString().length-2).replace(/\.\*\?$/,"*")}function w(n){return n instanceof Error?n.stack??n.message:n}function S(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var z=me(),de=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function le(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function pe(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+k(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let r=0,o=0;e[0].replace(/%[a-zA-Z%]/g,s=>{s!=="%%"&&(r++,s==="%c"&&(o=r))}),e.splice(o,0,t)}var he=console.debug??console.log??(()=>{});function be(e){try{e?z?.setItem("debug",e):z?.removeItem("debug")}catch{}}function Ce(){let e;try{e=z?.getItem("debug")}catch{}return!e&&typeof process<"u"&&"env"in process&&(e=process.env.DEBUG),e}function me(){try{return localStorage}catch{}}function ge(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var X=D({formatArgs:pe,save:be,load:Ce,useColors:le,setupFormatters:ge,colors:de,storage:z,log:he});var b=X;function Z(e,t={}){let r=t.prefixLength??2,o=t.suffixLength??4,s=e.toString();return`${s.substring(0,r)}\u2026${s.substring(s.length,s.length-o)}`}b.formatters.b=e=>e==null?"undefined":q.baseEncode(e);b.formatters.t=e=>e==null?"undefined":J.baseEncode(e);b.formatters.m=e=>e==null?"undefined":G.baseEncode(e);b.formatters.p=e=>e==null?"undefined":e.toString();b.formatters.c=e=>e==null?"undefined":e.toString();b.formatters.k=e=>e==null?"undefined":e.toString();b.formatters.a=e=>e==null?"undefined":e.toString();function we(e){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}function xe(e,t={}){return K(Z(e,t))}function K(e){return{forComponent(t){return I(`${e}:${t}`)}}}function ye(){return{forComponent(e){return I(e)}}}function I(e){let t=we(`${e}:trace`);return b.enabled(`${e}:trace`)&&b.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=b(`${e}:trace`)),Object.assign(b(e),{error:b(`${e}:error`),trace:t})}function Fe(){b.disable()}function Ae(e){b.enable(e)}function ve(e){return b.enabled(e)}return ee(Ee);})(); | ||
"use strict";var Libp2PLogger=(()=>{var L=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var Y=(e,t)=>{for(var r in t)L(e,r,{get:t[r],enumerable:!0})},H=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of _(t))!W.call(e,s)&&s!==r&&L(e,s,{get:()=>t[s],enumerable:!(o=Q(t,s))||o.enumerable});return e};var ee=e=>H(L({},"__esModule",{value:!0}),e);var Ee={};Y(Ee,{defaultLogger:()=>ye,disable:()=>Fe,enable:()=>Ae,enabled:()=>ve,logger:()=>I,peerLogger:()=>xe,prefixLogger:()=>K});var Se=new Uint8Array(0);function R(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function re(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),o=0;o<r.length;o++)r[o]=255;for(var s=0;s<e.length;s++){var p=e.charAt(s),g=p.charCodeAt(0);if(r[g]!==255)throw new TypeError(p+" is ambiguous");r[g]=s}var u=e.length,w=e.charAt(0),S=Math.log(u)/Math.log(256),n=Math.log(256)/Math.log(u);function i(a){if(a instanceof Uint8Array||(ArrayBuffer.isView(a)?a=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):Array.isArray(a)&&(a=Uint8Array.from(a))),!(a instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(a.length===0)return"";for(var c=0,d=0,l=0,C=a.length;l!==C&&a[l]===0;)l++,c++;for(var y=(C-l)*n+1>>>0,h=new Uint8Array(y);l!==C;){for(var v=a[l],F=0,x=y-1;(v!==0||F<d)&&x!==-1;x--,F++)v+=256*h[x]>>>0,h[x]=v%u>>>0,v=v/u>>>0;if(v!==0)throw new Error("Non-zero carry");d=F,l++}for(var A=y-d;A!==y&&h[A]===0;)A++;for(var U=w.repeat(c);A<y;++A)U+=e.charAt(h[A]);return U}function f(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var c=0;if(a[c]!==" "){for(var d=0,l=0;a[c]===w;)d++,c++;for(var C=(a.length-c)*S+1>>>0,y=new Uint8Array(C);a[c];){var h=r[a.charCodeAt(c)];if(h===255)return;for(var v=0,F=C-1;(h!==0||v<l)&&F!==-1;F--,v++)h+=u*y[F]>>>0,y[F]=h%256>>>0,h=h/256>>>0;if(h!==0)throw new Error("Non-zero carry");l=v,c++}if(a[c]!==" "){for(var x=C-l;x!==C&&y[x]===0;)x++;for(var A=new Uint8Array(d+(C-x)),U=d;x!==C;)A[U++]=y[x++];return A}}}function E(a){var c=f(a);if(c)return c;throw new Error(`Non-${t} character`)}return{encode:i,decodeUnsafe:f,decode:E}}var te=re,ne=te,T=ne;var M=class{name;prefix;baseEncode;constructor(t,r,o){this.name=t,this.prefix=r,this.baseEncode=o}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},N=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,o){this.name=t,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=o}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return V(this,t)}},O=class{decoders;constructor(t){this.decoders=t}or(t){return V(this,t)}decode(t){let r=t[0],o=this.decoders[r];if(o!=null)return o.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function V(e,t){return new O({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var P=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,o,s){this.name=t,this.prefix=r,this.baseEncode=o,this.baseDecode=s,this.encoder=new M(t,r,o),this.decoder=new N(t,r,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function B({name:e,prefix:t,encode:r,decode:o}){return new P(e,t,r,o)}function j({name:e,prefix:t,alphabet:r}){let{encode:o,decode:s}=T(r,e);return B({prefix:t,name:e,encode:o,decode:p=>R(s(p))})}function oe(e,t,r,o){let s={};for(let n=0;n<t.length;++n)s[t[n]]=n;let p=e.length;for(;e[p-1]==="=";)--p;let g=new Uint8Array(p*r/8|0),u=0,w=0,S=0;for(let n=0;n<p;++n){let i=s[e[n]];if(i===void 0)throw new SyntaxError(`Non-${o} character`);w=w<<r|i,u+=r,u>=8&&(u-=8,g[S++]=255&w>>u)}if(u>=r||255&w<<8-u)throw new SyntaxError("Unexpected end of data");return g}function se(e,t,r){let o=t[t.length-1]==="=",s=(1<<r)-1,p="",g=0,u=0;for(let w=0;w<e.length;++w)for(u=u<<8|e[w],g+=8;g>r;)g-=r,p+=t[s&u>>g];if(g!==0&&(p+=t[s&u<<r-g]),o)for(;p.length*r&7;)p+="=";return p}function m({name:e,prefix:t,bitsPerChar:r,alphabet:o}){return B({prefix:t,name:e,encode(s){return se(s,o,r)},decode(s){return oe(s,o,r,e)}})}var J=m({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Oe=m({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Pe=m({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),je=m({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),De=m({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ie=m({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Re=m({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Te=m({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ve=m({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var q=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),qe=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var G=m({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ze=m({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ke=m({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Qe=m({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function ie(e,t){try{if(typeof e=="string"&&e.length>0)return ae(e);if(typeof e=="number"&&isFinite(e))return t?.long?fe(e):ce(e);throw new Error("Value is not a string or number.")}catch(r){let o=ue(r)?`${r.message}. value=${JSON.stringify(e)}`:"An unknown error has occured.";throw new Error(o)}}function ae(e){if(e=String(e),e.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return NaN;let r=parseFloat(t[1]),o=(t[2]||"ms").toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return r*315576e5;case"weeks":case"week":case"w":return r*6048e5;case"days":case"day":case"d":return r*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return r*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return r*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return r*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:throw new Error(`The unit ${o} was matched, but no matching case exists.`)}}var k=ie;function ce(e){let t=Math.abs(e);return t>=864e5?`${Math.round(e/864e5)}d`:t>=36e5?`${Math.round(e/36e5)}h`:t>=6e4?`${Math.round(e/6e4)}m`:t>=1e3?`${Math.round(e/1e3)}s`:`${e}ms`}function fe(e){let t=Math.abs(e);return t>=864e5?$(e,t,864e5,"day"):t>=36e5?$(e,t,36e5,"hour"):t>=6e4?$(e,t,6e4,"minute"):t>=1e3?$(e,t,1e3,"second"):`${e} ms`}function $(e,t,r,o){let s=t>=r*1.5;return`${Math.round(e/r)} ${o}${s?"s":""}`}function ue(e){return typeof e=="object"&&e!==null&&"message"in e}function D(e){r.debug=r,r.default=r,r.coerce=w,r.disable=p,r.enable=s,r.enabled=g,r.humanize=k,r.destroy=S,Object.keys(e).forEach(n=>{r[n]=e[n]}),r.names=[],r.skips=[],r.formatters={};function t(n){let i=0;for(let f=0;f<n.length;f++)i=(i<<5)-i+n.charCodeAt(f),i|=0;return r.colors[Math.abs(i)%r.colors.length]}r.selectColor=t;function r(n){let i,f=null,E,a;function c(...d){if(!c.enabled)return;let l=c,C=Number(new Date),y=C-(i||C);l.diff=y,l.prev=i,l.curr=C,i=C,d[0]=r.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let h=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(F,x)=>{if(F==="%%")return"%";h++;let A=r.formatters[x];if(typeof A=="function"){let U=d[h];F=A.call(l,U),d.splice(h,1),h--}return F}),r.formatArgs.call(l,d),(l.log||r.log).apply(l,d)}return c.namespace=n,c.useColors=r.useColors(),c.color=r.selectColor(n),c.extend=o,c.destroy=r.destroy,Object.defineProperty(c,"enabled",{enumerable:!0,configurable:!1,get:()=>f!==null?f:(E!==r.namespaces&&(E=r.namespaces,a=r.enabled(n)),a),set:d=>{f=d}}),typeof r.init=="function"&&r.init(c),c}function o(n,i){let f=r(this.namespace+(typeof i>"u"?":":i)+n);return f.log=this.log,f}function s(n){r.save(n),r.namespaces=n,r.names=[],r.skips=[];let i,f=(typeof n=="string"?n:"").split(/[\s,]+/),E=f.length;for(i=0;i<E;i++)f[i]&&(n=f[i].replace(/\*/g,".*?"),n[0]==="-"?r.skips.push(new RegExp("^"+n.substr(1)+"$")):r.names.push(new RegExp("^"+n+"$")))}function p(){let n=[...r.names.map(u),...r.skips.map(u).map(i=>"-"+i)].join(",");return r.enable(""),n}function g(n){if(n[n.length-1]==="*")return!0;let i,f;for(i=0,f=r.skips.length;i<f;i++)if(r.skips[i].test(n))return!1;for(i=0,f=r.names.length;i<f;i++)if(r.names[i].test(n))return!0;return!1}function u(n){return n.toString().substring(2,n.toString().length-2).replace(/\.\*\?$/,"*")}function w(n){return n instanceof Error?n.stack??n.message:n}function S(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var z=me(),de=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function le(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function pe(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+k(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let r=0,o=0;e[0].replace(/%[a-zA-Z%]/g,s=>{s!=="%%"&&(r++,s==="%c"&&(o=r))}),e.splice(o,0,t)}var he=console.debug??console.log??(()=>{});function be(e){try{e?z?.setItem("debug",e):z?.removeItem("debug")}catch{}}function Ce(){let e;try{e=z?.getItem("debug")}catch{}return!e&&typeof process<"u"&&"env"in process&&(e=process.env.DEBUG),e}function me(){try{return localStorage}catch{}}function ge(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var X=D({formatArgs:pe,save:be,load:Ce,useColors:le,setupFormatters:ge,colors:de,storage:z,log:he});var b=X;function Z(e,t={}){let r=t.prefixLength??2,o=t.suffixLength??4,s=e.toString();return`${s.substring(0,r)}\u2026${s.substring(s.length,s.length-o)}`}b.formatters.b=e=>e==null?"undefined":q.baseEncode(e);b.formatters.t=e=>e==null?"undefined":J.baseEncode(e);b.formatters.m=e=>e==null?"undefined":G.baseEncode(e);b.formatters.p=e=>e==null?"undefined":e.toString();b.formatters.c=e=>e==null?"undefined":e.toString();b.formatters.k=e=>e==null?"undefined":e.toString();b.formatters.a=e=>e==null?"undefined":e.toString();b.formatters.e=e=>e==null?"undefined":e.stack??e.message;function we(e){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}function xe(e,t={}){return K(Z(e,t))}function K(e){return{forComponent(t){return I(`${e}:${t}`)}}}function ye(){return{forComponent(e){return I(e)}}}function I(e){let t=we(`${e}:trace`);return b.enabled(`${e}:trace`)&&b.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=b(`${e}:trace`)),Object.assign(b(e),{error:b(`${e}:error`),trace:t})}function Fe(){b.disable()}function Ae(e){b.enable(e)}function ve(e){return b.enabled(e)}return ee(Ee);})(); | ||
return Libp2PLogger})); |
@@ -67,2 +67,6 @@ /** | ||
}; | ||
// Add a formatter for stringifying Errors | ||
debug.formatters.e = (v) => { | ||
return v == null ? 'undefined' : v.stack ?? v.message; | ||
}; | ||
function createDisabledLogger(namespace) { | ||
@@ -69,0 +73,0 @@ const logger = () => { }; |
{ | ||
"name": "@libp2p/logger", | ||
"version": "5.0.4", | ||
"version": "5.1.0", | ||
"description": "A logging component for use in js-libp2p modules", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT", |
@@ -80,2 +80,7 @@ /** | ||
// Add a formatter for stringifying Errors | ||
debug.formatters.e = (v?: Error): string => { | ||
return v == null ? 'undefined' : v.stack ?? v.message | ||
} | ||
export interface Logger { | ||
@@ -82,0 +87,0 @@ (formatter: any, ...args: any[]): void |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40592
590