yavascript 0.0.5 → 0.0.7

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/yavascript.d.ts CHANGED
@@ -1,12 +1,8 @@
1
-
1
+ // ===============
2
2
  // ---------------
3
3
  // YavaScript APIs
4
4
  // ---------------
5
-
6
- // -----------
7
- // --- env ---
8
- // -----------
9
-
5
+ // ===============
10
6
  /**
11
7
  * An object representing the process's environment variables. You can read
12
8
  * from it to read environment variables, write into it to set environment
@@ -15,300 +11,88 @@
15
11
  */
16
12
  declare const env: { [key: string]: string | undefined };
17
13
 
18
- // ------------
19
- // --- exec ---
20
- // ------------
21
-
22
- type BaseExecOptions = {
23
- /** Sets the current working directory for the child process. */
24
- cwd?: string;
25
-
26
- /** Sets environment variables within the process. */
27
- env?: { [key: string | number]: string | number | boolean };
28
- };
29
-
30
- interface Exec {
31
- (args: Array<string> | string): void;
32
-
33
- (args: Array<string> | string, options: Record<string, never>): void;
34
-
35
- (
36
- args: Array<string> | string,
37
- options: BaseExecOptions & {
38
- /**
39
- * Whether an Error should be thrown when the process exits with a nonzero
40
- * status code.
41
- *
42
- * Defaults to true.
43
- */
44
- failOnNonZeroStatus: true;
45
- /**
46
- * If true, stdout and stderr will be collected into strings and returned
47
- * instead of being printed to the screen.
48
- *
49
- * Defaults to false.
50
- */
51
- captureOutput: false;
52
- }
53
- ): void;
54
-
55
- (
56
- args: Array<string> | string,
57
- options: BaseExecOptions & {
58
- /**
59
- * Whether an Error should be thrown when the process exits with a nonzero
60
- * status code.
61
- *
62
- * Defaults to true.
63
- */
64
- failOnNonZeroStatus: false;
65
- /**
66
- * If true, stdout and stderr will be collected into strings and returned
67
- * instead of being printed to the screen.
68
- *
69
- * Defaults to false.
70
- */
71
- captureOutput: false;
72
- }
73
- ): { status: number };
74
-
75
- (
76
- args: Array<string> | string,
77
- options: BaseExecOptions & {
78
- /**
79
- * Whether an Error should be thrown when the process exits with a nonzero
80
- * status code.
81
- *
82
- * Defaults to true.
83
- */
84
- failOnNonZeroStatus: false;
85
- }
86
- ): { status: number };
87
-
88
- (
89
- args: Array<string> | string,
90
- options: BaseExecOptions & {
91
- /**
92
- * Whether an Error should be thrown when the process exits with a nonzero
93
- * status code.
94
- *
95
- * Defaults to true.
96
- */
97
- failOnNonZeroStatus: true;
98
- /**
99
- * If true, stdout and stderr will be collected into strings and returned
100
- * instead of being printed to the screen.
101
- *
102
- * Defaults to false.
103
- */
104
- captureOutput: true;
105
- }
106
- ): { stdout: string; stderr: string };
107
-
108
- (
109
- args: Array<string> | string,
110
- options: BaseExecOptions & {
111
- /**
112
- * If true, stdout and stderr will be collected into strings and returned
113
- * instead of being printed to the screen.
114
- *
115
- * Defaults to false.
116
- */
117
- captureOutput: true;
118
- }
119
- ): { stdout: string; stderr: string };
120
-
121
- (
122
- args: Array<string> | string,
123
- options: BaseExecOptions & {
124
- /**
125
- * Whether an Error should be thrown when the process exits with a nonzero
126
- * status code.
127
- *
128
- * Defaults to true.
129
- */
130
- failOnNonZeroStatus: false;
131
- captureOutput: true;
132
- }
133
- ): { stdout: string; stderr: string; status: number };
134
-
135
- /** Log all executed commands to stderr. `isOn` is optional and defaults to `true`. Pass `false` to disable logging. */
136
- enableLogging(isOn?: boolean): void;
137
- }
138
-
139
- /** Run a child process using the provided arguments. The first value in the arguments array is the program to run. */
140
- declare const exec: Exec;
141
-
142
- /** Alias for `exec(args, { captureOutput: true })` */
143
- declare function $(args: Array<string> | string): {
144
- stdout: string;
145
- stderr: string;
146
- };
147
-
148
- // -------------
149
- // --- paths ---
150
- // -------------
151
-
152
14
  /**
153
- * Change the process's current working directory to the specified path.
15
+ * Parse command line --flags into an object of flags and an array of
16
+ * positional arguments. This function is opinionated; if it doesn't meet your
17
+ * needs, you can parse the `scriptArgs` global manually.
154
18
  *
155
- * Provides the same functionality as the shell builtin of the same name.
156
- */
157
- declare function cd(path: string): void;
158
-
159
- /**
160
- * Return the process's current working directory.
19
+ * Flags `--like-this`, `--like_this`, or `--LIKE_THIS` get converted into
20
+ * property names `likeThis` on the returned flags object.
161
21
  *
162
- * Provides the same functionality as the shell builtin of the same name.
163
- */
164
- declare function pwd(): string;
165
-
166
- /**
167
- * Get the absolute path given a relative path. Symlinks are also resolved.
22
+ * Flags like this: `-v` get converted into into property names like this: `v`
23
+ * on the returned flags object.
168
24
  *
169
- * The path's target file/directory must exist.
25
+ * Anything that appears after `--` is considered a positional argument instead
26
+ * of a flag. `--` is not present in the returned positional arguments Array.
170
27
  *
171
- * Provides the same functionality as the unix binary of the same name.
172
- */
173
- declare function realpath(path: string): string;
174
-
175
- /**
176
- * Removes the final component from a path string.
28
+ * Single-character flags must have a single leading dash, and multi-character
29
+ * flags must have two leading dashes.
177
30
  *
178
- * Provides the same functionality as the unix binary of the same name.
179
- */
180
- declare function dirname(path: string): string;
181
-
182
- /**
183
- * Return the last component of a path string.
31
+ * Flags with equals signs in them (eg. `--something=42`) are not supported.
32
+ * Write `--something 42` instead.
184
33
  *
185
- * Provides the same functionality as the unix binary of the same name.
186
- */
187
- declare function basename(path: string): string;
188
-
189
- /**
190
- * Returns the file extension of the file at a given path.
34
+ * Flags where you specify them multiple times, like `-vvv`, are not supported.
35
+ * Write something like `-v 3` instead.
191
36
  *
192
- * If the file has no extension (eg `Makefile`, etc), then `''` will be returned.
37
+ * @param hints - An object whose keys are flag names (in camelCase) and whose values indicate what type to treat that flag as. Valid property values are `String`, `Boolean`, `Number`, and `parseScriptArgs.Path`. `parseScriptArgs.Path` will resolve relative paths into absolute paths for you. If no hints object is specified, `parseScriptArgs` will do its best to guess, based on the command-line args.
38
+ * @param argv - An array containing the command line flags you want to parse. If unspecified, `scriptArgs.slice(2)` will be used (we slice 2 in order to skip the yavascript binary and script name). If you pass in an array here, it should only contain command-line flags, not the binary being called.
193
39
  *
194
- * Pass `{ full: true }` to get compound extensions, eg `.d.ts` or `.test.js` instead of just `.ts`/`.js`.
195
- */
196
- declare function extname(
197
- pathOrFilename: string,
198
- options?: { full?: boolean }
199
- ): string;
200
-
201
- /**
202
- * A namespace object providing several path-string-related APIs.
40
+ * @returns An object with two properties: `flags` and `args`. `flags` is an object whose keys are camelCase flag names and whose values are strings, booleans, or numbers corresponding to the input command-line args. `args` is an Array of positional arguments, as found on the command-line.
203
41
  */
204
- declare const paths: {
205
- /**
206
- * The separator character the host operating system uses between path
207
- * components, ie. the slashes in a filepath. On windows, it's a backslash, and
208
- * on all other OSes, it's a forward slash.
209
- */
210
- OS_PATH_SEPARATOR: "/" | "\\";
211
-
42
+ declare const parseScriptArgs: {
212
43
  /**
213
- * Split a path string (or array of path strings) on / or \\, returning an
214
- * Array of strings.
44
+ * Parse command line --flags into an object of flags and an array of
45
+ * positional arguments. This function is opinionated; if it doesn't meet your
46
+ * needs, you can parse the `scriptArgs` global manually.
215
47
  *
216
- * Trailing slashes and duplicate path separators will be removed.
48
+ * Flags `--like-this`, `--like_this`, or `--LIKE_THIS` get converted into
49
+ * property names `likeThis` on the returned flags object.
217
50
  *
218
- * If the path starts with `/`, the first string in the Array will be empty.
219
- */
220
- split(path: string | Array<string>): Array<string>;
221
-
222
- /**
223
- * Detect which path separator is present in the given path or array of
224
- * paths: `\` or `/`.
51
+ * Flags like this: `-v` get converted into into property names like this: `v`
52
+ * on the returned flags object.
225
53
  *
226
- * If neither is present, `/` will be returned.
227
- */
228
- detectSeparator(input: string | Array<string>): string;
229
-
230
- /**
231
- * Create a path string from one or more path or path component strings.
232
- * {@link paths.OS_PATH_SEPARATOR} will be used to combine parts.
54
+ * Anything that appears after `--` is considered a positional argument instead
55
+ * of a flag. `--` is not present in the returned positional arguments Array.
233
56
  *
234
- * This function does not resolve `..` or `.`. Use {@link paths.resolve} for that.
235
- */
236
- join(...parts: Array<string>): string;
237
-
238
- /**
239
- * Resolves all `..` and `.` components in a path, returning an absolute
240
- * path.
57
+ * Single-character flags must have a single leading dash, and multi-character
58
+ * flags must have two leading dashes.
59
+ *
60
+ * Flags with equals signs in them (eg. `--something=42`) are not supported.
61
+ * Write `--something 42` instead.
241
62
  *
242
- * Use `from` to specify where leading `.` or `..` characters should be
243
- * resolved relative to. If unspecified, it defaults to `pwd()`.
63
+ * Flags where you specify them multiple times, like `-vvv`, are not supported.
64
+ * Write something like `-v 3` instead.
65
+ *
66
+ * @param hints - An object whose keys are flag names (in camelCase) and whose values indicate what type to treat that flag as. Valid property values are `String`, `Boolean`, `Number`, and `parseScriptArgs.Path`. `parseScriptArgs.Path` will resolve relative paths into absolute paths for you. If no hints object is specified, `parseScriptArgs` will do its best to guess, based on the command-line args.
67
+ * @param args - An array containing the command line flags you want to parse. If unspecified, `scriptArgs.slice(2)` will be used (we slice 2 in order to skip the yavascript binary and script name). If you pass in an array here, it should only contain command-line flags, not the binary being called.
68
+ *
69
+ * @returns An object with two properties: `flags` and `args`. `flags` is an object whose keys are camelCase flag names and whose values are strings, booleans, or numbers corresponding to the input command-line args. `args` is an Array of positional arguments, as found on the command-line.
244
70
  */
245
- resolve(path: string, from?: string): string;
71
+ (
72
+ hints?: {
73
+ [key: string]:
74
+ | typeof String
75
+ | typeof Boolean
76
+ | typeof Number
77
+ | typeof parseScriptArgs["Path"];
78
+ },
79
+ args?: Array<string>
80
+ ): {
81
+ flags: { [key: string]: any };
82
+ args: Array<string>;
83
+ };
246
84
 
247
85
  /**
248
- * Returns whether the path starts with either a leading slash or a windows
249
- * drive letter.
86
+ * A hint value for {@link parseScriptArgs}. Behaves similar to the hint value
87
+ * `String`, except that it also resolves relative paths into absolute paths,
88
+ * using the following rules:
89
+ *
90
+ * - paths `./like/this` or `../like/this` get resolved relative to `pwd()`.
91
+ * - paths `like/this` or `this` get resolved relative to `pwd()` as if they had a leading `./`.
250
92
  */
251
- isAbsolute(path: string): boolean;
93
+ readonly Path: unique symbol;
252
94
  };
253
95
 
254
- /**
255
- * The absolute path to the current file (whether script or module).
256
- *
257
- * Behaves the same as in Node.js, except that it's present within ES modules.
258
- */
259
- declare const __filename: string;
260
-
261
- /**
262
- * The absolute path to the directory the current file is inside of.
263
- *
264
- * Behaves the same as in Node.js, except that it's present within ES modules.
265
- */
266
- declare const __dirname: string;
267
-
268
- // ------------
269
- // --- repo ---
270
- // ------------
271
-
272
- /**
273
- * Returns the absolute path to the root folder of the git/hg repo.
274
- *
275
- * This is done by running `git rev-parse --show-toplevel` and `hg root`.
276
- *
277
- * If `relativeTo` is provided, the git and hg commands will be executed in
278
- * that folder instead of in `pwd()`.
279
- */
280
- declare function repoRoot(relativeTo?: string): string;
281
-
282
- /**
283
- * Returns whether the provided path is ignored by git.
284
- */
285
- declare function isGitignored(path: string): boolean;
286
-
287
- // ------------------
288
- // --- filesystem ---
289
- // ------------------
290
-
291
- /**
292
- * Return the contents of a directory, as absolute paths. `.` and `..` are
293
- * omitted.
294
- *
295
- * Use the `relativePaths` option to get relative paths instead (relative to
296
- * the parent directory).
297
- */
298
- declare function ls(
299
- dir?: string,
300
- options?: { relativePaths?: boolean }
301
- ): Array<string>;
302
-
303
- /**
304
- * Read a symlink.
305
- *
306
- * Returns the target of the symlink, which may be absolute or relative.
307
- *
308
- * Provides the same functionality as the unix binary of the same name.
309
- */
310
- declare function readlink(path: string): string;
311
-
312
96
  /**
313
97
  * Read the contents of a file from disk, as a UTF-8 string.
314
98
  */
@@ -408,135 +192,1234 @@ declare type CopyOptions = {
408
192
  */
409
193
  declare function copy(from: string, to: string, options?: CopyOptions): void;
410
194
 
411
- // ------------
412
- // --- glob ---
413
- // ------------
195
+ /** An object that represents a filesystem path. */
196
+ declare class Path {
197
+ /** The character used to separate path segments on this OS. */
198
+ static readonly OS_SEGMENT_SEPARATOR: "/" | "\\";
414
199
 
415
- /**
416
- * Options for {@link glob}.
417
- */
418
- declare type GlobOptions = {
419
200
  /**
420
- * Whether to treat symlinks to directories as if they themselves were
421
- * directories, traversing into them.
422
- *
423
- * Defaults to false.
201
+ * The character used to separate entries within the PATH environment
202
+ * variable on this OS.
424
203
  */
425
- followSymlinks?: boolean;
204
+ static readonly OS_ENV_VAR_SEPARATOR: ":" | ";";
205
+
206
+ /** Split one or more path strings into an array of path segments. */
207
+ static splitToSegments(inputParts: Array<string> | string): Array<string>;
426
208
 
427
209
  /**
428
- * If provided, this function will be called multiple times as `glob`
429
- * traverses the filesystem, to help you understand what's going on and/or
430
- * troubleshoot things. In most cases, it makes sense to use a logging
431
- * function here, like so:
432
- *
433
- * ```js
434
- * glob(pwd(), ["./*.js"], { trace: console.log });
435
- * ```
210
+ * Search the provided path string or strings for a path separator character,
211
+ * and return it. If none is found, return `fallback`, which defaults to the
212
+ * OS's path segment separator.
436
213
  */
437
- trace?: (...args: Array<any>) => void;
438
- };
214
+ static detectSeparator<Fallback extends string | null = string>(
215
+ input: Array<string> | string,
216
+ // @ts-ignore might be instantiated with a different subtype
217
+ fallback: Fallback = Path.OS_SEGMENT_SEPARATOR
218
+ ): string | Fallback;
439
219
 
440
- /**
441
- * Search the filesystem for files matching the specified glob patterns.
442
- *
443
- * Uses [minimatch](https://www.npmjs.com/package/minimatch) with its default
220
+ /** Join together one or more paths. */
221
+ static join(...inputs: Array<string | Path | Array<string | Path>>): string;
222
+
223
+ /**
224
+ * Turns the input path(s) into an absolute path by resolving all `.` and `..`
225
+ * segments, using `pwd()` as a base dir to use when resolving leading `.` or
226
+ * `..` segments.
227
+ */
228
+ static resolve(
229
+ ...inputs: Array<string | Path | Array<string | Path>>
230
+ ): string;
231
+
232
+ /**
233
+ * Concatenates the input path(s) and then resolves all non-leading `.` and
234
+ * `..` segments.
235
+ */
236
+ static normalize(
237
+ ...inputs: Array<string | Path | Array<string | Path>>
238
+ ): string;
239
+
240
+ /**
241
+ * Return whether the provided path string is absolute; that is, whether it
242
+ * starts with either `/` or a drive letter (ie `C:`).
243
+ */
244
+ static isAbsolute(path: string): boolean;
245
+
246
+ /**
247
+ * An array of the path segments that make up this path.
248
+ *
249
+ * For `/tmp/foo.txt`, it'd be `["", "tmp", "foo.txt"]`.
250
+ *
251
+ * For `C:\something\somewhere.txt`, it'd be `["C:", "something", "somewhere.txt"]`.
252
+ */
253
+ segments: Array<string>;
254
+
255
+ /**
256
+ * The path separator that should be used to turn this path into a string.
257
+ *
258
+ * Will be either `/` or `\`.
259
+ */
260
+ separator: string;
261
+
262
+ /** Create a new Path object using the provided input(s). */
263
+ constructor(...inputs: Array<string | Path | Array<string | Path>>);
264
+
265
+ /** Create a new Path object using the provided segments and separator. */
266
+ static from(segments: Array<string>, separator: string): Path;
267
+
268
+ /**
269
+ * Turn this path into an absolute path by resolving all `.` and `..`
270
+ * segments, using `from` as a base dir to use when resolving leading `.` or
271
+ * `..` segments.
272
+ *
273
+ * If `from` is unspecified, it defaults to `pwd()`.
274
+ */
275
+ resolve(from?: string | Path): Path;
276
+
277
+ /**
278
+ * Resolve all non-leading `.` and `..` segments in this path.
279
+ */
280
+ normalize(): Path;
281
+
282
+ /**
283
+ * Create a new path by appending another path's segments after this path's
284
+ * segments.
285
+ *
286
+ * The returned path will use this path's separator.
287
+ */
288
+ concat(other: string | Path | Array<string | Path>): Path;
289
+
290
+ /**
291
+ * Return whether this path is absolute; that is, whether it starts with
292
+ * either `/` or a drive letter (ie `C:`).
293
+ */
294
+ isAbsolute(): boolean;
295
+
296
+ /**
297
+ * Turn this path into a string by joining its segments using its separator.
298
+ */
299
+ toString(): string;
300
+ }
301
+
302
+ /**
303
+ * The absolute path to the current file (whether script or module).
304
+ *
305
+ * Behaves the same as in Node.js, except that it's present within ES modules.
306
+ */
307
+ declare const __filename: string;
308
+
309
+ /**
310
+ * The absolute path to the directory the current file is inside of.
311
+ *
312
+ * Behaves the same as in Node.js, except that it's present within ES modules.
313
+ */
314
+ declare const __dirname: string;
315
+
316
+ /**
317
+ * Return the last component of a path string.
318
+ *
319
+ * Provides the same functionality as the unix binary of the same name.
320
+ */
321
+ declare function basename(path: string): string;
322
+
323
+ /**
324
+ * Read the contents of one of more files from disk as one UTF-8 string,
325
+ * print that string to stdout, then return it.
326
+ */
327
+ declare function cat(...paths: Array<string>): string;
328
+
329
+ /**
330
+ * Change the process's current working directory to the specified path. If no
331
+ * path is specified, moves to the user's home directory.
332
+ *
333
+ * Provides the same functionality as the shell builtin of the same name.
334
+ */
335
+ declare function cd(path?: string): void;
336
+
337
+ /** A string representing who a permission applies to. */
338
+ declare type ChmodPermissionsWho =
339
+ | "user"
340
+ | "group"
341
+ | "others"
342
+ | "all"
343
+ | "u"
344
+ | "g"
345
+ | "o"
346
+ | "a"
347
+ | "ug"
348
+ | "go"
349
+ | "uo";
350
+
351
+ /** A string representing the access level for the given permission. */
352
+ declare type ChmodPermissionsWhat =
353
+ | "read"
354
+ | "write"
355
+ | "execute"
356
+ | "readwrite"
357
+ | "none"
358
+ | "full"
359
+ | "r"
360
+ | "w"
361
+ | "x"
362
+ | "rw"
363
+ | "rx"
364
+ | "wx"
365
+ | "rwx";
366
+
367
+ /**
368
+ * Set the permission bits for the specified file.
369
+ *
370
+ * @param permissions The permission bits to set. This can be a number, a string containing an octal number, or an object.
371
+ * @param path The path to the file.
372
+ */
373
+ declare function chmod(
374
+ permissions:
375
+ | number
376
+ | string
377
+ | Record<ChmodPermissionsWho, ChmodPermissionsWhat>,
378
+ path: string
379
+ ): void;
380
+
381
+ /**
382
+ * Removes the final component from a path string.
383
+ *
384
+ * Provides the same functionality as the unix binary of the same name.
385
+ */
386
+ declare function dirname(path: string): string;
387
+
388
+ /**
389
+ * Print one or more values to stdout.
390
+ */
391
+ declare const echo: typeof console.log;
392
+
393
+ /**
394
+ * Returns the file extension of the file at a given path.
395
+ *
396
+ * If the file has no extension (eg `Makefile`, etc), then `''` will be returned.
397
+ *
398
+ * Pass `{ full: true }` to get compound extensions, eg `.d.ts` or `.test.js` instead of just `.ts`/`.js`.
399
+ */
400
+ declare function extname(
401
+ pathOrFilename: string,
402
+ options?: { full?: boolean }
403
+ ): string;
404
+
405
+ /**
406
+ * Return the contents of a directory, as absolute paths. `.` and `..` are
407
+ * omitted.
408
+ *
409
+ * Use the `relativePaths` option to get relative paths instead (relative to
410
+ * the parent directory).
411
+ */
412
+ declare function ls(
413
+ dir?: string,
414
+ options?: { relativePaths?: boolean }
415
+ ): Array<string>;
416
+
417
+ /**
418
+ * Print data to stdout using C-style format specifiers.
419
+ */
420
+ declare function printf(format: string, ...args: Array<any>): void;
421
+
422
+ /**
423
+ * Return the process's current working directory.
424
+ *
425
+ * Provides the same functionality as the shell builtin of the same name.
426
+ */
427
+ declare function pwd(): string;
428
+
429
+ /**
430
+ * Read a symlink.
431
+ *
432
+ * Returns the target of the symlink, which may be absolute or relative.
433
+ *
434
+ * Provides the same functionality as the unix binary of the same name.
435
+ */
436
+ declare function readlink(path: string): string;
437
+
438
+ /**
439
+ * Get the absolute path given a relative path. Symlinks are also resolved.
440
+ *
441
+ * The path's target file/directory must exist.
442
+ *
443
+ * Provides the same functionality as the unix binary of the same name.
444
+ */
445
+ declare function realpath(path: string): string;
446
+
447
+ /**
448
+ * If the file at `path` exists, update its creation/modification timestamps.
449
+ *
450
+ * Otherwise, create an empty file at that path.
451
+ *
452
+ * @param path The target path for the file.
453
+ */
454
+ declare function touch(path: string): void;
455
+
456
+ declare type BaseExecOptions = {
457
+ /** Sets the current working directory for the child process. */
458
+ cwd?: string;
459
+
460
+ /** Sets environment variables within the process. */
461
+ env?: { [key: string | number]: string | number | boolean };
462
+
463
+ /**
464
+ * If provided, this function will be called multiple times as `exec`
465
+ * runs, to help you understand what's going on and/or troubleshoot things.
466
+ * In most cases, it makes sense to use a logging function here, like so:
467
+ *
468
+ * ```js
469
+ * exec(["echo", "hi"], { trace: console.log });
470
+ * ```
471
+ */
472
+ trace?: (...args: Array<any>) => void;
473
+ };
474
+
475
+ declare interface Exec {
476
+ (args: Array<string> | string): void;
477
+
478
+ (args: Array<string> | string, options: Record<string, never>): void;
479
+
480
+ (
481
+ args: Array<string> | string,
482
+ options: BaseExecOptions & {
483
+ /**
484
+ * Whether an Error should be thrown when the process exits with a nonzero
485
+ * status code.
486
+ *
487
+ * Defaults to true.
488
+ */
489
+ failOnNonZeroStatus: true;
490
+ /**
491
+ * If true, stdout and stderr will be collected into strings and returned
492
+ * instead of being printed to the screen.
493
+ *
494
+ * Defaults to false.
495
+ */
496
+ captureOutput: false;
497
+ }
498
+ ): void;
499
+
500
+ (
501
+ args: Array<string> | string,
502
+ options: BaseExecOptions & {
503
+ /**
504
+ * Whether an Error should be thrown when the process exits with a nonzero
505
+ * status code.
506
+ *
507
+ * Defaults to true.
508
+ */
509
+ failOnNonZeroStatus: false;
510
+ /**
511
+ * If true, stdout and stderr will be collected into strings and returned
512
+ * instead of being printed to the screen.
513
+ *
514
+ * Defaults to false.
515
+ */
516
+ captureOutput: false;
517
+ }
518
+ ):
519
+ | { status: number; signal: undefined }
520
+ | { status: undefined; signal: number };
521
+
522
+ (
523
+ args: Array<string> | string,
524
+ options: BaseExecOptions & {
525
+ /**
526
+ * Whether an Error should be thrown when the process exits with a nonzero
527
+ * status code.
528
+ *
529
+ * Defaults to true.
530
+ */
531
+ failOnNonZeroStatus: false;
532
+ }
533
+ ):
534
+ | { status: number; signal: undefined }
535
+ | { status: undefined; signal: number };
536
+
537
+ (
538
+ args: Array<string> | string,
539
+ options: BaseExecOptions & {
540
+ /**
541
+ * Whether an Error should be thrown when the process exits with a nonzero
542
+ * status code.
543
+ *
544
+ * Defaults to true.
545
+ */
546
+ failOnNonZeroStatus: true;
547
+ /**
548
+ * If true, stdout and stderr will be collected into strings and returned
549
+ * instead of being printed to the screen.
550
+ *
551
+ * Defaults to false.
552
+ */
553
+ captureOutput: true;
554
+ }
555
+ ): { stdout: string; stderr: string };
556
+
557
+ (
558
+ args: Array<string> | string,
559
+ options: BaseExecOptions & {
560
+ /**
561
+ * If true, stdout and stderr will be collected into strings and returned
562
+ * instead of being printed to the screen.
563
+ *
564
+ * Defaults to false.
565
+ */
566
+ captureOutput: true;
567
+ }
568
+ ): { stdout: string; stderr: string };
569
+
570
+ (
571
+ args: Array<string> | string,
572
+ options: BaseExecOptions & {
573
+ /**
574
+ * Whether an Error should be thrown when the process exits with a nonzero
575
+ * status code.
576
+ *
577
+ * Defaults to true.
578
+ */
579
+ failOnNonZeroStatus: false;
580
+ captureOutput: true;
581
+ }
582
+ ):
583
+ | { stdout: string; stderr: string; status: number; signal: undefined }
584
+ | { stdout: string; stderr: string; status: undefined; signal: number };
585
+ }
586
+
587
+ /** Run a child process using the provided arguments. The first value in the arguments array is the program to run. */
588
+ declare const exec: Exec;
589
+
590
+ /** Alias for `exec(args, { captureOutput: true })` */
591
+ declare function $(args: Array<string> | string): {
592
+ stdout: string;
593
+ stderr: string;
594
+ };
595
+
596
+ /**
597
+ * Options for {@link glob}.
598
+ */
599
+ declare type GlobOptions = {
600
+ /**
601
+ * Whether to treat symlinks to directories as if they themselves were
602
+ * directories, traversing into them.
603
+ *
604
+ * Defaults to false.
605
+ */
606
+ followSymlinks?: boolean;
607
+
608
+ /**
609
+ * If provided, this function will be called multiple times as `glob`
610
+ * traverses the filesystem, to help you understand what's going on and/or
611
+ * troubleshoot things. In most cases, it makes sense to use a logging
612
+ * function here, like so:
613
+ *
614
+ * ```js
615
+ * glob(["./*.js"], { trace: console.log });
616
+ * ```
617
+ */
618
+ trace?: (...args: Array<any>) => void;
619
+
620
+ /**
621
+ * Directory to interpret glob patterns relative to. Defaults to `pwd()`.
622
+ */
623
+ dir?: string;
624
+ };
625
+
626
+ /**
627
+ * Search the filesystem for files matching the specified glob patterns.
628
+ *
629
+ * Uses [minimatch](https://www.npmjs.com/package/minimatch) with its default
444
630
  * options.
445
631
  */
446
632
  declare function glob(
447
- dir: string,
448
- patterns: Array<string>,
633
+ patterns: string | Array<string>,
449
634
  options?: GlobOptions
450
635
  ): Array<string>;
451
636
 
452
- // ---------------
453
- // --- console ---
454
- // ---------------
637
+ /**
638
+ * Remove ANSI control characters from a string.
639
+ */
640
+ declare function stripAnsi(input: string): string;
455
641
 
456
642
  /**
457
- * Print one or more values to stdout.
643
+ * Wrap a string in double quotes, and escape any double-quotes inside using `\"`.
644
+ */
645
+ declare function quote(input: string): string;
646
+
647
+ /**
648
+ * Clear the contents and scrollback buffer of the tty by printing special characters into stdout.
649
+ */
650
+ declare function clear(): void;
651
+
652
+ // Colors
653
+
654
+ /** Wrap a string with the ANSI control characters that will make it print as black text. */
655
+ declare function black(input: string | number): string;
656
+ /** Wrap a string with the ANSI control characters that will make it print as red text. */
657
+ declare function red(input: string | number): string;
658
+ /** Wrap a string with the ANSI control characters that will make it print as green text. */
659
+ declare function green(input: string | number): string;
660
+ /** Wrap a string with the ANSI control characters that will make it print as yellow text. */
661
+ declare function yellow(input: string | number): string;
662
+ /** Wrap a string with the ANSI control characters that will make it print as blue text. */
663
+ declare function blue(input: string | number): string;
664
+ /** Wrap a string with the ANSI control characters that will make it print as magenta text. */
665
+ declare function magenta(input: string | number): string;
666
+ /** Wrap a string with the ANSI control characters that will make it print as cyan text. */
667
+ declare function cyan(input: string | number): string;
668
+ /** Wrap a string with the ANSI control characters that will make it print as white text. */
669
+ declare function white(input: string | number): string;
670
+ /** Wrap a string with the ANSI control characters that will make it print as gray text. */
671
+ declare function gray(input: string | number): string;
672
+ /** Wrap a string with the ANSI control characters that will make it print as grey text. */
673
+ declare function grey(input: string | number): string;
674
+
675
+ // Background Colors
676
+
677
+ /** Wrap a string with the ANSI control characters that will make it have a black background. */
678
+ declare function bgBlack(input: string | number): string;
679
+ /** Wrap a string with the ANSI control characters that will make it have a red background. */
680
+ declare function bgRed(input: string | number): string;
681
+ /** Wrap a string with the ANSI control characters that will make it have a green background. */
682
+ declare function bgGreen(input: string | number): string;
683
+ /** Wrap a string with the ANSI control characters that will make it have a yellow background. */
684
+ declare function bgYellow(input: string | number): string;
685
+ /** Wrap a string with the ANSI control characters that will make it have a blue background. */
686
+ declare function bgBlue(input: string | number): string;
687
+ /** Wrap a string with the ANSI control characters that will make it have a magenta background. */
688
+ declare function bgMagenta(input: string | number): string;
689
+ /** Wrap a string with the ANSI control characters that will make it have a cyan background. */
690
+ declare function bgCyan(input: string | number): string;
691
+ /** Wrap a string with the ANSI control characters that will make it have a white background. */
692
+ declare function bgWhite(input: string | number): string;
693
+
694
+ // Modifiers
695
+
696
+ /** Wrap a string with the ANSI control character that resets all styling. */
697
+ declare function reset(input: string | number): string;
698
+ /** Wrap a string with the ANSI control characters that will make it print with a bold style. */
699
+ declare function bold(input: string | number): string;
700
+ /** Wrap a string with the ANSI control characters that will make it print with a dimmed style. */
701
+ declare function dim(input: string | number): string;
702
+ /** Wrap a string with the ANSI control characters that will make it print italicized. */
703
+ declare function italic(input: string | number): string;
704
+ /** Wrap a string with the ANSI control characters that will make it print underlined. */
705
+ declare function underline(input: string | number): string;
706
+ /** Wrap a string with ANSI control characters such that its foreground (text) and background colors are swapped. */
707
+ declare function inverse(input: string | number): string;
708
+ /** Wrap a string with ANSI control characters such that it is hidden. */
709
+ declare function hidden(input: string | number): string;
710
+ /** Wrap a string with the ANSI control characters that will make it print with a horizontal line through its center. */
711
+ declare function strikethrough(input: string | number): string;
712
+
713
+ /** Split `str` on newline and then return lines matching `pattern`. */
714
+ declare const grepString: {
715
+ /** Split `str` on newline and then return lines matching `pattern`. */
716
+ (str: string, pattern: string | RegExp): Array<string>;
717
+
718
+ /** Split `str` on newline and then return lines matching `pattern`. */
719
+ (
720
+ str: string,
721
+ pattern: string | RegExp,
722
+ options: { inverse: false }
723
+ ): Array<string>;
724
+
725
+ /** Split `str` on newline and then return lines NOT matching `pattern`. */
726
+ (
727
+ str: string,
728
+ pattern: string | RegExp,
729
+ options: { inverse: true }
730
+ ): Array<string>;
731
+
732
+ /** Split `str` on newline and then return lines matching `pattern`. */
733
+ (
734
+ str: string,
735
+ pattern: string | RegExp,
736
+ options: { details: false }
737
+ ): Array<string>;
738
+
739
+ /** Split `str` on newline and then return lines matching `pattern`. */
740
+ (
741
+ str: string,
742
+ pattern: string | RegExp,
743
+ options: { inverse: false; details: false }
744
+ ): Array<string>;
745
+
746
+ /** Split `str` on newline and then return lines NOT matching `pattern`. */
747
+ (
748
+ str: string,
749
+ pattern: string | RegExp,
750
+ options: { inverse: true; details: false }
751
+ ): Array<string>;
752
+
753
+ /** Split `str` on newline and then return info about lines matching `pattern`. */
754
+ (str: string, pattern: string | RegExp, options: { details: true }): Array<{
755
+ lineNumber: number;
756
+ lineContent: string;
757
+ matches: RegExpMatchArray;
758
+ }>;
759
+
760
+ /** Split `str` on newline and then return info about lines matching `pattern`. */
761
+ (
762
+ str: string,
763
+ pattern: string | RegExp,
764
+ options: { inverse: false; details: true }
765
+ ): Array<string>;
766
+
767
+ /** Split `str` on newline and then return info about lines NOT matching `pattern`. */
768
+ (
769
+ str: string,
770
+ pattern: string | RegExp,
771
+ options: { inverse: true; details: true }
772
+ ): Array<string>;
773
+ };
774
+
775
+ /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
776
+ declare const grepFile: {
777
+ /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
778
+ (path: string, pattern: string | RegExp): Array<string>;
779
+
780
+ /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
781
+ (
782
+ path: string,
783
+ pattern: string | RegExp,
784
+ options: { inverse: false }
785
+ ): Array<string>;
786
+
787
+ /** Read the content at `path`, split it on newline, and then return lines NOT matching `pattern`. */
788
+ (
789
+ path: string,
790
+ pattern: string | RegExp,
791
+ options: { inverse: true }
792
+ ): Array<string>;
793
+
794
+ /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
795
+ (
796
+ path: string,
797
+ pattern: string | RegExp,
798
+ options: { details: false }
799
+ ): Array<string>;
800
+
801
+ /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
802
+ (
803
+ path: string,
804
+ pattern: string | RegExp,
805
+ options: { inverse: false; details: false }
806
+ ): Array<string>;
807
+
808
+ /** Read the content at `path`, split it on newline, and then return lines NOT matching `pattern`. */
809
+ (
810
+ path: string,
811
+ pattern: string | RegExp,
812
+ options: { inverse: true; details: false }
813
+ ): Array<string>;
814
+
815
+ /** Read the content at `path`, split it on newline, and then return info about lines matching `pattern`. */
816
+ (path: string, pattern: string | RegExp, options: { details: true }): Array<{
817
+ lineNumber: number;
818
+ lineContent: string;
819
+ matches: RegExpMatchArray;
820
+ }>;
821
+
822
+ /** Read the content at `path`, split it on newline, and then return info about lines matching `pattern`. */
823
+ (
824
+ path: string,
825
+ pattern: string | RegExp,
826
+ options: { inverse: false; details: true }
827
+ ): Array<string>;
828
+
829
+ /** Read the content at `path`, split it on newline, and then return info about lines NOT matching `pattern`. */
830
+ (
831
+ path: string,
832
+ pattern: string | RegExp,
833
+ options: { inverse: true; details: true }
834
+ ): Array<string>;
835
+ };
836
+
837
+ interface String {
838
+ // Same as grepString but without the first argument.
839
+ grep: {
840
+ /** Split the string on newline and then return lines matching `pattern`. */
841
+ (pattern: string | RegExp): Array<string>;
842
+
843
+ /** Split the string on newline and then return lines matching `pattern`. */
844
+ (pattern: string | RegExp, options: { inverse: false }): Array<string>;
845
+
846
+ /** Split the string on newline and then return lines NOT matching `pattern`. */
847
+ (pattern: string | RegExp, options: { inverse: true }): Array<string>;
848
+
849
+ /** Split the string on newline and then return lines matching `pattern`. */
850
+ (pattern: string | RegExp, options: { details: false }): Array<string>;
851
+
852
+ /** Split the string on newline and then return lines matching `pattern`. */
853
+ (
854
+ pattern: string | RegExp,
855
+ options: { inverse: false; details: false }
856
+ ): Array<string>;
857
+
858
+ /** Split the string on newline and then return lines NOT matching `pattern`. */
859
+ (
860
+ pattern: string | RegExp,
861
+ options: { inverse: true; details: false }
862
+ ): Array<string>;
863
+
864
+ /** Split the string on newline and then return info about lines matching `pattern`. */
865
+ (pattern: string | RegExp, options: { details: true }): Array<{
866
+ lineNumber: number;
867
+ lineContent: string;
868
+ matches: RegExpMatchArray;
869
+ }>;
870
+
871
+ /** Split the string on newline and then return info about lines matching `pattern`. */
872
+ (
873
+ pattern: string | RegExp,
874
+ options: { inverse: false; details: true }
875
+ ): Array<string>;
876
+
877
+ /** Split the string on newline and then return info about lines NOT matching `pattern`. */
878
+ (
879
+ pattern: string | RegExp,
880
+ options: { inverse: true; details: true }
881
+ ): Array<string>;
882
+ };
883
+ }
884
+
885
+ declare type TypedArray =
886
+ | Int8Array
887
+ | Uint8Array
888
+ | Uint8ClampedArray
889
+ | Int16Array
890
+ | Uint16Array
891
+ | Int32Array
892
+ | Uint32Array
893
+ | Float32Array
894
+ | Float64Array;
895
+ declare type TypedArrayConstructor =
896
+ | Int8ArrayConstructor
897
+ | Uint8ArrayConstructor
898
+ | Uint8ClampedArrayConstructor
899
+ | Int16ArrayConstructor
900
+ | Uint16ArrayConstructor
901
+ | Int32ArrayConstructor
902
+ | Uint32ArrayConstructor
903
+ | Float32ArrayConstructor
904
+ | Float64ArrayConstructor;
905
+
906
+ declare const is: {
907
+ string(value: any): value is string;
908
+ String(value: any): value is string;
909
+ number(value: any): value is number;
910
+ Number(value: any): value is number;
911
+ boolean(value: any): value is boolean;
912
+ Boolean(value: any): value is boolean;
913
+ bigint(value: any): value is bigint;
914
+ BigInt(value: any): value is bigint;
915
+ symbol(value: any): value is symbol;
916
+ Symbol(value: any): value is symbol;
917
+ null(value: any): value is null;
918
+ undefined(value: any): value is undefined;
919
+ void(value: any): value is null | undefined;
920
+ object(value: any): value is {
921
+ [key: string]: unknown;
922
+ [key: number]: unknown;
923
+ [key: symbol]: unknown;
924
+ };
925
+ Object(value: any): value is {
926
+ [key: string]: unknown;
927
+ [key: number]: unknown;
928
+ [key: symbol]: unknown;
929
+ };
930
+ Array(value: any): value is unknown[];
931
+ function(value: any): value is Function & {
932
+ [key: string]: unknown;
933
+ [key: number]: unknown;
934
+ [key: symbol]: unknown;
935
+ };
936
+ Function(value: any): value is Function & {
937
+ [key: string]: unknown;
938
+ [key: number]: unknown;
939
+ [key: symbol]: unknown;
940
+ };
941
+ tagged(value: any, tag: string): boolean;
942
+ instanceOf<T>(value: any, klass: new (...args: any) => T): value is T;
943
+ Error(value: any): value is Error;
944
+ Infinity(value: any): value is number;
945
+ NegativeInfinity(value: any): value is number;
946
+ NaN(value: any): value is number;
947
+ Date(value: any): value is Date;
948
+ RegExp(value: any): value is RegExp;
949
+ Map(value: any): value is Map<unknown, unknown>;
950
+ Set(value: any): value is Set<unknown>;
951
+ WeakMap(value: any): value is Map<unknown, unknown>;
952
+ WeakSet(value: any): value is Set<unknown>;
953
+ ArrayBuffer(value: any): value is ArrayBuffer;
954
+ SharedArrayBuffer(value: any): value is SharedArrayBuffer;
955
+ DataView(value: any): value is DataView;
956
+ TypedArray(value: any): value is TypedArray;
957
+ Int8Array(value: any): value is Int8Array;
958
+ Uint8Array(value: any): value is Uint8Array;
959
+ Uint8ClampedArray(value: any): value is Uint8ClampedArray;
960
+ Int16Array(value: any): value is Int16Array;
961
+ Uint16Array(value: any): value is Uint16Array;
962
+ Int32Array(value: any): value is Int32Array;
963
+ Uint32Array(value: any): value is Uint32Array;
964
+ Float32Array(value: any): value is Float32Array;
965
+ Float64Array(value: any): value is Float64Array;
966
+ Promise(value: any): value is Promise<unknown>;
967
+ Generator(value: any): value is Generator<unknown, any, unknown>;
968
+ GeneratorFunction(value: any): value is GeneratorFunction;
969
+ AsyncFunction(value: any): value is ((...args: any) => Promise<unknown>) & {
970
+ [key: string]: unknown;
971
+ [key: number]: unknown;
972
+ [key: symbol]: unknown;
973
+ };
974
+ AsyncGenerator(value: any): value is AsyncGenerator<unknown, any, unknown>;
975
+ AsyncGeneratorFunction(value: any): value is AsyncGeneratorFunction;
976
+
977
+ FILE(value: any): value is FILE;
978
+
979
+ JSX: {
980
+ /** Returns whether `value` is a JSX Element object as created via JSX syntax. */
981
+ Element(value: any): value is JSX.Element;
982
+ /** Returns whether `value` is a JSX fragment element as created via JSX syntax. */
983
+ Fragment(value: any): value is JSX.Fragment;
984
+ };
985
+ };
986
+
987
+ declare const assert: {
988
+ /**
989
+ * Throws an error if `value` is not truthy.
990
+ *
991
+ * @param value - The value to test for truthiness
992
+ * @param message - An optional error message to use. If unspecified, "Assertion failed" will be used.
993
+ */
994
+ <ValueType>(
995
+ value: ValueType,
996
+ message?: string
997
+ ): asserts value is ValueType extends null | undefined | false | 0 | ""
998
+ ? never
999
+ : ValueType;
1000
+
1001
+ string(value: any, message?: string): asserts value is string;
1002
+ String(value: any, message?: string): asserts value is string;
1003
+ number(value: any, message?: string): asserts value is number;
1004
+ Number(value: any, message?: string): asserts value is number;
1005
+ boolean(value: any, message?: string): asserts value is boolean;
1006
+ Boolean(value: any, message?: string): asserts value is boolean;
1007
+ bigint(value: any, message?: string): asserts value is bigint;
1008
+ BigInt(value: any, message?: string): asserts value is bigint;
1009
+ symbol(value: any, message?: string): asserts value is symbol;
1010
+ Symbol(value: any, message?: string): asserts value is symbol;
1011
+ null(value: any, message?: string): asserts value is null;
1012
+ undefined(value: any, message?: string): asserts value is undefined;
1013
+ void(value: any, message?: string): asserts value is null | undefined;
1014
+ object(
1015
+ value: any,
1016
+ message?: string
1017
+ ): asserts value is {
1018
+ [key: string]: unknown;
1019
+ [key: number]: unknown;
1020
+ [key: symbol]: unknown;
1021
+ };
1022
+ Object(
1023
+ value: any,
1024
+ message?: string
1025
+ ): asserts value is {
1026
+ [key: string]: unknown;
1027
+ [key: number]: unknown;
1028
+ [key: symbol]: unknown;
1029
+ };
1030
+ Array(value: any, message?: string): asserts value is unknown[];
1031
+ function(
1032
+ value: any,
1033
+ message?: string
1034
+ ): asserts value is Function & {
1035
+ [key: string]: unknown;
1036
+ [key: number]: unknown;
1037
+ [key: symbol]: unknown;
1038
+ };
1039
+ Function(
1040
+ value: any,
1041
+ message?: string
1042
+ ): asserts value is Function & {
1043
+ [key: string]: unknown;
1044
+ [key: number]: unknown;
1045
+ [key: symbol]: unknown;
1046
+ };
1047
+ tagged(value: any, tag: string, message?: string): void;
1048
+ instanceOf<T>(value: any, klass: new (...args: any) => T): asserts value is T;
1049
+ Error(value: any, message?: string): asserts value is Error;
1050
+ Infinity(value: any, message?: string): asserts value is number;
1051
+ NegativeInfinity(value: any, message?: string): asserts value is number;
1052
+ NaN(value: any, message?: string): asserts value is number;
1053
+ Date(value: any, message?: string): asserts value is Date;
1054
+ RegExp(value: any, message?: string): asserts value is RegExp;
1055
+ Map(value: any, message?: string): asserts value is Map<unknown, unknown>;
1056
+ Set(value: any, message?: string): asserts value is Set<unknown>;
1057
+ WeakMap(value: any, message?: string): asserts value is Map<unknown, unknown>;
1058
+ WeakSet(value: any, message?: string): asserts value is Set<unknown>;
1059
+ ArrayBuffer(value: any, message?: string): asserts value is ArrayBuffer;
1060
+ SharedArrayBuffer(
1061
+ value: any,
1062
+ message?: string
1063
+ ): asserts value is SharedArrayBuffer;
1064
+ DataView(value: any, message?: string): asserts value is DataView;
1065
+ TypedArray(value: any, message?: string): asserts value is TypedArray;
1066
+ Int8Array(value: any, message?: string): asserts value is Int8Array;
1067
+ Uint8Array(value: any, message?: string): asserts value is Uint8Array;
1068
+ Uint8ClampedArray(
1069
+ value: any,
1070
+ message?: string
1071
+ ): asserts value is Uint8ClampedArray;
1072
+ Int16Array(value: any, message?: string): asserts value is Int16Array;
1073
+ Uint16Array(value: any, message?: string): asserts value is Uint16Array;
1074
+ Int32Array(value: any, message?: string): asserts value is Int32Array;
1075
+ Uint32Array(value: any, message?: string): asserts value is Uint32Array;
1076
+ Float32Array(value: any, message?: string): asserts value is Float32Array;
1077
+ Float64Array(value: any, message?: string): asserts value is Float64Array;
1078
+ Promise(value: any, message?: string): asserts value is Promise<unknown>;
1079
+ Generator(
1080
+ value: any,
1081
+ message?: string
1082
+ ): asserts value is Generator<unknown, any, unknown>;
1083
+ GeneratorFunction(
1084
+ value: any,
1085
+ message?: string
1086
+ ): asserts value is GeneratorFunction;
1087
+ AsyncFunction(
1088
+ value: any,
1089
+ message?: string
1090
+ ): asserts value is ((...args: any) => Promise<unknown>) & {
1091
+ [key: string]: unknown;
1092
+ [key: number]: unknown;
1093
+ [key: symbol]: unknown;
1094
+ };
1095
+ AsyncGenerator(
1096
+ value: any
1097
+ ): asserts value is AsyncGenerator<unknown, any, unknown>;
1098
+ AsyncGeneratorFunction(
1099
+ value: any,
1100
+ message?: string
1101
+ ): asserts value is AsyncGeneratorFunction;
1102
+
1103
+ FILE(value: any, message?: string): asserts value is FILE;
1104
+
1105
+ JSX: {
1106
+ /** Returns whether `value` is a JSX Element object as created via JSX syntax. */
1107
+ Element(value: any, message?: string): asserts value is JSX.Element;
1108
+ /** Returns whether `value` is a JSX fragment element as created via JSX syntax. */
1109
+ Fragment(value: any, message?: string): asserts value is JSX.Fragment;
1110
+ };
1111
+ };
1112
+
1113
+ /**
1114
+ * The data source of a pipe operation; either an in-memory object, or a
1115
+ * file stream.
1116
+ *
1117
+ * - Use `maxLength` to limit how much data to read.
1118
+ * - Use `until` to stop reading once a certain byte or character has been
1119
+ * read.
1120
+ * - Use `path` or `fd` to open a file.
1121
+ */
1122
+ declare type PipeSource =
1123
+ | { data: string; maxLength?: number; until?: string | byte }
1124
+ | ArrayBuffer
1125
+ | { data: ArrayBuffer; maxLength?: number; until?: string | byte }
1126
+ | SharedArrayBuffer
1127
+ | { data: SharedArrayBuffer; maxLength?: number; until?: string | byte }
1128
+ | TypedArray
1129
+ | { data: TypedArray; maxLength?: number; until?: string | byte }
1130
+ | DataView
1131
+ | { data: DataView; maxLength?: number; until?: string | byte }
1132
+ | FILE
1133
+ | {
1134
+ data: FILE;
1135
+ maxLength?: number;
1136
+ until?: string | byte;
1137
+ }
1138
+ | { path: string; maxLength?: number; until?: string | byte }
1139
+ | { fd: number; maxLength?: number; until?: string | byte };
1140
+
1141
+ /**
1142
+ * The target destination of a pipe operation; either an in-memory object, or a
1143
+ * file stream.
1144
+ *
1145
+ * - Use `intoExisting` to put data into an existing object or file handle.
1146
+ * - Use `intoNew` to put data into a new object.
1147
+ * - Use `path` or `fd` to create a new file handle and put data into it.
1148
+ */
1149
+ declare type PipeDestination =
1150
+ | ArrayBuffer
1151
+ | SharedArrayBuffer
1152
+ | DataView
1153
+ | TypedArray
1154
+ | FILE
1155
+ | ArrayBufferConstructor
1156
+ | SharedArrayBufferConstructor
1157
+ | DataViewConstructor
1158
+ | TypedArrayConstructor
1159
+ | StringConstructor
1160
+ | { path: string }
1161
+ | { fd: number };
1162
+
1163
+ /**
1164
+ * Copy data from one source into the given target. Returns the number of bytes
1165
+ * written, and the target that data was written into.
1166
+ */
1167
+ declare function pipe<Dest extends PipeDestination>(
1168
+ from: PipeSource,
1169
+ to: Dest
1170
+ ): {
1171
+ bytesTransferred: number;
1172
+ target: Dest extends
1173
+ | ArrayBuffer
1174
+ | SharedArrayBuffer
1175
+ | DataView
1176
+ | FILE
1177
+ | { path: string }
1178
+ | { fd: number }
1179
+ ? Dest
1180
+ : Dest extends
1181
+ | ArrayBufferConstructor
1182
+ | SharedArrayBufferConstructor
1183
+ | DataViewConstructor
1184
+ | TypedArrayConstructor
1185
+ | DataViewConstructor
1186
+ ? Dest["prototype"]
1187
+ : Dest extends StringConstructor
1188
+ ? string
1189
+ : never;
1190
+ };
1191
+
1192
+ /**
1193
+ * Launch the Yavascript REPL (read-eval-print-loop).
1194
+ *
1195
+ * @param context Variables to make available as globals within the repl.
1196
+ * @param lang The langauge to use in the repl. Defaults to "javascript".
1197
+ */
1198
+ declare function startRepl(
1199
+ context?: { [key: string]: any },
1200
+ lang?:
1201
+ | "js"
1202
+ | "javascript"
1203
+ | "ts"
1204
+ | "typescript"
1205
+ | "jsx"
1206
+ | "tsx"
1207
+ | "coffee"
1208
+ | "coffeescript"
1209
+ ): void;
1210
+
1211
+ /**
1212
+ * Returns the absolute path to the root folder of the git/hg repo.
1213
+ *
1214
+ * This is done by running `git rev-parse --show-toplevel` and `hg root`.
1215
+ *
1216
+ * If `relativeTo` is provided, the git and hg commands will be executed in
1217
+ * that folder instead of in `pwd()`.
458
1218
  */
459
- declare const echo: typeof console.log;
460
-
461
- // ---------------
462
- // --- strings ---
463
- // ---------------
1219
+ declare function repoRoot(relativeTo?: string): string;
464
1220
 
465
1221
  /**
466
- * Remove ANSI control characters from a string.
1222
+ * Returns whether the provided path is ignored by git.
467
1223
  */
468
- declare function stripAnsi(input: string): string;
1224
+ declare function isGitignored(path: string): boolean;
469
1225
 
470
1226
  /**
471
- * Wrap a string in double quotes, and escape any double-quotes inside using `\"`.
1227
+ * Configures the default value of `trace` in functions which receive `trace`
1228
+ * as an option.
1229
+ *
1230
+ * - If called with `true`, the default value of `trace` in all functions which
1231
+ * receive a `trace` option will be changed to `console.error`.
1232
+ * - If called with `false`, the default value of `trace` in all functions which
1233
+ * receive a `trace` option will be changed to `undefined`.
1234
+ * - If called with any other value, the provided value will be used as the
1235
+ * default value of `trace` in all functions which receive a `trace` option.
1236
+ *
1237
+ * If you would like to make your own functions use the default value of
1238
+ * `trace` as set by this function (in order to get the same behavior as
1239
+ * yavascript API functions which do so), call `traceAll.getDefaultTrace()` to
1240
+ * get the value which should be used as the default value.
472
1241
  */
473
- declare function quote(input: string): string;
1242
+ declare const traceAll: ((
1243
+ trace: boolean | undefined | ((...args: Array<any>) => void)
1244
+ ) => void) & {
1245
+ getDefaultTrace(): ((...args: Array<any>) => void) | undefined;
1246
+ };
474
1247
 
475
- // Colors
1248
+ declare namespace JSX {
1249
+ /**
1250
+ * A string containing the expression that should be called to create JSX
1251
+ * elements.
1252
+ *
1253
+ * Defaults to "JSX.createElement".
1254
+ *
1255
+ * If changed, any JSX code loaded afterwards will use a different
1256
+ * expression.
1257
+ *
1258
+ * Note that if you change this, you need to verify that the following
1259
+ * expression always evaluates to `true` (by changing {@link is.JSX.Element}
1260
+ * and {@link is.JSX.Fragment}):
1261
+ * ```jsx
1262
+ * is.JSX.Element(<a />) && is.JSX.Fragment(<></>)
1263
+ * ```
1264
+ *
1265
+ * Failure to uphold this guarantee indicates a bug.
1266
+ */
1267
+ export let pragma: string;
476
1268
 
477
- /** Wrap a string with the ANSI control characters that will make it print as black text. */
478
- declare function black(input: string | number): string;
479
- /** Wrap a string with the ANSI control characters that will make it print as red text. */
480
- declare function red(input: string | number): string;
481
- /** Wrap a string with the ANSI control characters that will make it print as green text. */
482
- declare function green(input: string | number): string;
483
- /** Wrap a string with the ANSI control characters that will make it print as yellow text. */
484
- declare function yellow(input: string | number): string;
485
- /** Wrap a string with the ANSI control characters that will make it print as blue text. */
486
- declare function blue(input: string | number): string;
487
- /** Wrap a string with the ANSI control characters that will make it print as magenta text. */
488
- declare function magenta(input: string | number): string;
489
- /** Wrap a string with the ANSI control characters that will make it print as cyan text. */
490
- declare function cyan(input: string | number): string;
491
- /** Wrap a string with the ANSI control characters that will make it print as white text. */
492
- declare function white(input: string | number): string;
493
- /** Wrap a string with the ANSI control characters that will make it print as gray text. */
494
- declare function gray(input: string | number): string;
495
- /** Wrap a string with the ANSI control characters that will make it print as grey text. */
496
- declare function grey(input: string | number): string;
1269
+ /**
1270
+ * A string containing the expression that should be used as the first
1271
+ * parameter when creating JSX fragment elements.
1272
+ *
1273
+ * Defaults to "JSX.Fragment".
1274
+ *
1275
+ * If changed, any JSX code loaded afterwards will use a different
1276
+ * expression.
1277
+ *
1278
+ * Note that if you change this, you need to verify that the following
1279
+ * expression always evaluates to `true` (by changing {@link is.JSX.Element}
1280
+ * and {@link is.JSX.Fragment}):
1281
+ * ```jsx
1282
+ * is.JSX.Element(<a />) && is.JSX.Fragment(<></>)
1283
+ * ```
1284
+ *
1285
+ * Failure to uphold this guarantee indicates a bug.
1286
+ */
1287
+ export let pragmaFrag: string;
1288
+
1289
+ export const Element: unique symbol;
1290
+
1291
+ export interface Element<
1292
+ Props = { [key: string | symbol | number]: any },
1293
+ Type = any
1294
+ > {
1295
+ $$typeof: typeof Element;
1296
+ type: Type;
1297
+ props: Props;
1298
+ key: string | number | null;
1299
+ }
497
1300
 
498
- // Background Colors
1301
+ /**
1302
+ * The value which gets passed into the JSX element constructor (as
1303
+ * determined by {@link JSX.pragma}) when JSX fragment syntax is used (unless
1304
+ * {@link JSX.pragmaFrag} is changed).
1305
+ */
1306
+ export const Fragment: unique symbol;
499
1307
 
500
- /** Wrap a string with the ANSI control characters that will make it have a black background. */
501
- declare function bgBlack(input: string | number): string;
502
- /** Wrap a string with the ANSI control characters that will make it have a red background. */
503
- declare function bgRed(input: string | number): string;
504
- /** Wrap a string with the ANSI control characters that will make it have a green background. */
505
- declare function bgGreen(input: string | number): string;
506
- /** Wrap a string with the ANSI control characters that will make it have a yellow background. */
507
- declare function bgYellow(input: string | number): string;
508
- /** Wrap a string with the ANSI control characters that will make it have a blue background. */
509
- declare function bgBlue(input: string | number): string;
510
- /** Wrap a string with the ANSI control characters that will make it have a magenta background. */
511
- declare function bgMagenta(input: string | number): string;
512
- /** Wrap a string with the ANSI control characters that will make it have a cyan background. */
513
- declare function bgCyan(input: string | number): string;
514
- /** Wrap a string with the ANSI control characters that will make it have a white background. */
515
- declare function bgWhite(input: string | number): string;
1308
+ export type Fragment = Element<{}, typeof Fragment>;
516
1309
 
517
- // Modifiers
1310
+ /**
1311
+ * The JSX element constructor, which gets invoked whenever JSX syntax is
1312
+ * used (unless {@link JSX.pragma} is changed).
1313
+ */
1314
+ export const createElement: {
1315
+ <Type extends string | typeof Fragment | ((...args: any) => any)>(
1316
+ type: Type
1317
+ ): Element<{}, Type>;
1318
+ <
1319
+ Type extends string | typeof Fragment | ((...args: any) => any),
1320
+ Props extends { [key: string | number | symbol]: any }
1321
+ >(
1322
+ type: Type,
1323
+ props: Props
1324
+ ): Element<Props, Type>;
1325
+
1326
+ <
1327
+ Type extends string | typeof Fragment | ((...args: any) => any),
1328
+ Props extends { [key: string | number | symbol]: any },
1329
+ Children extends Array<any>
1330
+ >(
1331
+ type: Type,
1332
+ props: Props,
1333
+ ...children: Children
1334
+ ): Element<Props & { children: Children }, Type>;
1335
+
1336
+ <
1337
+ Type extends string | typeof Fragment | ((...args: any) => any),
1338
+ Children extends Array<any>
1339
+ >(
1340
+ type: Type,
1341
+ ...children: Children
1342
+ ): Element<{ children: Children }, Type>;
1343
+ };
1344
+ }
518
1345
 
519
- /** Wrap a string with the ANSI control character that resets all styling. */
520
- declare function reset(input: string | number): string;
521
- /** Wrap a string with the ANSI control characters that will make it print with a bold style. */
522
- declare function bold(input: string | number): string;
523
- /** Wrap a string with the ANSI control characters that will make it print with a dimmed style. */
524
- declare function dim(input: string | number): string;
525
- /** Wrap a string with the ANSI control characters that will make it print italicized. */
526
- declare function italic(input: string | number): string;
527
- /** Wrap a string with the ANSI control characters that will make it print underlined. */
528
- declare function underline(input: string | number): string;
529
- /** Wrap a string with ANSI control characters such that its foreground (text) and background colors are swapped. */
530
- declare function inverse(input: string | number): string;
531
- /** Wrap a string with ANSI control characters such that it is hidden. */
532
- declare function hidden(input: string | number): string;
533
- /** Wrap a string with the ANSI control characters that will make it print with a horizontal line through its center. */
534
- declare function strikethrough(input: string | number): string;
1346
+ declare const YAML: {
1347
+ /**
1348
+ * Parse a YAML document (`input`) into a JSON-compatible value.
1349
+ */
1350
+ parse(
1351
+ input: string,
1352
+ reviver?: (this: any, key: string, value: any) => any
1353
+ ): any;
535
1354
 
1355
+ /**
1356
+ * Convert a JSON-compatible value into a YAML document.
1357
+ */
1358
+ stringify(
1359
+ input: any,
1360
+ replacer?:
1361
+ | ((this: any, key: string, value: any) => any)
1362
+ | (number | string)[]
1363
+ | null,
1364
+ indent?: number
1365
+ ): string;
1366
+ };
1367
+
1368
+ declare const CSV: {
1369
+ /**
1370
+ * Parse a CSV string into an Array of Arrays of strings.
1371
+ *
1372
+ * The outer array holds the rows, and the inner arrays hold the items in
1373
+ * each row.
1374
+ */
1375
+ parse(input: string): Array<Array<string>>;
1376
+
1377
+ /**
1378
+ * Convert an Array of Arrays of strings into a CSV string.
1379
+ *
1380
+ * The outer array holds the rows, and the inner arrays hold the items in
1381
+ * each row.
1382
+ */
1383
+ stringify(input: Array<Array<string>>): string;
1384
+ };
1385
+
1386
+ interface RegExpConstructor {
1387
+ /** See https://github.com/tc39/proposal-regex-escaping */
1388
+ escape(str: any): string;
1389
+ }
1390
+
1391
+ // prettier-ignore
1392
+ /** Any integer in the range [0, 255]. */
1393
+ declare type byte =
1394
+ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15
1395
+ | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31
1396
+ | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47
1397
+ | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63
1398
+ | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79
1399
+ | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95
1400
+ | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111
1401
+ | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127
1402
+ | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143
1403
+ | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159
1404
+ | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175
1405
+ | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191
1406
+ | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207
1407
+ | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223
1408
+ | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239
1409
+ | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255;
1410
+
1411
+ // Convenience aliases to provide parity with TypeScript types.
1412
+ declare var number: NumberConstructor;
1413
+ declare var string: StringConstructor;
1414
+ declare var boolean: BooleanConstructor;
1415
+ declare var bigint: BigIntConstructor;
1416
+ declare var symbol: SymbolConstructor;
1417
+
1418
+ // ==========================================
536
1419
  // ------------------------------------------
537
1420
  // QuickJS APIs, which YavaScript builds upon
538
1421
  // ------------------------------------------
539
-
1422
+ // ==========================================
540
1423
  // Definitions of the globals and modules added by quickjs-libc
541
1424
 
542
1425
  /**
@@ -569,6 +1452,91 @@ declare var console: {
569
1452
  info: typeof print;
570
1453
  };
571
1454
 
1455
+ /** An object representing a file handle. */
1456
+ declare interface FILE {
1457
+ /**
1458
+ * Human-readable description of where this FILE points.
1459
+ *
1460
+ * If `target` is a number, the FILE was opened with fdopen, and `target` is
1461
+ * the fd. Otherwise, `target` will be an arbitrary string that describes the
1462
+ * file; it may be the absolute path to the file, the relative path to the
1463
+ * file at time of its opening, or some other string like "stdin" or
1464
+ * "tmpfile".
1465
+ *
1466
+ * You should *not* use this property for anything other than logging and
1467
+ * debugging. It is *only* provided for debugging and/or troubleshooting
1468
+ * purposes. The value of this property could change at any time when
1469
+ * upgrading yavascript, even if upgrading by a minor or patch release.
1470
+ */
1471
+ target: string | number;
1472
+
1473
+ /**
1474
+ * Close the file handle. Note that for files other than stdin/stdout/stderr,
1475
+ * the file will be closed automatically when the `FILE` object is
1476
+ * garbage-collected.
1477
+ */
1478
+ close(): void;
1479
+
1480
+ /** Outputs the string with the UTF-8 encoding. */
1481
+ puts(...strings: Array<string>): void;
1482
+
1483
+ /**
1484
+ * Formatted printf.
1485
+ *
1486
+ * The same formats as the standard C library `printf` are supported. Integer format types (e.g. `%d`) truncate the Numbers or BigInts to 32 bits. Use the `l` modifier (e.g. `%ld`) to truncate to 64 bits.
1487
+ */
1488
+ printf(fmt: string, ...args: Array<any>): void;
1489
+
1490
+ /** Flush the buffered file. Wrapper for C `fflush`. */
1491
+ flush(): void;
1492
+
1493
+ /** Sync the buffered file to disk. Wrapper for C `fsync`. */
1494
+ sync(): void;
1495
+
1496
+ /**
1497
+ * Seek to a given file position (whence is `std.SEEK_*`).
1498
+ *
1499
+ * `offset` can be a number or a bigint.
1500
+ */
1501
+ seek(offset: number, whence: number): void;
1502
+
1503
+ /** Return the current file position. */
1504
+ tell(): number;
1505
+
1506
+ /** Return the current file position as a bigint. */
1507
+ tello(): BigInt;
1508
+
1509
+ /** Return true if end of file. */
1510
+ eof(): boolean;
1511
+
1512
+ /** Return the associated OS handle. */
1513
+ fileno(): number;
1514
+
1515
+ /** Read `length` bytes from the file to the ArrayBuffer `buffer` at byte position `position` (wrapper to the libc `fread`). Returns the number of bytes read, or `0` if the end of the file has been reached. */
1516
+ read(buffer: ArrayBuffer, position: number, length: number): number;
1517
+
1518
+ /** Write `length` bytes from the ArrayBuffer `buffer` at byte position `position` into the file (wrapper to the libc `fwrite`). Returns the number of bytes written. */
1519
+ write(buffer: ArrayBuffer, position: number, length: number): number;
1520
+
1521
+ /**
1522
+ * Return the next line from the file, assuming UTF-8 encoding, excluding the trailing line feed or EOF.
1523
+ *
1524
+ * If the end of the file has been reached, then `null` will be returned instead of a string.
1525
+ *
1526
+ * Note: Although the trailing line feed has been removed, a carriage return (`\r`) may still be present.
1527
+ */
1528
+ getline(): string | null;
1529
+
1530
+ /** Read `maxSize` bytes from the file and return them as a string assuming UTF-8 encoding. If `maxSize` is not present, the file is read up its end. */
1531
+ readAsString(maxSize?: number): string;
1532
+
1533
+ /** Return the next byte from the file. Return -1 if the end of file is reached. */
1534
+ getByte(): number;
1535
+
1536
+ /** Write one byte to the file. */
1537
+ putByte(value: number): void;
1538
+ }
1539
+
572
1540
  declare module "std" {
573
1541
  /**
574
1542
  * Exit the process with the provided status code.
@@ -610,6 +1578,15 @@ declare module "std" {
610
1578
  basename?: string
611
1579
  ): { [key: string]: any };
612
1580
 
1581
+ /**
1582
+ * Return the resolved path to a module.
1583
+ *
1584
+ * @param filename - The relative or absolute path to the file to import. Relative paths are resolved relative to the file calling `importModule`, or `basename` if present.
1585
+ * @param basename - If present and `filename` is a relative path, `filename` will be resolved relative to this basename.
1586
+ * @returns The resolved module path.
1587
+ */
1588
+ export function resolveModule(filename: string, basename?: string): string;
1589
+
613
1590
  /**
614
1591
  * Load the file `filename` and return it as a string assuming UTF-8 encoding.
615
1592
  *
@@ -624,7 +1601,15 @@ declare module "std" {
624
1601
  *
625
1602
  * @param stackLevels - How many levels up the stack to search for a filename. Defaults to 0, which uses the current stack frame.
626
1603
  */
627
- export function getFileNameFromStack(stackLevels: number): string;
1604
+ export function getFileNameFromStack(stackLevels?: number): string;
1605
+
1606
+ /**
1607
+ * Return a boolean indicating whether the provided value is a FILE object.
1608
+ *
1609
+ * @param value - The value to check.
1610
+ * @returns Whether the value was a `FILE` or not.
1611
+ */
1612
+ export function isFILE(value: any): boolean;
628
1613
 
629
1614
  /**
630
1615
  * Open a file (wrapper to the libc `fopen()`).
@@ -665,7 +1650,7 @@ declare module "std" {
665
1650
  export function tmpfile(): FILE;
666
1651
 
667
1652
  /** Equivalent to `std.out.puts(str)`. */
668
- export function puts(str: string): void;
1653
+ export function puts(...strings: Array<string>): void;
669
1654
 
670
1655
  /** Equivalent to `std.out.printf(fmt, ...args)` */
671
1656
  export function printf(fmt: string, ...args: Array<any>): void;
@@ -825,68 +1810,6 @@ declare module "std" {
825
1810
  * - octal (0o prefix) and hexadecimal (0x prefix) numbers
826
1811
  */
827
1812
  export function parseExtJSON(str: string): any;
828
-
829
- /** An object representing a file handle. */
830
- export class FILE {
831
- /** Close the file. */
832
- close(): void;
833
-
834
- /** Outputs the string with the UTF-8 encoding. */
835
- puts(str: string): void;
836
-
837
- /**
838
- * Formatted printf.
839
- *
840
- * The same formats as the standard C library `printf` are supported. Integer format types (e.g. `%d`) truncate the Numbers or BigInts to 32 bits. Use the `l` modifier (e.g. `%ld`) to truncate to 64 bits.
841
- */
842
- printf(fmt: string, ...args: Array<any>): void;
843
-
844
- /** Flush the buffered file. Wrapper for C `fflush`. */
845
- flush(): void;
846
-
847
- /** Sync the buffered file to disk. Wrapper for C `fsync`. */
848
- sync(): void;
849
-
850
- /**
851
- * Seek to a given file position (whence is `std.SEEK_*`).
852
- *
853
- * `offset` can be a number or a bigint.
854
- */
855
- seek(
856
- offset: number,
857
- whence: typeof SEEK_SET | typeof SEEK_CUR | typeof SEEK_END
858
- ): void;
859
-
860
- /** Return the current file position. */
861
- tell(): number;
862
-
863
- /** Return the current file position as a bigint. */
864
- tello(): BigInt;
865
-
866
- /** Return true if end of file. */
867
- eof(): boolean;
868
-
869
- /** Return the associated OS handle. */
870
- fileno(): number;
871
-
872
- /** Read `length` bytes from the file to the ArrayBuffer `buffer` at byte position `position` (wrapper to the libc `fread`). Returns the number of bytes read, or `0` if the end of the file has been reached. */
873
- read(buffer: ArrayBuffer, position: number, length: number): number;
874
-
875
- /** Write `length` bytes from the ArrayBuffer `buffer` at byte position `position` into the file (wrapper to the libc `fwrite`). Returns the number of bytes written. */
876
- write(buffer: ArrayBuffer, position: number, length: number): number;
877
-
878
- /** Return the next line from the file, assuming UTF-8 encoding, excluding the trailing line feed. */
879
- getline(): string;
880
-
881
- /** Read `maxSize` bytes from the file and return them as a string assuming UTF-8 encoding. If `maxSize` is not present, the file is read up its end. */
882
- readAsString(maxSize?: number): string;
883
-
884
- /** Return the next byte from the file. Return -1 if the end of file is reached. */
885
- getByte(): number;
886
-
887
- /** Write one byte to the file. */
888
- putByte(value: number): void;
889
- }
890
1813
  }
891
1814
 
892
1815
  declare module "os" {
@@ -1151,6 +2074,24 @@ declare module "os" {
1151
2074
 
1152
2075
  /** Constant for the `options` argument of `waitpid`. */
1153
2076
  export var WNOHANG: number;
2077
+ /** Constant for the `options` argument of `waitpid`. */
2078
+ export var WUNTRACED: number;
2079
+
2080
+ /** Function to be used to interpret the 'status' return value of `waitpid`. */
2081
+ export function WEXITSTATUS(status: number): number;
2082
+ /** Function to be used to interpret the 'status' return value of `waitpid`. */
2083
+ export function WTERMSIG(status: number): number;
2084
+ /** Function to be used to interpret the 'status' return value of `waitpid`. */
2085
+ export function WSTOPSIG(status: number): number;
2086
+
2087
+ /** Function to be used to interpret the 'status' return value of `waitpid`. */
2088
+ export function WIFEXITED(status: number): boolean;
2089
+ /** Function to be used to interpret the 'status' return value of `waitpid`. */
2090
+ export function WIFSIGNALED(status: number): boolean;
2091
+ /** Function to be used to interpret the 'status' return value of `waitpid`. */
2092
+ export function WIFSTOPPED(status: number): boolean;
2093
+ /** Function to be used to interpret the 'status' return value of `waitpid`. */
2094
+ export function WIFCONTINUED(status: number): boolean;
1154
2095
 
1155
2096
  /** `dup` Unix system call. */
1156
2097
  export function dup(fd: number): number;
@@ -1164,16 +2105,19 @@ declare module "os" {
1164
2105
  /** Sleep for `delay_ms` milliseconds. */
1165
2106
  export function sleep(delay_ms: number): void;
1166
2107
 
1167
- export type Timer = number & { __is: "Timer" };
2108
+ export type OSTimer = { [Symbol.toStringTag]: "OSTimer" };
1168
2109
 
1169
2110
  /** Call the function func after delay ms. Return a handle to the timer. */
1170
- export function setTimeout(func: () => void, delay: number): Timer;
2111
+ export function setTimeout(
2112
+ func: (...args: any) => any,
2113
+ delay: number
2114
+ ): OSTimer;
1171
2115
 
1172
2116
  /** Cancel a timer. */
1173
- export function clearTimeout(handle: Timer): void;
2117
+ export function clearTimeout(handle: OSTimer): void;
1174
2118
 
1175
- /** Return a string representing the platform: "linux", "darwin", "win32" or "js". */
1176
- export var platform: "linux" | "darwin" | "win32" | "js";
2119
+ /** Return a string representing the platform: "linux", "darwin", "win32", "freebsd", or "js" (emscripten). */
2120
+ export var platform: "linux" | "darwin" | "win32" | "freebsd" | "js";
1177
2121
 
1178
2122
  /**
1179
2123
  * Things that can be put into Worker.postMessage.
@@ -1261,6 +2205,12 @@ declare module "os" {
1261
2205
 
1262
2206
  /** `access` Unix system call; checks if a file is readable, writable, executable, and/or exists (use {@link R_OK}, {@link W_OK}, {@link X_OK}, and/or {@link F_OK} for `accessMode`). Throws a descriptive error (with errno property) if the requested access is not available; otherwise, returns undefined. */
1263
2207
  export function access(path: string, accessMode: number): void;
2208
+
2209
+ /** gets the path to the executable which is executing this JS code. might be a relative path or symlink. */
2210
+ export function execPath(): string;
2211
+
2212
+ /** changes the access permission bits of the file at `path` using the octal number `mode`. */
2213
+ export function chmod(path: string, mode: number): void;
1264
2214
  }
1265
2215
 
1266
2216
  /**
@@ -1368,3 +2318,193 @@ declare interface InspectFunction {
1368
2318
  */
1369
2319
  declare var inspect: InspectFunction;
1370
2320
 
2321
+ /**
2322
+ * A class which represents a module namespace object. Note, however, that
2323
+ * instances of this class cannot be constructed manually, and must instead be
2324
+ * obtained from `import * as`, `import()`, `std.importModule`, or `require`.
2325
+ *
2326
+ * The static properties on `Module` let you configure the module loader
2327
+ * (import/export/require). You can use these properties to add support for
2328
+ * importing new filetypes.
2329
+ */
2330
+ declare class Module {
2331
+ /** A module namespace object has arbitrary exports. */
2332
+ [key: string | number | symbol]: any;
2333
+
2334
+ /**
2335
+ * Module objects are not constructable.
2336
+ *
2337
+ * You must instead obtain them using import or require.
2338
+ */
2339
+ private constructor();
2340
+
2341
+ /**
2342
+ * Returns true if `target` is a module namespace object.
2343
+ */
2344
+ static [Symbol.hasInstance](target: any): target is Module;
2345
+
2346
+ /**
2347
+ * A list of filetype extensions that may be omitted from an import specifier
2348
+ * string.
2349
+ *
2350
+ * Defaults to `[".js"]`. You can add more strings to this array to
2351
+ * make the engine search for additional files when resolving a
2352
+ * require/import.
2353
+ *
2354
+ * See the doc comment on {@link require} for more information.
2355
+ *
2356
+ * NOTE: If you add a new extension to this array, you will likely also want
2357
+ * to add to {@link Module.compilers}.
2358
+ */
2359
+ static searchExtensions: Array<string>;
2360
+
2361
+ /**
2362
+ * User-defined functions which will handle getting the JavaScript code
2363
+ * associated with a module.
2364
+ *
2365
+ * The key for each property in this object should be a file extension
2366
+ * string with a leading dot, eg `".jsx"`. The value for each property should
2367
+ * be a function which receives (1) the filepath to a module, and (2) that
2368
+ * file's content as a UTF-8 string, and the function should return a string
2369
+ * containing JavaScript code that corresponds to that module. In most cases,
2370
+ * these functions will compile the contents of the file from one format into JavaScript.
2371
+ *
2372
+ * The function does not have to use the second 'content' argument it
2373
+ * receives (ie. when loading binary files).
2374
+ *
2375
+ * By adding to this object, you can make it possible to import non-js
2376
+ * filetypes; compile-to-JS languages like JSX, TypeScript, and CoffeeScript
2377
+ * can be compiled at import time, and asset files like .txt files or .png
2378
+ * files can be converted into an appropriate data structure at import time.
2379
+ *
2380
+ * As an example, to make it possible to import .txt files, you might do:
2381
+ * ```js
2382
+ * import * as std from "std";
2383
+ *
2384
+ * Module.compilers[".txt"] = (filename, content) => {
2385
+ * return `export default ${JSON.stringify(content)}`;
2386
+ * }
2387
+ * ```
2388
+ * (leveraging `JSON.stringify`'s ability to escape quotes).
2389
+ *
2390
+ * Then, later in your code, you can do:
2391
+ * ```js
2392
+ * import names from "./names.txt";
2393
+ * ```
2394
+ *
2395
+ * And `names` will be a string containing the contents of names.txt.
2396
+ *
2397
+ * NOTE: When adding to this object, you may also wish to add to
2398
+ * {@link Module.searchExtensions}.
2399
+ */
2400
+ static compilers: {
2401
+ [extensionWithDot: string]: (filename: string, content: string) => string;
2402
+ };
2403
+
2404
+ /**
2405
+ * Create a virtual built-in module whose exports consist of the own
2406
+ * enumerable properties of `obj`.
2407
+ */
2408
+ static define(name: string, obj: { [key: string]: any }): void;
2409
+ }
2410
+
2411
+ /**
2412
+ * Synchronously import a module.
2413
+ *
2414
+ * `source` will be resolved relative to the calling file.
2415
+ *
2416
+ * If `source` does not have a file extension, and a file without an extension
2417
+ * cannot be found, the engine will check for files with the extensions in
2418
+ * {@link Module.searchExtensions}, and use one of those if present. This
2419
+ * behavior also happens when using normal `import` statements.
2420
+ *
2421
+ * For example, if you write:
2422
+ *
2423
+ * ```js
2424
+ * import something from "./somewhere";
2425
+ * ```
2426
+ *
2427
+ * but there's no file named `somewhere` in the same directory as the file
2428
+ * where that import appears, and `Module.searchExtensions` is the default
2429
+ * value:
2430
+ *
2431
+ * ```js
2432
+ * [".js"]
2433
+ * ```
2434
+ *
2435
+ * then the engine will look for `somewhere.js`. If that doesn't exist, the
2436
+ * engine will look for `somewhere/index.js`. If *that* doesn't exist, an error
2437
+ * will be thrown.
2438
+ *
2439
+ * If you add more extensions to `Module.searchExtensions`, then the engine
2440
+ * will use those, too. It will search in the same order as the strings appear
2441
+ * in the `Module.searchExtensions` array.
2442
+ */
2443
+ declare var require: ((source: string) => { [key: string]: any }) & {
2444
+ /**
2445
+ * Resolves the normalized path to a modules, relative to the calling file.
2446
+ */
2447
+ resolve: (source: string) => string;
2448
+ };
2449
+
2450
+ declare var setTimeout: typeof import("os").setTimeout;
2451
+ declare var clearTimeout: typeof import("os").clearTimeout;
2452
+
2453
+ declare type Interval = { [Symbol.toStringTag]: "Interval" };
2454
+
2455
+ declare function setInterval(func: (...args: any) => any, ms: number): Interval;
2456
+ declare function clearInterval(interval: Interval): void;
2457
+
2458
+ interface StringConstructor {
2459
+ /**
2460
+ * A no-op template literal tag.
2461
+ *
2462
+ * https://github.com/tc39/proposal-string-cooked
2463
+ */
2464
+ cooked(
2465
+ strings: readonly string[] | ArrayLike<string>,
2466
+ ...substitutions: any[]
2467
+ ): string;
2468
+
2469
+ /**
2470
+ * Remove leading minimum indentation from the string.
2471
+ * The first line of the string must be empty.
2472
+ *
2473
+ * https://github.com/tc39/proposal-string-dedent
2474
+ */
2475
+ dedent: {
2476
+ /**
2477
+ * Remove leading minimum indentation from the string.
2478
+ * The first line of the string must be empty.
2479
+ *
2480
+ * https://github.com/tc39/proposal-string-dedent
2481
+ */
2482
+ (input: string): string;
2483
+
2484
+ /**
2485
+ * Remove leading minimum indentation from the template literal.
2486
+ * The first line of the string must be empty.
2487
+ *
2488
+ * https://github.com/tc39/proposal-string-dedent
2489
+ */
2490
+ (
2491
+ strings: readonly string[] | ArrayLike<string>,
2492
+ ...substitutions: any[]
2493
+ ): string;
2494
+
2495
+ /**
2496
+ * Wrap another template tag function such that tagged literals
2497
+ * become dedented before being passed to the wrapped function.
2498
+ *
2499
+ * https://www.npmjs.com/package/string-dedent#usage
2500
+ */
2501
+ <
2502
+ Func extends (
2503
+ strings: readonly string[] | ArrayLike<string>,
2504
+ ...substitutions: any[]
2505
+ ) => string
2506
+ >(
2507
+ input: Func
2508
+ ): Func;
2509
+ };
2510
+ }