8000 refactor(types): merge `LogTypeLiteral` and `logtype` types to `LogType` · unjs/consola@da1bc73 · GitHub
[go: up one dir, main page]

Skip to content

Commit da1bc73

Browse files
committed
refactor(types): merge LogTypeLiteral and logtype types to LogType
1 parent 6833945 commit da1bc73

File tree

2 files changed

+11
-69
lines changed

2 files changed

+11
-69
lines changed

src/consola.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
ConsolaOptions,
66
ConsolaReporter,
77
ConsolaLogObject,
8-
logType,
8+
LogType,
99
ConsolaReporterLogObject,
1010
} from "./types";
1111
import type { PromptOptions } from "./prompt";
@@ -43,8 +43,8 @@ export class Consola {
4343
// Create logger functions for current instance
4444
for (const type in types) {
4545
const defaults: ConsolaLogObject = {
46-
type: type as logType,
47-
...types[type as logType],
46+
type: type as LogType,
47+
...types[type as LogType],
4848
...this.options.defaults,
4949
};
5050
(this as any)[type] = this._wrapLogFn(defaults);
@@ -229,7 +229,7 @@ export class Consola {
229229

230230
for (const type in this.options.types) {
231231
(this as any)[type] =
232-
_mockFn(type as logType, (this as any)._types[type]) ||
232+
_mockFn(type as LogType, (this as any)._types[type]) ||
233233
(this as any)[type];
234234
(this as any)[type].raw = (this as any)[type];
235235
}
@@ -282,7 +282,7 @@ export class Consola {
282282
// Normalize type and tag to lowercase
283283
logObj.type = (
284284
typeof logObj.type === "string" ? logObj.type.toLowerCase() : ""
285-
) as logType;
285+
) as LogType;
286286
logObj.tag = typeof logObj.tag === "string" ? logObj.tag.toLowerCase() : "";
287287

288288
// Resolve log

src/types.ts

Lines changed: 6 additions & 64 deletions
52EC
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
11
import { InspectOptions } from "node:util";
22

3-
export type LogLevelLiteral =
4-
| "fatal"
5-
| "error"
6-
| "warn"
7-
| "log"
8-
| "info"
9-
| "success"
10-
| "fail"
11-
| "debug"
12-
| "trace"
13-
| "silent"
14-
| "verbose";
15-
163
export type LogLevel = number; // Built-in: 0 | 1 | 2 | 3 | 4 | 5;
174

18-
export type logType =
5+
export type LogType =
196
// 0
207
| "silent"
218
| "fatal"
@@ -35,9 +22,9 @@ export type logType =
3522
| "verbose";
3623

3724
export interface ConsolaLogObject {
38-
level?: LogLevel | LogLevelLiteral;
25+
level?: LogLevel | LogType;
3926
tag?: string;
40-
type?: logType;
27+
type?: LogType;
4128
message?: string;
4229
additional?: string | string[];
4330
args?: any[];
@@ -46,7 +33,7 @@ export interface ConsolaLogObject {
4633

4734
export interface ConsolaReporterLogObject {
4835
level: LogLevel;
49-
type: logType;
36+
type: LogType;
5037
tag: string;
5138
args: any[];
5239
date: Date;
@@ -55,7 +42,7 @@ export interface ConsolaReporterLogObject {
5542
export type ConsolaMock = (...args: any) => void;
5643

5744
export type ConsolaMockFn = (
58-
type: logType,
45+
type: LogType,
5946
defaults: ConsolaLogObject
6047
) => ConsolaMock;
6148

@@ -70,7 +57,7 @@ export interface ConsolaReporter {
7057

7158
export interface ConsolaOptions {
7259
reporters: ConsolaReporter[];
73-
types: Record<logType, ConsolaLogObject>;
60+
types: Record<LogType, ConsolaLogObject>;
7461
level: LogLevel;
7562
defaults: ConsolaLogObject;
7663
throttle: number;
@@ -84,50 +71,5 @@ export interface ConsolaOptions {
8471
export interface BasicReporterOptions {
8572
dateFormat?: string;
8673
formatOptions?: InspectOptions;
87-
}
88-
89-
export declare class BasicReporter implements ConsolaReporter {
90-
protected options: BasicReporterOptions;
91-
92-
constructor(options?: BasicReporterOptions);
93-
94-
public log(logObj: ConsolaReporterLogObject, args: ConsolaReporterArgs): void;
95-
96-
protected formatStack(stack: string): string;
97-
protected formatArgs(args: any[]): string;
98-
protected formatDate(date: Date): string;
99-
protected filterAndJoin(arr: Array<string | undefined>): string;
100-
protected formatLogObj(logObj: ConsolaReporterLogObject): string;
101-
}
102-
103-
export interface FancyReporterOptions extends BasicReporterOptions {
10474
secondaryColor?: string;
10575
}
106-
107-
export declare class FancyReporter extends BasicReporter {
108-
constructor(options?: FancyReporterOptions);
109-
110-
protected formatType(logObj: ConsolaReporterLogObject): void;
111-
}
112-
113-
export type BrowserReporterOptions = Record<string, any>;
114-
115-
export declare class BrowserReporter implements ConsolaReporter {
116-
public log(logObj: ConsolaReporterLogObject, args: ConsolaReporterArgs): void;
117-
}
118-
119-
export type JSONReporterOptions = {
120-
stream?: NodeJS.WritableStream;
121-
};
122-
123-
export declare class JSONReporter implements ConsolaReporter {
124-
constructor(options?: JSONReporterOptions);
125-
public log(logObj: ConsolaReporterLogObject, args: ConsolaReporterArgs): void;
126-
}
127-
128-
export type Winston = any;
129-
130-
export declare class WinstonReporter implements ConsolaReporter {
131-
constructor(logger?: Winston);
132-
public log(logObj: ConsolaReporterLogObject, args: ConsolaReporterArgs): void;
133-
}

0 commit comments

Comments
 (0)
0