yavascript 0.0.8 → 0.0.9

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
@@ -3,6 +3,44 @@
3
3
  // YavaScript APIs
4
4
  // ---------------
5
5
  // ===============
6
+ /**
7
+ * Prints help and usage text about the provided value, if any is available.
8
+ */
9
+ declare var help: {
10
+ /**
11
+ * Prints help and usage text about the provided value, if any is available.
12
+ */
13
+ (value?: any): void;
14
+
15
+ /**
16
+ * Set the help text for the provided value to the provided string.
17
+ *
18
+ * If the value is later passed into the `help` function, the provided text
19
+ * will be printed.
20
+ */
21
+ setHelpText: {
22
+ /**
23
+ * Set the help text for the provided value to the provided string.
24
+ *
25
+ * If the value is later passed into the `help` function, the provided text
26
+ * will be printed.
27
+ */
28
+ (value: object, text: string): void;
29
+
30
+ /**
31
+ * Lazily sets the help text for the provided value using the provided
32
+ * string-returning function.
33
+ *
34
+ * The first time help text is requested for the value, the string-returning
35
+ * function will be called, and its result will be registered as the help
36
+ * text for the value. Afterwards, the function will not be called again;
37
+ * instead, it will re-use the text returned from the first time the
38
+ * function was called.
39
+ */
40
+ lazy(value: object, getText: () => string): void;
41
+ };
42
+ };
43
+
6
44
  /** Info about the currently-running yavascript binary */
7
45
  declare const yavascript: {
8
46
  /**
@@ -99,63 +137,19 @@ declare const env: { [key: string]: string | undefined };
99
137
  * Flags where you specify them multiple times, like `-vvv`, are not supported.
100
138
  * Write something like `-v 3` instead.
101
139
  *
102
- * @param hints - An object whose keys are flag names (in camelCase) and whose values indicate what type to treat that flag as. Valid property values are `String`, `Boolean`, `Number`, and `parseScriptArgs.Path`. `parseScriptArgs.Path` will resolve relative paths into absolute paths for you. If no hints object is specified, `parseScriptArgs` will do its best to guess, based on the command-line args.
140
+ * @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.
103
141
  * @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.
104
142
  *
105
143
  * @returns An object with two properties: `flags` and `args`. `flags` is an object whose keys are camelCase flag names and whose values are strings, booleans, or numbers corresponding to the input command-line args. `args` is an Array of positional arguments, as found on the command-line.
106
144
  */
107
- declare const parseScriptArgs: {
108
- /**
109
- * Parse command line --flags into an object of flags and an array of
110
- * positional arguments. This function is opinionated; if it doesn't meet your
111
- * needs, you can parse the `scriptArgs` global manually.
112
- *
113
- * Flags `--like-this`, `--like_this`, or `--LIKE_THIS` get converted into
114
- * property names `likeThis` on the returned flags object.
115
- *
116
- * Flags like this: `-v` get converted into into property names like this: `v`
117
- * on the returned flags object.
118
- *
119
- * Anything that appears after `--` is considered a positional argument instead
120
- * of a flag. `--` is not present in the returned positional arguments Array.
121
- *
122
- * Single-character flags must have a single leading dash, and multi-character
123
- * flags must have two leading dashes.
124
- *
125
- * Flags with equals signs in them (eg. `--something=42`) are not supported.
126
- * Write `--something 42` instead.
127
- *
128
- * Flags where you specify them multiple times, like `-vvv`, are not supported.
129
- * Write something like `-v 3` instead.
130
- *
131
- * @param hints - An object whose keys are flag names (in camelCase) and whose values indicate what type to treat that flag as. Valid property values are `String`, `Boolean`, `Number`, and `parseScriptArgs.Path`. `parseScriptArgs.Path` will resolve relative paths into absolute paths for you. If no hints object is specified, `parseScriptArgs` will do its best to guess, based on the command-line args.
132
- * @param args - An array containing the command line flags you want to parse. If unspecified, `scriptArgs.slice(2)` will be used (we slice 2 in order to skip the yavascript binary and script name). If you pass in an array here, it should only contain command-line flags, not the binary being called.
133
- *
134
- * @returns An object with two properties: `flags` and `args`. `flags` is an object whose keys are camelCase flag names and whose values are strings, booleans, or numbers corresponding to the input command-line args. `args` is an Array of positional arguments, as found on the command-line.
135
- */
136
- (
137
- hints?: {
138
- [key: string]:
139
- | typeof String
140
- | typeof Boolean
141
- | typeof Number
142
- | typeof parseScriptArgs["Path"];
143
- },
144
- args?: Array<string>
145
- ): {
146
- flags: { [key: string]: any };
147
- args: Array<string>;
148
- };
149
-
150
- /**
151
- * A hint value for {@link parseScriptArgs}. Behaves similar to the hint value
152
- * `String`, except that it also resolves relative paths into absolute paths,
153
- * using the following rules:
154
- *
155
- * - paths `./like/this` or `../like/this` get resolved relative to `pwd()`.
156
- * - paths `like/this` or `this` get resolved relative to `pwd()` as if they had a leading `./`.
157
- */
158
- readonly Path: unique symbol;
145
+ declare function parseScriptArgs(
146
+ hints?: {
147
+ [key: string]: typeof String | typeof Boolean | typeof Number | typeof Path;
148
+ },
149
+ args?: Array<string>
150
+ ): {
151
+ flags: { [key: string]: any };
152
+ args: Array<string>;
159
153
  };
160
154
 
161
155
  /**
@@ -165,22 +159,22 @@ declare const readFile: {
165
159
  /**
166
160
  * Read the contents of a file from disk, as a UTF-8 string.
167
161
  */
168
- (path: string): string;
162
+ (path: string | Path): string;
169
163
 
170
164
  /**
171
165
  * Read the contents of a file from disk, as a UTF-8 string.
172
166
  */
173
- (path: string, options: {}): string;
167
+ (path: string | Path, options: {}): string;
174
168
 
175
169
  /**
176
170
  * Read the contents of a file from disk, as a UTF-8 string.
177
171
  */
178
- (path: string, options: { binary: false }): string;
172
+ (path: string | Path, options: { binary: false }): string;
179
173
 
180
174
  /**
181
175
  * Read the contents of a file from disk, as an ArrayBuffer.
182
176
  */
183
- (path: string, options: { binary: true }): ArrayBuffer;
177
+ (path: string | Path, options: { binary: true }): ArrayBuffer;
184
178
  };
185
179
 
186
180
  /**
@@ -188,37 +182,22 @@ declare const readFile: {
188
182
  *
189
183
  * Strings are written using the UTF-8 encoding.
190
184
  */
191
- declare function writeFile(path: string, data: string | ArrayBuffer): void;
192
-
193
- /**
194
- * Function which returns true if the path points to a directory, or if the
195
- * path points to a symlink which points to a directory. Otherwise, it returns
196
- * false.
197
- */
198
- interface IsDir {
199
- /**
200
- * Returns true if the path points to a directory, or if the path points to
201
- * a symlink which points to a directory. Otherwise, returns false.
202
- */
203
- (path: string): boolean;
204
-
205
- /**
206
- * Maximum number of symlinks to follow before erroring. Defaults to 100.
207
- */
208
- symlinkLimit: number;
209
- }
185
+ declare function writeFile(
186
+ path: string | Path,
187
+ data: string | ArrayBuffer
188
+ ): void;
210
189
 
211
190
  /**
212
191
  * Function which returns true if the path points to a directory, or if the
213
192
  * path points to a symlink which points to a directory. Otherwise, it returns
214
193
  * false.
215
194
  */
216
- declare const isDir: IsDir;
195
+ declare function isDir(path: string | Path): boolean;
217
196
 
218
197
  /**
219
198
  * Returns true if the path points to a symlink.
220
199
  */
221
- declare function isLink(path: string): boolean;
200
+ declare function isLink(path: string | Path): boolean;
222
201
 
223
202
  /**
224
203
  * Delete the file or directory at the specified path.
@@ -227,22 +206,22 @@ declare function isLink(path: string): boolean;
227
206
  *
228
207
  * Provides the same functionality as the command `rm -rf`.
229
208
  */
230
- declare function remove(path: string): void;
209
+ declare function remove(path: string | Path): void;
231
210
 
232
211
  /**
233
212
  * Returns true if a file or directory exists at the specified path.
234
213
  *
235
214
  * Provides the same functionality as the command `test -e`.
236
215
  */
237
- declare function exists(path: string): boolean;
216
+ declare function exists(path: string | Path): boolean;
238
217
 
239
218
  /**
240
- * Create directories for each of the provided path components,
219
+ * Creates directories for each of the provided path components,
241
220
  * if they don't already exist.
242
221
  *
243
222
  * Provides the same functionality as the command `mkdir -p`.
244
223
  */
245
- declare function ensureDir(path: string): string;
224
+ declare function ensureDir(path: string | Path): string;
246
225
 
247
226
  /**
248
227
  * Options for {@link copy}.
@@ -270,12 +249,23 @@ declare type CopyOptions = {
270
249
  };
271
250
 
272
251
  /**
273
- * Copy a file or folder from one location to another.
252
+ * Copies a file or folder from one location to another.
274
253
  * Folders are copied recursively.
275
254
  *
276
255
  * Provides the same functionality as the command `cp -R`.
277
256
  */
278
- declare function copy(from: string, to: string, options?: CopyOptions): void;
257
+ declare function copy(
258
+ from: string | Path,
259
+ to: string | Path,
260
+ options?: CopyOptions
261
+ ): void;
262
+
263
+ /**
264
+ * Rename the file or directory at the specified path.
265
+ *
266
+ * Provides the same functionality as the command `mv`.
267
+ */
268
+ declare function rename(from: string | Path, to: string | Path): void;
279
269
 
280
270
  /** An object that represents a filesystem path. */
281
271
  declare class Path {
@@ -323,10 +313,10 @@ declare class Path {
323
313
  ): string;
324
314
 
325
315
  /**
326
- * Return whether the provided path string is absolute; that is, whether it
316
+ * Return whether the provided path is absolute; that is, whether it
327
317
  * starts with either `/` or a drive letter (ie `C:`).
328
318
  */
329
- static isAbsolute(path: string): boolean;
319
+ static isAbsolute(path: string | Path): boolean;
330
320
 
331
321
  /** A tagged template literal function that creates a `Path` object. */
332
322
  static tag(
@@ -390,25 +380,52 @@ declare class Path {
390
380
  */
391
381
  isAbsolute(): boolean;
392
382
 
383
+ /**
384
+ * Make a second Path object containing the same information as this one.
385
+ */
386
+ clone(): this;
387
+
388
+ /**
389
+ * Express this path relative to `dir`.
390
+ *
391
+ * @param dir - The directory to create a new path relative to.
392
+ * @param options - Options that affect the resulting path.
393
+ */
394
+ relativeTo(
395
+ dir: Path | string,
396
+ options?: {
397
+ /**
398
+ * Defaults to false. When true, a leading `./` will be omitted from the
399
+ * path, if present. Note that a leading `../` will never be omitted.
400
+ */
401
+ noLeadingDot?: boolean;
402
+ }
403
+ ): Path;
404
+
393
405
  /**
394
406
  * Turn this path into a string by joining its segments using its separator.
395
407
  */
396
408
  toString(): string;
409
+
410
+ /**
411
+ * Alias for `toString`; causes Path objects to be serialized as strings.
412
+ */
413
+ toJSON(): string;
397
414
  }
398
415
 
399
416
  /**
400
417
  * The absolute path to the current file (whether script or module).
401
418
  *
402
- * Behaves the same as in Node.js, except that it's present within ES modules.
419
+ * Behaves the same as in Node.js, except that it's also present within ES modules.
403
420
  */
404
- declare const __filename: string;
421
+ declare var __filename: string;
405
422
 
406
423
  /**
407
424
  * The absolute path to the directory the current file is inside of.
408
425
  *
409
- * Behaves the same as in Node.js, except that it's present within ES modules.
426
+ * Behaves the same as in Node.js, except that it's also present within ES modules.
410
427
  */
411
- declare const __dirname: string;
428
+ declare var __dirname: string;
412
429
 
413
430
  /**
414
431
  * Return the last component of a path string.
@@ -500,7 +517,7 @@ declare function extname(
500
517
  ): string;
501
518
 
502
519
  /**
503
- * Return the contents of a directory, as absolute paths. `.` and `..` are
520
+ * Returns the contents of a directory, as absolute paths. `.` and `..` are
504
521
  * omitted.
505
522
  *
506
523
  * Use the `relativePaths` option to get relative paths instead (relative to
@@ -513,18 +530,22 @@ declare function ls(
513
530
 
514
531
  /**
515
532
  * Print data to stdout using C-style format specifiers.
533
+ *
534
+ * The same formats as the standard C library printf are supported. Integer
535
+ * format types (e.g. `%d`) truncate the Numbers or BigInts to 32 bits. Use the l
536
+ * modifier (e.g. `%ld`) to truncate to 64 bits.
516
537
  */
517
538
  declare function printf(format: string, ...args: Array<any>): void;
518
539
 
519
540
  /**
520
- * Return the process's current working directory.
541
+ * Returns the process's current working directory.
521
542
  *
522
543
  * Provides the same functionality as the shell builtin of the same name.
523
544
  */
524
545
  declare function pwd(): string;
525
546
 
526
547
  /**
527
- * Read a symlink.
548
+ * Reads a symlink.
528
549
  *
529
550
  * Returns the target of the symlink, which may be absolute or relative.
530
551
  *
@@ -552,7 +573,7 @@ declare function touch(path: string | Path): void;
552
573
 
553
574
  declare type BaseExecOptions = {
554
575
  /** Sets the current working directory for the child process. */
555
- cwd?: string;
576
+ cwd?: string | Path;
556
577
 
557
578
  /** Sets environment variables within the process. */
558
579
  env?: { [key: string | number]: string | number | boolean };
@@ -567,12 +588,26 @@ declare type BaseExecOptions = {
567
588
  * ```
568
589
  */
569
590
  trace?: (...args: Array<any>) => void;
591
+
592
+ /**
593
+ * Whether an Error should be thrown when the process exits with a nonzero
594
+ * status code.
595
+ *
596
+ * Defaults to true.
597
+ */
598
+ failOnNonZeroStatus?: boolean;
599
+
600
+ /**
601
+ * If true, stdout and stderr will be collected into strings and returned
602
+ * instead of being printed to the screen.
603
+ *
604
+ * Defaults to false.
605
+ */
606
+ captureOutput?: boolean;
570
607
  };
571
608
 
572
609
  declare interface Exec {
573
- (args: Array<string> | string): void;
574
-
575
- (args: Array<string> | string, options: Record<string, never>): void;
610
+ (args: Array<string> | string, options?: BaseExecOptions): void;
576
611
 
577
612
  (
578
613
  args: Array<string> | string,
@@ -616,6 +651,19 @@ declare interface Exec {
616
651
  | { status: number; signal: undefined }
617
652
  | { status: undefined; signal: number };
618
653
 
654
+ (
655
+ args: Array<string> | string,
656
+ options: BaseExecOptions & {
657
+ /**
658
+ * Whether an Error should be thrown when the process exits with a nonzero
659
+ * status code.
660
+ *
661
+ * Defaults to true.
662
+ */
663
+ failOnNonZeroStatus: true;
664
+ }
665
+ ): void;
666
+
619
667
  (
620
668
  args: Array<string> | string,
621
669
  options: BaseExecOptions & {
@@ -664,6 +712,19 @@ declare interface Exec {
664
712
  }
665
713
  ): { stdout: string; stderr: string };
666
714
 
715
+ (
716
+ args: Array<string> | string,
717
+ options: BaseExecOptions & {
718
+ /**
719
+ * If true, stdout and stderr will be collected into strings and returned
720
+ * instead of being printed to the screen.
721
+ *
722
+ * Defaults to false.
723
+ */
724
+ captureOutput: false;
725
+ }
726
+ ): void;
727
+
667
728
  (
668
729
  args: Array<string> | string,
669
730
  options: BaseExecOptions & {
@@ -681,7 +742,7 @@ declare interface Exec {
681
742
  | { stdout: string; stderr: string; status: undefined; signal: number };
682
743
  }
683
744
 
684
- /** Run a child process using the provided arguments. The first value in the arguments array is the program to run. */
745
+ /** Runs a child process using the provided arguments. The first value in the arguments array is the program to run. */
685
746
  declare const exec: Exec;
686
747
 
687
748
  /** Alias for `exec(args, { captureOutput: true })` */
@@ -690,6 +751,100 @@ declare function $(args: Array<string> | string): {
690
751
  stderr: string;
691
752
  };
692
753
 
754
+ /** A class which represents a child process. The process may or may not be running. */
755
+ declare interface ChildProcess {
756
+ /**
757
+ * The argv for the process. The first entry in this array is the program to
758
+ * run.
759
+ */
760
+ args: Array<string>;
761
+
762
+ /** The current working directory for the process. */
763
+ cwd: string;
764
+
765
+ /** The environment variables for the process. */
766
+ env: { [key: string]: string };
767
+
768
+ /**
769
+ * The standard I/O streams for the process. Generally these are the same as
770
+ * `std.in`, `std.out`, and `std.err`, but they can be customized to write
771
+ * output elsewhere.
772
+ */
773
+ stdio: {
774
+ /** Where the process reads stdin from */
775
+ in: FILE;
776
+ /** Where the process writes stdout to */
777
+ out: FILE;
778
+ /** Where the process writes stderr to */
779
+ err: FILE;
780
+ };
781
+
782
+ /**
783
+ * Optional trace function which, if present, will be called at various times
784
+ * to provide information about the lifecycle of the process.
785
+ */
786
+ trace?: (...args: Array<any>) => void;
787
+
788
+ pid: number | null;
789
+
790
+ /** Spawns the process and returns its pid (process id). */
791
+ start(): number;
792
+
793
+ /** Blocks the calling thread until the process exits or is killed. */
794
+ waitUntilComplete():
795
+ | { status: number; signal: undefined }
796
+ | { status: undefined; signal: number };
797
+ }
798
+
799
+ /**
800
+ * Options to be passed to the ChildProcess constructor. Their purposes and
801
+ * types match the same-named properties found on the resulting ChildProcess.
802
+ */
803
+ declare type ChildProcessOptions = {
804
+ /** The current working directory for the process. */
805
+ cwd?: string;
806
+
807
+ /** The environment variables for the process. */
808
+ env?: { [key: string]: string };
809
+
810
+ /**
811
+ * The standard I/O streams for the process. Generally these are the same as
812
+ * `std.in`, `std.out`, and `std.err`, but they can be customized to write
813
+ * output elsewhere.
814
+ */
815
+ stdio?: {
816
+ /** Where the process reads stdin from */
817
+ in?: FILE;
818
+ /** Where the process writes stdout to */
819
+ out?: FILE;
820
+ /** Where the process writes stderr to */
821
+ err?: FILE;
822
+ };
823
+
824
+ /**
825
+ * Optional trace function which, if present, will be called at various times
826
+ * to provide information about the lifecycle of the process.
827
+ */
828
+ trace?: (...args: Array<any>) => void;
829
+ };
830
+
831
+ declare interface ChildProcessConstructor {
832
+ /**
833
+ * Construct a new ChildProcess.
834
+ *
835
+ * @param args - The argv for the process. The first entry in this array is the program to run.
836
+ * @param options - Options for the process (cwd, env, stdio, etc)
837
+ */
838
+ new (
839
+ args: string | Array<string>,
840
+ options?: ChildProcessOptions
841
+ ): ChildProcess;
842
+
843
+ readonly prototype: ChildProcess;
844
+ }
845
+
846
+ declare var ChildProcess: ChildProcessConstructor;
847
+
693
848
  /**
694
849
  * Options for {@link glob}.
695
850
  */
@@ -717,7 +872,7 @@ declare type GlobOptions = {
717
872
  /**
718
873
  * Directory to interpret glob patterns relative to. Defaults to `pwd()`.
719
874
  */
720
- dir?: string;
875
+ dir?: string | Path;
721
876
  };
722
877
 
723
878
  /**
@@ -729,7 +884,17 @@ declare type GlobOptions = {
729
884
  declare function glob(
730
885
  patterns: string | Array<string>,
731
886
  options?: GlobOptions
732
- ): Array<string>;
887
+ ): Array<Path>;
888
+
889
+ /**
890
+ * Clear the contents and scrollback buffer of the tty by printing special characters into stdout.
891
+ */
892
+ declare function clear(): void;
893
+
894
+ interface Console {
895
+ /** Same as {@link clear}(). */
896
+ clear: typeof clear;
897
+ }
733
898
 
734
899
  /**
735
900
  * Remove ANSI control characters from a string.
@@ -741,11 +906,6 @@ declare function stripAnsi(input: string): string;
741
906
  */
742
907
  declare function quote(input: string): string;
743
908
 
744
- /**
745
- * Clear the contents and scrollback buffer of the tty by printing special characters into stdout.
746
- */
747
- declare function clear(): void;
748
-
749
909
  // Colors
750
910
 
751
911
  /** Wrap a string with the ANSI control characters that will make it print as black text. */
@@ -872,45 +1032,49 @@ declare const grepString: {
872
1032
  /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
873
1033
  declare const grepFile: {
874
1034
  /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
875
- (path: string, pattern: string | RegExp): Array<string>;
1035
+ (path: string | Path, pattern: string | RegExp): Array<string>;
876
1036
 
877
1037
  /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
878
1038
  (
879
- path: string,
1039
+ path: string | Path,
880
1040
  pattern: string | RegExp,
881
1041
  options: { inverse: false }
882
1042
  ): Array<string>;
883
1043
 
884
1044
  /** Read the content at `path`, split it on newline, and then return lines NOT matching `pattern`. */
885
1045
  (
886
- path: string,
1046
+ path: string | Path,
887
1047
  pattern: string | RegExp,
888
1048
  options: { inverse: true }
889
1049
  ): Array<string>;
890
1050
 
891
1051
  /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
892
1052
  (
893
- path: string,
1053
+ path: string | Path,
894
1054
  pattern: string | RegExp,
895
1055
  options: { details: false }
896
1056
  ): Array<string>;
897
1057
 
898
1058
  /** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
899
1059
  (
900
- path: string,
1060
+ path: string | Path,
901
1061
  pattern: string | RegExp,
902
1062
  options: { inverse: false; details: false }
903
1063
  ): Array<string>;
904
1064
 
905
1065
  /** Read the content at `path`, split it on newline, and then return lines NOT matching `pattern`. */
906
1066
  (
907
- path: string,
1067
+ path: string | Path,
908
1068
  pattern: string | RegExp,
909
1069
  options: { inverse: true; details: false }
910
1070
  ): Array<string>;
911
1071
 
912
1072
  /** Read the content at `path`, split it on newline, and then return info about lines matching `pattern`. */
913
- (path: string, pattern: string | RegExp, options: { details: true }): Array<{
1073
+ (
1074
+ path: string | Path,
1075
+ pattern: string | RegExp,
1076
+ options: { details: true }
1077
+ ): Array<{
914
1078
  lineNumber: number;
915
1079
  lineContent: string;
916
1080
  matches: RegExpMatchArray;
@@ -918,14 +1082,14 @@ declare const grepFile: {
918
1082
 
919
1083
  /** Read the content at `path`, split it on newline, and then return info about lines matching `pattern`. */
920
1084
  (
921
- path: string,
1085
+ path: string | Path,
922
1086
  pattern: string | RegExp,
923
1087
  options: { inverse: false; details: true }
924
1088
  ): Array<string>;
925
1089
 
926
1090
  /** Read the content at `path`, split it on newline, and then return info about lines NOT matching `pattern`. */
927
1091
  (
928
- path: string,
1092
+ path: string | Path,
929
1093
  pattern: string | RegExp,
930
1094
  options: { inverse: true; details: true }
931
1095
  ): Array<string>;
@@ -2365,7 +2529,7 @@ declare const assert: {
2365
2529
  * - Use `maxLength` to limit how much data to read.
2366
2530
  * - Use `until` to stop reading once a certain byte or character has been
2367
2531
  * read.
2368
- * - Use `path` or `fd` to open a file.
2532
+ * - Use `path` or `fd` to open a file (or pass a FILE or Path object).
2369
2533
  */
2370
2534
  declare type PipeSource =
2371
2535
  | { data: string; maxLength?: number; until?: string | byte }
@@ -2378,12 +2542,9 @@ declare type PipeSource =
2378
2542
  | DataView
2379
2543
  | { data: DataView; maxLength?: number; until?: string | byte }
2380
2544
  | FILE
2381
- | {
2382
- data: FILE;
2383
- maxLength?: number;
2384
- until?: string | byte;
2385
- }
2386
- | { path: string; maxLength?: number; until?: string | byte }
2545
+ | { data: FILE; maxLength?: number; until?: string | byte }
2546
+ | Path
2547
+ | { path: Path | string; maxLength?: number; until?: string | byte }
2387
2548
  | { fd: number; maxLength?: number; until?: string | byte };
2388
2549
 
2389
2550
  /**
@@ -2399,6 +2560,7 @@ declare type PipeDestination =
2399
2560
  | SharedArrayBuffer
2400
2561
  | DataView
2401
2562
  | TypedArray
2563
+ | Path
2402
2564
  | FILE
2403
2565
  | ArrayBufferConstructor
2404
2566
  | SharedArrayBufferConstructor
@@ -2437,39 +2599,133 @@ declare function pipe<Dest extends PipeDestination>(
2437
2599
  : never;
2438
2600
  };
2439
2601
 
2602
+ interface InteractivePrompt {
2603
+ prompt?: () => string;
2604
+ printInput?: (input: string) => void;
2605
+ historyFileName?: string;
2606
+ getCompletions?: (
2607
+ line: string,
2608
+ pos: number
2609
+ ) => {
2610
+ // TODO refactor these to have better key names
2611
+ tab: Array<string>;
2612
+ pos: number;
2613
+ ctx: { [key: string | number | symbol]: any };
2614
+ };
2615
+
2616
+ handleInput: (input: string) => void;
2617
+ start(): void;
2618
+ }
2619
+
2620
+ interface InteractivePromptConstructor {
2621
+ new (
2622
+ handleInput: (input: string) => void,
2623
+ options?: {
2624
+ prompt?: () => string;
2625
+ printInput?: (input: string) => void;
2626
+ historyFileName?: string;
2627
+ getCompletions?: (
2628
+ line: string,
2629
+ pos: number
2630
+ ) => {
2631
+ // TODO refactor these to have better key names
2632
+ tab: Array<string>;
2633
+ pos: number;
2634
+ ctx: { [key: string | number | symbol]: any };
2635
+ };
2636
+ }
2637
+ ): InteractivePrompt;
2638
+
2639
+ prototype: InteractivePrompt;
2640
+ }
2641
+
2642
+ /** wip experimental use at your own risk */
2643
+ declare var InteractivePrompt: InteractivePromptConstructor;
2644
+
2440
2645
  /**
2441
2646
  * Launch the Yavascript REPL (read-eval-print-loop).
2442
2647
  *
2443
2648
  * @param context Variables to make available as globals within the repl.
2444
2649
  * @param lang The langauge to use in the repl. Defaults to "javascript".
2445
2650
  */
2446
- declare function startRepl(
2447
- context?: { [key: string]: any },
2448
- lang?:
2449
- | "js"
2450
- | "javascript"
2451
- | "ts"
2452
- | "typescript"
2453
- | "jsx"
2454
- | "tsx"
2455
- | "coffee"
2456
- | "coffeescript"
2457
- ): void;
2651
+ declare const startRepl: {
2652
+ (
2653
+ context?: { [key: string]: any },
2654
+ lang?:
2655
+ | "js"
2656
+ | "javascript"
2657
+ | "ts"
2658
+ | "typescript"
2659
+ | "jsx"
2660
+ | "tsx"
2661
+ | "coffee"
2662
+ | "coffeescript"
2663
+ ): void;
2458
2664
 
2459
- /**
2460
- * Returns the absolute path to the root folder of the git/hg repo.
2461
- *
2462
- * This is done by running `git rev-parse --show-toplevel` and `hg root`.
2463
- *
2464
- * If `relativeTo` is provided, the git and hg commands will be executed in
2465
- * that folder instead of in `pwd()`.
2466
- */
2467
- declare function repoRoot(relativeTo?: string): string;
2665
+ /**
2666
+ * A special value; when expressions result in this value, the repl will
2667
+ * print nothing instead of printing this value.
2668
+ */
2669
+ NOTHING: symbol;
2670
+ };
2468
2671
 
2469
2672
  /**
2470
- * Returns whether the provided path is ignored by git.
2673
+ * An object that points to a git repository on disk and provides utility
2674
+ * methods for getting information from that repo.
2471
2675
  */
2472
- declare function isGitignored(path: string): boolean;
2676
+ declare class GitRepo {
2677
+ /**
2678
+ * Given a path to a file or folder on disk, finds the parent git repo
2679
+ * containing that path, and returns the absolute path to the repo root (the
2680
+ * folder that contains the '.git' folder).
2681
+ *
2682
+ * This is done by running `git rev-parse --show-toplevel`.
2683
+ */
2684
+ static findRoot(fromPath: string | Path): Path;
2685
+
2686
+ /**
2687
+ * Creates a new `Git` object for the given repo on disk.
2688
+ */
2689
+ constructor(repoDir: string | Path);
2690
+
2691
+ /**
2692
+ * The root folder of the git repo that this `Git` object represents (the
2693
+ * folder that contains the '.git' folder).
2694
+ */
2695
+ repoDir: Path;
2696
+
2697
+ /**
2698
+ * Returns the commit SHA the git repo is currently pointed at.
2699
+ *
2700
+ * This is done by running `git rev-parse HEAD`.
2701
+ */
2702
+ commitSHA(): string;
2703
+
2704
+ /**
2705
+ * If the commit SHA the git repo is currently pointed at is the tip of a
2706
+ * named branch, returns the branch name. Otherwise, returns `null`.
2707
+ *
2708
+ * This is done by running `git rev-parse --abbrev-ref HEAD`.
2709
+ */
2710
+ branchName(): string | null;
2711
+
2712
+ /**
2713
+ * Returns a boolean indicating whether there are uncommited changes in the
2714
+ * git repo. `true` means there are changes, `false` means there are no
2715
+ * changes (ie. the repo is clean).
2716
+ *
2717
+ * This is done by running `git status --quiet`.
2718
+ */
2719
+ isWorkingTreeDirty(): boolean;
2720
+
2721
+ /**
2722
+ * Returns whether the provided path is ignored by git.
2723
+ *
2724
+ * If `path` is an absolute path, it must be a child directory of this Git
2725
+ * object's `repoDir`, or else an error will be thrown.
2726
+ */
2727
+ isIgnored(path: string | Path): boolean;
2728
+ }
2473
2729
 
2474
2730
  /**
2475
2731
  * Configures the default value of `trace` in functions which receive `trace`
@@ -2689,48 +2945,910 @@ declare type TypedArrayConstructor =
2689
2945
  // QuickJS APIs, which YavaScript builds upon
2690
2946
  // ------------------------------------------
2691
2947
  // ==========================================
2692
- // Definitions of the globals and modules added by quickjs-libc
2693
-
2694
- /**
2695
- * Provides the command line arguments. The first argument is the script name.
2696
- */
2697
- declare var scriptArgs: Array<string>;
2698
-
2699
- /**
2700
- * Print the arguments separated by spaces and a trailing newline.
2701
- *
2702
- * Non-string args are coerced into a string via [ToString](https://tc39.es/ecma262/#sec-tostring).
2703
- * Objects can override the default `ToString` behavior by defining a `toString` method.
2704
- */
2705
- declare var print: (...args: Array<any>) => void;
2706
-
2707
- /**
2708
- * Object that provides functions for logging information.
2709
- */
2710
- declare var console: {
2711
- /** Same as {@link print}(). */
2712
- log: typeof print;
2713
-
2714
- /** Same as {@link print}(). */
2715
- warn: typeof print;
2716
-
2717
- /** Same as {@link print}(). */
2718
- error: typeof print;
2719
-
2720
- /** Same as {@link print}(). */
2721
- info: typeof print;
2722
- };
2723
-
2724
- /** An object representing a file handle. */
2725
- declare interface FILE {
2948
+ interface ObjectConstructor {
2726
2949
  /**
2727
- * Human-readable description of where this FILE points.
2728
- *
2729
- * If `target` is a number, the FILE was opened with fdopen, and `target` is
2730
- * the fd. Otherwise, `target` will be an arbitrary string that describes the
2731
- * file; it may be the absolute path to the file, the relative path to the
2732
- * file at time of its opening, or some other string like "stdin" or
2733
- * "tmpfile".
2950
+ * Convert the specified value to a primitive value.
2951
+ *
2952
+ * The provided hint indicates a preferred return type, which may or may not
2953
+ * be respected by the engine.
2954
+ *
2955
+ * See the abstract operation "ToPrimitive" in the ECMAScript standard for
2956
+ * more info.
2957
+ */
2958
+ toPrimitive(
2959
+ input: any,
2960
+ hint: "string" | "number" | "default"
2961
+ ): string | number | bigint | boolean | undefined | symbol | null;
2962
+
2963
+ /**
2964
+ * Returns a boolean indicating whether the specified value is a primitive value.
2965
+ */
2966
+ isPrimitive(input: any): boolean;
2967
+ }
2968
+
2969
+ interface SymbolConstructor {
2970
+ /**
2971
+ * A method that changes the result of using the `typeof` operator on the
2972
+ * object. Called by the semantics of the typeof operator.
2973
+ *
2974
+ * Note that the following semantics will come into play when use of the
2975
+ * `typeof` operator causes the engine to call a `Symbol.typeofValue` method
2976
+ * on an object:
2977
+ *
2978
+ * - If the method returns any value other than one of the string values
2979
+ * which are normally the result of using the `typeof` operator, the engine
2980
+ * behaves as if no `Symbol.typeofValue` method was present on the object.
2981
+ * - If an error is thrown from this method, or an error is thrown while
2982
+ * accessing this property, the error will be silently ignored, and the
2983
+ * engine will behave as if no `Symbol.typeofValue` method was present on
2984
+ * the object.
2985
+ * - If this property is present on an object, but the value of that property
2986
+ * is not a function, the engine will not consider that value when
2987
+ * determining the result of the `typeof` operation (it'll ignore it).
2988
+ */
2989
+ readonly typeofValue: unique symbol;
2990
+
2991
+ /**
2992
+ * To override operators (+, -, ==, etc) for an object, set its
2993
+ * `Symbol.operatorSet` property to an `OperatorSet` object, which can be
2994
+ * created via `Operators.create`.
2995
+ */
2996
+ readonly operatorSet: unique symbol;
2997
+ }
2998
+
2999
+ /**
3000
+ * An object that, if placed on another object's `Symbol.operatorSet` property,
3001
+ * will overload its operators to behave as defined by the functions this
3002
+ * OperatorSet was constructed with.
3003
+ *
3004
+ * You can create an OperatorSet via `Operators(...)` or
3005
+ * `Operators.create(...)`.
3006
+ */
3007
+ declare type OperatorSet = {
3008
+ /**
3009
+ * This property is not here at runtime; we just use it to make this type
3010
+ * differ from an empty object.
3011
+ */
3012
+ __is__: "OperatorSet";
3013
+ };
3014
+
3015
+ interface OperatorFunctions<Left, Right> {
3016
+ "+": (left: Left, right: Right) => any;
3017
+ "-": (left: Left, right: Right) => any;
3018
+ "*": (left: Left, right: Right) => any;
3019
+ "/": (left: Left, right: Right) => any;
3020
+ "%": (left: Left, right: Right) => any;
3021
+ "**": (left: Left, right: Right) => any;
3022
+ "|": (left: Left, right: Right) => any;
3023
+ "&": (left: Left, right: Right) => any;
3024
+ "^": (left: Left, right: Right) => any;
3025
+ "<<": (left: Left, right: Right) => any;
3026
+ ">>": (left: Left, right: Right) => any;
3027
+ ">>>": (left: Left, right: Right) => any;
3028
+ "==": (left: Left, right: Right) => any;
3029
+ "<": (left: Left, right: Right) => any;
3030
+ pos: (left: Left, right: Right) => any;
3031
+ neg: (left: Left, right: Right) => any;
3032
+ "++": (left: Left, right: Right) => any;
3033
+ "--": (left: Left, right: Right) => any;
3034
+ "~": (left: Left, right: Right) => any;
3035
+ }
3036
+
3037
+ interface SelfOperators<T> extends Partial<OperatorFunctions<T, T>> {
3038
+ left?: undefined;
3039
+ right?: undefined;
3040
+ }
3041
+
3042
+ interface LeftOperators<T, Left> extends Partial<OperatorFunctions<Left, T>> {
3043
+ left: {};
3044
+ right?: undefined;
3045
+ }
3046
+
3047
+ interface RightOperators<T, Right>
3048
+ extends Partial<OperatorFunctions<T, Right>> {
3049
+ left?: undefined;
3050
+ right: {};
3051
+ }
3052
+
3053
+ interface OperatorsConstructor {
3054
+ /**
3055
+ * Creates a new OperatorSet object, which should be placed on an object's
3056
+ * Symbol.operatorSet property.
3057
+ */
3058
+ <T>(
3059
+ selfOperators?: SelfOperators<T>,
3060
+ ...otherOperators: Array<LeftOperators<T, any> | RightOperators<T, any>>
3061
+ ): OperatorSet;
3062
+
3063
+ /**
3064
+ * Creates a new OperatorSet object, which should be placed on an object's
3065
+ * Symbol.operatorSet property.
3066
+ */
3067
+ create: <T>(
3068
+ selfOperators?: SelfOperators<T>,
3069
+ ...otherOperators: Array<LeftOperators<T, any> | RightOperators<T, any>>
3070
+ ) => OperatorSet;
3071
+
3072
+ /**
3073
+ * In math mode, the BigInt division and power operators can be overloaded by
3074
+ * using this function.
3075
+ */
3076
+ updateBigIntOperators(
3077
+ ops: Pick<OperatorFunctions<BigInt, BigInt>, "/" | "**">
3078
+ ): void;
3079
+ }
3080
+
3081
+ declare var Operators: OperatorsConstructor;
3082
+
3083
+ interface Number {
3084
+ [Symbol.operatorSet]: OperatorSet;
3085
+ }
3086
+
3087
+ interface Boolean {
3088
+ [Symbol.operatorSet]: OperatorSet;
3089
+ }
3090
+
3091
+ interface String {
3092
+ [Symbol.operatorSet]: OperatorSet;
3093
+ }
3094
+
3095
+ interface BigInt {
3096
+ [Symbol.operatorSet]: OperatorSet;
3097
+ }
3098
+
3099
+ interface BigIntConstructor {
3100
+ /**
3101
+ * Return trunc(a/b).
3102
+ *
3103
+ * b = 0 raises a RangeError exception.
3104
+ */
3105
+ tdiv(a: bigint, b: bigint): bigint;
3106
+
3107
+ /**
3108
+ * Return \lfloor a/b \rfloor.
3109
+ *
3110
+ * b = 0 raises a RangeError exception.
3111
+ */
3112
+ fdiv(a: bigint, b: bigint): bigint;
3113
+
3114
+ /**
3115
+ * Return \lceil a/b \rceil.
3116
+ *
3117
+ * b = 0 raises a RangeError exception.
3118
+ */
3119
+ cdiv(a: bigint, b: bigint): bigint;
3120
+
3121
+ /**
3122
+ * Return sgn(b) \lfloor a/{|b|} \rfloor (Euclidian division).
3123
+ *
3124
+ * b = 0 raises a RangeError exception.
3125
+ */
3126
+ ediv(a: bigint, b: bigint): bigint;
3127
+
3128
+ /**
3129
+ * Perform trunc(a/b) and return an array of two elements. The first element
3130
+ * is the quotient, the second is the remainder.
3131
+ *
3132
+ * b = 0 raises a RangeError exception.
3133
+ */
3134
+ tdivrem(a: bigint, b: bigint): [bigint, bigint];
3135
+
3136
+ /**
3137
+ * Perform \lfloor a/b \rfloor and return an array of two elements. The first
3138
+ * element is the quotient, the second is the remainder.
3139
+ *
3140
+ * b = 0 raises a RangeError exception.
3141
+ */
3142
+ fdivrem(a: bigint, b: bigint): [bigint, bigint];
3143
+
3144
+ /**
3145
+ * Perform \lceil a/b \rceil and return an array of two elements. The first
3146
+ * element is the quotient, the second is the remainder.
3147
+ *
3148
+ * b = 0 raises a RangeError exception.
3149
+ */
3150
+ cdivrem(a: bigint, b: bigint): [bigint, bigint];
3151
+
3152
+ /**
3153
+ * Perform sgn(b) \lfloor a/{|b|} \rfloor (Euclidian division) and return an
3154
+ * array of two elements. The first element is the quotient, the second is
3155
+ * the remainder.
3156
+ *
3157
+ * b = 0 raises a RangeError exception.
3158
+ */
3159
+ edivrem(a: bigint, b: bigint): [bigint, bigint];
3160
+
3161
+ /**
3162
+ * Return \lfloor \sqrt(a) \rfloor.
3163
+ *
3164
+ * A RangeError exception is raised if a < 0.
3165
+ */
3166
+ sqrt(a: bigint): bigint;
3167
+
3168
+ /**
3169
+ * Return an array of two elements. The first element is
3170
+ * \lfloor \sqrt{a} \rfloor. The second element is
3171
+ * a-\lfloor \sqrt{a} \rfloor^2.
3172
+ *
3173
+ * A RangeError exception is raised if a < 0.
3174
+ */
3175
+ sqrtrem(a: bigint): [bigint, bigint];
3176
+
3177
+ /**
3178
+ * Return -1 if a \leq 0 otherwise return \lfloor \log2(a) \rfloor.
3179
+ */
3180
+ floorLog2(a: bigint): bigint;
3181
+
3182
+ /**
3183
+ * Return the number of trailing zeros in the two’s complement binary representation of a.
3184
+ *
3185
+ * Return -1 if a=0.
3186
+ */
3187
+ ctz(a: bigint): bigint;
3188
+ }
3189
+
3190
+ declare type BigFloatRoundingMode = number & {
3191
+ /**
3192
+ * This property is not here at runtime; we just use it to make this type
3193
+ * differ from a normal number
3194
+ */
3195
+ __is__: "BigFloatRoundingMode";
3196
+ };
3197
+
3198
+ interface BigFloatEnvConstructor {
3199
+ /**
3200
+ * Creates a new floating point environment. Its status flags are reset.
3201
+ *
3202
+ * - If unspecified, `precision` defaults to the precision from the global floating point environment.
3203
+ * - If unspecified, `roundingMode` defaults to RNDN.
3204
+ */
3205
+ new (precision?: number, roundingMode?: BigFloatRoundingMode): BigFloatEnv;
3206
+
3207
+ /**
3208
+ * The mantissa precision in bits of the global floating point environment.
3209
+ *
3210
+ * The initial value is 113.
3211
+ */
3212
+ get prec(): number;
3213
+
3214
+ /**
3215
+ * The exponent size in bits of the global floating point environment,
3216
+ * assuming an IEEE 754 representation.
3217
+ *
3218
+ * The initial value is 15.
3219
+ */
3220
+ get expBits(): number;
3221
+
3222
+ /**
3223
+ * Sets the mantissa precision of the global floating point environment to
3224
+ * `prec` and the exponent size to `expBits`, then calls the function `func`.
3225
+ * Then the precision and exponent size are reset to their previous values
3226
+ * and the return value of `func` is returned (or an exception is raised if
3227
+ * `func` raised an exception).
3228
+ *
3229
+ * If expBits is undefined, it is set to {@link BigFloatEnv.expBitsMax}.
3230
+ *
3231
+ * @param func The function to call within the modified environment
3232
+ * @param prec The mantissa precision (in bits) to use in the modified environment
3233
+ * @param expBits The exponent size (in bits) to use in the modified environment. Defaults to {@link BigFloatEnv.expBitsMax}.
3234
+ */
3235
+ setPrec<Ret>(func: () => Ret, prec: number, expBits?: number): Ret;
3236
+
3237
+ /**
3238
+ * Integer; the minimum allowed precision. Must be at least 2.
3239
+ */
3240
+ readonly precMin: number;
3241
+
3242
+ /**
3243
+ * Integer; the maximum allowed precision. Must be at least 113.
3244
+ */
3245
+ readonly precMax: number;
3246
+
3247
+ /**
3248
+ * Integer; the minimum allowed exponent size in bits. Must be at least 3.
3249
+ */
3250
+ readonly expBitsMin: number;
3251
+
3252
+ /**
3253
+ * Integer; the maximum allowed exponent size in bits. Must be at least 15.
3254
+ */
3255
+ readonly expBitsMax: number;
3256
+
3257
+ /**
3258
+ * Round to nearest, with ties to even rounding mode.
3259
+ */
3260
+ readonly RNDN: BigFloatRoundingMode;
3261
+
3262
+ /**
3263
+ * Round to zero rounding mode.
3264
+ */
3265
+ readonly RNDZ: BigFloatRoundingMode;
3266
+
3267
+ /**
3268
+ * Round to -Infinity rounding mode.
3269
+ */
3270
+ readonly RNDD: BigFloatRoundingMode;
3271
+
3272
+ /**
3273
+ * Round to +Infinity rounding mode.
3274
+ */
3275
+ readonly RNDU: BigFloatRoundingMode;
3276
+
3277
+ /**
3278
+ * Round to nearest, with ties away from zero rounding mode.
3279
+ */
3280
+ readonly RNDNA: BigFloatRoundingMode;
3281
+
3282
+ /**
3283
+ * Round away from zero rounding mode.
3284
+ */
3285
+ readonly RNDA: BigFloatRoundingMode;
3286
+
3287
+ /**
3288
+ * Faithful rounding mode. The result is non-deterministically rounded to
3289
+ * -Infinity or +Infinity.
3290
+ *
3291
+ * This rounding mode usually gives a faster and deterministic running time
3292
+ * for the floating point operations.
3293
+ */
3294
+ readonly RNDF: BigFloatRoundingMode;
3295
+
3296
+ prototype: BigFloatEnv;
3297
+ }
3298
+
3299
+ declare var BigFloatEnv: BigFloatEnvConstructor;
3300
+
3301
+ /**
3302
+ * A BigFloatEnv contains:
3303
+ *
3304
+ * - the mantissa precision in bits
3305
+ * - the exponent size in bits assuming an IEEE 754 representation;
3306
+ * - the subnormal flag (if true, subnormal floating point numbers can be generated by the floating point operations).
3307
+ * - the rounding mode
3308
+ * - the floating point status. The status flags can only be set by the floating point operations. They can be reset with BigFloatEnv.prototype.clearStatus() or with the various status flag setters.
3309
+ */
3310
+ interface BigFloatEnv {
3311
+ /**
3312
+ * The mantissa precision, in bits.
3313
+ *
3314
+ * If precision was not specified as an argument to the BigFloatEnv
3315
+ * constructor, defaults to the precision value of the global floating-point
3316
+ * environment ({@link BigFloatEnv.prec}).
3317
+ */
3318
+ get prec(): number;
3319
+ set prec(newValue: number);
3320
+
3321
+ /**
3322
+ * The exponent size in bits assuming an IEEE 754 representation.
3323
+ *
3324
+ * Defaults to the exponent size of the global floating-point environment
3325
+ * ({@link BigFloatEnv.expBits}).
3326
+ */
3327
+ get expBits(): number;
3328
+ set expBits(newValue: number);
3329
+
3330
+ /**
3331
+ * The rounding mode.
3332
+ *
3333
+ * If the rounding mode was not specified as an argument to the BigFloatEnv
3334
+ * constructor, defaults to {@link BigFloatEnv.RNDN}.
3335
+ */
3336
+ get rndMode(): BigFloatRoundingMode;
3337
+ set rndMode(newMode: BigFloatRoundingMode);
3338
+
3339
+ /** subnormal flag. It is false when expBits = expBitsMax. Defaults to false. */
3340
+ get subnormal(): boolean;
3341
+ set subnormal(newValue: boolean);
3342
+
3343
+ /** Status flag; cleared by `clearStatus`. */
3344
+ get invalidOperation(): boolean;
3345
+ set invalidOperation(newValue: boolean);
3346
+
3347
+ /** Status flag; cleared by `clearStatus`. */
3348
+ get divideByZero(): boolean;
3349
+ set divideByZero(newValue: boolean);
3350
+
3351
+ /** Status flag; cleared by `clearStatus`. */
3352
+ get overflow(): boolean;
3353
+ set overflow(newValue: boolean);
3354
+
3355
+ /** Status flag; cleared by `clearStatus`. */
3356
+ get underflow(): boolean;
3357
+ set underflow(newValue: boolean);
3358
+
3359
+ /** Status flag; cleared by `clearStatus`. */
3360
+ get inexact(): boolean;
3361
+ set inexact(newValue: boolean);
3362
+
3363
+ /**
3364
+ * Clear the status flags (invalidOperation, divideByZero, overflow,
3365
+ * underflow, and inexact).
3366
+ */
3367
+ clearStatus(): void;
3368
+ }
3369
+
3370
+ interface BigFloatConstructor {
3371
+ /**
3372
+ * If `value` is a numeric type, it is converted to BigFloat without rounding.
3373
+ *
3374
+ * If `value`` is a string, it is converted to BigFloat using the precision of the global floating point environment ({@link BigFloatEnv.prec}).
3375
+ */
3376
+ (value: number | string | BigInt | BigFloat): BigFloat;
3377
+
3378
+ prototype: BigFloat;
3379
+
3380
+ /**
3381
+ * The value of {@link Math.LN2} rounded to nearest, ties to even with the
3382
+ * current global precision.
3383
+ *
3384
+ * The constant values are cached for small precisions.
3385
+ */
3386
+ get LN2(): BigFloat;
3387
+
3388
+ /**
3389
+ * The value of {@link Math.PI} rounded to nearest, ties to even with
3390
+ * the current global precision.
3391
+ *
3392
+ * The constant values are cached for small precisions.
3393
+ */
3394
+ get PI(): BigFloat;
3395
+
3396
+ /**
3397
+ * The value of {@link Number.MIN_VALUE} as a BigFloat.
3398
+ */
3399
+ get MIN_VALUE(): BigFloat;
3400
+
3401
+ /**
3402
+ * The value of {@link Number.MAX_VALUE} as a BigFloat.
3403
+ */
3404
+ get MAX_VALUE(): BigFloat;
3405
+
3406
+ /**
3407
+ * The value of {@link Number.EPSILON} as a BigFloat.
3408
+ */
3409
+ get EPSILON(): BigFloat;
3410
+
3411
+ /**
3412
+ * Rounds the floating point number `a` according to the floating point
3413
+ * environment `e` or the global environment if `e` is undefined.
3414
+ */
3415
+ fpRound(a: BigFloat, e?: BigFloatEnv): BigFloat;
3416
+
3417
+ /**
3418
+ * Parses the string `a` as a floating point number in radix `radix`.
3419
+ *
3420
+ * The radix is 0 (default) or from 2 to 36. The radix 0 means radix 10
3421
+ * unless there is a hexadecimal or binary prefix.
3422
+ *
3423
+ * The result is rounded according to the floating point environment `e` or
3424
+ * the global environment if `e` is undefined.
3425
+ */
3426
+ parseFloat(a: string, radix?: number, e?: BigFloatEnv): BigFloat;
3427
+
3428
+ /**
3429
+ * Returns true if `a` is a finite bigfloat. Returns false otherwise.
3430
+ */
3431
+ isFinite(a: BigFloat): boolean;
3432
+
3433
+ /**
3434
+ * Returns true if a is a NaN bigfloat. Returns false otherwise.
3435
+ */
3436
+ isNaN(a: BigFloat): boolean;
3437
+
3438
+ /**
3439
+ * Adds `a` and `b` together and rounds the resulting floating point number
3440
+ * according to the floating point environment `e`, or the global environment
3441
+ * if e is undefined.
3442
+ *
3443
+ * If `e` is specified, the floating point status flags on `e` are updated.
3444
+ */
3445
+ add(a: BigFloat, b: BigFloat, e?: BigFloatEnv): BigFloat;
3446
+
3447
+ /**
3448
+ * Subtracts `b` from `a` and rounds the resulting floating point number
3449
+ * according to the floating point environment `e`, or the global environment
3450
+ * if e is undefined.
3451
+ *
3452
+ * If `e` is specified, the floating point status flags on `e` are updated.
3453
+ */
3454
+ sub(a: BigFloat, b: BigFloat, e?: BigFloatEnv): BigFloat;
3455
+
3456
+ /**
3457
+ * Multiplies `a` and `b` together and rounds the resulting floating point
3458
+ * number according to the floating point environment `e`, or the global
3459
+ * environment if e is undefined.
3460
+ *
3461
+ * If `e` is specified, the floating point status flags on `e` are updated.
3462
+ */
3463
+ mul(a: BigFloat, b: BigFloat, e?: BigFloatEnv): BigFloat;
3464
+
3465
+ /**
3466
+ * Divides `a` by `b` and rounds the resulting floating point number
3467
+ * according to the floating point environment `e`, or the global environment
3468
+ * if e is undefined.
3469
+ *
3470
+ * If `e` is specified, the floating point status flags on `e` are updated.
3471
+ */
3472
+ div(a: BigFloat, b: BigFloat, e?: BigFloatEnv): BigFloat;
3473
+
3474
+ /**
3475
+ * Rounds `x` down to the nearest integer.
3476
+ *
3477
+ * No additional rounding (ie. BigFloatEnv-related rounding) is performed.
3478
+ */
3479
+ floor(x: BigFloat): BigFloat;
3480
+
3481
+ /**
3482
+ * Rounds `x` up to the nearest integer.
3483
+ *
3484
+ * No additional rounding (ie. BigFloatEnv-related rounding) is performed.
3485
+ */
3486
+ ceil(x: BigFloat): BigFloat;
3487
+
3488
+ /**
3489
+ * Rounds `x` to the nearest integer.
3490
+ *
3491
+ * No additional rounding (ie. BigFloatEnv-related rounding) is performed.
3492
+ */
3493
+ round(x: BigFloat): BigFloat;
3494
+
3495
+ /**
3496
+ * Truncates the fractional part of `x`, resulting in an integer.
3497
+ *
3498
+ * No additional rounding (ie. BigFloatEnv-related rounding) is performed.
3499
+ */
3500
+ trunc(x: BigFloat): BigFloat;
3501
+
3502
+ /**
3503
+ * Returns the absolute value of `x`.
3504
+ *
3505
+ * No additional rounding (ie. BigFloatEnv-related rounding) is performed.
3506
+ */
3507
+ abs(x: BigFloat): BigFloat;
3508
+
3509
+ /**
3510
+ * Floating point remainder. The quotient is truncated to zero.
3511
+ *
3512
+ * `e` is an optional floating point environment.
3513
+ */
3514
+ fmod(x: BigFloat, y: BigFloat, e?: BigFloatEnv): BigFloat;
3515
+
3516
+ /**
3517
+ * Floating point remainder. The quotient is rounded to the nearest integer
3518
+ * with ties to even.
3519
+ *
3520
+ * `e` is an optional floating point environment.
3521
+ */
3522
+ remainder(x: BigFloat, y: BigFloat, e?: BigFloatEnv): BigFloat;
3523
+
3524
+ /**
3525
+ * Square root. Returns a rounded floating point number.
3526
+ *
3527
+ * e is an optional floating point environment.
3528
+ */
3529
+ sqrt(x: BigFloat, e?: BigFloatEnv): BigFloat;
3530
+
3531
+ /**
3532
+ * Returns a rounded floating point number.
3533
+ *
3534
+ * `e` is an optional floating point environment.
3535
+ */
3536
+ sin(x: BigFloat, e?: BigFloatEnv): BigFloat;
3537
+
3538
+ /**
3539
+ * Returns a rounded floating point number.
3540
+ *
3541
+ * `e` is an optional floating point environment.
3542
+ */
3543
+ cos(x: BigFloat, e?: BigFloatEnv): BigFloat;
3544
+
3545
+ /**
3546
+ * Returns a rounded floating point number.
3547
+ *
3548
+ * `e` is an optional floating point environment.
3549
+ */
3550
+ tan(x: BigFloat, e?: BigFloatEnv): BigFloat;
3551
+
3552
+ /**
3553
+ * Returns a rounded floating point number.
3554
+ *
3555
+ * `e` is an optional floating point environment.
3556
+ */
3557
+ asin(x: BigFloat, e?: BigFloatEnv): BigFloat;
3558
+
3559
+ /**
3560
+ * Returns a rounded floating point number.
3561
+ *
3562
+ * `e` is an optional floating point environment.
3563
+ */
3564
+ acos(x: BigFloat, e?: BigFloatEnv): BigFloat;
3565
+
3566
+ /**
3567
+ * Returns a rounded floating point number.
3568
+ *
3569
+ * `e` is an optional floating point environment.
3570
+ */
3571
+ atan(x: BigFloat, e?: BigFloatEnv): BigFloat;
3572
+
3573
+ /**
3574
+ * Returns a rounded floating point number.
3575
+ *
3576
+ * `e` is an optional floating point environment.
3577
+ */
3578
+ atan2(x: BigFloat, y: BigFloat, e?: BigFloatEnv): BigFloat;
3579
+
3580
+ /**
3581
+ * Returns a rounded floating point number.
3582
+ *
3583
+ * `e` is an optional floating point environment.
3584
+ */
3585
+ exp(x: BigFloat, e?: BigFloatEnv): BigFloat;
3586
+
3587
+ /**
3588
+ * Returns a rounded floating point number.
3589
+ *
3590
+ * `e` is an optional floating point environment.
3591
+ */
3592
+ log(x: BigFloat, e?: BigFloatEnv): BigFloat;
3593
+
3594
+ /**
3595
+ * Returns a rounded floating point number.
3596
+ *
3597
+ * `e` is an optional floating point environment.
3598
+ */
3599
+ pow(x: BigFloat, y: BigFloat, e?: BigFloatEnv): BigFloat;
3600
+ }
3601
+
3602
+ declare var BigFloat: BigFloatConstructor;
3603
+
3604
+ /**
3605
+ * The BigFloat type represents floating point numbers in base 2 with the IEEE 754 semantics.
3606
+ *
3607
+ * A floating point number is represented as a sign, mantissa and exponent.
3608
+ *
3609
+ * The special values NaN, +/-Infinity, +0 and -0 are supported.
3610
+ *
3611
+ * The mantissa and exponent can have any bit length with an implementation specific minimum and maximum.
3612
+ */
3613
+ interface BigFloat {
3614
+ valueOf(): BigFloat;
3615
+
3616
+ /** radix must be between 2 and 36 */
3617
+ toString(radix?: number): string;
3618
+
3619
+ /**
3620
+ * Returns a string containing a number represented either in exponential or
3621
+ * fixed-point notation with a specified number of digits.
3622
+ *
3623
+ * @param precision Number of significant digits. There is no range limit on this number.
3624
+ * @param roundingMode The rounding mode to use when representing the value. Defaults to {@link BigFloatEnv.RNDNA}.
3625
+ * @param radix The base to use when representing the value. Must be an integer between 2 and 36. Defaults to 10.
3626
+ */
3627
+ toPrecision(
3628
+ precision: number,
3629
+ roundingMode?: BigFloatRoundingMode,
3630
+ radix?: number
3631
+ ): string;
3632
+
3633
+ /**
3634
+ * Returns a string representing a number in fixed-point notation.
3635
+ *
3636
+ * @param fractionDigits Number of digits after the decimal point. There is no range limit on this number.
3637
+ * @param roundingMode The rounding mode to use when representing the value. Defaults to {@link BigFloatEnv.RNDNA}.
3638
+ * @param radix The base to use when representing the value. Must be an integer between 2 and 36. Defaults to 10.
3639
+ */
3640
+ toFixed(
3641
+ fractionDigits: number,
3642
+ roundingMode?: BigFloatRoundingMode,
3643
+ radix?: number
3644
+ ): string;
3645
+
3646
+ /**
3647
+ * Returns a string containing a number represented in exponential notation.
3648
+ *
3649
+ * @param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.
3650
+ * @param roundingMode The rounding mode to use when representing the value. Defaults to {@link BigFloatEnv.RNDNA}.
3651
+ * @param radix The base to use when representing the value. Must be an integer between 2 and 36. Defaults to 10.
3652
+ */
3653
+ toExponential(
3654
+ fractionDigits: number,
3655
+ roundingMode?: BigFloatRoundingMode,
3656
+ radix?: number
3657
+ ): string;
3658
+
3659
+ [Symbol.typeofValue]: () => "bigfloat";
3660
+ }
3661
+
3662
+ declare type BigDecimalRoundingMode =
3663
+ | "floor"
3664
+ | "ceiling"
3665
+ | "down"
3666
+ | "up"
3667
+ | "half-even"
3668
+ | "half-up";
3669
+
3670
+ declare type BigDecimalRoundingObject =
3671
+ | {
3672
+ /** must be >= 1 */
3673
+ maximumSignificantDigits: number;
3674
+ roundingMode: BigDecimalRoundingMode;
3675
+ }
3676
+ | {
3677
+ /** must be >= 0 */
3678
+ maximumFractionDigits: number;
3679
+ roundingMode: BigDecimalRoundingMode;
3680
+ };
3681
+
3682
+ interface BigDecimalConstructor {
3683
+ (): BigDecimal;
3684
+ (value: number | string | BigInt | BigFloat): BigDecimal;
3685
+
3686
+ /**
3687
+ * Adds together `a` and `b` and rounds the result according to the rounding
3688
+ * object `e`. If the rounding object is not present, the operation is
3689
+ * executed with infinite precision; in other words, no rounding occurs when
3690
+ * the rounding object is not present.
3691
+ */
3692
+ add(a: BigDecimal, b: BigDecimal, e?: BigDecimalRoundingObject): BigDecimal;
3693
+
3694
+ /**
3695
+ * Subtracts `b` from `a` and rounds the result according to the rounding
3696
+ * object `e`. If the rounding object is not present, the operation is
3697
+ * executed with infinite precision; in other words, no rounding occurs when
3698
+ * the rounding object is not present.
3699
+ */
3700
+ sub(a: BigDecimal, b: BigDecimal, e?: BigDecimalRoundingObject): BigDecimal;
3701
+
3702
+ /**
3703
+ * Multiplies together `a` and `b` and rounds the result according to the
3704
+ * rounding object `e`. If the rounding object is not present, the operation
3705
+ * is executed with infinite precision; in other words, no rounding occurs
3706
+ * when the rounding object is not present.
3707
+ */
3708
+ mul(a: BigDecimal, b: BigDecimal, e?: BigDecimalRoundingObject): BigDecimal;
3709
+
3710
+ /**
3711
+ * Divides `a` by `b` and rounds the result according to the rounding object
3712
+ * `e`.
3713
+ *
3714
+ * If the rounding object is not present, an attempt is made to perform the
3715
+ * operation with infinite precision. However, not all quotients can be
3716
+ * represented with infinite precision. If the quotient cannot be represented
3717
+ * with infinite precision, a RangeError is thrown.
3718
+ *
3719
+ * A RangeError is thrown when dividing by zero.
3720
+ */
3721
+ div(a: BigDecimal, b: BigDecimal, e?: BigDecimalRoundingObject): BigDecimal;
3722
+
3723
+ /**
3724
+ * Perform the modulo operation of `a` by `b` and round the result according
3725
+ * to the rounding object `e`. If the rounding object is not present, the
3726
+ * operation is executed with infinite precision; in other words, no rounding
3727
+ * occurs when the rounding object is not present.
3728
+ */
3729
+ mod(a: BigDecimal, b: BigDecimal, e?: BigDecimalRoundingObject): BigDecimal;
3730
+
3731
+ /**
3732
+ * Obtain the square root of `a`, rounding the result according to the
3733
+ * rounding object `e`.
3734
+ *
3735
+ * If `a` is less than zero, a RangeError will be thrown.
3736
+ *
3737
+ * Note that the rounding object is *required*.
3738
+ */
3739
+ sqrt(a: BigDecimal, e: BigDecimalRoundingObject): BigDecimal;
3740
+
3741
+ /**
3742
+ * Rounds `a` using the rounding object `e`.
3743
+ */
3744
+ round(a: BigDecimal, e: BigDecimalRoundingObject): BigDecimal;
3745
+
3746
+ prototype: BigDecimal;
3747
+ }
3748
+
3749
+ declare var BigDecimal: BigDecimalConstructor;
3750
+
3751
+ /**
3752
+ * The BigDecimal type represents floating point numbers in base 10.
3753
+ *
3754
+ * It is inspired from the proposal available at https://github.com/littledan/proposal-bigdecimal.
3755
+ *
3756
+ * The BigDecimal floating point numbers are always normalized and finite.
3757
+ * There is no concept of -0, Infinity or NaN. By default, all the computations
3758
+ * are done with infinite precision.
3759
+ */
3760
+ interface BigDecimal {
3761
+ /**
3762
+ * Returns the bigdecimal primitive value corresponding to this BigDecimal.
3763
+ */
3764
+ valueOf(): BigDecimal;
3765
+
3766
+ /**
3767
+ * Converts this BigDecimal to a string with infinite precision in base 10.
3768
+ */
3769
+ toString(): string;
3770
+
3771
+ /**
3772
+ * Returns a string containing a number represented either in exponential or
3773
+ * fixed-point notation with a specified number of digits.
3774
+ *
3775
+ * @param precision Number of significant digits. There is no range limit on this number.
3776
+ * @param roundingMode The rounding mode to use when representing the value. Defaults to "half-up".
3777
+ */
3778
+ toPrecision(precision: number, roundingMode?: BigDecimalRoundingMode): string;
3779
+
3780
+ /**
3781
+ * Returns a string representing a number in fixed-point notation.
3782
+ *
3783
+ * @param fractionDigits Number of digits after the decimal point. There is no range limit on this number.
3784
+ * @param roundingMode The rounding mode to use when representing the value. Defaults to "half-up".
3785
+ */
3786
+ toFixed(
3787
+ fractionDigits: number,
3788
+ roundingMode?: BigDecimalRoundingMode
3789
+ ): string;
3790
+
3791
+ /**
3792
+ * Returns a string containing a number represented in exponential notation.
3793
+ *
3794
+ * @param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.
3795
+ * @param roundingMode The rounding mode to use when representing the value. Defaults to "half-up".
3796
+ */
3797
+ toExponential(
3798
+ fractionDigits: number,
3799
+ roundingMode?: BigDecimalRoundingMode
3800
+ ): string;
3801
+ }
3802
+
3803
+ // Note that BigFloat and BigDecimal have custom operator overloads defined in
3804
+ // QuickJS, but TypeScript does not support operator overloading. As such,
3805
+ // TypeScript will not understand or handle unary/binary operators for BigFloat
3806
+ // and BigDecimal properly.
3807
+
3808
+ // Definitions of the globals and modules added by quickjs-libc
3809
+
3810
+ /**
3811
+ * Provides the command line arguments. The first argument is the script name.
3812
+ */
3813
+ declare var scriptArgs: Array<string>;
3814
+
3815
+ /**
3816
+ * Print the arguments separated by spaces and a trailing newline.
3817
+ *
3818
+ * Non-string args are coerced into a string via [ToString](https://tc39.es/ecma262/#sec-tostring).
3819
+ * Objects can override the default `ToString` behavior by defining a `toString` method.
3820
+ */
3821
+ declare var print: (...args: Array<any>) => void;
3822
+
3823
+ /**
3824
+ * Object that provides functions for logging information.
3825
+ */
3826
+ interface Console {
3827
+ /** Same as {@link print}(). */
3828
+ log: typeof print;
3829
+
3830
+ /** Same as {@link print}(). */
3831
+ warn: typeof print;
3832
+
3833
+ /** Same as {@link print}(). */
3834
+ error: typeof print;
3835
+
3836
+ /** Same as {@link print}(). */
3837
+ info: typeof print;
3838
+ }
3839
+
3840
+ declare var console: Console;
3841
+
3842
+ /** An object representing a file handle. */
3843
+ declare interface FILE {
3844
+ /**
3845
+ * Human-readable description of where this FILE points.
3846
+ *
3847
+ * If `target` is a number, the FILE was opened with fdopen, and `target` is
3848
+ * the fd. Otherwise, `target` will be an arbitrary string that describes the
3849
+ * file; it may be the absolute path to the file, the relative path to the
3850
+ * file at time of its opening, or some other string like "stdin" or
3851
+ * "tmpfile".
2734
3852
  *
2735
3853
  * You should *not* use this property for anything other than logging and
2736
3854
  * debugging. It is *only* provided for debugging and/or troubleshooting
@@ -2804,6 +3922,16 @@ declare interface FILE {
2804
3922
 
2805
3923
  /** Write one byte to the file. */
2806
3924
  putByte(value: number): void;
3925
+
3926
+ /**
3927
+ * Set the buffering mode and buffer size for the file stream (wrapper to the libc `setvbuf()`).
3928
+ *
3929
+ * Note that unlike the libc setvbuf, the "buffer" argument is not supported, and therefore is not present.
3930
+ *
3931
+ * @param mode The buffering mode to use. It can be one of the following values: `std._IOFBF` for full buffering, `std._IOLBF` for line buffering, or `std._IONBF` for no buffering.
3932
+ * @param size The size to resize the internal in-memory buffer for this file to.
3933
+ */
3934
+ setvbuf(mode: number, size: number): void;
2807
3935
  }
2808
3936
 
2809
3937
  declare module "quickjs:std" {
@@ -2820,11 +3948,12 @@ declare module "quickjs:std" {
2820
3948
  * @param code - The code to evaluate.
2821
3949
  * @param options - An optional object containing the following optional properties:
2822
3950
  * @property backtraceBarrier - Boolean (default = false). If true, error backtraces do not list the stack frames below the evalScript.
3951
+ * @property filename - String (default = "<evalScript>"). The filename to associate with the code being executed.
2823
3952
  * @returns The result of the evaluation.
2824
3953
  */
2825
3954
  export function evalScript(
2826
3955
  code: string,
2827
- options?: { backtraceBarrier?: boolean }
3956
+ options?: { backtraceBarrier?: boolean; filename?: string }
2828
3957
  ): any;
2829
3958
 
2830
3959
  /**
@@ -2947,6 +4076,15 @@ declare module "quickjs:std" {
2947
4076
  /** Constant for {@link FILE.seek}. Declares that the offset should be relative to the end of the file. See also libc `fseek()`. */
2948
4077
  export var SEEK_END: number;
2949
4078
 
4079
+ /** Constant for {@link FILE.setvbuf}. Declares that the buffer mode should be 'full buffering'. */
4080
+ export var _IOFBF: number;
4081
+
4082
+ /** Constant for {@link FILE.setvbuf}. Declares that the buffer mode should be 'line buffering'. */
4083
+ export var _IOLBF: number;
4084
+
4085
+ /** Constant for {@link FILE.setvbuf}. Declares that the buffer mode should be 'no buffering'. */
4086
+ export var _IONBF: number;
4087
+
2950
4088
  /** Manually invoke the cycle removal algorithm (garbage collector). The cycle removal algorithm is automatically started when needed, so this function is useful in case of specific memory constraints or for testing. */
2951
4089
  export function gc(): void;
2952
4090
 
@@ -3112,8 +4250,19 @@ declare module "quickjs:os" {
3112
4250
  /** POSIX open flag, used in {@link open}. */
3113
4251
  export var O_TRUNC: number;
3114
4252
 
3115
- /** Windows-specific open flag: open the file in text mode. The default is binary mode. Used in {@link open}. */
3116
- export var O_TEXT: number;
4253
+ /**
4254
+ * Windows-specific open flag: open the file in binary mode (which is the default). Used in {@link open}.
4255
+ *
4256
+ * NOTE: this property is only present on windows
4257
+ */
4258
+ export var O_BINARY: number | undefined;
4259
+
4260
+ /**
4261
+ * Windows-specific open flag: open the file in text mode. The default is binary mode. Used in {@link open}.
4262
+ *
4263
+ * NOTE: this property is only present on windows
4264
+ */
4265
+ export var O_TEXT: number | undefined;
3117
4266
 
3118
4267
  /** Close the file with descriptor `fd`. */
3119
4268
  export function close(fd: number): void;
@@ -3227,26 +4376,167 @@ declare module "quickjs:os" {
3227
4376
  */
3228
4377
  export function lstat(path: string): Stats;
3229
4378
 
3230
- /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
4379
+ /**
4380
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4381
+ *
4382
+ * Mask for getting type of file from mode.
4383
+ */
3231
4384
  export var S_IFMT: number;
3232
- /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
4385
+
4386
+ /**
4387
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4388
+ *
4389
+ * File type: named pipe (fifo)
4390
+ */
3233
4391
  export var S_IFIFO: number;
3234
- /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
4392
+
4393
+ /**
4394
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4395
+ *
4396
+ * File type: character special
4397
+ */
3235
4398
  export var S_IFCHR: number;
3236
- /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
4399
+
4400
+ /**
4401
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4402
+ *
4403
+ * File type: directory
4404
+ */
3237
4405
  export var S_IFDIR: number;
3238
- /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
4406
+
4407
+ /**
4408
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4409
+ *
4410
+ * File type: block special
4411
+ */
3239
4412
  export var S_IFBLK: number;
3240
- /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
4413
+
4414
+ /**
4415
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4416
+ *
4417
+ * File type: regular
4418
+ */
3241
4419
  export var S_IFREG: number;
3242
- /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
3243
- export var S_IFSOCK: number;
3244
- /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
3245
- export var S_IFLNK: number;
3246
- /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
3247
- export var S_ISGID: number;
3248
- /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
3249
- export var S_ISUID: number;
4420
+
4421
+ /**
4422
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4423
+ *
4424
+ * File type: socket
4425
+ *
4426
+ * NOTE: this property is not present on windows
4427
+ */
4428
+ export var S_IFSOCK: number | undefined;
4429
+
4430
+ /**
4431
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4432
+ *
4433
+ * File type: symbolic link
4434
+ *
4435
+ * NOTE: this property is not present on windows
4436
+ */
4437
+ export var S_IFLNK: number | undefined;
4438
+
4439
+ /**
4440
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4441
+ *
4442
+ * Flag: set group id on execution
4443
+ *
4444
+ * NOTE: this property is not present on windows
4445
+ */
4446
+ export var S_ISGID: number | undefined;
4447
+
4448
+ /**
4449
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4450
+ *
4451
+ * Flag: set user id on execution
4452
+ *
4453
+ * NOTE: this property is not present on windows
4454
+ */
4455
+ export var S_ISUID: number | undefined;
4456
+
4457
+ /**
4458
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4459
+ *
4460
+ * Mask for getting RWX permissions for owner
4461
+ */
4462
+ export var S_IRWXU: number;
4463
+
4464
+ /**
4465
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4466
+ *
4467
+ * Permission: read for owner
4468
+ */
4469
+ export var S_IRUSR: number;
4470
+
4471
+ /**
4472
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4473
+ *
4474
+ * Permission: write for owner
4475
+ */
4476
+ export var S_IWUSR: number;
4477
+
4478
+ /**
4479
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4480
+ *
4481
+ * Permission: execute for owner
4482
+ */
4483
+ export var S_IXUSR: number;
4484
+
4485
+ /**
4486
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4487
+ *
4488
+ * Mask for getting RWX permissions for group
4489
+ */
4490
+ export var S_IRWXG: number;
4491
+
4492
+ /**
4493
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4494
+ *
4495
+ * Permission: read for group
4496
+ */
4497
+ export var S_IRGRP: number;
4498
+
4499
+ /**
4500
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4501
+ *
4502
+ * Permission: write for group
4503
+ */
4504
+ export var S_IWGRP: number;
4505
+
4506
+ /**
4507
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4508
+ *
4509
+ * Permission: execute for group
4510
+ */
4511
+ export var S_IXGRP: number;
4512
+
4513
+ /**
4514
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4515
+ *
4516
+ * Mask for getting RWX permissions for others
4517
+ */
4518
+ export var S_IRWXO: number;
4519
+
4520
+ /**
4521
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4522
+ *
4523
+ * Permission: read for others
4524
+ */
4525
+ export var S_IROTH: number;
4526
+
4527
+ /**
4528
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4529
+ *
4530
+ * Permission: write for others
4531
+ */
4532
+ export var S_IWOTH: number;
4533
+
4534
+ /**
4535
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
4536
+ *
4537
+ * Permission: execute for others
4538
+ */
4539
+ export var S_IXOTH: number;
3250
4540
 
3251
4541
  /**
3252
4542
  * Change the access and modification times of the file path.
@@ -3294,6 +4584,39 @@ declare module "quickjs:os" {
3294
4584
  /** POSIX signal number. */
3295
4585
  export var SIGTERM: number;
3296
4586
 
4587
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
4588
+ export var SIGQUIT: number | undefined;
4589
+
4590
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
4591
+ export var SIGPIPE: number | undefined;
4592
+
4593
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
4594
+ export var SIGALRM: number | undefined;
4595
+
4596
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
4597
+ export var SIGUSR1: number | undefined;
4598
+
4599
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
4600
+ export var SIGUSR2: number | undefined;
4601
+
4602
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
4603
+ export var SIGCHLD: number | undefined;
4604
+
4605
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
4606
+ export var SIGCONT: number | undefined;
4607
+
4608
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
4609
+ export var SIGSTOP: number | undefined;
4610
+
4611
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
4612
+ export var SIGTSTP: number | undefined;
4613
+
4614
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
4615
+ export var SIGTTIN: number | undefined;
4616
+
4617
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
4618
+ export var SIGTTOU: number | undefined;
4619
+
3297
4620
  /** Send the signal `sig` to the process `pid`. Use `os.SIG*` constants. */
3298
4621
  export function kill(pid: number, sig: number): void;
3299
4622
 
@@ -3588,29 +4911,19 @@ declare interface InspectFunction {
3588
4911
  declare var inspect: InspectFunction;
3589
4912
 
3590
4913
  /**
3591
- * A class which represents a module namespace object. Note, however, that
3592
- * instances of this class cannot be constructed manually, and must instead be
3593
- * obtained from `import * as`, `import()`, `std.importModule`, or `require`.
4914
+ * A global which lets you configure the module loader (import/export/require).
4915
+ * You can use these properties to add support for importing new filetypes.
3594
4916
  *
3595
- * The static properties on `Module` let you configure the module loader
3596
- * (import/export/require). You can use these properties to add support for
3597
- * importing new filetypes.
4917
+ * This global can also be used to identify whether an object is a module
4918
+ * namespace record.
3598
4919
  */
3599
- declare class Module {
3600
- /** A module namespace object has arbitrary exports. */
3601
- [key: string | number | symbol]: any;
3602
-
3603
- /**
3604
- * Module objects are not constructable.
3605
- *
3606
- * You must instead obtain them using import or require.
3607
- */
3608
- private constructor();
3609
-
4920
+ interface ModuleGlobal {
3610
4921
  /**
3611
4922
  * Returns true if `target` is a module namespace object.
3612
4923
  */
3613
- static [Symbol.hasInstance](target: any): target is Module;
4924
+ [Symbol.hasInstance](target: any): target is {
4925
+ [key: string | number | symbol]: any;
4926
+ };
3614
4927
 
3615
4928
  /**
3616
4929
  * A list of filetype extensions that may be omitted from an import specifier
@@ -3625,7 +4938,7 @@ declare class Module {
3625
4938
  * NOTE: If you add a new extension to this array, you will likely also want
3626
4939
  * to add to {@link Module.compilers}.
3627
4940
  */
3628
- static searchExtensions: Array<string>;
4941
+ searchExtensions: Array<string>;
3629
4942
 
3630
4943
  /**
3631
4944
  * User-defined functions which will handle getting the JavaScript code
@@ -3666,7 +4979,7 @@ declare class Module {
3666
4979
  * NOTE: When adding to this object, you may also wish to add to
3667
4980
  * {@link Module.searchExtensions}.
3668
4981
  */
3669
- static compilers: {
4982
+ compilers: {
3670
4983
  [extensionWithDot: string]: (filename: string, content: string) => string;
3671
4984
  };
3672
4985
 
@@ -3674,63 +4987,71 @@ declare class Module {
3674
4987
  * Create a virtual built-in module whose exports consist of the own
3675
4988
  * enumerable properties of `obj`.
3676
4989
  */
3677
- static define(name: string, obj: { [key: string]: any }): void;
4990
+ define(name: string, obj: { [key: string]: any }): void;
3678
4991
 
3679
4992
  /**
3680
4993
  * Resolves a require/import request from `fromFile` into a canonicalized path.
3681
4994
  *
3682
4995
  * To change native module resolution behavior, replace this function with
3683
- * your own implementation.
4996
+ * your own implementation. Note that you must handle
4997
+ * `Module.searchExtensions` yourself in your replacement implementation.
3684
4998
  */
3685
- static resolve(name: string, fromFile: string): string;
4999
+ resolve(name: string, fromFile: string): string;
3686
5000
 
3687
5001
  /**
3688
5002
  * Reads the contents of the given resolved module name into a string.
3689
5003
  *
3690
5004
  * To change native module loading behavior, replace this function with your
3691
- * own implementation.
5005
+ * own implementation. Note that you must handle `Module.compilers` yourself
5006
+ * in your replacement implementation.
3692
5007
  */
3693
- static read(modulePath: string): string;
5008
+ read(modulePath: string): string;
3694
5009
  }
3695
5010
 
3696
- /**
3697
- * Synchronously import a module.
3698
- *
3699
- * `source` will be resolved relative to the calling file.
3700
- *
3701
- * If `source` does not have a file extension, and a file without an extension
3702
- * cannot be found, the engine will check for files with the extensions in
3703
- * {@link Module.searchExtensions}, and use one of those if present. This
3704
- * behavior also happens when using normal `import` statements.
3705
- *
3706
- * For example, if you write:
3707
- *
3708
- * ```js
3709
- * import something from "./somewhere";
3710
- * ```
3711
- *
3712
- * but there's no file named `somewhere` in the same directory as the file
3713
- * where that import appears, and `Module.searchExtensions` is the default
3714
- * value:
3715
- *
3716
- * ```js
3717
- * [".js"]
3718
- * ```
3719
- *
3720
- * then the engine will look for `somewhere.js`. If that doesn't exist, the
3721
- * engine will look for `somewhere/index.js`. If *that* doesn't exist, an error
3722
- * will be thrown.
3723
- *
3724
- * If you add more extensions to `Module.searchExtensions`, then the engine
3725
- * will use those, too. It will search in the same order as the strings appear
3726
- * in the `Module.searchExtensions` array.
3727
- */
3728
- declare var require: ((source: string) => any) & {
5011
+ declare var Module: ModuleGlobal;
5012
+
5013
+ interface RequireFunction {
5014
+ /**
5015
+ * Synchronously import a module.
5016
+ *
5017
+ * `source` will be resolved relative to the calling file.
5018
+ *
5019
+ * If `source` does not have a file extension, and a file without an extension
5020
+ * cannot be found, the engine will check for files with the extensions in
5021
+ * {@link Module.searchExtensions}, and use one of those if present. This
5022
+ * behavior also happens when using normal `import` statements.
5023
+ *
5024
+ * For example, if you write:
5025
+ *
5026
+ * ```js
5027
+ * import something from "./somewhere";
5028
+ * ```
5029
+ *
5030
+ * but there's no file named `somewhere` in the same directory as the file
5031
+ * where that import appears, and `Module.searchExtensions` is the default
5032
+ * value:
5033
+ *
5034
+ * ```js
5035
+ * [".js"]
5036
+ * ```
5037
+ *
5038
+ * then the engine will look for `somewhere.js`. If that doesn't exist, the
5039
+ * engine will look for `somewhere/index.js`. If *that* doesn't exist, an error
5040
+ * will be thrown.
5041
+ *
5042
+ * If you add more extensions to `Module.searchExtensions`, then the engine
5043
+ * will use those, too. It will search in the same order as the strings appear
5044
+ * in the `Module.searchExtensions` array.
5045
+ */
5046
+ (source: string): any;
5047
+
3729
5048
  /**
3730
5049
  * Resolves the normalized path to a modules, relative to the calling file.
3731
5050
  */
3732
5051
  resolve: (source: string) => string;
3733
- };
5052
+ }
5053
+
5054
+ declare var require: RequireFunction;
3734
5055
 
3735
5056
  declare var setTimeout: typeof import("quickjs:os").setTimeout;
3736
5057
  declare var clearTimeout: typeof import("quickjs:os").clearTimeout;
@@ -3794,41 +5115,207 @@ interface StringConstructor {
3794
5115
  };
3795
5116
  }
3796
5117
 
3797
- interface ObjectConstructor {
5118
+ declare module "quickjs:bytecode" {
3798
5119
  /**
3799
- * Convert the specified value to a primitive value.
3800
- *
3801
- * The provided hint indicates a preferred return type, which may or may not
3802
- * be respected by the engine.
5120
+ * Convert the module or script in the specified file into bytecode.
3803
5121
  *
3804
- * See the abstract operation "ToPrimitive" in the ECMAScript standard for
3805
- * more info.
5122
+ * When converted back to a value, it will be a function.
3806
5123
  */
3807
- toPrimitive(
3808
- input: any,
3809
- hint: "string" | "number" | "default"
3810
- ): string | number | bigint | boolean | undefined | symbol | null;
5124
+ export function fromFile(
5125
+ path: string,
5126
+ options?: { byteSwap?: boolean; sourceType?: "module" | "script" }
5127
+ ): ArrayBuffer;
5128
+
5129
+ /**
5130
+ * Convert the provided value into bytecode. Doesn't work with all values.
5131
+ */
5132
+ export function fromValue(
5133
+ value: any,
5134
+ options?: { byteSwap?: boolean }
5135
+ ): ArrayBuffer;
5136
+
5137
+ /**
5138
+ * Convert the provided bytecode into a value.
5139
+ */
5140
+ export function toValue(bytecode: ArrayBuffer): any;
3811
5141
  }
3812
5142
 
3813
- interface SymbolConstructor {
5143
+ declare module "quickjs:context" {
3814
5144
  /**
3815
- * A method that changes the result of using the `typeof` operator on the
3816
- * object. Called by the semantics of the typeof operator.
3817
- *
3818
- * Note that the following semantics will come into play when use of the
3819
- * `typeof` operator causes the engine to call a `Symbol.typeofValue` method
3820
- * on an object:
3821
- *
3822
- * - If the method returns any value other than one of the string values
3823
- * which are normally the result of using the `typeof` operator, the engine
3824
- * behaves as if no `Symbol.typeofValue` method was present on the object.
3825
- * - If an error is thrown from this method, or an error is thrown while
3826
- * accessing this property, the error will be silently ignored, and the
3827
- * engine will behave as if no `Symbol.typeofValue` method was present on
3828
- * the object.
3829
- * - If this property is present on an object, but the value of that property
3830
- * is not a function, the engine will not consider that value when
3831
- * determining the result of the `typeof` operation (it'll ignore it).
5145
+ * A separate global context (or 'realm') within which code can be executed.
3832
5146
  */
3833
- readonly typeofValue: unique symbol;
5147
+ export class Context {
5148
+ /**
5149
+ * Create a new global context (or 'realm') within code can be executed.
5150
+ *
5151
+ * @param options Options for what globals/modules/etc to make available within the context.
5152
+ *
5153
+ * The following globals are always present, regardless of options:
5154
+ *
5155
+ * - Object
5156
+ * - Function
5157
+ * - Error
5158
+ * - EvalError
5159
+ * - RangeError
5160
+ * - ReferenceError
5161
+ * - SyntaxError
5162
+ * - TypeError
5163
+ * - URIError
5164
+ * - InternalError
5165
+ * - AggregateError
5166
+ * - Array
5167
+ * - parseInt
5168
+ * - parseFloat
5169
+ * - isNaN
5170
+ * - isFinite
5171
+ * - decodeURI
5172
+ * - decodeURIComponent
5173
+ * - encodeURI
5174
+ * - encodeURIComponent
5175
+ * - escape
5176
+ * - unescape
5177
+ * - Infinity
5178
+ * - NaN
5179
+ * - undefined
5180
+ * - __date_clock
5181
+ * - Number
5182
+ * - Boolean
5183
+ * - String
5184
+ * - Math
5185
+ * - Reflect
5186
+ * - Symbol
5187
+ * - eval (but it doesn't work unless the `eval` option is enabled)
5188
+ * - globalThis
5189
+ */
5190
+ constructor(options?: {
5191
+ /** Enables `Date`. Defaults to `true` */
5192
+ date?: boolean;
5193
+
5194
+ /** Enables `eval`. Defaults to `true` */
5195
+ eval?: boolean;
5196
+
5197
+ /** Enables `String.prototype.normalize`. Defaults to `true`. */
5198
+ stringNormalize?: boolean;
5199
+
5200
+ /** Enables `RegExp`. Defaults to `true`. */
5201
+ regExp?: boolean;
5202
+
5203
+ /** Enables `JSON`. Defaults to `true`. */
5204
+ json?: boolean;
5205
+
5206
+ /** Enables `Proxy`. Defaults to `true`. */
5207
+ proxy?: boolean;
5208
+
5209
+ /** Enables `Map` and `Set`. Defaults to `true`. */
5210
+ mapSet?: boolean;
5211
+
5212
+ /**
5213
+ * Enables:
5214
+ *
5215
+ * - ArrayBuffer
5216
+ * - SharedArrayBuffer
5217
+ * - Uint8ClampedArray
5218
+ * - Int8Array
5219
+ * - Uint8Array
5220
+ * - Int16Array
5221
+ * - Uint16Array
5222
+ * - Int32Array
5223
+ * - Uint32Array
5224
+ * - BigInt64Array
5225
+ * - BigUint64Array
5226
+ * - Float32Array
5227
+ * - Float64Array
5228
+ * - DataView
5229
+ *
5230
+ * Defaults to `true`.
5231
+ */
5232
+ typedArrays?: boolean;
5233
+
5234
+ /**
5235
+ * Enables:
5236
+ *
5237
+ * - Promise
5238
+ * - async functions
5239
+ * - async iterators
5240
+ * - async generators
5241
+ *
5242
+ * Defaults to `true`.
5243
+ */
5244
+ promise?: boolean;
5245
+
5246
+ /** Enables `BigInt`. Defaults to `true`. */
5247
+ bigint?: boolean;
5248
+
5249
+ /** Enables `BigFloat`. Defaults to `true`. */
5250
+ bigfloat?: boolean;
5251
+
5252
+ /** Enables `BigDecimal`. Defaults to `true`. */
5253
+ bigdecimal?: boolean;
5254
+
5255
+ /**
5256
+ * Enables:
5257
+ *
5258
+ * - Operators
5259
+ * - OperatorSet creation
5260
+ * - operator overloading
5261
+ *
5262
+ * Defaults to `true`.
5263
+ */
5264
+ operators?: boolean;
5265
+
5266
+ /** Enables "use math". Defaults to `true`. */
5267
+ useMath?: boolean;
5268
+
5269
+ /**
5270
+ * Enables:
5271
+ *
5272
+ * - inspect
5273
+ * - console
5274
+ * - print
5275
+ * - require (and require.resolve)
5276
+ * - setTimeout
5277
+ * - clearTimeout
5278
+ * - setInterval
5279
+ * - clearInterval
5280
+ * - String.cooked
5281
+ * - String.dedent
5282
+ *
5283
+ * Defaults to `true`.
5284
+ *
5285
+ * NOTE: The following globals, normally part of `js_std_add_helpers`, are NEVER added:
5286
+ *
5287
+ * - Module
5288
+ * - scriptArgs
5289
+ *
5290
+ * If you need them in the new context, copy them over from your context's globalThis onto the child context's globalThis.
5291
+ */
5292
+ stdHelpers?: boolean;
5293
+
5294
+ /** Enable builtin modules. */
5295
+ modules?: {
5296
+ /** Enables the "quickjs:std" module. Defaults to `true`. */
5297
+ "quickjs:std"?: boolean;
5298
+ /** Enables the "quickjs:os" module. Defaults to `true`. */
5299
+ "quickjs:os"?: boolean;
5300
+ /** Enables the "quickjs:bytecode" module. Defaults to `true`. */
5301
+ "quickjs:bytecode"?: boolean;
5302
+ /** Enables the "quickjs:context" module. Defaults to `true`. */
5303
+ "quickjs:context"?: boolean;
5304
+ };
5305
+ });
5306
+
5307
+ /**
5308
+ * The `globalThis` object used by this context.
5309
+ *
5310
+ * You can add to or remove from it to change what is visible to the context.
5311
+ */
5312
+ globalThis: typeof globalThis;
5313
+
5314
+ /**
5315
+ * Runs code within the context and returns the result.
5316
+ *
5317
+ * @param code The code to run.
5318
+ */
5319
+ eval(code: string): any;
5320
+ }
3834
5321
  }