@e-mc/module 0.9.9 → 0.9.11

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,11 +1,11 @@
1
- Copyright 2024 An Pham
2
-
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
-
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
-
7
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
-
9
- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
-
1
+ Copyright 2024 An Pham
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
11
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,402 +1,405 @@
1
- # @e-mc/module
2
-
3
- * NodeJS 16
4
- * ES2020
5
-
6
- ## General Usage
7
-
8
- * [Read the Docs](https://e-mc.readthedocs.io)
9
-
10
- ## Interface
11
-
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.9.9/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, LoggerFormat, 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
- import type { LoggerFormatSettings } from "/settings";
23
-
24
- import type { SpawnOptions } from "child_process";
25
- import type { BinaryLike } from "crypto";
26
- import type { FileTypeResult } from "file-type";
27
- import type { NoParamCallback } from "fs";
28
-
29
- import type * as EventEmitter from "events";
30
-
31
- type BufferView = Buffer | string | NodeJS.ArrayBufferView;
32
- type CpuUsage = NodeJS.CpuUsage;
33
-
34
- interface IModule extends EventEmitter, IAbortComponent {
35
- readonly status: LogStatus<StatusType>[];
36
- readonly errors: unknown[];
37
- supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
38
- supports(name: string, value?: boolean): boolean;
39
- getTempDir(options: GetTempDirOptions): string;
40
- getTempDir(uuidDir: boolean, createDir: boolean): string;
41
- getTempDir(pathname: string, createDir: boolean): string;
42
- getTempDir(uuidDir: boolean, filename?: string, createDir?: boolean): string;
43
- getTempDir(pathname?: string, filename?: string, createDir?: boolean): string;
44
- canRead(uri: string, options?: PermissionOptions): boolean;
45
- canWrite(uri: string, options?: PermissionOptions): boolean;
46
- readFile(src: string): Buffer | undefined;
47
- readFile(src: string, options?: ReadFileOptions): Promise<Buffer | string> | Buffer | string | undefined;
48
- readFile(src: string, promises: true): Promise<Buffer | undefined>;
49
- readFile(src: string, options: ReadFileOptions, promises: true): Promise<Buffer | string | undefined>;
50
- readFile(src: string, callback: ReadFileCallback<Buffer | string>): Buffer | string | undefined;
51
- readFile(src: string, options: ReadFileOptions, callback: ReadFileCallback<Buffer | string>): Buffer | string | undefined;
52
- writeFile(src: string, data: BufferView, options?: WriteFileOptions): boolean;
53
- writeFile(src: string, data: BufferView, promises: true): Promise<boolean>;
54
- writeFile(src: string, data: BufferView, options: WriteFileOptions, promises: true): Promise<boolean>;
55
- writeFile(src: string, data: BufferView, callback: NoParamCallback): void;
56
- writeFile(src: string, data: BufferView, options: WriteFileOptions, callback: NoParamCallback): void;
57
- deleteFile(src: string, options?: DeleteFileOptions): boolean;
58
- deleteFile(src: string, promises: true): Promise<boolean>;
59
- deleteFile(src: string, options: DeleteFileOptions, promises: true): Promise<boolean>;
60
- deleteFile(src: string, callback: NoParamCallback): void;
61
- deleteFile(src: string, options: DeleteFileOptions, callback: NoParamCallback): void;
62
- copyFile(src: string, dest: string, options?: CopyFileOptions): boolean;
63
- copyFile(src: string, dest: string, promises: true): Promise<boolean>;
64
- copyFile(src: string, dest: string, options: CopyFileOptions, promises: true): Promise<boolean>;
65
- copyFile(src: string, dest: string, callback: NoParamCallback): void;
66
- copyFile(src: string, dest: string, options: CopyFileOptions, callback: NoParamCallback): void;
67
- moveFile(src: string, dest: string, options?: MoveFileOptions): boolean;
68
- moveFile(src: string, dest: string, promises: true): Promise<boolean>;
69
- moveFile(src: string, dest: string, options: MoveFileOptions, promises: true): Promise<boolean>;
70
- moveFile(src: string, dest: string, callback: NoParamCallback): void;
71
- moveFile(src: string, dest: string, options: MoveFileOptions, callback: NoParamCallback): void;
72
- createDir(src: string, options?: CreateDirOptions): boolean;
73
- createDir(src: string, promises: true): Promise<boolean>;
74
- createDir(src: string, options: CreateDirOptions, promises: true): Promise<boolean>;
75
- createDir(src: string, callback: NoParamCallback): void;
76
- createDir(src: string, options: CreateDirOptions, callback: NoParamCallback): void;
77
- removeDir(src: string, options?: RemoveDirOptions): boolean;
78
- removeDir(src: string, promises: true): Promise<boolean>;
79
- removeDir(src: string, options: RemoveDirOptions, promises: true): Promise<boolean>;
80
- removeDir(src: string, callback: NoParamCallback): void;
81
- removeDir(src: string, options: RemoveDirOptions, callback: NoParamCallback): void;
82
- allSettled(values: readonly PromiseLike<unknown>[], rejected?: LogValue, type?: LogType): Promise<PromiseFulfilledResult<unknown>[]>;
83
- allSettled(values: readonly PromiseLike<unknown>[], rejected?: LogValue, options?: LogFailOptions): Promise<PromiseFulfilledResult<unknown>[]>;
84
- formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
85
- formatFail(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogFailOptions): void;
86
- writeFail(value: LogValue, message?: unknown, type?: LogType): void;
87
- writeFail(value: LogValue, message?: unknown, options?: LogFailOptions): void;
88
- writeTimeProcess(title: string, value: string, startTime: LogTime, options?: LogProcessOptions): void;
89
- writeTimeElapsed(title: string, value: LogValue, startTime: LogTime, options?: LogMessageOptions): void;
90
- checkPackage(err: unknown, name: string | undefined, type: LogType): boolean;
91
- checkPackage(err: unknown, name: string | undefined, options: LogFailOptions): boolean;
92
- checkPackage(err: unknown, name: string | undefined, value?: LogValue, options?: LogFailOptions | LogType): boolean;
93
- checkFail(message: unknown, options: LogFailOptions): LogArguments | false | undefined;
94
- writeLog(component: LogComponent, queue?: boolean): void;
95
- writeLog(type: StatusType, value: unknown, options: LogOptions): void;
96
- writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number): void;
97
- addLog(component: LogComponent, queue?: boolean): void;
98
- addLog(type: StatusType, value: unknown, options: LogOptions): void;
99
- addLog(type: StatusType, value: unknown, from: string, source?: string): void;
100
- addLog(type: StatusType, value: unknown, timeStamp?: LogDate, from?: string, source?: string): void;
101
- addLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number, from?: string, source?: string): void;
102
- getLog(...type: StatusType[]): LogStatus<StatusType>[];
103
- flushLog(): void;
104
- willAbort(value: unknown): boolean;
105
- hasOwnPermission(): boolean;
106
- isFatal(err?: unknown): boolean;
107
- detach(): void;
108
- reset(): void;
109
- get moduleName(): string;
110
- set host(value);
111
- get host(): IHost | null;
112
- set permission(value);
113
- get permission(): IPermission | null;
114
- get aborted(): boolean;
115
- set abortable(value);
116
- get abortable(): boolean;
117
- get threadable(): boolean;
118
- set sessionId(value);
119
- get sessionId(): string;
120
- set broadcastId(value);
121
- get broadcastId(): string | string[];
122
- get logType(): LOG_TYPE;
123
- set logLevel(value: number | string);
124
- get logLevel(): number;
125
- get statusType(): STATUS_TYPE;
126
- set tempDir(value);
127
- get tempDir(): string;
128
-
129
- /* EventEmitter */
130
- on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
131
- on(event: "error", listener: (err: Error) => void): this;
132
- on(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
133
- on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
134
- on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
135
- on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
136
- on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
137
- on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
138
- on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
139
- once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
140
- once(event: "error", listener: (err: Error) => void): this;
141
- once(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
142
- once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
143
- once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
144
- once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
145
- once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
146
- once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
147
- once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
148
- emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
149
- emit(event: "error", err: Error): boolean;
150
- emit(event: "file:read", src: string, data: Buffer | string, options?: ReadFileOptions): boolean;
151
- emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
152
- emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
153
- emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
154
- emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
155
- emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
156
- emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
157
- }
158
-
159
- interface ModuleConstructor {
160
- PROCESS_TIMEOUT: number;
161
- LOG_STYLE_FAIL: LogMessageOptions;
162
- LOG_STYLE_SUCCESS: LogMessageOptions;
163
- LOG_STYLE_INFO: LogMessageOptions;
164
- LOG_STYLE_WARN: LogMessageOptions;
165
- LOG_STYLE_NOTICE: LogMessageOptions;
166
- LOG_STYLE_REVERSE: LogMessageOptions;
167
- readonly VERSION: string;
168
- readonly LOG_TYPE: LOG_TYPE;
169
- readonly LOG_FORMAT: LoggerFormatSettings<LoggerFormat<number>>;
170
- readonly STATUS_TYPE: STATUS_TYPE;
171
- readonly MAX_TIMEOUT: number;
172
- readonly TEMP_DIR: string;
173
- supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
174
- formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
175
- writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
176
- enabled(key: string, username?: string): boolean;
177
- parseFunction(value: unknown, options?: ParseFunctionOptions): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
178
- parseFunction(value: unknown, absolute: boolean, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
179
- asString(value: unknown, cacheKey?: boolean | "throws"): string;
180
- asHash(data: BinaryLike, options: AsHashOptions): string;
181
- asHash(data: BinaryLike, algorithm?: unknown, digest?: unknown): string;
182
- readHash(value: string | URL, options?: ReadHashOptions): Promise<string>;
183
- toPosix(value: unknown, normalize: boolean): string;
184
- toPosix(value: unknown, filename?: string, normalize?: boolean): string;
185
- hasLogType(value: LogType): boolean;
186
- isURL(value: string, ...exclude: string[]): boolean;
187
- isFile(value: string | URL, type?: ProtocolType): boolean;
188
- isDir(value: string | URL): boolean;
189
- isPath(value: string | URL, type?: "unc" | "unc-exists"): boolean;
190
- isPath(value: string | URL, isFile?: boolean): boolean;
191
- isErrorCode(err: unknown, ...code: string[]): boolean;
192
- fromLocalPath(value: string): string;
193
- resolveFile(value: string): string;
194
- resolvePath(value: string, base: string | URL): string;
195
- joinPath(...values: [...paths: unknown[], normalize: boolean][]): string;
196
- joinPath(...values: unknown[]): string;
197
- normalizePath(value: unknown, flags?: boolean | NormalizeFlags): string;
198
- createDir(value: string | URL, overwrite?: boolean): boolean;
199
- removeDir(value: string | URL, sinceCreated: number, recursive?: boolean): boolean;
200
- removeDir(value: string | URL, empty?: boolean, recursive?: boolean): boolean;
201
- copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
202
- copyDir(src: string | URL, dest: string | URL, options?: CopyDirOptions): Promise<CopyDirResult>;
203
- renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
204
- streamFile(src: string, cache: boolean): Promise<Buffer | string>;
205
- streamFile(src: string, options: ReadBufferOptions): Promise<Buffer | string>;
206
- streamFile(src: string, cache?: boolean | ReadBufferOptions, options?: ReadBufferOptions): Promise<Buffer | string>;
207
- readText(value: string | URL, cache: boolean): string;
208
- readText(value: string | URL, options: ReadTextOptions): Promise<string> | string;
209
- readText(value: string | URL, encoding?: BufferEncoding | ReadTextOptions, cache?: boolean): string;
210
- readBuffer(value: string | URL, options: ReadBufferOptions): Promise<Buffer | null> | Buffer | null;
211
- readBuffer(value: string | URL, cache?: boolean | ReadBufferOptions): Buffer | null;
212
- resolveMime(data: string | Buffer | Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
213
- lookupMime(value: string, extension?: boolean): string;
214
- initCpuUsage(instance?: IModule): CpuUsage;
215
- getCpuUsage(start: CpuUsage, format: true): string;
216
- getCpuUsage(start: CpuUsage, format?: boolean): number;
217
- getMemUsage(format: true): string;
218
- getMemUsage(format?: boolean): number;
219
- formatCpuMem(start: CpuUsage, all?: boolean): string;
220
- getPackageVersion(name: string | [string, string], startDir: string, baseDir?: string): string;
221
- getPackageVersion(name: string | [string, string], unstable?: boolean, startDir?: string, baseDir?: string): string;
222
- checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
223
- checkSemVer(name: string | [string, string], min: number | string, max?: number | string, unstable?: boolean, startDir?: string): boolean;
224
- checkSemVer(name: string | [string, string], min: number | string, max: number | string, options?: CheckSemVerOptions): boolean;
225
- sanitizeCmd(value: string): string;
226
- sanitizeArgs(value: string, doubleQuote?: boolean): string;
227
- sanitizeArgs(values: string[], doubleQuote?: boolean): string[];
228
- purgeMemory(percent: number, parent: boolean): Promise<number>;
229
- purgeMemory(percent: number, limit: number, parent?: boolean): Promise<number>;
230
- purgeMemory(percent?: number, limit?: number | boolean, parent?: unknown): Promise<number>;
231
- canWrite(name: "temp" | "home"): boolean;
232
- loadSettings(settings: Settings, password?: string): boolean;
233
- readonly prototype: IModule<IHost>;
234
- new(): IModule<IHost>;
235
- }
236
- ```
237
-
238
- ## Settings
239
-
240
- ```typescript
241
- import type { LogMessageOptions, LogTypeValue, LoggerStatus } from "./logger";
242
- import type { LoggerProcessSettings } from "./settings";
243
-
244
- import type { BackgroundColor as IBackgroundColor, ForegroundColor as IForegroundColor } from "chalk";
245
- import type { BinaryLike, CipherGCMTypes } from "crypto";
246
- import type { SecureVersion } from "tls";
247
-
248
- interface NodeModule {
249
- process?: {
250
- cpu_usage?: boolean;
251
- memory_usage?: boolean;
252
- inline?: boolean;
253
- };
254
- require?: {
255
- ext?: string | string[] | boolean;
256
- npm?: boolean;
257
- inline?: boolean;
258
- };
259
- }
260
-
261
- interface ProcessModule {
262
- env?: {
263
- apply?: boolean;
264
- };
265
- cipher?: {
266
- algorithm?: CipherGCMTypes;
267
- key?: BinaryLike;
268
- iv?: BinaryLike;
269
- };
270
- password?: string;
271
- }
272
-
273
- interface MemoryModule {
274
- settings?: {
275
- users?: boolean | string[];
276
- cache_disk?: {
277
- enabled?: boolean;
278
- min_size?: number | string;
279
- max_size?: number | string;
280
- include?: string[];
281
- exclude?: string[];
282
- expires?: number | string;
283
- };
284
- };
285
- }
286
-
287
- interface PermissionModule {
288
- home_read?: boolean;
289
- home_write?: boolean;
290
- process_exec?: (string | ExecOptions)[];
291
- }
292
-
293
- interface ErrorModule {
294
- out?: string | (err: Error, data: LogTypeValue, require?: NodeRequire) => void;
295
- fatal?: boolean;
296
- }
297
-
298
- interface TempModule {
299
- dir?: string;
300
- write?: boolean;
301
- }
302
-
303
- interface LoggerModule {
304
- enabled?: boolean;
305
- level?: number,
306
- production?: string[];
307
- format?: {
308
- title?: {
309
- width?: number;
310
- color?: ForegroundColor;
311
- bg_color?: BackgroundColor;
312
- bold?: boolean;
313
- justify?: "left" | "center" | "right";
314
- as?: StringMap;
315
- };
316
- value?: {
317
- width?: number;
318
- color?: ForegroundColor;
319
- bg_color?: BackgroundColor;
320
- bold?: boolean;
321
- justify?: "left" | "center" | "right";
322
- },
323
- hint?: {
324
- width?: number;
325
- color?: ForegroundColor;
326
- bg_color?: BackgroundColor;
327
- bold?: boolean;
328
- as?: StringMap;
329
- unit?: "auto" | "s" | "ms";
330
- };
331
- message?: {
332
- width?: number;
333
- color?: ForegroundColor;
334
- bg_color?: BackgroundColor;
335
- bold?: boolean;
336
- };
337
- meter?: {
338
- color?: ForegroundColor;
339
- bg_color?: BackgroundColor;
340
- bg_alt_color?: BackgroundColor;
341
- bold?: boolean;
342
- };
343
- };
344
- meter?: {
345
- http?: number;
346
- image?: number;
347
- compress?: number;
348
- process?: number;
349
- };
350
- broadcast?: {
351
- enabled?: boolean;
352
- out?: string | (value: string, options: LogMessageOptions, require?: NodeRequire) => void;
353
- color?: boolean;
354
- port?: number | number[];
355
- secure?: {
356
- port?: number | number[];
357
- ca?: string;
358
- key?: string;
359
- cert?: string;
360
- version?: SecureVersion
361
- };
362
- };
363
- color?: boolean;
364
- message?: boolean;
365
- stdout?: boolean;
366
- abort?: boolean;
367
- status?: boolean | LoggerStatus;
368
- unknown?: boolean | LoggerColor;
369
- system?: boolean | LoggerColor;
370
- process?: boolean | LoggerProcessSettings;
371
- image?: boolean | LoggerColor;
372
- compress?: boolean | LoggerColor;
373
- watch?: boolean | LoggerColor;
374
- file?: boolean | LoggerColor;
375
- cloud?: boolean | LoggerColor;
376
- db?: boolean | LoggerColor;
377
- time_elapsed?: boolean | LoggerColor;
378
- time_process?: boolean | LoggerColor;
379
- exec?: boolean | LoggerColor;
380
- http?: boolean | LoggerColor;
381
- node?: boolean | LoggerColor;
382
- session_id?: boolean | number;
383
- stack_trace?: boolean | number;
384
- }
385
-
386
- type BackgroundColor = typeof IBackgroundColor | `#${string}`;
387
- type ForegroundColor = typeof IForegroundColor | `#${string}`;
388
- ```
389
-
390
- ## References
391
-
392
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/core.d.ts
393
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/logger.d.ts
394
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/module.d.ts
395
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/node.d.ts
396
- - https://www.unpkg.com/@e-mc/types@0.9.9/lib/settings.d.ts
397
-
398
- * https://www.npmjs.com/package/@types/node
399
-
400
- ## LICENSE
401
-
1
+ # @e-mc/module
2
+
3
+ * NodeJS 16
4
+ * ES2020
5
+
6
+ ## General Usage
7
+
8
+ * [Read the Docs](https://e-mc.readthedocs.io)
9
+
10
+ ## Interface
11
+
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.9.11/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, LoggerFormat, 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
+ import type { LoggerFormatSettings } from "/settings";
23
+
24
+ import type { SpawnOptions } from "child_process";
25
+ import type { BinaryLike } from "crypto";
26
+ import type { FileTypeResult } from "file-type";
27
+ import type { NoParamCallback } from "fs";
28
+
29
+ import type * as EventEmitter from "events";
30
+
31
+ type BufferView = Buffer | string | NodeJS.ArrayBufferView;
32
+ type CpuUsage = NodeJS.CpuUsage;
33
+
34
+ interface IModule extends EventEmitter, IAbortComponent {
35
+ readonly status: LogStatus<StatusType>[];
36
+ readonly errors: unknown[];
37
+ supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
38
+ supports(name: string, value?: boolean): boolean;
39
+ getTempDir(options: GetTempDirOptions): string;
40
+ getTempDir(uuidDir: boolean, createDir: boolean): string;
41
+ getTempDir(pathname: string, createDir: boolean): string;
42
+ getTempDir(uuidDir: boolean, filename?: string, createDir?: boolean): string;
43
+ getTempDir(pathname?: string, filename?: string, createDir?: boolean): string;
44
+ canRead(uri: string, options?: PermissionOptions): boolean;
45
+ canWrite(uri: string, options?: PermissionOptions): boolean;
46
+ readFile(src: string): Buffer | undefined;
47
+ readFile(src: string, options?: ReadFileOptions): Promise<Buffer | string> | Buffer | string | undefined;
48
+ readFile(src: string, promises: true): Promise<Buffer | undefined>;
49
+ readFile(src: string, options: ReadFileOptions, promises: true): Promise<Buffer | string | undefined>;
50
+ readFile(src: string, callback: ReadFileCallback<Buffer | string>): Buffer | string | undefined;
51
+ readFile(src: string, options: ReadFileOptions, callback: ReadFileCallback<Buffer | string>): Buffer | string | undefined;
52
+ writeFile(src: string, data: BufferView, options?: WriteFileOptions): boolean;
53
+ writeFile(src: string, data: BufferView, promises: true): Promise<boolean>;
54
+ writeFile(src: string, data: BufferView, options: WriteFileOptions, promises: true): Promise<boolean>;
55
+ writeFile(src: string, data: BufferView, callback: NoParamCallback): void;
56
+ writeFile(src: string, data: BufferView, options: WriteFileOptions, callback: NoParamCallback): void;
57
+ deleteFile(src: string, options?: DeleteFileOptions): boolean;
58
+ deleteFile(src: string, promises: true): Promise<boolean>;
59
+ deleteFile(src: string, options: DeleteFileOptions, promises: true): Promise<boolean>;
60
+ deleteFile(src: string, callback: NoParamCallback): void;
61
+ deleteFile(src: string, options: DeleteFileOptions, callback: NoParamCallback): void;
62
+ copyFile(src: string, dest: string, options?: CopyFileOptions): boolean;
63
+ copyFile(src: string, dest: string, promises: true): Promise<boolean>;
64
+ copyFile(src: string, dest: string, options: CopyFileOptions, promises: true): Promise<boolean>;
65
+ copyFile(src: string, dest: string, callback: NoParamCallback): void;
66
+ copyFile(src: string, dest: string, options: CopyFileOptions, callback: NoParamCallback): void;
67
+ moveFile(src: string, dest: string, options?: MoveFileOptions): boolean;
68
+ moveFile(src: string, dest: string, promises: true): Promise<boolean>;
69
+ moveFile(src: string, dest: string, options: MoveFileOptions, promises: true): Promise<boolean>;
70
+ moveFile(src: string, dest: string, callback: NoParamCallback): void;
71
+ moveFile(src: string, dest: string, options: MoveFileOptions, callback: NoParamCallback): void;
72
+ createDir(src: string, options?: CreateDirOptions): boolean;
73
+ createDir(src: string, promises: true): Promise<boolean>;
74
+ createDir(src: string, options: CreateDirOptions, promises: true): Promise<boolean>;
75
+ createDir(src: string, callback: NoParamCallback): void;
76
+ createDir(src: string, options: CreateDirOptions, callback: NoParamCallback): void;
77
+ removeDir(src: string, options?: RemoveDirOptions): boolean;
78
+ removeDir(src: string, promises: true): Promise<boolean>;
79
+ removeDir(src: string, options: RemoveDirOptions, promises: true): Promise<boolean>;
80
+ removeDir(src: string, callback: NoParamCallback): void;
81
+ removeDir(src: string, options: RemoveDirOptions, callback: NoParamCallback): void;
82
+ allSettled(values: readonly PromiseLike<unknown>[], rejected?: LogValue, type?: LogType): Promise<PromiseFulfilledResult<unknown>[]>;
83
+ allSettled(values: readonly PromiseLike<unknown>[], rejected?: LogValue, options?: LogFailOptions): Promise<PromiseFulfilledResult<unknown>[]>;
84
+ formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
85
+ formatFail(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogFailOptions): void;
86
+ writeFail(value: LogValue, message?: unknown, type?: LogType): void;
87
+ writeFail(value: LogValue, message?: unknown, options?: LogFailOptions): void;
88
+ writeTimeProcess(title: string, value: string, startTime: LogTime, options?: LogProcessOptions): void;
89
+ writeTimeElapsed(title: string, value: LogValue, startTime: LogTime, options?: LogMessageOptions): void;
90
+ checkPackage(err: unknown, name: string | undefined, type: LogType): boolean;
91
+ checkPackage(err: unknown, name: string | undefined, options: LogFailOptions): boolean;
92
+ checkPackage(err: unknown, name: string | undefined, value?: LogValue, options?: LogFailOptions | LogType): boolean;
93
+ checkFail(message: unknown, options: LogFailOptions): LogArguments | false | undefined;
94
+ writeLog(component: LogComponent, queue?: boolean): void;
95
+ writeLog(type: StatusType, value: unknown, options: LogOptions): void;
96
+ writeLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number): void;
97
+ addLog(component: LogComponent, queue?: boolean): void;
98
+ addLog(type: StatusType, value: unknown, options: LogOptions): void;
99
+ addLog(type: StatusType, value: unknown, from: string, source?: string): void;
100
+ addLog(type: StatusType, value: unknown, timeStamp?: LogDate, from?: string, source?: string): void;
101
+ addLog(type: StatusType, value: unknown, timeStamp?: LogDate, duration?: number, from?: string, source?: string): void;
102
+ getLog(...type: StatusType[]): LogStatus<StatusType>[];
103
+ flushLog(): void;
104
+ willAbort(value: unknown): boolean;
105
+ hasOwnPermission(): boolean;
106
+ isFatal(err?: unknown): boolean;
107
+ detach(): void;
108
+ reset(): void;
109
+ get moduleName(): string;
110
+ set host(value);
111
+ get host(): IHost | null;
112
+ set permission(value);
113
+ get permission(): IPermission | null;
114
+ get aborted(): boolean;
115
+ set abortable(value);
116
+ get abortable(): boolean;
117
+ get threadable(): boolean;
118
+ set sessionId(value);
119
+ get sessionId(): string;
120
+ set broadcastId(value);
121
+ get broadcastId(): string | string[];
122
+ get logType(): LOG_TYPE;
123
+ set logLevel(value: number | string);
124
+ get logLevel(): number;
125
+ get statusType(): STATUS_TYPE;
126
+ set tempDir(value);
127
+ get tempDir(): string;
128
+
129
+ /* EventEmitter */
130
+ on(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
131
+ on(event: "error", listener: (err: Error) => void): this;
132
+ on(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
133
+ on(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
134
+ on(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
135
+ on(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
136
+ on(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
137
+ on(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
138
+ on(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
139
+ once(event: "exec", listener: (command: ExecCommand, options?: SpawnOptions) => void): this;
140
+ once(event: "error", listener: (err: Error) => void): this;
141
+ once(event: "file:read", listener: (src: string, data: Buffer | string, options?: ReadFileOptions) => void): this;
142
+ once(event: "file:write", listener: (src: string, options?: WriteFileOptions) => void): this;
143
+ once(event: "file:delete", listener: (src: string, options?: DeleteFileOptions) => void): this;
144
+ once(event: "file:copy", listener: (dest: string, options?: CopyFileOptions) => void): this;
145
+ once(event: "file:move", listener: (dest: string, options?: MoveFileOptions) => void): this;
146
+ once(event: "dir:create", listener: (src: string, options?: CreateDirOptions) => void): this;
147
+ once(event: "dir:remove", listener: (src: string, options?: RemoveDirOptions) => void): this;
148
+ emit(event: "exec", command: ExecCommand, options?: SpawnOptions): boolean;
149
+ emit(event: "error", err: Error): boolean;
150
+ emit(event: "file:read", src: string, data: Buffer | string, options?: ReadFileOptions): boolean;
151
+ emit(event: "file:write", src: string, options?: WriteFileOptions): boolean;
152
+ emit(event: "file:delete", src: string, options?: DeleteFileOptions): boolean;
153
+ emit(event: "file:copy", dest: string, options?: CopyFileOptions): boolean;
154
+ emit(event: "file:move", dest: string, options?: MoveFileOptions): boolean;
155
+ emit(event: "dir:create", src: string, options?: CreateDirOptions): boolean;
156
+ emit(event: "dir:remove", src: string, options?: RemoveDirOptions): boolean;
157
+ }
158
+
159
+ interface ModuleConstructor {
160
+ PROCESS_TIMEOUT: number;
161
+ LOG_STYLE_FAIL: LogMessageOptions;
162
+ LOG_STYLE_SUCCESS: LogMessageOptions;
163
+ LOG_STYLE_INFO: LogMessageOptions;
164
+ LOG_STYLE_WARN: LogMessageOptions;
165
+ LOG_STYLE_NOTICE: LogMessageOptions;
166
+ LOG_STYLE_REVERSE: LogMessageOptions;
167
+ readonly VERSION: string;
168
+ readonly LOG_TYPE: LOG_TYPE;
169
+ readonly LOG_FORMAT: LoggerFormatSettings<LoggerFormat<number>>;
170
+ readonly STATUS_TYPE: STATUS_TYPE;
171
+ readonly MAX_TIMEOUT: number;
172
+ readonly TEMP_DIR: string;
173
+ supported(major: number, minor?: number, patch?: number, lts?: boolean): boolean;
174
+ formatMessage(type: LogType, title: string, value: LogValue, message?: unknown, options?: LogMessageOptions): void;
175
+ writeFail(value: LogValue, message?: unknown, options?: LogFailOptions | LogType): void;
176
+ enabled(key: string, username?: string): boolean;
177
+ parseFunction(value: unknown, options?: ParseFunctionOptions): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
178
+ parseFunction(value: unknown, absolute: boolean, sync?: boolean): ((...args: unknown[]) => Promise<unknown> | unknown) | null;
179
+ asString(value: unknown, cacheKey?: boolean | "throws"): string;
180
+ asHash(data: BinaryLike, options: AsHashOptions): string;
181
+ asHash(data: BinaryLike, algorithm?: unknown, digest?: unknown): string;
182
+ readHash(value: string | URL, options?: ReadHashOptions): Promise<string>;
183
+ toPosix(value: unknown, normalize: boolean): string;
184
+ toPosix(value: unknown, filename?: string, normalize?: boolean): string;
185
+ hasLogType(value: LogType): boolean;
186
+ isURL(value: string, ...exclude: string[]): boolean;
187
+ isFile(value: string | URL, type?: ProtocolType): boolean;
188
+ isDir(value: string | URL): boolean;
189
+ isPath(value: string | URL, type?: "unc" | "unc-exists"): boolean;
190
+ isPath(value: string | URL, isFile?: boolean): boolean;
191
+ isErrorCode(err: unknown, ...code: string[]): boolean;
192
+ fromLocalPath(value: string): string;
193
+ resolveFile(value: string): string;
194
+ resolvePath(value: string, base: string | URL): string;
195
+ joinPath(...values: [...paths: unknown[], normalize: boolean][]): string;
196
+ joinPath(...values: unknown[]): string;
197
+ normalizePath(value: unknown, flags?: boolean | NormalizeFlags): string;
198
+ createDir(value: string | URL, overwrite?: boolean): boolean;
199
+ removeDir(value: string | URL, sinceCreated: number, recursive?: boolean): boolean;
200
+ removeDir(value: string | URL, empty?: boolean, recursive?: boolean): boolean;
201
+ copyDir(src: string | URL, dest: string | URL, move?: boolean, recursive?: boolean): Promise<CopyDirResult>;
202
+ copyDir(src: string | URL, dest: string | URL, options?: CopyDirOptions): Promise<CopyDirResult>;
203
+ renameFile(src: string | URL, dest: string | URL, throws?: boolean): boolean;
204
+ streamFile(src: string, cache: boolean): Promise<Buffer | string>;
205
+ streamFile(src: string, options: ReadBufferOptions): Promise<Buffer | string>;
206
+ streamFile(src: string, cache?: boolean | ReadBufferOptions, options?: ReadBufferOptions): Promise<Buffer | string>;
207
+ readText(value: string | URL, cache: boolean): string;
208
+ readText(value: string | URL, options: ReadTextOptions): Promise<string> | string;
209
+ readText(value: string | URL, encoding?: BufferEncoding | ReadTextOptions, cache?: boolean): string;
210
+ readBuffer(value: string | URL, options: ReadBufferOptions): Promise<Buffer | null> | Buffer | null;
211
+ readBuffer(value: string | URL, cache?: boolean | ReadBufferOptions): Buffer | null;
212
+ resolveMime(data: string | Buffer | Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
213
+ lookupMime(value: string, extension?: boolean): string;
214
+ initCpuUsage(instance?: IModule): CpuUsage;
215
+ getCpuUsage(start: CpuUsage, format: true): string;
216
+ getCpuUsage(start: CpuUsage, format?: boolean): number;
217
+ getMemUsage(format: true): string;
218
+ getMemUsage(format?: boolean): number;
219
+ formatCpuMem(start: CpuUsage, all?: boolean): string;
220
+ getPackageVersion(name: string | [string, string], startDir: string, baseDir?: string): string;
221
+ getPackageVersion(name: string | [string, string], unstable?: boolean, startDir?: string, baseDir?: string): string;
222
+ checkSemVer(name: string | [string, string], options: CheckSemVerOptions): boolean;
223
+ checkSemVer(name: string | [string, string], min: number | string, max?: number | string, unstable?: boolean, startDir?: string): boolean;
224
+ checkSemVer(name: string | [string, string], min: number | string, max: number | string, options?: CheckSemVerOptions): boolean;
225
+ sanitizeCmd(value: string): string;
226
+ sanitizeArgs(value: string, doubleQuote?: boolean): string;
227
+ sanitizeArgs(values: string[], doubleQuote?: boolean): string[];
228
+ purgeMemory(percent: number, parent: boolean): Promise<number>;
229
+ purgeMemory(percent: number, limit: number, parent?: boolean): Promise<number>;
230
+ purgeMemory(percent?: number, limit?: number | boolean, parent?: unknown): Promise<number>;
231
+ canWrite(name: "temp" | "home"): boolean;
232
+ loadSettings(settings: Settings, password?: string): boolean;
233
+ readonly prototype: IModule<IHost>;
234
+ new(): IModule<IHost>;
235
+ }
236
+ ```
237
+
238
+ ## Settings
239
+
240
+ ```typescript
241
+ import type { LogMessageOptions, LogTypeValue, LoggerStatus } from "./logger";
242
+ import type { LoggerProcessSettings } from "./settings";
243
+
244
+ import type { BackgroundColor as IBackgroundColor, ForegroundColor as IForegroundColor } from "chalk";
245
+ import type { BinaryLike, CipherGCMTypes } from "crypto";
246
+ import type { SecureVersion } from "tls";
247
+
248
+ interface NodeModule {
249
+ process?: {
250
+ cpu_usage?: boolean;
251
+ memory_usage?: boolean;
252
+ inline?: boolean;
253
+ };
254
+ require?: {
255
+ ext?: string | string[] | boolean;
256
+ npm?: boolean;
257
+ inline?: boolean;
258
+ };
259
+ settings?: {
260
+ package_manager?: "npm" | "yarn" | "pnpm";
261
+ };
262
+ }
263
+
264
+ interface ProcessModule {
265
+ env?: {
266
+ apply?: boolean;
267
+ };
268
+ cipher?: {
269
+ algorithm?: CipherGCMTypes;
270
+ key?: BinaryLike;
271
+ iv?: BinaryLike;
272
+ };
273
+ password?: string;
274
+ }
275
+
276
+ interface MemoryModule {
277
+ settings?: {
278
+ users?: boolean | string[];
279
+ cache_disk?: {
280
+ enabled?: boolean;
281
+ min_size?: number | string;
282
+ max_size?: number | string;
283
+ include?: string[];
284
+ exclude?: string[];
285
+ expires?: number | string;
286
+ };
287
+ };
288
+ }
289
+
290
+ interface PermissionModule {
291
+ home_read?: boolean;
292
+ home_write?: boolean;
293
+ process_exec?: (string | ExecOptions)[];
294
+ }
295
+
296
+ interface ErrorModule {
297
+ out?: string | (err: Error, data: LogTypeValue, require?: NodeRequire) => void;
298
+ fatal?: boolean;
299
+ }
300
+
301
+ interface TempModule {
302
+ dir?: string;
303
+ write?: boolean;
304
+ }
305
+
306
+ interface LoggerModule {
307
+ enabled?: boolean;
308
+ level?: number,
309
+ production?: string[];
310
+ format?: {
311
+ title?: {
312
+ width?: number;
313
+ color?: ForegroundColor;
314
+ bg_color?: BackgroundColor;
315
+ bold?: boolean;
316
+ justify?: "left" | "center" | "right";
317
+ as?: StringMap;
318
+ };
319
+ value?: {
320
+ width?: number;
321
+ color?: ForegroundColor;
322
+ bg_color?: BackgroundColor;
323
+ bold?: boolean;
324
+ justify?: "left" | "center" | "right";
325
+ },
326
+ hint?: {
327
+ width?: number;
328
+ color?: ForegroundColor;
329
+ bg_color?: BackgroundColor;
330
+ bold?: boolean;
331
+ as?: StringMap;
332
+ unit?: "auto" | "s" | "ms";
333
+ };
334
+ message?: {
335
+ width?: number;
336
+ color?: ForegroundColor;
337
+ bg_color?: BackgroundColor;
338
+ bold?: boolean;
339
+ };
340
+ meter?: {
341
+ color?: ForegroundColor;
342
+ bg_color?: BackgroundColor;
343
+ bg_alt_color?: BackgroundColor;
344
+ bold?: boolean;
345
+ };
346
+ };
347
+ meter?: {
348
+ http?: number;
349
+ image?: number;
350
+ compress?: number;
351
+ process?: number;
352
+ };
353
+ broadcast?: {
354
+ enabled?: boolean;
355
+ out?: string | (value: string, options: LogMessageOptions, require?: NodeRequire) => void;
356
+ color?: boolean;
357
+ port?: number | number[];
358
+ secure?: {
359
+ port?: number | number[];
360
+ ca?: string;
361
+ key?: string;
362
+ cert?: string;
363
+ version?: SecureVersion
364
+ };
365
+ };
366
+ color?: boolean;
367
+ message?: boolean;
368
+ stdout?: boolean;
369
+ abort?: boolean;
370
+ status?: boolean | LoggerStatus;
371
+ unknown?: boolean | LoggerColor;
372
+ system?: boolean | LoggerColor;
373
+ process?: boolean | LoggerProcessSettings;
374
+ image?: boolean | LoggerColor;
375
+ compress?: boolean | LoggerColor;
376
+ watch?: boolean | LoggerColor;
377
+ file?: boolean | LoggerColor;
378
+ cloud?: boolean | LoggerColor;
379
+ db?: boolean | LoggerColor;
380
+ time_elapsed?: boolean | LoggerColor;
381
+ time_process?: boolean | LoggerColor;
382
+ exec?: boolean | LoggerColor;
383
+ http?: boolean | LoggerColor;
384
+ node?: boolean | LoggerColor;
385
+ session_id?: boolean | number;
386
+ stack_trace?: boolean | number;
387
+ }
388
+
389
+ type BackgroundColor = typeof IBackgroundColor | `#${string}`;
390
+ type ForegroundColor = typeof IForegroundColor | `#${string}`;
391
+ ```
392
+
393
+ ## References
394
+
395
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/core.d.ts
396
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/logger.d.ts
397
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/module.d.ts
398
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/node.d.ts
399
+ - https://www.unpkg.com/@e-mc/types@0.9.11/lib/settings.d.ts
400
+
401
+ * https://www.npmjs.com/package/@types/node
402
+
403
+ ## LICENSE
404
+
402
405
  BSD 3-Clause
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 '@e-mc/types/lib';
2
+
3
+ declare const Module: ModuleConstructor;
4
+
5
5
  export = Module;
package/index.js CHANGED
@@ -106,6 +106,7 @@ const VALUES = {
106
106
  ["node.process.cpu_usage"]: true,
107
107
  ["node.process.memory_usage"]: true,
108
108
  ["node.process.inline"]: true,
109
+ ["node.settings.package_manager"]: '',
109
110
  ["temp.dir"]: "tmp",
110
111
  ["temp.write"]: false,
111
112
  ["process.password"]: '',
@@ -176,7 +177,7 @@ function setPnpmVer() {
176
177
  value = value.substring(0, index);
177
178
  }
178
179
  index = value.lastIndexOf(value.indexOf('@', 2) !== -1 ? '@' : '/');
179
- const name = value.substring(1, index);
180
+ const name = value.substring(0, index).replace(/^\//, '');
180
181
  const version = value.substring(index + 1);
181
182
  if (!items.find(item => item[0] === name && item[1] === version)) {
182
183
  items.push([name, version]);
@@ -230,9 +231,8 @@ function setYarnVer() {
230
231
  return YARN_VER;
231
232
  }
232
233
  function applyStyle(options, style) {
233
- var _h;
234
234
  for (const attr in style) {
235
- (_h = options)[attr] ?? (_h[attr] = style[attr]);
235
+ options[attr] ??= style[attr];
236
236
  }
237
237
  return options;
238
238
  }
@@ -242,51 +242,51 @@ function checkColorOptions(type, settings, options) {
242
242
  }
243
243
  let result = false;
244
244
  if (settings.valueColor) {
245
- options.valueColor || (options.valueColor = settings.valueColor);
245
+ options.valueColor ||= settings.valueColor;
246
246
  result = true;
247
247
  }
248
248
  if (settings.valueBgColor) {
249
- options.valueBgColor || (options.valueBgColor = settings.valueBgColor);
249
+ options.valueBgColor ||= settings.valueBgColor;
250
250
  result = true;
251
251
  }
252
252
  if (typeof settings.valueBold === 'boolean') {
253
- options.valueBold ?? (options.valueBold = settings.valueBold);
253
+ options.valueBold ??= settings.valueBold;
254
254
  }
255
255
  if (settings.hintColor) {
256
- options.hintColor || (options.hintColor = settings.hintColor);
256
+ options.hintColor ||= settings.hintColor;
257
257
  result = true;
258
258
  }
259
259
  if (settings.hintBgColor) {
260
- options.hintBgColor || (options.hintBgColor = settings.hintBgColor);
260
+ options.hintBgColor ||= settings.hintBgColor;
261
261
  result = true;
262
262
  }
263
263
  if (typeof settings.hintBold === 'boolean') {
264
- options.hintBold ?? (options.hintBold = settings.hintBold);
264
+ options.hintBold ??= settings.hintBold;
265
265
  }
266
266
  if (type & types_1.LOG_TYPE.FAIL) {
267
267
  return result;
268
268
  }
269
269
  if (settings.titleColor) {
270
- options.titleColor || (options.titleColor = settings.titleColor);
270
+ options.titleColor ||= settings.titleColor;
271
271
  result = true;
272
272
  }
273
273
  if (settings.titleBgColor) {
274
- options.titleBgColor || (options.titleBgColor = settings.titleBgColor);
274
+ options.titleBgColor ||= settings.titleBgColor;
275
275
  result = true;
276
276
  }
277
277
  if (typeof settings.titleBold === 'boolean') {
278
- options.titleBold ?? (options.titleBold = settings.titleBold);
278
+ options.titleBold ??= settings.titleBold;
279
279
  }
280
280
  if (settings.messageColor) {
281
- options.messageColor || (options.messageColor = settings.messageColor);
281
+ options.messageColor ||= settings.messageColor;
282
282
  result = true;
283
283
  }
284
284
  if (settings.messageBgColor) {
285
- options.messageBgColor || (options.messageBgColor = settings.messageBgColor);
285
+ options.messageBgColor ||= settings.messageBgColor;
286
286
  result = true;
287
287
  }
288
288
  if (typeof settings.messageBold === 'boolean') {
289
- options.messageBold ?? (options.messageBold = settings.messageBold);
289
+ options.messageBold ??= settings.messageBold;
290
290
  }
291
291
  return result;
292
292
  }
@@ -557,12 +557,11 @@ function checkFunction(value) {
557
557
  return null;
558
558
  }
559
559
  function encryptMessage(data, cipher, algorithm) {
560
- var _h;
561
560
  if (cipher?.key && cipher.iv) {
562
- algorithm || (algorithm = cipher.algorithm || 'aes-256-gcm');
561
+ algorithm ||= cipher.algorithm || 'aes-256-gcm';
563
562
  const result = (0, types_1.encryptUTF8)(algorithm, cipher.key, cipher.iv, data);
564
563
  if (result) {
565
- VALUES[_h = "process.cipher.algorithm"] || (VALUES[_h] = algorithm);
564
+ VALUES["process.cipher.algorithm"] ||= algorithm;
566
565
  return result;
567
566
  }
568
567
  }
@@ -647,7 +646,7 @@ function hasFileSystem(type, value, options, ignoreExists, overwrite) {
647
646
  return result;
648
647
  }
649
648
  function applyLogId(options) {
650
- options.sessionId ?? (options.sessionId = this.sessionId);
649
+ options.sessionId ??= this.sessionId;
651
650
  let value = options.broadcastId;
652
651
  if (value === undefined) {
653
652
  if (value = this.broadcastId) {
@@ -722,7 +721,7 @@ class Module extends EventEmitter {
722
721
  this[_f] = new AbortController();
723
722
  this[_g] = null;
724
723
  }
725
- static get VERSION() { return "0.9.9"; }
724
+ static get VERSION() { return "0.9.11"; }
726
725
  static get LOG_TYPE() { return types_1.LOG_TYPE; }
727
726
  static get STATUS_TYPE() { return types_1.STATUS_TYPE; }
728
727
  static get MAX_TIMEOUT() { return 2147483647; }
@@ -765,6 +764,7 @@ class Module extends EventEmitter {
765
764
  case "error.fatal":
766
765
  return VALUES[key];
767
766
  case "node.require.ext":
767
+ case "node.settings.package_manager":
768
768
  case "process.password":
769
769
  case "process.cipher.algorithm":
770
770
  return VALUES[key] !== '';
@@ -941,7 +941,7 @@ class Module extends EventEmitter {
941
941
  else if (type & 2) {
942
942
  if (!checkColorOptions(type, SETTINGS.node, options)) {
943
943
  applyStyle(options, this.LOG_STYLE_REVERSE);
944
- options.hintColor || (options.hintColor = 'yellow');
944
+ options.hintColor ||= 'yellow';
945
945
  }
946
946
  titleJustify = 'center';
947
947
  }
@@ -975,7 +975,7 @@ class Module extends EventEmitter {
975
975
  }
976
976
  if (type & 128) {
977
977
  if (!checkColorOptions(type, SETTINGS.time_elapsed, options)) {
978
- options.hintColor || (options.hintColor = 'yellow');
978
+ options.hintColor ||= 'yellow';
979
979
  }
980
980
  if (options.titleBgColor) {
981
981
  titleJustify = 'center';
@@ -983,7 +983,7 @@ class Module extends EventEmitter {
983
983
  }
984
984
  else if (type & 256) {
985
985
  if (options.failed) {
986
- options.messageBgColor || (options.messageBgColor = 'bgGrey');
986
+ options.messageBgColor ||= 'bgGrey';
987
987
  }
988
988
  else {
989
989
  const { color, bgColor, bold } = format.meter;
@@ -996,7 +996,7 @@ class Module extends EventEmitter {
996
996
  }
997
997
  }
998
998
  if (bold) {
999
- options.messageBold ?? (options.messageBold = true);
999
+ options.messageBold ??= true;
1000
1000
  }
1001
1001
  }
1002
1002
  }
@@ -1014,7 +1014,7 @@ class Module extends EventEmitter {
1014
1014
  }
1015
1015
  if (!hintColor && !hintBgColor) {
1016
1016
  ({ color: hintColor, bgColor: hintBgColor } = formatHint);
1017
- hintBold ?? (hintBold = formatHint.bold);
1017
+ hintBold ??= formatHint.bold;
1018
1018
  }
1019
1019
  value = getValue();
1020
1020
  hint = coloring ? chalk.blackBright('[') + formatColumn(truncateEnd(hint, hintWidth), hintColor, hintBgColor, hintBold) + chalk.blackBright(']') : `[${truncateEnd(hint, hintWidth)}]`;
@@ -1034,7 +1034,7 @@ class Module extends EventEmitter {
1034
1034
  }
1035
1035
  if (!valueColor && !valueBgColor) {
1036
1036
  ({ color: valueColor, bgColor: valueBgColor } = formatValue);
1037
- valueBold ?? (valueBold = formatValue.bold);
1037
+ valueBold ??= formatValue.bold;
1038
1038
  }
1039
1039
  try {
1040
1040
  let v = value, i = id, m = message;
@@ -1044,15 +1044,15 @@ class Module extends EventEmitter {
1044
1044
  }
1045
1045
  if ((m || unit) && SETTINGS.message !== false) {
1046
1046
  if (error) {
1047
- m && (m = chalk.redBright('{') + chalk.bgWhite.blackBright(m) + chalk.redBright('}'));
1047
+ m &&= chalk.redBright('{') + chalk.bgWhite.blackBright(m) + chalk.redBright('}');
1048
1048
  }
1049
1049
  else {
1050
1050
  const formatMessage = format.message;
1051
1051
  if (!messageColor && !messageBgColor) {
1052
1052
  ({ color: messageColor, bgColor: messageBgColor, bold: messageBold } = formatMessage);
1053
- messageBold ?? (messageBold = formatMessage.bold);
1053
+ messageBold ??= formatMessage.bold;
1054
1054
  }
1055
- messageWidth ?? (messageWidth = formatMessage.width);
1055
+ messageWidth ??= formatMessage.width;
1056
1056
  let u = unit;
1057
1057
  if (u) {
1058
1058
  if ((0, types_1.isObject)(SETTINGS.time_process)) {
@@ -1167,7 +1167,7 @@ class Module extends EventEmitter {
1167
1167
  }
1168
1168
  }
1169
1169
  try {
1170
- result || (result = (0, types_1.asFunction)(fs.readFileSync(pathname, 'utf-8'), sync));
1170
+ result ||= (0, types_1.asFunction)(fs.readFileSync(pathname, 'utf-8'), sync);
1171
1171
  }
1172
1172
  catch (err) {
1173
1173
  this.writeFail(["Unable to read file", value], err, 32);
@@ -2109,8 +2109,8 @@ class Module extends EventEmitter {
2109
2109
  }
2110
2110
  static sanitizeArgs(values, doubleQuote) {
2111
2111
  const result = typeof values === 'string' ? [values] : values;
2112
- const pattern = /[^0-9a-z%+-./:=@_]/gi;
2113
- const sanitize = (value) => value.replace(pattern, capture => (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
2112
+ const pattern = /[^\w+-.,/:@]/g;
2113
+ const sanitize = (value) => value.replace(pattern, capture => capture === '\n' ? "'\n'" : (capture === '$' || capture === '`' ? '\\' : '') + '\\' + capture);
2114
2114
  for (let i = 0; i < result.length; ++i) {
2115
2115
  let value = result[i].trim(), leading = '';
2116
2116
  if (value !== '--') {
@@ -2225,7 +2225,6 @@ class Module extends EventEmitter {
2225
2225
  }
2226
2226
  }
2227
2227
  static loadSettings(settings, password) {
2228
- var _h;
2229
2228
  const current = VALUES["process.password"];
2230
2229
  if (current) {
2231
2230
  const proc = settings.process || {};
@@ -2280,6 +2279,17 @@ class Module extends EventEmitter {
2280
2279
  VALUES["node.require.inline"] = inline;
2281
2280
  }
2282
2281
  }
2282
+ const manager = node.settings?.package_manager;
2283
+ switch (manager) {
2284
+ case 'npm':
2285
+ case 'yarn':
2286
+ case 'pnpm':
2287
+ VALUES["node.settings.package_manager"] = manager;
2288
+ break;
2289
+ default:
2290
+ VALUES["node.settings.package_manager"] = '';
2291
+ break;
2292
+ }
2283
2293
  }
2284
2294
  if ((0, types_1.isPlainObject)(settings.process)) {
2285
2295
  const { env, cipher, password: pwd } = settings.process;
@@ -2287,7 +2297,7 @@ class Module extends EventEmitter {
2287
2297
  VALUES["process.env.apply"] = env.apply;
2288
2298
  }
2289
2299
  if ((0, types_1.isString)(pwd)) {
2290
- VALUES[_h = "process.password"] || (VALUES[_h] = encryptMessage(pwd, cipher));
2300
+ VALUES["process.password"] ||= encryptMessage(pwd, cipher);
2291
2301
  }
2292
2302
  }
2293
2303
  if ((0, types_1.isPlainObject)(memory?.settings)) {
@@ -2507,7 +2517,7 @@ class Module extends EventEmitter {
2507
2517
  }
2508
2518
  let dir = settings.temp_dir, write, modified;
2509
2519
  if ((0, types_1.isPlainObject)(temp)) {
2510
- dir || (dir = temp.dir);
2520
+ dir ||= temp.dir;
2511
2521
  write = temp.write;
2512
2522
  }
2513
2523
  if ((0, types_1.isString)(dir) && path.isAbsolute(dir = path.normalize(dir).replace(/[\\/]$/, ''))) {
@@ -2586,11 +2596,11 @@ class Module extends EventEmitter {
2586
2596
  let result;
2587
2597
  if ((0, types_1.isString)(pathname)) {
2588
2598
  leading.push(pathname);
2589
- createDir ?? (createDir = true);
2599
+ createDir ??= true;
2590
2600
  }
2591
2601
  if (uuidDir) {
2592
2602
  leading.push((0, types_1.generateUUID)());
2593
- createDir ?? (createDir = true);
2603
+ createDir ??= true;
2594
2604
  }
2595
2605
  if ((createDir || increment > 0) && !Module.isDir(result = path.join(...leading))) {
2596
2606
  const [output] = tryIncrementDir(result, increment);
@@ -2689,7 +2699,7 @@ class Module extends EventEmitter {
2689
2699
  }
2690
2700
  }
2691
2701
  if (cache) {
2692
- result || (result = (encoding ? getCacheItem(CACHE_READTEXT, outSrc) : getCacheItem(CACHE_READBUFFER, outSrc)));
2702
+ result ||= (encoding ? getCacheItem(CACHE_READTEXT, outSrc) : getCacheItem(CACHE_READBUFFER, outSrc));
2693
2703
  }
2694
2704
  try {
2695
2705
  if (!isNaN(minStreamSize = (0, types_1.alignSize)(minStreamSize)) || promises && fs.statSync(outSrc).size >= 2097152000) {
@@ -3104,7 +3114,7 @@ class Module extends EventEmitter {
3104
3114
  return false;
3105
3115
  }
3106
3116
  async allSettled(tasks, rejected, options) {
3107
- rejected || (rejected = "Unknown");
3117
+ rejected ||= "Unknown";
3108
3118
  return Promise.allSettled(tasks).then(result => {
3109
3119
  const items = [];
3110
3120
  for (const item of result) {
@@ -3199,7 +3209,7 @@ class Module extends EventEmitter {
3199
3209
  message = value;
3200
3210
  value = '';
3201
3211
  }
3202
- value || (value = isFailed(options) ? "Failed" : "Success");
3212
+ value ||= isFailed(options) ? "Failed" : "Success";
3203
3213
  const duration = getTimeOffset(startTime);
3204
3214
  const args = [
3205
3215
  (128 | type),
@@ -3260,7 +3270,7 @@ class Module extends EventEmitter {
3260
3270
  if ((0, types_1.isPlainObject)(output)) {
3261
3271
  output = { ...output };
3262
3272
  if (Array.isArray(output.warn)) {
3263
- (exec.warn || (exec.warn = [])).push(...output.warn);
3273
+ (exec.warn ||= []).push(...output.warn);
3264
3274
  }
3265
3275
  delete output.command;
3266
3276
  delete output.warn;
@@ -3372,7 +3382,7 @@ class Module extends EventEmitter {
3372
3382
  if (typeof options === 'number') {
3373
3383
  options = undefined;
3374
3384
  }
3375
- this.writeFail("Unknown", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: types_1.ERR_CODE.MODULE_NOT_FOUND, exec: { command: 'npm', args: ['i', name] } });
3385
+ this.writeFail("Unknown", err, { ...options, type: types_1.LOG_TYPE.SYSTEM, code: types_1.ERR_CODE.MODULE_NOT_FOUND, exec: { command: VALUES["node.settings.package_manager"] || (setPnpmVer() ? 'pnpm' : setYarnVer() ? 'yarn' : 'npm'), args: ['install', name] } });
3376
3386
  return true;
3377
3387
  }
3378
3388
  if (value) {
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 '@e-mc/types/lib/compat-v4';
2
+
3
+ declare const LibV4: IModuleLibV4;
4
+
5
5
  export = LibV4;
package/package.json CHANGED
@@ -1,31 +1,31 @@
1
- {
2
- "name": "@e-mc/module",
3
- "version": "0.9.9",
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": "BSD 3-Clause",
21
- "homepage": "https://github.com/anpham6/e-mc#readme",
22
- "dependencies": {
23
- "@e-mc/types": "0.9.9",
24
- "chalk": "4.1.2",
25
- "file-type": "16.5.4",
26
- "js-yaml": "^4.1.0",
27
- "mime-types": "^2.1.35",
28
- "picomatch": "^4.0.2",
29
- "strip-ansi": "6.0.1"
30
- }
31
- }
1
+ {
2
+ "name": "@e-mc/module",
3
+ "version": "0.9.11",
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": "BSD 3-Clause",
21
+ "homepage": "https://github.com/anpham6/e-mc#readme",
22
+ "dependencies": {
23
+ "@e-mc/types": "0.9.11",
24
+ "chalk": "4.1.2",
25
+ "file-type": "16.5.4",
26
+ "js-yaml": "^4.1.0",
27
+ "mime-types": "^2.1.35",
28
+ "picomatch": "^4.0.2",
29
+ "strip-ansi": "6.0.1"
30
+ }
31
+ }