@ribbon-studios/logger 3.0.1 → 3.1.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/dist/index.cjs +1 -1
- package/dist/index.js +27 -16
- package/dist/utils/__tests__/random.spec.d.ts +1 -0
- package/dist/utils/random.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`chalk`);c=s(c);function l(e){let t=new Set;return JSON.stringify(e,(e,n)=>{if(typeof n==`object`&&n){if(t.has(n))return;t.add(n)}return n},4)}function u(e){return e.map(e=>e instanceof Error||typeof e!=`object`?e:l(e))}
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`chalk`);c=s(c);function l(e){let t=new Set;return JSON.stringify(e,(e,n)=>{if(typeof n==`object`&&n){if(t.has(n))return;t.add(n)}return n},4)}function u(e){return e.map(e=>e instanceof Error||typeof e!=`object`?e:l(e))}function d(e,t,n){let r=2166136261;for(let t=0;t<e.length;t++)r^=e.charCodeAt(t),r=r*16777619>>>0;return t+r%(n-t+1)}var f=function(e){return e[e.ERROR=0]=`ERROR`,e[e.WARN=1]=`WARN`,e[e.INFO=2]=`INFO`,e[e.SILLY=3]=`SILLY`,e}({}),p=Object.keys(f).reduce((e,t)=>Math.max(e,t.length),0)+2,m={[f.ERROR]:c.default.red,[f.WARN]:c.default.yellow,[f.INFO]:c.default.cyan,[f.SILLY]:c.default.magenta},h=class{#e;constructor(e){this.#e={level:f.INFO,...typeof e==`string`?{scope:e}:e},this.#e.scope&&(this.prefix=c.default.rgb(d(`${this.#e.scope}:r`,0,255),d(`${this.#e.scope}:g`,0,255),d(`${this.#e.scope}:b`,0,255))(`[${this.#e.scope}]`))}isLevel(e){return e!=null&&this.#e.level>=e}isNotLevel(e){return!this.isLevel(e)}setLevel(e){this.#e.level=e}log(e,...t){if(this.isNotLevel(e))return;let n=m[e],r=u(t).map(e=>e instanceof Error?e:n(e)),i=[n(`[${f[e].toLowerCase()}]`.padStart(p,` `)),this.prefix,`:`].filter(Boolean).join(``);console.log(i,...r)}error(...e){this.log(f.ERROR,...e)}warn(...e){this.log(f.WARN,...e)}info(...e){this.log(f.INFO,...e)}silly(...e){this.log(f.SILLY,...e)}},g=new h;exports.LEVEL_CHALK=m,exports.LogLevel=f,exports.MAX_LENGTH=p,exports.RibbonLogger=h,exports.logger=g;
|
package/dist/index.js
CHANGED
|
@@ -16,21 +16,28 @@ function n(e) {
|
|
|
16
16
|
return e.map((e) => e instanceof Error || typeof e != "object" ? e : t(e));
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
|
+
//#region src/utils/random.ts
|
|
20
|
+
function r(e, t, n) {
|
|
21
|
+
let r = 2166136261;
|
|
22
|
+
for (let t = 0; t < e.length; t++) r ^= e.charCodeAt(t), r = r * 16777619 >>> 0;
|
|
23
|
+
return t + r % (n - t + 1);
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
19
26
|
//#region src/logger.ts
|
|
20
|
-
var
|
|
27
|
+
var i = /* @__PURE__ */ function(e) {
|
|
21
28
|
return e[e.ERROR = 0] = "ERROR", e[e.WARN = 1] = "WARN", e[e.INFO = 2] = "INFO", e[e.SILLY = 3] = "SILLY", e;
|
|
22
|
-
}({}),
|
|
23
|
-
[
|
|
24
|
-
[
|
|
25
|
-
[
|
|
26
|
-
[
|
|
27
|
-
},
|
|
29
|
+
}({}), a = Object.keys(i).reduce((e, t) => Math.max(e, t.length), 0) + 2, o = {
|
|
30
|
+
[i.ERROR]: e.red,
|
|
31
|
+
[i.WARN]: e.yellow,
|
|
32
|
+
[i.INFO]: e.cyan,
|
|
33
|
+
[i.SILLY]: e.magenta
|
|
34
|
+
}, s = class {
|
|
28
35
|
#e;
|
|
29
36
|
constructor(t) {
|
|
30
37
|
this.#e = {
|
|
31
|
-
level:
|
|
38
|
+
level: i.INFO,
|
|
32
39
|
...typeof t == "string" ? { scope: t } : t
|
|
33
|
-
}, this.#e.scope && (this.prefix = e.rgb(
|
|
40
|
+
}, this.#e.scope && (this.prefix = e.rgb(r(`${this.#e.scope}:r`, 0, 255), r(`${this.#e.scope}:g`, 0, 255), r(`${this.#e.scope}:b`, 0, 255))(`[${this.#e.scope}]`));
|
|
34
41
|
}
|
|
35
42
|
isLevel(e) {
|
|
36
43
|
return e != null && this.#e.level >= e;
|
|
@@ -43,21 +50,25 @@ var r = /* @__PURE__ */ function(e) {
|
|
|
43
50
|
}
|
|
44
51
|
log(e, ...t) {
|
|
45
52
|
if (this.isNotLevel(e)) return;
|
|
46
|
-
let
|
|
53
|
+
let r = o[e], s = n(t).map((e) => e instanceof Error ? e : r(e)), c = [
|
|
54
|
+
r(`[${i[e].toLowerCase()}]`.padStart(a, " ")),
|
|
55
|
+
this.prefix,
|
|
56
|
+
":"
|
|
57
|
+
].filter(Boolean).join("");
|
|
47
58
|
console.log(c, ...s);
|
|
48
59
|
}
|
|
49
60
|
error(...e) {
|
|
50
|
-
this.log(
|
|
61
|
+
this.log(i.ERROR, ...e);
|
|
51
62
|
}
|
|
52
63
|
warn(...e) {
|
|
53
|
-
this.log(
|
|
64
|
+
this.log(i.WARN, ...e);
|
|
54
65
|
}
|
|
55
66
|
info(...e) {
|
|
56
|
-
this.log(
|
|
67
|
+
this.log(i.INFO, ...e);
|
|
57
68
|
}
|
|
58
69
|
silly(...e) {
|
|
59
|
-
this.log(
|
|
70
|
+
this.log(i.SILLY, ...e);
|
|
60
71
|
}
|
|
61
|
-
},
|
|
72
|
+
}, c = new s();
|
|
62
73
|
//#endregion
|
|
63
|
-
export {
|
|
74
|
+
export { o as LEVEL_CHALK, i as LogLevel, a as MAX_LENGTH, s as RibbonLogger, c as logger };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function random(seed: string, min: number, max: number): number;
|