yavascript 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/yavascript.d.ts CHANGED
@@ -4,44 +4,19 @@
4
4
  // ---------------
5
5
  // ===============
6
6
  /**
7
- * Prints help and usage text about the provided value, if any is available.
7
+ * Prints a link to the YavaScript help docs for the currently-running version
8
+ * of YavaScript.
9
+ *
10
+ * For the latest help docs, see:
11
+ * https://github.com/suchipi/yavascript/blob/main/meta/generated-docs/README.md
8
12
  */
9
- declare var help: {
10
- /**
11
- * Prints help and usage text about the provided value, if any is available.
12
- */
13
- (value?: any): void;
14
-
15
- /**
16
- * Set the help text for the provided value to the provided string.
17
- *
18
- * If the value is later passed into the `help` function, the provided text
19
- * will be printed.
20
- */
21
- setHelpText: {
22
- /**
23
- * Set the help text for the provided value to the provided string.
24
- *
25
- * If the value is later passed into the `help` function, the provided text
26
- * will be printed.
27
- */
28
- (value: object, text: string): void;
29
-
30
- /**
31
- * Lazily sets the help text for the provided value using the provided
32
- * string-returning function.
33
- *
34
- * The first time help text is requested for the value, the string-returning
35
- * function will be called, and its result will be registered as the help
36
- * text for the value. Afterwards, the function will not be called again;
37
- * instead, it will re-use the text returned from the first time the
38
- * function was called.
39
- */
40
- lazy(value: object, getText: () => string): void;
41
- };
42
- };
13
+ declare function help(): void;
43
14
 
44
- /** Info about the currently-running yavascript binary */
15
+ /**
16
+ * The `yavascript` global contains metadata about the currently-running
17
+ * yavascript binary, as well as access to yavascript's compilers for
18
+ * compile-to-js languages.
19
+ */
45
20
  declare const yavascript: {
46
21
  /**
47
22
  * The version of the currently-running yavascript binary.
@@ -62,48 +37,107 @@ declare const yavascript: {
62
37
  */
63
38
  version: string;
64
39
 
65
- /** The processor architecture we're running on. */
40
+ /**
41
+ * The processor architecture of the currently-running `yavascript` binary.
42
+ */
66
43
  arch: "x86_64" | "arm64";
67
44
 
68
45
  /**
69
- * The version of the ecma262 standard supported by the currently-running yavascript binary.
46
+ * The version of the ecma262 standard supported by the currently-running
47
+ * yavascript binary.
70
48
  *
71
- * Will always be in the format "ES" + a year. Is never lower than ES2020.
49
+ * Currently, this is always "ES2020", but if future versions of yavascript
50
+ * support a newer version of the standard, this will change. In that event,
51
+ * this property will always be in the format of "ES" + a year, and will never
52
+ * be lower than ES2020.
72
53
  */
73
54
  ecmaVersion: string;
74
55
 
75
- /** The compilers yavascript uses internally to load files. */
56
+ /**
57
+ * The compilers yavascript uses internally to load files.
58
+ *
59
+ * Each function returns a JavaScript source code string.
60
+ */
76
61
  compilers: {
62
+ /**
63
+ * The function yavascript uses internally to load JavaScript files.
64
+ *
65
+ * You might think this would be a no-op, but we do some CommonJS/ECMAScript
66
+ * Module interop transformations here.
67
+ */
77
68
  js(
78
69
  code: string,
79
70
  options?: { filename?: string; expression?: boolean }
80
71
  ): string;
81
72
 
73
+ /**
74
+ * The function yavascript uses internally to load [TypeScript JSX](https://www.typescriptlang.org/docs/handbook/jsx.html) files.
75
+ *
76
+ * yavascript uses [Sucrase 3.35.0](https://sucrase.io/) to load TypeScript JSX syntax. yavascript doesn't do typechecking of TypeScript syntax.
77
+ */
82
78
  tsx(
83
79
  code: string,
84
80
  options?: { filename?: string; expression?: boolean }
85
81
  ): string;
86
82
 
83
+ /**
84
+ * The function yavascript uses internally to load [TypeScript](https://www.typescriptlang.org/) files.
85
+ *
86
+ * yavascript uses [Sucrase 3.35.0](https://sucrase.io/) to load TypeScript syntax. yavascript doesn't do typechecking of TypeScript syntax.
87
+ */
87
88
  ts(
88
89
  code: string,
89
90
  options?: { filename?: string; expression?: boolean }
90
91
  ): string;
91
92
 
93
+ /**
94
+ * The function yavascript uses internally to load JSX files.
95
+ *
96
+ * yavascript uses [Sucrase 3.35.0](https://sucrase.io/) to load JSX syntax.
97
+ *
98
+ * See {@link JSX} for info about configuring JSX pragma, swapping out the
99
+ * default `createElement` implementation, etc.
100
+ */
92
101
  jsx(
93
102
  code: string,
94
103
  options?: { filename?: string; expression?: boolean }
95
104
  ): string;
96
105
 
106
+ /**
107
+ * The function yavascript uses internally to load [CoffeeScript](https://coffeescript.org/) files.
108
+ *
109
+ * yavascript embeds CoffeeScript 2.7.0.
110
+ */
97
111
  coffee(
98
112
  code: string,
99
113
  options?: { filename?: string; expression?: boolean }
100
114
  ): string;
101
115
 
116
+ /**
117
+ * The function yavascript uses internally to load [Civet](https://civet.dev/) files.
118
+ *
119
+ * yavascript embeds Civet 0.9.0.
120
+ */
102
121
  civet(
103
122
  code: string,
104
123
  options?: { filename?: string; expression?: boolean }
105
124
  ): string;
106
125
 
126
+ /**
127
+ * The function yavascript uses internally to load files which don't have an
128
+ * extension.
129
+ *
130
+ * It tries to parse the file as each of the following languages, in order,
131
+ * until it finds one which doesn't have a syntax error:
132
+ *
133
+ * - JSX
134
+ * - TSX
135
+ * - Civet
136
+ * - CoffeeScript
137
+ *
138
+ * If none of the languages work, the file's original content gets used so
139
+ * that a syntax error can be reported to the user.
140
+ */
107
141
  autodetect(
108
142
  code: string,
109
143
  options?: { filename?: string; expression?: boolean }
@@ -120,9 +154,9 @@ declare const yavascript: {
120
154
  declare const env: { [key: string]: string | undefined };
121
155
 
122
156
  /**
123
- * Parse command line --flags into an object of flags and an array of
124
- * positional arguments. This function is opinionated; if it doesn't meet your
125
- * needs, you can parse the `scriptArgs` global manually.
157
+ * A function which parses command line `--flags` into an object of flags and an
158
+ * array of positional arguments. This function is opinionated; if it doesn't
159
+ * meet your needs, you can parse the {@link scriptArgs} global manually.
126
160
  *
127
161
  * Flags `--like-this`, `--like_this`, or `--LIKE_THIS` get converted into
128
162
  * property names `likeThis` on the returned flags object.
@@ -133,34 +167,145 @@ declare const env: { [key: string]: string | undefined };
133
167
  * Anything that appears after `--` is considered a positional argument instead
134
168
  * of a flag. `--` is not present in the returned positional arguments Array.
135
169
  *
136
- * @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 `Path`. `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.
137
- * @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.
170
+ * `parseScriptArgs` accepts two optional parameters: `hints` and `argv`.
171
+ *
172
+ * ## hints
138
173
  *
139
- * @returns An object with three properties: `flags`, `args`, and `metadata`. `flags` is an object whose keys are camelCase flag names and whose values are strings, booleans, numbers, or `Path`s corresponding to the input command-line args. `args` is an Array of positional arguments, as found on the command-line. `metadata` contains information about what name and type the flags got mapped to.
174
+ * If present, `hints` should be an object whose keys are flag names (in
175
+ * lowerCamelCase) and whose values indicate what type to treat that flag as.
176
+ * Valid property values are `String`, `Boolean`, `Number`, and `Path`. `Path`
177
+ * will resolve relative paths into absolute paths for you. If no hints object
178
+ * is specified, `parseScriptArgs` will do its best to guess the types.
179
+ *
180
+ * ## argv
181
+ *
182
+ * The `argv` parameter, if present, should be an array containing the command
183
+ * line flags you want to parse. If you don't provide one, `scriptArgs.slice(2)`
184
+ * will be used (we slice 2 in order to skip the yavascript binary and script
185
+ * name). If you pass in an array here, it should only contain command-line
186
+ * flags, not the binary being called.
187
+ *
188
+ * ## Return Value
189
+ *
190
+ * `parseScriptArgs` returns an object with three properties: `flags`, `args`,
191
+ * and `metadata`.
192
+ *
193
+ * - `flags` is an object whose keys are lowerCamelCase flag names and whose
194
+ * values are strings, booleans, numbers, or `Path`s corresponding to the
195
+ * input command-line args.
196
+ * - `args` is an Array of positional arguments, as found on the command-line.
197
+ * - `metadata` contains information about what name and type the flags got
198
+ * mapped to.
199
+ *
200
+ * @param hints - An object whose keys are flag names (in lowerCamelCase) and
201
+ * whose values indicate what type to treat that flag as. Valid property values
202
+ * are `String`, `Boolean`, `Number`, and `Path`. `Path` will resolve relative
203
+ * paths into absolute paths for you. If no hints object is specified,
204
+ * `parseScriptArgs` will do its best to guess, based on the command-line args.
205
+ * @param argv - An array containing the command line flags you want to parse.
206
+ * If unspecified, `scriptArgs.slice(2)` will be used (we slice 2 in order to
207
+ * skip the yavascript binary and script name). If you pass in an array here, it
208
+ * should only contain command-line flags, not the binary being called.
209
+ *
210
+ * @returns A {@link ParseScriptArgsResult}, which is an object with three
211
+ * properties: `flags`, `args`, and `metadata`. `flags` is an object whose keys
212
+ * are camelCase flag names and whose values are strings, booleans, numbers, or
213
+ * `Path`s corresponding to the input command-line args. `args` is an Array of
214
+ * positional arguments, as found on the command-line. `metadata` contains
215
+ * information about what name and type the flags got mapped to.
140
216
  */
141
217
  declare function parseScriptArgs(
142
218
  hints?: {
143
219
  [key: string]: typeof String | typeof Boolean | typeof Number | typeof Path;
144
220
  },
145
221
  args?: Array<string>
146
- ): {
222
+ ): ParseScriptArgsResult;
223
+
224
+ /**
225
+ * The return type of {@link parseScriptArgs}.
226
+ *
227
+ * The `flags` property contains the values for any command-line `--flags`, with
228
+ * key names converted to `lowerCamelCase`.
229
+ *
230
+ * The `args` property contains an array of those command-line arguments which
231
+ * weren't associated with a flag.
232
+ *
233
+ * The `metadata` property contains information about the parsing process,
234
+ * including what case changes were applied to the keys, which hints were used,
235
+ * and which properties had their type guessed because no corresponding hint was
236
+ * available.
237
+ */
238
+ declare interface ParseScriptArgsResult {
239
+ /**
240
+ * The values for any command-line `--flags`, with key names converted to `lowerCamelCase`.
241
+ */
147
242
  flags: { [key: string]: any };
243
+ /**
244
+ * An array of those command-line arguments which weren't associated with a flag.
245
+ */
148
246
  args: Array<string>;
247
+ /**
248
+ * Information about the parsing process, including what case changes were
249
+ * applied to the keys, which hints were used, and which properties had their
250
+ * type guessed because no corresponding hint was available.
251
+ */
149
252
  metadata: {
253
+ /**
254
+ * An object whose keys are the verbatim flags from the command-line, and
255
+ * whose values are the lowerCamelCase names they were converted to in the
256
+ * `flags` property of the {@link ParseScriptArgsResult}.
257
+ */
150
258
  keys: {
151
259
  [key: string]: string | undefined;
152
260
  };
261
+ /**
262
+ * An object whose keys are the lowerCamelCase flag names, and whose values
263
+ * are strings indicating the hint values that were specified for those
264
+ * flags.
265
+ */
153
266
  hints: {
154
- [key: string]: string | undefined;
267
+ [key: string]: "path" | "number" | "boolean" | "string" | undefined;
155
268
  };
269
+ /**
270
+ * An object indicating which flags we inferred the type of, because no
271
+ * corresponding hint was present.
272
+ *
273
+ * The keys are the lowerCamelCase flag names, and the values are strings
274
+ * indicating what type we guessed for that flag.
275
+ *
276
+ * If you're seeing incorrect inference, consider passing a `hints` argument
277
+ * to {@link parseScriptArgs}.
278
+ */
156
279
  guesses: {
157
- [key: string]: string | undefined;
280
+ [key: string]: "number" | "boolean" | "string" | undefined;
158
281
  };
159
282
  };
160
- };
283
+ }
161
284
 
162
285
  /**
163
286
  * Read the contents of a file from disk.
287
+ *
288
+ * With no options specified, it reads the file as UTF-8 and returns a string:
289
+ *
290
+ * ```ts
291
+ * const contents = readFile("README.md");
292
+ * console.log(contents);
293
+ * // "# yavascript\n\nYavaScript is a cross-platform bash-like script runner and repl which is distributed as a single\nstatically-linked binary..."
294
+ * ```
295
+ *
296
+ * But, if you pass `{ binary: true }` as the second argument, it returns an
297
+ * ArrayBuffer containing the raw bytes from the file:
298
+ *
299
+ * ```ts
300
+ * const contents = readFile("README.md", { binary: true });
301
+ * console.log(contents);
302
+ * // ArrayBuffer {
303
+ * // │0x00000000│ 23 20 79 61 76 61 73 63 72 69 70 74 0A 0A 59 61
304
+ * // │0x00000010│ 76 61 53 63 72 69 70 74 20 69 73 20 61 20 63 72
305
+ * // │0x00000020│ 6F 73 73 2D 70 6C 61 74 66 6F 72 6D 20 62 61 73
306
+ * // │0x00000030│ 68 2D 6C 69 6B 65 20 73 63 72 69 70 74 20 72 75
307
+ * // ...
308
+ * ```
164
309
  */
165
310
  declare const readFile: {
166
311
  /**
@@ -250,12 +395,16 @@ declare function remove(path: string | Path): void;
250
395
  declare function exists(path: string | Path): boolean;
251
396
 
252
397
  /**
253
- * Creates directories for each of the provided path components,
254
- * if they don't already exist.
398
+ * Copies a file or folder from one location to another.
399
+ * Folders are copied recursively.
255
400
  *
256
- * Provides the same functionality as the command `mkdir -p`.
401
+ * Provides the same functionality as the command `cp -R`.
257
402
  */
258
- declare function ensureDir(path: string | Path): string;
403
+ declare function copy(
404
+ from: string | Path,
405
+ to: string | Path,
406
+ options?: CopyOptions
407
+ ): void;
259
408
 
260
409
  /**
261
410
  * Options for {@link copy}.
@@ -269,30 +418,35 @@ declare type CopyOptions = {
269
418
  */
270
419
  whenTargetExists?: "overwrite" | "skip" | "error";
271
420
 
272
- /**
273
- * If provided, this function will be called multiple times as `copy`
274
- * traverses the filesystem, to help you understand what's going on and/or
275
- * troubleshoot things. In most cases, it makes sense to use a logging
276
- * function here, like so:
277
- *
278
- * ```js
279
- * copy("./source", "./destination", { trace: console.log });
280
- * ```
281
- */
282
- trace?: (...args: Array<any>) => void;
283
- };
421
+ /** Options which control logging. */
422
+ logging?: {
423
+ /**
424
+ * If provided, this function will be called multiple times as `copy`
425
+ * traverses the filesystem, to help you understand what's going on and/or
426
+ * troubleshoot things. In most cases, it makes sense to use a logging
427
+ * function here, like so:
428
+ *
429
+ * ```js
430
+ * copy("./source", "./destination", {
431
+ * logging: { trace: console.log },
432
+ * });
433
+ * ```
434
+ *
435
+ * Defaults to the current value of {@link logger.trace}. `logger.trace`
436
+ * defaults to a no-op function.
437
+ */
438
+ trace?: (...args: Array<any>) => void;
284
439
 
285
- /**
286
- * Copies a file or folder from one location to another.
287
- * Folders are copied recursively.
288
- *
289
- * Provides the same functionality as the command `cp -R`.
290
- */
291
- declare function copy(
292
- from: string | Path,
293
- to: string | Path,
294
- options?: CopyOptions
295
- ): void;
440
+ /**
441
+ * An optional, user-provided logging function to be used for informational
442
+ * messages.
443
+ *
444
+ * Defaults to the current value of {@link logger.info}. `logger.info`
445
+ * defaults to a function which writes to stderr.
446
+ */
447
+ info?: (...args: Array<any>) => void;
448
+ };
449
+ };
296
450
 
297
451
  /**
298
452
  * Rename the file or directory at the specified path.
@@ -301,32 +455,93 @@ declare function copy(
301
455
  */
302
456
  declare function rename(from: string | Path, to: string | Path): void;
303
457
 
304
- /** An object that represents a filesystem path. */
458
+ /**
459
+ * A class which represents a filesystem path. The class contains various
460
+ * methods that make it easy to work with filesystem paths; there are methods
461
+ * for adding/removing path components, converting between absolute and relative
462
+ * paths, getting the basename and dirname, and more.
463
+ *
464
+ * All functions in yavascript which accept path strings as arguments also
465
+ * accept Path objects. As such, it is recommended that all filesystem paths in
466
+ * your programs are Path objects rather than strings.
467
+ *
468
+ * Every Path object has two properties: `segments` and `separator`. `segments`
469
+ * is an Array of strings containing all the non-slash portions of the path. For
470
+ * example, the path "one/two/three" would have segments `["one", "two",
471
+ * "three"]`. `separator` is which slash is used to separate the segments;
472
+ * either `"/"` or `"\"`.
473
+ *
474
+ * A Path object can represent either a POSIX-style path or a win32-style path.
475
+ * For the win32 style, UNC paths are supported. POSIX-style paths starting with
476
+ * "/" (eg. "/usr/bin") have an empty string at the beginning of their segments
477
+ * array to represent the left-hand-side of the leading slash. For instance,
478
+ * "/usr/bin" would have segments `["", "usr", "bin"]`.
479
+ */
305
480
  declare class Path {
306
- /** The character used to separate path segments on this OS. */
481
+ /**
482
+ * The character used to separate path segments on the current operating
483
+ * system where yavascript is running.
484
+ *
485
+ * Its value is either a forward slash (`"/"`) or a backslash (`"\"`). Its value
486
+ * is a backslash on windows, and a forward slash on all other operating
487
+ * systems.
488
+ */
307
489
  static readonly OS_SEGMENT_SEPARATOR: "/" | "\\";
308
490
 
309
491
  /**
310
- * The character used to separate entries within the PATH environment
311
- * variable on this OS.
492
+ * The character used to separate entries within the system's `PATH`
493
+ * environment variable on the current operating system where yavascript is
494
+ * running.
495
+ *
496
+ * The `PATH` environment variable contains a list of folders wherein
497
+ * command-line programs can be found, separated by either a colon (`:`) or a
498
+ * semicolon (`;`). The value of `OS_ENV_VAR_SEPARATOR` is a semicolon on
499
+ * windows, and a colon on all other operating systems.
500
+ *
501
+ * The `PATH` environment variable can be accessed by yavascript programs via
502
+ * `env.PATH`. Therefore, one can contain a list of all entries in the `PATH`
503
+ * environment variable via:
504
+ *
505
+ * ```ts
506
+ * const folders: Array<string> = env.PATH.split(Path.OS_ENV_VAR_SEPARATOR);
507
+ * ```
312
508
  */
313
509
  static readonly OS_ENV_VAR_SEPARATOR: ":" | ";";
314
510
 
315
511
  /**
316
- * A list of suffixes that could appear in the filename for a program on the
317
- * current OS. For instance, on Windows, programs often end with ".exe".
512
+ * A Set of filename extension strings that command-line programs may end with
513
+ * on the current operating system where yavascript is running. For instance,
514
+ * on Windows, programs often end with ".exe". Each of these strings contains
515
+ * a leading dot (`.`).
318
516
  *
319
- * On Unix-like OSes, this is empty, On Windows, it's based on `env.PATHEXT`.
517
+ * On windows, this value is based on the `PATHEXT` environment variable,
518
+ * which defaults to ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
519
+ * on Windows Vista and up. If `PATHEXT` is not defined, that default value is
520
+ * used.
521
+ *
522
+ * On all other operating systems, this Set is empty.
320
523
  */
321
524
  static readonly OS_PROGRAM_EXTENSIONS: ReadonlySet<string>;
322
525
 
323
- /** Split one or more path strings into an array of path segments. */
526
+ /**
527
+ * Converts a string (or array of strings) into an array of path segment
528
+ * strings (the parts between the slashes).
529
+ *
530
+ * Example:
531
+ *
532
+ * ```ts
533
+ * const input = ["hi", "there/every/one", "yeah\\yup"];
534
+ * const result = Path.splitToSegments(input);
535
+ * // result is ["hi", "there", "every", "one", "yeah", "yup"]
536
+ * ```
537
+ */
324
538
  static splitToSegments(inputParts: Array<string> | string): Array<string>;
325
539
 
326
540
  /**
327
- * Search the provided path string or strings for a path separator character,
328
- * and return it. If none is found, return `fallback`, which defaults to the
329
- * OS's path segment separator.
541
+ * Searches the provided path string or strings for a path separator character
542
+ * (either forward slash or backslash), and returns the one it finds. If
543
+ * neither is found, it returns the `fallback` arg, which defaults to the
544
+ * current OS's path segment separator (`Path.OS_SEGMENT_SEPARATOR`).
330
545
  */
331
546
  static detectSeparator<Fallback extends string | null = string>(
332
547
  input: Array<string> | string,
@@ -334,30 +549,46 @@ declare class Path {
334
549
  fallback: Fallback = Path.OS_SEGMENT_SEPARATOR
335
550
  ): string | Fallback;
336
551
 
337
- /** Join together one or more paths. */
338
- static join(...inputs: Array<string | Path | Array<string | Path>>): Path;
339
-
340
- /**
341
- * Turns the input path(s) into an absolute path by resolving all `.` and `..`
342
- * segments, using `pwd()` as a base dir to use when resolving leading `.` or
343
- * `..` segments.
344
- */
345
- static resolve(...inputs: Array<string | Path | Array<string | Path>>): Path;
346
-
347
552
  /**
348
- * Concatenates the input path(s) and then resolves all non-leading `.` and
349
- * `..` segments.
553
+ * Creates a new Path by concatenating the input path(s) and then resolving all
554
+ * non-leading `.` and `..` segments. In other words:
555
+ *
556
+ * - Segments containing `.` are removed
557
+ * - Segments containing `..` are removed, along with the segment preceding
558
+ * them.
559
+ *
560
+ * Note that any `.` or `..` segments at the beginning of the path (ie.
561
+ * "leading segments") are not removed.
350
562
  */
351
563
  static normalize(
352
564
  ...inputs: Array<string | Path | Array<string | Path>>
353
565
  ): Path;
354
566
 
355
567
  /**
356
- * Return whether the provided path is absolute; that is, whether it
357
- * starts with either `/` or a drive letter (ie `C:`).
568
+ * Returns a boolean indicating whether the provided path is absolute; that
569
+ * is, whether it starts with either a slash (`/` or `\`) or a drive letter
570
+ * (ie `C:`).
571
+ *
572
+ * Note that Windows UNC Paths (eg. `\\MYSERVER\share$\`) are considered
573
+ * absolute.
358
574
  */
359
575
  static isAbsolute(path: string | Path): boolean;
360
576
 
577
+ /**
578
+ * Creates a new Path containing the user-provided segments and separator. In
579
+ * most cases, you won't need to do this, and can use `new Path(...)` instead.
580
+ *
581
+ * If unspecified, the `separator` parameter defaults to
582
+ * `Path.OS_SEGMENT_SEPARATOR`.
583
+ */
584
+ static fromRaw(segments: Array<string>, separator?: string): Path;
585
+
586
+ /**
587
+ * Creates a new Path object using the provided input(s), which will be
588
+ * concatenated together in order left-to-right.
589
+ */
590
+ constructor(...inputs: Array<string | Path | Array<string | Path>>);
591
+
361
592
  /**
362
593
  * An array of the path segments that make up this path.
363
594
  *
@@ -370,93 +601,95 @@ declare class Path {
370
601
  /**
371
602
  * The path separator that should be used to turn this path into a string.
372
603
  *
373
- * Will be either `/` or `\`.
604
+ * Will be either `"/"` or `"\"`.
374
605
  */
375
606
  separator: string;
376
607
 
377
- /** Create a new Path object using the provided input(s). */
378
- constructor(...inputs: Array<string | Path | Array<string | Path>>);
379
-
380
- /** Create a new Path object using the provided segments and separator. */
381
- static from(segments: Array<string>, separator: string): Path;
382
-
383
- /**
384
- * Create an absolute path by `concat`ting `subpaths` onto this Path (which is
385
- * presumed to be an absolute path) and then using `normalize()` on the
386
- * result. If the result is not an absolute path, an error will be thrown.
387
- */
388
- resolve(...subpaths: Array<string | Path>): Path;
389
-
390
608
  /**
391
- * Resolve all non-leading `.` and `..` segments in this path.
609
+ * Creates a new Path by resolving all non-leading `.` and `..` segments in
610
+ * the target Path. In other words:
611
+ *
612
+ * - Segments containing `.` are removed
613
+ * - Segments containing `..` are removed, along with the segment preceding
614
+ * them.
615
+ *
616
+ * Note that any `.` or `..` segments at the beginning of the path (ie.
617
+ * "leading segments") are not removed.
392
618
  */
393
619
  normalize(): Path;
394
620
 
395
621
  /**
396
- * Create a new Path by appending additional path segments onto the end of
397
- * this Path's segments.
622
+ * Creates a new Path by appending additional path segments onto the end of
623
+ * the target Path's segments.
398
624
  *
399
- * The returned path will use this path's separator.
625
+ * The returned Path will use the same separator as the target Path.
400
626
  */
401
627
  concat(...other: Array<string | Path | Array<string | Path>>): Path;
402
628
 
403
629
  /**
404
- * Return whether this path is absolute; that is, whether it starts with
405
- * either `/`, `\`, or a drive letter (ie `C:`).
630
+ * Returns a boolean indicating whether the target Path is absolute; that
631
+ * is, whether it starts with either a slash (`/` or `\`) or a drive letter
632
+ * (ie `C:`).
633
+ *
634
+ * Note that Windows UNC Paths (eg. `\\MYSERVER\share$\`) are considered
635
+ * absolute.
406
636
  */
407
637
  isAbsolute(): boolean;
408
638
 
409
639
  /**
410
- * Make a second Path object containing the same segments and separator as
411
- * this one.
640
+ * Creates a new Path object containing the same segments and separator as
641
+ * the target Path.
642
+ *
643
+ * Note that although it contains the same segments, the new Path does not use
644
+ * the same Array instance for segments as the target Path is was cloned from.
412
645
  */
413
646
  clone(): this;
414
647
 
415
648
  /**
416
- * Express this path relative to `dir`.
649
+ * Creates a new Path which expresses the target Path relative to `dir`.
417
650
  *
418
651
  * @param dir - The directory to create a new path relative to.
419
- * @param options - Options that affect the resulting path.
652
+ * @param options - Options that affect the resulting path (see {@link PathRelativeToOptions}).
420
653
  */
421
- relativeTo(
422
- dir: Path | string,
423
- options?: {
424
- /**
425
- * Defaults to false. When true, a leading `./` will be omitted from the
426
- * path, if present. Note that a leading `../` will never be omitted.
427
- */
428
- noLeadingDot?: boolean;
429
- }
430
- ): Path;
654
+ relativeTo(dir: Path | string, options?: PathRelativeToOptions): Path;
431
655
 
432
656
  /**
433
- * Turn this path into a string by joining its segments using its separator.
657
+ * Turns the target Path into a string by joining its segments using its
658
+ * separator as the delimiter.
434
659
  */
435
660
  toString(): string;
436
661
 
437
662
  /**
438
- * Alias for `toString`; causes Path objects to be serialized as strings when
439
- * they (or an object referencing them) are passed into JSON.stringify.
663
+ * Alias for `toString`. The presence of this method causes Path objects to be
664
+ * serialized as strings when they (or an object referencing them) get(s) passed
665
+ * into JSON.stringify.
440
666
  */
441
667
  toJSON(): string;
442
668
 
443
669
  /**
444
- * Return the final path segment of this path. If this path has no path
445
- * segments, the empty string is returned.
670
+ * Returns the final segment of the target Path. If the target Path has no
671
+ * segments, an empty string (`""`) is returned.
446
672
  */
447
673
  basename(): string;
448
674
 
449
675
  /**
450
- * Return the trailing extension of this path. The `options` parameter works
451
- * the same as the global `extname`'s `options` parameter.
676
+ * Returns the trailing file extension of this path.
677
+ *
678
+ * @param options - Works the same as the options parameter for the global {@link extname} (see {@link ExtnameOptions}).
679
+ */
680
+ extname(options?: ExtnameOptions): string;
681
+
682
+ /**
683
+ * Creates a new Path containing all of the segments in the target Path except
684
+ * for the last one; ie. the path to the directory that contains the target Path.
452
685
  */
453
- extname(options?: { full?: boolean }): string;
686
+ dirname(): Path;
454
687
 
455
688
  /**
456
- * Return whether this path starts with the provided value, by comparing one
457
- * path segment at a time.
689
+ * Returns a boolean indicating whether the target Path starts with the
690
+ * provided value, by comparing one path segment at a time.
458
691
  *
459
- * The starting segments of this path must *exactly* match the segments in the
692
+ * The starting segments of the target Path must *exactly* match the segments in the
460
693
  * provided value.
461
694
  *
462
695
  * This means that, given two Paths A and B:
@@ -471,10 +704,10 @@ declare class Path {
471
704
  startsWith(value: string | Path | Array<string | Path>): boolean;
472
705
 
473
706
  /**
474
- * Return whether this path ends with the provided value, by comparing one
475
- * path segment at a time.
707
+ * Returns a boolean indicating whether the target Path ends with the provided
708
+ * value, by comparing one path segment at a time.
476
709
  *
477
- * The ending segments of this path must *exactly* match the segments in the
710
+ * The ending segments of the target Path must *exactly* match the segments in the
478
711
  * provided value.
479
712
  *
480
713
  * This means that, given two Paths A and B:
@@ -489,11 +722,11 @@ declare class Path {
489
722
  endsWith(value: string | Path | Array<string | Path>): boolean;
490
723
 
491
724
  /**
492
- * Return the path segment index at which `value` appears in this path, or
493
- * `-1` if it doesn't appear in this path.
725
+ * Returns the index at which `value` appears in the target Path's segments,
726
+ * or `-1` if `value` doesn't appear in the target Path.
494
727
  *
495
728
  * @param value - The value to search for. If the value contains more than one path segment, the returned index will refer to the location of the value's first path segment.
496
- * @param fromIndex - The index into this path's segments to begin searching at. Defaults to `0`.
729
+ * @param fromIndex - The index into the target Path's segments to begin searching at. Defaults to `0`.
497
730
  */
498
731
  indexOf(
499
732
  value: string | Path | Array<string | Path>,
@@ -501,10 +734,10 @@ declare class Path {
501
734
  ): number;
502
735
 
503
736
  /**
504
- * Return whether `value` appears in this path.
737
+ * Returns a boolean indicating whether `value` appears in the target Path.
505
738
  *
506
739
  * @param value - The value to search for.
507
- * @param fromIndex - The index into this path's segments to begin searching at. Defaults to `0`.
740
+ * @param fromIndex - The index into the target Path's segments to begin searching at. Defaults to `0`.
508
741
  */
509
742
  includes(
510
743
  value: string | Path | Array<string | Path>,
@@ -512,14 +745,18 @@ declare class Path {
512
745
  ): boolean;
513
746
 
514
747
  /**
515
- * Return a new Path wherein the segments in `value` have been replaced with
516
- * the segments in `replacement`. If the segments in `value` are not present
517
- * in this path, a clone of this path is returned.
748
+ * Creates a new Path based on the target Path wherein the segments in `value`
749
+ * have been replaced with the segments in `replacement`. If the segments in
750
+ * `value` are not present in the target Path, a clone of the target Path is
751
+ * returned.
518
752
  *
519
- * Note that only the first match is replaced.
753
+ * Note that only the first match is replaced. To replace more than one match,
754
+ * use {@link Path.prototype.replaceAll}.
520
755
  *
521
756
  * @param value - What should be replaced
522
757
  * @param replacement - What it should be replaced with
758
+ *
759
+ * See also {@link Path.prototype.replaceLast}.
523
760
  */
524
761
  replace(
525
762
  value: string | Path | Array<string | Path>,
@@ -527,12 +764,18 @@ declare class Path {
527
764
  ): Path;
528
765
 
529
766
  /**
530
- * Return a new Path wherein all occurrences of the segments in `value` have
531
- * been replaced with the segments in `replacement`. If the segments in
532
- * `value` are not present in this path, a clone of this path is returned.
767
+ * Creates a new Path based on the target Path wherein all occurrences of the
768
+ * segments in `value` have been replaced with the segments in `replacement`.
769
+ * If the segments in `value` are not present in the target Path, a clone of
770
+ * the target Path is returned.
771
+ *
772
+ * Note that all matches are replaced. To replace only the first match,
773
+ * use {@link Path.prototype.replace}.
533
774
  *
534
775
  * @param value - What should be replaced
535
776
  * @param replacement - What it should be replaced with
777
+ *
778
+ * See also {@link Path.prototype.replaceLast}.
536
779
  */
537
780
  replaceAll(
538
781
  value: string | Path | Array<string | Path>,
@@ -540,7 +783,11 @@ declare class Path {
540
783
  ): Path;
541
784
 
542
785
  /**
543
- * Return a copy of this path but with the final segment replaced with `replacement`
786
+ * Creates a new Path based on the target Path but with the final segment
787
+ * replaced with `replacement`.
788
+ *
789
+ * If the target Path has no segments, the newly created Path will be the same
790
+ * as `new Path(replacement)`; ie. non-empty.
544
791
  *
545
792
  * @param replacement - The new final segment(s) for the returned Path
546
793
  */
@@ -548,16 +795,33 @@ declare class Path {
548
795
  }
549
796
 
550
797
  /**
551
- * The absolute path to the current file (whether script or module).
798
+ * Options for {@link Path.prototype.relativeTo}.
799
+ */
800
+ declare interface PathRelativeToOptions {
801
+ /**
802
+ * Defaults to false. When true, a leading `./` will be omitted from the
803
+ * path, if present. Note that a leading `../` will never be omitted.
804
+ */
805
+ noLeadingDot?: boolean;
806
+ }
807
+
808
+ /**
809
+ * The absolute path to the currently-executing file (whether script or module).
552
810
  *
553
- * Behaves the same as in Node.js, except that it's also present within ES modules.
811
+ * Behaves the same as in Node.js, except that it's also present within ES
812
+ * modules.
813
+ *
814
+ * Example: `/home/suchipi/some-folder/some-file.js`
554
815
  */
555
816
  declare var __filename: string;
556
817
 
557
818
  /**
558
- * The absolute path to the directory the current file is inside of.
819
+ * The absolute path to the directory containing the currently-executing file.
820
+ *
821
+ * Behaves the same as in Node.js, except that it's also present within ES
822
+ * modules.
559
823
  *
560
- * Behaves the same as in Node.js, except that it's also present within ES modules.
824
+ * Example: `/home/suchipi/some-folder`
561
825
  */
562
826
  declare var __dirname: string;
563
827
 
@@ -565,105 +829,287 @@ declare var __dirname: string;
565
829
  * Return the last component of a path string.
566
830
  *
567
831
  * Provides the same functionality as the unix binary of the same name.
832
+ *
833
+ * > Example: `basename("/home/suchipi/something")` returns `"something"`, the last part.
568
834
  */
569
835
  declare function basename(path: string | Path): string;
570
836
 
571
837
  /**
572
- * Reads the contents of one of more files from disk as one UTF-8 string.
838
+ * Reads the contents of one or more files from disk as either one UTF-8 string
839
+ * or one ArrayBuffer.
840
+ *
841
+ * Provides the same functionality as the unix binary of the same name.
842
+ *
843
+ * > Example: If you have a file called `hi.txt` in the current working
844
+ * > directory, and it contains the text "hello", running `cat("hi.txt")`
845
+ * > returns `"hello"`.
573
846
  */
574
- declare function cat(...paths: Array<string | Path>): string;
847
+ declare const cat: {
848
+ /**
849
+ * Read the contents of one or more files from disk, as one UTF-8 string.
850
+ */
851
+ (paths: string | Path | Array<string | Path>): string;
852
+
853
+ /**
854
+ * Read the contents of one or more files from disk, as one UTF-8 string.
855
+ */
856
+ (paths: string | Path | Array<string | Path>, options: {}): string;
857
+
858
+ /**
859
+ * Read the contents of one or more files from disk, as one UTF-8 string.
860
+ */
861
+ (
862
+ paths: string | Path | Array<string | Path>,
863
+ options: { binary: false }
864
+ ): string;
865
+
866
+ /**
867
+ * Read the contents of one or more files from disk, as one ArrayBuffer.
868
+ */
869
+ (
870
+ paths: string | Path | Array<string | Path>,
871
+ options: { binary: true }
872
+ ): ArrayBuffer;
873
+ };
575
874
 
576
875
  /**
577
- * Change the process's current working directory to the specified path. If no
876
+ * Changes the process's current working directory to the specified path. If no
578
877
  * path is specified, moves to the user's home directory.
579
878
  *
580
879
  * Provides the same functionality as the shell builtin of the same name.
581
880
  */
582
881
  declare function cd(path?: string | Path): void;
583
882
 
584
- /** A string representing who a permission applies to. */
585
- declare type ChmodPermissionsWho =
586
- | "user"
587
- | "group"
588
- | "others"
589
- | "all"
590
- | "u"
591
- | "g"
592
- | "o"
593
- | "a"
594
- | "ug"
595
- | "go"
596
- | "uo";
597
-
598
- /** A string representing the access level for the given permission. */
599
- declare type ChmodPermissionsWhat =
600
- | "read"
601
- | "write"
602
- | "execute"
603
- | "readwrite"
604
- | "none"
605
- | "full"
606
- | "r"
607
- | "w"
608
- | "x"
609
- | "rw"
610
- | "rx"
611
- | "wx"
612
- | "rwx";
613
-
614
883
  /**
615
884
  * Set the permission bits for the specified file.
616
885
  *
617
- * @param permissions The permission bits to set. This can be a number, a string containing an octal number, or an object.
618
- * @param path The path to the file.
886
+ * Provides the same functionality as the unix binary of the same name.
619
887
  */
620
- declare function chmod(
621
- permissions:
622
- | number
623
- | string
624
- | Record<ChmodPermissionsWho, ChmodPermissionsWhat>,
625
- path: string | Path
626
- ): void;
888
+ declare const chmod: Chmod;
889
+
890
+ /**
891
+ * The interface for the global function `chmod`, which has two call signatures.
892
+ */
893
+ interface Chmod {
894
+ /**
895
+ * Set the permission bits for the specified file.
896
+ *
897
+ * Provides the same functionality as the unix binary of the same name.
898
+ *
899
+ * @param permissions The permission bits to set. This can be a number, or a string containing an octal number.
900
+ * @param path The path to the file.
901
+ */
902
+ (permissions: number | string, path: string | Path): void;
903
+
904
+ /**
905
+ * Apply a change to the permission bits for the specified file.
906
+ *
907
+ * Provides the same functionality as the unix binary of the same name.
908
+ *
909
+ * @param operation What to do to the bits; can be "add", "set", or "remove".
910
+ * @param permissions An object describing the changes (see below).
911
+ * @param path The path to the file.
912
+ *
913
+ * Each of the `permissions` object's own property keys must be one of these
914
+ * strings:
915
+ *
916
+ * - `"user"`
917
+ * - `"group"`
918
+ * - `"others"`
919
+ * - `"all"` (meaning "user", "group", and "others")
920
+ * - `"u"` (alias for "user")
921
+ * - `"g"` (alias for "group")
922
+ * - `"o"` (alias for "others")
923
+ * - `"a"` (alias for "all")
924
+ * - `"ug"` ("user" plus "group")
925
+ * - `"go"` ("group" plus "others")
926
+ * - `"uo"` ("user" plus "others")
927
+ *
928
+ * and their values must be one of these strings:
929
+ *
930
+ * - `"read"` (permission to read the contents of the file)
931
+ * - `"write"` (permission to write to the file's contents)
932
+ * - `"execute"` (permission to run the file as an executable)
933
+ * - `"readwrite"` (both "read" and "write")
934
+ * - `"none"` (no permissions)
935
+ * - `"full"` ("read", "write", and "execute")
936
+ * - `"r"` (alias for "read")
937
+ * - `"w"` (alias for "write")
938
+ * - `"x"` (alias for "execute")
939
+ * - `"rw"` (alias for "readwrite")
940
+ * - `"rx"` ("read" and "execute")
941
+ * - `"wx"` ("write" and "execute")
942
+ * - `"rwx"` (alias for "full")
943
+ *
944
+ * Some example objects:
945
+ *
946
+ * ```json
947
+ * { user: "readwrite", group: "read", others: "none" }
948
+ * { ug: "rw", o: "w" }
949
+ * { all: "full" }
950
+ * ```
951
+ */
952
+ (
953
+ operation: Chmod.Operation,
954
+ permissions: Record<Chmod.Who, Chmod.Permission>,
955
+ path: string | Path
956
+ ): void;
957
+ }
958
+
959
+ declare namespace Chmod {
960
+ /** A string representing who a permission applies to. */
961
+ export type Who =
962
+ | "user"
963
+ | "group"
964
+ | "others"
965
+ | "all"
966
+ | "u"
967
+ | "g"
968
+ | "o"
969
+ | "a"
970
+ | "ug"
971
+ | "go"
972
+ | "uo";
973
+
974
+ /** A string representing how the permissions should be changed. */
975
+ export type Operation = "add" | "set" | "remove";
976
+
977
+ /** A string representing the access level for the given permission. */
978
+ export type Permission =
979
+ | "read"
980
+ | "write"
981
+ | "execute"
982
+ | "readwrite"
983
+ | "none"
984
+ | "full"
985
+ | "r"
986
+ | "w"
987
+ | "x"
988
+ | "rw"
989
+ | "rx"
990
+ | "wx"
991
+ | "rwx";
992
+ }
627
993
 
628
994
  /**
629
995
  * Removes the final component from a path string.
630
996
  *
631
997
  * Provides the same functionality as the unix binary of the same name.
998
+ *
999
+ * > Example: `dirname("/home/suchipi/something")` returns
1000
+ * > `"/home/suchipi"`, everything except the last part.
632
1001
  */
633
1002
  declare function dirname(path: string | Path): Path;
634
1003
 
635
1004
  /**
636
1005
  * Print one or more values to stdout.
1006
+ *
1007
+ * Provides the same functionality as the shell builtin of the same name.
1008
+ *
1009
+ * > NOTE: This can print any value, not just strings.
1010
+ *
1011
+ * `echo` is functionally identical to `console.log`.
637
1012
  */
638
1013
  declare const echo: typeof console.log;
639
1014
 
1015
+ /**
1016
+ * Exit the yavascript process.
1017
+ *
1018
+ * Provides the same functionality as the shell builtin of the same name.
1019
+ *
1020
+ * If exit is called with an argument, that argument is used as the exit code.
1021
+ * Otherwise, `exit.code` is used, which defaults to 0.
1022
+ *
1023
+ * `exit.code` will also be used as the exit status code for the yavascript
1024
+ * process if the process exits normally.
1025
+ *
1026
+ * > Attempting to call `exit` or set `exit.code` within a Worker will fail and
1027
+ * > throw an error.
1028
+ */
1029
+ declare const exit: {
1030
+ (code?: number): never;
1031
+ code: number;
1032
+ };
1033
+
640
1034
  /**
641
1035
  * Returns the file extension of the file at a given path.
642
1036
  *
643
- * If the file has no extension (eg `Makefile`, etc), then `''` will be returned.
1037
+ * If the file has no extension (eg `Makefile`, etc), then `''` will be
1038
+ * returned.
644
1039
  *
645
- * Pass `{ full: true }` to get compound extensions, eg `.d.ts` or `.test.js` instead of just `.ts`/`.js`.
1040
+ * @param pathOrFilename The input path
1041
+ * @param options Options which affect the return value. See {@link ExtnameOptions}.
646
1042
  */
647
1043
  declare function extname(
648
1044
  pathOrFilename: string | Path,
649
- options?: { full?: boolean }
1045
+ options?: ExtnameOptions
650
1046
  ): string;
651
1047
 
1048
+ /**
1049
+ * Options for {@link extname} and {@link Path.prototype.extname}.
1050
+ */
1051
+ declare interface ExtnameOptions {
1052
+ /**
1053
+ * Whether to get compound extensions, like `.d.ts` or `.test.js`, instead of
1054
+ * just the final extension (`.ts` or `.js` in this example).
1055
+ */
1056
+ full?: boolean;
1057
+ }
1058
+
652
1059
  /**
653
1060
  * Returns the contents of a directory, as absolute paths. `.` and `..` are
654
1061
  * omitted.
1062
+ *
1063
+ * If `ls()` is called with no directory, the present working directory
1064
+ * (`pwd()`) is used.
655
1065
  */
656
1066
  declare function ls(dir?: string | Path): Array<Path>;
657
1067
 
658
1068
  /**
659
- * Print data to stdout using C-style format specifiers.
1069
+ * Create a directory (folder).
660
1070
  *
661
- * The same formats as the standard C library printf are supported. Integer
662
- * format types (e.g. `%d`) truncate the Numbers or BigInts to 32 bits. Use the l
663
- * modifier (e.g. `%ld`) to truncate to 64 bits.
1071
+ * Provides the same functionality as the unix binary of the same name.
664
1072
  */
665
- declare function printf(format: string, ...args: Array<any>): void;
666
-
1073
+ declare function mkdir(
1074
+ path: string | Path,
1075
+ options?: {
1076
+ recursive?: boolean;
1077
+ mode?: number;
1078
+ logging?: {
1079
+ trace?: (...args: Array<any>) => void;
1080
+ info?: (...args: Array<any>) => void;
1081
+ };
1082
+ }
1083
+ ): void;
1084
+
1085
+ /**
1086
+ * Create a directory (folder) and all parents, recursively
1087
+ *
1088
+ * Alias for `mkdir(path, { recursive: true })`.
1089
+ *
1090
+ * Provides the same functionality as `mkdir -p`.
1091
+ */
1092
+ declare function mkdirp(
1093
+ path: string | Path,
1094
+ options?: {
1095
+ mode?: number;
1096
+ logging?: {
1097
+ trace?: (...args: Array<any>) => void;
1098
+ info?: (...args: Array<any>) => void;
1099
+ };
1100
+ }
1101
+ ): void;
1102
+
1103
+ /**
1104
+ * Print data to stdout using C-style format specifiers.
1105
+ *
1106
+ * The same formats as the [standard C library
1107
+ * printf](https://en.cppreference.com/w/c/io/fprintf) are supported. Integer
1108
+ * format types (e.g. `%d`) truncate the Numbers or BigInts to 32 bits. Use the
1109
+ * l modifier (e.g. `%ld`) to truncate to 64 bits.
1110
+ */
1111
+ declare function printf(format: string, ...args: Array<any>): void;
1112
+
667
1113
  /**
668
1114
  * Returns the process's current working directory.
669
1115
  *
@@ -699,31 +1145,48 @@ declare function readlink(path: string | Path): Path;
699
1145
  * The path's target file/directory must exist.
700
1146
  *
701
1147
  * Provides the same functionality as the unix binary of the same name.
1148
+ *
1149
+ * > If you want to convert a relative path to an absolute path, but the path's
1150
+ * > target might NOT exist, use {@link Path.normalize}.
702
1151
  */
703
1152
  declare function realpath(path: string | Path): Path;
704
1153
 
705
1154
  /**
706
- * Blocks the current thread for at least the specified number of milliseconds,
707
- * or maybe a tiny bit longer.
1155
+ * `sleep` and `sleep.sync` block the current thread for at least the specified
1156
+ * number of milliseconds, but maybe a tiny bit longer.
1157
+ *
1158
+ * `sleep.async` returns a Promise which resolves in at least the specified
1159
+ * number of milliseconds, but maybe a tiny bit longer.
708
1160
  *
709
- * alias for `sleep.sync`.
1161
+ * `sleep` and `sleep.sync` block the current thread. `sleep.async` doesn't
1162
+ * block the current thread.
1163
+ *
1164
+ * "Blocking the thread" means no other JavaScript code can run while `sleep` or
1165
+ * `sleep.sync` is running. If this is not the behavior you want, use
1166
+ * `sleep.async` instead.
710
1167
  */
711
1168
  declare var sleep: {
712
1169
  /**
713
- * Blocks the current thread for at least the specified number of milliseconds,
714
- * or maybe a tiny bit longer.
1170
+ * Blocks the current thread for at least the specified number of
1171
+ * milliseconds, but maybe a tiny bit longer.
715
1172
  *
716
1173
  * alias for `sleep.sync`.
717
1174
  *
718
1175
  * @param milliseconds - The number of milliseconds to block for.
1176
+ *
1177
+ * No other JavaScript code can run while `sleep()` is running. If this is
1178
+ * not the behavior you want, use `sleep.async` instead.
719
1179
  */
720
1180
  (milliseconds: number): void;
721
1181
 
722
1182
  /**
723
- * Blocks the current thread for at least the specified number of milliseconds,
724
- * or maybe a tiny bit longer.
1183
+ * Blocks the current thread for at least the specified number of
1184
+ * milliseconds, but maybe a tiny bit longer.
725
1185
  *
726
1186
  * @param milliseconds - The number of milliseconds to block for.
1187
+ *
1188
+ * No other JavaScript code can run while `sleep.sync` is running. If this is
1189
+ * not the behavior you want, use `sleep.async` instead.
727
1190
  */
728
1191
  sync(milliseconds: number): void;
729
1192
 
@@ -732,6 +1195,14 @@ declare var sleep: {
732
1195
  * milliseconds, maybe a little longer.
733
1196
  *
734
1197
  * @param milliseconds - The number of milliseconds to wait before the returned Promise should be resolved.
1198
+ *
1199
+ * `sleep.async` doesn't block the current thread, so other JavaScript code
1200
+ * (registered event handlers, async functions, timers, etc) can run while
1201
+ * `sleep.async`'s return Promise is waiting to resolve. If this is not the
1202
+ * behavior you want, use `sleep.sync` instead.
1203
+ *
1204
+ * The Promise returned by `sleep.async` will never get rejected. It will only
1205
+ * ever get resolved.
735
1206
  */
736
1207
  async(milliseconds: number): Promise<void>;
737
1208
  };
@@ -754,16 +1225,131 @@ declare function touch(path: string | Path): void;
754
1225
  * @param options Options which affect how the search is performed
755
1226
  * @param options.searchPaths A list of folders where programs may be found. Defaults to `env.PATH?.split(Path.OS_ENV_VAR_SEPARATOR) || []`.
756
1227
  * @param options.suffixes A list of filename extension suffixes to include in the search, ie [".exe"]. Defaults to `Path.OS_PROGRAM_EXTENSIONS`.
757
- * @param options.trace A logging function that will be called at various times during the execution of `which`. Defaults to `traceAll.getDefaultTrace()`.
1228
+ * @param options.trace A logging function that will be called at various times during the execution of `which`. Defaults to {@link logger.trace}.
758
1229
  */
759
- declare function which(
760
- binaryName: string,
761
- options?: {
762
- searchPaths?: Array<Path | string>;
763
- suffixes?: Array<string>;
1230
+ declare function which(binaryName: string, options?: WhichOptions): Path | null;
1231
+
1232
+ declare type WhichOptions = {
1233
+ /**
1234
+ * A list of folders where programs may be found. Defaults to
1235
+ * `env.PATH?.split(Path.OS_ENV_VAR_SEPARATOR) || []`.
1236
+ */
1237
+ searchPaths?: Array<Path | string>;
1238
+
1239
+ /**
1240
+ * A list of filename extension suffixes to include in the search, ie
1241
+ * `[".exe"]`. Defaults to {@link Path.OS_PROGRAM_EXTENSIONS}.
1242
+ */
1243
+ suffixes?: Array<string>;
1244
+
1245
+ /** Options which control logging. */
1246
+ logging?: {
1247
+ /**
1248
+ * If provided, this logging function will be called multiple times as
1249
+ * `which` runs, to help you understand what's going on and/or troubleshoot
1250
+ * things. In most cases, it makes sense to use a function from `console`
1251
+ * here, like so:
1252
+ *
1253
+ * ```js
1254
+ * which("bash", {
1255
+ * logging: { trace: console.log }
1256
+ * });
1257
+ * ```
1258
+ *
1259
+ * Defaults to the current value of {@link logger.trace}. `logger.trace`
1260
+ * defaults to a no-op function.
1261
+ */
764
1262
  trace?: (...args: Array<any>) => void;
765
- }
766
- ): Path | null;
1263
+ };
1264
+ };
1265
+
1266
+ /** The type of the return value of {@link whoami}. */
1267
+ declare interface WhoAmIResult {
1268
+ name: string;
1269
+ uid: number;
1270
+ gid: number;
1271
+ }
1272
+
1273
+ /**
1274
+ * Get info about the user the yavascript process is executing as.
1275
+ *
1276
+ * Provides functionality similar to the unix binaries `whoami` and `id`.
1277
+ *
1278
+ * NOTE: Doesn't work on Windows; throws an error.
1279
+ */
1280
+ declare function whoami(): WhoAmIResult;
1281
+
1282
+ /**
1283
+ * Runs a child process and blocks until it exits. You can call it with either a
1284
+ * string or an array of strings.
1285
+ *
1286
+ * When calling `exec` with an array of strings, the first string in the array
1287
+ * is the program to run, and the rest of the strings in the array are arguments
1288
+ * to the program, eg:
1289
+ *
1290
+ * ```ts
1291
+ * exec(["echo", "hi", "there"]);
1292
+ * exec(["printf", "something with spaces\n"]);
1293
+ * ```
1294
+ *
1295
+ * When calling with a string instead of an array, the string will be split into
1296
+ * separate arguments using the following rules:
1297
+ *
1298
+ * - The program and its arguments will be determined by splitting the input
1299
+ * string on whitespace, except:
1300
+ * - Stuff in single or double-quotes will be preserved as a single argument
1301
+ * - Double and single quotes can be "glued" together (eg `"bla"'bla'` becomes
1302
+ * `blabla`)
1303
+ * - The escape sequences `\n`, `\r`, `\t`, `\v`, `\0`, and `\\` can be used
1304
+ * inside of quotes get replaced with newline, carriage return, tab,
1305
+ * vertical tab, nul, and `\` characters, respectively
1306
+ *
1307
+ * For example:
1308
+ *
1309
+ * ```ts
1310
+ * exec(`echo hi there`);
1311
+ * exec(`printf "something with spaces\n"`);
1312
+ * ```
1313
+ *
1314
+ * The intent is that it behaves similarly to what you would expect from a UNIX
1315
+ * shell, but only the "safe" features. "Unsafe" features like environment
1316
+ * variable expansion (`$VAR` or `${VAR}`), subshells (\`echo hi\` or `$(echo
1317
+ * hi)`), and redirection (`> /dev/null` or `2>&1 `) are not supported. To use
1318
+ * those features, shell out to `bash` or `sh` directly via eg `exec(['bash',
1319
+ * '-c', 'your command string'])`, but be aware of the security implications of
1320
+ * doing so.
1321
+ *
1322
+ * `exec` also supports a second argument, an options object which supports the
1323
+ * following keys (all are optional):
1324
+ *
1325
+ * | Property | Purpose |
1326
+ * | ------------------------------ | --------------------------------------------------- |
1327
+ * | cwd (string) | current working directory for the child process |
1328
+ * | env (object) | environment variables for the process |
1329
+ * | failOnNonZeroStatus (boolean) | whether to throw error on nonzero exit status |
1330
+ * | captureOutput (boolean/string) | controls how stdout/stderr is directed |
1331
+ * | logging (object) | controls how/whether info messages are logged |
1332
+ * | block (boolean) | whether to wait for child process exit now or later |
1333
+ *
1334
+ * The return value of `exec` varies depending on the options passed:
1335
+ *
1336
+ * - When `captureOutput` is true or "utf-8", an object will be returned with
1337
+ * `stdout` and `stderr` properties, both strings.
1338
+ * - When `captureOutput` is "arraybuffer", an object will be returned with
1339
+ * `stdout` and `stderr` properties, both `ArrayBuffer`s.
1340
+ * - When `failOnNonZeroStatus` is false, an object will be returned with
1341
+ * `status` (the exit code; number or undefined) and `signal` (the signal that
1342
+ * killed the process; number or undefined).
1343
+ * - When `captureOutput` is non-false and `failOnNonZeroStatus` is false, an
1344
+ * object will be returned with four properties (the two associated with
1345
+ * `failOnNonZeroStatus`, and the two associated with `captureOutput`).
1346
+ * - When `captureOutput` is false or unspecified, and `failOnNonZeroStatus` is
1347
+ * true or unspecified, undefined will be returned.
1348
+ * - If `block` is false, an object with a "wait" method is returned instead,
1349
+ * which blocks the calling thread until the process exits, and then returns
1350
+ * one of the values described above.
1351
+ */
1352
+ declare const exec: Exec;
767
1353
 
768
1354
  declare type BaseExecOptions = {
769
1355
  /** Sets the current working directory for the child process. */
@@ -772,16 +1358,34 @@ declare type BaseExecOptions = {
772
1358
  /** Sets environment variables within the process. */
773
1359
  env?: { [key: string | number]: string | number | boolean };
774
1360
 
775
- /**
776
- * If provided, this function will be called multiple times as `exec`
777
- * runs, to help you understand what's going on and/or troubleshoot things.
778
- * In most cases, it makes sense to use a logging function here, like so:
779
- *
780
- * ```js
781
- * exec(["echo", "hi"], { trace: console.log });
782
- * ```
783
- */
784
- trace?: (...args: Array<any>) => void;
1361
+ /** Options which control logging. */
1362
+ logging?: {
1363
+ /**
1364
+ * If provided, this logging function will be called multiple times as
1365
+ * `exec` runs, to help you understand what's going on and/or troubleshoot
1366
+ * things. In most cases, it makes sense to use a function from `console`
1367
+ * here, like so:
1368
+ *
1369
+ * ```js
1370
+ * exec(["echo", "hi"], {
1371
+ * logging: { trace: console.log },
1372
+ * });
1373
+ * ```
1374
+ *
1375
+ * Defaults to the current value of {@link logger.trace}. `logger.trace`
1376
+ * defaults to a no-op function.
1377
+ */
1378
+ trace?: (...args: Array<any>) => void;
1379
+
1380
+ /**
1381
+ * An optional, user-provided logging function to be used for informational
1382
+ * messages. Less verbose than `logging.trace`.
1383
+ *
1384
+ * Defaults to the current value of {@link logger.info}. `logger.info`
1385
+ * defaults to a function which logs to stderr.
1386
+ */
1387
+ info?: (...args: Array<any>) => void;
1388
+ };
785
1389
 
786
1390
  /**
787
1391
  * Whether an Error should be thrown when the process exits with a nonzero
@@ -798,139 +1402,39 @@ declare type BaseExecOptions = {
798
1402
  * Defaults to false. true is an alias for "utf8".
799
1403
  */
800
1404
  captureOutput?: boolean | "utf8" | "arraybuffer";
1405
+
1406
+ /**
1407
+ * If true, exec doesn't return until the process is done running. If false,
1408
+ * exec returns an object with a "wait" method which can be used to wait for
1409
+ * the process to be done running.
1410
+ *
1411
+ * Defaults to true.
1412
+ */
1413
+ block?: boolean;
801
1414
  };
802
1415
 
803
1416
  declare interface Exec {
804
- (
805
- args: Array<string | Path | number> | string | Path,
806
- options: BaseExecOptions & {
807
- failOnNonZeroStatus: true;
808
- captureOutput: false;
809
- }
810
- ): void;
811
-
812
- (
813
- args: Array<string | Path | number> | string | Path,
814
- options: BaseExecOptions & {
815
- failOnNonZeroStatus: false;
816
- captureOutput: false;
817
- }
818
- ):
819
- | { status: number; signal: undefined }
820
- | { status: undefined; signal: number };
821
-
822
- (
823
- args: Array<string | Path | number> | string | Path,
824
- options: BaseExecOptions & {
825
- failOnNonZeroStatus: true;
826
- captureOutput: true;
827
- }
828
- ): { stdout: string; stderr: string };
829
-
830
- (
831
- args: Array<string | Path | number> | string | Path,
832
- options: BaseExecOptions & {
833
- failOnNonZeroStatus: true;
834
- captureOutput: "utf8";
835
- }
836
- ): { stdout: string; stderr: string };
837
-
838
- (
839
- args: Array<string | Path | number> | string | Path,
840
- options: BaseExecOptions & {
841
- failOnNonZeroStatus: true;
842
- captureOutput: "arraybuffer";
843
- }
844
- ): { stdout: ArrayBuffer; stderr: ArrayBuffer };
845
-
846
- (
847
- args: Array<string | Path | number> | string | Path,
848
- options: BaseExecOptions & {
849
- failOnNonZeroStatus: false;
850
- captureOutput: true;
851
- }
852
- ):
853
- | { stdout: string; stderr: string; status: number; signal: undefined }
854
- | { stdout: string; stderr: string; status: undefined; signal: number };
855
-
856
- (
857
- args: Array<string | Path | number> | string | Path,
858
- options: BaseExecOptions & {
859
- failOnNonZeroStatus: false;
860
- captureOutput: "utf-8";
861
- }
862
- ):
863
- | { stdout: string; stderr: string; status: number; signal: undefined }
864
- | { stdout: string; stderr: string; status: undefined; signal: number };
865
-
866
- (
867
- args: Array<string | Path | number> | string | Path,
868
- options: BaseExecOptions & {
869
- failOnNonZeroStatus: false;
870
- captureOutput: "arraybuffer";
871
- }
872
- ):
873
- | {
874
- stdout: ArrayBuffer;
875
- stderr: ArrayBuffer;
876
- status: number;
877
- signal: undefined;
878
- }
879
- | {
880
- stdout: ArrayBuffer;
881
- stderr: ArrayBuffer;
882
- status: undefined;
883
- signal: number;
884
- };
885
-
886
- (
887
- args: Array<string | Path | number> | string | Path,
888
- options: BaseExecOptions & {
1417
+ /**
1418
+ * Runs a child process using the provided arguments.
1419
+ *
1420
+ * When `args` is an Array, the first value in the Array is the program to
1421
+ * run.
1422
+ *
1423
+ * @param args - The command to run.
1424
+ * @param options - Options; see {@link BaseExecOptions}
1425
+ */
1426
+ <
1427
+ ExecOptions extends BaseExecOptions = {
889
1428
  failOnNonZeroStatus: true;
890
- }
891
- ): void;
892
-
893
- (
894
- args: Array<string | Path | number> | string | Path,
895
- options: BaseExecOptions & {
896
- failOnNonZeroStatus: false;
897
- }
898
- ):
899
- | { status: number; signal: undefined }
900
- | { status: undefined; signal: number };
901
-
902
- (
903
- args: Array<string | Path | number> | string | Path,
904
- options: BaseExecOptions & {
905
- captureOutput: true;
906
- }
907
- ): { stdout: string; stderr: string };
908
-
909
- (
910
- args: Array<string | Path | number> | string | Path,
911
- options: BaseExecOptions & {
912
- captureOutput: "utf8";
913
- }
914
- ): { stdout: string; stderr: string };
915
-
916
- (
917
- args: Array<string | Path | number> | string | Path,
918
- options: BaseExecOptions & {
919
- captureOutput: "arraybuffer";
920
- }
921
- ): { stdout: ArrayBuffer; stderr: ArrayBuffer };
922
-
923
- (
924
- args: Array<string | Path | number> | string | Path,
925
- options: BaseExecOptions & {
926
1429
  captureOutput: false;
1430
+ block: true;
927
1431
  }
928
- ): void;
929
-
930
- (
1432
+ >(
931
1433
  args: Array<string | Path | number> | string | Path,
932
- options?: BaseExecOptions
933
- ): void;
1434
+ options?: ExecOptions
1435
+ ): ExecOptions["block"] extends false
1436
+ ? { wait(): ExecWaitResult<ExecOptions> }
1437
+ : ExecWaitResult<ExecOptions>;
934
1438
 
935
1439
  /**
936
1440
  * Parse the provided value into an array of command-line argument strings,
@@ -940,19 +1444,50 @@ declare interface Exec {
940
1444
  }
941
1445
 
942
1446
  /**
943
- * Runs a child process using the provided arguments.
1447
+ * `$(...)` is an alias for `exec(..., { captureOutput: true, failOnNonZeroStatus: true })`.
1448
+ *
1449
+ * It's often used to capture the output of a program:
1450
+ *
1451
+ * ```ts
1452
+ * const result = $(`echo hi`).stdout;
1453
+ * // result is 'hi\n'
1454
+ * ```
944
1455
  *
945
- * The first value in the arguments array is the program to run.
1456
+ * For more info, see {@link exec}.
946
1457
  */
947
- declare const exec: Exec;
948
-
949
- /** Alias for `exec(args, { captureOutput: true })` */
950
1458
  declare function $(args: Array<string | Path | number> | string | Path): {
951
1459
  stdout: string;
952
1460
  stderr: string;
953
1461
  };
954
1462
 
955
- /** A class which represents a child process. The process may or may not be running. */
1463
+ type ExecWaitResult<ExecOptions extends BaseExecOptions> = ExecOptions extends
1464
+ | { captureOutput: true | "utf8" | "arraybuffer" }
1465
+ | { failOnNonZeroStatus: false }
1466
+ ? (ExecOptions["captureOutput"] extends true | "utf8"
1467
+ ? { stdout: string; stderr: string }
1468
+ : {}) &
1469
+ (ExecOptions["captureOutput"] extends "arraybuffer"
1470
+ ? { stdout: ArrayBuffer; stderr: ArrayBuffer }
1471
+ : {}) &
1472
+ (ExecOptions["failOnNonZeroStatus"] extends false
1473
+ ?
1474
+ | { status: number; signal: undefined }
1475
+ | { status: undefined; signal: number }
1476
+ : {})
1477
+ : void;
1478
+
1479
+ /**
1480
+ * A class which represents a child process. The process may or may not be
1481
+ * running.
1482
+ *
1483
+ * This class is the API used internally by the {@link exec} function to spawn child
1484
+ * processes.
1485
+ *
1486
+ * Generally, you should not need to use the `ChildProcess` class directly, and
1487
+ * should use {@link exec} or {@link $} instead. However, you may need to use it in some
1488
+ * special cases, like when specifying custom stdio for a process, or spawning a
1489
+ * non-blocking long-running process.
1490
+ */
956
1491
  declare interface ChildProcess {
957
1492
  /**
958
1493
  * The argv for the process. The first entry in this array is the program to
@@ -980,12 +1515,6 @@ declare interface ChildProcess {
980
1515
  err: FILE;
981
1516
  };
982
1517
 
983
- /**
984
- * Optional trace function which, if present, will be called at various times
985
- * to provide information about the lifecycle of the process.
986
- */
987
- trace?: (...args: Array<any>) => void;
988
-
989
1518
  pid: number | null;
990
1519
 
991
1520
  /** Spawns the process and returns its pid (process id). */
@@ -1022,11 +1551,17 @@ declare type ChildProcessOptions = {
1022
1551
  err?: FILE;
1023
1552
  };
1024
1553
 
1025
- /**
1026
- * Optional trace function which, if present, will be called at various times
1027
- * to provide information about the lifecycle of the process.
1028
- */
1029
- trace?: (...args: Array<any>) => void;
1554
+ /** Options which control logging */
1555
+ logging?: {
1556
+ /**
1557
+ * Optional trace function which, if present, will be called at various
1558
+ * times to provide information about the lifecycle of the process.
1559
+ *
1560
+ * Defaults to the current value of {@link logger.trace}. `logger.trace`
1561
+ * defaults to a function which writes to stderr.
1562
+ */
1563
+ trace?: (...args: Array<any>) => void;
1564
+ };
1030
1565
  };
1031
1566
 
1032
1567
  declare interface ChildProcessConstructor {
@@ -1046,6 +1581,32 @@ declare interface ChildProcessConstructor {
1046
1581
 
1047
1582
  declare var ChildProcess: ChildProcessConstructor;
1048
1583
 
1584
+ /**
1585
+ * Searches the filesystem in order to resolve [UNIX-style glob
1586
+ * strings](https://man7.org/linux/man-pages/man7/glob.7.html) into an array of
1587
+ * matching filesystem paths.
1588
+ *
1589
+ * Glob strings assist in succinctly finding and describing a set of files on
1590
+ * disk. For instance, to find the path of every `.js` file in the `src` folder,
1591
+ * one might write `src/*.js`.
1592
+ *
1593
+ * The function `glob` can be used to turn one or more of these "glob strings" into an array of
1594
+ * `Path` objects.
1595
+ *
1596
+ * `glob` uses [minimatch](https://www.npmjs.com/package/minimatch) with its
1597
+ * default options, which means it supports features like brace expanstion,
1598
+ * "globstar" (**) matching, and other features you would expect from a modern
1599
+ * globbing solution.
1600
+ *
1601
+ * > When specifying more than one pattern string, paths must match ALL of the
1602
+ * > patterns to be included in the returned Array. In other words, it uses
1603
+ * > "logical AND" behavior when you give it more than one pattern.
1604
+ */
1605
+ declare function glob(
1606
+ patterns: string | Array<string>,
1607
+ options?: GlobOptions
1608
+ ): Array<Path>;
1609
+
1049
1610
  /**
1050
1611
  * Options for {@link glob}.
1051
1612
  */
@@ -1058,17 +1619,34 @@ declare type GlobOptions = {
1058
1619
  */
1059
1620
  followSymlinks?: boolean;
1060
1621
 
1061
- /**
1062
- * If provided, this function will be called multiple times as `glob`
1063
- * traverses the filesystem, to help you understand what's going on and/or
1064
- * troubleshoot things. In most cases, it makes sense to use a logging
1065
- * function here, like so:
1066
- *
1067
- * ```js
1068
- * glob(["./*.js"], { trace: console.log });
1069
- * ```
1070
- */
1071
- trace?: (...args: Array<any>) => void;
1622
+ /** Options which control logging. */
1623
+ logging?: {
1624
+ /**
1625
+ * If provided, this function will be called multiple times as `glob`
1626
+ * traverses the filesystem, to help you understand what's going on and/or
1627
+ * troubleshoot things. In most cases, it makes sense to use a logging
1628
+ * function here, like so:
1629
+ *
1630
+ * ```js
1631
+ * glob(["./*.js"], {
1632
+ * logging: { trace: console.log }
1633
+ * });
1634
+ * ```
1635
+ *
1636
+ * Defaults to the current value of {@link logger.trace}. `logger.trace`
1637
+ * defaults to a no-op function.
1638
+ */
1639
+ trace?: (...args: Array<any>) => void;
1640
+
1641
+ /**
1642
+ * An optional, user-provided logging function to be used for informational
1643
+ * messages. Less verbose than `logging.trace`.
1644
+ *
1645
+ * Defaults to the current value of {@link logger.info}. `logger.info`
1646
+ * defaults to a function which writes to stderr.
1647
+ */
1648
+ info?: (...args: Array<any>) => void;
1649
+ };
1072
1650
 
1073
1651
  /**
1074
1652
  * Directory to interpret glob patterns relative to. Defaults to `pwd()`.
@@ -1077,406 +1655,464 @@ declare type GlobOptions = {
1077
1655
  };
1078
1656
 
1079
1657
  /**
1080
- * Search the filesystem for files matching the specified glob patterns.
1658
+ * Prints special ANSI escape characters to stdout which instruct your terminal
1659
+ * emulator to clear the screen and clear your terminal scrollback.
1081
1660
  *
1082
- * Uses [minimatch](https://www.npmjs.com/package/minimatch) with its default
1083
- * options.
1084
- */
1085
- declare function glob(
1086
- patterns: string | Array<string>,
1087
- options?: GlobOptions
1088
- ): Array<Path>;
1089
-
1090
- /**
1091
- * Clear the contents and scrollback buffer of the tty by printing special characters into stdout.
1661
+ * Identical to {@link console.clear}.
1092
1662
  */
1093
1663
  declare function clear(): void;
1094
1664
 
1095
1665
  interface Console {
1096
- /** Same as {@link clear}(). */
1097
- clear: typeof clear;
1666
+ /**
1667
+ * Logs its arguments to stdout, with a newline appended.
1668
+ *
1669
+ * Any value can be logged, not just strings. Non-string values will be
1670
+ * formatted using {@link inspect}.
1671
+ *
1672
+ * Functionally identical to {@link console.info}, {@link echo}, and
1673
+ * {@link print}. Contrast with {@link console.error}, which prints to stderr
1674
+ * instead of stdout.
1675
+ */
1676
+ log(message?: any, ...optionalParams: any[]): void;
1677
+
1678
+ /**
1679
+ * Logs its arguments to stdout, with a newline appended.
1680
+ *
1681
+ * Any value can be logged, not just strings. Non-string values will be
1682
+ * formatted using {@link inspect}.
1683
+ *
1684
+ * Functionally identical to {@link console.log}, {@link echo}, and
1685
+ * {@link print}. Contrast with {@link console.error}, which prints to stderr
1686
+ * instead of stdout.
1687
+ */
1688
+ info(message?: any, ...optionalParams: any[]): void;
1689
+
1690
+ /**
1691
+ * Logs its arguments to stderr, with a newline appended.
1692
+ *
1693
+ * Any value can be logged, not just strings. Non-string values will be
1694
+ * formatted using {@link inspect}.
1695
+ *
1696
+ * Functionally identical to {@link console.error}. Contrast with
1697
+ * {@link console.log}, which prints to stdout instead of stderr.
1698
+ */
1699
+ warn(message?: any, ...optionalParams: any[]): void;
1700
+
1701
+ /**
1702
+ * Logs its arguments to stderr, with a newline appended.
1703
+ *
1704
+ * Any value can be logged, not just strings. Non-string values will be
1705
+ * formatted using {@link inspect}.
1706
+ *
1707
+ * Functionally identical to {@link console.warn}. Contrast with
1708
+ * {@link console.log}, which prints to stdout instead of stderr.
1709
+ */
1710
+ error(message?: any, ...optionalParams: any[]): void;
1711
+
1712
+ /**
1713
+ * Prints special ANSI escape characters to stdout which instruct your terminal
1714
+ * emulator to clear the screen and clear your terminal scrollback.
1715
+ *
1716
+ * Identical to {@link clear}.
1717
+ */
1718
+ clear(): void;
1098
1719
  }
1099
1720
 
1721
+ declare var console: Console;
1722
+
1723
+ /**
1724
+ * `print` is an alias for {@link console.log}, which prints values to stdout.
1725
+ *
1726
+ * Any value can be logged, not just strings. Non-string values will be
1727
+ * formatted using {@link inspect}.
1728
+ */
1729
+ declare function print(...args: any): void;
1730
+
1100
1731
  /**
1101
- * Remove ANSI control characters from a string.
1732
+ * Removes ANSI control characters from a string.
1102
1733
  */
1103
- declare function stripAnsi(input: string): string;
1734
+ declare function stripAnsi(input: string | number | Path): string;
1104
1735
 
1105
1736
  /**
1106
- * Wrap a string in double quotes, and escape any double-quotes inside using `\"`.
1737
+ * Wraps a string in double quotes, and escapes any double-quotes inside using `\"`.
1107
1738
  */
1108
- declare function quote(input: string | Path): string;
1739
+ declare function quote(input: string | number | Path): string;
1109
1740
 
1110
1741
  // Colors
1111
1742
 
1112
- /** Wrap a string with the ANSI control characters that will make it print as black text. */
1113
- declare function black(input: string | number): string;
1114
- /** Wrap a string with the ANSI control characters that will make it print as red text. */
1115
- declare function red(input: string | number): string;
1116
- /** Wrap a string with the ANSI control characters that will make it print as green text. */
1117
- declare function green(input: string | number): string;
1118
- /** Wrap a string with the ANSI control characters that will make it print as yellow text. */
1119
- declare function yellow(input: string | number): string;
1120
- /** Wrap a string with the ANSI control characters that will make it print as blue text. */
1121
- declare function blue(input: string | number): string;
1122
- /** Wrap a string with the ANSI control characters that will make it print as magenta text. */
1123
- declare function magenta(input: string | number): string;
1124
- /** Wrap a string with the ANSI control characters that will make it print as cyan text. */
1125
- declare function cyan(input: string | number): string;
1126
- /** Wrap a string with the ANSI control characters that will make it print as white text. */
1127
- declare function white(input: string | number): string;
1128
- /** Wrap a string with the ANSI control characters that will make it print as gray text. */
1129
- declare function gray(input: string | number): string;
1130
- /** Wrap a string with the ANSI control characters that will make it print as grey text. */
1131
- declare function grey(input: string | number): string;
1743
+ /** Wraps a string with the ANSI control characters that will make it print as black text. */
1744
+ declare function black(input: string | number | Path): string;
1745
+ /** Wraps a string with the ANSI control characters that will make it print as red text. */
1746
+ declare function red(input: string | number | Path): string;
1747
+ /** Wraps a string with the ANSI control characters that will make it print as green text. */
1748
+ declare function green(input: string | number | Path): string;
1749
+ /** Wraps a string with the ANSI control characters that will make it print as yellow text. */
1750
+ declare function yellow(input: string | number | Path): string;
1751
+ /** Wraps a string with the ANSI control characters that will make it print as blue text. */
1752
+ declare function blue(input: string | number | Path): string;
1753
+ /** Wraps a string with the ANSI control characters that will make it print as magenta text. */
1754
+ declare function magenta(input: string | number | Path): string;
1755
+ /** Wraps a string with the ANSI control characters that will make it print as cyan text. */
1756
+ declare function cyan(input: string | number | Path): string;
1757
+ /** Wraps a string with the ANSI control characters that will make it print as white text. */
1758
+ declare function white(input: string | number | Path): string;
1759
+ /** Wraps a string with the ANSI control characters that will make it print as gray text. (Alias for {@link grey}.) */
1760
+ declare function gray(input: string | number | Path): string;
1761
+ /** Wraps a string with the ANSI control characters that will make it print as grey text. (Alias for {@link gray}.) */
1762
+ declare function grey(input: string | number | Path): string;
1132
1763
 
1133
1764
  // Background Colors
1134
1765
 
1135
- /** Wrap a string with the ANSI control characters that will make it have a black background. */
1136
- declare function bgBlack(input: string | number): string;
1137
- /** Wrap a string with the ANSI control characters that will make it have a red background. */
1138
- declare function bgRed(input: string | number): string;
1139
- /** Wrap a string with the ANSI control characters that will make it have a green background. */
1140
- declare function bgGreen(input: string | number): string;
1141
- /** Wrap a string with the ANSI control characters that will make it have a yellow background. */
1142
- declare function bgYellow(input: string | number): string;
1143
- /** Wrap a string with the ANSI control characters that will make it have a blue background. */
1144
- declare function bgBlue(input: string | number): string;
1145
- /** Wrap a string with the ANSI control characters that will make it have a magenta background. */
1146
- declare function bgMagenta(input: string | number): string;
1147
- /** Wrap a string with the ANSI control characters that will make it have a cyan background. */
1148
- declare function bgCyan(input: string | number): string;
1149
- /** Wrap a string with the ANSI control characters that will make it have a white background. */
1150
- declare function bgWhite(input: string | number): string;
1766
+ /** Wraps a string with the ANSI control characters that will make it have a black background when printed. */
1767
+ declare function bgBlack(input: string | number | Path): string;
1768
+ /** Wraps a string with the ANSI control characters that will make it have a red background when printed. */
1769
+ declare function bgRed(input: string | number | Path): string;
1770
+ /** Wraps a string with the ANSI control characters that will make it have a green background when printed. */
1771
+ declare function bgGreen(input: string | number | Path): string;
1772
+ /** Wraps a string with the ANSI control characters that will make it have a yellow background when printed. */
1773
+ declare function bgYellow(input: string | number | Path): string;
1774
+ /** Wraps a string with the ANSI control characters that will make it have a blue background when printed. */
1775
+ declare function bgBlue(input: string | number | Path): string;
1776
+ /** Wraps a string with the ANSI control characters that will make it have a magenta background when printed. */
1777
+ declare function bgMagenta(input: string | number | Path): string;
1778
+ /** Wraps a string with the ANSI control characters that will make it have a cyan background when printed. */
1779
+ declare function bgCyan(input: string | number | Path): string;
1780
+ /** Wraps a string with the ANSI control characters that will make it have a white background when printed. */
1781
+ declare function bgWhite(input: string | number | Path): string;
1151
1782
 
1152
1783
  // Modifiers
1153
1784
 
1154
- /** Wrap a string with the ANSI control character that resets all styling. */
1155
- declare function reset(input: string | number): string;
1156
- /** Wrap a string with the ANSI control characters that will make it print with a bold style. */
1157
- declare function bold(input: string | number): string;
1158
- /** Wrap a string with the ANSI control characters that will make it print with a dimmed style. */
1159
- declare function dim(input: string | number): string;
1160
- /** Wrap a string with the ANSI control characters that will make it print italicized. */
1161
- declare function italic(input: string | number): string;
1162
- /** Wrap a string with the ANSI control characters that will make it print underlined. */
1163
- declare function underline(input: string | number): string;
1164
- /** Wrap a string with ANSI control characters such that its foreground (text) and background colors are swapped. */
1165
- declare function inverse(input: string | number): string;
1166
- /** Wrap a string with ANSI control characters such that it is hidden. */
1167
- declare function hidden(input: string | number): string;
1168
- /** Wrap a string with the ANSI control characters that will make it print with a horizontal line through its center. */
1169
- declare function strikethrough(input: string | number): string;
1170
-
1171
- /** Split `str` on newline and then return lines matching `pattern`. */
1172
- declare const grepString: {
1173
- /** Split `str` on newline and then return lines matching `pattern`. */
1174
- (str: string, pattern: string | RegExp): Array<string>;
1175
-
1176
- /** Split `str` on newline and then return lines matching `pattern`. */
1177
- (
1178
- str: string,
1179
- pattern: string | RegExp,
1180
- options: { inverse: false }
1181
- ): Array<string>;
1182
-
1183
- /** Split `str` on newline and then return lines NOT matching `pattern`. */
1184
- (
1185
- str: string,
1186
- pattern: string | RegExp,
1187
- options: { inverse: true }
1188
- ): Array<string>;
1189
-
1190
- /** Split `str` on newline and then return lines matching `pattern`. */
1191
- (
1192
- str: string,
1193
- pattern: string | RegExp,
1194
- options: { details: false }
1195
- ): Array<string>;
1196
-
1197
- /** Split `str` on newline and then return lines matching `pattern`. */
1198
- (
1199
- str: string,
1200
- pattern: string | RegExp,
1201
- options: { inverse: false; details: false }
1202
- ): Array<string>;
1785
+ /** Prefixes a string with the ANSI control character that resets all styling. */
1786
+ declare function reset(input: string | number | Path): string;
1787
+ /** Wraps a string with the ANSI control characters that will make it print with a bold style. */
1788
+ declare function bold(input: string | number | Path): string;
1789
+ /** Wraps a string with the ANSI control characters that will make it print with a dimmed style. */
1790
+ declare function dim(input: string | number | Path): string;
1791
+ /** Wraps a string with the ANSI control characters that will make it print italicized. */
1792
+ declare function italic(input: string | number | Path): string;
1793
+ /** Wraps a string with the ANSI control characters that will make it print underlined. */
1794
+ declare function underline(input: string | number | Path): string;
1795
+ /** Wraps a string with ANSI control characters that will make it print with its foreground (text) and background colors swapped. */
1796
+ declare function inverse(input: string | number | Path): string;
1797
+ /** Wraps a string with ANSI control characters that will make it print as hidden. */
1798
+ declare function hidden(input: string | number | Path): string;
1799
+ /** Wraps a string with the ANSI control characters that will make it print with a horizontal line through its center. */
1800
+ declare function strikethrough(input: string | number | Path): string;
1203
1801
 
1204
- /** Split `str` on newline and then return lines NOT matching `pattern`. */
1205
- (
1206
- str: string,
1207
- pattern: string | RegExp,
1208
- options: { inverse: true; details: false }
1209
- ): Array<string>;
1210
-
1211
- /** Split `str` on newline and then return info about lines matching `pattern`. */
1212
- (str: string, pattern: string | RegExp, options: { details: true }): Array<{
1213
- lineNumber: number;
1214
- lineContent: string;
1215
- matches: RegExpMatchArray;
1216
- }>;
1217
-
1218
- /** Split `str` on newline and then return info about lines matching `pattern`. */
1802
+ /**
1803
+ * Splits the string passed into it on `\n` and then returns the lines matching
1804
+ * the specified pattern, as an array of strings or detail objects.
1805
+ *
1806
+ * @param str - The string to search through.
1807
+ * @param pattern - The pattern to find. Can be a string or a RegExp.
1808
+ * @param options - Options which control matching behavior.
1809
+ *
1810
+ * See also {@link grepFile} and {@link String.prototype.grep}.
1811
+ */
1812
+ declare const grepString: {
1219
1813
  (
1220
1814
  str: string,
1221
1815
  pattern: string | RegExp,
1222
- options: { inverse: false; details: true }
1223
- ): Array<string>;
1816
+ options: GrepOptions & { details: true }
1817
+ ): Array<GrepMatchDetail>;
1224
1818
 
1225
- /** Split `str` on newline and then return info about lines NOT matching `pattern`. */
1226
- (
1227
- str: string,
1228
- pattern: string | RegExp,
1229
- options: { inverse: true; details: true }
1230
- ): Array<{
1231
- lineNumber: number;
1232
- lineContent: string;
1233
- matches: RegExpMatchArray;
1234
- }>;
1819
+ (str: string, pattern: string | RegExp, options?: GrepOptions): Array<string>;
1235
1820
  };
1236
1821
 
1237
- /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
1822
+ /**
1823
+ * Reads the file content at `path`, splits it on `\n`, and then returns the
1824
+ * lines matching the specified pattern, as an array of strings or detail objects.
1825
+ *
1826
+ * @param str - The string to search through.
1827
+ * @param pattern - The pattern to find. Can be a string or a RegExp.
1828
+ * @param options - Options which control matching behavior.
1829
+ *
1830
+ * See also {@link grepString} and {@link String.prototype.grep}.
1831
+ */
1238
1832
  declare const grepFile: {
1239
- /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
1240
- (path: string | Path, pattern: string | RegExp): Array<string>;
1241
-
1242
- /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
1243
1833
  (
1244
1834
  path: string | Path,
1245
- pattern: string | RegExp,
1246
- options: { inverse: false }
1247
- ): Array<string>;
1248
-
1249
- /** Read the content at `path`, split it on newline, and then return lines NOT matching `pattern`. */
1250
- (
1251
- path: string | Path,
1252
- pattern: string | RegExp,
1253
- options: { inverse: true }
1254
- ): Array<string>;
1255
-
1256
- /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
1257
- (
1258
- path: string | Path,
1259
- pattern: string | RegExp,
1260
- options: { details: false }
1261
- ): Array<string>;
1262
-
1263
- /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
1264
- (
1265
- path: string | Path,
1266
- pattern: string | RegExp,
1267
- options: { inverse: false; details: false }
1268
- ): Array<string>;
1269
-
1270
- /** Read the content at `path`, split it on newline, and then return lines NOT matching `pattern`. */
1271
- (
1272
- path: string | Path,
1273
- pattern: string | RegExp,
1274
- options: { inverse: true; details: false }
1275
- ): Array<string>;
1276
-
1277
- /** Read the content at `path`, split it on newline, and then return info about lines matching `pattern`. */
1278
- (
1279
- path: string | Path,
1280
- pattern: string | RegExp,
1281
- options: { details: true }
1282
- ): Array<{
1283
- lineNumber: number;
1284
- lineContent: string;
1285
- matches: RegExpMatchArray;
1286
- }>;
1287
-
1288
- /** Read the content at `path`, split it on newline, and then return info about lines matching `pattern`. */
1289
- (
1290
- path: string | Path,
1291
- pattern: string | RegExp,
1292
- options: { inverse: false; details: true }
1293
- ): Array<string>;
1294
-
1295
- /** Read the content at `path`, split it on newline, and then return info about lines NOT matching `pattern`. */
1296
- (
1297
- path: string | Path,
1298
- pattern: string | RegExp,
1299
- options: { inverse: true; details: true }
1300
- ): Array<{
1301
- lineNumber: number;
1302
- lineContent: string;
1303
- matches: RegExpMatchArray;
1304
- }>;
1305
- };
1306
-
1307
- interface String {
1308
- // Same as grepString but without the first argument.
1309
- grep: {
1310
- /** Split the string on newline and then return lines matching `pattern`. */
1311
- (pattern: string | RegExp): Array<string>;
1312
-
1313
- /** Split the string on newline and then return lines matching `pattern`. */
1314
- (pattern: string | RegExp, options: { inverse: false }): Array<string>;
1315
-
1316
- /** Split the string on newline and then return lines NOT matching `pattern`. */
1317
- (pattern: string | RegExp, options: { inverse: true }): Array<string>;
1318
-
1319
- /** Split the string on newline and then return lines matching `pattern`. */
1320
- (pattern: string | RegExp, options: { details: false }): Array<string>;
1321
-
1322
- /** Split the string on newline and then return lines matching `pattern`. */
1323
- (
1324
- pattern: string | RegExp,
1325
- options: { inverse: false; details: false }
1326
- ): Array<string>;
1327
-
1328
- /** Split the string on newline and then return lines NOT matching `pattern`. */
1329
- (
1330
- pattern: string | RegExp,
1331
- options: { inverse: true; details: false }
1332
- ): Array<string>;
1333
-
1334
- /** Split the string on newline and then return info about lines matching `pattern`. */
1335
- (pattern: string | RegExp, options: { details: true }): Array<{
1336
- lineNumber: number;
1337
- lineContent: string;
1338
- matches: RegExpMatchArray;
1339
- }>;
1340
-
1341
- /** Split the string on newline and then return info about lines matching `pattern`. */
1342
- (
1343
- pattern: string | RegExp,
1344
- options: { inverse: false; details: true }
1345
- ): Array<string>;
1346
-
1347
- /** Split the string on newline and then return info about lines NOT matching `pattern`. */
1348
- (
1349
- pattern: string | RegExp,
1350
- options: { inverse: true; details: true }
1351
- ): Array<{
1352
- lineNumber: number;
1353
- lineContent: string;
1354
- matches: RegExpMatchArray;
1355
- }>;
1356
- };
1357
- }
1358
-
1359
- declare type TypeValidator<T> = (value: any) => value is T;
1360
-
1361
- declare type CoerceToTypeValidator<V extends CoerceableToTypeValidator> =
1362
- V extends StringConstructor
1363
- ? TypeValidator<string>
1364
- : V extends NumberConstructor
1365
- ? TypeValidator<number>
1366
- : V extends BooleanConstructor
1367
- ? TypeValidator<boolean>
1368
- : V extends BigIntConstructor
1369
- ? TypeValidator<BigInt>
1370
- : V extends SymbolConstructor
1371
- ? TypeValidator<Symbol>
1372
- : V extends RegExpConstructor
1373
- ? TypeValidator<RegExp>
1374
- : V extends ArrayConstructor
1375
- ? TypeValidator<Array<unknown>>
1376
- : V extends SetConstructor
1377
- ? TypeValidator<Set<unknown>>
1378
- : V extends MapConstructor
1379
- ? TypeValidator<Map<unknown, unknown>>
1380
- : V extends ObjectConstructor
1381
- ? TypeValidator<{
1382
- [key: string | number | symbol]: unknown;
1383
- }>
1384
- : V extends DateConstructor
1385
- ? TypeValidator<Date>
1386
- : V extends FunctionConstructor
1387
- ? TypeValidator<Function>
1388
- : V extends ArrayBufferConstructor
1389
- ? TypeValidator<ArrayBuffer>
1390
- : V extends SharedArrayBufferConstructor
1391
- ? TypeValidator<SharedArrayBuffer>
1392
- : V extends DataViewConstructor
1393
- ? TypeValidator<DataView>
1394
- : V extends Int8ArrayConstructor
1395
- ? TypeValidator<Int8Array>
1396
- : V extends Uint8ArrayConstructor
1397
- ? TypeValidator<Uint8Array>
1398
- : V extends Uint8ClampedArrayConstructor
1399
- ? TypeValidator<Uint8ClampedArray>
1400
- : V extends Int16ArrayConstructor
1401
- ? TypeValidator<Int16Array>
1402
- : V extends Uint16ArrayConstructor
1403
- ? TypeValidator<Uint16Array>
1404
- : V extends Int32ArrayConstructor
1405
- ? TypeValidator<Int32Array>
1406
- : V extends Uint32ArrayConstructor
1407
- ? TypeValidator<Uint32Array>
1408
- : V extends Float32ArrayConstructor
1409
- ? TypeValidator<Float32Array>
1410
- : V extends Float64ArrayConstructor
1411
- ? TypeValidator<Float64Array>
1412
- : V extends RegExp
1413
- ? TypeValidator<string>
1414
- : V extends {}
1415
- ? TypeValidator<{
1416
- [key in keyof V]: CoerceToTypeValidator<V[key]>;
1417
- }>
1418
- : V extends []
1419
- ? TypeValidator<[]>
1420
- : V extends [any]
1421
- ? TypeValidator<Array<CoerceToTypeValidator<V[0]>>>
1422
- : V extends Array<any>
1423
- ? TypeValidator<Array<unknown>>
1424
- : V extends {
1425
- new (...args: any): any;
1426
- }
1427
- ? TypeValidator<InstanceType<V>>
1428
- : TypeValidator<V>;
1429
-
1430
- declare type CoerceableToTypeValidator =
1431
- | boolean
1432
- | number
1433
- | string
1434
- | bigint
1435
- | undefined
1436
- | null
1437
- | RegExp
1438
- | StringConstructor
1439
- | NumberConstructor
1440
- | BooleanConstructor
1441
- | BigIntConstructor
1442
- | SymbolConstructor
1443
- | RegExpConstructor
1444
- | ArrayConstructor
1445
- | SetConstructor
1446
- | MapConstructor
1447
- | ObjectConstructor
1448
- | DateConstructor
1449
- | FunctionConstructor
1450
- | ArrayBufferConstructor
1451
- | SharedArrayBufferConstructor
1452
- | DataViewConstructor
1453
- | Int8ArrayConstructor
1454
- | Uint8ArrayConstructor
1455
- | Uint8ClampedArrayConstructor
1456
- | Int16ArrayConstructor
1457
- | Uint16ArrayConstructor
1458
- | Int32ArrayConstructor
1459
- | Uint32ArrayConstructor
1460
- | Float32ArrayConstructor
1461
- | Float64ArrayConstructor
1462
- | {}
1463
- | []
1464
- | [any]
1465
- | Array<any>
1466
- | {
1467
- new (...args: any): any;
1468
- };
1835
+ pattern: string | RegExp,
1836
+ options: GrepOptions & { details: true }
1837
+ ): Array<GrepMatchDetail>;
1469
1838
 
1470
- declare type UnwrapTypeFromCoerceableOrValidator<
1471
- V extends CoerceableToTypeValidator | TypeValidator<any> | unknown
1472
- > = V extends TypeValidator<infer T>
1473
- ? T
1474
- : V extends CoerceableToTypeValidator
1475
- ? CoerceToTypeValidator<V> extends TypeValidator<infer T>
1476
- ? T
1477
- : never
1478
- : unknown;
1839
+ (
1840
+ path: string | Path,
1841
+ pattern: string | RegExp,
1842
+ options?: GrepOptions
1843
+ ): Array<string>;
1844
+ };
1845
+
1846
+ interface String {
1847
+ // Same as grepString but without the first argument.
1848
+ /**
1849
+ * Splits the target string on `\n` and then returns the lines matching the
1850
+ * specified pattern, as an array of strings or detail objects.
1851
+ *
1852
+ * @param str - The string to search through.
1853
+ * @param pattern - The pattern to find. Can be a string or a RegExp.
1854
+ * @param options - Options which control matching behavior.
1855
+ *
1856
+ * See also {@link grepString} and {@link grepFile}.
1857
+ */
1858
+ grep: {
1859
+ (
1860
+ pattern: string | RegExp,
1861
+ options: GrepOptions & { details: true }
1862
+ ): Array<GrepMatchDetail>;
1863
+
1864
+ (pattern: string | RegExp, options?: GrepOptions): Array<string>;
1865
+ };
1866
+ }
1867
+
1868
+ declare interface GrepOptions {
1869
+ /**
1870
+ * When `inverse` is true, the grep function returns those lines which DON'T
1871
+ * match the pattern, instead of those which do. Defaults to `false`.
1872
+ */
1873
+ inverse?: boolean;
1874
+
1875
+ /**
1876
+ * When `details` is true, the grep function returns an array of
1877
+ * {@link GrepMatchDetail} objects instead of an array of strings. Defaults to
1878
+ * `false`.
1879
+ */
1880
+ details?: boolean;
1881
+ }
1882
+
1883
+ /**
1884
+ * When `grepString`, `grepFile`, or `String.prototype.grep` are called with the
1885
+ * `{ details: true }` option set, an Array of `GrepMatchDetail` objects is
1886
+ * returned.
1887
+ */
1888
+ declare interface GrepMatchDetail {
1889
+ lineNumber: number;
1890
+ lineContent: string;
1891
+ matches: RegExpMatchArray;
1892
+ }
1479
1893
 
1894
+ /**
1895
+ * The `types` namespace object contains various functions which can be used to
1896
+ * identify the type of a value at runtime. It is based on
1897
+ * [pheno](https://github.com/suchipi/pheno), with some yavascript-specific
1898
+ * extensions.
1899
+ *
1900
+ * ## Usage
1901
+ *
1902
+ * To check that a value is of a type, use `is`. To assert that a value is of a
1903
+ * type, use `assert.type`:
1904
+ *
1905
+ * ```ts
1906
+ * is("hi", types.string); // true
1907
+ * is("hi", types.number); // false
1908
+ * is({ blah: 42 }, types.objectWithProperties({ blah: types.number })); // true
1909
+ *
1910
+ * assert.type("hi", types.string);
1911
+ * assert.type("hi", types.number); // throws
1912
+ * assert.type({ blah: 42 }, types.objectWithProperties({ blah: types.number }));
1913
+ * ```
1914
+ *
1915
+ * In many cases, you can use a "normal" JavaScript value for the type instead
1916
+ * of something from the `types` namespace. For instance, the following code
1917
+ * block is equivalent to the previous one:
1918
+ *
1919
+ * ```ts
1920
+ * is("hi", String); // true
1921
+ * is("hi", Number); // false
1922
+ * is({ blah: 42 }, { blah: Number }); // true
1923
+ *
1924
+ * assert.type("hi", String);
1925
+ * assert.type("hi", Number); // throws
1926
+ * assert.type({ blah: 42 }, { blah: Number });
1927
+ * ```
1928
+ *
1929
+ * For more info about using "normal" values, see the "Coercion" heading below.
1930
+ *
1931
+ * ## Explanation
1932
+ *
1933
+ * There are two kinds of function properties found on the `types` namespace:
1934
+ * those which return a boolean, and those which return a function. Functions
1935
+ * which return a boolean are called "type validators", and can be used to check
1936
+ * the type of a value. For example, `types.number` is a type validator:
1937
+ *
1938
+ * ```ts
1939
+ * is(42, types.number); // returns true
1940
+ * ```
1941
+ *
1942
+ * The other kind of function is a function which returns a function. These are
1943
+ * called "type validator constructors", because the function they return is a
1944
+ * type validator. They are used to construct complex type validators. For
1945
+ * example, `types.exactString` is a type validator constructor:
1946
+ *
1947
+ * ```ts
1948
+ * const myType = types.exactString("potato");
1949
+ * // myType is a function which returns true or false
1950
+ *
1951
+ * is("eggplant", myType); // returns false
1952
+ * is("potato", myType); // returns true
1953
+ * ```
1954
+ *
1955
+ * ## List of Functions
1956
+ *
1957
+ * ### Type Validators
1958
+ *
1959
+ * Here is a list of all the type validators:
1960
+ *
1961
+ * - `any`
1962
+ * - `anyArray`
1963
+ * - `anyFunction`
1964
+ * - `anyMap`
1965
+ * - `anyObject`
1966
+ * - `anySet`
1967
+ * - `anyTypeValidator`
1968
+ * - `array` (alias of `arrayOfUnknown`)
1969
+ * - `arrayOfAny`
1970
+ * - `arrayOfUnknown`
1971
+ * - `Array` (alias of `arrayOfUnknown`)
1972
+ * - `bigint`
1973
+ * - `BigInt` (alias of `bigint`)
1974
+ * - `boolean`
1975
+ * - `Boolean` (alias of `boolean`)
1976
+ * - `Date`
1977
+ * - `Error`
1978
+ * - `false`
1979
+ * - `falsy`
1980
+ * - `Function` (alias of `unknownFunction`)
1981
+ * - `Infinity`
1982
+ * - `integer`
1983
+ * - `map` (alias of `unknownMap`)
1984
+ * - `Map` (alias of `unknownMap`)
1985
+ * - `NaN`
1986
+ * - `NegativeInfinity`
1987
+ * - `never`
1988
+ * - `nonNullOrUndefined`
1989
+ * - `null`
1990
+ * - `nullish`
1991
+ * - `void` (alias of `nullish`)
1992
+ * - `number` (doesn't include NaN, Infinity, or -Infinity)
1993
+ * - `Number` (alias of `number`)
1994
+ * - `numberIncludingNanAndInfinities`
1995
+ * - `object` (alias of `unknownObject`)
1996
+ * - `Object` (alias of `unknownObject`)
1997
+ * - `objectOrNull`
1998
+ * - `RegExp`
1999
+ * - `set` (alias of `unknownSet`)
2000
+ * - `Set` (alias of `unknownSet`)
2001
+ * - `string`
2002
+ * - `String` (alias of `string`)
2003
+ * - `Symbol`
2004
+ * - `symbol` (alias of `Symbol`)
2005
+ * - `true`
2006
+ * - `truthy`
2007
+ * - `undefined`
2008
+ * - `unknown`
2009
+ * - `unknownFunction`
2010
+ * - `unknownMap`
2011
+ * - `unknownObject`
2012
+ * - `unknownSet`
2013
+ * - `unknownTypeValidator`
2014
+ * - `ArrayBuffer`
2015
+ * - `SharedArrayBuffer`
2016
+ * - `DataView`
2017
+ * - `TypedArray`
2018
+ * - `Int8Array`
2019
+ * - `Uint8Array`
2020
+ * - `Uint8ClampedArray`
2021
+ * - `Int16Array`
2022
+ * - `Uint16Array`
2023
+ * - `Int32Array`
2024
+ * - `Uint32Array`
2025
+ * - `Float32Array`
2026
+ * - `Float64Array`
2027
+ * - `FILE`
2028
+ * - `Path`
2029
+ * - `JSX.Element` (alias of `JSX.unknownElement`)
2030
+ * - `JSX.unknownElement`
2031
+ * - `JSX.anyElement`
2032
+ * - `JSX.Fragment`
2033
+ *
2034
+ * ### Type Validator Constructors
2035
+ *
2036
+ * And all the type validator constructors:
2037
+ *
2038
+ * - `and`
2039
+ * - `arrayOf`
2040
+ * - `exactBigInt`
2041
+ * - `exactNumber`
2042
+ * - `exactString`
2043
+ * - `exactSymbol`
2044
+ * - `hasClassName`
2045
+ * - `hasToStringTag`
2046
+ * - `instanceOf`
2047
+ * - `intersection`
2048
+ * - `mapOf`
2049
+ * - `mappingObjectOf`
2050
+ * - `maybe`
2051
+ * - `objectWithOnlyTheseProperties`
2052
+ * - `objectWithProperties`
2053
+ * - `or`
2054
+ * - `optional`
2055
+ * - `partialObjectWithProperties`
2056
+ * - `record`
2057
+ * - `setOf`
2058
+ * - `stringMatching`
2059
+ * - `symbolFor`
2060
+ * - `union`
2061
+ *
2062
+ * ## Coercion
2063
+ *
2064
+ * There is also a function, `types.coerce`, which returns an appropriate type
2065
+ * validator value for a given input value, using the following logic:
2066
+ *
2067
+ * | Input value | Output validator |
2068
+ * | ----------------------------- | ---------------------------------- |
2069
+ * | `String` or `string` global | `types.string` |
2070
+ * | `Number` or `number` global | `types.number` |
2071
+ * | `Boolean` or `boolean` global | `types.boolean` |
2072
+ * | `BigInt` or `bigint` global | `types.bigint` |
2073
+ * | `Symbol` global | `types.Symbol` |
2074
+ * | `RegExp` global | `types.RegExp` |
2075
+ * | `Array` global | `types.arrayOfUnknown` |
2076
+ * | `Set` global | `types.unknownSet` |
2077
+ * | `Map` global | `types.unknownMap` |
2078
+ * | `Object` global | `types.unknownObject` |
2079
+ * | `Date` global | `types.Date` |
2080
+ * | `Function` global | `types.unknownFunction` |
2081
+ * | `ArrayBuffer` global | `types.ArrayBuffer` |
2082
+ * | `SharedArrayBuffer` global | `types.SharedArrayBuffer` |
2083
+ * | `DataView` global | `types.DataView` |
2084
+ * | `Int8Array` global | `types.Int8Array` |
2085
+ * | `Uint8Array` global | `types.Uint8Array` |
2086
+ * | `Uint8ClampedArray` global | `types.Uint8ClampedArray` |
2087
+ * | `Int16Array` global | `types.Int16Array` |
2088
+ * | `Uint16Array` global | `types.Uint16Array` |
2089
+ * | `Int32Array` global | `types.Int32Array` |
2090
+ * | `Uint32Array` global | `types.Uint32Array` |
2091
+ * | `Float32Array` global | `types.Float32Array` |
2092
+ * | `Float64Array` global | `types.Float64Array` |
2093
+ * | `Path` global | `types.Path` |
2094
+ * | Any RegExp value | Validator for matching strings |
2095
+ * | Empty array | Validator for empty arrays |
2096
+ * | Array with one item | Validator for array of that item |
2097
+ * | Array with multiple items | Validator for tuple of those types |
2098
+ * | Class constructor function | Validator for instances of it |
2099
+ * | Any Object value | Validator for same-shaped object |
2100
+ * | null | `types.null` |
2101
+ * | undefined | `types.undefined` |
2102
+ * | true | `types.true` |
2103
+ * | false | `types.false` |
2104
+ * | NaN | `types.NaN` |
2105
+ * | Infinity | `types.Infinity` |
2106
+ * | `-Infinity` | `types.NegativeInfinity` |
2107
+ * | Any string value | `types.exactString(<the value>)` |
2108
+ * | Any 'normal' number value | `types.exactNumber(<the value>)` |
2109
+ * | Any Symbol value | `types.exactSymbol(<the value>)` |
2110
+ * | Any BigInt value | `types.exactBigInt(<the value>)` |
2111
+ *
2112
+ * > All type constructors, as well as `is` and `assert.type`, do coercion
2113
+ * > automatically! This means that in many cases, you do not need to access
2114
+ * > properties from the `types` namespace.
2115
+ */
1480
2116
  declare const types: {
1481
2117
  // basic types
1482
2118
  any: TypeValidator<any>;
@@ -1562,17 +2198,9 @@ declare const types: {
1562
2198
  exactSymbol<T extends symbol>(sym: T): TypeValidator<T>;
1563
2199
  hasClassName<Name extends string>(
1564
2200
  name: Name
1565
- ): TypeValidator<{
1566
- constructor: Function & {
1567
- name: Name;
1568
- };
1569
- }>;
2201
+ ): TypeValidator<{ constructor: Function & { name: Name } }>;
1570
2202
  hasToStringTag(name: string): TypeValidator<any>;
1571
- instanceOf<
1572
- Klass extends Function & {
1573
- prototype: any;
1574
- }
1575
- >(
2203
+ instanceOf<Klass extends Function & { prototype: any }>(
1576
2204
  klass: Klass
1577
2205
  ): TypeValidator<Klass["prototype"]>;
1578
2206
  stringMatching(regexp: RegExp): TypeValidator<string>;
@@ -2690,7 +3318,6 @@ declare const types: {
2690
3318
  ) => TypeValidator<UnwrapTypeFromCoerceableOrValidator<V>>;
2691
3319
 
2692
3320
  FILE: TypeValidator<FILE>;
2693
- Module: TypeValidator<{ [key: string]: unknown }>;
2694
3321
  Path: TypeValidator<Path>;
2695
3322
  JSX: {
2696
3323
  unknownElement: TypeValidator<
@@ -2704,10 +3331,177 @@ declare const types: {
2704
3331
  };
2705
3332
  };
2706
3333
 
3334
+ declare type TypeValidator<T> = (value: any) => value is T;
3335
+
3336
+ declare type CoerceToTypeValidator<V extends CoerceableToTypeValidator> =
3337
+ V extends StringConstructor
3338
+ ? TypeValidator<string>
3339
+ : V extends NumberConstructor
3340
+ ? TypeValidator<number>
3341
+ : V extends BooleanConstructor
3342
+ ? TypeValidator<boolean>
3343
+ : V extends BigIntConstructor
3344
+ ? TypeValidator<BigInt>
3345
+ : V extends SymbolConstructor
3346
+ ? TypeValidator<Symbol>
3347
+ : V extends RegExpConstructor
3348
+ ? TypeValidator<RegExp>
3349
+ : V extends ArrayConstructor
3350
+ ? TypeValidator<Array<unknown>>
3351
+ : V extends SetConstructor
3352
+ ? TypeValidator<Set<unknown>>
3353
+ : V extends MapConstructor
3354
+ ? TypeValidator<Map<unknown, unknown>>
3355
+ : V extends ObjectConstructor
3356
+ ? TypeValidator<{
3357
+ [key: string | number | symbol]: unknown;
3358
+ }>
3359
+ : V extends DateConstructor
3360
+ ? TypeValidator<Date>
3361
+ : V extends FunctionConstructor
3362
+ ? TypeValidator<Function>
3363
+ : V extends ArrayBufferConstructor
3364
+ ? TypeValidator<ArrayBuffer>
3365
+ : V extends SharedArrayBufferConstructor
3366
+ ? TypeValidator<SharedArrayBuffer>
3367
+ : V extends DataViewConstructor
3368
+ ? TypeValidator<DataView>
3369
+ : V extends Int8ArrayConstructor
3370
+ ? TypeValidator<Int8Array>
3371
+ : V extends Uint8ArrayConstructor
3372
+ ? TypeValidator<Uint8Array>
3373
+ : V extends Uint8ClampedArrayConstructor
3374
+ ? TypeValidator<Uint8ClampedArray>
3375
+ : V extends Int16ArrayConstructor
3376
+ ? TypeValidator<Int16Array>
3377
+ : V extends Uint16ArrayConstructor
3378
+ ? TypeValidator<Uint16Array>
3379
+ : V extends Int32ArrayConstructor
3380
+ ? TypeValidator<Int32Array>
3381
+ : V extends Uint32ArrayConstructor
3382
+ ? TypeValidator<Uint32Array>
3383
+ : V extends Float32ArrayConstructor
3384
+ ? TypeValidator<Float32Array>
3385
+ : V extends Float64ArrayConstructor
3386
+ ? TypeValidator<Float64Array>
3387
+ : V extends RegExp
3388
+ ? TypeValidator<string>
3389
+ : V extends {}
3390
+ ? TypeValidator<{
3391
+ [key in keyof V]: CoerceToTypeValidator<V[key]>;
3392
+ }>
3393
+ : V extends []
3394
+ ? TypeValidator<[]>
3395
+ : V extends [any]
3396
+ ? TypeValidator<Array<CoerceToTypeValidator<V[0]>>>
3397
+ : V extends Array<any>
3398
+ ? TypeValidator<Array<unknown>>
3399
+ : V extends {
3400
+ new (...args: any): any;
3401
+ }
3402
+ ? TypeValidator<InstanceType<V>>
3403
+ : TypeValidator<V>;
3404
+
3405
+ declare type CoerceableToTypeValidator =
3406
+ | boolean
3407
+ | number
3408
+ | string
3409
+ | bigint
3410
+ | undefined
3411
+ | null
3412
+ | RegExp
3413
+ | StringConstructor
3414
+ | NumberConstructor
3415
+ | BooleanConstructor
3416
+ | BigIntConstructor
3417
+ | SymbolConstructor
3418
+ | RegExpConstructor
3419
+ | ArrayConstructor
3420
+ | SetConstructor
3421
+ | MapConstructor
3422
+ | ObjectConstructor
3423
+ | DateConstructor
3424
+ | FunctionConstructor
3425
+ | ArrayBufferConstructor
3426
+ | SharedArrayBufferConstructor
3427
+ | DataViewConstructor
3428
+ | Int8ArrayConstructor
3429
+ | Uint8ArrayConstructor
3430
+ | Uint8ClampedArrayConstructor
3431
+ | Int16ArrayConstructor
3432
+ | Uint16ArrayConstructor
3433
+ | Int32ArrayConstructor
3434
+ | Uint32ArrayConstructor
3435
+ | Float32ArrayConstructor
3436
+ | Float64ArrayConstructor
3437
+ | {}
3438
+ | []
3439
+ | [any]
3440
+ | Array<any>
3441
+ | {
3442
+ new (...args: any): any;
3443
+ };
3444
+
3445
+ declare type UnwrapTypeFromCoerceableOrValidator<
3446
+ V extends CoerceableToTypeValidator | TypeValidator<any> | unknown
3447
+ > = V extends TypeValidator<infer T>
3448
+ ? T
3449
+ : V extends CoerceableToTypeValidator
3450
+ ? CoerceToTypeValidator<V> extends TypeValidator<infer T>
3451
+ ? T
3452
+ : never
3453
+ : unknown;
3454
+
2707
3455
  /**
2708
- * Returns whether `value` is of type `type`. Useful for validating that values have the correct type at runtime, in library functions or etc.
3456
+ * Returns whether `value` is of type `type`. Useful for validating that values
3457
+ * have the correct type at runtime, in library functions or etc.
2709
3458
  *
2710
- * Run `help(is)` for more info.
3459
+ * The `type` parameter can be any of the following:
3460
+ *
3461
+ * - a TypeValidator function from the `types` namespace
3462
+ * - a global constructor like `String`, `Number`, `Boolean`, `Set`,
3463
+ * `Int8Array`, etc
3464
+ * - a user-defined class
3465
+ * - a primitive value like `true`, `false`, `null`, or `42`
3466
+ * - a Regular Expression (to match strings that match the regexp)
3467
+ * - an object or array containing any combination of the above
3468
+ *
3469
+ * Note that yavascript has the following global aliases defined, which are also
3470
+ * valid types:
3471
+ *
3472
+ * ```ts
3473
+ * const bigint = BigInt;
3474
+ * const boolean = Boolean;
3475
+ * const number = Number;
3476
+ * const string = String;
3477
+ * const symbol = Symbol;
3478
+ * ```
3479
+ *
3480
+ * ## Example
3481
+ *
3482
+ * ```ts
3483
+ * is(42, Number); // true
3484
+ * is(42, number); // true
3485
+ * is(42, types.number); // true
3486
+ *
3487
+ * is(42, String); // false
3488
+ * is(42, Set); // false
3489
+ * is(42, Array); // false
3490
+ *
3491
+ * is(42, 42); // true
3492
+ * is(42, 45); // false
3493
+ *
3494
+ * is({ kind: "success", data: 99 }, { kind: "success" }); // true
3495
+ * ```
3496
+ *
3497
+ * ```ts
3498
+ * // Defined in yavascript/src/api/is
3499
+ * declare function is(value: any, type: TypeValidator<any>): boolean;
3500
+ * ```
3501
+ *
3502
+ * See also {@link types} (which contains {@link TypeValidator}s that can be
3503
+ * used by `is`) and {@link assert.type} (which throws an error instead of
3504
+ * returning a boolean).
2711
3505
  */
2712
3506
  declare const is: <T extends TypeValidator<any> | CoerceableToTypeValidator>(
2713
3507
  value: any,
@@ -2715,7 +3509,8 @@ declare const is: <T extends TypeValidator<any> | CoerceableToTypeValidator>(
2715
3509
  ) => value is UnwrapTypeFromCoerceableOrValidator<T>;
2716
3510
 
2717
3511
  /**
2718
- * Alias to {@link is}, for Civet, because `is` is a reserved keyword in Civet.
3512
+ * Alias to {@link is}, for when using the Civet language, because `is` is a
3513
+ * reserved keyword in Civet.
2719
3514
  */
2720
3515
  declare const _is: typeof is;
2721
3516
 
@@ -2734,9 +3529,11 @@ declare const assert: {
2734
3529
  : ValueType;
2735
3530
 
2736
3531
  /**
2737
- * Throws an error if `value` is not of the type `type`.
3532
+ * Throws an error if its argument isn't the correct type.
2738
3533
  *
2739
- * `type` should be either a {@link TypeValidator}, or a value which can be coerced into one via {@link types.coerce}.
3534
+ * @param value - The value to test the type of
3535
+ * @param type - The type that `value` should be, as either a `TypeValidator` (from the `types.*` namespace) or a value which can be coerced into a `TypeValidator` via the `types.coerce` function, like `String`, `Boolean`, etc.
3536
+ * @param message - An optional error message to use. If unspecified, a generic-but-descriptive message will be used.
2740
3537
  */
2741
3538
  type: <T extends TypeValidator<any> | CoerceableToTypeValidator>(
2742
3539
  value: any,
@@ -2746,82 +3543,8 @@ declare const assert: {
2746
3543
  };
2747
3544
 
2748
3545
  /**
2749
- * The data source of a pipe operation; either an in-memory object, or a
2750
- * file stream.
2751
- *
2752
- * - Use `maxLength` to limit how much data to read.
2753
- * - Use `until` to stop reading once a certain byte or character has been
2754
- * read.
2755
- * - Use `path` or `fd` to open a file (or pass a FILE or Path object).
2756
- */
2757
- declare type PipeSource =
2758
- | { data: string; maxLength?: number; until?: string | byte }
2759
- | ArrayBuffer
2760
- | { data: ArrayBuffer; maxLength?: number; until?: string | byte }
2761
- | SharedArrayBuffer
2762
- | { data: SharedArrayBuffer; maxLength?: number; until?: string | byte }
2763
- | TypedArray
2764
- | { data: TypedArray; maxLength?: number; until?: string | byte }
2765
- | DataView
2766
- | { data: DataView; maxLength?: number; until?: string | byte }
2767
- | FILE
2768
- | { data: FILE; maxLength?: number; until?: string | byte }
2769
- | Path
2770
- | { path: Path | string; maxLength?: number; until?: string | byte }
2771
- | { fd: number; maxLength?: number; until?: string | byte };
2772
-
2773
- /**
2774
- * The target destination of a pipe operation; either an in-memory object, or a
2775
- * file stream.
2776
- *
2777
- * - Use `intoExisting` to put data into an existing object or file handle.
2778
- * - Use `intoNew` to put data into a new object.
2779
- * - Use `path` or `fd` to create a new file handle and put data into it.
2780
- */
2781
- declare type PipeDestination =
2782
- | ArrayBuffer
2783
- | SharedArrayBuffer
2784
- | DataView
2785
- | TypedArray
2786
- | Path
2787
- | FILE
2788
- | ArrayBufferConstructor
2789
- | SharedArrayBufferConstructor
2790
- | DataViewConstructor
2791
- | TypedArrayConstructor
2792
- | StringConstructor
2793
- | { path: string }
2794
- | { fd: number };
2795
-
2796
- /**
2797
- * Copy data from one source into the given target. Returns the number of bytes
2798
- * written, and the target that data was written into.
3546
+ * This API is a work-in-progress and is subject to change at any time.
2799
3547
  */
2800
- declare function pipe<Dest extends PipeDestination>(
2801
- from: PipeSource,
2802
- to: Dest
2803
- ): {
2804
- bytesTransferred: number;
2805
- target: Dest extends
2806
- | ArrayBuffer
2807
- | SharedArrayBuffer
2808
- | DataView
2809
- | FILE
2810
- | { path: string }
2811
- | { fd: number }
2812
- ? Dest
2813
- : Dest extends
2814
- | ArrayBufferConstructor
2815
- | SharedArrayBufferConstructor
2816
- | DataViewConstructor
2817
- | TypedArrayConstructor
2818
- | DataViewConstructor
2819
- ? Dest["prototype"]
2820
- : Dest extends StringConstructor
2821
- ? string
2822
- : never;
2823
- };
2824
-
2825
3548
  interface InteractivePrompt {
2826
3549
  prompt?: () => string;
2827
3550
  printInput?: (input: string) => void;
@@ -2840,6 +3563,9 @@ interface InteractivePrompt {
2840
3563
  start(): void;
2841
3564
  }
2842
3565
 
3566
+ /**
3567
+ * This API is a work-in-progress and is subject to change at any time.
3568
+ */
2843
3569
  interface InteractivePromptConstructor {
2844
3570
  new (
2845
3571
  handleInput: (input: string) => void,
@@ -2862,14 +3588,16 @@ interface InteractivePromptConstructor {
2862
3588
  prototype: InteractivePrompt;
2863
3589
  }
2864
3590
 
2865
- /** wip experimental use at your own risk */
3591
+ /**
3592
+ * This API is a work-in-progress and is subject to change at any time.
3593
+ */
2866
3594
  declare var InteractivePrompt: InteractivePromptConstructor;
2867
3595
 
2868
3596
  /**
2869
3597
  * Launch the Yavascript REPL (read-eval-print-loop).
2870
3598
  *
2871
3599
  * @param context Variables to make available as globals within the repl.
2872
- * @param lang The langauge to use in the repl. Defaults to "javascript".
3600
+ * @param lang The language to use in the repl. Defaults to "javascript".
2873
3601
  */
2874
3602
  declare const startRepl: {
2875
3603
  (
@@ -2883,6 +3611,7 @@ declare const startRepl: {
2883
3611
  | "tsx"
2884
3612
  | "coffee"
2885
3613
  | "coffeescript"
3614
+ | "civet"
2886
3615
  ): void;
2887
3616
 
2888
3617
  /**
@@ -2895,6 +3624,19 @@ declare const startRepl: {
2895
3624
  /**
2896
3625
  * An object that points to a git repository on disk and provides utility
2897
3626
  * methods for getting information from that repo.
3627
+ *
3628
+ * To use it, construct a GitRepo object, passing in the path to the repo:
3629
+ *
3630
+ * ```ts
3631
+ * // The path here is just an example
3632
+ * const repo = new GitRepo("/home/suchipi/Code/yavascript");
3633
+ * ```
3634
+ *
3635
+ * Then, you can use methods/properties on the `repo` object:
3636
+ *
3637
+ * ```ts
3638
+ * console.log(repo.branchName() || repo.commitSHA());
3639
+ * ```
2898
3640
  */
2899
3641
  declare class GitRepo {
2900
3642
  /**
@@ -2902,6 +3644,88 @@ declare class GitRepo {
2902
3644
  * directory ancestry to find a `.git` folder, then returns the Path that
2903
3645
  * contains that `.git` folder. If no `.git` folder is found, an error will be
2904
3646
  * thrown.
3647
+ *
3648
+ * For example, if you have a git repo at `/home/suchipi/Code/my-project`,
3649
+ * such that `/home/suchipi/Code/my-project/.git` exists, calling
3650
+ * `GitRepo.findRoot("/home/suchipi/Code/my-project/src/index.js")` will
3651
+ * return a `Path` object pointing to `/home/suchipi/Code/my-project`.
3652
+ *
3653
+ * This function can be useful in order to set the current working directory
3654
+ * of a script relative to the root of the git repo the script appears in. By
3655
+ * doing so, the script can be invoked from any directory.
3656
+ *
3657
+ * For instance, consider this theoretical filesystem layout:
3658
+ *
3659
+ * ```
3660
+ * my-project
3661
+ * - src
3662
+ * - my-script.js
3663
+ * - README.md
3664
+ * ```
3665
+ *
3666
+ * If `my-script.js` contained the following content:
3667
+ *
3668
+ * ```ts
3669
+ * #!/usr/bin/env yavascript
3670
+ *
3671
+ * cat("README.md");
3672
+ * ```
3673
+ *
3674
+ * Then running `src/my-script.js` would print the contents of the README as
3675
+ * expected.
3676
+ *
3677
+ * However, suppose someone ran the script from a different folder:
3678
+ *
3679
+ * ```sh
3680
+ * $ cd src
3681
+ * $ ./my-script.js
3682
+ * ```
3683
+ *
3684
+ * Now an error occurs!
3685
+ *
3686
+ * To make the script resilient against this, you can use `cd` at the top of
3687
+ * the script:
3688
+ *
3689
+ * ```ts
3690
+ * #!/usr/bin/env yavascript
3691
+ *
3692
+ * // __dirname is a special variable that refers to the folder the current script is in.
3693
+ * cd(__dirname);
3694
+ * cd("..");
3695
+ *
3696
+ * cat("README.md");
3697
+ * ```
3698
+ *
3699
+ * However, if the location of `my-script.js` later changes, you will have to
3700
+ * remember to update the script. For instance, if `src/my-script.js` got
3701
+ * moved to `src/tools/my-script.js`, you would need to update the script like
3702
+ * so:
3703
+ *
3704
+ * ```ts
3705
+ * #!/usr/bin/env yavascript
3706
+ *
3707
+ * cd(__dirname);
3708
+ * cd("../.."); // Changed this line
3709
+ *
3710
+ * cat("README.md");
3711
+ * ```
3712
+ *
3713
+ * Since `README.md` will always be in the repository root, using
3714
+ * `GitRepo.findRoot` would make the `cd` resilient against file moves:
3715
+ *
3716
+ * ```ts
3717
+ * #!/usr/bin/env yavascript
3718
+ *
3719
+ * cd(GitRepo.findRoot(__dirname));
3720
+ *
3721
+ * cat("README.md");
3722
+ * ```
3723
+ *
3724
+ * Depending on how you anticipate your codebase changing over time, and how
3725
+ * you expect others to use your scripts, it might make sense to use
3726
+ * `cd(__dirname)`, `cd(GitRepo.findRoot(__dirname))`, or no `cd` at all. Pick what
3727
+ * makes the most sense for your situation.
3728
+ *
2905
3729
  */
2906
3730
  static findRoot(fromPath: string | Path): Path;
2907
3731
 
@@ -2917,9 +3741,24 @@ declare class GitRepo {
2917
3741
  repoDir: Path;
2918
3742
 
2919
3743
  /**
2920
- * Returns the commit SHA the git repo is currently pointed at.
3744
+ * Returns the full SHA-1 hash string associated with the repo's current
3745
+ * commit.
3746
+ *
3747
+ * For example:
2921
3748
  *
2922
- * This is done by running `git rev-parse HEAD`.
3749
+ * ```ts
3750
+ * const repo = new GitRepo(".");
3751
+ * const sha = repo.commitSHA();
3752
+ * console.log(sha);
3753
+ * // "2a0a15f9872406faebcac694562efeae3447a4ba"
3754
+ * ```
3755
+ *
3756
+ * To obtain this information, the command `git rev-parse HEAD` gets run
3757
+ * within the repo's directory.
3758
+ *
3759
+ * > If the repo has unstaged or uncommitted changes, that state will NOT be
3760
+ * > reflected in the SHA-1 hash. As such, it may be desirable to use this
3761
+ * > method in conjunction with `GitRepo.prototype.isWorkingTreeDirty`.
2923
3762
  */
2924
3763
  commitSHA(): string;
2925
3764
 
@@ -2927,7 +3766,20 @@ declare class GitRepo {
2927
3766
  * If the commit SHA the git repo is currently pointed at is the tip of a
2928
3767
  * named branch, returns the branch name. Otherwise, returns `null`.
2929
3768
  *
2930
- * This is done by running `git rev-parse --abbrev-ref HEAD`.
3769
+ * This is done by running `git rev-parse --abbrev-ref HEAD` within the repo
3770
+ * directory.
3771
+ *
3772
+ * Example:
3773
+ *
3774
+ * ```ts
3775
+ * const repo = new GitRepo(".");
3776
+ * const branch = repo.branchName();
3777
+ * console.log(branch);
3778
+ * // "main"
3779
+ * ```
3780
+ *
3781
+ * > The most common situation where there is no current branch is when the
3782
+ * > repository is in "detached HEAD" state.
2931
3783
  */
2932
3784
  branchName(): string | null;
2933
3785
 
@@ -2936,62 +3788,143 @@ declare class GitRepo {
2936
3788
  * git repo. `true` means there are changes, `false` means there are no
2937
3789
  * changes (ie. the repo is clean).
2938
3790
  *
2939
- * This is done by running `git status --quiet`.
3791
+ * This is done by running `git status --quiet` within the repo directory.
2940
3792
  */
2941
3793
  isWorkingTreeDirty(): boolean;
2942
3794
 
2943
3795
  /**
2944
- * Returns whether the provided path is ignored by git.
3796
+ * Returns a boolean indicating whether the provided path is ignored by one or
3797
+ * more `.gitignore` files in the repository.
3798
+ *
3799
+ * Example:
3800
+ *
3801
+ * ```ts
3802
+ * const repo = new GitRepo(".");
3803
+ * const ignoreStatus = repo.isIgnored("README.md");
3804
+ * console.log(ignoreStatus);
3805
+ * // false
3806
+ * ```
3807
+ *
3808
+ * To obtain this information, the command `git check-ignore <the-path>` gets
3809
+ * run within the repo's directory.
3810
+ *
3811
+ * An error will be thrown if the provided path is not within the repository's
3812
+ * directory tree. For instance, calling `gitRepo.isIgnored("/tmp")` on a
3813
+ * `gitRepo` pointed at `/home/suchipi/my-project` would throw an error,
3814
+ * because `/tmp` is not a child of `/home/suchipi/my-project`.
2945
3815
  *
2946
- * If `path` is an absolute path, it must be a child directory of this GitRepo
2947
- * object's `repoDir`, or else an error will be thrown.
3816
+ * > NOTE: When passing relative paths to `isIgnored`, they will be resolved
3817
+ * > relative to the repo root, NOT relative to `pwd()`. It's best practice to
3818
+ * > always pass around absolute paths in your program instead of relative
3819
+ * > ones so that this type of ambiguity is avoided.
2948
3820
  */
2949
3821
  isIgnored(path: string | Path): boolean;
2950
3822
  }
2951
3823
 
2952
3824
  /**
2953
- * Configures the default value of `trace` in yavascript API functions which
2954
- * receive `trace` as an option, like {@link which}, {@link exec}, {@link copy}
2955
- * and {@link glob}.
2956
- *
2957
- * - If called with `true`, the default value of `trace` in all functions which
2958
- * receive a `trace` option will be changed to `console.error`.
2959
- * - If called with `false`, the default value of `trace` in all functions which
2960
- * receive a `trace` option will be changed to `undefined`.
2961
- * - If called with any other value, the provided value will be used as the
2962
- * default value of `trace` in all functions which receive a `trace` option.
2963
- *
2964
- * If you would like to make your own functions use the default value of `trace`
2965
- * as set by this function (in order to get the same behavior as yavascript API
2966
- * functions which do so), call `traceAll.getDefaultTrace()` to get the current
2967
- * value which should be used as the default value.
2968
- *
2969
- * `traceAll` provides similar functionality to shell builtin `set -x`.
3825
+ * The logger used internally by yavascript API functions such as {@link which},
3826
+ * {@link exec}, {@link copy}, {@link glob}, and more.
3827
+ *
3828
+ * You can modify the properties on this object in order to configure the
3829
+ * amount and style of log output from yavascript API functions.
3830
+ *
3831
+ * This object behaves similarly to the shell builtin `set -x`.
2970
3832
  */
2971
- declare const traceAll: ((
2972
- trace: boolean | undefined | ((...args: Array<any>) => void)
2973
- ) => void) & {
2974
- getDefaultTrace(): ((...args: Array<any>) => void) | undefined;
3833
+ declare const logger: {
3834
+ /**
3835
+ * This property is used as the default value for `trace` in yavascript API
3836
+ * functions which receive `logging.trace` as an option, like {@link which},
3837
+ * {@link exec}, {@link copy} and {@link glob}.
3838
+ *
3839
+ * The default value of `logger.trace` is a no-op function.
3840
+ */
3841
+ trace: (...args: Array<any>) => void;
3842
+
3843
+ /**
3844
+ * This property is used as the default value for `info` in yavascript API
3845
+ * functions which receive `logging.info` as an option, like {@link exec},
3846
+ * {@link copy}, and {@link glob}.
3847
+ *
3848
+ * The default value of `logger.info` writes dimmed text to stdout.
3849
+ */
3850
+ info: (...args: Array<any>) => void;
2975
3851
  };
2976
3852
 
3853
+ /**
3854
+ * The properties of the `JSX` global can be modified to change how JSX syntax
3855
+ * gets compiled by yavascript. Those properties are:
3856
+ *
3857
+ * - `pragma` (string): The JavaScript expression that should be called to
3858
+ * create JSX elements. Defaults to "JSX.createElement".
3859
+ * - `pragmaFrag` (string): The JavaScript expression that should be used when
3860
+ * creating JSX fragments. Defaults to "JSX.Fragment".
3861
+ * - `createElement` (function): The function used to create JSX elements,
3862
+ * unless `JSX.pragma` has been changed.
3863
+ * - `Element` (symbol): used by the default `JSX.createElement` function to
3864
+ * identify JSX elements.
3865
+ * - `Fragment` (symbol): used by the default `JSX.createElement` function to
3866
+ * identify JSX fragments. Referenced by the default value for
3867
+ * `JSX.pragmaFrag`.
3868
+ *
3869
+ * Modifying these properties will change how JSX syntax gets compiled.
3870
+ *
3871
+ * For instance, to use React for JSX, you could either replace
3872
+ * `JSX.createElement` and `JSX.Fragment` with React's versions:
3873
+ *
3874
+ * ```ts
3875
+ * import * as React from "npm:react";
3876
+ *
3877
+ * JSX.createElement = React.createElement;
3878
+ * JSX.Fragment = React.Fragment;
3879
+ * ```
3880
+ *
3881
+ * Or, you could change `JSX.pragma` and `JSX.pragmaFrag` to reference React
3882
+ * directly:
3883
+ *
3884
+ * ```ts
3885
+ * JSX.pragma = "React.createElement";
3886
+ * JSX.pragmaFrag = "React.Fragment";
3887
+ * ```
3888
+ *
3889
+ * Note however, that changes to `pragma` and `pragmaFrag` will only affect JSX
3890
+ * appearing in files which are loaded _after_ the change, but changing
3891
+ * `createElement` and `Fragment` will affect all JSX syntax appearing after the
3892
+ * change, even within the same file.
3893
+ *
3894
+ * Whichever approach you take, you should also update `types.JSX.Element` and
3895
+ * `types.JSX.Fragment` such that the expression `types.JSX.Element(<a />) &&
3896
+ * types.JSX.Fragment(<></>)` is always `true`. To do that for React, you would
3897
+ * do:
3898
+ *
3899
+ * ```ts
3900
+ * types.JSX.Element = React.isValidElement;
3901
+ * types.JSX.Fragment = (value) => {
3902
+ * return React.isValidElement(value) && value.type === React.Fragment;
3903
+ * };
3904
+ * ```
3905
+ */
2977
3906
  declare namespace JSX {
2978
3907
  /**
3908
+ *
2979
3909
  * A string containing the expression that should be called to create JSX
2980
3910
  * elements. yavascript's internals use this string to transpile JSX syntax.
2981
3911
  *
2982
- * Defaults to "JSX.createElement".
3912
+ * The default value is "JSX.createElement".
2983
3913
  *
2984
- * If changed, any JSX code loaded afterwards will use a different
2985
- * expression.
3914
+ * If changed, any JSX code loaded afterwards will use a different expression.
2986
3915
  *
2987
3916
  * Note that if you change this, you need to verify that the following
2988
- * expression always evaluates to `true` (by changing {@link types.JSX.Element}
2989
- * and {@link types.JSX.Fragment}):
3917
+ * expression always evaluates to `true` (by changing `types.JSX.Element` and
3918
+ * `types.JSX.Fragment`):
3919
+ *
2990
3920
  * ```jsx
2991
- * types.JSX.Element(<a />) && types.JSX.Fragment(<></>)
3921
+ * types.JSX.Element(<a />) && types.JSX.Fragment(<></>);
2992
3922
  * ```
2993
3923
  *
2994
3924
  * Failure to uphold this guarantee indicates a bug.
3925
+ *
3926
+ * For more info, including info on how to change how JSX is compiled, see
3927
+ * {@link JSX}.
2995
3928
  */
2996
3929
  export let pragma: string;
2997
3930
 
@@ -3002,22 +3935,66 @@ declare namespace JSX {
3002
3935
  *
3003
3936
  * Defaults to "JSX.Fragment".
3004
3937
  *
3005
- * If changed, any JSX code loaded afterwards will use a different
3006
- * expression.
3938
+ * If changed, any JSX code loaded afterwards will use a different expression.
3007
3939
  *
3008
3940
  * Note that if you change this, you need to verify that the following
3009
- * expression always evaluates to `true` (by changing {@link types.JSX.Element}
3010
- * and {@link types.JSX.Fragment}):
3941
+ * expression always evaluates to `true` (by changing `types.JSX.Element` and
3942
+ * `types.JSX.Fragment`):
3943
+ *
3011
3944
  * ```jsx
3012
- * types.JSX.Element(<a />) && types.JSX.Fragment(<></>)
3945
+ * types.JSX.Element(<a />) && types.JSX.Fragment(<></>);
3013
3946
  * ```
3014
3947
  *
3015
3948
  * Failure to uphold this guarantee indicates a bug.
3949
+ *
3950
+ * For more info, including info on how to change how JSX is compiled, see
3951
+ * {@link JSX}.
3016
3952
  */
3017
3953
  export let pragmaFrag: string;
3018
3954
 
3955
+ /**
3956
+ * `JSX.Element` is a Symbol. The default implementation of
3957
+ * `JSX.createElement` creates objects whose `$$typeof` property is set to
3958
+ * `JSX.Element`, and type validator functions under the `types.JSX.*`
3959
+ * namespace look for this property in order to determine whether an object is
3960
+ * a JSX element, as created via `JSX.createElement` or JSX syntax.
3961
+ *
3962
+ * ```jsx
3963
+ * // This gets compiled internally by yavascript into:
3964
+ * // const a = JSX.createElement('a', null);
3965
+ * const a = <a />;
3966
+ *
3967
+ * console.log(a);
3968
+ * // {
3969
+ * // $$typeof: Symbol(JSX.Element)
3970
+ * // type: "a"
3971
+ * // props: null
3972
+ * // key: null
3973
+ * // }
3974
+ *
3975
+ * console.log(a.$$typeof === JSX.Element);
3976
+ * // true
3977
+ * ```
3978
+ *
3979
+ * There is also a TypeScript type called `JSX.Element` which is a type for
3980
+ * the JSX element objects as created by `JSX.createElement` or JSX syntax.
3981
+ *
3982
+ * If you modify properties on the JSX global such that the default
3983
+ * implementation of `JSX.createElement` is no longer used (eg. by replacing
3984
+ * it with `React.createElement`), this value may no longer be relevant.
3985
+ * However, the default JSX element object shape is designed to match
3986
+ * React/Preact/etc.
3987
+ *
3988
+ * For more info, including info on how to change how JSX is compiled, see
3989
+ * {@link JSX}.
3990
+ *
3991
+ */
3019
3992
  export const Element: unique symbol;
3020
3993
 
3994
+ /**
3995
+ * The TypeScript type for JSX Element objects created by the default
3996
+ * implementation of `JSX.createElement`.
3997
+ */
3021
3998
  export interface Element<
3022
3999
  Props = { [key: string | symbol | number]: any },
3023
4000
  Type = any
@@ -3029,26 +4006,69 @@ declare namespace JSX {
3029
4006
  }
3030
4007
 
3031
4008
  /**
3032
- * The value which gets passed into the JSX element constructor (as
3033
- * determined by {@link JSX.pragma}) when JSX fragment syntax is used (unless
3034
- * {@link JSX.pragmaFrag} is changed).
4009
+ *
4010
+ * `JSX.Fragment` is a Symbol which is used to indicate whether a JSX element
4011
+ * is a JSX fragment.
4012
+ *
4013
+ * ```jsx
4014
+ * // This gets compiled internally by yavascript into:
4015
+ * // const a = JSX.createElement(JSX.Fragment, null);
4016
+ * const frag = <></>;
4017
+ *
4018
+ * console.log(frag);
4019
+ * // {
4020
+ * // $$typeof: Symbol(JSX.Element)
4021
+ * // type: Symbol(JSX.Fragment)
4022
+ * // props: null
4023
+ * // key: null
4024
+ * // }
4025
+ *
4026
+ * console.log(a.type === JSX.Fragment);
4027
+ * // true
4028
+ * ```
4029
+ *
4030
+ * There is also a TypeScript type called `JSX.Fragment` which is a type for
4031
+ * the JSX fragment element objects as created by `JSX.createElement` or JSX
4032
+ * syntax.
4033
+ *
4034
+ * If you modify properties on the JSX global such that `JSX.Fragment` is no
4035
+ * longer used (eg. by replacing it with `React.Fragment`), this value may no
4036
+ * longer be relevant.
4037
+ *
4038
+ * For more info, including info on how to change how JSX is compiled, see
4039
+ * {@link JSX}.
3035
4040
  */
3036
4041
  export const Fragment: unique symbol;
3037
4042
 
4043
+ /**
4044
+ * The TypeScript type for JSX Element objects whose type is `JSX.Fragment`,
4045
+ * which is what yavascript creates internally when JSX fragment syntax
4046
+ * (`<></>`) is used.
4047
+ *
4048
+ * If you modify properties on the JSX global such that `JSX.Fragment` is no
4049
+ * longer used (eg. by replacing it with `React.Fragment`), this type may no
4050
+ * longer be relevant.
4051
+ */
3038
4052
  export type Fragment = Element<{}, typeof Fragment>;
3039
4053
 
3040
4054
  /**
3041
- * The JSX element builder function, which gets invoked whenever JSX syntax is
3042
- * used (unless {@link JSX.pragma} is changed).
4055
+ * The JSX element builder function, which gets invoked internally by
4056
+ * yavascript whenever JSX syntax is used (unless `JSX.pragma` gets changed by
4057
+ * the user).
3043
4058
  *
3044
4059
  * Note that if you change this, you need to verify that the following
3045
- * expression always evaluates to `true` (by changing {@link types.JSX.Element}
3046
- * and {@link types.JSX.Fragment}):
4060
+ * expression always evaluates to `true` (by changing `types.JSX.Element` and
4061
+ * `types.JSX.Fragment`):
4062
+ *
3047
4063
  * ```jsx
3048
- * types.JSX.Element(<a />) && types.JSX.Fragment(<></>)
4064
+ * types.JSX.Element(<a />) && types.JSX.Fragment(<></>);
3049
4065
  * ```
3050
4066
  *
3051
4067
  * Failure to uphold this guarantee indicates a bug.
4068
+ *
4069
+ * For more info, including info on how to change how JSX is compiled, see
4070
+ * {@link JSX}.
4071
+ *
3052
4072
  */
3053
4073
  export let createElement: {
3054
4074
  <Type extends string | typeof Fragment | ((...args: any) => any)>(
@@ -3082,9 +4102,14 @@ declare namespace JSX {
3082
4102
  };
3083
4103
  }
3084
4104
 
4105
+ /**
4106
+ * The `YAML` namespace contains functions which can serialize and deserialize
4107
+ * YAML documents, following the same pattern as JavaScript's `JSON` builtin.
4108
+ */
3085
4109
  declare const YAML: {
3086
4110
  /**
3087
- * Parse a YAML document (`input`) into a JSON-compatible value.
4111
+ * Converts a YAML document string into a JavaScript value. It works the same
4112
+ * way that `JSON.parse` does, but for YAML.
3088
4113
  */
3089
4114
  parse(
3090
4115
  input: string,
@@ -3092,7 +4117,8 @@ declare const YAML: {
3092
4117
  ): any;
3093
4118
 
3094
4119
  /**
3095
- * Convert a JSON-compatible value into a YAML document.
4120
+ * Converts a JavaScript value into a YAML document string. It works the same
4121
+ * way that `JSON.stringify` does, but for YAML.
3096
4122
  */
3097
4123
  stringify(
3098
4124
  input: any,
@@ -3104,6 +4130,18 @@ declare const YAML: {
3104
4130
  ): string;
3105
4131
  };
3106
4132
 
4133
+ /**
4134
+ * Serializes or deserializes CSV data.
4135
+ *
4136
+ * The `CSV` object contains a `parse` function and a `stringify` function which
4137
+ * can be used to parse strings of CSV (comma-separated values) data into
4138
+ * arrays-of-arrays-of-strings and serialize arrays-of-arrays-of-strings into
4139
+ * strings of CSV data.
4140
+ *
4141
+ * Its interface is similar to `JSON.parse` and `JSON.stringify`, but CSV does
4142
+ * not support the spacing/replacer/reviver options that `JSON.parse` and
4143
+ * `JSON.stringify` have.
4144
+ */
3107
4145
  declare const CSV: {
3108
4146
  /**
3109
4147
  * Parse a CSV string into an Array of Arrays of strings.
@@ -3122,11 +4160,105 @@ declare const CSV: {
3122
4160
  stringify(input: Array<Array<string>>): string;
3123
4161
  };
3124
4162
 
4163
+ /**
4164
+ * An object with a `parse` function and a `stringify` function which can be
4165
+ * used to parse TOML document strings into objects and serialize objects into
4166
+ * TOML document strings.
4167
+ *
4168
+ * Its interface is similar to `JSON.parse` and `JSON.stringify`, but
4169
+ * `TOML.parse` and `TOML.stringify` do not support the spacing/replacer/reviver
4170
+ * options that `JSON.parse` and `JSON.stringify` do.
4171
+ */
4172
+ declare var TOML: {
4173
+ /**
4174
+ * Parse a TOML document string (`data`) into an object.
4175
+ */
4176
+ parse(data: string): { [key: string]: any };
4177
+ /**
4178
+ * Convert an object into a TOML document.
4179
+ */
4180
+ stringify(data: { [key: string]: any }): string;
4181
+ };
4182
+
3125
4183
  interface RegExpConstructor {
3126
- /** See https://github.com/tc39/proposal-regex-escaping */
4184
+ /**
4185
+ * The function `RegExp.escape` accepts an input string and prefixes with `\`
4186
+ * those characters in that string which have a special meaning when appearing
4187
+ * in a regular expression.
4188
+ *
4189
+ * The implementation is based on the stage 2 ECMAScript proposal of the same
4190
+ * name: https://github.com/tc39/proposal-regex-escaping
4191
+ */
3127
4192
  escape(str: any): string;
3128
4193
  }
3129
4194
 
4195
+ interface StringConstructor {
4196
+ /**
4197
+ * The function `String.dedent` can be used to remove leading indentation from
4198
+ * a string. It is commonly used as a tagged template function, but you can
4199
+ * also call it and pass in a string.
4200
+ *
4201
+ * Note that the first line of the string must be empty.
4202
+ *
4203
+ * `String.dedent` is the default export from the npm package `string-dedent`.
4204
+ * See its readme on npm for more info:
4205
+ * https://www.npmjs.com/package/string-dedent
4206
+ */
4207
+ dedent: {
4208
+ /**
4209
+ * Removes leading minimum indentation from the string `input`.
4210
+ * The first line of `input` MUST be empty.
4211
+ *
4212
+ * For more info, see: https://www.npmjs.com/package/string-dedent#usage
4213
+ */
4214
+ (input: string): string;
4215
+
4216
+ /**
4217
+ * Removes leading minimum indentation from the tagged template literal.
4218
+ * The first line of the template literal MUST be empty.
4219
+ *
4220
+ * For more info, see: https://www.npmjs.com/package/string-dedent#usage
4221
+ */
4222
+ (
4223
+ strings: readonly string[] | ArrayLike<string>,
4224
+ ...substitutions: unknown[]
4225
+ ): string;
4226
+
4227
+ /**
4228
+ * Wrap another template tag function such that tagged literals
4229
+ * become dedented before being passed to the wrapped function.
4230
+ *
4231
+ * For more info, see: https://www.npmjs.com/package/string-dedent#usage
4232
+ */
4233
+ <
4234
+ Func extends (
4235
+ strings: readonly string[] | ArrayLike<string>,
4236
+ ...substitutions: any[]
4237
+ ) => string
4238
+ >(
4239
+ input: Func
4240
+ ): Func;
4241
+ };
4242
+ }
4243
+
4244
+ /**
4245
+ * Opens the resource at the given path or URL using the operating system's
4246
+ * default application or handler.
4247
+ *
4248
+ * Examples:
4249
+ *
4250
+ * ```ts
4251
+ * openUrl("/home/me/stuff/code.txt"); // opens code.txt in your default text editor
4252
+ * openUrl("code.txt"); // same as above, using relative path
4253
+ * openUrl("file:///home/me/stuff/code.txt"); // same as above, using file:// url
4254
+ *
4255
+ * openUrl("IMG_001.jpg"); // opens IMG_001.jpg in your default image viewer
4256
+ *
4257
+ * openUrl("https://example.com/") // opens example.com in your default web browser
4258
+ * ```
4259
+ */
4260
+ declare function openUrl(urlOrFilePath: string | Path): void;
4261
+
3130
4262
  // prettier-ignore
3131
4263
  /** Any integer in the range [0, 255]. */
3132
4264
  declare type byte =
@@ -3175,6 +4307,57 @@ declare type TypedArrayConstructor =
3175
4307
  | Float32ArrayConstructor
3176
4308
  | Float64ArrayConstructor;
3177
4309
 
4310
+ interface ErrorOptions {
4311
+ [key: string]: any;
4312
+ }
4313
+
4314
+ /**
4315
+ * For compatibility with Node.js scripts, the global object is accessible via
4316
+ * the global variable named "global".
4317
+ */
4318
+ declare var global: typeof globalThis;
4319
+
4320
+ /**
4321
+ * A `process` global is provided for rudimentary compatibility with Node.js
4322
+ * scripts. It contains a subset of the properties found on the Node.js
4323
+ * `process` global, which each forward to their corresponding yavascript API.
4324
+ *
4325
+ * For instance, `process.env` is a getter that returns {@link env}, and
4326
+ * `process.argv` is a getter that returns {@link scriptArgs}.
4327
+ *
4328
+ * If you are writing yavascript-specific code, you should use yavascript's APIs
4329
+ * instead of `process`.
4330
+ */
4331
+ declare var process: {
4332
+ version: string;
4333
+ versions: {
4334
+ node: string;
4335
+ yavascript: string;
4336
+ unicode: string;
4337
+ };
4338
+ arch: string;
4339
+ /** Same as the global {@link env}. */
4340
+ readonly env: { [key: string]: string | undefined };
4341
+ /** Same as the global {@link scriptArgs}. */
4342
+ readonly argv: Array<string>;
4343
+ /** Same as `scriptArgs[0]`. */
4344
+ readonly argv0: string;
4345
+ /**
4346
+ * Shortcut for `os.realpath(os.execPath())`, using the QuickJS {@link os}
4347
+ * module.
4348
+ */
4349
+ readonly execPath: string;
4350
+ /**
4351
+ * Uses `std.getExitCode()` and `std.setExitCode()` from the QuickJS
4352
+ * {@link std} module.
4353
+ */
4354
+ exitCode: number;
4355
+ /**
4356
+ * Uses `std.exit()` from the QuickJS {@link std} module.
4357
+ */
4358
+ exit(code?: number | null | undefined): void;
4359
+ };
4360
+
3178
4361
  // ==========================================
3179
4362
  // ------------------------------------------
3180
4363
  // QuickJS APIs, which YavaScript builds upon
@@ -4197,6 +5380,11 @@ declare interface InspectCustomInputs {
4197
5380
  colours: { [Key in keyof Required<InspectColours>]: string };
4198
5381
  }
4199
5382
 
5383
+ declare type Interval = { [Symbol.toStringTag]: "Interval" };
5384
+
5385
+ declare function setInterval(func: (...args: any) => any, ms: number): Interval;
5386
+ declare function clearInterval(interval: Interval): void;
5387
+
4200
5388
  // Definitions of the globals and modules added by quickjs-libc
4201
5389
 
4202
5390
  /**
@@ -4204,33 +5392,6 @@ declare interface InspectCustomInputs {
4204
5392
  */
4205
5393
  declare var scriptArgs: Array<string>;
4206
5394
 
4207
- /**
4208
- * Print the arguments separated by spaces and a trailing newline.
4209
- *
4210
- * Non-string args are coerced into a string via [ToString](https://tc39.es/ecma262/#sec-tostring).
4211
- * Objects can override the default `ToString` behavior by defining a `toString` method.
4212
- */
4213
- declare var print: (...args: Array<any>) => void;
4214
-
4215
- /**
4216
- * Object that provides functions for logging information.
4217
- */
4218
- interface Console {
4219
- /** Same as {@link print}(). */
4220
- log: typeof print;
4221
-
4222
- /** Same as {@link print}(). */
4223
- warn: typeof print;
4224
-
4225
- /** Same as {@link print}(). */
4226
- error: typeof print;
4227
-
4228
- /** Same as {@link print}(). */
4229
- info: typeof print;
4230
- }
4231
-
4232
- declare var console: Console;
4233
-
4234
5395
  /** An object representing a file handle. */
4235
5396
  declare interface FILE {
4236
5397
  /**
@@ -4297,6 +5458,20 @@ declare interface FILE {
4297
5458
  /** 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. */
4298
5459
  write(buffer: ArrayBuffer, position: number, length: number): number;
4299
5460
 
5461
+ /**
5462
+ * Write this file into `target`, using a memory buffer of size `bufferSize`.
5463
+ *
5464
+ * If `limit` is specified, only that amount of bytes will be read and
5465
+ * written. Otherwise, data is read and written until this file reaches EOF.
5466
+ *
5467
+ * A `limit` of 0 is treated the same as not specifying a limit.
5468
+ *
5469
+ * Internally, this function uses libc `fread` and `fwrite` in a loop.
5470
+ *
5471
+ * Returns the number of bytes read and written.
5472
+ */
5473
+ writeTo(target: FILE, bufferSize: number, limit?: number): number;
5474
+
4300
5475
  /**
4301
5476
  * Return the next line from the file, assuming UTF-8 encoding, excluding the trailing line feed or EOF.
4302
5477
  *
@@ -4456,9 +5631,6 @@ declare module "quickjs:std" {
4456
5631
  /** Constant for {@link FILE.setvbuf}. Declares that the buffer mode should be 'no buffering'. */
4457
5632
  export var _IONBF: number;
4458
5633
 
4459
- /** Manually invoke the cycle removal algorithm (garbage collector). The cycle removal algorithm is automatically started when needed, so this function is useful in case of specific memory constraints or for testing. */
4460
- export function gc(): void;
4461
-
4462
5634
  /** Return the value of the environment variable `name` or `undefined` if it is not defined. */
4463
5635
  export function getenv(name: string): string | undefined;
4464
5636
 
@@ -4503,6 +5675,27 @@ declare module "quickjs:std" {
4503
5675
  */
4504
5676
  export function getegid(): number;
4505
5677
 
5678
+ /** The type of the object returned by {@link getpwuid}. */
5679
+ export interface PasswdEntry {
5680
+ name: string;
5681
+ passwd: string;
5682
+ uid: number;
5683
+ gid: number;
5684
+ gecos: string;
5685
+ dir: string;
5686
+ shell: string;
5687
+ }
5688
+
5689
+ /**
5690
+ * Get information from the passwd file entry for the specified user id.
5691
+ *
5692
+ * See https://linux.die.net/man/3/getpwuid.
5693
+ *
5694
+ * This function throws an error on windows, because windows doesn't support
5695
+ * the same uid/gid paradigm as Unix-like operating systems.
5696
+ */
5697
+ export function getpwuid(id: number): PasswdEntry;
5698
+
4506
5699
  interface UrlGet {
4507
5700
  /**
4508
5701
  * Download `url` using the `curl` command line utility. Returns string
@@ -5109,7 +6302,7 @@ declare module "quickjs:os" {
5109
6302
  export function dup2(oldfd: number, newfd: number): number;
5110
6303
 
5111
6304
  /** `pipe` Unix system call. Return two handles as `[read_fd, write_fd]`. */
5112
- export function pipe(): null | [number, number];
6305
+ export function pipe(): [number, number];
5113
6306
 
5114
6307
  /** Sleep for `delay_ms` milliseconds. */
5115
6308
  export function sleep(delay_ms: number): void;
@@ -5225,70 +6418,11 @@ declare module "quickjs:os" {
5225
6418
  declare var setTimeout: typeof import("quickjs:os").setTimeout;
5226
6419
  declare var clearTimeout: typeof import("quickjs:os").clearTimeout;
5227
6420
 
5228
- declare type Interval = { [Symbol.toStringTag]: "Interval" };
5229
-
5230
- declare function setInterval(func: (...args: any) => any, ms: number): Interval;
5231
- declare function clearInterval(interval: Interval): void;
5232
-
5233
- interface StringConstructor {
5234
- /**
5235
- * Remove leading minimum indentation from the string.
5236
- * The first line of the string must be empty.
5237
- *
5238
- * https://github.com/tc39/proposal-string-dedent
5239
- */
5240
- dedent: {
5241
- /**
5242
- * Remove leading minimum indentation from the string.
5243
- * The first line of the string must be empty.
5244
- *
5245
- * https://github.com/tc39/proposal-string-dedent
5246
- */
5247
- (input: string): string;
5248
-
5249
- /**
5250
- * Remove leading minimum indentation from the template literal.
5251
- * The first line of the string must be empty.
5252
- *
5253
- * https://github.com/tc39/proposal-string-dedent
5254
- */
5255
- (
5256
- strings: readonly string[] | ArrayLike<string>,
5257
- ...substitutions: any[]
5258
- ): string;
5259
-
5260
- /**
5261
- * Wrap another template tag function such that tagged literals
5262
- * become dedented before being passed to the wrapped function.
5263
- *
5264
- * https://www.npmjs.com/package/string-dedent#usage
5265
- */
5266
- <
5267
- Func extends (
5268
- strings: readonly string[] | ArrayLike<string>,
5269
- ...substitutions: any[]
5270
- ) => string
5271
- >(
5272
- input: Func
5273
- ): Func;
5274
- };
5275
- }
5276
-
5277
6421
  /**
5278
- * A global which lets you configure the module loader (import/export/require).
5279
- * You can use these properties to add support for importing new filetypes.
5280
- *
5281
- * This global can also be used to identify whether an object is a module
5282
- * namespace record.
6422
+ * An object which lets you configure the module loader (import/export/require).
6423
+ * You can change these properties to add support for importing new filetypes.
5283
6424
  */
5284
- interface ModuleGlobal {
5285
- /**
5286
- * Returns true if `target` is a module namespace object.
5287
- */
5288
- [Symbol.hasInstance](target: any): target is {
5289
- [key: string | number | symbol]: any;
5290
- };
5291
-
6425
+ interface ModuleDelegate {
5292
6426
  /**
5293
6427
  * A list of filetype extensions that may be omitted from an import specifier
5294
6428
  * string.
@@ -5300,7 +6434,7 @@ interface ModuleGlobal {
5300
6434
  * See the doc comment on {@link require} for more information.
5301
6435
  *
5302
6436
  * NOTE: If you add a new extension to this array, you will likely also want
5303
- * to add to {@link Module.compilers}.
6437
+ * to add to {@link compilers}.
5304
6438
  */
5305
6439
  searchExtensions: Array<string>;
5306
6440
 
@@ -5327,7 +6461,7 @@ interface ModuleGlobal {
5327
6461
  * ```js
5328
6462
  * import * as std from "std";
5329
6463
  *
5330
- * Module.compilers[".txt"] = (filename, content) => {
6464
+ * ModuleDelegate.compilers[".txt"] = (filename, content) => {
5331
6465
  * return `export default ${JSON.stringify(content)}`;
5332
6466
  * }
5333
6467
  * ```
@@ -5341,24 +6475,29 @@ interface ModuleGlobal {
5341
6475
  * And `names` will be a string containing the contents of names.txt.
5342
6476
  *
5343
6477
  * NOTE: When adding to this object, you may also wish to add to
5344
- * {@link Module.searchExtensions}.
6478
+ * {@link searchExtensions}.
5345
6479
  */
5346
6480
  compilers: {
5347
6481
  [extensionWithDot: string]: (filename: string, content: string) => string;
5348
6482
  };
5349
6483
 
5350
6484
  /**
5351
- * Create a virtual built-in module whose exports consist of the own
5352
- * enumerable properties of `obj`.
6485
+ * An Array containing the names of all the built-in modules, such as
6486
+ * "quickjs:std", "quickjs:bytecode", etc.
6487
+ *
6488
+ * `quickjs:engine`'s `defineBuiltinModule` function adds to the end of this
6489
+ * array.
5353
6490
  */
5354
- define(name: string, obj: { [key: string]: any }): void;
6491
+ builtinModuleNames: Array<string>;
5355
6492
 
5356
6493
  /**
5357
- * Resolves a require/import request from `fromFile` into a canonicalized path.
6494
+ * Resolves a require/import request from `fromFile` into a canonicalized
6495
+ * path.
5358
6496
  *
5359
6497
  * To change native module resolution behavior, replace this function with
5360
6498
  * your own implementation. Note that you must handle
5361
- * `Module.searchExtensions` yourself in your replacement implementation.
6499
+ * `ModuleDelegate.searchExtensions` yourself in your replacement
6500
+ * implementation.
5362
6501
  */
5363
6502
  resolve(name: string, fromFile: string): string;
5364
6503
 
@@ -5366,15 +6505,12 @@ interface ModuleGlobal {
5366
6505
  * Reads the contents of the given resolved module name into a string.
5367
6506
  *
5368
6507
  * To change native module loading behavior, replace this function with your
5369
- * own implementation. Note that you must handle `Module.compilers` yourself
5370
- * in your replacement implementation.
6508
+ * own implementation. Note that you must handle `ModuleDelegate.compilers`
6509
+ * yourself in your replacement implementation.
5371
6510
  */
5372
6511
  read(modulePath: string): string;
5373
6512
  }
5374
6513
 
5375
- // global added by QJMS_AddModuleGlobal
5376
- declare var Module: ModuleGlobal;
5377
-
5378
6514
  interface RequireFunction {
5379
6515
  /**
5380
6516
  * Synchronously import a module.
@@ -5383,8 +6519,8 @@ interface RequireFunction {
5383
6519
  *
5384
6520
  * If `source` does not have a file extension, and a file without an extension
5385
6521
  * cannot be found, the engine will check for files with the extensions in
5386
- * {@link Module.searchExtensions}, and use one of those if present. This
5387
- * behavior also happens when using normal `import` statements.
6522
+ * {@link ModuleDelegate.searchExtensions}, and use one of those if present.
6523
+ * This behavior also happens when using normal `import` statements.
5388
6524
  *
5389
6525
  * For example, if you write:
5390
6526
  *
@@ -5393,20 +6529,20 @@ interface RequireFunction {
5393
6529
  * ```
5394
6530
  *
5395
6531
  * but there's no file named `somewhere` in the same directory as the file
5396
- * where that import appears, and `Module.searchExtensions` is the default
5397
- * value:
6532
+ * where that import appears, and `ModuleDelegate.searchExtensions` is the
6533
+ * default value:
5398
6534
  *
5399
6535
  * ```js
5400
6536
  * [".js"]
5401
6537
  * ```
5402
6538
  *
5403
6539
  * then the engine will look for `somewhere.js`. If that doesn't exist, the
5404
- * engine will look for `somewhere/index.js`. If *that* doesn't exist, an error
5405
- * will be thrown.
6540
+ * engine will look for `somewhere/index.js`. If *that* doesn't exist, an
6541
+ * error will be thrown.
5406
6542
  *
5407
- * If you add more extensions to `Module.searchExtensions`, then the engine
5408
- * will use those, too. It will search in the same order as the strings appear
5409
- * in the `Module.searchExtensions` array.
6543
+ * If you add more extensions to `ModuleDelegate.searchExtensions`, then the
6544
+ * engine will use those, too. It will search in the same order as the strings
6545
+ * appear in the `ModuleDelegate.searchExtensions` array.
5410
6546
  */
5411
6547
  (source: string): any;
5412
6548
 
@@ -5416,7 +6552,7 @@ interface RequireFunction {
5416
6552
  resolve: (source: string) => string;
5417
6553
  }
5418
6554
 
5419
- // global added by QJMS_AddRequireGlobal
6555
+ // global added by QJMS_InitContext
5420
6556
  declare var require: RequireFunction;
5421
6557
 
5422
6558
  // gets set per-module by QJMS_SetModuleImportMeta
@@ -5446,16 +6582,17 @@ interface ImportMeta {
5446
6582
  *
5447
6583
  * Equivalent to `globalThis.require.resolve`.
5448
6584
  *
5449
- * Behaves similarly to [the browser import.meta.resolve](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve),
6585
+ * Behaves similarly to [the browser
6586
+ * import.meta.resolve](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve),
5450
6587
  * but it does not ensure that the returned string is a valid URL, because it
5451
- * delegates directly to {@link Module.resolve} to resolve the name. If you
5452
- * want this to return URL strings, change `Module.resolve` and `Module.read`
5453
- * to work with URL strings.
6588
+ * delegates directly to {@link ModuleDelegate.resolve} to resolve the name.
6589
+ * If you want this to return URL strings, change `ModuleDelegate.resolve` and
6590
+ * `ModuleDelegate.read` to work with URL strings.
5454
6591
  */
5455
6592
  resolve: RequireFunction["resolve"];
5456
6593
  }
5457
6594
 
5458
- declare module "quickjs:module" {
6595
+ declare module "quickjs:engine" {
5459
6596
  /**
5460
6597
  * Return whether the provided resolved module path is set as the main module.
5461
6598
  *
@@ -5526,6 +6663,34 @@ declare module "quickjs:module" {
5526
6663
  * @param stackLevels - How many levels up the stack to search for a filename. Defaults to 0, which uses the current stack frame.
5527
6664
  */
5528
6665
  export function getFileNameFromStack(stackLevels?: number): string;
6666
+
6667
+ /**
6668
+ * Returns true if `target` is a module namespace object.
6669
+ */
6670
+ export function isModuleNamespace(target: any): boolean;
6671
+
6672
+ /**
6673
+ * Create a virtual built-in module whose exports consist of the own
6674
+ * enumerable properties of `obj`.
6675
+ */
6676
+ export function defineBuiltinModule(
6677
+ name: string,
6678
+ obj: { [key: string]: any }
6679
+ ): void;
6680
+
6681
+ /**
6682
+ * An object which lets you configure the module loader (import/export/require).
6683
+ * You can change these properties to add support for importing new filetypes.
6684
+ */
6685
+ export const ModuleDelegate: ModuleDelegate;
6686
+
6687
+ /**
6688
+ * Manually invoke the cycle removal algorithm (garbage collector).
6689
+ *
6690
+ * The cycle removal algorithm is automatically started when needed, so this
6691
+ * function is useful in case of specific memory constraints or for testing.
6692
+ */
6693
+ export function gc(): void;
5529
6694
  }
5530
6695
 
5531
6696
  declare module "quickjs:bytecode" {
@@ -5536,7 +6701,11 @@ declare module "quickjs:bytecode" {
5536
6701
  */
5537
6702
  export function fromFile(
5538
6703
  path: string,
5539
- options?: { byteSwap?: boolean; sourceType?: "module" | "script" }
6704
+ options?: {
6705
+ byteSwap?: boolean;
6706
+ sourceType?: "module" | "script";
6707
+ encodedFileName?: string;
6708
+ }
5540
6709
  ): ArrayBuffer;
5541
6710
 
5542
6711
  /**
@@ -5614,9 +6783,6 @@ declare module "quickjs:context" {
5614
6783
  /** Enables `String.prototype.normalize`. Defaults to `true`. */
5615
6784
  stringNormalize?: boolean;
5616
6785
 
5617
- /** Enables `String.dedent`. Defaults to `true`. */
5618
- stringDedent?: boolean;
5619
-
5620
6786
  /** Enables `RegExp`. Defaults to `true`. */
5621
6787
  regExp?: boolean;
5622
6788
 
@@ -5692,7 +6858,7 @@ declare module "quickjs:context" {
5692
6858
  console?: boolean;
5693
6859
  /** Enables `print`. Defaults to `true`. */
5694
6860
  print?: boolean;
5695
- /** Enables `require` and `Module`. Defaults to `true`. */
6861
+ /** Enables `require`. Defaults to `true`. */
5696
6862
  moduleGlobals?: boolean;
5697
6863
  /**
5698
6864
  * Enables `setTimeout`, `clearTimeout`, `setInterval`, and
@@ -5710,8 +6876,10 @@ declare module "quickjs:context" {
5710
6876
  "quickjs:bytecode"?: boolean;
5711
6877
  /** Enables the "quickjs:context" module. Defaults to `true`. */
5712
6878
  "quickjs:context"?: boolean;
5713
- /** Enables the "quickjs:module" module. Defaults to `true`. */
5714
- "quickjs:module"?: boolean;
6879
+ /** Enables the "quickjs:engine" module. Defaults to `true`. */
6880
+ "quickjs:engine"?: boolean;
6881
+ /** Enables the "quickjs:encoding" module. Defaults to `true`. */
6882
+ "quickjs:encoding"?: boolean;
5715
6883
  };
5716
6884
  });
5717
6885
 
@@ -5731,5 +6899,16 @@ declare module "quickjs:context" {
5731
6899
  }
5732
6900
  }
5733
6901
 
6902
+ // WHATWG encoding spec at https://encoding.spec.whatwg.org/ would be better,
6903
+ // but this is better than nothing
6904
+ declare module "quickjs:encoding" {
6905
+ export function toUtf8(input: ArrayBuffer): string;
6906
+ export function fromUtf8(input: string): ArrayBuffer;
6907
+ }
6908
+
5734
6909
  declare const std: typeof import("quickjs:std");
5735
6910
  declare const os: typeof import("quickjs:os");
6911
+
6912
+ // undocumented from quickjs, but it's there
6913
+ /** Get the current unix timestamp with microsecond precision. */
6914
+ declare function __date_clock(): number;