@ix-xs/node-comfort 1.1.31 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +190 -0
- package/LICENSE +21 -0
- package/README.md +210 -748
- package/index.js +84 -13
- package/package.json +201 -21
- package/src/Arr.js +901 -0
- package/src/Async.js +585 -0
- package/src/Cache.js +329 -0
- package/src/Checker.js +979 -188
- package/src/Cli.js +1034 -0
- package/src/Color.js +415 -0
- package/src/Crypto.js +707 -0
- package/src/Emitter.js +289 -0
- package/src/Env.js +555 -0
- package/src/FS.js +1483 -768
- package/src/Func.js +692 -0
- package/src/Http.js +538 -0
- package/src/Id.js +418 -0
- package/src/Logger.js +739 -307
- package/src/Num.js +849 -0
- package/src/Obj.js +904 -0
- package/src/SQLite.js +1308 -994
- package/src/Schema.js +1586 -0
- package/src/Str.js +999 -0
- package/src/Sys.js +511 -0
- package/src/Time.js +1323 -0
- package/src/Utils.js +321 -325
- package/src/errors.js +292 -0
- package/types/index.d.ts +693 -120
- package/types/src/Arr.d.ts +562 -0
- package/types/src/Arr.d.ts.map +1 -0
- package/types/src/Async.d.ts +321 -0
- package/types/src/Async.d.ts.map +1 -0
- package/types/src/Cache.d.ts +195 -0
- package/types/src/Cache.d.ts.map +1 -0
- package/types/src/Checker.d.ts +609 -81
- package/types/src/Checker.d.ts.map +1 -1
- package/types/src/Cli.d.ts +582 -0
- package/types/src/Cli.d.ts.map +1 -0
- package/types/src/Color.d.ts +294 -0
- package/types/src/Color.d.ts.map +1 -0
- package/types/src/Crypto.d.ts +534 -0
- package/types/src/Crypto.d.ts.map +1 -0
- package/types/src/Emitter.d.ts +170 -0
- package/types/src/Emitter.d.ts.map +1 -0
- package/types/src/Env.d.ts +382 -0
- package/types/src/Env.d.ts.map +1 -0
- package/types/src/FS.d.ts +709 -201
- package/types/src/FS.d.ts.map +1 -1
- package/types/src/Func.d.ts +455 -0
- package/types/src/Func.d.ts.map +1 -0
- package/types/src/Http.d.ts +374 -0
- package/types/src/Http.d.ts.map +1 -0
- package/types/src/Id.d.ts +200 -0
- package/types/src/Id.d.ts.map +1 -0
- package/types/src/Logger.d.ts +374 -24
- package/types/src/Logger.d.ts.map +1 -1
- package/types/src/Num.d.ts +578 -0
- package/types/src/Num.d.ts.map +1 -0
- package/types/src/Obj.d.ts +475 -0
- package/types/src/Obj.d.ts.map +1 -0
- package/types/src/SQLite.d.ts +647 -305
- package/types/src/SQLite.d.ts.map +1 -1
- package/types/src/Schema.d.ts +940 -0
- package/types/src/Schema.d.ts.map +1 -0
- package/types/src/Str.d.ts +696 -0
- package/types/src/Str.d.ts.map +1 -0
- package/types/src/Sys.d.ts +269 -0
- package/types/src/Sys.d.ts.map +1 -0
- package/types/src/Time.d.ts +664 -0
- package/types/src/Time.d.ts.map +1 -0
- package/types/src/Utils.d.ts +154 -102
- package/types/src/Utils.d.ts.map +1 -1
- package/types/src/errors.d.ts +292 -0
- package/types/src/errors.d.ts.map +1 -0
- package/tsconfig.json +0 -18
- package/types/index.d.ts.map +0 -1
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for `run()` and `exec()`.
|
|
3
|
+
*/
|
|
4
|
+
export type RunOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Where to run the command.
|
|
7
|
+
*/
|
|
8
|
+
cwd?: string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Extra environment variables, added to `process.env`.
|
|
11
|
+
*/
|
|
12
|
+
env?: Record<string, string | undefined> | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Set to `false` to pass only `env`, without `process.env`.
|
|
15
|
+
*/
|
|
16
|
+
extendEnv?: boolean | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Written to the command's stdin.
|
|
19
|
+
*/
|
|
20
|
+
input?: string | Buffer<ArrayBufferLike> | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Kill the command after this long, like `"30s"`.
|
|
23
|
+
*/
|
|
24
|
+
timeout?: string | number | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Kills the command when aborted.
|
|
27
|
+
*/
|
|
28
|
+
signal?: AbortSignal | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* `"inherit"` shows the output live instead of capturing it. Defaults to `"pipe"`.
|
|
31
|
+
*/
|
|
32
|
+
stdio?: "pipe" | "inherit" | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Called for each line of stdout.
|
|
35
|
+
*/
|
|
36
|
+
onStdout?: ((line: string) => void) | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Called for each line of stderr.
|
|
39
|
+
*/
|
|
40
|
+
onStderr?: ((line: string) => void) | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Throw when the exit code isn't 0. Defaults to `true`.
|
|
43
|
+
*/
|
|
44
|
+
reject?: boolean | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Drop the final newline of the output. Defaults to `true`.
|
|
47
|
+
*/
|
|
48
|
+
trim?: boolean | undefined;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* A finished command.
|
|
52
|
+
*/
|
|
53
|
+
export type RunResult = {
|
|
54
|
+
/**
|
|
55
|
+
* The command line that ran.
|
|
56
|
+
*/
|
|
57
|
+
command: string;
|
|
58
|
+
stdout: string;
|
|
59
|
+
stderr: string;
|
|
60
|
+
/**
|
|
61
|
+
* `null` if a signal killed it.
|
|
62
|
+
*/
|
|
63
|
+
exitCode: number | null;
|
|
64
|
+
signal: string | null;
|
|
65
|
+
/**
|
|
66
|
+
* In milliseconds.
|
|
67
|
+
*/
|
|
68
|
+
duration: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Options for `onShutdown()`. They apply to all handlers.
|
|
72
|
+
*/
|
|
73
|
+
export type ShutdownOptions = {
|
|
74
|
+
/**
|
|
75
|
+
* How long the handlers get before the exit is forced. Defaults to 10 seconds.
|
|
76
|
+
*/
|
|
77
|
+
timeout?: string | number | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Exit code after a clean shutdown. Defaults to `0`.
|
|
80
|
+
*/
|
|
81
|
+
exitCode?: number | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Signals that trigger it. Defaults to `SIGINT`, `SIGTERM` and `SIGHUP`.
|
|
84
|
+
*/
|
|
85
|
+
signals?: NodeJS.Signals[] | undefined;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Returned by `info()`.
|
|
89
|
+
*/
|
|
90
|
+
export type SystemInfo = {
|
|
91
|
+
/**
|
|
92
|
+
* `"win32"`, `"darwin"`, `"linux"`...
|
|
93
|
+
*/
|
|
94
|
+
platform: NodeJS.Platform;
|
|
95
|
+
/**
|
|
96
|
+
* `"x64"`, `"arm64"`...
|
|
97
|
+
*/
|
|
98
|
+
arch: string;
|
|
99
|
+
/**
|
|
100
|
+
* OS release.
|
|
101
|
+
*/
|
|
102
|
+
release: string;
|
|
103
|
+
/**
|
|
104
|
+
* Node.js version.
|
|
105
|
+
*/
|
|
106
|
+
node: string;
|
|
107
|
+
/**
|
|
108
|
+
* Number of logical CPUs.
|
|
109
|
+
*/
|
|
110
|
+
cpus: number;
|
|
111
|
+
cpuModel: string;
|
|
112
|
+
/**
|
|
113
|
+
* System memory, in bytes.
|
|
114
|
+
*/
|
|
115
|
+
memory: {
|
|
116
|
+
total: number;
|
|
117
|
+
free: number;
|
|
118
|
+
used: number;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* In seconds.
|
|
122
|
+
*/
|
|
123
|
+
uptime: number;
|
|
124
|
+
hostname: string;
|
|
125
|
+
user: string;
|
|
126
|
+
pid: number;
|
|
127
|
+
/**
|
|
128
|
+
* Running in CI.
|
|
129
|
+
*/
|
|
130
|
+
ci: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Running in a container.
|
|
133
|
+
*/
|
|
134
|
+
docker: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Running in WSL.
|
|
137
|
+
*/
|
|
138
|
+
wsl: boolean;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Runs a program without a shell, so arguments are passed as they are and
|
|
142
|
+
* user input can't inject anything. Resolves with the output; rejects with
|
|
143
|
+
* a `ProcessError` if the exit code isn't 0.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* const { stdout } = await sys.run("git", ["log", "-1", "--format=%s"]);
|
|
147
|
+
* await sys.run("npm", ["install"], { cwd: "./app", stdio: "inherit" });
|
|
148
|
+
* await sys.run("ffmpeg", ["-i", input, output], { timeout: "5m" });
|
|
149
|
+
*
|
|
150
|
+
* @param {string} file A name found in `PATH`, or a path.
|
|
151
|
+
* @param {string[]} [args=[]]
|
|
152
|
+
* @param {RunOptions} [options]
|
|
153
|
+
* @returns {Promise<RunResult>}
|
|
154
|
+
* @throws {ProcessError} If it can't start, fails (unless `reject: false`) or times out.
|
|
155
|
+
*/
|
|
156
|
+
export function run(file: string, args?: string[], options?: RunOptions): Promise<RunResult>;
|
|
157
|
+
/**
|
|
158
|
+
* Runs a command line through the shell, so pipes, `&&` and variables
|
|
159
|
+
* work. Don't build it from untrusted input; use `run()` for that.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* const { stdout } = await sys.exec("git status --short | wc -l");
|
|
163
|
+
* const { exitCode } = await sys.exec("npm test", { reject: false, stdio: "inherit" });
|
|
164
|
+
*
|
|
165
|
+
* @param {string} command
|
|
166
|
+
* @param {RunOptions} [options]
|
|
167
|
+
* @returns {Promise<RunResult>}
|
|
168
|
+
* @throws {ProcessError} If it fails (unless `reject: false`) or times out.
|
|
169
|
+
*/
|
|
170
|
+
export function exec(command: string, options?: RunOptions): Promise<RunResult>;
|
|
171
|
+
/**
|
|
172
|
+
* Finds an executable in `PATH`, like the `which` command.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* sys.which("git"); // "/usr/bin/git"
|
|
176
|
+
* sys.which("nope"); // undefined
|
|
177
|
+
*
|
|
178
|
+
* @param {string} command
|
|
179
|
+
* @returns {string | undefined}
|
|
180
|
+
*/
|
|
181
|
+
export function which(command: string): string | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* Opens a URL, file or folder with the default app.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* sys.open("http://localhost:3000");
|
|
187
|
+
*
|
|
188
|
+
* @param {string} target
|
|
189
|
+
* @returns {boolean} `true` if the opener started.
|
|
190
|
+
*/
|
|
191
|
+
export function open(target: string): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Runs cleanup code when the process is asked to stop (Ctrl+C,
|
|
194
|
+
* `docker stop`, `kill`): close servers, flush logs, disconnect databases.
|
|
195
|
+
* Handlers run in reverse order, then the process exits. If they take
|
|
196
|
+
* longer than `timeout`, the exit is forced; a second Ctrl+C exits at once.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* const server = app.listen(3000);
|
|
200
|
+
* sys.onShutdown(() => new Promise((done) => server.close(done)));
|
|
201
|
+
* sys.onShutdown(() => db.close());
|
|
202
|
+
*
|
|
203
|
+
* @param {() => unknown} handler Can be async.
|
|
204
|
+
* @param {ShutdownOptions} [options]
|
|
205
|
+
* @returns {() => void} Removes the handler.
|
|
206
|
+
*/
|
|
207
|
+
export function onShutdown(handler: () => unknown, options?: ShutdownOptions): () => void;
|
|
208
|
+
/**
|
|
209
|
+
* Are we on Windows?
|
|
210
|
+
* @returns {boolean}
|
|
211
|
+
*/
|
|
212
|
+
export function isWindows(): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Are we on macOS?
|
|
215
|
+
* @returns {boolean}
|
|
216
|
+
*/
|
|
217
|
+
export function isMac(): boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Are we on Linux? WSL counts.
|
|
220
|
+
* @returns {boolean}
|
|
221
|
+
*/
|
|
222
|
+
export function isLinux(): boolean;
|
|
223
|
+
/**
|
|
224
|
+
* Are we running in CI? Detects GitHub Actions, GitLab, CircleCI, Jenkins,
|
|
225
|
+
* Azure, Vercel, Netlify and more.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* if (sys.isCI()) nc.setLevel("warn");
|
|
229
|
+
*
|
|
230
|
+
* @returns {boolean}
|
|
231
|
+
*/
|
|
232
|
+
export function isCI(): boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Are we running inside a container?
|
|
235
|
+
*
|
|
236
|
+
* @returns {boolean}
|
|
237
|
+
*/
|
|
238
|
+
export function isDocker(): boolean;
|
|
239
|
+
/**
|
|
240
|
+
* Are we running in WSL?
|
|
241
|
+
*
|
|
242
|
+
* @returns {boolean}
|
|
243
|
+
*/
|
|
244
|
+
export function isWSL(): boolean;
|
|
245
|
+
/**
|
|
246
|
+
* Facts about the machine and the runtime, handy for bug reports.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* console.table(sys.info());
|
|
250
|
+
*
|
|
251
|
+
* @returns {SystemInfo}
|
|
252
|
+
*/
|
|
253
|
+
export function info(): SystemInfo;
|
|
254
|
+
/**
|
|
255
|
+
* Memory used by this process, in bytes.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* nc.num.formatBytes(sys.memory().heapUsed); // "42.1 MB"
|
|
259
|
+
*
|
|
260
|
+
* @returns {{ rss: number, heapTotal: number, heapUsed: number, external: number, arrayBuffers: number }}
|
|
261
|
+
*/
|
|
262
|
+
export function memory(): {
|
|
263
|
+
rss: number;
|
|
264
|
+
heapTotal: number;
|
|
265
|
+
heapUsed: number;
|
|
266
|
+
external: number;
|
|
267
|
+
arrayBuffers: number;
|
|
268
|
+
};
|
|
269
|
+
//# sourceMappingURL=Sys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sys.d.ts","sourceRoot":"","sources":["../../src/Sys.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAgCqB,MAAM,KAAK,IAAI;;;;uBACf,MAAM,KAAK,IAAI;;;;;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