@e-mc/module 0.8.12 → 0.8.13

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/LICENSE CHANGED
@@ -1,7 +1,7 @@
1
- Copyright 2024 An Pham
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
1
+ Copyright 2024 An Pham
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
7
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,242 +1,242 @@
1
- # @e-mc/module
2
-
3
- * NodeJS 14
4
- * ES2019
5
-
6
- ## General Usage
7
-
8
- * [Read the Docs](https://e-mc.readthedocs.io)
9
-
10
- ## Interface
11
-
12
- - https://www.unpkg.com/@e-mc/types@0.8.12/lib/index.d.ts
13
-
14
- ```typescript
15
- import type { LogStatus } from "./squared";
16
-
17
- import type { IHost } from "./index";
18
- import type { IAbortComponent, IPermission } from "./core";
19
- import type { LOG_TYPE, STATUS_TYPE, ExecCommand, LogArguments, LogComponent, LogDate, LogFailOptions, LogMessageOptions, LogOptions, LogProcessOptions, LogTime, LogType, LogValue, StatusType } from "./logger";
20
- import type { AsHashOptions, CheckSemVerOptions, CopyDirOptions, CopyDirResult, CopyFileOptions, CreateDirOptions, DeleteFileOptions, GetTempDirOptions, MoveFileOptions, NormalizeFlags, ParseFunctionOptions, PermissionOptions, ProtocolType, ReadBufferOptions, ReadFileCallback, ReadFileOptions, ReadHashOptions, ReadTextOptions, RemoveDirOptions, WriteFileOptions } from "./module";
21
- import type { Settings } from "./node";
22
-
23
- import type { SpawnOptions } from "child_process";
24
- import type { BinaryLike } from "crypto";
25
- import type { FileTypeResult } from "file-type";
26
- import type { NoParamCallback } from "fs";
27
-
28
- import type * as EventEmitter from "events";
29
-
30
- type BufferView = Buffer | string | NodeJS.ArrayBufferView;
31
- type CpuUsage = NodeJS.CpuUsage;
32
-
33
- interface IModule extends EventEmitter, IAbortComponent {
34
- readonly status: LogStatus<StatusType>[];
35
- readonly errors: unknown[];
36
- supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
37
- supports(name: string, value?: boolean): boolean;
38
- getTempDir(options: GetTempDirOptions): string;
39
- getTempDir(uuidDir: boolean, createDir?: boolean): string;
40
- getTempDir(pathname: string, createDir?: boolean): string;
41
- getTempDir(uuidDir: boolean, filename: string, createDir?: boolean): string;
42
- getTempDir(pathname?: string, filename?: string, createDir?: boolean): string;
43
- canRead(uri: string, options?: PermissionOptions): boolean;
44
- canWrite(uri: string, options?: PermissionOptions): boolean;
45
- readFile(src: string): Buffer | undefined;
46
- readFile(src: string, options?: ReadFileOptions): Promise<Buffer | string> | Buffer | string | undefined;
47
- readFile(src: string, promises: true): Promise<Buffer | undefined>;
48
- readFile(src: string, options: ReadFileOptions, promises: true): Promise<Buffer | string | undefined>;
49
- readFile(src: string, callback: ReadFileCallback<Buffer>): Buffer | undefined;
50
- readFile(src: string, options: ReadFileOptions, callback: ReadFileCallback<Buffer | string>): Buffer | string | undefined;
51
- writeFile(src: string, data: BufferView, options?: WriteFileOptions): boolean;
52
- writeFile(src: string, data: BufferView, promises: true): Promise<boolean>;
53
- writeFile(src: string, data: BufferView, options: WriteFileOptions, promises: true): Promise<boolean>;
54
- writeFile(src: string, data: BufferView, callback: NoParamCallback): void;
55
- writeFile(src: string, data: BufferView, options: WriteFileOptions, callback: NoParamCallback): void;
56
- deleteFile(src: string, options?: DeleteFileOptions): boolean;
57
- deleteFile(src: string, promises: true): Promise<boolean>;
58
- deleteFile(src: string, options: DeleteFileOptions, promises: true): Promise<boolean>;
59
- deleteFile(src: string, callback: NoParamCallback): void;
60
- deleteFile(src: string, options: DeleteFileOptions, callback: NoParamCallback): void;
61
- copyFile(src: string, dest: string, options?: CopyFileOptions): boolean;
62
- copyFile(src: string, dest: string, promises: true): Promise<boolean>;
63
- copyFile(src: string, dest: string, options: CopyFileOptions, promises: true): Promise<boolean>;
64
- copyFile(src: string, dest: string, callback: NoParamCallback): void;
65
- copyFile(src: string, dest: string, options: CopyFileOptions, callback: NoParamCallback): void;
66
- moveFile(src: string, dest: string, options?: MoveFileOptions): boolean;
67
- moveFile(src: string, dest: string, promises: true): Promise<boolean>;
68
- moveFile(src: string, dest: string, options: MoveFileOptions, promises: true): Promise<boolean>;
69
- moveFile(src: string, dest: string, callback: NoParamCallback): void;
70
- moveFile(src: string, dest: string, options: MoveFileOptions, callback: NoParamCallback): void;
71
- createDir(src: string, options?: CreateDirOptions): boolean;
72
- createDir(src: string, promises: true): Promise<boolean>;
73
- createDir(src: string, options: CreateDirOptions, promises: true): Promise<boolean>;
74
- createDir(src: string, callback: NoParamCallback): void;
75
- createDir(src: string, options: CreateDirOptions, callback: NoParamCallback): void;
76
- removeDir(src: string, options?: RemoveDirOptions): boolean;
77
- removeDir(src: string, promises: true): Promise<boolean>;
78
- removeDir(src: string, options: RemoveDirOptions, promises: true): Promise<boolean>;
79
- removeDir(src: string, callback: NoParamCallback): void;
80
- removeDir(src: string, options: RemoveDirOptions, callback: NoParamCallback): void;
81
- allSettled(values: readonly PromiseLike<unknown>[], rejected?: LogValue, options?: LogFailOptions | LogType): Promise<PromiseFulfilledResult<unknown>[]>;
82
- formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
83
- formatFail(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogFailOptions): void;
84
- writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
85
- writeTimeProcess(title: string, value: string, startTime: LogTime, options?: LogProcessOptions): void;
86
- writeTimeElapsed(title: string, value: LogValue, startTime: LogTime, options?: LogMessageOptions): void;
87
- checkPackage(err: unknown, name: string | undefined, options?: LogFailOptions | LogType): boolean;
88
- checkPackage(err: unknown, name: string | undefined, value?: LogValue, options?: LogFailOptions | LogType): boolean;
89
- checkFail(message: unknown, options: LogFailOptions): LogArguments | false | undefined;
90
- writeLog(component: LogComponent, queue?: boolean): void;
91
- writeLog(type: StatusType, value: unknown, options?: LogOptions): void;
92
- writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number): void;
93
- addLog(component: LogComponent, queue?: boolean): void;
94
- addLog(type: StatusType, value: unknown, from: string, source?: string): void;
95
- addLog(type: StatusType, value: unknown, options?: LogOptions): void;
96
- addLog(type: StatusType, value: unknown, timeStamp?: LogDate, from?: string, source?: string): void;
97
- addLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number, from?: string, source?: string): void;
98
- getLog(...type: StatusType[]): LogStatus<StatusType>[];
99
- flushLog(): void;
100
- willAbort(value: unknown): boolean;
101
- hasOwnPermission(): boolean;
102
- isFatal(err?: unknown): boolean;
103
- detach(): void;
104
- reset(): void;
105
- get moduleName(): string;
106
- set host(value);
107
- get host(): IHost | null;
108
- set permission(value);
109
- get permission(): IPermission | null;
110
- get aborted(): boolean;
111
- set abortable(value);
112
- get abortable(): boolean;
113
- get threadable(): boolean;
114
- set sessionId(value);
115
- get sessionId(): string;
116
- set broadcastId(value);
117
- get broadcastId(): string | string[];
118
- get logType(): LOG_TYPE;
119
- set logLevel(value: number | string);
120
- get logLevel(): number;
121
- get statusType(): STATUS_TYPE;
122
- set tempDir(value);
123
- get tempDir(): string;
124
-
125
- /* EventEmitter */
126
- on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
127
- on(event: "error", listener: (err: Error) => void): this;
128
- on(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
129
- on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
130
- on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
131
- on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
132
- on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
133
- on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
134
- on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
135
- once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
136
- once(event: "error", listener: (err: Error) => void): this;
137
- once(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
138
- once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
139
- once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
140
- once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
141
- once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
142
- once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
143
- once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
144
- emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
145
- emit(event: "error", err: Error): boolean;
146
- emit(event: "file:read", src: string, data: Buffer | string, options?: ReadFileOptions): boolean;
147
- emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
148
- emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
149
- emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
150
- emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
151
- emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
152
- emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
153
- }
154
-
155
- interface ModuleConstructor {
156
- PROCESS_TIMEOUT: number;
157
- LOG_STYLE_FAIL: LogMessageOptions;
158
- LOG_STYLE_SUCCESS: LogMessageOptions;
159
- LOG_STYLE_INFO: LogMessageOptions;
160
- LOG_STYLE_WARN: LogMessageOptions;
161
- LOG_STYLE_NOTICE: LogMessageOptions;
162
- LOG_STYLE_REVERSE: LogMessageOptions;
163
- readonly VERSION: string;
164
- readonly LOG_TYPE: LOG_TYPE;
165
- readonly STATUS_TYPE: STATUS_TYPE;
166
- readonly MAX_TIMEOUT: number;
167
- readonly TEMP_DIR: string;
168
- supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
169
- formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
170
- writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
171
- enabled(key: string, username?: string): boolean;
172
- parseFunction(value: unknown, options?: ParseFunctionOptions): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
173
- parseFunction(value: unknown, absolute: boolean, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
174
- asString(value: unknown, cacheKey?: boolean | "throws"): string;
175
- asHash(data: BinaryLike, options: AsHashOptions): string;
176
- asHash(data: BinaryLike, minLength: number): string;
177
- asHash(data: BinaryLike, algorithm?: number | string | AsHashOptions, minLength?: number | AsHashOptions): string;
178
- readHash(value: string | URL, options?: ReadHashOptions): Promise<string>;
179
- toPosix(value: unknown, normalize: boolean): string;
180
- toPosix(value: unknown, filename?: string, normalize?: boolean): string;
181
- hasLogType(value: LogType): boolean;
182
- isURL(value: string, ...exclude: string[]): boolean;
183
- isFile(value: string | URL, type?: ProtocolType): boolean;
184
- isDir(value: string | URL): boolean;
185
- isPath(value: string | URL, type?: "unc" | "unc-exists"): boolean;
186
- isPath(value: string | URL, isFile?: boolean): boolean;
187
- isErrorCode(err: unknown, ...code: string[]): boolean;
188
- fromLocalPath(value: string): string;
189
- resolveFile(value: string): string;
190
- resolvePath(value: string, base: string | URL): string;
191
- joinPath(...values: [...paths: unknown[], normalize: boolean][]): string;
192
- joinPath(...values: unknown[]): string;
193
- normalizePath(value: unknown, flags?: boolean | NormalizeFlags): string;
194
- createDir(value: string | URL, overwrite?: boolean): boolean;
195
- removeDir(value: string | URL, sinceCreated: number, recursive?: boolean): boolean;
196
- removeDir(value: string | URL, empty?: boolean, recursive?: boolean): boolean;
197
- copyDir(src: string | URL, dest: string | URL, options: CopyDirOptions): Promise<CopyDirResult>;
198
- copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
199
- renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
200
- streamFile(src: string, cache: boolean): Promise<Buffer | string>;
201
- streamFile(src: string, options: ReadBufferOptions): Promise<Buffer | string>;
202
- streamFile(src: string, cache?: boolean | ReadBufferOptions, options?: ReadBufferOptions): Promise<Buffer | string>;
203
- readText(value: string | URL, cache: boolean): string;
204
- readText(value: string | URL, options: ReadTextOptions): Promise<string> | string;
205
- readText(value: string | URL, encoding?: BufferEncoding | boolean | ReadTextOptions, cache?: boolean): string;
206
- readBuffer(value: string | URL, options: ReadBufferOptions): Promise<Buffer | null> | Buffer | null;
207
- readBuffer(value: string | URL, cache?: boolean): Buffer | null;
208
- resolveMime(data: string | Buffer | Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
209
- lookupMime(value: string, extension?: boolean): string;
210
- initCpuUsage(instance?: IModule): CpuUsage;
211
- getCpuUsage(start: CpuUsage, format: true): string;
212
- getCpuUsage(start: CpuUsage, format?: boolean): number;
213
- getMemUsage(format: true): string;
214
- getMemUsage(format?: boolean): number;
215
- formatCpuMem(start: CpuUsage, all?: boolean): string;
216
- getPackageVersion(name: string | [string, string], startDir: string, baseDir?: string): string;
217
- getPackageVersion(name: string | [string, string], unstable?: boolean, startDir?: string, baseDir?: string): string;
218
- checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
219
- checkSemVer(name: string | [string, string], min: number | string, max: number | string, options: CheckSemVerOptions): boolean;
220
- checkSemVer(name: string | [string, string], min: number | string, max?: number | string, unstable?: boolean, startDir?: string): boolean;
221
- sanitizeCmd(value: string): string;
222
- sanitizeArgs(value: string, doubleQuote?: boolean): string;
223
- sanitizeArgs(values: string[], doubleQuote?: boolean): string[];
224
- purgeMemory(percent: number, parent: boolean | number): Promise<number>;
225
- purgeMemory(percent?: number, limit?: number, parent?: boolean | number): Promise<number>;
226
- canWrite(name: "temp" | "home"): boolean;
227
- loadSettings(settings: Settings, password?: string): boolean;
228
- readonly prototype: IModule<IHost>;
229
- new(): IModule<IHost>;
230
- }
231
- ```
232
-
233
- ## References
234
-
235
- - https://www.unpkg.com/@e-mc/types@0.8.12/lib/core.d.ts
236
- - https://www.unpkg.com/@e-mc/types@0.8.12/lib/logger.d.ts
237
- - https://www.unpkg.com/@e-mc/types@0.8.12/lib/module.d.ts
238
- - https://www.unpkg.com/@e-mc/types@0.8.12/lib/node.d.ts
239
-
240
- ## LICENSE
241
-
1
+ # @e-mc/module
2
+
3
+ * NodeJS 14
4
+ * ES2019
5
+
6
+ ## General Usage
7
+
8
+ * [Read the Docs](https://e-mc.readthedocs.io)
9
+
10
+ ## Interface
11
+
12
+ - https://www.unpkg.com/@e-mc/types@0.8.13/lib/index.d.ts
13
+
14
+ ```typescript
15
+ import type { LogStatus } from "./squared";
16
+
17
+ import type { IHost } from "./index";
18
+ import type { IAbortComponent, IPermission } from "./core";
19
+ import type { LOG_TYPE, STATUS_TYPE, ExecCommand, LogArguments, LogComponent, LogDate, LogFailOptions, LogMessageOptions, LogOptions, LogProcessOptions, LogTime, LogType, LogValue, StatusType } from "./logger";
20
+ import type { AsHashOptions, CheckSemVerOptions, CopyDirOptions, CopyDirResult, CopyFileOptions, CreateDirOptions, DeleteFileOptions, GetTempDirOptions, MoveFileOptions, NormalizeFlags, ParseFunctionOptions, PermissionOptions, ProtocolType, ReadBufferOptions, ReadFileCallback, ReadFileOptions, ReadHashOptions, ReadTextOptions, RemoveDirOptions, WriteFileOptions } from "./module";
21
+ import type { Settings } from "./node";
22
+
23
+ import type { SpawnOptions } from "child_process";
24
+ import type { BinaryLike } from "crypto";
25
+ import type { FileTypeResult } from "file-type";
26
+ import type { NoParamCallback } from "fs";
27
+
28
+ import type * as EventEmitter from "events";
29
+
30
+ type BufferView = Buffer | string | NodeJS.ArrayBufferView;
31
+ type CpuUsage = NodeJS.CpuUsage;
32
+
33
+ interface IModule extends EventEmitter, IAbortComponent {
34
+ readonly status: LogStatus<StatusType>[];
35
+ readonly errors: unknown[];
36
+ supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
37
+ supports(name: string, value?: boolean): boolean;
38
+ getTempDir(options: GetTempDirOptions): string;
39
+ getTempDir(uuidDir: boolean, createDir?: boolean): string;
40
+ getTempDir(pathname: string, createDir?: boolean): string;
41
+ getTempDir(uuidDir: boolean, filename: string, createDir?: boolean): string;
42
+ getTempDir(pathname?: string, filename?: string, createDir?: boolean): string;
43
+ canRead(uri: string, options?: PermissionOptions): boolean;
44
+ canWrite(uri: string, options?: PermissionOptions): boolean;
45
+ readFile(src: string): Buffer | undefined;
46
+ readFile(src: string, options?: ReadFileOptions): Promise<Buffer | string> | Buffer | string | undefined;
47
+ readFile(src: string, promises: true): Promise<Buffer | undefined>;
48
+ readFile(src: string, options: ReadFileOptions, promises: true): Promise<Buffer | string | undefined>;
49
+ readFile(src: string, callback: ReadFileCallback<Buffer>): Buffer | undefined;
50
+ readFile(src: string, options: ReadFileOptions, callback: ReadFileCallback<Buffer | string>): Buffer | string | undefined;
51
+ writeFile(src: string, data: BufferView, options?: WriteFileOptions): boolean;
52
+ writeFile(src: string, data: BufferView, promises: true): Promise<boolean>;
53
+ writeFile(src: string, data: BufferView, options: WriteFileOptions, promises: true): Promise<boolean>;
54
+ writeFile(src: string, data: BufferView, callback: NoParamCallback): void;
55
+ writeFile(src: string, data: BufferView, options: WriteFileOptions, callback: NoParamCallback): void;
56
+ deleteFile(src: string, options?: DeleteFileOptions): boolean;
57
+ deleteFile(src: string, promises: true): Promise<boolean>;
58
+ deleteFile(src: string, options: DeleteFileOptions, promises: true): Promise<boolean>;
59
+ deleteFile(src: string, callback: NoParamCallback): void;
60
+ deleteFile(src: string, options: DeleteFileOptions, callback: NoParamCallback): void;
61
+ copyFile(src: string, dest: string, options?: CopyFileOptions): boolean;
62
+ copyFile(src: string, dest: string, promises: true): Promise<boolean>;
63
+ copyFile(src: string, dest: string, options: CopyFileOptions, promises: true): Promise<boolean>;
64
+ copyFile(src: string, dest: string, callback: NoParamCallback): void;
65
+ copyFile(src: string, dest: string, options: CopyFileOptions, callback: NoParamCallback): void;
66
+ moveFile(src: string, dest: string, options?: MoveFileOptions): boolean;
67
+ moveFile(src: string, dest: string, promises: true): Promise<boolean>;
68
+ moveFile(src: string, dest: string, options: MoveFileOptions, promises: true): Promise<boolean>;
69
+ moveFile(src: string, dest: string, callback: NoParamCallback): void;
70
+ moveFile(src: string, dest: string, options: MoveFileOptions, callback: NoParamCallback): void;
71
+ createDir(src: string, options?: CreateDirOptions): boolean;
72
+ createDir(src: string, promises: true): Promise<boolean>;
73
+ createDir(src: string, options: CreateDirOptions, promises: true): Promise<boolean>;
74
+ createDir(src: string, callback: NoParamCallback): void;
75
+ createDir(src: string, options: CreateDirOptions, callback: NoParamCallback): void;
76
+ removeDir(src: string, options?: RemoveDirOptions): boolean;
77
+ removeDir(src: string, promises: true): Promise<boolean>;
78
+ removeDir(src: string, options: RemoveDirOptions, promises: true): Promise<boolean>;
79
+ removeDir(src: string, callback: NoParamCallback): void;
80
+ removeDir(src: string, options: RemoveDirOptions, callback: NoParamCallback): void;
81
+ allSettled(values: readonly PromiseLike<unknown>[], rejected?: LogValue, options?: LogFailOptions | LogType): Promise<PromiseFulfilledResult<unknown>[]>;
82
+ formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
83
+ formatFail(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogFailOptions): void;
84
+ writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
85
+ writeTimeProcess(title: string, value: string, startTime: LogTime, options?: LogProcessOptions): void;
86
+ writeTimeElapsed(title: string, value: LogValue, startTime: LogTime, options?: LogMessageOptions): void;
87
+ checkPackage(err: unknown, name: string | undefined, options?: LogFailOptions | LogType): boolean;
88
+ checkPackage(err: unknown, name: string | undefined, value?: LogValue, options?: LogFailOptions | LogType): boolean;
89
+ checkFail(message: unknown, options: LogFailOptions): LogArguments | false | undefined;
90
+ writeLog(component: LogComponent, queue?: boolean): void;
91
+ writeLog(type: StatusType, value: unknown, options?: LogOptions): void;
92
+ writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number): void;
93
+ addLog(component: LogComponent, queue?: boolean): void;
94
+ addLog(type: StatusType, value: unknown, from: string, source?: string): void;
95
+ addLog(type: StatusType, value: unknown, options?: LogOptions): void;
96
+ addLog(type: StatusType, value: unknown, timeStamp?: LogDate, from?: string, source?: string): void;
97
+ addLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number, from?: string, source?: string): void;
98
+ getLog(...type: StatusType[]): LogStatus<StatusType>[];
99
+ flushLog(): void;
100
+ willAbort(value: unknown): boolean;
101
+ hasOwnPermission(): boolean;
102
+ isFatal(err?: unknown): boolean;
103
+ detach(): void;
104
+ reset(): void;
105
+ get moduleName(): string;
106
+ set host(value);
107
+ get host(): IHost | null;
108
+ set permission(value);
109
+ get permission(): IPermission | null;
110
+ get aborted(): boolean;
111
+ set abortable(value);
112
+ get abortable(): boolean;
113
+ get threadable(): boolean;
114
+ set sessionId(value);
115
+ get sessionId(): string;
116
+ set broadcastId(value);
117
+ get broadcastId(): string | string[];
118
+ get logType(): LOG_TYPE;
119
+ set logLevel(value: number | string);
120
+ get logLevel(): number;
121
+ get statusType(): STATUS_TYPE;
122
+ set tempDir(value);
123
+ get tempDir(): string;
124
+
125
+ /* EventEmitter */
126
+ on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
127
+ on(event: "error", listener: (err: Error) => void): this;
128
+ on(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
129
+ on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
130
+ on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
131
+ on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
132
+ on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
133
+ on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
134
+ on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
135
+ once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
136
+ once(event: "error", listener: (err: Error) => void): this;
137
+ once(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
138
+ once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
139
+ once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
140
+ once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
141
+ once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
142
+ once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
143
+ once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
144
+ emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
145
+ emit(event: "error", err: Error): boolean;
146
+ emit(event: "file:read", src: string, data: Buffer | string, options?: ReadFileOptions): boolean;
147
+ emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
148
+ emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
149
+ emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
150
+ emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
151
+ emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
152
+ emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
153
+ }
154
+
155
+ interface ModuleConstructor {
156
+ PROCESS_TIMEOUT: number;
157
+ LOG_STYLE_FAIL: LogMessageOptions;
158
+ LOG_STYLE_SUCCESS: LogMessageOptions;
159
+ LOG_STYLE_INFO: LogMessageOptions;
160
+ LOG_STYLE_WARN: LogMessageOptions;
161
+ LOG_STYLE_NOTICE: LogMessageOptions;
162
+ LOG_STYLE_REVERSE: LogMessageOptions;
163
+ readonly VERSION: string;
164
+ readonly LOG_TYPE: LOG_TYPE;
165
+ readonly STATUS_TYPE: STATUS_TYPE;
166
+ readonly MAX_TIMEOUT: number;
167
+ readonly TEMP_DIR: string;
168
+ supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
169
+ formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
170
+ writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
171
+ enabled(key: string, username?: string): boolean;
172
+ parseFunction(value: unknown, options?: ParseFunctionOptions): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
173
+ parseFunction(value: unknown, absolute: boolean, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
174
+ asString(value: unknown, cacheKey?: boolean | "throws"): string;
175
+ asHash(data: BinaryLike, options: AsHashOptions): string;
176
+ asHash(data: BinaryLike, minLength: number): string;
177
+ asHash(data: BinaryLike, algorithm?: number | string | AsHashOptions, minLength?: number | AsHashOptions): string;
178
+ readHash(value: string | URL, options?: ReadHashOptions): Promise<string>;
179
+ toPosix(value: unknown, normalize: boolean): string;
180
+ toPosix(value: unknown, filename?: string, normalize?: boolean): string;
181
+ hasLogType(value: LogType): boolean;
182
+ isURL(value: string, ...exclude: string[]): boolean;
183
+ isFile(value: string | URL, type?: ProtocolType): boolean;
184
+ isDir(value: string | URL): boolean;
185
+ isPath(value: string | URL, type?: "unc" | "unc-exists"): boolean;
186
+ isPath(value: string | URL, isFile?: boolean): boolean;
187
+ isErrorCode(err: unknown, ...code: string[]): boolean;
188
+ fromLocalPath(value: string): string;
189
+ resolveFile(value: string): string;
190
+ resolvePath(value: string, base: string | URL): string;
191
+ joinPath(...values: [...paths: unknown[], normalize: boolean][]): string;
192
+ joinPath(...values: unknown[]): string;
193
+ normalizePath(value: unknown, flags?: boolean | NormalizeFlags): string;
194
+ createDir(value: string | URL, overwrite?: boolean): boolean;
195
+ removeDir(value: string | URL, sinceCreated: number, recursive?: boolean): boolean;
196
+ removeDir(value: string | URL, empty?: boolean, recursive?: boolean): boolean;
197
+ copyDir(src: string | URL, dest: string | URL, options: CopyDirOptions): Promise<CopyDirResult>;
198
+ copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
199
+ renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
200
+ streamFile(src: string, cache: boolean): Promise<Buffer | string>;
201
+ streamFile(src: string, options: ReadBufferOptions): Promise<Buffer | string>;
202
+ streamFile(src: string, cache?: boolean | ReadBufferOptions, options?: ReadBufferOptions): Promise<Buffer | string>;
203
+ readText(value: string | URL, cache: boolean): string;
204
+ readText(value: string | URL, options: ReadTextOptions): Promise<string> | string;
205
+ readText(value: string | URL, encoding?: BufferEncoding | boolean | ReadTextOptions, cache?: boolean): string;
206
+ readBuffer(value: string | URL, options: ReadBufferOptions): Promise<Buffer | null> | Buffer | null;
207
+ readBuffer(value: string | URL, cache?: boolean): Buffer | null;
208
+ resolveMime(data: string | Buffer | Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
209
+ lookupMime(value: string, extension?: boolean): string;
210
+ initCpuUsage(instance?: IModule): CpuUsage;
211
+ getCpuUsage(start: CpuUsage, format: true): string;
212
+ getCpuUsage(start: CpuUsage, format?: boolean): number;
213
+ getMemUsage(format: true): string;
214
+ getMemUsage(format?: boolean): number;
215
+ formatCpuMem(start: CpuUsage, all?: boolean): string;
216
+ getPackageVersion(name: string | [string, string], startDir: string, baseDir?: string): string;
217
+ getPackageVersion(name: string | [string, string], unstable?: boolean, startDir?: string, baseDir?: string): string;
218
+ checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
219
+ checkSemVer(name: string | [string, string], min: number | string, max: number | string, options: CheckSemVerOptions): boolean;
220
+ checkSemVer(name: string | [string, string], min: number | string, max?: number | string, unstable?: boolean, startDir?: string): boolean;
221
+ sanitizeCmd(value: string): string;
222
+ sanitizeArgs(value: string, doubleQuote?: boolean): string;
223
+ sanitizeArgs(values: string[], doubleQuote?: boolean): string[];
224
+ purgeMemory(percent: number, parent: boolean | number): Promise<number>;
225
+ purgeMemory(percent?: number, limit?: number, parent?: boolean | number): Promise<number>;
226
+ canWrite(name: "temp" | "home"): boolean;
227
+ loadSettings(settings: Settings, password?: string): boolean;
228
+ readonly prototype: IModule<IHost>;
229
+ new(): IModule<IHost>;
230
+ }
231
+ ```
232
+
233
+ ## References
234
+
235
+ - https://www.unpkg.com/@e-mc/types@0.8.13/lib/core.d.ts
236
+ - https://www.unpkg.com/@e-mc/types@0.8.13/lib/logger.d.ts
237
+ - https://www.unpkg.com/@e-mc/types@0.8.13/lib/module.d.ts
238
+ - https://www.unpkg.com/@e-mc/types@0.8.13/lib/node.d.ts
239
+
240
+ ## LICENSE
241
+
242
242
  MIT
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { ModuleConstructor } from '../types/lib';
2
-
3
- declare const Module: ModuleConstructor;
4
-
1
+ import type { ModuleConstructor } from '../types/lib';
2
+
3
+ declare const Module: ModuleConstructor;
4
+
5
5
  export = Module;
package/index.js CHANGED
@@ -129,6 +129,25 @@ const MEMORY_CACHE_DISK = {
129
129
  exclude: null
130
130
  };
131
131
  const REGEXP_TORRENT = /^(?:magnet:\?xt=|(?:https?|s?ftp):\/\/[^/][^\n]*?\.(?:torrent|metalink|meta4)(?:\?[^\n]*)?$)/i;
132
+ const RESERVED_SHELL = [
133
+ 'if',
134
+ 'then',
135
+ 'elif',
136
+ 'else',
137
+ 'fi',
138
+ 'time',
139
+ 'for',
140
+ 'in',
141
+ 'until',
142
+ 'while',
143
+ 'do',
144
+ 'done',
145
+ 'case',
146
+ 'esac',
147
+ 'coproc',
148
+ 'select',
149
+ 'function'
150
+ ];
132
151
  let LOG_NEWLINE = true;
133
152
  let LOG_EMPTYLINE = false;
134
153
  let TEMP_DIR = path.join(PROCESS_CWD, "tmp");
@@ -688,7 +707,7 @@ class Module extends EventEmitter {
688
707
  this[_f] = new AbortController();
689
708
  this[_g] = null;
690
709
  }
691
- static get VERSION() { return "0.8.12"; }
710
+ static get VERSION() { return "0.8.13"; }
692
711
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
693
712
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
694
713
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -982,10 +1001,14 @@ class Module extends EventEmitter {
982
1001
  ({ color: hintColor, bgColor: hintBgColor } = formatHint);
983
1002
  hintBold !== null && hintBold !== void 0 ? hintBold : (hintBold = formatHint.bold);
984
1003
  }
985
- value = getValue() + (coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`);
986
- }
987
- else if (title) {
988
1004
  value = getValue();
1005
+ hint = coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`;
1006
+ }
1007
+ else {
1008
+ if (title) {
1009
+ value = getValue();
1010
+ }
1011
+ hint = '';
989
1012
  }
990
1013
  const unit = options.messageUnit ? type & 256 ? options.messageUnit.padStart(options.messageUnitMinWidth || 0) : options.messageUnit : '';
991
1014
  const getMessage = (m, u) => type & 256 && messageUnitIndent === undefined ? (u + m).trimEnd() : u ? (m + (messageUnitIndent === undefined ? ' ' : '') + u).trimStart() : m;
@@ -1030,19 +1053,19 @@ class Module extends EventEmitter {
1030
1053
  }
1031
1054
  }
1032
1055
  else {
1033
- if (!i) {
1056
+ if (!i && !hint) {
1034
1057
  v = v.trim();
1035
1058
  }
1036
1059
  m = '';
1037
1060
  }
1038
- output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (_k = (options.titleBold || formatTitle.bold)) !== null && _k !== void 0 ? _k : false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + (i ? i : ' ') + m;
1061
+ output = (titleIndent !== -1 ? title : title ? formatColumn(title, titleColor || 'green', titleBgColor, (_k = (options.titleBold || formatTitle.bold)) !== null && _k !== void 0 ? _k : false) + chalk.blackBright(':') + ' ' : '') + formatColumn(v, valueColor, valueBgColor, valueBold) + hint + (i ? i : ' ') + m;
1039
1062
  }
1040
1063
  catch {
1041
1064
  }
1042
1065
  }
1043
1066
  if (!output) {
1044
- const m = truncateStart(this.asString(message), (_l = options.messageWidth) !== null && _l !== void 0 ? _l : format.message.width);
1045
- output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + value + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
1067
+ const m = truncateStart(stripansi(this.asString(message)), (_l = options.messageWidth) !== null && _l !== void 0 ? _l : format.message.width);
1068
+ output = (titleIndent !== -1 ? title : title ? title + ': ' : '') + stripansi(value) + stripansi(hint) + (id ? id : ' ') + (m && SETTINGS.message !== false ? (error ? '{' : '(') + getMessage(m, unit) + (error ? '}' : ')') : '');
1046
1069
  }
1047
1070
  if (broadcastId) {
1048
1071
  if (BROADCAST_OUT) {
@@ -2112,6 +2135,9 @@ class Module extends EventEmitter {
2112
2135
  value = "'" + value.replace(/'/g, "'\\''") + "'";
2113
2136
  }
2114
2137
  }
2138
+ else if (RESERVED_SHELL.includes(value)) {
2139
+ value = "'" + value + "'";
2140
+ }
2115
2141
  }
2116
2142
  }
2117
2143
  else if (opt) {
package/lib-v4.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { IModuleLibV4 } from '../types/lib/compat-v4';
2
-
3
- declare const LibV4: IModuleLibV4;
4
-
1
+ import type { IModuleLibV4 } from '../types/lib/compat-v4';
2
+
3
+ declare const LibV4: IModuleLibV4;
4
+
5
5
  export = LibV4;
package/package.json CHANGED
@@ -1,33 +1,33 @@
1
- {
2
- "name": "@e-mc/module",
3
- "version": "0.8.12",
4
- "description": "Module base class for E-mc.",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/anpham6/e-mc.git",
13
- "directory": "src/module"
14
- },
15
- "keywords": [
16
- "squared",
17
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "MIT",
21
- "homepage": "https://github.com/anpham6/e-mc#readme",
22
- "dependencies": {
23
- "@e-mc/types": "0.8.12",
24
- "abort-controller": "^3.0.0",
25
- "chalk": "4.1.2",
26
- "event-target-shim": "^5.0.1",
27
- "file-type": "16.5.4",
28
- "js-yaml": "^4.1.0",
29
- "mime-types": "^2.1.35",
30
- "picomatch": "^3.0.1",
31
- "strip-ansi": "6.0.1"
32
- }
33
- }
1
+ {
2
+ "name": "@e-mc/module",
3
+ "version": "0.8.13",
4
+ "description": "Module base class for E-mc.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/anpham6/e-mc.git",
13
+ "directory": "src/module"
14
+ },
15
+ "keywords": [
16
+ "squared",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "MIT",
21
+ "homepage": "https://github.com/anpham6/e-mc#readme",
22
+ "dependencies": {
23
+ "@e-mc/types": "0.8.13",
24
+ "abort-controller": "^3.0.0",
25
+ "chalk": "4.1.2",
26
+ "event-target-shim": "^5.0.1",
27
+ "file-type": "16.5.4",
28
+ "js-yaml": "^4.1.0",
29
+ "mime-types": "^2.1.35",
30
+ "picomatch": "^3.0.1",
31
+ "strip-ansi": "6.0.1"
32
+ }
33
+ }