Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add 类型注释文件 #1

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ rlog.toolkit.methodName();

Toolkit是一个工具类,用于提供一些常用的工具函数。它具有以下方法:

- `checkLogFile(path, rlog)`:检查日志文件是否存在,如果不存在则创建该文件。
- `checkLogFile(path)`:检查日志文件是否存在,如果不存在则创建该文件。
- `colorizeString(str)`:根据配置的颜色规则对字符串进行着色。
- `formatTime()`:根据配置的时间格式和时区生成时间字符串。
- `encryptPrivacyContent(str)`:对字符串中的敏感内容进行加密。
Expand Down
74 changes: 74 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* rlog-js
* @license MIT
*/
declare namespace Rlog {
interface CustomColorRule {
reg: string;
color: string;
}

class Config {
enableColorfulOutput: boolean;
logFilePath?: string;
timeFormat: string;
timezone: string;
blockedWordsList: string[];
customColorRules: CustomColorRule[];
setConfig(obj?: Partial<Config>): void;
setConfigGlobal(obj?: Partial<Config>): void;
}

class Toolkit {
constructor(config: Config);
config: Config;
screen: Screen;
checkLogFile(path: string): Promise<void>;
colorizeString(str: string): string;
formatTime(): string;
encryptPrivacyContent(str: string): string;
colorizeType(variable: any): string;
padLines(str: string, width: number): string;
}

class Screen {
constructor(toolkit: Toolkit);
toolkit: Toolkit;
info(message: any, time?: string): void;
warning(message: any, time?: string): void;
error(message: any, time?: string): void;
success(message: any, time?: string): void;
exit(message: any, time?: string): void;
}

class File {
constructor(toolkit: Toolkit, config: Config, screen: Screen);
config: Config;
toolkit: Toolkit;
screen: Screen;
logStream: NodeJS.WriteStream;
init(): void;
writeLogToStream(text: string): Promise<void>;
wirteLog(text: string): void;
info(message: any, time?: string): void;
warning(message: any, time?: string): void;
error(message: any, time?: string): void;
success(message: any, time?: string): void;
exit(message: any, time?: string): void;
}
}
declare class Rlog {
constructor(config?: Rlog.Config);
config: Rlog.Config;
toolkit: Rlog.Toolkit;
screen: Screen;
file: File;
info(message: any): void;
warning(message: any): void;
error(message: any): void;
success(message: any): void;
exit(message: any): Promise<never>;
log(message: any): void;
}

export = Rlog;
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Toolkit {
config = null;
/**@type {Screen} */
screen = null;
async checkLogFile(path, rlog) {
async checkLogFile(path) {
try {
await fs.promises.access(path, fs.constants.F_OK);
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"homepage": "https://github.com/RavelloH/RLog#readme",
"dependencies": {
"@types/node": "",
"chalk": "^4.1.2",
"moment": "^2.29.4",
"moment-timezone": "^0.5.43"
Expand Down