@holz/console-backend 0.8.2 → 0.8.3-rc.152

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r={fatal:60,error:50,warn:40,info:30,debug:20,trace:10},c=1e3,i=60*c,u=60*i,d=24*u,h=(a,s=a)=>{const t=a.getTime()-s.getTime(),e=Math.abs(t),n=t<0?"":"+";return e>=d?`${n}${Math.round(t/d)}d`:e>=u?`${n}${Math.round(t/u)}h`:e>=i?`${n}${Math.round(t/i)}m`:e>=c?`${n}${Math.round(t/c)}s`:`${n}${t}ms`},v=(a={})=>{const s=a.console??console;let t;return e=>{const n=new Date(e.timestamp),{error:l,...f}=e.context,m=[{include:!0,format:"%s",values:[e.message]},{include:Object.keys(f).length>0,format:"%o",values:[f]},{include:!0,format:"%c%s",values:["color: gray",h(n,t)]},{include:e.origin.length>0,format:"%c%s",values:["color: rgba(128, 128, 128, 0.6); font-style: italic",e.origin.join(":")]},{include:l,format:"%o",values:[l]}].filter(o=>o.include),g=m.map(o=>o.format).join(" "),$=m.flatMap(o=>o.values);s[b[e.level]](g,...$),t=n}},b={[r.trace]:"trace",[r.debug]:"debug",[r.info]:"info",[r.warn]:"warn",[r.error]:"error",[r.fatal]:"error"};exports.createConsoleBackend=v;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e={fatal:60,error:50,warn:40,info:30,debug:20,trace:10},t=(n,r)=>{let i=(e,t,i={})=>{n({timestamp:Date.now(),message:t,level:e,origin:r,context:i})},a={owner:r,trace:i.bind(null,e.trace),debug:i.bind(null,e.debug),info:i.bind(null,e.info),warn:i.bind(null,e.warn),error:i.bind(null,e.error),fatal:i.bind(null,e.fatal),namespace:e=>t(n,r.concat(e)),withMiddleware:e=>t(e(n),r)},o={configurable:!1,enumerable:!1};return Object.defineProperties(a,{withMiddleware:o,namespace:o,trace:o,debug:o,info:o,warn:o,error:o,fatal:o})},n=1e3,r=60*n,i=60*r,a=24*i,o=(e,t=e)=>{let o=e.getTime()-t.getTime(),s=Math.abs(o),c=o<0?``:`+`;return s>=a?`${c}${Math.round(o/a)}d`:s>=i?`${c}${Math.round(o/i)}h`:s>=r?`${c}${Math.round(o/r)}m`:s>=n?`${c}${Math.round(o/n)}s`:`${c}${o}ms`},s=(e={})=>{let t=e.console??console,n;return e=>{let r=new Date(e.timestamp),{error:i,...a}=e.context,s=[{include:!0,format:`%s`,values:[e.message]},{include:Object.keys(a).length>0,format:`%o`,values:[a]},{include:!0,format:`%c%s`,values:[`color: gray`,o(r,n)]},{include:e.origin.length>0,format:`%c%s`,values:[`color: rgba(128, 128, 128, 0.6); font-style: italic`,e.origin.join(`:`)]},{include:i,format:`%o`,values:[i]}].filter(e=>e.include),l=s.map(e=>e.format).join(` `),u=s.flatMap(e=>e.values);t[c[e.level]](l,...u),n=r}},c={[e.trace]:`trace`,[e.debug]:`debug`,[e.info]:`info`,[e.warn]:`warn`,[e.error]:`error`,[e.fatal]:`error`};exports.createConsoleBackend=s;
@@ -1,64 +1,86 @@
1
- const r = {
2
- /** A critical failure happened and the program must exit. */
3
- fatal: 60,
4
- /** Something failed, but we can keep going. */
5
- error: 50,
6
- /** Cause for concern, but we can keep going. */
7
- warn: 40,
8
- /** High-level progress updates. */
9
- info: 30,
10
- /** Verbose update about events or control flow (usually hidden). */
11
- debug: 20,
12
- /** Extremely detailed progress updates (usually hidden). */
13
- trace: 10
14
- }, c = 1e3, i = 60 * c, u = 60 * i, d = 24 * u, h = (a, s = a) => {
15
- const e = a.getTime() - s.getTime(), t = Math.abs(e), n = e < 0 ? "" : "+";
16
- return t >= d ? `${n}${Math.round(e / d)}d` : t >= u ? `${n}${Math.round(e / u)}h` : t >= i ? `${n}${Math.round(e / i)}m` : t >= c ? `${n}${Math.round(e / c)}s` : `${n}${e}ms`;
17
- }, p = (a = {}) => {
18
- const s = a.console ?? console;
19
- let e;
20
- return (t) => {
21
- const n = new Date(t.timestamp), { error: l, ...f } = t.context, m = [
22
- {
23
- include: !0,
24
- format: "%s",
25
- values: [t.message]
26
- },
27
- {
28
- include: Object.keys(f).length > 0,
29
- format: "%o",
30
- // Chrome hides object content with `%O`.
31
- values: [f]
32
- },
33
- {
34
- include: !0,
35
- format: "%c%s",
36
- values: ["color: gray", h(n, e)]
37
- },
38
- {
39
- include: t.origin.length > 0,
40
- format: "%c%s",
41
- values: [
42
- "color: rgba(128, 128, 128, 0.6); font-style: italic",
43
- t.origin.join(":")
44
- ]
45
- },
46
- {
47
- include: l,
48
- format: "%o",
49
- values: [l]
50
- }
51
- ].filter((o) => o.include), $ = m.map((o) => o.format).join(" "), g = m.flatMap((o) => o.values);
52
- s[v[t.level]]($, ...g), e = n;
53
- };
54
- }, v = {
55
- [r.trace]: "trace",
56
- [r.debug]: "debug",
57
- [r.info]: "info",
58
- [r.warn]: "warn",
59
- [r.error]: "error",
60
- [r.fatal]: "error"
61
- };
62
- export {
63
- p as createConsoleBackend
1
+ //#region ../holz-core/dist/holz-core.js
2
+ var e = {
3
+ fatal: 60,
4
+ error: 50,
5
+ warn: 40,
6
+ info: 30,
7
+ debug: 20,
8
+ trace: 10
9
+ }, t = (n, r) => {
10
+ let i = (e, t, i = {}) => {
11
+ n({
12
+ timestamp: Date.now(),
13
+ message: t,
14
+ level: e,
15
+ origin: r,
16
+ context: i
17
+ });
18
+ }, a = {
19
+ owner: r,
20
+ trace: i.bind(null, e.trace),
21
+ debug: i.bind(null, e.debug),
22
+ info: i.bind(null, e.info),
23
+ warn: i.bind(null, e.warn),
24
+ error: i.bind(null, e.error),
25
+ fatal: i.bind(null, e.fatal),
26
+ namespace: (e) => t(n, r.concat(e)),
27
+ withMiddleware: (e) => t(e(n), r)
28
+ }, o = {
29
+ configurable: !1,
30
+ enumerable: !1
31
+ };
32
+ return Object.defineProperties(a, {
33
+ withMiddleware: o,
34
+ namespace: o,
35
+ trace: o,
36
+ debug: o,
37
+ info: o,
38
+ warn: o,
39
+ error: o,
40
+ fatal: o
41
+ });
42
+ }, n = 1e3, r = 60 * n, i = 60 * r, a = 24 * i, o = (e, t = e) => {
43
+ let o = e.getTime() - t.getTime(), s = Math.abs(o), c = o < 0 ? "" : "+";
44
+ return s >= a ? `${c}${Math.round(o / a)}d` : s >= i ? `${c}${Math.round(o / i)}h` : s >= r ? `${c}${Math.round(o / r)}m` : s >= n ? `${c}${Math.round(o / n)}s` : `${c}${o}ms`;
45
+ }, s = (e = {}) => {
46
+ let t = e.console ?? console, n;
47
+ return (e) => {
48
+ let r = new Date(e.timestamp), { error: i, ...a } = e.context, s = [
49
+ {
50
+ include: !0,
51
+ format: "%s",
52
+ values: [e.message]
53
+ },
54
+ {
55
+ include: Object.keys(a).length > 0,
56
+ format: "%o",
57
+ values: [a]
58
+ },
59
+ {
60
+ include: !0,
61
+ format: "%c%s",
62
+ values: ["color: gray", o(r, n)]
63
+ },
64
+ {
65
+ include: e.origin.length > 0,
66
+ format: "%c%s",
67
+ values: ["color: rgba(128, 128, 128, 0.6); font-style: italic", e.origin.join(":")]
68
+ },
69
+ {
70
+ include: i,
71
+ format: "%o",
72
+ values: [i]
73
+ }
74
+ ].filter((e) => e.include), l = s.map((e) => e.format).join(" "), u = s.flatMap((e) => e.values);
75
+ t[c[e.level]](l, ...u), n = r;
76
+ };
77
+ }, c = {
78
+ [e.trace]: "trace",
79
+ [e.debug]: "debug",
80
+ [e.info]: "info",
81
+ [e.warn]: "warn",
82
+ [e.error]: "error",
83
+ [e.fatal]: "error"
64
84
  };
85
+ //#endregion
86
+ export { s as createConsoleBackend };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,22 +1,18 @@
1
- import { LogProcessor } from '@holz/core';
2
-
3
- /**
4
- * A backend that pretty-prints logs to a browser console, or any
5
- * remote-attached console.
6
- */
7
- export declare const createConsoleBackend: (options?: Options) => LogProcessor;
8
-
9
- /**
10
- * A subset of the Console interface. Must support printf-style interpolation.
11
- * @see https://console.spec.whatwg.org/#formatting-specifiers
12
- *
13
- * Note that `fatal` has no corresponding equivalent. It will be downgraded to
14
- * `error` when printed.
15
- */
16
- declare type MinimalConsole = Pick<Console, 'trace' | 'debug' | 'info' | 'warn' | 'error'>;
17
-
18
- declare interface Options {
19
- console?: MinimalConsole;
20
- }
21
-
22
- export { }
1
+ import { LogProcessor } from '@holz/core';
2
+ /**
3
+ * A backend that pretty-prints logs to a browser console, or any
4
+ * remote-attached console.
5
+ */
6
+ export declare const createConsoleBackend: (options?: Options) => LogProcessor;
7
+ interface Options {
8
+ console?: MinimalConsole;
9
+ }
10
+ /**
11
+ * A subset of the Console interface. Must support printf-style interpolation.
12
+ * @see https://console.spec.whatwg.org/#formatting-specifiers
13
+ *
14
+ * Note that `fatal` has no corresponding equivalent. It will be downgraded to
15
+ * `error` when printed.
16
+ */
17
+ export type MinimalConsole = Pick<Console, 'trace' | 'debug' | 'info' | 'warn' | 'error'>;
18
+ export {};
@@ -0,0 +1 @@
1
+ export { createConsoleBackend } from './console-backend';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Formats the difference between two dates in human-readable time.
3
+ *
4
+ * Inspired by the `ms` package. Thanks TJ.
5
+ */
6
+ export declare const timeDelta: (now: Date, then?: Date) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holz/console-backend",
3
- "version": "0.8.2",
3
+ "version": "0.8.3-rc.152+a4ea736",
4
4
  "description": "A console backend for Holz",
5
5
  "type": "module",
6
6
  "repository": {
@@ -32,21 +32,21 @@
32
32
  ],
33
33
  "scripts": {
34
34
  "prepack": "vite build",
35
- "test:unit": "vitest --color --passWithNoTests",
35
+ "test:unit": "vitest run --color --passWithNoTests",
36
36
  "test:types": "tsc"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@holz/core": "^0.8.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@holz/core": "^0.8.2",
43
- "@types/node": "^22.0.0",
44
- "@vitest/coverage-v8": "^3.0.8",
45
- "typescript": "^5.8.2",
46
- "vite": "^6.0.0",
47
- "vite-plugin-dts": "^4.5.3",
48
- "vite-tsconfig-paths": "^5.1.4",
49
- "vitest": "^3.0.8"
42
+ "@holz/core": "^0.8.3-rc.152+a4ea736",
43
+ "@types/node": "^24.0.0",
44
+ "@vitest/coverage-v8": "^4.0.0",
45
+ "typescript": "^6.0.0",
46
+ "vite": "^8.0.0",
47
+ "vite-plugin-dts": "^5.0.0",
48
+ "vite-tsconfig-paths": "^6.0.0",
49
+ "vitest": "^4.0.0"
50
50
  },
51
- "gitHead": "f099a09cd01834de9bc1714908183cbb7b828c85"
51
+ "gitHead": "a4ea7361cad7340841a12ca7c7366ffbd25eaa35"
52
52
  }