@ribbon-studios/logger 2.0.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/__tests__/logger.spec.d.ts +1 -0
- package/dist/index.cjs +5 -0
- package/dist/index.js +397 -2
- package/dist/logger.d.ts +22 -9
- package/dist/utils/__tests__/messages.spec.d.ts +1 -0
- package/dist/utils/__tests__/stringify.spec.d.ts +1 -0
- package/package.json +23 -21
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +0 -1
- package/dist/index.modern.mjs +0 -2
- package/dist/index.modern.mjs.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
package/README.md
CHANGED
|
@@ -9,19 +9,19 @@
|
|
|
9
9
|
[![Semantic Release][semantic-release-image]][semantic-release-url]
|
|
10
10
|
[![Code Style: Prettier][code-style-image]][code-style-url]
|
|
11
11
|
|
|
12
|
-
A simple logger for all
|
|
12
|
+
A simple logger for all Ribbon Studios Apps & Libraries
|
|
13
13
|
|
|
14
14
|
### Usage
|
|
15
15
|
|
|
16
16
|
```ts
|
|
17
|
-
import {
|
|
17
|
+
import { logger, LogLevel } from '@ribbon-studios/logger';
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
logger.setLevel(LogLevel.INFO); // This is the default LogLevel
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
logger.silly('hello', 'world!'); // Outputs nothing since its lower then the configured level!
|
|
22
|
+
logger.info('hello', 'world!'); // '[info]: hello world!'
|
|
23
|
+
logger.warn('hello', 'world!'); // '[warn]: hello world!'
|
|
24
|
+
logger.error('hello', 'world!'); // '[error]: hello world!'
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
[npm-version-image]: https://img.shields.io/npm/v/@ribbon-studios/logger.svg
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var M=t=>{throw TypeError(t)};var T=(t,e,r)=>e.has(t)||M("Cannot "+r);var b=(t,e,r)=>(T(t,e,"read from private field"),r?r.call(t):e.get(t)),C=(t,e,r)=>e.has(t)?M("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),j=(t,e,r,o)=>(T(t,e,"write to private field"),o?o.call(t,r):e.set(t,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=10,R=(t=0)=>e=>`\x1B[${e+t}m`,E=(t=0)=>e=>`\x1B[${38+t};5;${e}m`,S=(t=0)=>(e,r,o)=>`\x1B[${38+t};2;${e};${r};${o}m`,l={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};Object.keys(l.modifier);const $=Object.keys(l.color),G=Object.keys(l.bgColor);[...$,...G];function Y(){const t=new Map;for(const[e,r]of Object.entries(l)){for(const[o,n]of Object.entries(r))l[o]={open:`\x1B[${n[0]}m`,close:`\x1B[${n[1]}m`},r[o]=l[o],t.set(n[0],n[1]);Object.defineProperty(l,e,{value:r,enumerable:!1})}return Object.defineProperty(l,"codes",{value:t,enumerable:!1}),l.color.close="\x1B[39m",l.bgColor.close="\x1B[49m",l.color.ansi=R(),l.color.ansi256=E(),l.color.ansi16m=S(),l.bgColor.ansi=R(m),l.bgColor.ansi256=E(m),l.bgColor.ansi16m=S(m),Object.defineProperties(l,{rgbToAnsi256:{value(e,r,o){return e===r&&r===o?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(r/255*5)+Math.round(o/255*5)},enumerable:!1},hexToRgb:{value(e){const r=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!r)return[0,0,0];let[o]=r;o.length===3&&(o=[...o].map(i=>i+i).join(""));const n=Number.parseInt(o,16);return[n>>16&255,n>>8&255,n&255]},enumerable:!1},hexToAnsi256:{value:e=>l.rgbToAnsi256(...l.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let r,o,n;if(e>=232)r=((e-232)*10+8)/255,o=r,n=r;else{e-=16;const B=e%36;r=Math.floor(e/36)/5,o=Math.floor(B/6)/5,n=B%6/5}const i=Math.max(r,o,n)*2;if(i===0)return 30;let s=30+(Math.round(n)<<2|Math.round(o)<<1|Math.round(r));return i===2&&(s+=60),s},enumerable:!1},rgbToAnsi:{value:(e,r,o)=>l.ansi256ToAnsi(l.rgbToAnsi256(e,r,o)),enumerable:!1},hexToAnsi:{value:e=>l.ansi256ToAnsi(l.hexToAnsi256(e)),enumerable:!1}}),l}const a=Y(),x=(()=>{if(!("navigator"in globalThis))return 0;if(globalThis.navigator.userAgentData){const t=navigator.userAgentData.brands.find(({brand:e})=>e==="Chromium");if(t&&t.version>93)return 3}return/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)?1:0})(),w=x!==0&&{level:x},W={stdout:w,stderr:w};function H(t,e,r){let o=t.indexOf(e);if(o===-1)return t;const n=e.length;let i=0,s="";do s+=t.slice(i,o)+e+r,i=o+n,o=t.indexOf(e,i);while(o!==-1);return s+=t.slice(i),s}function V(t,e,r,o){let n=0,i="";do{const s=t[o-1]==="\r";i+=t.slice(n,s?o-1:o)+e+(s?`\r
|
|
2
|
+
`:`
|
|
3
|
+
`)+r,n=o+1,o=t.indexOf(`
|
|
4
|
+
`,n)}while(o!==-1);return i+=t.slice(n),i}const{stdout:N,stderr:k}=W,v=Symbol("GENERATOR"),u=Symbol("STYLER"),g=Symbol("IS_EMPTY"),F=["ansi","ansi","ansi256","ansi16m"],h=Object.create(null),D=(t,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");const r=N?N.level:0;t.level=e.level===void 0?r:e.level},K=t=>{const e=(...r)=>r.join(" ");return D(e,t),Object.setPrototypeOf(e,d.prototype),e};function d(t){return K(t)}Object.setPrototypeOf(d.prototype,Function.prototype);for(const[t,e]of Object.entries(a))h[t]={get(){const r=y(this,O(e.open,e.close,this[u]),this[g]);return Object.defineProperty(this,t,{value:r}),r}};h.visible={get(){const t=y(this,this[u],!0);return Object.defineProperty(this,"visible",{value:t}),t}};const A=(t,e,r,...o)=>t==="rgb"?e==="ansi16m"?a[r].ansi16m(...o):e==="ansi256"?a[r].ansi256(a.rgbToAnsi256(...o)):a[r].ansi(a.rgbToAnsi(...o)):t==="hex"?A("rgb",e,r,...a.hexToRgb(...o)):a[r][t](...o),U=["rgb","hex","ansi256"];for(const t of U){h[t]={get(){const{level:r}=this;return function(...o){const n=O(A(t,F[r],"color",...o),a.color.close,this[u]);return y(this,n,this[g])}}};const e="bg"+t[0].toUpperCase()+t.slice(1);h[e]={get(){const{level:r}=this;return function(...o){const n=O(A(t,F[r],"bgColor",...o),a.bgColor.close,this[u]);return y(this,n,this[g])}}}}const X=Object.defineProperties(()=>{},{...h,level:{enumerable:!0,get(){return this[v].level},set(t){this[v].level=t}}}),O=(t,e,r)=>{let o,n;return r===void 0?(o=t,n=e):(o=r.openAll+t,n=e+r.closeAll),{open:t,close:e,openAll:o,closeAll:n,parent:r}},y=(t,e,r)=>{const o=(...n)=>_(o,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(o,X),o[v]=t,o[u]=e,o[g]=r,o},_=(t,e)=>{if(t.level<=0||!e)return t[g]?"":e;let r=t[u];if(r===void 0)return e;const{openAll:o,closeAll:n}=r;if(e.includes("\x1B"))for(;r!==void 0;)e=H(e,r.close,r.open),r=r.parent;const i=e.indexOf(`
|
|
5
|
+
`);return i!==-1&&(e=V(e,n,o,i)),o+e+n};Object.defineProperties(d.prototype,h);const f=d();d({level:k?k.level:0});function z(t){const e=new Set;return JSON.stringify(t,(r,o)=>{if(typeof o=="object"&&o!==null){if(e.has(o))return;e.add(o)}return o},4)}function J(t){return t.map(e=>e instanceof Error||typeof e!="object"?e:z(e))}var p=(t=>(t[t.ERROR=0]="ERROR",t[t.WARN=1]="WARN",t[t.INFO=2]="INFO",t[t.SILLY=3]="SILLY",t))(p||{});const I=Object.keys(p).reduce((t,e)=>Math.max(t,e.length),0)+3,L={0:f.red,1:f.yellow,2:f.cyan,3:f.magenta};var c;class P{constructor(e){C(this,c);if(j(this,c,{level:2,...typeof e=="string"?{scope:e}:e}),b(this,c).scope){const r=f.rgb(Math.floor(Math.random()*255),Math.floor(Math.random()*255),Math.floor(Math.random()*255));this.prefix=r(`[${b(this,c).scope}]`)}}isLevel(e){return e!=null&&b(this,c).level>=e}isNotLevel(e){return!this.isLevel(e)}setLevel(e){b(this,c).level=e}log(e,...r){if(this.isNotLevel(e))return;const o=L[e],n=J(r).map(s=>s instanceof Error?s:o(s)),i=[this.prefix,o(`[${p[e].toLowerCase()}]:`).padEnd(I," ")].filter(Boolean).join("");console.log(i,...n)}error(...e){this.log(0,...e)}warn(...e){this.log(1,...e)}info(...e){this.log(2,...e)}silly(...e){this.log(3,...e)}}c=new WeakMap;const q=new P;exports.LEVEL_CHALK=L;exports.LogLevel=p;exports.MAX_LENGTH=I;exports.RibbonLogger=P;exports.logger=q;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,397 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var B = (t) => {
|
|
2
|
+
throw TypeError(t);
|
|
3
|
+
};
|
|
4
|
+
var T = (t, e, r) => e.has(t) || B("Cannot " + r);
|
|
5
|
+
var f = (t, e, r) => (T(t, e, "read from private field"), r ? r.call(t) : e.get(t)), C = (t, e, r) => e.has(t) ? B("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r), M = (t, e, r, o) => (T(t, e, "write to private field"), o ? o.call(t, r) : e.set(t, r), r);
|
|
6
|
+
const R = (t = 0) => (e) => `\x1B[${e + t}m`, S = (t = 0) => (e) => `\x1B[${38 + t};5;${e}m`, N = (t = 0) => (e, r, o) => `\x1B[${38 + t};2;${e};${r};${o}m`, l = {
|
|
7
|
+
modifier: {
|
|
8
|
+
reset: [0, 0],
|
|
9
|
+
// 21 isn't widely supported and 22 does the same thing
|
|
10
|
+
bold: [1, 22],
|
|
11
|
+
dim: [2, 22],
|
|
12
|
+
italic: [3, 23],
|
|
13
|
+
underline: [4, 24],
|
|
14
|
+
overline: [53, 55],
|
|
15
|
+
inverse: [7, 27],
|
|
16
|
+
hidden: [8, 28],
|
|
17
|
+
strikethrough: [9, 29]
|
|
18
|
+
},
|
|
19
|
+
color: {
|
|
20
|
+
black: [30, 39],
|
|
21
|
+
red: [31, 39],
|
|
22
|
+
green: [32, 39],
|
|
23
|
+
yellow: [33, 39],
|
|
24
|
+
blue: [34, 39],
|
|
25
|
+
magenta: [35, 39],
|
|
26
|
+
cyan: [36, 39],
|
|
27
|
+
white: [37, 39],
|
|
28
|
+
// Bright color
|
|
29
|
+
blackBright: [90, 39],
|
|
30
|
+
gray: [90, 39],
|
|
31
|
+
// Alias of `blackBright`
|
|
32
|
+
grey: [90, 39],
|
|
33
|
+
// Alias of `blackBright`
|
|
34
|
+
redBright: [91, 39],
|
|
35
|
+
greenBright: [92, 39],
|
|
36
|
+
yellowBright: [93, 39],
|
|
37
|
+
blueBright: [94, 39],
|
|
38
|
+
magentaBright: [95, 39],
|
|
39
|
+
cyanBright: [96, 39],
|
|
40
|
+
whiteBright: [97, 39]
|
|
41
|
+
},
|
|
42
|
+
bgColor: {
|
|
43
|
+
bgBlack: [40, 49],
|
|
44
|
+
bgRed: [41, 49],
|
|
45
|
+
bgGreen: [42, 49],
|
|
46
|
+
bgYellow: [43, 49],
|
|
47
|
+
bgBlue: [44, 49],
|
|
48
|
+
bgMagenta: [45, 49],
|
|
49
|
+
bgCyan: [46, 49],
|
|
50
|
+
bgWhite: [47, 49],
|
|
51
|
+
// Bright color
|
|
52
|
+
bgBlackBright: [100, 49],
|
|
53
|
+
bgGray: [100, 49],
|
|
54
|
+
// Alias of `bgBlackBright`
|
|
55
|
+
bgGrey: [100, 49],
|
|
56
|
+
// Alias of `bgBlackBright`
|
|
57
|
+
bgRedBright: [101, 49],
|
|
58
|
+
bgGreenBright: [102, 49],
|
|
59
|
+
bgYellowBright: [103, 49],
|
|
60
|
+
bgBlueBright: [104, 49],
|
|
61
|
+
bgMagentaBright: [105, 49],
|
|
62
|
+
bgCyanBright: [106, 49],
|
|
63
|
+
bgWhiteBright: [107, 49]
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
Object.keys(l.modifier);
|
|
67
|
+
const k = Object.keys(l.color), I = Object.keys(l.bgColor);
|
|
68
|
+
[...k, ...I];
|
|
69
|
+
function P() {
|
|
70
|
+
const t = /* @__PURE__ */ new Map();
|
|
71
|
+
for (const [e, r] of Object.entries(l)) {
|
|
72
|
+
for (const [o, n] of Object.entries(r))
|
|
73
|
+
l[o] = {
|
|
74
|
+
open: `\x1B[${n[0]}m`,
|
|
75
|
+
close: `\x1B[${n[1]}m`
|
|
76
|
+
}, r[o] = l[o], t.set(n[0], n[1]);
|
|
77
|
+
Object.defineProperty(l, e, {
|
|
78
|
+
value: r,
|
|
79
|
+
enumerable: !1
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return Object.defineProperty(l, "codes", {
|
|
83
|
+
value: t,
|
|
84
|
+
enumerable: !1
|
|
85
|
+
}), l.color.close = "\x1B[39m", l.bgColor.close = "\x1B[49m", l.color.ansi = R(), l.color.ansi256 = S(), l.color.ansi16m = N(), l.bgColor.ansi = R(10), l.bgColor.ansi256 = S(10), l.bgColor.ansi16m = N(10), Object.defineProperties(l, {
|
|
86
|
+
rgbToAnsi256: {
|
|
87
|
+
value(e, r, o) {
|
|
88
|
+
return e === r && r === o ? e < 8 ? 16 : e > 248 ? 231 : Math.round((e - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(e / 255 * 5) + 6 * Math.round(r / 255 * 5) + Math.round(o / 255 * 5);
|
|
89
|
+
},
|
|
90
|
+
enumerable: !1
|
|
91
|
+
},
|
|
92
|
+
hexToRgb: {
|
|
93
|
+
value(e) {
|
|
94
|
+
const r = /[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));
|
|
95
|
+
if (!r)
|
|
96
|
+
return [0, 0, 0];
|
|
97
|
+
let [o] = r;
|
|
98
|
+
o.length === 3 && (o = [...o].map((s) => s + s).join(""));
|
|
99
|
+
const n = Number.parseInt(o, 16);
|
|
100
|
+
return [
|
|
101
|
+
/* eslint-disable no-bitwise */
|
|
102
|
+
n >> 16 & 255,
|
|
103
|
+
n >> 8 & 255,
|
|
104
|
+
n & 255
|
|
105
|
+
/* eslint-enable no-bitwise */
|
|
106
|
+
];
|
|
107
|
+
},
|
|
108
|
+
enumerable: !1
|
|
109
|
+
},
|
|
110
|
+
hexToAnsi256: {
|
|
111
|
+
value: (e) => l.rgbToAnsi256(...l.hexToRgb(e)),
|
|
112
|
+
enumerable: !1
|
|
113
|
+
},
|
|
114
|
+
ansi256ToAnsi: {
|
|
115
|
+
value(e) {
|
|
116
|
+
if (e < 8)
|
|
117
|
+
return 30 + e;
|
|
118
|
+
if (e < 16)
|
|
119
|
+
return 90 + (e - 8);
|
|
120
|
+
let r, o, n;
|
|
121
|
+
if (e >= 232)
|
|
122
|
+
r = ((e - 232) * 10 + 8) / 255, o = r, n = r;
|
|
123
|
+
else {
|
|
124
|
+
e -= 16;
|
|
125
|
+
const v = e % 36;
|
|
126
|
+
r = Math.floor(e / 36) / 5, o = Math.floor(v / 6) / 5, n = v % 6 / 5;
|
|
127
|
+
}
|
|
128
|
+
const s = Math.max(r, o, n) * 2;
|
|
129
|
+
if (s === 0)
|
|
130
|
+
return 30;
|
|
131
|
+
let i = 30 + (Math.round(n) << 2 | Math.round(o) << 1 | Math.round(r));
|
|
132
|
+
return s === 2 && (i += 60), i;
|
|
133
|
+
},
|
|
134
|
+
enumerable: !1
|
|
135
|
+
},
|
|
136
|
+
rgbToAnsi: {
|
|
137
|
+
value: (e, r, o) => l.ansi256ToAnsi(l.rgbToAnsi256(e, r, o)),
|
|
138
|
+
enumerable: !1
|
|
139
|
+
},
|
|
140
|
+
hexToAnsi: {
|
|
141
|
+
value: (e) => l.ansi256ToAnsi(l.hexToAnsi256(e)),
|
|
142
|
+
enumerable: !1
|
|
143
|
+
}
|
|
144
|
+
}), l;
|
|
145
|
+
}
|
|
146
|
+
const a = P(), j = (() => {
|
|
147
|
+
if (!("navigator" in globalThis))
|
|
148
|
+
return 0;
|
|
149
|
+
if (globalThis.navigator.userAgentData) {
|
|
150
|
+
const t = navigator.userAgentData.brands.find(({ brand: e }) => e === "Chromium");
|
|
151
|
+
if (t && t.version > 93)
|
|
152
|
+
return 3;
|
|
153
|
+
}
|
|
154
|
+
return /\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent) ? 1 : 0;
|
|
155
|
+
})(), x = j !== 0 && {
|
|
156
|
+
level: j
|
|
157
|
+
}, $ = {
|
|
158
|
+
stdout: x,
|
|
159
|
+
stderr: x
|
|
160
|
+
};
|
|
161
|
+
function G(t, e, r) {
|
|
162
|
+
let o = t.indexOf(e);
|
|
163
|
+
if (o === -1)
|
|
164
|
+
return t;
|
|
165
|
+
const n = e.length;
|
|
166
|
+
let s = 0, i = "";
|
|
167
|
+
do
|
|
168
|
+
i += t.slice(s, o) + e + r, s = o + n, o = t.indexOf(e, s);
|
|
169
|
+
while (o !== -1);
|
|
170
|
+
return i += t.slice(s), i;
|
|
171
|
+
}
|
|
172
|
+
function Y(t, e, r, o) {
|
|
173
|
+
let n = 0, s = "";
|
|
174
|
+
do {
|
|
175
|
+
const i = t[o - 1] === "\r";
|
|
176
|
+
s += t.slice(n, i ? o - 1 : o) + e + (i ? `\r
|
|
177
|
+
` : `
|
|
178
|
+
`) + r, n = o + 1, o = t.indexOf(`
|
|
179
|
+
`, n);
|
|
180
|
+
} while (o !== -1);
|
|
181
|
+
return s += t.slice(n), s;
|
|
182
|
+
}
|
|
183
|
+
const { stdout: E, stderr: w } = $, p = Symbol("GENERATOR"), u = Symbol("STYLER"), g = Symbol("IS_EMPTY"), F = [
|
|
184
|
+
"ansi",
|
|
185
|
+
"ansi",
|
|
186
|
+
"ansi256",
|
|
187
|
+
"ansi16m"
|
|
188
|
+
], h = /* @__PURE__ */ Object.create(null), D = (t, e = {}) => {
|
|
189
|
+
if (e.level && !(Number.isInteger(e.level) && e.level >= 0 && e.level <= 3))
|
|
190
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
191
|
+
const r = E ? E.level : 0;
|
|
192
|
+
t.level = e.level === void 0 ? r : e.level;
|
|
193
|
+
}, L = (t) => {
|
|
194
|
+
const e = (...r) => r.join(" ");
|
|
195
|
+
return D(e, t), Object.setPrototypeOf(e, d.prototype), e;
|
|
196
|
+
};
|
|
197
|
+
function d(t) {
|
|
198
|
+
return L(t);
|
|
199
|
+
}
|
|
200
|
+
Object.setPrototypeOf(d.prototype, Function.prototype);
|
|
201
|
+
for (const [t, e] of Object.entries(a))
|
|
202
|
+
h[t] = {
|
|
203
|
+
get() {
|
|
204
|
+
const r = y(this, O(e.open, e.close, this[u]), this[g]);
|
|
205
|
+
return Object.defineProperty(this, t, { value: r }), r;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
h.visible = {
|
|
209
|
+
get() {
|
|
210
|
+
const t = y(this, this[u], !0);
|
|
211
|
+
return Object.defineProperty(this, "visible", { value: t }), t;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
const m = (t, e, r, ...o) => t === "rgb" ? e === "ansi16m" ? a[r].ansi16m(...o) : e === "ansi256" ? a[r].ansi256(a.rgbToAnsi256(...o)) : a[r].ansi(a.rgbToAnsi(...o)) : t === "hex" ? m("rgb", e, r, ...a.hexToRgb(...o)) : a[r][t](...o), _ = ["rgb", "hex", "ansi256"];
|
|
215
|
+
for (const t of _) {
|
|
216
|
+
h[t] = {
|
|
217
|
+
get() {
|
|
218
|
+
const { level: r } = this;
|
|
219
|
+
return function(...o) {
|
|
220
|
+
const n = O(m(t, F[r], "color", ...o), a.color.close, this[u]);
|
|
221
|
+
return y(this, n, this[g]);
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
const e = "bg" + t[0].toUpperCase() + t.slice(1);
|
|
226
|
+
h[e] = {
|
|
227
|
+
get() {
|
|
228
|
+
const { level: r } = this;
|
|
229
|
+
return function(...o) {
|
|
230
|
+
const n = O(m(t, F[r], "bgColor", ...o), a.bgColor.close, this[u]);
|
|
231
|
+
return y(this, n, this[g]);
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
const K = Object.defineProperties(() => {
|
|
237
|
+
}, {
|
|
238
|
+
...h,
|
|
239
|
+
level: {
|
|
240
|
+
enumerable: !0,
|
|
241
|
+
get() {
|
|
242
|
+
return this[p].level;
|
|
243
|
+
},
|
|
244
|
+
set(t) {
|
|
245
|
+
this[p].level = t;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}), O = (t, e, r) => {
|
|
249
|
+
let o, n;
|
|
250
|
+
return r === void 0 ? (o = t, n = e) : (o = r.openAll + t, n = e + r.closeAll), {
|
|
251
|
+
open: t,
|
|
252
|
+
close: e,
|
|
253
|
+
openAll: o,
|
|
254
|
+
closeAll: n,
|
|
255
|
+
parent: r
|
|
256
|
+
};
|
|
257
|
+
}, y = (t, e, r) => {
|
|
258
|
+
const o = (...n) => U(o, n.length === 1 ? "" + n[0] : n.join(" "));
|
|
259
|
+
return Object.setPrototypeOf(o, K), o[p] = t, o[u] = e, o[g] = r, o;
|
|
260
|
+
}, U = (t, e) => {
|
|
261
|
+
if (t.level <= 0 || !e)
|
|
262
|
+
return t[g] ? "" : e;
|
|
263
|
+
let r = t[u];
|
|
264
|
+
if (r === void 0)
|
|
265
|
+
return e;
|
|
266
|
+
const { openAll: o, closeAll: n } = r;
|
|
267
|
+
if (e.includes("\x1B"))
|
|
268
|
+
for (; r !== void 0; )
|
|
269
|
+
e = G(e, r.close, r.open), r = r.parent;
|
|
270
|
+
const s = e.indexOf(`
|
|
271
|
+
`);
|
|
272
|
+
return s !== -1 && (e = Y(e, n, o, s)), o + e + n;
|
|
273
|
+
};
|
|
274
|
+
Object.defineProperties(d.prototype, h);
|
|
275
|
+
const b = d();
|
|
276
|
+
d({ level: w ? w.level : 0 });
|
|
277
|
+
function W(t) {
|
|
278
|
+
const e = /* @__PURE__ */ new Set();
|
|
279
|
+
return JSON.stringify(
|
|
280
|
+
t,
|
|
281
|
+
(r, o) => {
|
|
282
|
+
if (typeof o == "object" && o !== null) {
|
|
283
|
+
if (e.has(o))
|
|
284
|
+
return;
|
|
285
|
+
e.add(o);
|
|
286
|
+
}
|
|
287
|
+
return o;
|
|
288
|
+
},
|
|
289
|
+
4
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
function V(t) {
|
|
293
|
+
return t.map((e) => e instanceof Error || typeof e != "object" ? e : W(e));
|
|
294
|
+
}
|
|
295
|
+
var A = /* @__PURE__ */ ((t) => (t[t.ERROR = 0] = "ERROR", t[t.WARN = 1] = "WARN", t[t.INFO = 2] = "INFO", t[t.SILLY = 3] = "SILLY", t))(A || {});
|
|
296
|
+
const H = Object.keys(A).reduce((t, e) => Math.max(t, e.length), 0) + 3, z = {
|
|
297
|
+
0: b.red,
|
|
298
|
+
1: b.yellow,
|
|
299
|
+
2: b.cyan,
|
|
300
|
+
3: b.magenta
|
|
301
|
+
};
|
|
302
|
+
var c;
|
|
303
|
+
class J {
|
|
304
|
+
constructor(e) {
|
|
305
|
+
C(this, c);
|
|
306
|
+
if (M(this, c, {
|
|
307
|
+
level: 2,
|
|
308
|
+
...typeof e == "string" ? { scope: e } : e
|
|
309
|
+
}), f(this, c).scope) {
|
|
310
|
+
const r = b.rgb(
|
|
311
|
+
Math.floor(Math.random() * 255),
|
|
312
|
+
Math.floor(Math.random() * 255),
|
|
313
|
+
Math.floor(Math.random() * 255)
|
|
314
|
+
);
|
|
315
|
+
this.prefix = r(`[${f(this, c).scope}]`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Returns whether the logger is configured to allow the given log level to output.
|
|
320
|
+
* @param level the level to validate
|
|
321
|
+
* @returns true if the given level is equal to or higher priority then the configured level
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* Logger.setLevel(LogLevel.INFO);
|
|
325
|
+
* // Returns true
|
|
326
|
+
* Logger.isLevel(LogLevel.ERROR);
|
|
327
|
+
* // Also returns true
|
|
328
|
+
* Logger.isLevel(LogLevel.INFO);
|
|
329
|
+
*/
|
|
330
|
+
isLevel(e) {
|
|
331
|
+
return e != null && f(this, c).level >= e;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Returns whether the logger is configured to deny the given log level to output.
|
|
335
|
+
* @param level the level to validate
|
|
336
|
+
* @returns true if the given level is lower priority then the configured level
|
|
337
|
+
*/
|
|
338
|
+
isNotLevel(e) {
|
|
339
|
+
return !this.isLevel(e);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Sets the level to allow to output
|
|
343
|
+
* @param level the level to set
|
|
344
|
+
*/
|
|
345
|
+
setLevel(e) {
|
|
346
|
+
f(this, c).level = e;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* A wrapper around console.log with color formatting and filtering by the set LogLevel.
|
|
350
|
+
* @param level the LogLevel of this message
|
|
351
|
+
* @param rawMessages the messages to send
|
|
352
|
+
*/
|
|
353
|
+
log(e, ...r) {
|
|
354
|
+
if (this.isNotLevel(e)) return;
|
|
355
|
+
const o = z[e], n = V(r).map(
|
|
356
|
+
(i) => i instanceof Error ? i : o(i)
|
|
357
|
+
), s = [this.prefix, o(`[${A[e].toLowerCase()}]:`).padEnd(H, " ")].filter(Boolean).join("");
|
|
358
|
+
console.log(s, ...n);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* A helper that automatically calls {@link Logger.log} with {@link LogLevel.ERROR}
|
|
362
|
+
* @param messages the messages to send
|
|
363
|
+
*/
|
|
364
|
+
error(...e) {
|
|
365
|
+
this.log(0, ...e);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* A helper that automatically calls {@link Logger.log} with {@link LogLevel.WARN}
|
|
369
|
+
* @param messages the messages to send
|
|
370
|
+
*/
|
|
371
|
+
warn(...e) {
|
|
372
|
+
this.log(1, ...e);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* A helper that automatically calls {@link Logger.log} with {@link LogLevel.INFO}
|
|
376
|
+
* @param messages the messages to send
|
|
377
|
+
*/
|
|
378
|
+
info(...e) {
|
|
379
|
+
this.log(2, ...e);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* A helper that automatically calls {@link Logger.log} with {@link LogLevel.SILLY}
|
|
383
|
+
* @param messages the messages to send
|
|
384
|
+
*/
|
|
385
|
+
silly(...e) {
|
|
386
|
+
this.log(3, ...e);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
c = new WeakMap();
|
|
390
|
+
const q = new J();
|
|
391
|
+
export {
|
|
392
|
+
z as LEVEL_CHALK,
|
|
393
|
+
A as LogLevel,
|
|
394
|
+
H as MAX_LENGTH,
|
|
395
|
+
J as RibbonLogger,
|
|
396
|
+
q as logger
|
|
397
|
+
};
|
package/dist/logger.d.ts
CHANGED
|
@@ -12,8 +12,14 @@ export declare const LEVEL_CHALK: {
|
|
|
12
12
|
/**
|
|
13
13
|
* A simple wrapper around 'console.log'
|
|
14
14
|
*/
|
|
15
|
-
export declare class
|
|
15
|
+
export declare class RibbonLogger {
|
|
16
16
|
#private;
|
|
17
|
+
readonly prefix?: string;
|
|
18
|
+
/**
|
|
19
|
+
* @param scope prefixes the messages with the given scope
|
|
20
|
+
*/
|
|
21
|
+
constructor(scope?: string);
|
|
22
|
+
constructor(options?: Partial<RibbonLogger.Options>);
|
|
17
23
|
/**
|
|
18
24
|
* Returns whether the logger is configured to allow the given log level to output.
|
|
19
25
|
* @param level the level to validate
|
|
@@ -26,42 +32,49 @@ export declare class Logger {
|
|
|
26
32
|
* // Also returns true
|
|
27
33
|
* Logger.isLevel(LogLevel.INFO);
|
|
28
34
|
*/
|
|
29
|
-
|
|
35
|
+
isLevel(level?: LogLevel): boolean;
|
|
30
36
|
/**
|
|
31
37
|
* Returns whether the logger is configured to deny the given log level to output.
|
|
32
38
|
* @param level the level to validate
|
|
33
39
|
* @returns true if the given level is lower priority then the configured level
|
|
34
40
|
*/
|
|
35
|
-
|
|
41
|
+
isNotLevel(level?: LogLevel): boolean;
|
|
36
42
|
/**
|
|
37
43
|
* Sets the level to allow to output
|
|
38
44
|
* @param level the level to set
|
|
39
45
|
*/
|
|
40
|
-
|
|
46
|
+
setLevel(level: LogLevel): void;
|
|
41
47
|
/**
|
|
42
48
|
* A wrapper around console.log with color formatting and filtering by the set LogLevel.
|
|
43
49
|
* @param level the LogLevel of this message
|
|
44
50
|
* @param rawMessages the messages to send
|
|
45
51
|
*/
|
|
46
|
-
|
|
52
|
+
log(level: LogLevel, ...rawMessages: any[]): void;
|
|
47
53
|
/**
|
|
48
54
|
* A helper that automatically calls {@link Logger.log} with {@link LogLevel.ERROR}
|
|
49
55
|
* @param messages the messages to send
|
|
50
56
|
*/
|
|
51
|
-
|
|
57
|
+
error(...messages: any[]): void;
|
|
52
58
|
/**
|
|
53
59
|
* A helper that automatically calls {@link Logger.log} with {@link LogLevel.WARN}
|
|
54
60
|
* @param messages the messages to send
|
|
55
61
|
*/
|
|
56
|
-
|
|
62
|
+
warn(...messages: any[]): void;
|
|
57
63
|
/**
|
|
58
64
|
* A helper that automatically calls {@link Logger.log} with {@link LogLevel.INFO}
|
|
59
65
|
* @param messages the messages to send
|
|
60
66
|
*/
|
|
61
|
-
|
|
67
|
+
info(...messages: any[]): void;
|
|
62
68
|
/**
|
|
63
69
|
* A helper that automatically calls {@link Logger.log} with {@link LogLevel.SILLY}
|
|
64
70
|
* @param messages the messages to send
|
|
65
71
|
*/
|
|
66
|
-
|
|
72
|
+
silly(...messages: any[]): void;
|
|
73
|
+
}
|
|
74
|
+
export declare namespace RibbonLogger {
|
|
75
|
+
type Options = {
|
|
76
|
+
scope?: string;
|
|
77
|
+
level: LogLevel;
|
|
78
|
+
};
|
|
67
79
|
}
|
|
80
|
+
export declare const logger: RibbonLogger;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ribbon-studios/logger",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A simple logger for all Ribbon Studios Apps & Libraries",
|
|
5
6
|
"source": "src/index.ts",
|
|
6
|
-
"main": "dist/index.
|
|
7
|
-
"
|
|
8
|
-
"module": "dist/index.mjs",
|
|
9
|
-
"exports": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"require": "./dist/index.js",
|
|
12
|
-
"default": "./dist/index.modern.mjs"
|
|
13
|
-
},
|
|
7
|
+
"main": "dist/index.cjs",
|
|
8
|
+
"module": "dist/index.js",
|
|
14
9
|
"types": "dist/index.d.ts",
|
|
15
10
|
"scripts": {
|
|
16
11
|
"lint": "eslint 'src/**/*.ts'",
|
|
17
|
-
"build": "
|
|
12
|
+
"build": "vite build",
|
|
13
|
+
"test": "vitest",
|
|
14
|
+
"test:coverage": "vitest --coverage"
|
|
18
15
|
},
|
|
19
|
-
"
|
|
20
|
-
"chalk": "
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"chalk": "*"
|
|
21
18
|
},
|
|
22
19
|
"devDependencies": {
|
|
23
|
-
"@types/
|
|
24
|
-
"@
|
|
25
|
-
"@
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
20
|
+
"@types/chance": "^1.1.6",
|
|
21
|
+
"@types/node": "^22.13.9",
|
|
22
|
+
"@vitest/coverage-v8": "3.0.7",
|
|
23
|
+
"ajv": "^8.17.1",
|
|
24
|
+
"chance": "^1.1.12",
|
|
25
|
+
"dedent": "^1.5.3",
|
|
26
|
+
"eslint-plugin-unused-imports": "^4.1.4",
|
|
27
|
+
"jiti": "^2.4.2",
|
|
30
28
|
"string-dedent": "^3.0.1",
|
|
31
|
-
"typescript": "^5.
|
|
29
|
+
"typescript": "^5.8.2",
|
|
30
|
+
"typescript-eslint": "^8.26.0",
|
|
31
|
+
"vite": "^6.2.0",
|
|
32
|
+
"vite-plugin-dts": "^4.5.3",
|
|
33
|
+
"vitest": "^3.0.7"
|
|
32
34
|
},
|
|
33
35
|
"publishConfig": {
|
|
34
36
|
"access": "public"
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/logger.ts","../src/utils/messages.ts","../src/utils/stringify.ts"],"sourcesContent":["import chalk, { ChalkInstance } from 'chalk';\nimport { sanitizeMessages } from './utils/messages';\n\nexport enum LogLevel {\n ERROR,\n WARN,\n INFO,\n SILLY,\n}\n\nexport const MAX_LENGTH =\n Object.keys(LogLevel).reduce((output, value) => {\n return Math.max(output, value.length);\n }, 0) + 3;\n\nexport const LEVEL_CHALK: {\n [key in LogLevel]: ChalkInstance;\n} = {\n [LogLevel.ERROR]: chalk.red,\n [LogLevel.WARN]: chalk.yellow,\n [LogLevel.INFO]: chalk.cyan,\n [LogLevel.SILLY]: chalk.magenta,\n};\n\n/**\n * A simple wrapper around 'console.log'\n */\nexport class Logger {\n static #level: LogLevel = LogLevel.INFO;\n\n /**\n * Returns whether the logger is configured to allow the given log level to output.\n * @param level the level to validate\n * @returns true if the given level is equal to or higher priority then the configured level\n *\n * @example\n * Logger.setLevel(LogLevel.INFO);\n * // Returns true\n * Logger.isLevel(LogLevel.ERROR);\n * // Also returns true\n * Logger.isLevel(LogLevel.INFO);\n */\n public static isLevel(level?: LogLevel): boolean {\n return Logger.#level >= level;\n }\n\n /**\n * Returns whether the logger is configured to deny the given log level to output.\n * @param level the level to validate\n * @returns true if the given level is lower priority then the configured level\n */\n public static isNotLevel(level?: LogLevel): boolean {\n return !Logger.isLevel(level);\n }\n\n /**\n * Sets the level to allow to output\n * @param level the level to set\n */\n public static setLevel(level: LogLevel) {\n Logger.#level = level;\n }\n\n /**\n * A wrapper around console.log with color formatting and filtering by the set LogLevel.\n * @param level the LogLevel of this message\n * @param rawMessages the messages to send\n */\n public static log(level: LogLevel, ...rawMessages: any[]): void {\n if (Logger.isNotLevel(level)) return;\n\n const chalk = LEVEL_CHALK[level];\n\n const messages = sanitizeMessages(rawMessages).map((message) =>\n message instanceof Error ? message : chalk(message)\n );\n\n console.log(chalk(`[${LogLevel[level].toLowerCase()}]:`).padEnd(MAX_LENGTH, ' '), ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.ERROR}\n * @param messages the messages to send\n */\n public static error(...messages: any[]) {\n Logger.log(LogLevel.ERROR, ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.WARN}\n * @param messages the messages to send\n */\n public static warn(...messages: any[]) {\n Logger.log(LogLevel.WARN, ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.INFO}\n * @param messages the messages to send\n */\n public static info(...messages: any[]) {\n Logger.log(LogLevel.INFO, ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.SILLY}\n * @param messages the messages to send\n */\n public static silly(...messages: any[]) {\n Logger.log(LogLevel.SILLY, ...messages);\n }\n}\n","import { stringify } from './stringify';\n\nexport function sanitizeMessages(messages: any[]): any[] {\n return messages.map((message) => {\n if (message instanceof Error || typeof message !== 'object') {\n return message;\n }\n\n return stringify(message);\n });\n}\n","export function stringify(obj: any) {\n const cache = new Set();\n\n return JSON.stringify(\n obj,\n (key, value) => {\n if (typeof value === 'object' && value !== null) {\n if (cache.has(value)) {\n // Circular reference found, discard key\n return;\n }\n // Store value in our collection\n cache.add(value);\n }\n return value;\n },\n 4\n );\n}\n"],"names":["LogLevel","MAX_LENGTH","Object","keys","reduce","output","value","Math","max","length","LEVEL_CHALK","_LEVEL_CHALK","ERROR","chalk","red","WARN","yellow","INFO","cyan","SILLY","magenta","_level","_classPrivateFieldLooseKey","Logger","isLevel","level","_classPrivateFieldLooseBase","isNotLevel","setLevel","log","_console","messages","map","message","Error","obj","cache","Set","JSON","stringify","key","has","add","sanitizeMessages","slice","call","arguments","console","apply","toLowerCase","padEnd","concat","error","warn","info","silly","writable"],"mappings":"8EAGYA,iOAAAA,QAAZA,cAAA,GAAYA,EAAAA,QAAAA,WAAAA,QAAAA,SAKX,CAAA,IAJCA,EAAA,MAAA,GAAA,QACAA,EAAAA,EAAA,KAAA,GAAA,OACAA,EAAAA,EAAA,KAAA,GAAA,OACAA,EAAAA,EAAA,MAAA,GAAA,QAGW,IAAAC,EACXC,OAAOC,KAAKH,QAAQA,UAAEI,OAAO,SAACC,EAAQC,GACpC,OAAOC,KAAKC,IAAIH,EAAQC,EAAMG,OAChC,EAAG,GAAK,EAEGC,IAAWC,EAAA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IAAGmB,MAAVzB,EAAWvB,CAAAA,QAAAA,SAASY,OAAKuC,UAAAP,MAAAC,KAAAC,YAC3B,EAACvB,EAMa8B,KAAP,WACL9B,EAAOM,IAAGmB,MAAVzB,EAAM,CAAKvB,QAAQA,SAACe,MAAIoC,OAAAP,GAAAA,MAAAC,KAAAC,YAC1B,EAACvB,EAMa+B,KAAP,WACL/B,EAAOM,IAAGmB,MAAVzB,EAAWvB,CAAAA,QAAQA,SAACiB,MAAIkC,OAAA,GAAAP,MAAAC,KAAAC,YAC1B,EAACvB,EAMagC,MAAP,WACLhC,EAAOM,IAAGmB,MAAVzB,EAAM,CAAKvB,QAAAA,SAASmB,OAAKgC,OAAAP,GAAAA,MAAAC,KAAAC,YAC3B,EAACvB,CAAA,CAnFgB,yBAANA,EAAMF,EAAA,CAAAmC,UAAA,EAAAlD,MACSN,QAAAA,SAASiB"}
|
package/dist/index.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import n from"chalk";var e,t,o=0;function r(n){return"__private_"+o+++"_"+n}function c(n,e){if(!Object.prototype.hasOwnProperty.call(n,e))throw new TypeError("attempted to use private field on non-instance");return n}!function(n){n[n.ERROR=0]="ERROR",n[n.WARN=1]="WARN",n[n.INFO=2]="INFO",n[n.SILLY=3]="SILLY"}(t||(t={}));var l=Object.keys(t).reduce(function(n,e){return Math.max(n,e.length)},0)+3,i=((e={})[t.ERROR]=n.red,e[t.WARN]=n.yellow,e[t.INFO]=n.cyan,e[t.SILLY]=n.magenta,e),a=/*#__PURE__*/r("level"),u=/*#__PURE__*/function(){function n(){}return n.isLevel=function(e){return c(n,a)[a]>=e},n.isNotLevel=function(e){return!n.isLevel(e)},n.setLevel=function(e){c(n,a)[a]=e},n.log=function(e){var o;if(!n.isNotLevel(e)){var r=i[e],c=function(n){return n.map(function(n){return n instanceof Error||"object"!=typeof n?n:(e=n,t=new Set,JSON.stringify(e,function(n,e){if("object"==typeof e&&null!==e){if(t.has(e))return;t.add(e)}return e},4));var e,t})}([].slice.call(arguments,1)).map(function(n){return n instanceof Error?n:r(n)});(o=console).log.apply(o,[r("["+t[e].toLowerCase()+"]:").padEnd(l," ")].concat(c))}},n.error=function(){n.log.apply(n,[t.ERROR].concat([].slice.call(arguments)))},n.warn=function(){n.log.apply(n,[t.WARN].concat([].slice.call(arguments)))},n.info=function(){n.log.apply(n,[t.INFO].concat([].slice.call(arguments)))},n.silly=function(){n.log.apply(n,[t.SILLY].concat([].slice.call(arguments)))},n}();Object.defineProperty(u,a,{writable:!0,value:t.INFO});export{i as LEVEL_CHALK,t as LogLevel,u as Logger,l as MAX_LENGTH};
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/logger.ts","../src/utils/messages.ts","../src/utils/stringify.ts"],"sourcesContent":["import chalk, { ChalkInstance } from 'chalk';\nimport { sanitizeMessages } from './utils/messages';\n\nexport enum LogLevel {\n ERROR,\n WARN,\n INFO,\n SILLY,\n}\n\nexport const MAX_LENGTH =\n Object.keys(LogLevel).reduce((output, value) => {\n return Math.max(output, value.length);\n }, 0) + 3;\n\nexport const LEVEL_CHALK: {\n [key in LogLevel]: ChalkInstance;\n} = {\n [LogLevel.ERROR]: chalk.red,\n [LogLevel.WARN]: chalk.yellow,\n [LogLevel.INFO]: chalk.cyan,\n [LogLevel.SILLY]: chalk.magenta,\n};\n\n/**\n * A simple wrapper around 'console.log'\n */\nexport class Logger {\n static #level: LogLevel = LogLevel.INFO;\n\n /**\n * Returns whether the logger is configured to allow the given log level to output.\n * @param level the level to validate\n * @returns true if the given level is equal to or higher priority then the configured level\n *\n * @example\n * Logger.setLevel(LogLevel.INFO);\n * // Returns true\n * Logger.isLevel(LogLevel.ERROR);\n * // Also returns true\n * Logger.isLevel(LogLevel.INFO);\n */\n public static isLevel(level?: LogLevel): boolean {\n return Logger.#level >= level;\n }\n\n /**\n * Returns whether the logger is configured to deny the given log level to output.\n * @param level the level to validate\n * @returns true if the given level is lower priority then the configured level\n */\n public static isNotLevel(level?: LogLevel): boolean {\n return !Logger.isLevel(level);\n }\n\n /**\n * Sets the level to allow to output\n * @param level the level to set\n */\n public static setLevel(level: LogLevel) {\n Logger.#level = level;\n }\n\n /**\n * A wrapper around console.log with color formatting and filtering by the set LogLevel.\n * @param level the LogLevel of this message\n * @param rawMessages the messages to send\n */\n public static log(level: LogLevel, ...rawMessages: any[]): void {\n if (Logger.isNotLevel(level)) return;\n\n const chalk = LEVEL_CHALK[level];\n\n const messages = sanitizeMessages(rawMessages).map((message) =>\n message instanceof Error ? message : chalk(message)\n );\n\n console.log(chalk(`[${LogLevel[level].toLowerCase()}]:`).padEnd(MAX_LENGTH, ' '), ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.ERROR}\n * @param messages the messages to send\n */\n public static error(...messages: any[]) {\n Logger.log(LogLevel.ERROR, ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.WARN}\n * @param messages the messages to send\n */\n public static warn(...messages: any[]) {\n Logger.log(LogLevel.WARN, ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.INFO}\n * @param messages the messages to send\n */\n public static info(...messages: any[]) {\n Logger.log(LogLevel.INFO, ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.SILLY}\n * @param messages the messages to send\n */\n public static silly(...messages: any[]) {\n Logger.log(LogLevel.SILLY, ...messages);\n }\n}\n","import { stringify } from './stringify';\n\nexport function sanitizeMessages(messages: any[]): any[] {\n return messages.map((message) => {\n if (message instanceof Error || typeof message !== 'object') {\n return message;\n }\n\n return stringify(message);\n });\n}\n","export function stringify(obj: any) {\n const cache = new Set();\n\n return JSON.stringify(\n obj,\n (key, value) => {\n if (typeof value === 'object' && value !== null) {\n if (cache.has(value)) {\n // Circular reference found, discard key\n return;\n }\n // Store value in our collection\n cache.add(value);\n }\n return value;\n },\n 4\n );\n}\n"],"names":["LogLevel","MAX_LENGTH","Object","keys","reduce","output","value","Math","max","length","LEVEL_CHALK","_LEVEL_CHALK","ERROR","chalk","red","WARN","yellow","INFO","cyan","SILLY","magenta","_level","_classPrivateFieldLooseKey","Logger","isLevel","level","_classPrivateFieldLooseBase","isNotLevel","setLevel","log","_console","messages","map","message","Error","obj","cache","Set","JSON","stringify","key","has","add","sanitizeMessages","slice","call","arguments","console","apply","toLowerCase","padEnd","concat","error","warn","info","silly","writable"],"mappings":"2BAGYA,+LAAZ,SAAYA,GACVA,EAAAA,EAAA,MAAA,GAAA,QACAA,EAAAA,EAAA,KAAA,GAAA,OACAA,EAAAA,EAAA,KAAA,GAAA,OACAA,EAAAA,EAAA,MAAA,GAAA,OACD,CALD,CAAYA,IAAAA,EAKX,CAAA,IAEY,IAAAC,EACXC,OAAOC,KAAKH,GAAUI,OAAO,SAACC,EAAQC,GACpC,OAAOC,KAAKC,IAAIH,EAAQC,EAAMG,OAChC,EAAG,GAAK,EAEGC,IAAWC,EAAAA,CAAAA,GAGrBX,EAASY,OAAQC,EAAMC,IAAGH,EAC1BX,EAASe,MAAOF,EAAMG,OAAML,EAC5BX,EAASiB,MAAOJ,EAAMK,KAAIP,EAC1BX,EAASmB,OAAQN,EAAMO,QAAOT,GAC/BU,eAAAC,EAAA,SAKWC,eAAM,WAAA,SAAAA,IAAA,CAmFhB,OAnFgBA,EAeHC,QAAP,SAAeC,GACpB,OAAOC,EAAAH,EAAMF,GAAAA,IAAWI,CAC1B,EAACF,EAOaI,WAAP,SAAkBF,GACvB,OAAQF,EAAOC,QAAQC,EACzB,EAACF,EAMaK,SAAP,SAAgBH,GACrBC,EAAAH,EAAMF,GAAAA,GAAUI,CAClB,EAACF,EAOaM,IAAP,SAAWJ,GAAsC,IAAAK,EACtD,IAAIP,EAAOI,WAAWF,GAAtB,CAEA,IAAMZ,EAAQH,EAAYe,GAEpBM,ECvEM,SAAiBA,GAC/B,O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!Object.prototype.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}!function(t){t[t.ERROR=0]="ERROR",t[t.WARN=1]="WARN",t[t.INFO=2]="INFO",t[t.SILLY=3]="SILLY"}(e||(e={}));const a=Object.keys(e).reduce((t,e)=>Math.max(t,e.length),0)+3,i={[e.ERROR]:t.red,[e.WARN]:t.yellow,[e.INFO]:t.cyan,[e.SILLY]:t.magenta};var c=/*#__PURE__*/n("level");class s{static isLevel(t){return o(s,c)[c]>=t}static isNotLevel(t){return!s.isLevel(t)}static setLevel(t){o(s,c)[c]=t}static log(t,...r){if(s.isNotLevel(t))return;const n=i[t],o=function(t){return t.map(t=>t instanceof Error||"object"!=typeof t?t:function(t){const e=new Set;return JSON.stringify(t,(t,r)=>{if("object"==typeof r&&null!==r){if(e.has(r))return;e.add(r)}return r},4)}(t))}(r).map(t=>t instanceof Error?t:n(t));console.log(n(`[${e[t].toLowerCase()}]:`).padEnd(a," "),...o)}static error(...t){s.log(e.ERROR,...t)}static warn(...t){s.log(e.WARN,...t)}static info(...t){s.log(e.INFO,...t)}static silly(...t){s.log(e.SILLY,...t)}}Object.defineProperty(s,c,{writable:!0,value:e.INFO});export{i as LEVEL_CHALK,e as LogLevel,s as Logger,a as MAX_LENGTH};
|
|
2
|
-
//# sourceMappingURL=index.modern.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.mjs","sources":["../src/logger.ts","../src/utils/messages.ts","../src/utils/stringify.ts"],"sourcesContent":["import chalk, { ChalkInstance } from 'chalk';\nimport { sanitizeMessages } from './utils/messages';\n\nexport enum LogLevel {\n ERROR,\n WARN,\n INFO,\n SILLY,\n}\n\nexport const MAX_LENGTH =\n Object.keys(LogLevel).reduce((output, value) => {\n return Math.max(output, value.length);\n }, 0) + 3;\n\nexport const LEVEL_CHALK: {\n [key in LogLevel]: ChalkInstance;\n} = {\n [LogLevel.ERROR]: chalk.red,\n [LogLevel.WARN]: chalk.yellow,\n [LogLevel.INFO]: chalk.cyan,\n [LogLevel.SILLY]: chalk.magenta,\n};\n\n/**\n * A simple wrapper around 'console.log'\n */\nexport class Logger {\n static #level: LogLevel = LogLevel.INFO;\n\n /**\n * Returns whether the logger is configured to allow the given log level to output.\n * @param level the level to validate\n * @returns true if the given level is equal to or higher priority then the configured level\n *\n * @example\n * Logger.setLevel(LogLevel.INFO);\n * // Returns true\n * Logger.isLevel(LogLevel.ERROR);\n * // Also returns true\n * Logger.isLevel(LogLevel.INFO);\n */\n public static isLevel(level?: LogLevel): boolean {\n return Logger.#level >= level;\n }\n\n /**\n * Returns whether the logger is configured to deny the given log level to output.\n * @param level the level to validate\n * @returns true if the given level is lower priority then the configured level\n */\n public static isNotLevel(level?: LogLevel): boolean {\n return !Logger.isLevel(level);\n }\n\n /**\n * Sets the level to allow to output\n * @param level the level to set\n */\n public static setLevel(level: LogLevel) {\n Logger.#level = level;\n }\n\n /**\n * A wrapper around console.log with color formatting and filtering by the set LogLevel.\n * @param level the LogLevel of this message\n * @param rawMessages the messages to send\n */\n public static log(level: LogLevel, ...rawMessages: any[]): void {\n if (Logger.isNotLevel(level)) return;\n\n const chalk = LEVEL_CHALK[level];\n\n const messages = sanitizeMessages(rawMessages).map((message) =>\n message instanceof Error ? message : chalk(message)\n );\n\n console.log(chalk(`[${LogLevel[level].toLowerCase()}]:`).padEnd(MAX_LENGTH, ' '), ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.ERROR}\n * @param messages the messages to send\n */\n public static error(...messages: any[]) {\n Logger.log(LogLevel.ERROR, ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.WARN}\n * @param messages the messages to send\n */\n public static warn(...messages: any[]) {\n Logger.log(LogLevel.WARN, ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.INFO}\n * @param messages the messages to send\n */\n public static info(...messages: any[]) {\n Logger.log(LogLevel.INFO, ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.SILLY}\n * @param messages the messages to send\n */\n public static silly(...messages: any[]) {\n Logger.log(LogLevel.SILLY, ...messages);\n }\n}\n","import { stringify } from './stringify';\n\nexport function sanitizeMessages(messages: any[]): any[] {\n return messages.map((message) => {\n if (message instanceof Error || typeof message !== 'object') {\n return message;\n }\n\n return stringify(message);\n });\n}\n","export function stringify(obj: any) {\n const cache = new Set();\n\n return JSON.stringify(\n obj,\n (key, value) => {\n if (typeof value === 'object' && value !== null) {\n if (cache.has(value)) {\n // Circular reference found, discard key\n return;\n }\n // Store value in our collection\n cache.add(value);\n }\n return value;\n },\n 4\n );\n}\n"],"names":["LogLevel","MAX_LENGTH","Object","keys","reduce","output","value","Math","max","length","LEVEL_CHALK","ERROR","chalk","red","WARN","yellow","INFO","cyan","SILLY","magenta","_level","_classPrivateFieldLooseKey","Logger","isLevel","level","_classPrivateFieldLooseBase","isNotLevel","setLevel","log","rawMessages","messages","map","message","Error","obj","cache","Set","JSON","stringify","key","has","add","sanitizeMessages","console","toLowerCase","padEnd","error","warn","info","silly","writable"],"mappings":"yBAGYA,+LAAZ,SAAYA,GACVA,EAAAA,EAAA,MAAA,GAAA,QACAA,EAAAA,EAAA,KAAA,GAAA,OACAA,EAAAA,EAAA,KAAA,GAAA,OACAA,EAAAA,EAAA,MAAA,GAAA,OACD,CALD,CAAYA,IAAAA,EAKX,CAAA,IAEY,MAAAC,EACXC,OAAOC,KAAKH,GAAUI,OAAO,CAACC,EAAQC,IAC7BC,KAAKC,IAAIH,EAAQC,EAAMG,QAC7B,GAAK,EAEGC,EAET,CACF,CAACV,EAASW,OAAQC,EAAMC,IACxB,CAACb,EAASc,MAAOF,EAAMG,OACvB,CAACf,EAASgB,MAAOJ,EAAMK,KACvB,CAACjB,EAASkB,OAAQN,EAAMO,SACxB,IAAAC,eAAAC,iBAKWC,EAeJ,cAAOC,CAAQC,GACpB,OAAOC,EAAAH,EAAMF,GAAAA,IAAWI,CAC1B,CAOO,iBAAOE,CAAWF,GACvB,OAAQF,EAAOC,QAAQC,EACzB,CAMO,eAAOG,CAASH,GACrBC,EAAAH,EAAMF,GAAAA,GAAUI,CAClB,CAOO,UAAOI,CAAIJ,KAAoBK,GACpC,GAAIP,EAAOI,WAAWF,GAAQ,OAE9B,MAAMZ,EAAQF,EAAYc,GAEpBM,ECvEM,SAAiBA,GAC/B,OAAOA,EAASC,IAAKC,GACfA,aAAmBC,OAA4B,iBAAZD,EAC9BA,ECLG,SAAUE,GACxB,MAAMC,EAAQ,IAAIC,IAElB,OAAOC,KAAKC,UACVJ,EACA,CAACK,EAAKjC,KACJ,GAAqB,iBAAVA,GAAgC,OAAVA,EAAgB,CAC/C,GAAI6B,EAAMK,IAAIlC,GAEZ,OAGF6B,EAAMM,IAAInC,EACZ,CACA,OAAOA,GAET,EAEJ,CDVWgC,CAAUN,GAErB,CD+DqBU,CAAiBb,GAAaE,IAAKC,GAClDA,aAAmBC,MAAQD,EAAUpB,EAAMoB,IAG7CW,QAAQf,IAAIhB,EAAU,IAAAZ,EAASwB,GAAOoB,mBAAmBC,OAAO5C,EAAY,QAAS6B,EACvF,CAMO,YAAOgB,IAAShB,GACrBR,EAAOM,IAAI5B,EAASW,SAAUmB,EAChC,CAMO,WAAOiB,IAAQjB,GACpBR,EAAOM,IAAI5B,EAASc,QAASgB,EAC/B,CAMO,WAAOkB,IAAQlB,GACpBR,EAAOM,IAAI5B,EAASgB,QAASc,EAC/B,CAMO,YAAOmB,IAASnB,GACrBR,EAAOM,IAAI5B,EAASkB,SAAUY,EAChC,wBAnFWR,EAAMF,EAAA8B,CAAAA,YAAA5C,MACSN,EAASgB"}
|
package/dist/index.umd.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("chalk")):"function"==typeof define&&define.amd?define(["exports","chalk"],n):n((e||self).logger={},e.chalk)}(this,function(e,n){function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t,l,r=/*#__PURE__*/o(n),c=0;function i(e){return"__private_"+c+++"_"+e}function a(e,n){if(!Object.prototype.hasOwnProperty.call(e,n))throw new TypeError("attempted to use private field on non-instance");return e}e.LogLevel=void 0,(l=e.LogLevel||(e.LogLevel={}))[l.ERROR=0]="ERROR",l[l.WARN=1]="WARN",l[l.INFO=2]="INFO",l[l.SILLY=3]="SILLY";var f=Object.keys(e.LogLevel).reduce(function(e,n){return Math.max(e,n.length)},0)+3,u=((t={})[e.LogLevel.ERROR]=r.default.red,t[e.LogLevel.WARN]=r.default.yellow,t[e.LogLevel.INFO]=r.default.cyan,t[e.LogLevel.SILLY]=r.default.magenta,t),L=/*#__PURE__*/i("level"),p=/*#__PURE__*/function(){function n(){}return n.isLevel=function(e){return a(n,L)[L]>=e},n.isNotLevel=function(e){return!n.isLevel(e)},n.setLevel=function(e){a(n,L)[L]=e},n.log=function(o){var t;if(!n.isNotLevel(o)){var l=u[o],r=function(e){return e.map(function(e){return e instanceof Error||"object"!=typeof e?e:(n=e,o=new Set,JSON.stringify(n,function(e,n){if("object"==typeof n&&null!==n){if(o.has(n))return;o.add(n)}return n},4));var n,o})}([].slice.call(arguments,1)).map(function(e){return e instanceof Error?e:l(e)});(t=console).log.apply(t,[l("["+e.LogLevel[o].toLowerCase()+"]:").padEnd(f," ")].concat(r))}},n.error=function(){n.log.apply(n,[e.LogLevel.ERROR].concat([].slice.call(arguments)))},n.warn=function(){n.log.apply(n,[e.LogLevel.WARN].concat([].slice.call(arguments)))},n.info=function(){n.log.apply(n,[e.LogLevel.INFO].concat([].slice.call(arguments)))},n.silly=function(){n.log.apply(n,[e.LogLevel.SILLY].concat([].slice.call(arguments)))},n}();Object.defineProperty(p,L,{writable:!0,value:e.LogLevel.INFO}),e.LEVEL_CHALK=u,e.Logger=p,e.MAX_LENGTH=f});
|
|
2
|
-
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/logger.ts","../src/utils/messages.ts","../src/utils/stringify.ts"],"sourcesContent":["import chalk, { ChalkInstance } from 'chalk';\nimport { sanitizeMessages } from './utils/messages';\n\nexport enum LogLevel {\n ERROR,\n WARN,\n INFO,\n SILLY,\n}\n\nexport const MAX_LENGTH =\n Object.keys(LogLevel).reduce((output, value) => {\n return Math.max(output, value.length);\n }, 0) + 3;\n\nexport const LEVEL_CHALK: {\n [key in LogLevel]: ChalkInstance;\n} = {\n [LogLevel.ERROR]: chalk.red,\n [LogLevel.WARN]: chalk.yellow,\n [LogLevel.INFO]: chalk.cyan,\n [LogLevel.SILLY]: chalk.magenta,\n};\n\n/**\n * A simple wrapper around 'console.log'\n */\nexport class Logger {\n static #level: LogLevel = LogLevel.INFO;\n\n /**\n * Returns whether the logger is configured to allow the given log level to output.\n * @param level the level to validate\n * @returns true if the given level is equal to or higher priority then the configured level\n *\n * @example\n * Logger.setLevel(LogLevel.INFO);\n * // Returns true\n * Logger.isLevel(LogLevel.ERROR);\n * // Also returns true\n * Logger.isLevel(LogLevel.INFO);\n */\n public static isLevel(level?: LogLevel): boolean {\n return Logger.#level >= level;\n }\n\n /**\n * Returns whether the logger is configured to deny the given log level to output.\n * @param level the level to validate\n * @returns true if the given level is lower priority then the configured level\n */\n public static isNotLevel(level?: LogLevel): boolean {\n return !Logger.isLevel(level);\n }\n\n /**\n * Sets the level to allow to output\n * @param level the level to set\n */\n public static setLevel(level: LogLevel) {\n Logger.#level = level;\n }\n\n /**\n * A wrapper around console.log with color formatting and filtering by the set LogLevel.\n * @param level the LogLevel of this message\n * @param rawMessages the messages to send\n */\n public static log(level: LogLevel, ...rawMessages: any[]): void {\n if (Logger.isNotLevel(level)) return;\n\n const chalk = LEVEL_CHALK[level];\n\n const messages = sanitizeMessages(rawMessages).map((message) =>\n message instanceof Error ? message : chalk(message)\n );\n\n console.log(chalk(`[${LogLevel[level].toLowerCase()}]:`).padEnd(MAX_LENGTH, ' '), ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.ERROR}\n * @param messages the messages to send\n */\n public static error(...messages: any[]) {\n Logger.log(LogLevel.ERROR, ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.WARN}\n * @param messages the messages to send\n */\n public static warn(...messages: any[]) {\n Logger.log(LogLevel.WARN, ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.INFO}\n * @param messages the messages to send\n */\n public static info(...messages: any[]) {\n Logger.log(LogLevel.INFO, ...messages);\n }\n\n /**\n * A helper that automatically calls {@link Logger.log} with {@link LogLevel.SILLY}\n * @param messages the messages to send\n */\n public static silly(...messages: any[]) {\n Logger.log(LogLevel.SILLY, ...messages);\n }\n}\n","import { stringify } from './stringify';\n\nexport function sanitizeMessages(messages: any[]): any[] {\n return messages.map((message) => {\n if (message instanceof Error || typeof message !== 'object') {\n return message;\n }\n\n return stringify(message);\n });\n}\n","export function stringify(obj: any) {\n const cache = new Set();\n\n return JSON.stringify(\n obj,\n (key, value) => {\n if (typeof value === 'object' && value !== null) {\n if (cache.has(value)) {\n // Circular reference found, discard key\n return;\n }\n // Store value in our collection\n cache.add(value);\n }\n return value;\n },\n 4\n );\n}\n"],"names":["LogLevel","MAX_LENGTH","Object","keys","reduce","output","value","Math","max","length","LEVEL_CHALK","_LEVEL_CHALK","ERROR","chalk","red","WARN","yellow","INFO","cyan","SILLY","magenta","_level","_classPrivateFieldLooseKey","Logger","isLevel","level","_classPrivateFieldLooseBase","isNotLevel","setLevel","log","_console","messages","map","message","Error","obj","cache","Set","JSON","stringify","key","has","add","sanitizeMessages","slice","call","arguments","console","apply","toLowerCase","padEnd","concat","error","warn","info","silly","writable"],"mappings":"iVAGYA,kNAAAA,EAAZA,cAAA,GAAYA,EAAAA,EAAAA,WAAAA,EAAAA,SAKX,CAAA,IAJCA,EAAA,MAAA,GAAA,QACAA,EAAAA,EAAA,KAA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