@vlandoss/loggy 0.0.5-git-18658b8.0 → 0.0.6-git-07a3bc1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vlandoss/loggy",
3
- "version": "0.0.5-git-18658b8.0",
3
+ "version": "0.0.6-git-07a3bc1.0",
4
4
  "description": "Console wrapper to make logging fun again",
5
5
  "homepage": "https://github.com/variableland/dx/tree/main/packages/loggy#readme",
6
6
  "bugs": {
@@ -14,16 +14,8 @@
14
14
  "author": "rcrd <rcrd@variable.land>",
15
15
  "type": "module",
16
16
  "exports": {
17
- ".": {
18
- "bun": "./src/index.ts",
19
- "import": "./dist/index.js",
20
- "require": "./dist/index.cjs",
21
- "default": "./dist/index.js"
22
- }
17
+ ".": "./src/index.ts"
23
18
  },
24
- "main": "./dist/index.cjs",
25
- "module": "./dist/index.js",
26
- "types": "./dist/index.d.ts",
27
19
  "files": [
28
20
  "dist",
29
21
  "src"
@@ -36,12 +28,12 @@
36
28
  },
37
29
  "dependencies": {
38
30
  "consola": "^3.4.2",
39
- "debug": "^4.4.1"
31
+ "debug": "^4.4.3"
40
32
  },
41
33
  "devDependencies": {
42
34
  "@types/debug": "^4.1.12"
43
35
  },
44
36
  "scripts": {
45
- "build": "tsup"
37
+ "test:types": "rr tsc"
46
38
  }
47
39
  }
package/dist/index.cjs DELETED
@@ -1,170 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- Loggy: () => Loggy,
34
- createLoggy: () => createLoggy
35
- });
36
- module.exports = __toCommonJS(index_exports);
37
-
38
- // src/loggy.ts
39
- var import_node_util2 = __toESM(require("util"), 1);
40
- var import_consola = require("consola");
41
- var import_utils = require("consola/utils");
42
- var import_debug = __toESM(require("debug"), 1);
43
-
44
- // src/const.ts
45
- var import_node_util = __toESM(require("util"), 1);
46
- var DEFAULT_FORMAT_OPTIONS = {
47
- colors: true,
48
- depth: 3,
49
- maxArrayLength: 50,
50
- breakLength: 80,
51
- date: false
52
- };
53
- var DEFAULT_FORMATTERS = {
54
- o: (arg) => {
55
- return import_node_util.default.inspect(arg, DEFAULT_FORMAT_OPTIONS).split("\n").map((str) => str.trim()).join(" ");
56
- },
57
- O: (arg) => {
58
- return import_node_util.default.inspect(arg, DEFAULT_FORMAT_OPTIONS);
59
- }
60
- };
61
-
62
- // src/loggy.ts
63
- function isLogFnOptions(arg) {
64
- try {
65
- return typeof arg.message === "string" && typeof arg.tag === "string";
66
- } catch {
67
- return false;
68
- }
69
- }
70
- var Loggy = class _Loggy {
71
- #options;
72
- #debug;
73
- #consola;
74
- constructor(options) {
75
- this.#options = options;
76
- this.#debug = (0, import_debug.default)(`${options.namespace}:root`);
77
- this.#consola = (0, import_consola.createConsola)({
78
- formatOptions: options.formatOptions
79
- });
80
- }
81
- get namespace() {
82
- return this.#options.namespace;
83
- }
84
- debug(...args) {
85
- this.#debug(...args);
86
- }
87
- error(...args) {
88
- this.#consola.error(this.#format(...args));
89
- }
90
- info(opts, ...args) {
91
- this.#consola.info(this.#format(opts, ...args));
92
- }
93
- trace(opts, ...args) {
94
- this.#consola.trace(this.#format(opts, ...args));
95
- }
96
- warn(opts, ...args) {
97
- this.#consola.warn(this.#format(opts, ...args));
98
- }
99
- child(options) {
100
- return new _Loggy({
101
- ...this.#options,
102
- ...options,
103
- namespace: `${this.#options.namespace}:${options.namespace}`
104
- });
105
- }
106
- start(opts, ...args) {
107
- this.#consola.start(this.#format(opts, ...args));
108
- }
109
- success(opts, ...args) {
110
- this.#consola.success(this.#format(opts, ...args));
111
- }
112
- subdebug(namespace) {
113
- return (0, import_debug.default)(`${this.#options.namespace}:${namespace}`);
114
- }
115
- #format(...args) {
116
- const [firstArg, ...restArgs] = args;
117
- const tag = isLogFnOptions(firstArg) ? firstArg.tag : this.#options.tag;
118
- const formattedArgs = isLogFnOptions(firstArg) ? [firstArg.message, ...restArgs] : args;
119
- if (typeof formattedArgs[0] !== "string") {
120
- formattedArgs.unshift("%O");
121
- }
122
- const [message, ...replacements] = formattedArgs;
123
- let replacementIndex = -1;
124
- if (typeof message !== "string") {
125
- throw new TypeError("message must be a string");
126
- }
127
- let formattedMessage = message.replace(
128
- /%([a-zA-Z%])/g,
129
- // matches %o, %O, %%, etc.
130
- (match, formatKey) => {
131
- if (formatKey === "%") {
132
- return "%";
133
- }
134
- replacementIndex++;
135
- const formatter = this.#options.formatters[formatKey];
136
- if (typeof formatter !== "function") {
137
- return match;
138
- }
139
- const replacement = replacements[replacementIndex];
140
- const formattedMatch = formatter(replacement);
141
- replacements.splice(replacementIndex, 1);
142
- replacementIndex--;
143
- return formattedMatch;
144
- }
145
- ).split("\n").join(`
146
- ${" ".repeat(2)}`);
147
- formattedMessage = !tag ? formattedMessage : `${import_utils.colors.cyan(`[${tag}]`)} ${formattedMessage}`;
148
- return import_node_util2.default.formatWithOptions(this.#options.formatOptions, formattedMessage, ...replacements);
149
- }
150
- };
151
- function createLoggy(options) {
152
- return new Loggy({
153
- namespace: options.namespace,
154
- tag: options.tag,
155
- formatOptions: {
156
- ...DEFAULT_FORMAT_OPTIONS,
157
- ...options.formatOptions
158
- },
159
- formatters: {
160
- ...DEFAULT_FORMATTERS,
161
- ...options.formatters
162
- }
163
- });
164
- }
165
- // Annotate the CommonJS export names for ESM import in node:
166
- 0 && (module.exports = {
167
- Loggy,
168
- createLoggy
169
- });
170
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/loggy.ts","../src/const.ts"],"sourcesContent":["export * from \"./loggy\";\nexport * from \"./types\";\n","import util from \"node:util\";\nimport { type ConsolaInstance, createConsola } from \"consola\";\nimport { colors } from \"consola/utils\";\nimport createDebug from \"debug\";\nimport { DEFAULT_FORMAT_OPTIONS, DEFAULT_FORMATTERS } from \"./const\";\nimport type { AnyLogger, CreateOptions, LogFnOptions, LoggerOptions } from \"./types\";\n\nfunction isLogFnOptions(arg: unknown): arg is LogFnOptions {\n try {\n // @ts-expect-error\n return typeof arg.message === \"string\" && typeof arg.tag === \"string\";\n } catch {\n return false;\n }\n}\n\nexport class Loggy implements AnyLogger {\n #options: LoggerOptions;\n #debug: ReturnType<typeof createDebug>;\n #consola: ConsolaInstance;\n\n constructor(options: LoggerOptions) {\n this.#options = options;\n this.#debug = createDebug(`${options.namespace}:root`);\n this.#consola = createConsola({\n formatOptions: options.formatOptions,\n });\n }\n\n get namespace() {\n return this.#options.namespace;\n }\n\n debug(...args: unknown[]) {\n // @ts-expect-error - it really accepts this signature\n this.#debug(...args);\n }\n\n error(...args: unknown[]) {\n this.#consola.error(this.#format(...args));\n }\n\n info(opts: LogFnOptions | unknown, ...args: unknown[]) {\n this.#consola.info(this.#format(opts, ...args));\n }\n\n trace(opts: LogFnOptions | unknown, ...args: unknown[]) {\n this.#consola.trace(this.#format(opts, ...args));\n }\n\n warn(opts: LogFnOptions | unknown, ...args: unknown[]) {\n this.#consola.warn(this.#format(opts, ...args));\n }\n\n child(options: CreateOptions) {\n return new Loggy({\n ...this.#options,\n ...options,\n namespace: `${this.#options.namespace}:${options.namespace}`,\n });\n }\n\n start(opts: LogFnOptions | unknown, ...args: unknown[]) {\n this.#consola.start(this.#format(opts, ...args));\n }\n\n success(opts: LogFnOptions | unknown, ...args: unknown[]) {\n this.#consola.success(this.#format(opts, ...args));\n }\n\n subdebug(namespace: string) {\n return createDebug(`${this.#options.namespace}:${namespace}`);\n }\n\n #format(...args: unknown[]) {\n const [firstArg, ...restArgs] = args;\n\n const tag = isLogFnOptions(firstArg) ? firstArg.tag : this.#options.tag;\n const formattedArgs = isLogFnOptions(firstArg) ? [firstArg.message, ...restArgs] : args;\n\n if (typeof formattedArgs[0] !== \"string\") {\n formattedArgs.unshift(\"%O\");\n }\n\n const [message, ...replacements] = formattedArgs;\n let replacementIndex = -1;\n\n if (typeof message !== \"string\") {\n throw new TypeError(\"message must be a string\");\n }\n\n let formattedMessage = message\n .replace(\n /%([a-zA-Z%])/g, // matches %o, %O, %%, etc.\n (match: string, formatKey: string) => {\n if (formatKey === \"%\") {\n return \"%\";\n }\n\n replacementIndex++;\n\n const formatter = this.#options.formatters[formatKey];\n\n if (typeof formatter !== \"function\") {\n return match;\n }\n\n const replacement = replacements[replacementIndex];\n const formattedMatch = formatter(replacement);\n\n replacements.splice(replacementIndex, 1);\n replacementIndex--;\n\n return formattedMatch;\n },\n )\n .split(\"\\n\")\n .join(`\\n${\" \".repeat(2)}`);\n\n formattedMessage = !tag ? formattedMessage : `${colors.cyan(`[${tag}]`)} ${formattedMessage}`;\n\n return util.formatWithOptions(this.#options.formatOptions, formattedMessage, ...replacements);\n }\n}\n\nexport function createLoggy(options: CreateOptions) {\n return new Loggy({\n namespace: options.namespace,\n tag: options.tag,\n formatOptions: {\n ...DEFAULT_FORMAT_OPTIONS,\n ...options.formatOptions,\n },\n formatters: {\n ...DEFAULT_FORMATTERS,\n ...options.formatters,\n },\n });\n}\n","import util from \"node:util\";\nimport type { FormatOptions, Formatters } from \"./types\";\n\nexport const DEFAULT_FORMAT_OPTIONS: FormatOptions = {\n colors: true,\n depth: 3,\n maxArrayLength: 50,\n breakLength: 80,\n date: false,\n};\n\nexport const DEFAULT_FORMATTERS: Formatters = {\n o: (arg: unknown) => {\n return util\n .inspect(arg, DEFAULT_FORMAT_OPTIONS)\n .split(\"\\n\")\n .map((str) => str.trim())\n .join(\" \");\n },\n O: (arg: unknown) => {\n return util.inspect(arg, DEFAULT_FORMAT_OPTIONS);\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,oBAAiB;AACjB,qBAAoD;AACpD,mBAAuB;AACvB,mBAAwB;;;ACHxB,uBAAiB;AAGV,IAAM,yBAAwC;AAAA,EACnD,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,MAAM;AACR;AAEO,IAAM,qBAAiC;AAAA,EAC5C,GAAG,CAAC,QAAiB;AACnB,WAAO,iBAAAC,QACJ,QAAQ,KAAK,sBAAsB,EACnC,MAAM,IAAI,EACV,IAAI,CAAC,QAAQ,IAAI,KAAK,CAAC,EACvB,KAAK,GAAG;AAAA,EACb;AAAA,EACA,GAAG,CAAC,QAAiB;AACnB,WAAO,iBAAAA,QAAK,QAAQ,KAAK,sBAAsB;AAAA,EACjD;AACF;;;ADfA,SAAS,eAAe,KAAmC;AACzD,MAAI;AAEF,WAAO,OAAO,IAAI,YAAY,YAAY,OAAO,IAAI,QAAQ;AAAA,EAC/D,QAAQ;AACN,WAAO;AAAA,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AAA,MACb,GAAG;AAAA,MACH,GAAG,QAAQ;AAAA,IACb;AAAA,IACA,YAAY;AAAA,MACV,GAAG;AAAA,MACH,GAAG,QAAQ;AAAA,IACb;AAAA,EACF,CAAC;AACH;","names":["import_node_util","util","createDebug","util"]}
package/dist/index.d.cts DELETED
@@ -1,52 +0,0 @@
1
- import createDebug from 'debug';
2
- import { FormatOptions } from 'consola';
3
- export { FormatOptions } from 'consola';
4
-
5
- type AnyLogFn = (...args: unknown[]) => void;
6
- type Formatters = Record<string, (arg: unknown) => string>;
7
- type AnyLogger = {
8
- namespace: string;
9
- debug: AnyLogFn;
10
- error: AnyLogFn;
11
- info: AnyLogFn;
12
- trace: AnyLogFn;
13
- warn: AnyLogFn;
14
- child: (options: CreateOptions) => AnyLogger;
15
- subdebug: (namespace: string) => AnyLogFn;
16
- start: AnyLogFn;
17
- success: AnyLogFn;
18
- };
19
- type CreateOptions = {
20
- namespace: string;
21
- tag?: string;
22
- formatOptions?: FormatOptions;
23
- formatters?: Formatters;
24
- };
25
- type LoggerOptions = {
26
- tag?: string;
27
- namespace: string;
28
- formatOptions: FormatOptions;
29
- formatters: Formatters;
30
- };
31
- type LogFnOptions = {
32
- tag: string;
33
- message: string;
34
- };
35
-
36
- declare class Loggy implements AnyLogger {
37
- #private;
38
- constructor(options: LoggerOptions);
39
- get namespace(): string;
40
- debug(...args: unknown[]): void;
41
- error(...args: unknown[]): void;
42
- info(opts: LogFnOptions | unknown, ...args: unknown[]): void;
43
- trace(opts: LogFnOptions | unknown, ...args: unknown[]): void;
44
- warn(opts: LogFnOptions | unknown, ...args: unknown[]): void;
45
- child(options: CreateOptions): Loggy;
46
- start(opts: LogFnOptions | unknown, ...args: unknown[]): void;
47
- success(opts: LogFnOptions | unknown, ...args: unknown[]): void;
48
- subdebug(namespace: string): createDebug.Debugger;
49
- }
50
- declare function createLoggy(options: CreateOptions): Loggy;
51
-
52
- export { type AnyLogFn, type AnyLogger, type CreateOptions, type Formatters, type LogFnOptions, type LoggerOptions, Loggy, createLoggy };
package/dist/index.d.ts DELETED
@@ -1,52 +0,0 @@
1
- import createDebug from 'debug';
2
- import { FormatOptions } from 'consola';
3
- export { FormatOptions } from 'consola';
4
-
5
- type AnyLogFn = (...args: unknown[]) => void;
6
- type Formatters = Record<string, (arg: unknown) => string>;
7
- type AnyLogger = {
8
- namespace: string;
9
- debug: AnyLogFn;
10
- error: AnyLogFn;
11
- info: AnyLogFn;
12
- trace: AnyLogFn;
13
- warn: AnyLogFn;
14
- child: (options: CreateOptions) => AnyLogger;
15
- subdebug: (namespace: string) => AnyLogFn;
16
- start: AnyLogFn;
17
- success: AnyLogFn;
18
- };
19
- type CreateOptions = {
20
- namespace: string;
21
- tag?: string;
22
- formatOptions?: FormatOptions;
23
- formatters?: Formatters;
24
- };
25
- type LoggerOptions = {
26
- tag?: string;
27
- namespace: string;
28
- formatOptions: FormatOptions;
29
- formatters: Formatters;
30
- };
31
- type LogFnOptions = {
32
- tag: string;
33
- message: string;
34
- };
35
-
36
- declare class Loggy implements AnyLogger {
37
- #private;
38
- constructor(options: LoggerOptions);
39
- get namespace(): string;
40
- debug(...args: unknown[]): void;
41
- error(...args: unknown[]): void;
42
- info(opts: LogFnOptions | unknown, ...args: unknown[]): void;
43
- trace(opts: LogFnOptions | unknown, ...args: unknown[]): void;
44
- warn(opts: LogFnOptions | unknown, ...args: unknown[]): void;
45
- child(options: CreateOptions): Loggy;
46
- start(opts: LogFnOptions | unknown, ...args: unknown[]): void;
47
- success(opts: LogFnOptions | unknown, ...args: unknown[]): void;
48
- subdebug(namespace: string): createDebug.Debugger;
49
- }
50
- declare function createLoggy(options: CreateOptions): Loggy;
51
-
52
- export { type AnyLogFn, type AnyLogger, type CreateOptions, type Formatters, type LogFnOptions, type LoggerOptions, Loggy, createLoggy };
package/dist/index.js DELETED
@@ -1,132 +0,0 @@
1
- // src/loggy.ts
2
- import util2 from "util";
3
- import { createConsola } from "consola";
4
- import { colors } from "consola/utils";
5
- import createDebug from "debug";
6
-
7
- // src/const.ts
8
- import util from "util";
9
- var DEFAULT_FORMAT_OPTIONS = {
10
- colors: true,
11
- depth: 3,
12
- maxArrayLength: 50,
13
- breakLength: 80,
14
- date: false
15
- };
16
- var DEFAULT_FORMATTERS = {
17
- o: (arg) => {
18
- return util.inspect(arg, DEFAULT_FORMAT_OPTIONS).split("\n").map((str) => str.trim()).join(" ");
19
- },
20
- O: (arg) => {
21
- return util.inspect(arg, DEFAULT_FORMAT_OPTIONS);
22
- }
23
- };
24
-
25
- // src/loggy.ts
26
- function isLogFnOptions(arg) {
27
- try {
28
- return typeof arg.message === "string" && typeof arg.tag === "string";
29
- } catch {
30
- return false;
31
- }
32
- }
33
- var Loggy = class _Loggy {
34
- #options;
35
- #debug;
36
- #consola;
37
- constructor(options) {
38
- this.#options = options;
39
- this.#debug = createDebug(`${options.namespace}:root`);
40
- this.#consola = createConsola({
41
- formatOptions: options.formatOptions
42
- });
43
- }
44
- get namespace() {
45
- return this.#options.namespace;
46
- }
47
- debug(...args) {
48
- this.#debug(...args);
49
- }
50
- error(...args) {
51
- this.#consola.error(this.#format(...args));
52
- }
53
- info(opts, ...args) {
54
- this.#consola.info(this.#format(opts, ...args));
55
- }
56
- trace(opts, ...args) {
57
- this.#consola.trace(this.#format(opts, ...args));
58
- }
59
- warn(opts, ...args) {
60
- this.#consola.warn(this.#format(opts, ...args));
61
- }
62
- child(options) {
63
- return new _Loggy({
64
- ...this.#options,
65
- ...options,
66
- namespace: `${this.#options.namespace}:${options.namespace}`
67
- });
68
- }
69
- start(opts, ...args) {
70
- this.#consola.start(this.#format(opts, ...args));
71
- }
72
- success(opts, ...args) {
73
- this.#consola.success(this.#format(opts, ...args));
74
- }
75
- subdebug(namespace) {
76
- return createDebug(`${this.#options.namespace}:${namespace}`);
77
- }
78
- #format(...args) {
79
- const [firstArg, ...restArgs] = args;
80
- const tag = isLogFnOptions(firstArg) ? firstArg.tag : this.#options.tag;
81
- const formattedArgs = isLogFnOptions(firstArg) ? [firstArg.message, ...restArgs] : args;
82
- if (typeof formattedArgs[0] !== "string") {
83
- formattedArgs.unshift("%O");
84
- }
85
- const [message, ...replacements] = formattedArgs;
86
- let replacementIndex = -1;
87
- if (typeof message !== "string") {
88
- throw new TypeError("message must be a string");
89
- }
90
- let formattedMessage = message.replace(
91
- /%([a-zA-Z%])/g,
92
- // matches %o, %O, %%, etc.
93
- (match, formatKey) => {
94
- if (formatKey === "%") {
95
- return "%";
96
- }
97
- replacementIndex++;
98
- const formatter = this.#options.formatters[formatKey];
99
- if (typeof formatter !== "function") {
100
- return match;
101
- }
102
- const replacement = replacements[replacementIndex];
103
- const formattedMatch = formatter(replacement);
104
- replacements.splice(replacementIndex, 1);
105
- replacementIndex--;
106
- return formattedMatch;
107
- }
108
- ).split("\n").join(`
109
- ${" ".repeat(2)}`);
110
- formattedMessage = !tag ? formattedMessage : `${colors.cyan(`[${tag}]`)} ${formattedMessage}`;
111
- return util2.formatWithOptions(this.#options.formatOptions, formattedMessage, ...replacements);
112
- }
113
- };
114
- function createLoggy(options) {
115
- return new Loggy({
116
- namespace: options.namespace,
117
- tag: options.tag,
118
- formatOptions: {
119
- ...DEFAULT_FORMAT_OPTIONS,
120
- ...options.formatOptions
121
- },
122
- formatters: {
123
- ...DEFAULT_FORMATTERS,
124
- ...options.formatters
125
- }
126
- });
127
- }
128
- export {
129
- Loggy,
130
- createLoggy
131
- };
132
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/loggy.ts","../src/const.ts"],"sourcesContent":["import util from \"node:util\";\nimport { type ConsolaInstance, createConsola } from \"consola\";\nimport { colors } from \"consola/utils\";\nimport createDebug from \"debug\";\nimport { DEFAULT_FORMAT_OPTIONS, DEFAULT_FORMATTERS } from \"./const\";\nimport type { AnyLogger, CreateOptions, LogFnOptions, LoggerOptions } from \"./types\";\n\nfunction isLogFnOptions(arg: unknown): arg is LogFnOptions {\n try {\n // @ts-expect-error\n return typeof arg.message === \"string\" && typeof arg.tag === \"string\";\n } catch {\n return false;\n }\n}\n\nexport class Loggy implements AnyLogger {\n #options: LoggerOptions;\n #debug: ReturnType<typeof createDebug>;\n #consola: ConsolaInstance;\n\n constructor(options: LoggerOptions) {\n this.#options = options;\n this.#debug = createDebug(`${options.namespace}:root`);\n this.#consola = createConsola({\n formatOptions: options.formatOptions,\n });\n }\n\n get namespace() {\n return this.#options.namespace;\n }\n\n debug(...args: unknown[]) {\n // @ts-expect-error - it really accepts this signature\n this.#debug(...args);\n }\n\n error(...args: unknown[]) {\n this.#consola.error(this.#format(...args));\n }\n\n info(opts: LogFnOptions | unknown, ...args: unknown[]) {\n this.#consola.info(this.#format(opts, ...args));\n }\n\n trace(opts: LogFnOptions | unknown, ...args: unknown[]) {\n this.#consola.trace(this.#format(opts, ...args));\n }\n\n warn(opts: LogFnOptions | unknown, ...args: unknown[]) {\n this.#consola.warn(this.#format(opts, ...args));\n }\n\n child(options: CreateOptions) {\n return new Loggy({\n ...this.#options,\n ...options,\n namespace: `${this.#options.namespace}:${options.namespace}`,\n });\n }\n\n start(opts: LogFnOptions | unknown, ...args: unknown[]) {\n this.#consola.start(this.#format(opts, ...args));\n }\n\n success(opts: LogFnOptions | unknown, ...args: unknown[]) {\n this.#consola.success(this.#format(opts, ...args));\n }\n\n subdebug(namespace: string) {\n return createDebug(`${this.#options.namespace}:${namespace}`);\n }\n\n #format(...args: unknown[]) {\n const [firstArg, ...restArgs] = args;\n\n const tag = isLogFnOptions(firstArg) ? firstArg.tag : this.#options.tag;\n const formattedArgs = isLogFnOptions(firstArg) ? [firstArg.message, ...restArgs] : args;\n\n if (typeof formattedArgs[0] !== \"string\") {\n formattedArgs.unshift(\"%O\");\n }\n\n const [message, ...replacements] = formattedArgs;\n let replacementIndex = -1;\n\n if (typeof message !== \"string\") {\n throw new TypeError(\"message must be a string\");\n }\n\n let formattedMessage = message\n .replace(\n /%([a-zA-Z%])/g, // matches %o, %O, %%, etc.\n (match: string, formatKey: string) => {\n if (formatKey === \"%\") {\n return \"%\";\n }\n\n replacementIndex++;\n\n const formatter = this.#options.formatters[formatKey];\n\n if (typeof formatter !== \"function\") {\n return match;\n }\n\n const replacement = replacements[replacementIndex];\n const formattedMatch = formatter(replacement);\n\n replacements.splice(replacementIndex, 1);\n replacementIndex--;\n\n return formattedMatch;\n },\n )\n .split(\"\\n\")\n .join(`\\n${\" \".repeat(2)}`);\n\n formattedMessage = !tag ? formattedMessage : `${colors.cyan(`[${tag}]`)} ${formattedMessage}`;\n\n return util.formatWithOptions(this.#options.formatOptions, formattedMessage, ...replacements);\n }\n}\n\nexport function createLoggy(options: CreateOptions) {\n return new Loggy({\n namespace: options.namespace,\n tag: options.tag,\n formatOptions: {\n ...DEFAULT_FORMAT_OPTIONS,\n ...options.formatOptions,\n },\n formatters: {\n ...DEFAULT_FORMATTERS,\n ...options.formatters,\n },\n });\n}\n","import util from \"node:util\";\nimport type { FormatOptions, Formatters } from \"./types\";\n\nexport const DEFAULT_FORMAT_OPTIONS: FormatOptions = {\n colors: true,\n depth: 3,\n maxArrayLength: 50,\n breakLength: 80,\n date: false,\n};\n\nexport const DEFAULT_FORMATTERS: Formatters = {\n o: (arg: unknown) => {\n return util\n .inspect(arg, DEFAULT_FORMAT_OPTIONS)\n .split(\"\\n\")\n .map((str) => str.trim())\n .join(\" \");\n },\n O: (arg: unknown) => {\n return util.inspect(arg, DEFAULT_FORMAT_OPTIONS);\n },\n};\n"],"mappings":";AAAA,OAAOA,WAAU;AACjB,SAA+B,qBAAqB;AACpD,SAAS,cAAc;AACvB,OAAO,iBAAiB;;;ACHxB,OAAO,UAAU;AAGV,IAAM,yBAAwC;AAAA,EACnD,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,MAAM;AACR;AAEO,IAAM,qBAAiC;AAAA,EAC5C,GAAG,CAAC,QAAiB;AACnB,WAAO,KACJ,QAAQ,KAAK,sBAAsB,EACnC,MAAM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