yavascript 0.0.12 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/yavascript.d.ts CHANGED
@@ -4,47 +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;
13
+ declare function help(): void;
14
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
- * To set help text for the values `null` or `undefined`, `allowNullish`
29
- * must be `true`.
30
- */
31
- (value: object, text: string, allowNullish?: boolean): void;
32
-
33
- /**
34
- * Lazily sets the help text for the provided value using the provided
35
- * string-returning function.
36
- *
37
- * The first time help text is requested for the value, the string-returning
38
- * function will be called, and its result will be registered as the help
39
- * text for the value. Afterwards, the function will not be called again;
40
- * instead, it will re-use the text returned from the first time the
41
- * function was called.
42
- */
43
- lazy(value: object, getText: () => string): void;
44
- };
45
- };
46
-
47
- /** 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
+ */
48
20
  declare const yavascript: {
49
21
  /**
50
22
  * The version of the currently-running yavascript binary.
@@ -65,48 +37,107 @@ declare const yavascript: {
65
37
  */
66
38
  version: string;
67
39
 
68
- /** The processor architecture we're running on. */
40
+ /**
41
+ * The processor architecture of the currently-running `yavascript` binary.
42
+ */
69
43
  arch: "x86_64" | "arm64";
70
44
 
71
45
  /**
72
- * 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.
73
48
  *
74
- * 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.
75
53
  */
76
54
  ecmaVersion: string;
77
55
 
78
- /** 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
+ */
79
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
+ */
80
68
  js(
81
69
  code: string,
82
70
  options?: { filename?: string; expression?: boolean }
83
71
  ): string;
84
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
+ */
85
78
  tsx(
86
79
  code: string,
87
80
  options?: { filename?: string; expression?: boolean }
88
81
  ): string;
89
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
+ */
90
88
  ts(
91
89
  code: string,
92
90
  options?: { filename?: string; expression?: boolean }
93
91
  ): string;
94
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
+ */
95
101
  jsx(
96
102
  code: string,
97
103
  options?: { filename?: string; expression?: boolean }
98
104
  ): string;
99
105
 
106
+ /**
107
+ * The function yavascript uses internally to load [CoffeeScript](https://coffeescript.org/) files.
108
+ *
109
+ * yavascript embeds CoffeeScript 2.7.0.
110
+ */
100
111
  coffee(
101
112
  code: string,
102
113
  options?: { filename?: string; expression?: boolean }
103
114
  ): string;
104
115
 
116
+ /**
117
+ * The function yavascript uses internally to load [Civet](https://civet.dev/) files.
118
+ *
119
+ * yavascript embeds Civet 0.9.0.
120
+ */
105
121
  civet(
106
122
  code: string,
107
123
  options?: { filename?: string; expression?: boolean }
108
124
  ): string;
109
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
+ */
110
141
  autodetect(
111
142
  code: string,
112
143
  options?: { filename?: string; expression?: boolean }
@@ -123,9 +154,9 @@ declare const yavascript: {
123
154
  declare const env: { [key: string]: string | undefined };
124
155
 
125
156
  /**
126
- * Parse command line --flags into an object of flags and an array of
127
- * positional arguments. This function is opinionated; if it doesn't meet your
128
- * 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.
129
160
  *
130
161
  * Flags `--like-this`, `--like_this`, or `--LIKE_THIS` get converted into
131
162
  * property names `likeThis` on the returned flags object.
@@ -136,34 +167,145 @@ declare const env: { [key: string]: string | undefined };
136
167
  * Anything that appears after `--` is considered a positional argument instead
137
168
  * of a flag. `--` is not present in the returned positional arguments Array.
138
169
  *
139
- * @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.
140
- * @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
173
+ *
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.
141
179
  *
142
- * @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.
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.
143
216
  */
144
217
  declare function parseScriptArgs(
145
218
  hints?: {
146
219
  [key: string]: typeof String | typeof Boolean | typeof Number | typeof Path;
147
220
  },
148
221
  args?: Array<string>
149
- ): {
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
+ */
150
242
  flags: { [key: string]: any };
243
+ /**
244
+ * An array of those command-line arguments which weren't associated with a flag.
245
+ */
151
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
+ */
152
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
+ */
153
258
  keys: {
154
259
  [key: string]: string | undefined;
155
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
+ */
156
266
  hints: {
157
- [key: string]: string | undefined;
267
+ [key: string]: "path" | "number" | "boolean" | "string" | undefined;
158
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
+ */
159
279
  guesses: {
160
- [key: string]: string | undefined;
280
+ [key: string]: "number" | "boolean" | "string" | undefined;
161
281
  };
162
282
  };
163
- };
283
+ }
164
284
 
165
285
  /**
166
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
+ * ```
167
309
  */
168
310
  declare const readFile: {
169
311
  /**
@@ -252,6 +394,18 @@ declare function remove(path: string | Path): void;
252
394
  */
253
395
  declare function exists(path: string | Path): boolean;
254
396
 
397
+ /**
398
+ * Copies a file or folder from one location to another.
399
+ * Folders are copied recursively.
400
+ *
401
+ * Provides the same functionality as the command `cp -R`.
402
+ */
403
+ declare function copy(
404
+ from: string | Path,
405
+ to: string | Path,
406
+ options?: CopyOptions
407
+ ): void;
408
+
255
409
  /**
256
410
  * Options for {@link copy}.
257
411
  */
@@ -294,18 +448,6 @@ declare type CopyOptions = {
294
448
  };
295
449
  };
296
450
 
297
- /**
298
- * Copies a file or folder from one location to another.
299
- * Folders are copied recursively.
300
- *
301
- * Provides the same functionality as the command `cp -R`.
302
- */
303
- declare function copy(
304
- from: string | Path,
305
- to: string | Path,
306
- options?: CopyOptions
307
- ): void;
308
-
309
451
  /**
310
452
  * Rename the file or directory at the specified path.
311
453
  *
@@ -313,32 +455,93 @@ declare function copy(
313
455
  */
314
456
  declare function rename(from: string | Path, to: string | Path): void;
315
457
 
316
- /** 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
+ */
317
480
  declare class Path {
318
- /** 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
+ */
319
489
  static readonly OS_SEGMENT_SEPARATOR: "/" | "\\";
320
490
 
321
491
  /**
322
- * The character used to separate entries within the PATH environment
323
- * 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
+ * ```
324
508
  */
325
509
  static readonly OS_ENV_VAR_SEPARATOR: ":" | ";";
326
510
 
327
511
  /**
328
- * A list of suffixes that could appear in the filename for a program on the
329
- * 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 (`.`).
330
516
  *
331
- * 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.
332
523
  */
333
524
  static readonly OS_PROGRAM_EXTENSIONS: ReadonlySet<string>;
334
525
 
335
- /** 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
+ */
336
538
  static splitToSegments(inputParts: Array<string> | string): Array<string>;
337
539
 
338
540
  /**
339
- * Search the provided path string or strings for a path separator character,
340
- * and return it. If none is found, return `fallback`, which defaults to the
341
- * 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`).
342
545
  */
343
546
  static detectSeparator<Fallback extends string | null = string>(
344
547
  input: Array<string> | string,
@@ -347,19 +550,45 @@ declare class Path {
347
550
  ): string | Fallback;
348
551
 
349
552
  /**
350
- * Concatenates the input path(s) and then resolves all non-leading `.` and
351
- * `..` 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.
352
562
  */
353
563
  static normalize(
354
564
  ...inputs: Array<string | Path | Array<string | Path>>
355
565
  ): Path;
356
566
 
357
567
  /**
358
- * Return whether the provided path is absolute; that is, whether it
359
- * 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.
360
574
  */
361
575
  static isAbsolute(path: string | Path): boolean;
362
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
+
363
592
  /**
364
593
  * An array of the path segments that make up this path.
365
594
  *
@@ -372,96 +601,95 @@ declare class Path {
372
601
  /**
373
602
  * The path separator that should be used to turn this path into a string.
374
603
  *
375
- * Will be either `/` or `\`.
604
+ * Will be either `"/"` or `"\"`.
376
605
  */
377
606
  separator: string;
378
607
 
379
- /** Create a new Path object using the provided input(s). */
380
- constructor(...inputs: Array<string | Path | Array<string | Path>>);
381
-
382
608
  /**
383
- * Create a new Path object using the provided segments and separator.
609
+ * Creates a new Path by resolving all non-leading `.` and `..` segments in
610
+ * the target Path. In other words:
384
611
  *
385
- * If unspecified, `separator` defaults to `Path.OS_SEGMENT_SEPARATOR`.
386
- */
387
- static fromRaw(segments: Array<string>, separator?: string): Path;
388
-
389
- /**
390
- * Resolve all non-leading `.` and `..` segments in this path.
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.
391
618
  */
392
619
  normalize(): Path;
393
620
 
394
621
  /**
395
- * Create a new Path by appending additional path segments onto the end of
396
- * this Path's segments.
622
+ * Creates a new Path by appending additional path segments onto the end of
623
+ * the target Path's segments.
397
624
  *
398
- * The returned path will use this path's separator.
625
+ * The returned Path will use the same separator as the target Path.
399
626
  */
400
627
  concat(...other: Array<string | Path | Array<string | Path>>): Path;
401
628
 
402
629
  /**
403
- * Return whether this path is absolute; that is, whether it starts with
404
- * 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.
405
636
  */
406
637
  isAbsolute(): boolean;
407
638
 
408
639
  /**
409
- * Make a second Path object containing the same segments and separator as
410
- * 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.
411
645
  */
412
646
  clone(): this;
413
647
 
414
648
  /**
415
- * Express this path relative to `dir`.
649
+ * Creates a new Path which expresses the target Path relative to `dir`.
416
650
  *
417
651
  * @param dir - The directory to create a new path relative to.
418
- * @param options - Options that affect the resulting path.
652
+ * @param options - Options that affect the resulting path (see {@link PathRelativeToOptions}).
419
653
  */
420
- relativeTo(
421
- dir: Path | string,
422
- options?: {
423
- /**
424
- * Defaults to false. When true, a leading `./` will be omitted from the
425
- * path, if present. Note that a leading `../` will never be omitted.
426
- */
427
- noLeadingDot?: boolean;
428
- }
429
- ): Path;
654
+ relativeTo(dir: Path | string, options?: PathRelativeToOptions): Path;
430
655
 
431
656
  /**
432
- * 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.
433
659
  */
434
660
  toString(): string;
435
661
 
436
662
  /**
437
- * Alias for `toString`; causes Path objects to be serialized as strings when
438
- * 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.
439
666
  */
440
667
  toJSON(): string;
441
668
 
442
669
  /**
443
- * Return the final path segment of this path. If this path has no path
444
- * 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.
445
672
  */
446
673
  basename(): string;
447
674
 
448
675
  /**
449
- * Return the trailing extension of this path. The `options` parameter works
450
- * 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}).
451
679
  */
452
- extname(options?: { full?: boolean }): string;
680
+ extname(options?: ExtnameOptions): string;
453
681
 
454
682
  /**
455
- * Return a new Path containing all of the path segments in this one except
456
- * for the last one; ie. the path to the directory that contains this path.
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.
457
685
  */
458
686
  dirname(): Path;
459
687
 
460
688
  /**
461
- * Return whether this path starts with the provided value, by comparing one
462
- * 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.
463
691
  *
464
- * 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
465
693
  * provided value.
466
694
  *
467
695
  * This means that, given two Paths A and B:
@@ -476,10 +704,10 @@ declare class Path {
476
704
  startsWith(value: string | Path | Array<string | Path>): boolean;
477
705
 
478
706
  /**
479
- * Return whether this path ends with the provided value, by comparing one
480
- * 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.
481
709
  *
482
- * 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
483
711
  * provided value.
484
712
  *
485
713
  * This means that, given two Paths A and B:
@@ -494,11 +722,11 @@ declare class Path {
494
722
  endsWith(value: string | Path | Array<string | Path>): boolean;
495
723
 
496
724
  /**
497
- * Return the path segment index at which `value` appears in this path, or
498
- * `-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.
499
727
  *
500
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.
501
- * @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`.
502
730
  */
503
731
  indexOf(
504
732
  value: string | Path | Array<string | Path>,
@@ -506,10 +734,10 @@ declare class Path {
506
734
  ): number;
507
735
 
508
736
  /**
509
- * Return whether `value` appears in this path.
737
+ * Returns a boolean indicating whether `value` appears in the target Path.
510
738
  *
511
739
  * @param value - The value to search for.
512
- * @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`.
513
741
  */
514
742
  includes(
515
743
  value: string | Path | Array<string | Path>,
@@ -517,14 +745,18 @@ declare class Path {
517
745
  ): boolean;
518
746
 
519
747
  /**
520
- * Return a new Path wherein the segments in `value` have been replaced with
521
- * the segments in `replacement`. If the segments in `value` are not present
522
- * 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.
523
752
  *
524
- * 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}.
525
755
  *
526
756
  * @param value - What should be replaced
527
757
  * @param replacement - What it should be replaced with
758
+ *
759
+ * See also {@link Path.prototype.replaceLast}.
528
760
  */
529
761
  replace(
530
762
  value: string | Path | Array<string | Path>,
@@ -532,12 +764,18 @@ declare class Path {
532
764
  ): Path;
533
765
 
534
766
  /**
535
- * Return a new Path wherein all occurrences of the segments in `value` have
536
- * been replaced with the segments in `replacement`. If the segments in
537
- * `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}.
538
774
  *
539
775
  * @param value - What should be replaced
540
776
  * @param replacement - What it should be replaced with
777
+ *
778
+ * See also {@link Path.prototype.replaceLast}.
541
779
  */
542
780
  replaceAll(
543
781
  value: string | Path | Array<string | Path>,
@@ -545,24 +783,59 @@ declare class Path {
545
783
  ): Path;
546
784
 
547
785
  /**
548
- * 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.
549
791
  *
550
792
  * @param replacement - The new final segment(s) for the returned Path
551
793
  */
552
794
  replaceLast(replacement: string | Path | Array<string | Path>): Path;
795
+
796
+ /**
797
+ * Return a boolean indicating whether this Path has the same separator and
798
+ * segments as another Path.
799
+ *
800
+ * To check only segments and not separator, use {@link Path.prototype.hasEqualSegments}.
801
+ */
802
+ equals(other: string | Path | Array<string | Path>): boolean;
803
+
804
+ /**
805
+ * Return a boolean indicating whether this Path has the same segments as
806
+ * another Path. **Separator is not checked; use {@link Path.prototype.equals} for that.**
807
+ */
808
+ hasEqualSegments(other: string | Path | Array<string | Path>): boolean;
809
+ }
810
+
811
+ /**
812
+ * Options for {@link Path.prototype.relativeTo}.
813
+ */
814
+ declare interface PathRelativeToOptions {
815
+ /**
816
+ * Defaults to false. When true, a leading `./` will be omitted from the
817
+ * path, if present. Note that a leading `../` will never be omitted.
818
+ */
819
+ noLeadingDot?: boolean;
553
820
  }
554
821
 
555
822
  /**
556
- * The absolute path to the current file (whether script or module).
823
+ * The absolute path to the currently-executing file (whether script or module).
824
+ *
825
+ * Behaves the same as in Node.js, except that it's also present within ES
826
+ * modules.
557
827
  *
558
- * Behaves the same as in Node.js, except that it's also present within ES modules.
828
+ * Example: `/home/suchipi/some-folder/some-file.js`
559
829
  */
560
830
  declare var __filename: string;
561
831
 
562
832
  /**
563
- * The absolute path to the directory the current file is inside of.
833
+ * The absolute path to the directory containing the currently-executing file.
564
834
  *
565
- * Behaves the same as in Node.js, except that it's also present within ES modules.
835
+ * Behaves the same as in Node.js, except that it's also present within ES
836
+ * modules.
837
+ *
838
+ * Example: `/home/suchipi/some-folder`
566
839
  */
567
840
  declare var __dirname: string;
568
841
 
@@ -570,12 +843,20 @@ declare var __dirname: string;
570
843
  * Return the last component of a path string.
571
844
  *
572
845
  * Provides the same functionality as the unix binary of the same name.
846
+ *
847
+ * > Example: `basename("/home/suchipi/something")` returns `"something"`, the last part.
573
848
  */
574
849
  declare function basename(path: string | Path): string;
575
850
 
576
851
  /**
577
852
  * Reads the contents of one or more files from disk as either one UTF-8 string
578
853
  * or one ArrayBuffer.
854
+ *
855
+ * Provides the same functionality as the unix binary of the same name.
856
+ *
857
+ * > Example: If you have a file called `hi.txt` in the current working
858
+ * > directory, and it contains the text "hello", running `cat("hi.txt")`
859
+ * > returns `"hello"`.
579
860
  */
580
861
  declare const cat: {
581
862
  /**
@@ -606,66 +887,144 @@ declare const cat: {
606
887
  };
607
888
 
608
889
  /**
609
- * Change the process's current working directory to the specified path. If no
890
+ * Changes the process's current working directory to the specified path. If no
610
891
  * path is specified, moves to the user's home directory.
611
892
  *
612
893
  * Provides the same functionality as the shell builtin of the same name.
613
894
  */
614
895
  declare function cd(path?: string | Path): void;
615
896
 
616
- /** A string representing who a permission applies to. */
617
- declare type ChmodPermissionsWho =
618
- | "user"
619
- | "group"
620
- | "others"
621
- | "all"
622
- | "u"
623
- | "g"
624
- | "o"
625
- | "a"
626
- | "ug"
627
- | "go"
628
- | "uo";
629
-
630
- /** A string representing the access level for the given permission. */
631
- declare type ChmodPermissionsWhat =
632
- | "read"
633
- | "write"
634
- | "execute"
635
- | "readwrite"
636
- | "none"
637
- | "full"
638
- | "r"
639
- | "w"
640
- | "x"
641
- | "rw"
642
- | "rx"
643
- | "wx"
644
- | "rwx";
645
-
646
897
  /**
647
898
  * Set the permission bits for the specified file.
648
899
  *
649
- * @param permissions The permission bits to set. This can be a number, a string containing an octal number, or an object.
650
- * @param path The path to the file.
900
+ * Provides the same functionality as the unix binary of the same name.
651
901
  */
652
- declare function chmod(
653
- permissions:
654
- | number
655
- | string
656
- | Record<ChmodPermissionsWho, ChmodPermissionsWhat>,
657
- path: string | Path
658
- ): void;
902
+ declare const chmod: Chmod;
903
+
904
+ /**
905
+ * The interface for the global function `chmod`, which has two call signatures.
906
+ */
907
+ interface Chmod {
908
+ /**
909
+ * Set the permission bits for the specified file.
910
+ *
911
+ * Provides the same functionality as the unix binary of the same name.
912
+ *
913
+ * @param permissions The permission bits to set. This can be a number, or a string containing an octal number.
914
+ * @param path The path to the file.
915
+ */
916
+ (permissions: number | string, path: string | Path): void;
917
+
918
+ /**
919
+ * Apply a change to the permission bits for the specified file.
920
+ *
921
+ * Provides the same functionality as the unix binary of the same name.
922
+ *
923
+ * @param operation What to do to the bits; can be "add", "set", or "remove".
924
+ * @param permissions An object describing the changes (see below).
925
+ * @param path The path to the file.
926
+ *
927
+ * Each of the `permissions` object's own property keys must be one of these
928
+ * strings:
929
+ *
930
+ * - `"user"`
931
+ * - `"group"`
932
+ * - `"others"`
933
+ * - `"all"` (meaning "user", "group", and "others")
934
+ * - `"u"` (alias for "user")
935
+ * - `"g"` (alias for "group")
936
+ * - `"o"` (alias for "others")
937
+ * - `"a"` (alias for "all")
938
+ * - `"ug"` ("user" plus "group")
939
+ * - `"go"` ("group" plus "others")
940
+ * - `"uo"` ("user" plus "others")
941
+ *
942
+ * and their values must be one of these strings:
943
+ *
944
+ * - `"read"` (permission to read the contents of the file)
945
+ * - `"write"` (permission to write to the file's contents)
946
+ * - `"execute"` (permission to run the file as an executable)
947
+ * - `"readwrite"` (both "read" and "write")
948
+ * - `"none"` (no permissions)
949
+ * - `"full"` ("read", "write", and "execute")
950
+ * - `"r"` (alias for "read")
951
+ * - `"w"` (alias for "write")
952
+ * - `"x"` (alias for "execute")
953
+ * - `"rw"` (alias for "readwrite")
954
+ * - `"rx"` ("read" and "execute")
955
+ * - `"wx"` ("write" and "execute")
956
+ * - `"rwx"` (alias for "full")
957
+ *
958
+ * Some example objects:
959
+ *
960
+ * ```json
961
+ * { user: "readwrite", group: "read", others: "none" }
962
+ * { ug: "rw", o: "w" }
963
+ * { all: "full" }
964
+ * ```
965
+ */
966
+ <Operation extends Chmod.Operation>(
967
+ operation: Operation,
968
+ permissions: Operation extends "set"
969
+ ? Record<Chmod.Who, Chmod.Permission>
970
+ : Partial<Record<Chmod.Who, Chmod.Permission>>,
971
+ path: string | Path
972
+ ): void;
973
+ }
974
+
975
+ declare namespace Chmod {
976
+ /** A string representing who a permission applies to. */
977
+ export type Who =
978
+ | "user"
979
+ | "group"
980
+ | "others"
981
+ | "all"
982
+ | "u"
983
+ | "g"
984
+ | "o"
985
+ | "a"
986
+ | "ug"
987
+ | "go"
988
+ | "uo";
989
+
990
+ /** A string representing how the permissions should be changed. */
991
+ export type Operation = "add" | "set" | "remove";
992
+
993
+ /** A string representing the access level for the given permission. */
994
+ export type Permission =
995
+ | "read"
996
+ | "write"
997
+ | "execute"
998
+ | "readwrite"
999
+ | "none"
1000
+ | "full"
1001
+ | "r"
1002
+ | "w"
1003
+ | "x"
1004
+ | "rw"
1005
+ | "rx"
1006
+ | "wx"
1007
+ | "rwx";
1008
+ }
659
1009
 
660
1010
  /**
661
1011
  * Removes the final component from a path string.
662
1012
  *
663
1013
  * Provides the same functionality as the unix binary of the same name.
1014
+ *
1015
+ * > Example: `dirname("/home/suchipi/something")` returns
1016
+ * > `"/home/suchipi"`, everything except the last part.
664
1017
  */
665
1018
  declare function dirname(path: string | Path): Path;
666
1019
 
667
1020
  /**
668
1021
  * Print one or more values to stdout.
1022
+ *
1023
+ * Provides the same functionality as the shell builtin of the same name.
1024
+ *
1025
+ * > NOTE: This can print any value, not just strings.
1026
+ *
1027
+ * `echo` is functionally identical to `console.log`.
669
1028
  */
670
1029
  declare const echo: typeof console.log;
671
1030
 
@@ -679,6 +1038,9 @@ declare const echo: typeof console.log;
679
1038
  *
680
1039
  * `exit.code` will also be used as the exit status code for the yavascript
681
1040
  * process if the process exits normally.
1041
+ *
1042
+ * > Attempting to call `exit` or set `exit.code` within a Worker will fail and
1043
+ * > throw an error.
682
1044
  */
683
1045
  declare const exit: {
684
1046
  (code?: number): never;
@@ -688,18 +1050,34 @@ declare const exit: {
688
1050
  /**
689
1051
  * Returns the file extension of the file at a given path.
690
1052
  *
691
- * If the file has no extension (eg `Makefile`, etc), then `''` will be returned.
1053
+ * If the file has no extension (eg `Makefile`, etc), then `''` will be
1054
+ * returned.
692
1055
  *
693
- * Pass `{ full: true }` to get compound extensions, eg `.d.ts` or `.test.js` instead of just `.ts`/`.js`.
1056
+ * @param pathOrFilename The input path
1057
+ * @param options Options which affect the return value. See {@link ExtnameOptions}.
694
1058
  */
695
1059
  declare function extname(
696
1060
  pathOrFilename: string | Path,
697
- options?: { full?: boolean }
1061
+ options?: ExtnameOptions
698
1062
  ): string;
699
1063
 
1064
+ /**
1065
+ * Options for {@link extname} and {@link Path.prototype.extname}.
1066
+ */
1067
+ declare interface ExtnameOptions {
1068
+ /**
1069
+ * Whether to get compound extensions, like `.d.ts` or `.test.js`, instead of
1070
+ * just the final extension (`.ts` or `.js` in this example).
1071
+ */
1072
+ full?: boolean;
1073
+ }
1074
+
700
1075
  /**
701
1076
  * Returns the contents of a directory, as absolute paths. `.` and `..` are
702
1077
  * omitted.
1078
+ *
1079
+ * If `ls()` is called with no directory, the present working directory
1080
+ * (`pwd()`) is used.
703
1081
  */
704
1082
  declare function ls(dir?: string | Path): Array<Path>;
705
1083
 
@@ -741,9 +1119,10 @@ declare function mkdirp(
741
1119
  /**
742
1120
  * Print data to stdout using C-style format specifiers.
743
1121
  *
744
- * The same formats as the standard C library printf are supported. Integer
745
- * format types (e.g. `%d`) truncate the Numbers or BigInts to 32 bits. Use the l
746
- * modifier (e.g. `%ld`) to truncate to 64 bits.
1122
+ * The same formats as the [standard C library
1123
+ * printf](https://en.cppreference.com/w/c/io/fprintf) are supported. Integer
1124
+ * format types (e.g. `%d`) truncate the Numbers or BigInts to 32 bits. Use the
1125
+ * l modifier (e.g. `%ld`) to truncate to 64 bits.
747
1126
  */
748
1127
  declare function printf(format: string, ...args: Array<any>): void;
749
1128
 
@@ -782,31 +1161,48 @@ declare function readlink(path: string | Path): Path;
782
1161
  * The path's target file/directory must exist.
783
1162
  *
784
1163
  * Provides the same functionality as the unix binary of the same name.
1164
+ *
1165
+ * > If you want to convert a relative path to an absolute path, but the path's
1166
+ * > target might NOT exist, use {@link Path.normalize}.
785
1167
  */
786
1168
  declare function realpath(path: string | Path): Path;
787
1169
 
788
1170
  /**
789
- * Blocks the current thread for at least the specified number of milliseconds,
790
- * or maybe a tiny bit longer.
1171
+ * `sleep` and `sleep.sync` block the current thread for at least the specified
1172
+ * number of milliseconds, but maybe a tiny bit longer.
791
1173
  *
792
- * alias for `sleep.sync`.
1174
+ * `sleep.async` returns a Promise which resolves in at least the specified
1175
+ * number of milliseconds, but maybe a tiny bit longer.
1176
+ *
1177
+ * `sleep` and `sleep.sync` block the current thread. `sleep.async` doesn't
1178
+ * block the current thread.
1179
+ *
1180
+ * "Blocking the thread" means no other JavaScript code can run while `sleep` or
1181
+ * `sleep.sync` is running. If this is not the behavior you want, use
1182
+ * `sleep.async` instead.
793
1183
  */
794
1184
  declare var sleep: {
795
1185
  /**
796
- * Blocks the current thread for at least the specified number of milliseconds,
797
- * or maybe a tiny bit longer.
1186
+ * Blocks the current thread for at least the specified number of
1187
+ * milliseconds, but maybe a tiny bit longer.
798
1188
  *
799
1189
  * alias for `sleep.sync`.
800
1190
  *
801
1191
  * @param milliseconds - The number of milliseconds to block for.
1192
+ *
1193
+ * No other JavaScript code can run while `sleep()` is running. If this is
1194
+ * not the behavior you want, use `sleep.async` instead.
802
1195
  */
803
1196
  (milliseconds: number): void;
804
1197
 
805
1198
  /**
806
- * Blocks the current thread for at least the specified number of milliseconds,
807
- * or maybe a tiny bit longer.
1199
+ * Blocks the current thread for at least the specified number of
1200
+ * milliseconds, but maybe a tiny bit longer.
808
1201
  *
809
1202
  * @param milliseconds - The number of milliseconds to block for.
1203
+ *
1204
+ * No other JavaScript code can run while `sleep.sync` is running. If this is
1205
+ * not the behavior you want, use `sleep.async` instead.
810
1206
  */
811
1207
  sync(milliseconds: number): void;
812
1208
 
@@ -815,6 +1211,14 @@ declare var sleep: {
815
1211
  * milliseconds, maybe a little longer.
816
1212
  *
817
1213
  * @param milliseconds - The number of milliseconds to wait before the returned Promise should be resolved.
1214
+ *
1215
+ * `sleep.async` doesn't block the current thread, so other JavaScript code
1216
+ * (registered event handlers, async functions, timers, etc) can run while
1217
+ * `sleep.async`'s return Promise is waiting to resolve. If this is not the
1218
+ * behavior you want, use `sleep.sync` instead.
1219
+ *
1220
+ * The Promise returned by `sleep.async` will never get rejected. It will only
1221
+ * ever get resolved.
818
1222
  */
819
1223
  async(milliseconds: number): Promise<void>;
820
1224
  };
@@ -839,42 +1243,129 @@ declare function touch(path: string | Path): void;
839
1243
  * @param options.suffixes A list of filename extension suffixes to include in the search, ie [".exe"]. Defaults to `Path.OS_PROGRAM_EXTENSIONS`.
840
1244
  * @param options.trace A logging function that will be called at various times during the execution of `which`. Defaults to {@link logger.trace}.
841
1245
  */
842
- declare function which(
843
- binaryName: string,
844
- options?: {
845
- /**
846
- * A list of folders where programs may be found. Defaults to
847
- * `env.PATH?.split(Path.OS_ENV_VAR_SEPARATOR) || []`.
848
- */
849
- searchPaths?: Array<Path | string>;
1246
+ declare function which(binaryName: string, options?: WhichOptions): Path | null;
1247
+
1248
+ declare type WhichOptions = {
1249
+ /**
1250
+ * A list of folders where programs may be found. Defaults to
1251
+ * `env.PATH?.split(Path.OS_ENV_VAR_SEPARATOR) || []`.
1252
+ */
1253
+ searchPaths?: Array<Path | string>;
1254
+
1255
+ /**
1256
+ * A list of filename extension suffixes to include in the search, ie
1257
+ * `[".exe"]`. Defaults to {@link Path.OS_PROGRAM_EXTENSIONS}.
1258
+ */
1259
+ suffixes?: Array<string>;
850
1260
 
1261
+ /** Options which control logging. */
1262
+ logging?: {
851
1263
  /**
852
- * A list of filename extension suffixes to include in the search, ie
853
- * `[".exe"]`. Defaults to {@link Path.OS_PROGRAM_EXTENSIONS}.
1264
+ * If provided, this logging function will be called multiple times as
1265
+ * `which` runs, to help you understand what's going on and/or troubleshoot
1266
+ * things. In most cases, it makes sense to use a function from `console`
1267
+ * here, like so:
1268
+ *
1269
+ * ```js
1270
+ * which("bash", {
1271
+ * logging: { trace: console.log }
1272
+ * });
1273
+ * ```
1274
+ *
1275
+ * Defaults to the current value of {@link logger.trace}. `logger.trace`
1276
+ * defaults to a no-op function.
854
1277
  */
855
- suffixes?: Array<string>;
1278
+ trace?: (...args: Array<any>) => void;
1279
+ };
1280
+ };
856
1281
 
857
- /** Options which control logging. */
858
- logging?: {
859
- /**
860
- * If provided, this logging function will be called multiple times as
861
- * `which` runs, to help you understand what's going on and/or troubleshoot
862
- * things. In most cases, it makes sense to use a function from `console`
863
- * here, like so:
864
- *
865
- * ```js
866
- * which("bash", {
867
- * logging: { trace: console.log }
868
- * });
869
- * ```
870
- *
871
- * Defaults to the current value of {@link logger.trace}. `logger.trace`
872
- * defaults to a no-op function.
873
- */
874
- trace?: (...args: Array<any>) => void;
875
- };
876
- }
877
- ): Path | null;
1282
+ /** The type of the return value of {@link whoami}. */
1283
+ declare interface WhoAmIResult {
1284
+ name: string;
1285
+ uid: number;
1286
+ gid: number;
1287
+ }
1288
+
1289
+ /**
1290
+ * Get info about the user the yavascript process is executing as.
1291
+ *
1292
+ * Provides functionality similar to the unix binaries `whoami` and `id`.
1293
+ *
1294
+ * NOTE: Doesn't work on Windows; throws an error.
1295
+ */
1296
+ declare function whoami(): WhoAmIResult;
1297
+
1298
+ /**
1299
+ * Runs a child process and blocks until it exits. You can call it with either a
1300
+ * string or an array of strings.
1301
+ *
1302
+ * When calling `exec` with an array of strings, the first string in the array
1303
+ * is the program to run, and the rest of the strings in the array are arguments
1304
+ * to the program, eg:
1305
+ *
1306
+ * ```ts
1307
+ * exec(["echo", "hi", "there"]);
1308
+ * exec(["printf", "something with spaces\n"]);
1309
+ * ```
1310
+ *
1311
+ * When calling with a string instead of an array, the string will be split into
1312
+ * separate arguments using the following rules:
1313
+ *
1314
+ * - The program and its arguments will be determined by splitting the input
1315
+ * string on whitespace, except:
1316
+ * - Stuff in single or double-quotes will be preserved as a single argument
1317
+ * - Double and single quotes can be "glued" together (eg `"bla"'bla'` becomes
1318
+ * `blabla`)
1319
+ * - The escape sequences `\n`, `\r`, `\t`, `\v`, `\0`, and `\\` can be used
1320
+ * inside of quotes get replaced with newline, carriage return, tab,
1321
+ * vertical tab, nul, and `\` characters, respectively
1322
+ *
1323
+ * For example:
1324
+ *
1325
+ * ```ts
1326
+ * exec(`echo hi there`);
1327
+ * exec(`printf "something with spaces\n"`);
1328
+ * ```
1329
+ *
1330
+ * The intent is that it behaves similarly to what you would expect from a UNIX
1331
+ * shell, but only the "safe" features. "Unsafe" features like environment
1332
+ * variable expansion (`$VAR` or `${VAR}`), subshells (\`echo hi\` or `$(echo
1333
+ * hi)`), and redirection (`> /dev/null` or `2>&1 `) are not supported. To use
1334
+ * those features, shell out to `bash` or `sh` directly via eg `exec(['bash',
1335
+ * '-c', 'your command string'])`, but be aware of the security implications of
1336
+ * doing so.
1337
+ *
1338
+ * `exec` also supports a second argument, an options object which supports the
1339
+ * following keys (all are optional):
1340
+ *
1341
+ * | Property | Purpose |
1342
+ * | ------------------------------ | --------------------------------------------------- |
1343
+ * | cwd (string) | current working directory for the child process |
1344
+ * | env (object) | environment variables for the process |
1345
+ * | failOnNonZeroStatus (boolean) | whether to throw error on nonzero exit status |
1346
+ * | captureOutput (boolean/string) | controls how stdout/stderr is directed |
1347
+ * | logging (object) | controls how/whether info messages are logged |
1348
+ * | block (boolean) | whether to wait for child process exit now or later |
1349
+ *
1350
+ * The return value of `exec` varies depending on the options passed:
1351
+ *
1352
+ * - When `captureOutput` is true or "utf-8", an object will be returned with
1353
+ * `stdout` and `stderr` properties, both strings.
1354
+ * - When `captureOutput` is "arraybuffer", an object will be returned with
1355
+ * `stdout` and `stderr` properties, both `ArrayBuffer`s.
1356
+ * - When `failOnNonZeroStatus` is false, an object will be returned with
1357
+ * `status` (the exit code; number or undefined) and `signal` (the signal that
1358
+ * killed the process; number or undefined).
1359
+ * - When `captureOutput` is non-false and `failOnNonZeroStatus` is false, an
1360
+ * object will be returned with four properties (the two associated with
1361
+ * `failOnNonZeroStatus`, and the two associated with `captureOutput`).
1362
+ * - When `captureOutput` is false or unspecified, and `failOnNonZeroStatus` is
1363
+ * true or unspecified, undefined will be returned.
1364
+ * - If `block` is false, an object with a "wait" method is returned instead,
1365
+ * which blocks the calling thread until the process exits, and then returns
1366
+ * one of the values described above.
1367
+ */
1368
+ declare const exec: Exec;
878
1369
 
879
1370
  declare type BaseExecOptions = {
880
1371
  /** Sets the current working directory for the child process. */
@@ -938,23 +1429,16 @@ declare type BaseExecOptions = {
938
1429
  block?: boolean;
939
1430
  };
940
1431
 
941
- type ExecWaitResult<ExecOptions extends BaseExecOptions> = ExecOptions extends
942
- | { captureOutput: true | "utf8" | "arraybuffer" }
943
- | { failOnNonZeroStatus: false }
944
- ? (ExecOptions["captureOutput"] extends true | "utf8"
945
- ? { stdout: string; stderr: string }
946
- : {}) &
947
- (ExecOptions["captureOutput"] extends "arraybuffer"
948
- ? { stdout: ArrayBuffer; stderr: ArrayBuffer }
949
- : {}) &
950
- (ExecOptions["failOnNonZeroStatus"] extends false
951
- ?
952
- | { status: number; signal: undefined }
953
- | { status: undefined; signal: number }
954
- : {})
955
- : void;
956
-
957
1432
  declare interface Exec {
1433
+ /**
1434
+ * Runs a child process using the provided arguments.
1435
+ *
1436
+ * When `args` is an Array, the first value in the Array is the program to
1437
+ * run.
1438
+ *
1439
+ * @param args - The command to run.
1440
+ * @param options - Options; see {@link BaseExecOptions}
1441
+ */
958
1442
  <
959
1443
  ExecOptions extends BaseExecOptions = {
960
1444
  failOnNonZeroStatus: true;
@@ -976,19 +1460,50 @@ declare interface Exec {
976
1460
  }
977
1461
 
978
1462
  /**
979
- * Runs a child process using the provided arguments.
1463
+ * `$(...)` is an alias for `exec(..., { captureOutput: true, failOnNonZeroStatus: true })`.
1464
+ *
1465
+ * It's often used to capture the output of a program:
980
1466
  *
981
- * The first value in the arguments array is the program to run.
1467
+ * ```ts
1468
+ * const result = $(`echo hi`).stdout;
1469
+ * // result is 'hi\n'
1470
+ * ```
1471
+ *
1472
+ * For more info, see {@link exec}.
982
1473
  */
983
- declare const exec: Exec;
984
-
985
- /** Alias for `exec(args, { captureOutput: true })` */
986
1474
  declare function $(args: Array<string | Path | number> | string | Path): {
987
1475
  stdout: string;
988
1476
  stderr: string;
989
1477
  };
990
1478
 
991
- /** A class which represents a child process. The process may or may not be running. */
1479
+ type ExecWaitResult<ExecOptions extends BaseExecOptions> = ExecOptions extends
1480
+ | { captureOutput: true | "utf8" | "arraybuffer" }
1481
+ | { failOnNonZeroStatus: false }
1482
+ ? (ExecOptions["captureOutput"] extends true | "utf8"
1483
+ ? { stdout: string; stderr: string }
1484
+ : {}) &
1485
+ (ExecOptions["captureOutput"] extends "arraybuffer"
1486
+ ? { stdout: ArrayBuffer; stderr: ArrayBuffer }
1487
+ : {}) &
1488
+ (ExecOptions["failOnNonZeroStatus"] extends false
1489
+ ?
1490
+ | { status: number; signal: undefined }
1491
+ | { status: undefined; signal: number }
1492
+ : {})
1493
+ : void;
1494
+
1495
+ /**
1496
+ * A class which represents a child process. The process may or may not be
1497
+ * running.
1498
+ *
1499
+ * This class is the API used internally by the {@link exec} function to spawn child
1500
+ * processes.
1501
+ *
1502
+ * Generally, you should not need to use the `ChildProcess` class directly, and
1503
+ * should use {@link exec} or {@link $} instead. However, you may need to use it in some
1504
+ * special cases, like when specifying custom stdio for a process, or spawning a
1505
+ * non-blocking long-running process.
1506
+ */
992
1507
  declare interface ChildProcess {
993
1508
  /**
994
1509
  * The argv for the process. The first entry in this array is the program to
@@ -1016,7 +1531,8 @@ declare interface ChildProcess {
1016
1531
  err: FILE;
1017
1532
  };
1018
1533
 
1019
- pid: number | null;
1534
+ get state(): ChildProcessState;
1535
+ get pid(): number | null;
1020
1536
 
1021
1537
  /** Spawns the process and returns its pid (process id). */
1022
1538
  start(): number;
@@ -1027,6 +1543,33 @@ declare interface ChildProcess {
1027
1543
  | { status: undefined; signal: number };
1028
1544
  }
1029
1545
 
1546
+ declare type ChildProcessState =
1547
+ | {
1548
+ id: "UNSTARTED";
1549
+ }
1550
+ | {
1551
+ id: "STARTED";
1552
+ pid: number;
1553
+ }
1554
+ | {
1555
+ id: "STOPPED";
1556
+ pid: number;
1557
+ }
1558
+ | {
1559
+ id: "CONTINUED";
1560
+ pid: number;
1561
+ }
1562
+ | {
1563
+ id: "EXITED";
1564
+ oldPid: number;
1565
+ status: number;
1566
+ }
1567
+ | {
1568
+ id: "SIGNALED";
1569
+ oldPid: number;
1570
+ signal: number;
1571
+ };
1572
+
1030
1573
  /**
1031
1574
  * Options to be passed to the ChildProcess constructor. Their purposes and
1032
1575
  * types match the same-named properties found on the resulting ChildProcess.
@@ -1082,6 +1625,32 @@ declare interface ChildProcessConstructor {
1082
1625
 
1083
1626
  declare var ChildProcess: ChildProcessConstructor;
1084
1627
 
1628
+ /**
1629
+ * Searches the filesystem in order to resolve [UNIX-style glob
1630
+ * strings](https://man7.org/linux/man-pages/man7/glob.7.html) into an array of
1631
+ * matching filesystem paths.
1632
+ *
1633
+ * Glob strings assist in succinctly finding and describing a set of files on
1634
+ * disk. For instance, to find the path of every `.js` file in the `src` folder,
1635
+ * one might write `src/*.js`.
1636
+ *
1637
+ * The function `glob` can be used to turn one or more of these "glob strings" into an array of
1638
+ * `Path` objects.
1639
+ *
1640
+ * `glob` uses [minimatch](https://www.npmjs.com/package/minimatch) with its
1641
+ * default options, which means it supports features like brace expanstion,
1642
+ * "globstar" (**) matching, and other features you would expect from a modern
1643
+ * globbing solution.
1644
+ *
1645
+ * > When specifying more than one pattern string, paths must match ALL of the
1646
+ * > patterns to be included in the returned Array. In other words, it uses
1647
+ * > "logical AND" behavior when you give it more than one pattern.
1648
+ */
1649
+ declare function glob(
1650
+ patterns: string | Array<string>,
1651
+ options?: GlobOptions
1652
+ ): Array<Path>;
1653
+
1085
1654
  /**
1086
1655
  * Options for {@link glob}.
1087
1656
  */
@@ -1130,406 +1699,464 @@ declare type GlobOptions = {
1130
1699
  };
1131
1700
 
1132
1701
  /**
1133
- * Search the filesystem for files matching the specified glob patterns.
1702
+ * Prints special ANSI escape characters to stdout which instruct your terminal
1703
+ * emulator to clear the screen and clear your terminal scrollback.
1134
1704
  *
1135
- * Uses [minimatch](https://www.npmjs.com/package/minimatch) with its default
1136
- * options.
1137
- */
1138
- declare function glob(
1139
- patterns: string | Array<string>,
1140
- options?: GlobOptions
1141
- ): Array<Path>;
1142
-
1143
- /**
1144
- * Clear the contents and scrollback buffer of the tty by printing special characters into stdout.
1705
+ * Identical to {@link console.clear}.
1145
1706
  */
1146
1707
  declare function clear(): void;
1147
1708
 
1148
1709
  interface Console {
1149
- /** Same as {@link clear}(). */
1150
- clear: typeof clear;
1710
+ /**
1711
+ * Logs its arguments to stdout, with a newline appended.
1712
+ *
1713
+ * Any value can be logged, not just strings. Non-string values will be
1714
+ * formatted using {@link inspect}.
1715
+ *
1716
+ * Functionally identical to {@link console.info}, {@link echo}, and
1717
+ * {@link print}. Contrast with {@link console.error}, which prints to stderr
1718
+ * instead of stdout.
1719
+ */
1720
+ log(message?: any, ...optionalParams: any[]): void;
1721
+
1722
+ /**
1723
+ * Logs its arguments to stdout, with a newline appended.
1724
+ *
1725
+ * Any value can be logged, not just strings. Non-string values will be
1726
+ * formatted using {@link inspect}.
1727
+ *
1728
+ * Functionally identical to {@link console.log}, {@link echo}, and
1729
+ * {@link print}. Contrast with {@link console.error}, which prints to stderr
1730
+ * instead of stdout.
1731
+ */
1732
+ info(message?: any, ...optionalParams: any[]): void;
1733
+
1734
+ /**
1735
+ * Logs its arguments to stderr, with a newline appended.
1736
+ *
1737
+ * Any value can be logged, not just strings. Non-string values will be
1738
+ * formatted using {@link inspect}.
1739
+ *
1740
+ * Functionally identical to {@link console.error}. Contrast with
1741
+ * {@link console.log}, which prints to stdout instead of stderr.
1742
+ */
1743
+ warn(message?: any, ...optionalParams: any[]): void;
1744
+
1745
+ /**
1746
+ * Logs its arguments to stderr, with a newline appended.
1747
+ *
1748
+ * Any value can be logged, not just strings. Non-string values will be
1749
+ * formatted using {@link inspect}.
1750
+ *
1751
+ * Functionally identical to {@link console.warn}. Contrast with
1752
+ * {@link console.log}, which prints to stdout instead of stderr.
1753
+ */
1754
+ error(message?: any, ...optionalParams: any[]): void;
1755
+
1756
+ /**
1757
+ * Prints special ANSI escape characters to stdout which instruct your terminal
1758
+ * emulator to clear the screen and clear your terminal scrollback.
1759
+ *
1760
+ * Identical to {@link clear}.
1761
+ */
1762
+ clear(): void;
1151
1763
  }
1152
1764
 
1765
+ declare var console: Console;
1766
+
1153
1767
  /**
1154
- * Remove ANSI control characters from a string.
1768
+ * `print` is an alias for {@link console.log}, which prints values to stdout.
1769
+ *
1770
+ * Any value can be logged, not just strings. Non-string values will be
1771
+ * formatted using {@link inspect}.
1772
+ */
1773
+ declare function print(...args: any): void;
1774
+
1775
+ /**
1776
+ * Removes ANSI control characters from a string.
1155
1777
  */
1156
1778
  declare function stripAnsi(input: string | number | Path): string;
1157
1779
 
1158
1780
  /**
1159
- * Wrap a string in double quotes, and escape any double-quotes inside using `\"`.
1781
+ * Wraps a string in double quotes, and escapes any double-quotes inside using `\"`.
1160
1782
  */
1161
1783
  declare function quote(input: string | number | Path): string;
1162
1784
 
1163
1785
  // Colors
1164
1786
 
1165
- /** Wrap a string with the ANSI control characters that will make it print as black text. */
1787
+ /** Wraps a string with the ANSI control characters that will make it print as black text. */
1166
1788
  declare function black(input: string | number | Path): string;
1167
- /** Wrap a string with the ANSI control characters that will make it print as red text. */
1789
+ /** Wraps a string with the ANSI control characters that will make it print as red text. */
1168
1790
  declare function red(input: string | number | Path): string;
1169
- /** Wrap a string with the ANSI control characters that will make it print as green text. */
1791
+ /** Wraps a string with the ANSI control characters that will make it print as green text. */
1170
1792
  declare function green(input: string | number | Path): string;
1171
- /** Wrap a string with the ANSI control characters that will make it print as yellow text. */
1793
+ /** Wraps a string with the ANSI control characters that will make it print as yellow text. */
1172
1794
  declare function yellow(input: string | number | Path): string;
1173
- /** Wrap a string with the ANSI control characters that will make it print as blue text. */
1795
+ /** Wraps a string with the ANSI control characters that will make it print as blue text. */
1174
1796
  declare function blue(input: string | number | Path): string;
1175
- /** Wrap a string with the ANSI control characters that will make it print as magenta text. */
1797
+ /** Wraps a string with the ANSI control characters that will make it print as magenta text. */
1176
1798
  declare function magenta(input: string | number | Path): string;
1177
- /** Wrap a string with the ANSI control characters that will make it print as cyan text. */
1799
+ /** Wraps a string with the ANSI control characters that will make it print as cyan text. */
1178
1800
  declare function cyan(input: string | number | Path): string;
1179
- /** Wrap a string with the ANSI control characters that will make it print as white text. */
1801
+ /** Wraps a string with the ANSI control characters that will make it print as white text. */
1180
1802
  declare function white(input: string | number | Path): string;
1181
- /** Wrap a string with the ANSI control characters that will make it print as gray text. */
1803
+ /** Wraps a string with the ANSI control characters that will make it print as gray text. (Alias for {@link grey}.) */
1182
1804
  declare function gray(input: string | number | Path): string;
1183
- /** Wrap a string with the ANSI control characters that will make it print as grey text. */
1805
+ /** Wraps a string with the ANSI control characters that will make it print as grey text. (Alias for {@link gray}.) */
1184
1806
  declare function grey(input: string | number | Path): string;
1185
1807
 
1186
1808
  // Background Colors
1187
1809
 
1188
- /** Wrap a string with the ANSI control characters that will make it have a black background. */
1810
+ /** Wraps a string with the ANSI control characters that will make it have a black background when printed. */
1189
1811
  declare function bgBlack(input: string | number | Path): string;
1190
- /** Wrap a string with the ANSI control characters that will make it have a red background. */
1812
+ /** Wraps a string with the ANSI control characters that will make it have a red background when printed. */
1191
1813
  declare function bgRed(input: string | number | Path): string;
1192
- /** Wrap a string with the ANSI control characters that will make it have a green background. */
1814
+ /** Wraps a string with the ANSI control characters that will make it have a green background when printed. */
1193
1815
  declare function bgGreen(input: string | number | Path): string;
1194
- /** Wrap a string with the ANSI control characters that will make it have a yellow background. */
1816
+ /** Wraps a string with the ANSI control characters that will make it have a yellow background when printed. */
1195
1817
  declare function bgYellow(input: string | number | Path): string;
1196
- /** Wrap a string with the ANSI control characters that will make it have a blue background. */
1818
+ /** Wraps a string with the ANSI control characters that will make it have a blue background when printed. */
1197
1819
  declare function bgBlue(input: string | number | Path): string;
1198
- /** Wrap a string with the ANSI control characters that will make it have a magenta background. */
1820
+ /** Wraps a string with the ANSI control characters that will make it have a magenta background when printed. */
1199
1821
  declare function bgMagenta(input: string | number | Path): string;
1200
- /** Wrap a string with the ANSI control characters that will make it have a cyan background. */
1822
+ /** Wraps a string with the ANSI control characters that will make it have a cyan background when printed. */
1201
1823
  declare function bgCyan(input: string | number | Path): string;
1202
- /** Wrap a string with the ANSI control characters that will make it have a white background. */
1824
+ /** Wraps a string with the ANSI control characters that will make it have a white background when printed. */
1203
1825
  declare function bgWhite(input: string | number | Path): string;
1204
1826
 
1205
1827
  // Modifiers
1206
1828
 
1207
- /** Wrap a string with the ANSI control character that resets all styling. */
1829
+ /** Prefixes a string with the ANSI control character that resets all styling. */
1208
1830
  declare function reset(input: string | number | Path): string;
1209
- /** Wrap a string with the ANSI control characters that will make it print with a bold style. */
1831
+ /** Wraps a string with the ANSI control characters that will make it print with a bold style. */
1210
1832
  declare function bold(input: string | number | Path): string;
1211
- /** Wrap a string with the ANSI control characters that will make it print with a dimmed style. */
1833
+ /** Wraps a string with the ANSI control characters that will make it print with a dimmed style. */
1212
1834
  declare function dim(input: string | number | Path): string;
1213
- /** Wrap a string with the ANSI control characters that will make it print italicized. */
1835
+ /** Wraps a string with the ANSI control characters that will make it print italicized. */
1214
1836
  declare function italic(input: string | number | Path): string;
1215
- /** Wrap a string with the ANSI control characters that will make it print underlined. */
1837
+ /** Wraps a string with the ANSI control characters that will make it print underlined. */
1216
1838
  declare function underline(input: string | number | Path): string;
1217
- /** Wrap a string with ANSI control characters such that its foreground (text) and background colors are swapped. */
1839
+ /** Wraps a string with ANSI control characters that will make it print with its foreground (text) and background colors swapped. */
1218
1840
  declare function inverse(input: string | number | Path): string;
1219
- /** Wrap a string with ANSI control characters such that it is hidden. */
1841
+ /** Wraps a string with ANSI control characters that will make it print as hidden. */
1220
1842
  declare function hidden(input: string | number | Path): string;
1221
- /** Wrap a string with the ANSI control characters that will make it print with a horizontal line through its center. */
1843
+ /** Wraps a string with the ANSI control characters that will make it print with a horizontal line through its center. */
1222
1844
  declare function strikethrough(input: string | number | Path): string;
1223
1845
 
1224
- /** Split `str` on newline and then return lines matching `pattern`. */
1225
- declare const grepString: {
1226
- /** Split `str` on newline and then return lines matching `pattern`. */
1227
- (str: string, pattern: string | RegExp): Array<string>;
1228
-
1229
- /** Split `str` on newline and then return lines matching `pattern`. */
1230
- (
1231
- str: string,
1232
- pattern: string | RegExp,
1233
- options: { inverse: false }
1234
- ): Array<string>;
1235
-
1236
- /** Split `str` on newline and then return lines NOT matching `pattern`. */
1237
- (
1238
- str: string,
1239
- pattern: string | RegExp,
1240
- options: { inverse: true }
1241
- ): Array<string>;
1242
-
1243
- /** Split `str` on newline and then return lines matching `pattern`. */
1244
- (
1245
- str: string,
1246
- pattern: string | RegExp,
1247
- options: { details: false }
1248
- ): Array<string>;
1249
-
1250
- /** Split `str` on newline and then return lines matching `pattern`. */
1251
- (
1252
- str: string,
1253
- pattern: string | RegExp,
1254
- options: { inverse: false; details: false }
1255
- ): Array<string>;
1256
-
1257
- /** Split `str` on newline and then return lines NOT matching `pattern`. */
1258
- (
1259
- str: string,
1260
- pattern: string | RegExp,
1261
- options: { inverse: true; details: false }
1262
- ): Array<string>;
1263
-
1264
- /** Split `str` on newline and then return info about lines matching `pattern`. */
1265
- (str: string, pattern: string | RegExp, options: { details: true }): Array<{
1266
- lineNumber: number;
1267
- lineContent: string;
1268
- matches: RegExpMatchArray;
1269
- }>;
1270
-
1271
- /** Split `str` on newline and then return info about lines matching `pattern`. */
1272
- (
1273
- str: string,
1274
- pattern: string | RegExp,
1275
- options: { inverse: false; details: true }
1276
- ): Array<string>;
1277
-
1278
- /** Split `str` on newline and then return info about lines NOT matching `pattern`. */
1279
- (
1280
- str: string,
1281
- pattern: string | RegExp,
1282
- options: { inverse: true; details: true }
1283
- ): Array<{
1284
- lineNumber: number;
1285
- lineContent: string;
1286
- matches: RegExpMatchArray;
1287
- }>;
1288
- };
1289
-
1290
- /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
1291
- declare const grepFile: {
1292
- /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
1293
- (path: string | Path, pattern: string | RegExp): Array<string>;
1294
-
1295
- /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
1296
- (
1297
- path: string | Path,
1298
- pattern: string | RegExp,
1299
- options: { inverse: false }
1300
- ): Array<string>;
1301
-
1302
- /** Read the content at `path`, split it on newline, and then return lines NOT matching `pattern`. */
1303
- (
1304
- path: string | Path,
1305
- pattern: string | RegExp,
1306
- options: { inverse: true }
1307
- ): Array<string>;
1308
-
1309
- /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
1310
- (
1311
- path: string | Path,
1312
- pattern: string | RegExp,
1313
- options: { details: false }
1314
- ): Array<string>;
1315
-
1316
- /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
1317
- (
1318
- path: string | Path,
1319
- pattern: string | RegExp,
1320
- options: { inverse: false; details: false }
1321
- ): Array<string>;
1322
-
1323
- /** Read the content at `path`, split it on newline, and then return lines NOT matching `pattern`. */
1846
+ /**
1847
+ * Splits the string passed into it on `\n` and then returns the lines matching
1848
+ * the specified pattern, as an array of strings or detail objects.
1849
+ *
1850
+ * @param str - The string to search through.
1851
+ * @param pattern - The pattern to find. Can be a string or a RegExp.
1852
+ * @param options - Options which control matching behavior.
1853
+ *
1854
+ * See also {@link grepFile} and {@link String.prototype.grep}.
1855
+ */
1856
+ declare const grepString: {
1324
1857
  (
1325
- path: string | Path,
1858
+ str: string,
1326
1859
  pattern: string | RegExp,
1327
- options: { inverse: true; details: false }
1328
- ): Array<string>;
1860
+ options: GrepOptions & { details: true }
1861
+ ): Array<GrepMatchDetail>;
1329
1862
 
1330
- /** Read the content at `path`, split it on newline, and then return info about lines matching `pattern`. */
1331
- (
1332
- path: string | Path,
1333
- pattern: string | RegExp,
1334
- options: { details: true }
1335
- ): Array<{
1336
- lineNumber: number;
1337
- lineContent: string;
1338
- matches: RegExpMatchArray;
1339
- }>;
1863
+ (str: string, pattern: string | RegExp, options?: GrepOptions): Array<string>;
1864
+ };
1340
1865
 
1341
- /** Read the content at `path`, split it on newline, and then return info about lines matching `pattern`. */
1866
+ /**
1867
+ * Reads the file content at `path`, splits it on `\n`, and then returns the
1868
+ * lines matching the specified pattern, as an array of strings or detail objects.
1869
+ *
1870
+ * @param str - The string to search through.
1871
+ * @param pattern - The pattern to find. Can be a string or a RegExp.
1872
+ * @param options - Options which control matching behavior.
1873
+ *
1874
+ * See also {@link grepString} and {@link String.prototype.grep}.
1875
+ */
1876
+ declare const grepFile: {
1342
1877
  (
1343
1878
  path: string | Path,
1344
1879
  pattern: string | RegExp,
1345
- options: { inverse: false; details: true }
1346
- ): Array<string>;
1880
+ options: GrepOptions & { details: true }
1881
+ ): Array<GrepMatchDetail>;
1347
1882
 
1348
- /** Read the content at `path`, split it on newline, and then return info about lines NOT matching `pattern`. */
1349
1883
  (
1350
1884
  path: string | Path,
1351
1885
  pattern: string | RegExp,
1352
- options: { inverse: true; details: true }
1353
- ): Array<{
1354
- lineNumber: number;
1355
- lineContent: string;
1356
- matches: RegExpMatchArray;
1357
- }>;
1886
+ options?: GrepOptions
1887
+ ): Array<string>;
1358
1888
  };
1359
1889
 
1360
1890
  interface String {
1361
1891
  // Same as grepString but without the first argument.
1892
+ /**
1893
+ * Splits the target string on `\n` and then returns the lines matching the
1894
+ * specified pattern, as an array of strings or detail objects.
1895
+ *
1896
+ * @param str - The string to search through.
1897
+ * @param pattern - The pattern to find. Can be a string or a RegExp.
1898
+ * @param options - Options which control matching behavior.
1899
+ *
1900
+ * See also {@link grepString} and {@link grepFile}.
1901
+ */
1362
1902
  grep: {
1363
- /** Split the string on newline and then return lines matching `pattern`. */
1364
- (pattern: string | RegExp): Array<string>;
1365
-
1366
- /** Split the string on newline and then return lines matching `pattern`. */
1367
- (pattern: string | RegExp, options: { inverse: false }): Array<string>;
1368
-
1369
- /** Split the string on newline and then return lines NOT matching `pattern`. */
1370
- (pattern: string | RegExp, options: { inverse: true }): Array<string>;
1371
-
1372
- /** Split the string on newline and then return lines matching `pattern`. */
1373
- (pattern: string | RegExp, options: { details: false }): Array<string>;
1374
-
1375
- /** Split the string on newline and then return lines matching `pattern`. */
1376
- (
1377
- pattern: string | RegExp,
1378
- options: { inverse: false; details: false }
1379
- ): Array<string>;
1380
-
1381
- /** Split the string on newline and then return lines NOT matching `pattern`. */
1382
- (
1383
- pattern: string | RegExp,
1384
- options: { inverse: true; details: false }
1385
- ): Array<string>;
1386
-
1387
- /** Split the string on newline and then return info about lines matching `pattern`. */
1388
- (pattern: string | RegExp, options: { details: true }): Array<{
1389
- lineNumber: number;
1390
- lineContent: string;
1391
- matches: RegExpMatchArray;
1392
- }>;
1393
-
1394
- /** Split the string on newline and then return info about lines matching `pattern`. */
1395
1903
  (
1396
1904
  pattern: string | RegExp,
1397
- options: { inverse: false; details: true }
1398
- ): Array<string>;
1905
+ options: GrepOptions & { details: true }
1906
+ ): Array<GrepMatchDetail>;
1399
1907
 
1400
- /** Split the string on newline and then return info about lines NOT matching `pattern`. */
1401
- (
1402
- pattern: string | RegExp,
1403
- options: { inverse: true; details: true }
1404
- ): Array<{
1405
- lineNumber: number;
1406
- lineContent: string;
1407
- matches: RegExpMatchArray;
1408
- }>;
1908
+ (pattern: string | RegExp, options?: GrepOptions): Array<string>;
1409
1909
  };
1410
1910
  }
1411
1911
 
1412
- declare type TypeValidator<T> = (value: any) => value is T;
1413
-
1414
- declare type CoerceToTypeValidator<V extends CoerceableToTypeValidator> =
1415
- V extends StringConstructor
1416
- ? TypeValidator<string>
1417
- : V extends NumberConstructor
1418
- ? TypeValidator<number>
1419
- : V extends BooleanConstructor
1420
- ? TypeValidator<boolean>
1421
- : V extends BigIntConstructor
1422
- ? TypeValidator<BigInt>
1423
- : V extends SymbolConstructor
1424
- ? TypeValidator<Symbol>
1425
- : V extends RegExpConstructor
1426
- ? TypeValidator<RegExp>
1427
- : V extends ArrayConstructor
1428
- ? TypeValidator<Array<unknown>>
1429
- : V extends SetConstructor
1430
- ? TypeValidator<Set<unknown>>
1431
- : V extends MapConstructor
1432
- ? TypeValidator<Map<unknown, unknown>>
1433
- : V extends ObjectConstructor
1434
- ? TypeValidator<{
1435
- [key: string | number | symbol]: unknown;
1436
- }>
1437
- : V extends DateConstructor
1438
- ? TypeValidator<Date>
1439
- : V extends FunctionConstructor
1440
- ? TypeValidator<Function>
1441
- : V extends ArrayBufferConstructor
1442
- ? TypeValidator<ArrayBuffer>
1443
- : V extends SharedArrayBufferConstructor
1444
- ? TypeValidator<SharedArrayBuffer>
1445
- : V extends DataViewConstructor
1446
- ? TypeValidator<DataView>
1447
- : V extends Int8ArrayConstructor
1448
- ? TypeValidator<Int8Array>
1449
- : V extends Uint8ArrayConstructor
1450
- ? TypeValidator<Uint8Array>
1451
- : V extends Uint8ClampedArrayConstructor
1452
- ? TypeValidator<Uint8ClampedArray>
1453
- : V extends Int16ArrayConstructor
1454
- ? TypeValidator<Int16Array>
1455
- : V extends Uint16ArrayConstructor
1456
- ? TypeValidator<Uint16Array>
1457
- : V extends Int32ArrayConstructor
1458
- ? TypeValidator<Int32Array>
1459
- : V extends Uint32ArrayConstructor
1460
- ? TypeValidator<Uint32Array>
1461
- : V extends Float32ArrayConstructor
1462
- ? TypeValidator<Float32Array>
1463
- : V extends Float64ArrayConstructor
1464
- ? TypeValidator<Float64Array>
1465
- : V extends RegExp
1466
- ? TypeValidator<string>
1467
- : V extends {}
1468
- ? TypeValidator<{
1469
- [key in keyof V]: CoerceToTypeValidator<V[key]>;
1470
- }>
1471
- : V extends []
1472
- ? TypeValidator<[]>
1473
- : V extends [any]
1474
- ? TypeValidator<Array<CoerceToTypeValidator<V[0]>>>
1475
- : V extends Array<any>
1476
- ? TypeValidator<Array<unknown>>
1477
- : V extends {
1478
- new (...args: any): any;
1479
- }
1480
- ? TypeValidator<InstanceType<V>>
1481
- : TypeValidator<V>;
1912
+ declare interface GrepOptions {
1913
+ /**
1914
+ * When `inverse` is true, the grep function returns those lines which DON'T
1915
+ * match the pattern, instead of those which do. Defaults to `false`.
1916
+ */
1917
+ inverse?: boolean;
1482
1918
 
1483
- declare type CoerceableToTypeValidator =
1484
- | boolean
1485
- | number
1486
- | string
1487
- | bigint
1488
- | undefined
1489
- | null
1490
- | RegExp
1491
- | StringConstructor
1492
- | NumberConstructor
1493
- | BooleanConstructor
1494
- | BigIntConstructor
1495
- | SymbolConstructor
1496
- | RegExpConstructor
1497
- | ArrayConstructor
1498
- | SetConstructor
1499
- | MapConstructor
1500
- | ObjectConstructor
1501
- | DateConstructor
1502
- | FunctionConstructor
1503
- | ArrayBufferConstructor
1504
- | SharedArrayBufferConstructor
1505
- | DataViewConstructor
1506
- | Int8ArrayConstructor
1507
- | Uint8ArrayConstructor
1508
- | Uint8ClampedArrayConstructor
1509
- | Int16ArrayConstructor
1510
- | Uint16ArrayConstructor
1511
- | Int32ArrayConstructor
1512
- | Uint32ArrayConstructor
1513
- | Float32ArrayConstructor
1514
- | Float64ArrayConstructor
1515
- | {}
1516
- | []
1517
- | [any]
1518
- | Array<any>
1519
- | {
1520
- new (...args: any): any;
1521
- };
1919
+ /**
1920
+ * When `details` is true, the grep function returns an array of
1921
+ * {@link GrepMatchDetail} objects instead of an array of strings. Defaults to
1922
+ * `false`.
1923
+ */
1924
+ details?: boolean;
1925
+ }
1522
1926
 
1523
- declare type UnwrapTypeFromCoerceableOrValidator<
1524
- V extends CoerceableToTypeValidator | TypeValidator<any> | unknown
1525
- > = V extends TypeValidator<infer T>
1526
- ? T
1527
- : V extends CoerceableToTypeValidator
1528
- ? CoerceToTypeValidator<V> extends TypeValidator<infer T>
1529
- ? T
1530
- : never
1531
- : unknown;
1927
+ /**
1928
+ * When `grepString`, `grepFile`, or `String.prototype.grep` are called with the
1929
+ * `{ details: true }` option set, an Array of `GrepMatchDetail` objects is
1930
+ * returned.
1931
+ */
1932
+ declare interface GrepMatchDetail {
1933
+ lineNumber: number;
1934
+ lineContent: string;
1935
+ matches: RegExpMatchArray;
1936
+ }
1532
1937
 
1938
+ /**
1939
+ * The `types` namespace object contains various functions which can be used to
1940
+ * identify the type of a value at runtime. It is based on
1941
+ * [pheno](https://github.com/suchipi/pheno), with some yavascript-specific
1942
+ * extensions.
1943
+ *
1944
+ * ## Usage
1945
+ *
1946
+ * To check that a value is of a type, use `is`. To assert that a value is of a
1947
+ * type, use `assert.type`:
1948
+ *
1949
+ * ```ts
1950
+ * is("hi", types.string); // true
1951
+ * is("hi", types.number); // false
1952
+ * is({ blah: 42 }, types.objectWithProperties({ blah: types.number })); // true
1953
+ *
1954
+ * assert.type("hi", types.string);
1955
+ * assert.type("hi", types.number); // throws
1956
+ * assert.type({ blah: 42 }, types.objectWithProperties({ blah: types.number }));
1957
+ * ```
1958
+ *
1959
+ * In many cases, you can use a "normal" JavaScript value for the type instead
1960
+ * of something from the `types` namespace. For instance, the following code
1961
+ * block is equivalent to the previous one:
1962
+ *
1963
+ * ```ts
1964
+ * is("hi", String); // true
1965
+ * is("hi", Number); // false
1966
+ * is({ blah: 42 }, { blah: Number }); // true
1967
+ *
1968
+ * assert.type("hi", String);
1969
+ * assert.type("hi", Number); // throws
1970
+ * assert.type({ blah: 42 }, { blah: Number });
1971
+ * ```
1972
+ *
1973
+ * For more info about using "normal" values, see the "Coercion" heading below.
1974
+ *
1975
+ * ## Explanation
1976
+ *
1977
+ * There are two kinds of function properties found on the `types` namespace:
1978
+ * those which return a boolean, and those which return a function. Functions
1979
+ * which return a boolean are called "type validators", and can be used to check
1980
+ * the type of a value. For example, `types.number` is a type validator:
1981
+ *
1982
+ * ```ts
1983
+ * is(42, types.number); // returns true
1984
+ * ```
1985
+ *
1986
+ * The other kind of function is a function which returns a function. These are
1987
+ * called "type validator constructors", because the function they return is a
1988
+ * type validator. They are used to construct complex type validators. For
1989
+ * example, `types.exactString` is a type validator constructor:
1990
+ *
1991
+ * ```ts
1992
+ * const myType = types.exactString("potato");
1993
+ * // myType is a function which returns true or false
1994
+ *
1995
+ * is("eggplant", myType); // returns false
1996
+ * is("potato", myType); // returns true
1997
+ * ```
1998
+ *
1999
+ * ## List of Functions
2000
+ *
2001
+ * ### Type Validators
2002
+ *
2003
+ * Here is a list of all the type validators:
2004
+ *
2005
+ * - `any`
2006
+ * - `anyArray`
2007
+ * - `anyFunction`
2008
+ * - `anyMap`
2009
+ * - `anyObject`
2010
+ * - `anySet`
2011
+ * - `anyTypeValidator`
2012
+ * - `array` (alias of `arrayOfUnknown`)
2013
+ * - `arrayOfAny`
2014
+ * - `arrayOfUnknown`
2015
+ * - `Array` (alias of `arrayOfUnknown`)
2016
+ * - `bigint`
2017
+ * - `BigInt` (alias of `bigint`)
2018
+ * - `boolean`
2019
+ * - `Boolean` (alias of `boolean`)
2020
+ * - `Date`
2021
+ * - `Error`
2022
+ * - `false`
2023
+ * - `falsy`
2024
+ * - `Function` (alias of `unknownFunction`)
2025
+ * - `Infinity`
2026
+ * - `integer`
2027
+ * - `map` (alias of `unknownMap`)
2028
+ * - `Map` (alias of `unknownMap`)
2029
+ * - `NaN`
2030
+ * - `NegativeInfinity`
2031
+ * - `never`
2032
+ * - `nonNullOrUndefined`
2033
+ * - `null`
2034
+ * - `nullish`
2035
+ * - `void` (alias of `nullish`)
2036
+ * - `number` (doesn't include NaN, Infinity, or -Infinity)
2037
+ * - `Number` (alias of `number`)
2038
+ * - `numberIncludingNanAndInfinities`
2039
+ * - `object` (alias of `unknownObject`)
2040
+ * - `Object` (alias of `unknownObject`)
2041
+ * - `objectOrNull`
2042
+ * - `RegExp`
2043
+ * - `set` (alias of `unknownSet`)
2044
+ * - `Set` (alias of `unknownSet`)
2045
+ * - `string`
2046
+ * - `String` (alias of `string`)
2047
+ * - `Symbol`
2048
+ * - `symbol` (alias of `Symbol`)
2049
+ * - `true`
2050
+ * - `truthy`
2051
+ * - `undefined`
2052
+ * - `unknown`
2053
+ * - `unknownFunction`
2054
+ * - `unknownMap`
2055
+ * - `unknownObject`
2056
+ * - `unknownSet`
2057
+ * - `unknownTypeValidator`
2058
+ * - `ArrayBuffer`
2059
+ * - `SharedArrayBuffer`
2060
+ * - `DataView`
2061
+ * - `TypedArray`
2062
+ * - `Int8Array`
2063
+ * - `Uint8Array`
2064
+ * - `Uint8ClampedArray`
2065
+ * - `Int16Array`
2066
+ * - `Uint16Array`
2067
+ * - `Int32Array`
2068
+ * - `Uint32Array`
2069
+ * - `Float32Array`
2070
+ * - `Float64Array`
2071
+ * - `FILE`
2072
+ * - `Path`
2073
+ * - `JSX.Element` (alias of `JSX.unknownElement`)
2074
+ * - `JSX.unknownElement`
2075
+ * - `JSX.anyElement`
2076
+ * - `JSX.Fragment`
2077
+ *
2078
+ * ### Type Validator Constructors
2079
+ *
2080
+ * And all the type validator constructors:
2081
+ *
2082
+ * - `and`
2083
+ * - `arrayOf`
2084
+ * - `exactBigInt`
2085
+ * - `exactNumber`
2086
+ * - `exactString`
2087
+ * - `exactSymbol`
2088
+ * - `hasClassName`
2089
+ * - `hasToStringTag`
2090
+ * - `instanceOf`
2091
+ * - `intersection`
2092
+ * - `mapOf`
2093
+ * - `mappingObjectOf`
2094
+ * - `maybe`
2095
+ * - `objectWithOnlyTheseProperties`
2096
+ * - `objectWithProperties`
2097
+ * - `or`
2098
+ * - `optional`
2099
+ * - `partialObjectWithProperties`
2100
+ * - `record`
2101
+ * - `setOf`
2102
+ * - `stringMatching`
2103
+ * - `symbolFor`
2104
+ * - `union`
2105
+ *
2106
+ * ## Coercion
2107
+ *
2108
+ * There is also a function, `types.coerce`, which returns an appropriate type
2109
+ * validator value for a given input value, using the following logic:
2110
+ *
2111
+ * | Input value | Output validator |
2112
+ * | ----------------------------- | ---------------------------------- |
2113
+ * | `String` or `string` global | `types.string` |
2114
+ * | `Number` or `number` global | `types.number` |
2115
+ * | `Boolean` or `boolean` global | `types.boolean` |
2116
+ * | `BigInt` or `bigint` global | `types.bigint` |
2117
+ * | `Symbol` global | `types.Symbol` |
2118
+ * | `RegExp` global | `types.RegExp` |
2119
+ * | `Array` global | `types.arrayOfUnknown` |
2120
+ * | `Set` global | `types.unknownSet` |
2121
+ * | `Map` global | `types.unknownMap` |
2122
+ * | `Object` global | `types.unknownObject` |
2123
+ * | `Date` global | `types.Date` |
2124
+ * | `Function` global | `types.unknownFunction` |
2125
+ * | `ArrayBuffer` global | `types.ArrayBuffer` |
2126
+ * | `SharedArrayBuffer` global | `types.SharedArrayBuffer` |
2127
+ * | `DataView` global | `types.DataView` |
2128
+ * | `Int8Array` global | `types.Int8Array` |
2129
+ * | `Uint8Array` global | `types.Uint8Array` |
2130
+ * | `Uint8ClampedArray` global | `types.Uint8ClampedArray` |
2131
+ * | `Int16Array` global | `types.Int16Array` |
2132
+ * | `Uint16Array` global | `types.Uint16Array` |
2133
+ * | `Int32Array` global | `types.Int32Array` |
2134
+ * | `Uint32Array` global | `types.Uint32Array` |
2135
+ * | `Float32Array` global | `types.Float32Array` |
2136
+ * | `Float64Array` global | `types.Float64Array` |
2137
+ * | `Path` global | `types.Path` |
2138
+ * | Any RegExp value | Validator for matching strings |
2139
+ * | Empty array | Validator for empty arrays |
2140
+ * | Array with one item | Validator for array of that item |
2141
+ * | Array with multiple items | Validator for tuple of those types |
2142
+ * | Class constructor function | Validator for instances of it |
2143
+ * | Any Object value | Validator for same-shaped object |
2144
+ * | null | `types.null` |
2145
+ * | undefined | `types.undefined` |
2146
+ * | true | `types.true` |
2147
+ * | false | `types.false` |
2148
+ * | NaN | `types.NaN` |
2149
+ * | Infinity | `types.Infinity` |
2150
+ * | `-Infinity` | `types.NegativeInfinity` |
2151
+ * | Any string value | `types.exactString(<the value>)` |
2152
+ * | Any 'normal' number value | `types.exactNumber(<the value>)` |
2153
+ * | Any Symbol value | `types.exactSymbol(<the value>)` |
2154
+ * | Any BigInt value | `types.exactBigInt(<the value>)` |
2155
+ *
2156
+ * > All type constructors, as well as `is` and `assert.type`, do coercion
2157
+ * > automatically! This means that in many cases, you do not need to access
2158
+ * > properties from the `types` namespace.
2159
+ */
1533
2160
  declare const types: {
1534
2161
  // basic types
1535
2162
  any: TypeValidator<any>;
@@ -2730,28 +3357,195 @@ declare const types: {
2730
3357
  >;
2731
3358
  };
2732
3359
 
2733
- coerce: <V extends CoerceableToTypeValidator | TypeValidator<any> | unknown>(
2734
- value: V
2735
- ) => TypeValidator<UnwrapTypeFromCoerceableOrValidator<V>>;
3360
+ coerce: <V extends CoerceableToTypeValidator | TypeValidator<any> | unknown>(
3361
+ value: V
3362
+ ) => TypeValidator<UnwrapTypeFromCoerceableOrValidator<V>>;
3363
+
3364
+ FILE: TypeValidator<FILE>;
3365
+ Path: TypeValidator<Path>;
3366
+ JSX: {
3367
+ unknownElement: TypeValidator<
3368
+ JSX.Element<{ [key: string | symbol | number]: unknown }, unknown>
3369
+ >;
3370
+ anyElement: TypeValidator<JSX.Element<any, any>>;
3371
+ Element: TypeValidator<
3372
+ JSX.Element<{ [key: string | symbol | number]: unknown }, unknown>
3373
+ >;
3374
+ Fragment: TypeValidator<JSX.Fragment>;
3375
+ };
3376
+ };
3377
+
3378
+ declare type TypeValidator<T> = (value: any) => value is T;
3379
+
3380
+ declare type CoerceToTypeValidator<V extends CoerceableToTypeValidator> =
3381
+ V extends StringConstructor
3382
+ ? TypeValidator<string>
3383
+ : V extends NumberConstructor
3384
+ ? TypeValidator<number>
3385
+ : V extends BooleanConstructor
3386
+ ? TypeValidator<boolean>
3387
+ : V extends BigIntConstructor
3388
+ ? TypeValidator<BigInt>
3389
+ : V extends SymbolConstructor
3390
+ ? TypeValidator<Symbol>
3391
+ : V extends RegExpConstructor
3392
+ ? TypeValidator<RegExp>
3393
+ : V extends ArrayConstructor
3394
+ ? TypeValidator<Array<unknown>>
3395
+ : V extends SetConstructor
3396
+ ? TypeValidator<Set<unknown>>
3397
+ : V extends MapConstructor
3398
+ ? TypeValidator<Map<unknown, unknown>>
3399
+ : V extends ObjectConstructor
3400
+ ? TypeValidator<{
3401
+ [key: string | number | symbol]: unknown;
3402
+ }>
3403
+ : V extends DateConstructor
3404
+ ? TypeValidator<Date>
3405
+ : V extends FunctionConstructor
3406
+ ? TypeValidator<Function>
3407
+ : V extends ArrayBufferConstructor
3408
+ ? TypeValidator<ArrayBuffer>
3409
+ : V extends SharedArrayBufferConstructor
3410
+ ? TypeValidator<SharedArrayBuffer>
3411
+ : V extends DataViewConstructor
3412
+ ? TypeValidator<DataView>
3413
+ : V extends Int8ArrayConstructor
3414
+ ? TypeValidator<Int8Array>
3415
+ : V extends Uint8ArrayConstructor
3416
+ ? TypeValidator<Uint8Array>
3417
+ : V extends Uint8ClampedArrayConstructor
3418
+ ? TypeValidator<Uint8ClampedArray>
3419
+ : V extends Int16ArrayConstructor
3420
+ ? TypeValidator<Int16Array>
3421
+ : V extends Uint16ArrayConstructor
3422
+ ? TypeValidator<Uint16Array>
3423
+ : V extends Int32ArrayConstructor
3424
+ ? TypeValidator<Int32Array>
3425
+ : V extends Uint32ArrayConstructor
3426
+ ? TypeValidator<Uint32Array>
3427
+ : V extends Float32ArrayConstructor
3428
+ ? TypeValidator<Float32Array>
3429
+ : V extends Float64ArrayConstructor
3430
+ ? TypeValidator<Float64Array>
3431
+ : V extends RegExp
3432
+ ? TypeValidator<string>
3433
+ : V extends {}
3434
+ ? TypeValidator<{
3435
+ [key in keyof V]: CoerceToTypeValidator<V[key]>;
3436
+ }>
3437
+ : V extends []
3438
+ ? TypeValidator<[]>
3439
+ : V extends [any]
3440
+ ? TypeValidator<Array<CoerceToTypeValidator<V[0]>>>
3441
+ : V extends Array<any>
3442
+ ? TypeValidator<Array<unknown>>
3443
+ : V extends {
3444
+ new (...args: any): any;
3445
+ }
3446
+ ? TypeValidator<InstanceType<V>>
3447
+ : TypeValidator<V>;
3448
+
3449
+ declare type CoerceableToTypeValidator =
3450
+ | boolean
3451
+ | number
3452
+ | string
3453
+ | bigint
3454
+ | undefined
3455
+ | null
3456
+ | RegExp
3457
+ | StringConstructor
3458
+ | NumberConstructor
3459
+ | BooleanConstructor
3460
+ | BigIntConstructor
3461
+ | SymbolConstructor
3462
+ | RegExpConstructor
3463
+ | ArrayConstructor
3464
+ | SetConstructor
3465
+ | MapConstructor
3466
+ | ObjectConstructor
3467
+ | DateConstructor
3468
+ | FunctionConstructor
3469
+ | ArrayBufferConstructor
3470
+ | SharedArrayBufferConstructor
3471
+ | DataViewConstructor
3472
+ | Int8ArrayConstructor
3473
+ | Uint8ArrayConstructor
3474
+ | Uint8ClampedArrayConstructor
3475
+ | Int16ArrayConstructor
3476
+ | Uint16ArrayConstructor
3477
+ | Int32ArrayConstructor
3478
+ | Uint32ArrayConstructor
3479
+ | Float32ArrayConstructor
3480
+ | Float64ArrayConstructor
3481
+ | {}
3482
+ | []
3483
+ | [any]
3484
+ | Array<any>
3485
+ | {
3486
+ new (...args: any): any;
3487
+ };
2736
3488
 
2737
- FILE: TypeValidator<FILE>;
2738
- Path: TypeValidator<Path>;
2739
- JSX: {
2740
- unknownElement: TypeValidator<
2741
- JSX.Element<{ [key: string | symbol | number]: unknown }, unknown>
2742
- >;
2743
- anyElement: TypeValidator<JSX.Element<any, any>>;
2744
- Element: TypeValidator<
2745
- JSX.Element<{ [key: string | symbol | number]: unknown }, unknown>
2746
- >;
2747
- Fragment: TypeValidator<JSX.Fragment>;
2748
- };
2749
- };
3489
+ declare type UnwrapTypeFromCoerceableOrValidator<
3490
+ V extends CoerceableToTypeValidator | TypeValidator<any> | unknown
3491
+ > = V extends TypeValidator<infer T>
3492
+ ? T
3493
+ : V extends CoerceableToTypeValidator
3494
+ ? CoerceToTypeValidator<V> extends TypeValidator<infer T>
3495
+ ? T
3496
+ : never
3497
+ : unknown;
2750
3498
 
2751
3499
  /**
2752
- * Returns whether `value` is of type `type`. Useful for validating that values have the correct type at runtime, in library functions or etc.
3500
+ * Returns whether `value` is of type `type`. Useful for validating that values
3501
+ * have the correct type at runtime, in library functions or etc.
3502
+ *
3503
+ * The `type` parameter can be any of the following:
3504
+ *
3505
+ * - a TypeValidator function from the `types` namespace
3506
+ * - a global constructor like `String`, `Number`, `Boolean`, `Set`,
3507
+ * `Int8Array`, etc
3508
+ * - a user-defined class
3509
+ * - a primitive value like `true`, `false`, `null`, or `42`
3510
+ * - a Regular Expression (to match strings that match the regexp)
3511
+ * - an object or array containing any combination of the above
3512
+ *
3513
+ * Note that yavascript has the following global aliases defined, which are also
3514
+ * valid types:
3515
+ *
3516
+ * ```ts
3517
+ * const bigint = BigInt;
3518
+ * const boolean = Boolean;
3519
+ * const number = Number;
3520
+ * const string = String;
3521
+ * const symbol = Symbol;
3522
+ * ```
2753
3523
  *
2754
- * Run `help(is)` for more info.
3524
+ * ## Example
3525
+ *
3526
+ * ```ts
3527
+ * is(42, Number); // true
3528
+ * is(42, number); // true
3529
+ * is(42, types.number); // true
3530
+ *
3531
+ * is(42, String); // false
3532
+ * is(42, Set); // false
3533
+ * is(42, Array); // false
3534
+ *
3535
+ * is(42, 42); // true
3536
+ * is(42, 45); // false
3537
+ *
3538
+ * is({ kind: "success", data: 99 }, { kind: "success" }); // true
3539
+ * ```
3540
+ *
3541
+ * ```ts
3542
+ * // Defined in yavascript/src/api/is
3543
+ * declare function is(value: any, type: TypeValidator<any>): boolean;
3544
+ * ```
3545
+ *
3546
+ * See also {@link types} (which contains {@link TypeValidator}s that can be
3547
+ * used by `is`) and {@link assert.type} (which throws an error instead of
3548
+ * returning a boolean).
2755
3549
  */
2756
3550
  declare const is: <T extends TypeValidator<any> | CoerceableToTypeValidator>(
2757
3551
  value: any,
@@ -2759,7 +3553,8 @@ declare const is: <T extends TypeValidator<any> | CoerceableToTypeValidator>(
2759
3553
  ) => value is UnwrapTypeFromCoerceableOrValidator<T>;
2760
3554
 
2761
3555
  /**
2762
- * Alias to {@link is}, for Civet, because `is` is a reserved keyword in Civet.
3556
+ * Alias to {@link is}, for when using the Civet language, because `is` is a
3557
+ * reserved keyword in Civet.
2763
3558
  */
2764
3559
  declare const _is: typeof is;
2765
3560
 
@@ -2778,9 +3573,11 @@ declare const assert: {
2778
3573
  : ValueType;
2779
3574
 
2780
3575
  /**
2781
- * Throws an error if `value` is not of the type `type`.
3576
+ * Throws an error if its argument isn't the correct type.
2782
3577
  *
2783
- * `type` should be either a {@link TypeValidator}, or a value which can be coerced into one via {@link types.coerce}.
3578
+ * @param value - The value to test the type of
3579
+ * @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.
3580
+ * @param message - An optional error message to use. If unspecified, a generic-but-descriptive message will be used.
2784
3581
  */
2785
3582
  type: <T extends TypeValidator<any> | CoerceableToTypeValidator>(
2786
3583
  value: any,
@@ -2789,6 +3586,9 @@ declare const assert: {
2789
3586
  ) => asserts value is UnwrapTypeFromCoerceableOrValidator<T>;
2790
3587
  };
2791
3588
 
3589
+ /**
3590
+ * This API is a work-in-progress and is subject to change at any time.
3591
+ */
2792
3592
  interface InteractivePrompt {
2793
3593
  prompt?: () => string;
2794
3594
  printInput?: (input: string) => void;
@@ -2807,6 +3607,9 @@ interface InteractivePrompt {
2807
3607
  start(): void;
2808
3608
  }
2809
3609
 
3610
+ /**
3611
+ * This API is a work-in-progress and is subject to change at any time.
3612
+ */
2810
3613
  interface InteractivePromptConstructor {
2811
3614
  new (
2812
3615
  handleInput: (input: string) => void,
@@ -2829,14 +3632,16 @@ interface InteractivePromptConstructor {
2829
3632
  prototype: InteractivePrompt;
2830
3633
  }
2831
3634
 
2832
- /** wip experimental use at your own risk */
3635
+ /**
3636
+ * This API is a work-in-progress and is subject to change at any time.
3637
+ */
2833
3638
  declare var InteractivePrompt: InteractivePromptConstructor;
2834
3639
 
2835
3640
  /**
2836
3641
  * Launch the Yavascript REPL (read-eval-print-loop).
2837
3642
  *
2838
3643
  * @param context Variables to make available as globals within the repl.
2839
- * @param lang The langauge to use in the repl. Defaults to "javascript".
3644
+ * @param lang The language to use in the repl. Defaults to "javascript".
2840
3645
  */
2841
3646
  declare const startRepl: {
2842
3647
  (
@@ -2863,6 +3668,19 @@ declare const startRepl: {
2863
3668
  /**
2864
3669
  * An object that points to a git repository on disk and provides utility
2865
3670
  * methods for getting information from that repo.
3671
+ *
3672
+ * To use it, construct a GitRepo object, passing in the path to the repo:
3673
+ *
3674
+ * ```ts
3675
+ * // The path here is just an example
3676
+ * const repo = new GitRepo("/home/suchipi/Code/yavascript");
3677
+ * ```
3678
+ *
3679
+ * Then, you can use methods/properties on the `repo` object:
3680
+ *
3681
+ * ```ts
3682
+ * console.log(repo.branchName() || repo.commitSHA());
3683
+ * ```
2866
3684
  */
2867
3685
  declare class GitRepo {
2868
3686
  /**
@@ -2870,6 +3688,88 @@ declare class GitRepo {
2870
3688
  * directory ancestry to find a `.git` folder, then returns the Path that
2871
3689
  * contains that `.git` folder. If no `.git` folder is found, an error will be
2872
3690
  * thrown.
3691
+ *
3692
+ * For example, if you have a git repo at `/home/suchipi/Code/my-project`,
3693
+ * such that `/home/suchipi/Code/my-project/.git` exists, calling
3694
+ * `GitRepo.findRoot("/home/suchipi/Code/my-project/src/index.js")` will
3695
+ * return a `Path` object pointing to `/home/suchipi/Code/my-project`.
3696
+ *
3697
+ * This function can be useful in order to set the current working directory
3698
+ * of a script relative to the root of the git repo the script appears in. By
3699
+ * doing so, the script can be invoked from any directory.
3700
+ *
3701
+ * For instance, consider this theoretical filesystem layout:
3702
+ *
3703
+ * ```
3704
+ * my-project
3705
+ * - src
3706
+ * - my-script.js
3707
+ * - README.md
3708
+ * ```
3709
+ *
3710
+ * If `my-script.js` contained the following content:
3711
+ *
3712
+ * ```ts
3713
+ * #!/usr/bin/env yavascript
3714
+ *
3715
+ * cat("README.md");
3716
+ * ```
3717
+ *
3718
+ * Then running `src/my-script.js` would print the contents of the README as
3719
+ * expected.
3720
+ *
3721
+ * However, suppose someone ran the script from a different folder:
3722
+ *
3723
+ * ```sh
3724
+ * $ cd src
3725
+ * $ ./my-script.js
3726
+ * ```
3727
+ *
3728
+ * Now an error occurs!
3729
+ *
3730
+ * To make the script resilient against this, you can use `cd` at the top of
3731
+ * the script:
3732
+ *
3733
+ * ```ts
3734
+ * #!/usr/bin/env yavascript
3735
+ *
3736
+ * // __dirname is a special variable that refers to the folder the current script is in.
3737
+ * cd(__dirname);
3738
+ * cd("..");
3739
+ *
3740
+ * cat("README.md");
3741
+ * ```
3742
+ *
3743
+ * However, if the location of `my-script.js` later changes, you will have to
3744
+ * remember to update the script. For instance, if `src/my-script.js` got
3745
+ * moved to `src/tools/my-script.js`, you would need to update the script like
3746
+ * so:
3747
+ *
3748
+ * ```ts
3749
+ * #!/usr/bin/env yavascript
3750
+ *
3751
+ * cd(__dirname);
3752
+ * cd("../.."); // Changed this line
3753
+ *
3754
+ * cat("README.md");
3755
+ * ```
3756
+ *
3757
+ * Since `README.md` will always be in the repository root, using
3758
+ * `GitRepo.findRoot` would make the `cd` resilient against file moves:
3759
+ *
3760
+ * ```ts
3761
+ * #!/usr/bin/env yavascript
3762
+ *
3763
+ * cd(GitRepo.findRoot(__dirname));
3764
+ *
3765
+ * cat("README.md");
3766
+ * ```
3767
+ *
3768
+ * Depending on how you anticipate your codebase changing over time, and how
3769
+ * you expect others to use your scripts, it might make sense to use
3770
+ * `cd(__dirname)`, `cd(GitRepo.findRoot(__dirname))`, or no `cd` at all. Pick what
3771
+ * makes the most sense for your situation.
3772
+ *
2873
3773
  */
2874
3774
  static findRoot(fromPath: string | Path): Path;
2875
3775
 
@@ -2885,9 +3785,24 @@ declare class GitRepo {
2885
3785
  repoDir: Path;
2886
3786
 
2887
3787
  /**
2888
- * Returns the commit SHA the git repo is currently pointed at.
3788
+ * Returns the full SHA-1 hash string associated with the repo's current
3789
+ * commit.
2889
3790
  *
2890
- * This is done by running `git rev-parse HEAD`.
3791
+ * For example:
3792
+ *
3793
+ * ```ts
3794
+ * const repo = new GitRepo(".");
3795
+ * const sha = repo.commitSHA();
3796
+ * console.log(sha);
3797
+ * // "2a0a15f9872406faebcac694562efeae3447a4ba"
3798
+ * ```
3799
+ *
3800
+ * To obtain this information, the command `git rev-parse HEAD` gets run
3801
+ * within the repo's directory.
3802
+ *
3803
+ * > If the repo has unstaged or uncommitted changes, that state will NOT be
3804
+ * > reflected in the SHA-1 hash. As such, it may be desirable to use this
3805
+ * > method in conjunction with `GitRepo.prototype.isWorkingTreeDirty`.
2891
3806
  */
2892
3807
  commitSHA(): string;
2893
3808
 
@@ -2895,7 +3810,20 @@ declare class GitRepo {
2895
3810
  * If the commit SHA the git repo is currently pointed at is the tip of a
2896
3811
  * named branch, returns the branch name. Otherwise, returns `null`.
2897
3812
  *
2898
- * This is done by running `git rev-parse --abbrev-ref HEAD`.
3813
+ * This is done by running `git rev-parse --abbrev-ref HEAD` within the repo
3814
+ * directory.
3815
+ *
3816
+ * Example:
3817
+ *
3818
+ * ```ts
3819
+ * const repo = new GitRepo(".");
3820
+ * const branch = repo.branchName();
3821
+ * console.log(branch);
3822
+ * // "main"
3823
+ * ```
3824
+ *
3825
+ * > The most common situation where there is no current branch is when the
3826
+ * > repository is in "detached HEAD" state.
2899
3827
  */
2900
3828
  branchName(): string | null;
2901
3829
 
@@ -2904,15 +3832,35 @@ declare class GitRepo {
2904
3832
  * git repo. `true` means there are changes, `false` means there are no
2905
3833
  * changes (ie. the repo is clean).
2906
3834
  *
2907
- * This is done by running `git status --quiet`.
3835
+ * This is done by running `git status --quiet` within the repo directory.
2908
3836
  */
2909
3837
  isWorkingTreeDirty(): boolean;
2910
3838
 
2911
3839
  /**
2912
- * Returns whether the provided path is ignored by git.
3840
+ * Returns a boolean indicating whether the provided path is ignored by one or
3841
+ * more `.gitignore` files in the repository.
2913
3842
  *
2914
- * If `path` is an absolute path, it must be a child directory of this GitRepo
2915
- * object's `repoDir`, or else an error will be thrown.
3843
+ * Example:
3844
+ *
3845
+ * ```ts
3846
+ * const repo = new GitRepo(".");
3847
+ * const ignoreStatus = repo.isIgnored("README.md");
3848
+ * console.log(ignoreStatus);
3849
+ * // false
3850
+ * ```
3851
+ *
3852
+ * To obtain this information, the command `git check-ignore <the-path>` gets
3853
+ * run within the repo's directory.
3854
+ *
3855
+ * An error will be thrown if the provided path is not within the repository's
3856
+ * directory tree. For instance, calling `gitRepo.isIgnored("/tmp")` on a
3857
+ * `gitRepo` pointed at `/home/suchipi/my-project` would throw an error,
3858
+ * because `/tmp` is not a child of `/home/suchipi/my-project`.
3859
+ *
3860
+ * > NOTE: When passing relative paths to `isIgnored`, they will be resolved
3861
+ * > relative to the repo root, NOT relative to `pwd()`. It's best practice to
3862
+ * > always pass around absolute paths in your program instead of relative
3863
+ * > ones so that this type of ambiguity is avoided.
2916
3864
  */
2917
3865
  isIgnored(path: string | Path): boolean;
2918
3866
  }
@@ -2946,24 +3894,81 @@ declare const logger: {
2946
3894
  info: (...args: Array<any>) => void;
2947
3895
  };
2948
3896
 
3897
+ /**
3898
+ * The properties of the `JSX` global can be modified to change how JSX syntax
3899
+ * gets compiled by yavascript. Those properties are:
3900
+ *
3901
+ * - `pragma` (string): The JavaScript expression that should be called to
3902
+ * create JSX elements. Defaults to "JSX.createElement".
3903
+ * - `pragmaFrag` (string): The JavaScript expression that should be used when
3904
+ * creating JSX fragments. Defaults to "JSX.Fragment".
3905
+ * - `createElement` (function): The function used to create JSX elements,
3906
+ * unless `JSX.pragma` has been changed.
3907
+ * - `Element` (symbol): used by the default `JSX.createElement` function to
3908
+ * identify JSX elements.
3909
+ * - `Fragment` (symbol): used by the default `JSX.createElement` function to
3910
+ * identify JSX fragments. Referenced by the default value for
3911
+ * `JSX.pragmaFrag`.
3912
+ *
3913
+ * Modifying these properties will change how JSX syntax gets compiled.
3914
+ *
3915
+ * For instance, to use React for JSX, you could either replace
3916
+ * `JSX.createElement` and `JSX.Fragment` with React's versions:
3917
+ *
3918
+ * ```ts
3919
+ * import * as React from "npm:react";
3920
+ *
3921
+ * JSX.createElement = React.createElement;
3922
+ * JSX.Fragment = React.Fragment;
3923
+ * ```
3924
+ *
3925
+ * Or, you could change `JSX.pragma` and `JSX.pragmaFrag` to reference React
3926
+ * directly:
3927
+ *
3928
+ * ```ts
3929
+ * JSX.pragma = "React.createElement";
3930
+ * JSX.pragmaFrag = "React.Fragment";
3931
+ * ```
3932
+ *
3933
+ * Note however, that changes to `pragma` and `pragmaFrag` will only affect JSX
3934
+ * appearing in files which are loaded _after_ the change, but changing
3935
+ * `createElement` and `Fragment` will affect all JSX syntax appearing after the
3936
+ * change, even within the same file.
3937
+ *
3938
+ * Whichever approach you take, you should also update `types.JSX.Element` and
3939
+ * `types.JSX.Fragment` such that the expression `types.JSX.Element(<a />) &&
3940
+ * types.JSX.Fragment(<></>)` is always `true`. To do that for React, you would
3941
+ * do:
3942
+ *
3943
+ * ```ts
3944
+ * types.JSX.Element = React.isValidElement;
3945
+ * types.JSX.Fragment = (value) => {
3946
+ * return React.isValidElement(value) && value.type === React.Fragment;
3947
+ * };
3948
+ * ```
3949
+ */
2949
3950
  declare namespace JSX {
2950
3951
  /**
3952
+ *
2951
3953
  * A string containing the expression that should be called to create JSX
2952
3954
  * elements. yavascript's internals use this string to transpile JSX syntax.
2953
3955
  *
2954
- * Defaults to "JSX.createElement".
3956
+ * The default value is "JSX.createElement".
2955
3957
  *
2956
- * If changed, any JSX code loaded afterwards will use a different
2957
- * expression.
3958
+ * If changed, any JSX code loaded afterwards will use a different expression.
2958
3959
  *
2959
3960
  * Note that if you change this, you need to verify that the following
2960
- * expression always evaluates to `true` (by changing {@link types.JSX.Element}
2961
- * and {@link types.JSX.Fragment}):
3961
+ * expression always evaluates to `true` (by changing `types.JSX.Element` and
3962
+ * `types.JSX.Fragment`):
3963
+ *
2962
3964
  * ```jsx
2963
- * types.JSX.Element(<a />) && types.JSX.Fragment(<></>)
3965
+ * types.JSX.Element(<a />) && types.JSX.Fragment(<></>);
2964
3966
  * ```
2965
3967
  *
2966
3968
  * Failure to uphold this guarantee indicates a bug.
3969
+ *
3970
+ * For more info, including info on how to change how JSX is compiled, see
3971
+ * {@link JSX}.
2967
3972
  */
2968
3973
  export let pragma: string;
2969
3974
 
@@ -2974,22 +3979,66 @@ declare namespace JSX {
2974
3979
  *
2975
3980
  * Defaults to "JSX.Fragment".
2976
3981
  *
2977
- * If changed, any JSX code loaded afterwards will use a different
2978
- * expression.
3982
+ * If changed, any JSX code loaded afterwards will use a different expression.
2979
3983
  *
2980
3984
  * Note that if you change this, you need to verify that the following
2981
- * expression always evaluates to `true` (by changing {@link types.JSX.Element}
2982
- * and {@link types.JSX.Fragment}):
3985
+ * expression always evaluates to `true` (by changing `types.JSX.Element` and
3986
+ * `types.JSX.Fragment`):
3987
+ *
2983
3988
  * ```jsx
2984
- * types.JSX.Element(<a />) && types.JSX.Fragment(<></>)
3989
+ * types.JSX.Element(<a />) && types.JSX.Fragment(<></>);
2985
3990
  * ```
2986
3991
  *
2987
3992
  * Failure to uphold this guarantee indicates a bug.
3993
+ *
3994
+ * For more info, including info on how to change how JSX is compiled, see
3995
+ * {@link JSX}.
2988
3996
  */
2989
3997
  export let pragmaFrag: string;
2990
3998
 
3999
+ /**
4000
+ * `JSX.Element` is a Symbol. The default implementation of
4001
+ * `JSX.createElement` creates objects whose `$$typeof` property is set to
4002
+ * `JSX.Element`, and type validator functions under the `types.JSX.*`
4003
+ * namespace look for this property in order to determine whether an object is
4004
+ * a JSX element, as created via `JSX.createElement` or JSX syntax.
4005
+ *
4006
+ * ```jsx
4007
+ * // This gets compiled internally by yavascript into:
4008
+ * // const a = JSX.createElement('a', null);
4009
+ * const a = <a />;
4010
+ *
4011
+ * console.log(a);
4012
+ * // {
4013
+ * // $$typeof: Symbol(JSX.Element)
4014
+ * // type: "a"
4015
+ * // props: null
4016
+ * // key: null
4017
+ * // }
4018
+ *
4019
+ * console.log(a.$$typeof === JSX.Element);
4020
+ * // true
4021
+ * ```
4022
+ *
4023
+ * There is also a TypeScript type called `JSX.Element` which is a type for
4024
+ * the JSX element objects as created by `JSX.createElement` or JSX syntax.
4025
+ *
4026
+ * If you modify properties on the JSX global such that the default
4027
+ * implementation of `JSX.createElement` is no longer used (eg. by replacing
4028
+ * it with `React.createElement`), this value may no longer be relevant.
4029
+ * However, the default JSX element object shape is designed to match
4030
+ * React/Preact/etc.
4031
+ *
4032
+ * For more info, including info on how to change how JSX is compiled, see
4033
+ * {@link JSX}.
4034
+ *
4035
+ */
2991
4036
  export const Element: unique symbol;
2992
4037
 
4038
+ /**
4039
+ * The TypeScript type for JSX Element objects created by the default
4040
+ * implementation of `JSX.createElement`.
4041
+ */
2993
4042
  export interface Element<
2994
4043
  Props = { [key: string | symbol | number]: any },
2995
4044
  Type = any
@@ -3001,26 +4050,69 @@ declare namespace JSX {
3001
4050
  }
3002
4051
 
3003
4052
  /**
3004
- * The value which gets passed into the JSX element constructor (as
3005
- * determined by {@link JSX.pragma}) when JSX fragment syntax is used (unless
3006
- * {@link JSX.pragmaFrag} is changed).
4053
+ *
4054
+ * `JSX.Fragment` is a Symbol which is used to indicate whether a JSX element
4055
+ * is a JSX fragment.
4056
+ *
4057
+ * ```jsx
4058
+ * // This gets compiled internally by yavascript into:
4059
+ * // const a = JSX.createElement(JSX.Fragment, null);
4060
+ * const frag = <></>;
4061
+ *
4062
+ * console.log(frag);
4063
+ * // {
4064
+ * // $$typeof: Symbol(JSX.Element)
4065
+ * // type: Symbol(JSX.Fragment)
4066
+ * // props: null
4067
+ * // key: null
4068
+ * // }
4069
+ *
4070
+ * console.log(a.type === JSX.Fragment);
4071
+ * // true
4072
+ * ```
4073
+ *
4074
+ * There is also a TypeScript type called `JSX.Fragment` which is a type for
4075
+ * the JSX fragment element objects as created by `JSX.createElement` or JSX
4076
+ * syntax.
4077
+ *
4078
+ * If you modify properties on the JSX global such that `JSX.Fragment` is no
4079
+ * longer used (eg. by replacing it with `React.Fragment`), this value may no
4080
+ * longer be relevant.
4081
+ *
4082
+ * For more info, including info on how to change how JSX is compiled, see
4083
+ * {@link JSX}.
3007
4084
  */
3008
4085
  export const Fragment: unique symbol;
3009
4086
 
4087
+ /**
4088
+ * The TypeScript type for JSX Element objects whose type is `JSX.Fragment`,
4089
+ * which is what yavascript creates internally when JSX fragment syntax
4090
+ * (`<></>`) is used.
4091
+ *
4092
+ * If you modify properties on the JSX global such that `JSX.Fragment` is no
4093
+ * longer used (eg. by replacing it with `React.Fragment`), this type may no
4094
+ * longer be relevant.
4095
+ */
3010
4096
  export type Fragment = Element<{}, typeof Fragment>;
3011
4097
 
3012
4098
  /**
3013
- * The JSX element builder function, which gets invoked whenever JSX syntax is
3014
- * used (unless {@link JSX.pragma} is changed).
4099
+ * The JSX element builder function, which gets invoked internally by
4100
+ * yavascript whenever JSX syntax is used (unless `JSX.pragma` gets changed by
4101
+ * the user).
3015
4102
  *
3016
4103
  * Note that if you change this, you need to verify that the following
3017
- * expression always evaluates to `true` (by changing {@link types.JSX.Element}
3018
- * and {@link types.JSX.Fragment}):
4104
+ * expression always evaluates to `true` (by changing `types.JSX.Element` and
4105
+ * `types.JSX.Fragment`):
4106
+ *
3019
4107
  * ```jsx
3020
- * types.JSX.Element(<a />) && types.JSX.Fragment(<></>)
4108
+ * types.JSX.Element(<a />) && types.JSX.Fragment(<></>);
3021
4109
  * ```
3022
4110
  *
3023
4111
  * Failure to uphold this guarantee indicates a bug.
4112
+ *
4113
+ * For more info, including info on how to change how JSX is compiled, see
4114
+ * {@link JSX}.
4115
+ *
3024
4116
  */
3025
4117
  export let createElement: {
3026
4118
  <Type extends string | typeof Fragment | ((...args: any) => any)>(
@@ -3054,9 +4146,14 @@ declare namespace JSX {
3054
4146
  };
3055
4147
  }
3056
4148
 
4149
+ /**
4150
+ * The `YAML` namespace contains functions which can serialize and deserialize
4151
+ * YAML documents, following the same pattern as JavaScript's `JSON` builtin.
4152
+ */
3057
4153
  declare const YAML: {
3058
4154
  /**
3059
- * Parse a YAML document (`input`) into a JSON-compatible value.
4155
+ * Converts a YAML document string into a JavaScript value. It works the same
4156
+ * way that `JSON.parse` does, but for YAML.
3060
4157
  */
3061
4158
  parse(
3062
4159
  input: string,
@@ -3064,7 +4161,8 @@ declare const YAML: {
3064
4161
  ): any;
3065
4162
 
3066
4163
  /**
3067
- * Convert a JSON-compatible value into a YAML document.
4164
+ * Converts a JavaScript value into a YAML document string. It works the same
4165
+ * way that `JSON.stringify` does, but for YAML.
3068
4166
  */
3069
4167
  stringify(
3070
4168
  input: any,
@@ -3076,6 +4174,18 @@ declare const YAML: {
3076
4174
  ): string;
3077
4175
  };
3078
4176
 
4177
+ /**
4178
+ * Serializes or deserializes CSV data.
4179
+ *
4180
+ * The `CSV` object contains a `parse` function and a `stringify` function which
4181
+ * can be used to parse strings of CSV (comma-separated values) data into
4182
+ * arrays-of-arrays-of-strings and serialize arrays-of-arrays-of-strings into
4183
+ * strings of CSV data.
4184
+ *
4185
+ * Its interface is similar to `JSON.parse` and `JSON.stringify`, but CSV does
4186
+ * not support the spacing/replacer/reviver options that `JSON.parse` and
4187
+ * `JSON.stringify` have.
4188
+ */
3079
4189
  declare const CSV: {
3080
4190
  /**
3081
4191
  * Parse a CSV string into an Array of Arrays of strings.
@@ -3094,9 +4204,18 @@ declare const CSV: {
3094
4204
  stringify(input: Array<Array<string>>): string;
3095
4205
  };
3096
4206
 
4207
+ /**
4208
+ * An object with a `parse` function and a `stringify` function which can be
4209
+ * used to parse TOML document strings into objects and serialize objects into
4210
+ * TOML document strings.
4211
+ *
4212
+ * Its interface is similar to `JSON.parse` and `JSON.stringify`, but
4213
+ * `TOML.parse` and `TOML.stringify` do not support the spacing/replacer/reviver
4214
+ * options that `JSON.parse` and `JSON.stringify` do.
4215
+ */
3097
4216
  declare var TOML: {
3098
4217
  /**
3099
- * Parse a TOML document (`data`) into an object.
4218
+ * Parse a TOML document string (`data`) into an object.
3100
4219
  */
3101
4220
  parse(data: string): { [key: string]: any };
3102
4221
  /**
@@ -3106,31 +4225,43 @@ declare var TOML: {
3106
4225
  };
3107
4226
 
3108
4227
  interface RegExpConstructor {
3109
- /** See https://github.com/tc39/proposal-regex-escaping */
4228
+ /**
4229
+ * The function `RegExp.escape` accepts an input string and prefixes with `\`
4230
+ * those characters in that string which have a special meaning when appearing
4231
+ * in a regular expression.
4232
+ *
4233
+ * The implementation is based on the stage 2 ECMAScript proposal of the same
4234
+ * name: https://github.com/tc39/proposal-regex-escaping
4235
+ */
3110
4236
  escape(str: any): string;
3111
4237
  }
3112
4238
 
3113
4239
  interface StringConstructor {
3114
4240
  /**
3115
- * Remove leading minimum indentation from the string.
3116
- * The first line of the string must be empty.
4241
+ * The function `String.dedent` can be used to remove leading indentation from
4242
+ * a string. It is commonly used as a tagged template function, but you can
4243
+ * also call it and pass in a string.
3117
4244
  *
3118
- * https://github.com/tc39/proposal-string-dedent
4245
+ * Note that the first line of the string must be empty.
4246
+ *
4247
+ * `String.dedent` is the default export from the npm package `string-dedent`.
4248
+ * See its readme on npm for more info:
4249
+ * https://www.npmjs.com/package/string-dedent
3119
4250
  */
3120
4251
  dedent: {
3121
4252
  /**
3122
- * Remove leading minimum indentation from the string.
3123
- * The first line of the string must be empty.
4253
+ * Removes leading minimum indentation from the string `input`.
4254
+ * The first line of `input` MUST be empty.
3124
4255
  *
3125
- * https://github.com/tc39/proposal-string-dedent
4256
+ * For more info, see: https://www.npmjs.com/package/string-dedent#usage
3126
4257
  */
3127
4258
  (input: string): string;
3128
4259
 
3129
4260
  /**
3130
- * Remove leading minimum indentation from the template literal.
3131
- * The first line of the string must be empty.
4261
+ * Removes leading minimum indentation from the tagged template literal.
4262
+ * The first line of the template literal MUST be empty.
3132
4263
  *
3133
- * https://github.com/tc39/proposal-string-dedent
4264
+ * For more info, see: https://www.npmjs.com/package/string-dedent#usage
3134
4265
  */
3135
4266
  (
3136
4267
  strings: readonly string[] | ArrayLike<string>,
@@ -3141,7 +4272,7 @@ interface StringConstructor {
3141
4272
  * Wrap another template tag function such that tagged literals
3142
4273
  * become dedented before being passed to the wrapped function.
3143
4274
  *
3144
- * https://www.npmjs.com/package/string-dedent#usage
4275
+ * For more info, see: https://www.npmjs.com/package/string-dedent#usage
3145
4276
  */
3146
4277
  <
3147
4278
  Func extends (
@@ -3154,6 +4285,24 @@ interface StringConstructor {
3154
4285
  };
3155
4286
  }
3156
4287
 
4288
+ /**
4289
+ * Opens the resource at the given path or URL using the operating system's
4290
+ * default application or handler.
4291
+ *
4292
+ * Examples:
4293
+ *
4294
+ * ```ts
4295
+ * openUrl("/home/me/stuff/code.txt"); // opens code.txt in your default text editor
4296
+ * openUrl("code.txt"); // same as above, using relative path
4297
+ * openUrl("file:///home/me/stuff/code.txt"); // same as above, using file:// url
4298
+ *
4299
+ * openUrl("IMG_001.jpg"); // opens IMG_001.jpg in your default image viewer
4300
+ *
4301
+ * openUrl("https://example.com/") // opens example.com in your default web browser
4302
+ * ```
4303
+ */
4304
+ declare function openUrl(urlOrFilePath: string | Path): void;
4305
+
3157
4306
  // prettier-ignore
3158
4307
  /** Any integer in the range [0, 255]. */
3159
4308
  declare type byte =
@@ -3206,6 +4355,53 @@ interface ErrorOptions {
3206
4355
  [key: string]: any;
3207
4356
  }
3208
4357
 
4358
+ /**
4359
+ * For compatibility with Node.js scripts, the global object is accessible via
4360
+ * the global variable named "global".
4361
+ */
4362
+ declare var global: typeof globalThis;
4363
+
4364
+ /**
4365
+ * A `process` global is provided for rudimentary compatibility with Node.js
4366
+ * scripts. It contains a subset of the properties found on the Node.js
4367
+ * `process` global, which each forward to their corresponding yavascript API.
4368
+ *
4369
+ * For instance, `process.env` is a getter that returns {@link env}, and
4370
+ * `process.argv` is a getter that returns {@link scriptArgs}.
4371
+ *
4372
+ * If you are writing yavascript-specific code, you should use yavascript's APIs
4373
+ * instead of `process`.
4374
+ */
4375
+ declare var process: {
4376
+ version: string;
4377
+ versions: {
4378
+ node: string;
4379
+ yavascript: string;
4380
+ unicode: string;
4381
+ };
4382
+ arch: string;
4383
+ /** Same as the global {@link env}. */
4384
+ readonly env: { [key: string]: string | undefined };
4385
+ /** Same as the global {@link scriptArgs}. */
4386
+ readonly argv: Array<string>;
4387
+ /** Same as `scriptArgs[0]`. */
4388
+ readonly argv0: string;
4389
+ /**
4390
+ * Shortcut for `os.realpath(os.execPath())`, using the QuickJS {@link os}
4391
+ * module.
4392
+ */
4393
+ readonly execPath: string;
4394
+ /**
4395
+ * Uses `std.getExitCode()` and `std.setExitCode()` from the QuickJS
4396
+ * {@link std} module.
4397
+ */
4398
+ exitCode: number;
4399
+ /**
4400
+ * Uses `std.exit()` from the QuickJS {@link std} module.
4401
+ */
4402
+ exit(code?: number | null | undefined): void;
4403
+ };
4404
+
3209
4405
  // ==========================================
3210
4406
  // ------------------------------------------
3211
4407
  // QuickJS APIs, which YavaScript builds upon
@@ -4083,33 +5279,6 @@ interface BigDecimal {
4083
5279
  // TypeScript will not understand or handle unary/binary operators for BigFloat
4084
5280
  // and BigDecimal properly.
4085
5281
 
4086
- /**
4087
- * Print the arguments separated by spaces and a trailing newline.
4088
- *
4089
- * Non-string args are coerced into a string via [ToString](https://tc39.es/ecma262/#sec-tostring).
4090
- * Objects can override the default `ToString` behavior by defining a `toString` method.
4091
- */
4092
- declare var print: (...args: Array<any>) => void;
4093
-
4094
- /**
4095
- * Object that provides functions for logging information.
4096
- */
4097
- interface Console {
4098
- /** Same as {@link print}(). */
4099
- log: typeof print;
4100
-
4101
- /** Same as {@link print}(). */
4102
- warn: typeof print;
4103
-
4104
- /** Same as {@link print}(). */
4105
- error: typeof print;
4106
-
4107
- /** Same as {@link print}(). */
4108
- info: typeof print;
4109
- }
4110
-
4111
- declare var console: Console;
4112
-
4113
5282
  /** npm: @suchipi/print@2.5.0. License: ISC */
4114
5283
  /* (with some QuickJS-specific modifications) */
4115
5284
 
@@ -4550,6 +5719,27 @@ declare module "quickjs:std" {
4550
5719
  */
4551
5720
  export function getegid(): number;
4552
5721
 
5722
+ /** The type of the object returned by {@link getpwuid}. */
5723
+ export interface PasswdEntry {
5724
+ name: string;
5725
+ passwd: string;
5726
+ uid: number;
5727
+ gid: number;
5728
+ gecos: string;
5729
+ dir: string;
5730
+ shell: string;
5731
+ }
5732
+
5733
+ /**
5734
+ * Get information from the passwd file entry for the specified user id.
5735
+ *
5736
+ * See https://linux.die.net/man/3/getpwuid.
5737
+ *
5738
+ * This function throws an error on windows, because windows doesn't support
5739
+ * the same uid/gid paradigm as Unix-like operating systems.
5740
+ */
5741
+ export function getpwuid(id: number): PasswdEntry;
5742
+
4553
5743
  interface UrlGet {
4554
5744
  /**
4555
5745
  * Download `url` using the `curl` command line utility. Returns string
@@ -5335,6 +6525,15 @@ interface ModuleDelegate {
5335
6525
  [extensionWithDot: string]: (filename: string, content: string) => string;
5336
6526
  };
5337
6527
 
6528
+ /**
6529
+ * An Array containing the names of all the built-in modules, such as
6530
+ * "quickjs:std", "quickjs:bytecode", etc.
6531
+ *
6532
+ * `quickjs:engine`'s `defineBuiltinModule` function adds to the end of this
6533
+ * array.
6534
+ */
6535
+ builtinModuleNames: Array<string>;
6536
+
5338
6537
  /**
5339
6538
  * Resolves a require/import request from `fromFile` into a canonicalized
5340
6539
  * path.