yavascript 0.0.11 → 0.0.12

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
@@ -24,8 +24,11 @@ declare var help: {
24
24
  *
25
25
  * If the value is later passed into the `help` function, the provided text
26
26
  * will be printed.
27
+ *
28
+ * To set help text for the values `null` or `undefined`, `allowNullish`
29
+ * must be `true`.
27
30
  */
28
- (value: object, text: string): void;
31
+ (value: object, text: string, allowNullish?: boolean): void;
29
32
 
30
33
  /**
31
34
  * Lazily sets the help text for the provided value using the provided
@@ -249,14 +252,6 @@ declare function remove(path: string | Path): void;
249
252
  */
250
253
  declare function exists(path: string | Path): boolean;
251
254
 
252
- /**
253
- * Creates directories for each of the provided path components,
254
- * if they don't already exist.
255
- *
256
- * Provides the same functionality as the command `mkdir -p`.
257
- */
258
- declare function ensureDir(path: string | Path): string;
259
-
260
255
  /**
261
256
  * Options for {@link copy}.
262
257
  */
@@ -269,17 +264,34 @@ declare type CopyOptions = {
269
264
  */
270
265
  whenTargetExists?: "overwrite" | "skip" | "error";
271
266
 
272
- /**
273
- * If provided, this function will be called multiple times as `copy`
274
- * traverses the filesystem, to help you understand what's going on and/or
275
- * troubleshoot things. In most cases, it makes sense to use a logging
276
- * function here, like so:
277
- *
278
- * ```js
279
- * copy("./source", "./destination", { trace: console.log });
280
- * ```
281
- */
282
- trace?: (...args: Array<any>) => void;
267
+ /** Options which control logging. */
268
+ logging?: {
269
+ /**
270
+ * If provided, this function will be called multiple times as `copy`
271
+ * traverses the filesystem, to help you understand what's going on and/or
272
+ * troubleshoot things. In most cases, it makes sense to use a logging
273
+ * function here, like so:
274
+ *
275
+ * ```js
276
+ * copy("./source", "./destination", {
277
+ * logging: { trace: console.log },
278
+ * });
279
+ * ```
280
+ *
281
+ * Defaults to the current value of {@link logger.trace}. `logger.trace`
282
+ * defaults to a no-op function.
283
+ */
284
+ trace?: (...args: Array<any>) => void;
285
+
286
+ /**
287
+ * An optional, user-provided logging function to be used for informational
288
+ * messages.
289
+ *
290
+ * Defaults to the current value of {@link logger.info}. `logger.info`
291
+ * defaults to a function which writes to stderr.
292
+ */
293
+ info?: (...args: Array<any>) => void;
294
+ };
283
295
  };
284
296
 
285
297
  /**
@@ -316,7 +328,7 @@ declare class Path {
316
328
  * A list of suffixes that could appear in the filename for a program on the
317
329
  * current OS. For instance, on Windows, programs often end with ".exe".
318
330
  *
319
- * On Unix-like OSes, this is empty, On Windows, it's based on `env.PATHEXT`.
331
+ * On Unix-like OSes, this is empty. On Windows, it's based on `env.PATHEXT`.
320
332
  */
321
333
  static readonly OS_PROGRAM_EXTENSIONS: ReadonlySet<string>;
322
334
 
@@ -334,16 +346,6 @@ declare class Path {
334
346
  fallback: Fallback = Path.OS_SEGMENT_SEPARATOR
335
347
  ): string | Fallback;
336
348
 
337
- /** Join together one or more paths. */
338
- static join(...inputs: Array<string | Path | Array<string | Path>>): Path;
339
-
340
- /**
341
- * Turns the input path(s) into an absolute path by resolving all `.` and `..`
342
- * segments, using `pwd()` as a base dir to use when resolving leading `.` or
343
- * `..` segments.
344
- */
345
- static resolve(...inputs: Array<string | Path | Array<string | Path>>): Path;
346
-
347
349
  /**
348
350
  * Concatenates the input path(s) and then resolves all non-leading `.` and
349
351
  * `..` segments.
@@ -377,15 +379,12 @@ declare class Path {
377
379
  /** Create a new Path object using the provided input(s). */
378
380
  constructor(...inputs: Array<string | Path | Array<string | Path>>);
379
381
 
380
- /** Create a new Path object using the provided segments and separator. */
381
- static from(segments: Array<string>, separator: string): Path;
382
-
383
382
  /**
384
- * Create an absolute path by `concat`ting `subpaths` onto this Path (which is
385
- * presumed to be an absolute path) and then using `normalize()` on the
386
- * result. If the result is not an absolute path, an error will be thrown.
383
+ * Create a new Path object using the provided segments and separator.
384
+ *
385
+ * If unspecified, `separator` defaults to `Path.OS_SEGMENT_SEPARATOR`.
387
386
  */
388
- resolve(...subpaths: Array<string | Path>): Path;
387
+ static fromRaw(segments: Array<string>, separator?: string): Path;
389
388
 
390
389
  /**
391
390
  * Resolve all non-leading `.` and `..` segments in this path.
@@ -452,6 +451,12 @@ declare class Path {
452
451
  */
453
452
  extname(options?: { full?: boolean }): string;
454
453
 
454
+ /**
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.
457
+ */
458
+ dirname(): Path;
459
+
455
460
  /**
456
461
  * Return whether this path starts with the provided value, by comparing one
457
462
  * path segment at a time.
@@ -569,9 +574,36 @@ declare var __dirname: string;
569
574
  declare function basename(path: string | Path): string;
570
575
 
571
576
  /**
572
- * Reads the contents of one of more files from disk as one UTF-8 string.
577
+ * Reads the contents of one or more files from disk as either one UTF-8 string
578
+ * or one ArrayBuffer.
573
579
  */
574
- declare function cat(...paths: Array<string | Path>): string;
580
+ declare const cat: {
581
+ /**
582
+ * Read the contents of one or more files from disk, as one UTF-8 string.
583
+ */
584
+ (paths: string | Path | Array<string | Path>): string;
585
+
586
+ /**
587
+ * Read the contents of one or more files from disk, as one UTF-8 string.
588
+ */
589
+ (paths: string | Path | Array<string | Path>, options: {}): string;
590
+
591
+ /**
592
+ * Read the contents of one or more files from disk, as one UTF-8 string.
593
+ */
594
+ (
595
+ paths: string | Path | Array<string | Path>,
596
+ options: { binary: false }
597
+ ): string;
598
+
599
+ /**
600
+ * Read the contents of one or more files from disk, as one ArrayBuffer.
601
+ */
602
+ (
603
+ paths: string | Path | Array<string | Path>,
604
+ options: { binary: true }
605
+ ): ArrayBuffer;
606
+ };
575
607
 
576
608
  /**
577
609
  * Change the process's current working directory to the specified path. If no
@@ -637,6 +669,22 @@ declare function dirname(path: string | Path): Path;
637
669
  */
638
670
  declare const echo: typeof console.log;
639
671
 
672
+ /**
673
+ * Exit the yavascript process.
674
+ *
675
+ * Provides the same functionality as the shell builtin of the same name.
676
+ *
677
+ * If exit is called with an argument, that argument is used as the exit code.
678
+ * Otherwise, `exit.code` is used, which defaults to 0.
679
+ *
680
+ * `exit.code` will also be used as the exit status code for the yavascript
681
+ * process if the process exits normally.
682
+ */
683
+ declare const exit: {
684
+ (code?: number): never;
685
+ code: number;
686
+ };
687
+
640
688
  /**
641
689
  * Returns the file extension of the file at a given path.
642
690
  *
@@ -655,6 +703,41 @@ declare function extname(
655
703
  */
656
704
  declare function ls(dir?: string | Path): Array<Path>;
657
705
 
706
+ /**
707
+ * Create a directory (folder).
708
+ *
709
+ * Provides the same functionality as the unix binary of the same name.
710
+ */
711
+ declare function mkdir(
712
+ path: string | Path,
713
+ options?: {
714
+ recursive?: boolean;
715
+ mode?: number;
716
+ logging?: {
717
+ trace?: (...args: Array<any>) => void;
718
+ info?: (...args: Array<any>) => void;
719
+ };
720
+ }
721
+ ): void;
722
+
723
+ /**
724
+ * Create a directory (folder) and all parents, recursively
725
+ *
726
+ * Alias for `mkdir(path, { recursive: true })`.
727
+ *
728
+ * Provides the same functionality as `mkdir -p`.
729
+ */
730
+ declare function mkdirp(
731
+ path: string | Path,
732
+ options?: {
733
+ mode?: number;
734
+ logging?: {
735
+ trace?: (...args: Array<any>) => void;
736
+ info?: (...args: Array<any>) => void;
737
+ };
738
+ }
739
+ ): void;
740
+
658
741
  /**
659
742
  * Print data to stdout using C-style format specifiers.
660
743
  *
@@ -754,14 +837,42 @@ declare function touch(path: string | Path): void;
754
837
  * @param options Options which affect how the search is performed
755
838
  * @param options.searchPaths A list of folders where programs may be found. Defaults to `env.PATH?.split(Path.OS_ENV_VAR_SEPARATOR) || []`.
756
839
  * @param options.suffixes A list of filename extension suffixes to include in the search, ie [".exe"]. Defaults to `Path.OS_PROGRAM_EXTENSIONS`.
757
- * @param options.trace A logging function that will be called at various times during the execution of `which`. Defaults to `traceAll.getDefaultTrace()`.
840
+ * @param options.trace A logging function that will be called at various times during the execution of `which`. Defaults to {@link logger.trace}.
758
841
  */
759
842
  declare function which(
760
843
  binaryName: string,
761
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
+ */
762
849
  searchPaths?: Array<Path | string>;
850
+
851
+ /**
852
+ * A list of filename extension suffixes to include in the search, ie
853
+ * `[".exe"]`. Defaults to {@link Path.OS_PROGRAM_EXTENSIONS}.
854
+ */
763
855
  suffixes?: Array<string>;
764
- trace?: (...args: Array<any>) => void;
856
+
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
+ };
765
876
  }
766
877
  ): Path | null;
767
878
 
@@ -772,16 +883,34 @@ declare type BaseExecOptions = {
772
883
  /** Sets environment variables within the process. */
773
884
  env?: { [key: string | number]: string | number | boolean };
774
885
 
775
- /**
776
- * If provided, this function will be called multiple times as `exec`
777
- * runs, to help you understand what's going on and/or troubleshoot things.
778
- * In most cases, it makes sense to use a logging function here, like so:
779
- *
780
- * ```js
781
- * exec(["echo", "hi"], { trace: console.log });
782
- * ```
783
- */
784
- trace?: (...args: Array<any>) => void;
886
+ /** Options which control logging. */
887
+ logging?: {
888
+ /**
889
+ * If provided, this logging function will be called multiple times as
890
+ * `exec` runs, to help you understand what's going on and/or troubleshoot
891
+ * things. In most cases, it makes sense to use a function from `console`
892
+ * here, like so:
893
+ *
894
+ * ```js
895
+ * exec(["echo", "hi"], {
896
+ * logging: { trace: console.log },
897
+ * });
898
+ * ```
899
+ *
900
+ * Defaults to the current value of {@link logger.trace}. `logger.trace`
901
+ * defaults to a no-op function.
902
+ */
903
+ trace?: (...args: Array<any>) => void;
904
+
905
+ /**
906
+ * An optional, user-provided logging function to be used for informational
907
+ * messages. Less verbose than `logging.trace`.
908
+ *
909
+ * Defaults to the current value of {@link logger.info}. `logger.info`
910
+ * defaults to a function which logs to stderr.
911
+ */
912
+ info?: (...args: Array<any>) => void;
913
+ };
785
914
 
786
915
  /**
787
916
  * Whether an Error should be thrown when the process exits with a nonzero
@@ -798,139 +927,46 @@ declare type BaseExecOptions = {
798
927
  * Defaults to false. true is an alias for "utf8".
799
928
  */
800
929
  captureOutput?: boolean | "utf8" | "arraybuffer";
801
- };
802
930
 
803
- declare interface Exec {
804
- (
805
- args: Array<string | Path | number> | string | Path,
806
- options: BaseExecOptions & {
807
- failOnNonZeroStatus: true;
808
- captureOutput: false;
809
- }
810
- ): void;
811
-
812
- (
813
- args: Array<string | Path | number> | string | Path,
814
- options: BaseExecOptions & {
815
- failOnNonZeroStatus: false;
816
- captureOutput: false;
817
- }
818
- ):
819
- | { status: number; signal: undefined }
820
- | { status: undefined; signal: number };
821
-
822
- (
823
- args: Array<string | Path | number> | string | Path,
824
- options: BaseExecOptions & {
825
- failOnNonZeroStatus: true;
826
- captureOutput: true;
827
- }
828
- ): { stdout: string; stderr: string };
829
-
830
- (
831
- args: Array<string | Path | number> | string | Path,
832
- options: BaseExecOptions & {
833
- failOnNonZeroStatus: true;
834
- captureOutput: "utf8";
835
- }
836
- ): { stdout: string; stderr: string };
837
-
838
- (
839
- args: Array<string | Path | number> | string | Path,
840
- options: BaseExecOptions & {
841
- failOnNonZeroStatus: true;
842
- captureOutput: "arraybuffer";
843
- }
844
- ): { stdout: ArrayBuffer; stderr: ArrayBuffer };
845
-
846
- (
847
- args: Array<string | Path | number> | string | Path,
848
- options: BaseExecOptions & {
849
- failOnNonZeroStatus: false;
850
- captureOutput: true;
851
- }
852
- ):
853
- | { stdout: string; stderr: string; status: number; signal: undefined }
854
- | { stdout: string; stderr: string; status: undefined; signal: number };
855
-
856
- (
857
- args: Array<string | Path | number> | string | Path,
858
- options: BaseExecOptions & {
859
- failOnNonZeroStatus: false;
860
- captureOutput: "utf-8";
861
- }
862
- ):
863
- | { stdout: string; stderr: string; status: number; signal: undefined }
864
- | { stdout: string; stderr: string; status: undefined; signal: number };
931
+ /**
932
+ * If true, exec doesn't return until the process is done running. If false,
933
+ * exec returns an object with a "wait" method which can be used to wait for
934
+ * the process to be done running.
935
+ *
936
+ * Defaults to true.
937
+ */
938
+ block?: boolean;
939
+ };
865
940
 
866
- (
867
- args: Array<string | Path | number> | string | Path,
868
- options: BaseExecOptions & {
869
- failOnNonZeroStatus: false;
870
- captureOutput: "arraybuffer";
871
- }
872
- ):
873
- | {
874
- stdout: ArrayBuffer;
875
- stderr: ArrayBuffer;
876
- status: number;
877
- signal: undefined;
878
- }
879
- | {
880
- stdout: ArrayBuffer;
881
- stderr: ArrayBuffer;
882
- status: undefined;
883
- signal: number;
884
- };
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;
885
956
 
886
- (
887
- args: Array<string | Path | number> | string | Path,
888
- options: BaseExecOptions & {
957
+ declare interface Exec {
958
+ <
959
+ ExecOptions extends BaseExecOptions = {
889
960
  failOnNonZeroStatus: true;
890
- }
891
- ): void;
892
-
893
- (
894
- args: Array<string | Path | number> | string | Path,
895
- options: BaseExecOptions & {
896
- failOnNonZeroStatus: false;
897
- }
898
- ):
899
- | { status: number; signal: undefined }
900
- | { status: undefined; signal: number };
901
-
902
- (
903
- args: Array<string | Path | number> | string | Path,
904
- options: BaseExecOptions & {
905
- captureOutput: true;
906
- }
907
- ): { stdout: string; stderr: string };
908
-
909
- (
910
- args: Array<string | Path | number> | string | Path,
911
- options: BaseExecOptions & {
912
- captureOutput: "utf8";
913
- }
914
- ): { stdout: string; stderr: string };
915
-
916
- (
917
- args: Array<string | Path | number> | string | Path,
918
- options: BaseExecOptions & {
919
- captureOutput: "arraybuffer";
920
- }
921
- ): { stdout: ArrayBuffer; stderr: ArrayBuffer };
922
-
923
- (
924
- args: Array<string | Path | number> | string | Path,
925
- options: BaseExecOptions & {
926
961
  captureOutput: false;
962
+ block: true;
927
963
  }
928
- ): void;
929
-
930
- (
964
+ >(
931
965
  args: Array<string | Path | number> | string | Path,
932
- options?: BaseExecOptions
933
- ): void;
966
+ options?: ExecOptions
967
+ ): ExecOptions["block"] extends false
968
+ ? { wait(): ExecWaitResult<ExecOptions> }
969
+ : ExecWaitResult<ExecOptions>;
934
970
 
935
971
  /**
936
972
  * Parse the provided value into an array of command-line argument strings,
@@ -980,12 +1016,6 @@ declare interface ChildProcess {
980
1016
  err: FILE;
981
1017
  };
982
1018
 
983
- /**
984
- * Optional trace function which, if present, will be called at various times
985
- * to provide information about the lifecycle of the process.
986
- */
987
- trace?: (...args: Array<any>) => void;
988
-
989
1019
  pid: number | null;
990
1020
 
991
1021
  /** Spawns the process and returns its pid (process id). */
@@ -1022,11 +1052,17 @@ declare type ChildProcessOptions = {
1022
1052
  err?: FILE;
1023
1053
  };
1024
1054
 
1025
- /**
1026
- * Optional trace function which, if present, will be called at various times
1027
- * to provide information about the lifecycle of the process.
1028
- */
1029
- trace?: (...args: Array<any>) => void;
1055
+ /** Options which control logging */
1056
+ logging?: {
1057
+ /**
1058
+ * Optional trace function which, if present, will be called at various
1059
+ * times to provide information about the lifecycle of the process.
1060
+ *
1061
+ * Defaults to the current value of {@link logger.trace}. `logger.trace`
1062
+ * defaults to a function which writes to stderr.
1063
+ */
1064
+ trace?: (...args: Array<any>) => void;
1065
+ };
1030
1066
  };
1031
1067
 
1032
1068
  declare interface ChildProcessConstructor {
@@ -1058,17 +1094,34 @@ declare type GlobOptions = {
1058
1094
  */
1059
1095
  followSymlinks?: boolean;
1060
1096
 
1061
- /**
1062
- * If provided, this function will be called multiple times as `glob`
1063
- * traverses the filesystem, to help you understand what's going on and/or
1064
- * troubleshoot things. In most cases, it makes sense to use a logging
1065
- * function here, like so:
1066
- *
1067
- * ```js
1068
- * glob(["./*.js"], { trace: console.log });
1069
- * ```
1070
- */
1071
- trace?: (...args: Array<any>) => void;
1097
+ /** Options which control logging. */
1098
+ logging?: {
1099
+ /**
1100
+ * If provided, this function will be called multiple times as `glob`
1101
+ * traverses the filesystem, to help you understand what's going on and/or
1102
+ * troubleshoot things. In most cases, it makes sense to use a logging
1103
+ * function here, like so:
1104
+ *
1105
+ * ```js
1106
+ * glob(["./*.js"], {
1107
+ * logging: { trace: console.log }
1108
+ * });
1109
+ * ```
1110
+ *
1111
+ * Defaults to the current value of {@link logger.trace}. `logger.trace`
1112
+ * defaults to a no-op function.
1113
+ */
1114
+ trace?: (...args: Array<any>) => void;
1115
+
1116
+ /**
1117
+ * An optional, user-provided logging function to be used for informational
1118
+ * messages. Less verbose than `logging.trace`.
1119
+ *
1120
+ * Defaults to the current value of {@link logger.info}. `logger.info`
1121
+ * defaults to a function which writes to stderr.
1122
+ */
1123
+ info?: (...args: Array<any>) => void;
1124
+ };
1072
1125
 
1073
1126
  /**
1074
1127
  * Directory to interpret glob patterns relative to. Defaults to `pwd()`.
@@ -1100,73 +1153,73 @@ interface Console {
1100
1153
  /**
1101
1154
  * Remove ANSI control characters from a string.
1102
1155
  */
1103
- declare function stripAnsi(input: string): string;
1156
+ declare function stripAnsi(input: string | number | Path): string;
1104
1157
 
1105
1158
  /**
1106
1159
  * Wrap a string in double quotes, and escape any double-quotes inside using `\"`.
1107
1160
  */
1108
- declare function quote(input: string | Path): string;
1161
+ declare function quote(input: string | number | Path): string;
1109
1162
 
1110
1163
  // Colors
1111
1164
 
1112
1165
  /** Wrap a string with the ANSI control characters that will make it print as black text. */
1113
- declare function black(input: string | number): string;
1166
+ declare function black(input: string | number | Path): string;
1114
1167
  /** Wrap a string with the ANSI control characters that will make it print as red text. */
1115
- declare function red(input: string | number): string;
1168
+ declare function red(input: string | number | Path): string;
1116
1169
  /** Wrap a string with the ANSI control characters that will make it print as green text. */
1117
- declare function green(input: string | number): string;
1170
+ declare function green(input: string | number | Path): string;
1118
1171
  /** Wrap a string with the ANSI control characters that will make it print as yellow text. */
1119
- declare function yellow(input: string | number): string;
1172
+ declare function yellow(input: string | number | Path): string;
1120
1173
  /** Wrap a string with the ANSI control characters that will make it print as blue text. */
1121
- declare function blue(input: string | number): string;
1174
+ declare function blue(input: string | number | Path): string;
1122
1175
  /** Wrap a string with the ANSI control characters that will make it print as magenta text. */
1123
- declare function magenta(input: string | number): string;
1176
+ declare function magenta(input: string | number | Path): string;
1124
1177
  /** Wrap a string with the ANSI control characters that will make it print as cyan text. */
1125
- declare function cyan(input: string | number): string;
1178
+ declare function cyan(input: string | number | Path): string;
1126
1179
  /** Wrap a string with the ANSI control characters that will make it print as white text. */
1127
- declare function white(input: string | number): string;
1180
+ declare function white(input: string | number | Path): string;
1128
1181
  /** Wrap a string with the ANSI control characters that will make it print as gray text. */
1129
- declare function gray(input: string | number): string;
1182
+ declare function gray(input: string | number | Path): string;
1130
1183
  /** Wrap a string with the ANSI control characters that will make it print as grey text. */
1131
- declare function grey(input: string | number): string;
1184
+ declare function grey(input: string | number | Path): string;
1132
1185
 
1133
1186
  // Background Colors
1134
1187
 
1135
1188
  /** Wrap a string with the ANSI control characters that will make it have a black background. */
1136
- declare function bgBlack(input: string | number): string;
1189
+ declare function bgBlack(input: string | number | Path): string;
1137
1190
  /** Wrap a string with the ANSI control characters that will make it have a red background. */
1138
- declare function bgRed(input: string | number): string;
1191
+ declare function bgRed(input: string | number | Path): string;
1139
1192
  /** Wrap a string with the ANSI control characters that will make it have a green background. */
1140
- declare function bgGreen(input: string | number): string;
1193
+ declare function bgGreen(input: string | number | Path): string;
1141
1194
  /** Wrap a string with the ANSI control characters that will make it have a yellow background. */
1142
- declare function bgYellow(input: string | number): string;
1195
+ declare function bgYellow(input: string | number | Path): string;
1143
1196
  /** Wrap a string with the ANSI control characters that will make it have a blue background. */
1144
- declare function bgBlue(input: string | number): string;
1197
+ declare function bgBlue(input: string | number | Path): string;
1145
1198
  /** Wrap a string with the ANSI control characters that will make it have a magenta background. */
1146
- declare function bgMagenta(input: string | number): string;
1199
+ declare function bgMagenta(input: string | number | Path): string;
1147
1200
  /** Wrap a string with the ANSI control characters that will make it have a cyan background. */
1148
- declare function bgCyan(input: string | number): string;
1201
+ declare function bgCyan(input: string | number | Path): string;
1149
1202
  /** Wrap a string with the ANSI control characters that will make it have a white background. */
1150
- declare function bgWhite(input: string | number): string;
1203
+ declare function bgWhite(input: string | number | Path): string;
1151
1204
 
1152
1205
  // Modifiers
1153
1206
 
1154
1207
  /** Wrap a string with the ANSI control character that resets all styling. */
1155
- declare function reset(input: string | number): string;
1208
+ declare function reset(input: string | number | Path): string;
1156
1209
  /** Wrap a string with the ANSI control characters that will make it print with a bold style. */
1157
- declare function bold(input: string | number): string;
1210
+ declare function bold(input: string | number | Path): string;
1158
1211
  /** Wrap a string with the ANSI control characters that will make it print with a dimmed style. */
1159
- declare function dim(input: string | number): string;
1212
+ declare function dim(input: string | number | Path): string;
1160
1213
  /** Wrap a string with the ANSI control characters that will make it print italicized. */
1161
- declare function italic(input: string | number): string;
1214
+ declare function italic(input: string | number | Path): string;
1162
1215
  /** Wrap a string with the ANSI control characters that will make it print underlined. */
1163
- declare function underline(input: string | number): string;
1216
+ declare function underline(input: string | number | Path): string;
1164
1217
  /** Wrap a string with ANSI control characters such that its foreground (text) and background colors are swapped. */
1165
- declare function inverse(input: string | number): string;
1218
+ declare function inverse(input: string | number | Path): string;
1166
1219
  /** Wrap a string with ANSI control characters such that it is hidden. */
1167
- declare function hidden(input: string | number): string;
1220
+ declare function hidden(input: string | number | Path): string;
1168
1221
  /** Wrap a string with the ANSI control characters that will make it print with a horizontal line through its center. */
1169
- declare function strikethrough(input: string | number): string;
1222
+ declare function strikethrough(input: string | number | Path): string;
1170
1223
 
1171
1224
  /** Split `str` on newline and then return lines matching `pattern`. */
1172
1225
  declare const grepString: {
@@ -1562,17 +1615,9 @@ declare const types: {
1562
1615
  exactSymbol<T extends symbol>(sym: T): TypeValidator<T>;
1563
1616
  hasClassName<Name extends string>(
1564
1617
  name: Name
1565
- ): TypeValidator<{
1566
- constructor: Function & {
1567
- name: Name;
1568
- };
1569
- }>;
1618
+ ): TypeValidator<{ constructor: Function & { name: Name } }>;
1570
1619
  hasToStringTag(name: string): TypeValidator<any>;
1571
- instanceOf<
1572
- Klass extends Function & {
1573
- prototype: any;
1574
- }
1575
- >(
1620
+ instanceOf<Klass extends Function & { prototype: any }>(
1576
1621
  klass: Klass
1577
1622
  ): TypeValidator<Klass["prototype"]>;
1578
1623
  stringMatching(regexp: RegExp): TypeValidator<string>;
@@ -2690,7 +2735,6 @@ declare const types: {
2690
2735
  ) => TypeValidator<UnwrapTypeFromCoerceableOrValidator<V>>;
2691
2736
 
2692
2737
  FILE: TypeValidator<FILE>;
2693
- Module: TypeValidator<{ [key: string]: unknown }>;
2694
2738
  Path: TypeValidator<Path>;
2695
2739
  JSX: {
2696
2740
  unknownElement: TypeValidator<
@@ -2745,83 +2789,6 @@ declare const assert: {
2745
2789
  ) => asserts value is UnwrapTypeFromCoerceableOrValidator<T>;
2746
2790
  };
2747
2791
 
2748
- /**
2749
- * The data source of a pipe operation; either an in-memory object, or a
2750
- * file stream.
2751
- *
2752
- * - Use `maxLength` to limit how much data to read.
2753
- * - Use `until` to stop reading once a certain byte or character has been
2754
- * read.
2755
- * - Use `path` or `fd` to open a file (or pass a FILE or Path object).
2756
- */
2757
- declare type PipeSource =
2758
- | { data: string; maxLength?: number; until?: string | byte }
2759
- | ArrayBuffer
2760
- | { data: ArrayBuffer; maxLength?: number; until?: string | byte }
2761
- | SharedArrayBuffer
2762
- | { data: SharedArrayBuffer; maxLength?: number; until?: string | byte }
2763
- | TypedArray
2764
- | { data: TypedArray; maxLength?: number; until?: string | byte }
2765
- | DataView
2766
- | { data: DataView; maxLength?: number; until?: string | byte }
2767
- | FILE
2768
- | { data: FILE; maxLength?: number; until?: string | byte }
2769
- | Path
2770
- | { path: Path | string; maxLength?: number; until?: string | byte }
2771
- | { fd: number; maxLength?: number; until?: string | byte };
2772
-
2773
- /**
2774
- * The target destination of a pipe operation; either an in-memory object, or a
2775
- * file stream.
2776
- *
2777
- * - Use `intoExisting` to put data into an existing object or file handle.
2778
- * - Use `intoNew` to put data into a new object.
2779
- * - Use `path` or `fd` to create a new file handle and put data into it.
2780
- */
2781
- declare type PipeDestination =
2782
- | ArrayBuffer
2783
- | SharedArrayBuffer
2784
- | DataView
2785
- | TypedArray
2786
- | Path
2787
- | FILE
2788
- | ArrayBufferConstructor
2789
- | SharedArrayBufferConstructor
2790
- | DataViewConstructor
2791
- | TypedArrayConstructor
2792
- | StringConstructor
2793
- | { path: string }
2794
- | { fd: number };
2795
-
2796
- /**
2797
- * Copy data from one source into the given target. Returns the number of bytes
2798
- * written, and the target that data was written into.
2799
- */
2800
- declare function pipe<Dest extends PipeDestination>(
2801
- from: PipeSource,
2802
- to: Dest
2803
- ): {
2804
- bytesTransferred: number;
2805
- target: Dest extends
2806
- | ArrayBuffer
2807
- | SharedArrayBuffer
2808
- | DataView
2809
- | FILE
2810
- | { path: string }
2811
- | { fd: number }
2812
- ? Dest
2813
- : Dest extends
2814
- | ArrayBufferConstructor
2815
- | SharedArrayBufferConstructor
2816
- | DataViewConstructor
2817
- | TypedArrayConstructor
2818
- | DataViewConstructor
2819
- ? Dest["prototype"]
2820
- : Dest extends StringConstructor
2821
- ? string
2822
- : never;
2823
- };
2824
-
2825
2792
  interface InteractivePrompt {
2826
2793
  prompt?: () => string;
2827
2794
  printInput?: (input: string) => void;
@@ -2883,6 +2850,7 @@ declare const startRepl: {
2883
2850
  | "tsx"
2884
2851
  | "coffee"
2885
2852
  | "coffeescript"
2853
+ | "civet"
2886
2854
  ): void;
2887
2855
 
2888
2856
  /**
@@ -2950,28 +2918,32 @@ declare class GitRepo {
2950
2918
  }
2951
2919
 
2952
2920
  /**
2953
- * Configures the default value of `trace` in yavascript API functions which
2954
- * receive `trace` as an option, like {@link which}, {@link exec}, {@link copy}
2955
- * and {@link glob}.
2921
+ * The logger used internally by yavascript API functions such as {@link which},
2922
+ * {@link exec}, {@link copy}, {@link glob}, and more.
2956
2923
  *
2957
- * - If called with `true`, the default value of `trace` in all functions which
2958
- * receive a `trace` option will be changed to `console.error`.
2959
- * - If called with `false`, the default value of `trace` in all functions which
2960
- * receive a `trace` option will be changed to `undefined`.
2961
- * - If called with any other value, the provided value will be used as the
2962
- * default value of `trace` in all functions which receive a `trace` option.
2924
+ * You can modify the properties on this object in order to configure the
2925
+ * amount and style of log output from yavascript API functions.
2963
2926
  *
2964
- * If you would like to make your own functions use the default value of `trace`
2965
- * as set by this function (in order to get the same behavior as yavascript API
2966
- * functions which do so), call `traceAll.getDefaultTrace()` to get the current
2967
- * value which should be used as the default value.
2968
- *
2969
- * `traceAll` provides similar functionality to shell builtin `set -x`.
2927
+ * This object behaves similarly to the shell builtin `set -x`.
2970
2928
  */
2971
- declare const traceAll: ((
2972
- trace: boolean | undefined | ((...args: Array<any>) => void)
2973
- ) => void) & {
2974
- getDefaultTrace(): ((...args: Array<any>) => void) | undefined;
2929
+ declare const logger: {
2930
+ /**
2931
+ * This property is used as the default value for `trace` in yavascript API
2932
+ * functions which receive `logging.trace` as an option, like {@link which},
2933
+ * {@link exec}, {@link copy} and {@link glob}.
2934
+ *
2935
+ * The default value of `logger.trace` is a no-op function.
2936
+ */
2937
+ trace: (...args: Array<any>) => void;
2938
+
2939
+ /**
2940
+ * This property is used as the default value for `info` in yavascript API
2941
+ * functions which receive `logging.info` as an option, like {@link exec},
2942
+ * {@link copy}, and {@link glob}.
2943
+ *
2944
+ * The default value of `logger.info` writes dimmed text to stdout.
2945
+ */
2946
+ info: (...args: Array<any>) => void;
2975
2947
  };
2976
2948
 
2977
2949
  declare namespace JSX {
@@ -3122,11 +3094,66 @@ declare const CSV: {
3122
3094
  stringify(input: Array<Array<string>>): string;
3123
3095
  };
3124
3096
 
3097
+ declare var TOML: {
3098
+ /**
3099
+ * Parse a TOML document (`data`) into an object.
3100
+ */
3101
+ parse(data: string): { [key: string]: any };
3102
+ /**
3103
+ * Convert an object into a TOML document.
3104
+ */
3105
+ stringify(data: { [key: string]: any }): string;
3106
+ };
3107
+
3125
3108
  interface RegExpConstructor {
3126
3109
  /** See https://github.com/tc39/proposal-regex-escaping */
3127
3110
  escape(str: any): string;
3128
3111
  }
3129
3112
 
3113
+ interface StringConstructor {
3114
+ /**
3115
+ * Remove leading minimum indentation from the string.
3116
+ * The first line of the string must be empty.
3117
+ *
3118
+ * https://github.com/tc39/proposal-string-dedent
3119
+ */
3120
+ dedent: {
3121
+ /**
3122
+ * Remove leading minimum indentation from the string.
3123
+ * The first line of the string must be empty.
3124
+ *
3125
+ * https://github.com/tc39/proposal-string-dedent
3126
+ */
3127
+ (input: string): string;
3128
+
3129
+ /**
3130
+ * Remove leading minimum indentation from the template literal.
3131
+ * The first line of the string must be empty.
3132
+ *
3133
+ * https://github.com/tc39/proposal-string-dedent
3134
+ */
3135
+ (
3136
+ strings: readonly string[] | ArrayLike<string>,
3137
+ ...substitutions: unknown[]
3138
+ ): string;
3139
+
3140
+ /**
3141
+ * Wrap another template tag function such that tagged literals
3142
+ * become dedented before being passed to the wrapped function.
3143
+ *
3144
+ * https://www.npmjs.com/package/string-dedent#usage
3145
+ */
3146
+ <
3147
+ Func extends (
3148
+ strings: readonly string[] | ArrayLike<string>,
3149
+ ...substitutions: any[]
3150
+ ) => string
3151
+ >(
3152
+ input: Func
3153
+ ): Func;
3154
+ };
3155
+ }
3156
+
3130
3157
  // prettier-ignore
3131
3158
  /** Any integer in the range [0, 255]. */
3132
3159
  declare type byte =
@@ -3175,6 +3202,10 @@ declare type TypedArrayConstructor =
3175
3202
  | Float32ArrayConstructor
3176
3203
  | Float64ArrayConstructor;
3177
3204
 
3205
+ interface ErrorOptions {
3206
+ [key: string]: any;
3207
+ }
3208
+
3178
3209
  // ==========================================
3179
3210
  // ------------------------------------------
3180
3211
  // QuickJS APIs, which YavaScript builds upon
@@ -4052,6 +4083,33 @@ interface BigDecimal {
4052
4083
  // TypeScript will not understand or handle unary/binary operators for BigFloat
4053
4084
  // and BigDecimal properly.
4054
4085
 
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
+
4055
4113
  /** npm: @suchipi/print@2.5.0. License: ISC */
4056
4114
  /* (with some QuickJS-specific modifications) */
4057
4115
 
@@ -4197,6 +4255,11 @@ declare interface InspectCustomInputs {
4197
4255
  colours: { [Key in keyof Required<InspectColours>]: string };
4198
4256
  }
4199
4257
 
4258
+ declare type Interval = { [Symbol.toStringTag]: "Interval" };
4259
+
4260
+ declare function setInterval(func: (...args: any) => any, ms: number): Interval;
4261
+ declare function clearInterval(interval: Interval): void;
4262
+
4200
4263
  // Definitions of the globals and modules added by quickjs-libc
4201
4264
 
4202
4265
  /**
@@ -4204,33 +4267,6 @@ declare interface InspectCustomInputs {
4204
4267
  */
4205
4268
  declare var scriptArgs: Array<string>;
4206
4269
 
4207
- /**
4208
- * Print the arguments separated by spaces and a trailing newline.
4209
- *
4210
- * Non-string args are coerced into a string via [ToString](https://tc39.es/ecma262/#sec-tostring).
4211
- * Objects can override the default `ToString` behavior by defining a `toString` method.
4212
- */
4213
- declare var print: (...args: Array<any>) => void;
4214
-
4215
- /**
4216
- * Object that provides functions for logging information.
4217
- */
4218
- interface Console {
4219
- /** Same as {@link print}(). */
4220
- log: typeof print;
4221
-
4222
- /** Same as {@link print}(). */
4223
- warn: typeof print;
4224
-
4225
- /** Same as {@link print}(). */
4226
- error: typeof print;
4227
-
4228
- /** Same as {@link print}(). */
4229
- info: typeof print;
4230
- }
4231
-
4232
- declare var console: Console;
4233
-
4234
4270
  /** An object representing a file handle. */
4235
4271
  declare interface FILE {
4236
4272
  /**
@@ -4297,6 +4333,20 @@ declare interface FILE {
4297
4333
  /** Write `length` bytes from the ArrayBuffer `buffer` at byte position `position` into the file (wrapper to the libc `fwrite`). Returns the number of bytes written. */
4298
4334
  write(buffer: ArrayBuffer, position: number, length: number): number;
4299
4335
 
4336
+ /**
4337
+ * Write this file into `target`, using a memory buffer of size `bufferSize`.
4338
+ *
4339
+ * If `limit` is specified, only that amount of bytes will be read and
4340
+ * written. Otherwise, data is read and written until this file reaches EOF.
4341
+ *
4342
+ * A `limit` of 0 is treated the same as not specifying a limit.
4343
+ *
4344
+ * Internally, this function uses libc `fread` and `fwrite` in a loop.
4345
+ *
4346
+ * Returns the number of bytes read and written.
4347
+ */
4348
+ writeTo(target: FILE, bufferSize: number, limit?: number): number;
4349
+
4300
4350
  /**
4301
4351
  * Return the next line from the file, assuming UTF-8 encoding, excluding the trailing line feed or EOF.
4302
4352
  *
@@ -4456,9 +4506,6 @@ declare module "quickjs:std" {
4456
4506
  /** Constant for {@link FILE.setvbuf}. Declares that the buffer mode should be 'no buffering'. */
4457
4507
  export var _IONBF: number;
4458
4508
 
4459
- /** Manually invoke the cycle removal algorithm (garbage collector). The cycle removal algorithm is automatically started when needed, so this function is useful in case of specific memory constraints or for testing. */
4460
- export function gc(): void;
4461
-
4462
4509
  /** Return the value of the environment variable `name` or `undefined` if it is not defined. */
4463
4510
  export function getenv(name: string): string | undefined;
4464
4511
 
@@ -5109,7 +5156,7 @@ declare module "quickjs:os" {
5109
5156
  export function dup2(oldfd: number, newfd: number): number;
5110
5157
 
5111
5158
  /** `pipe` Unix system call. Return two handles as `[read_fd, write_fd]`. */
5112
- export function pipe(): null | [number, number];
5159
+ export function pipe(): [number, number];
5113
5160
 
5114
5161
  /** Sleep for `delay_ms` milliseconds. */
5115
5162
  export function sleep(delay_ms: number): void;
@@ -5225,70 +5272,11 @@ declare module "quickjs:os" {
5225
5272
  declare var setTimeout: typeof import("quickjs:os").setTimeout;
5226
5273
  declare var clearTimeout: typeof import("quickjs:os").clearTimeout;
5227
5274
 
5228
- declare type Interval = { [Symbol.toStringTag]: "Interval" };
5229
-
5230
- declare function setInterval(func: (...args: any) => any, ms: number): Interval;
5231
- declare function clearInterval(interval: Interval): void;
5232
-
5233
- interface StringConstructor {
5234
- /**
5235
- * Remove leading minimum indentation from the string.
5236
- * The first line of the string must be empty.
5237
- *
5238
- * https://github.com/tc39/proposal-string-dedent
5239
- */
5240
- dedent: {
5241
- /**
5242
- * Remove leading minimum indentation from the string.
5243
- * The first line of the string must be empty.
5244
- *
5245
- * https://github.com/tc39/proposal-string-dedent
5246
- */
5247
- (input: string): string;
5248
-
5249
- /**
5250
- * Remove leading minimum indentation from the template literal.
5251
- * The first line of the string must be empty.
5252
- *
5253
- * https://github.com/tc39/proposal-string-dedent
5254
- */
5255
- (
5256
- strings: readonly string[] | ArrayLike<string>,
5257
- ...substitutions: any[]
5258
- ): string;
5259
-
5260
- /**
5261
- * Wrap another template tag function such that tagged literals
5262
- * become dedented before being passed to the wrapped function.
5263
- *
5264
- * https://www.npmjs.com/package/string-dedent#usage
5265
- */
5266
- <
5267
- Func extends (
5268
- strings: readonly string[] | ArrayLike<string>,
5269
- ...substitutions: any[]
5270
- ) => string
5271
- >(
5272
- input: Func
5273
- ): Func;
5274
- };
5275
- }
5276
-
5277
5275
  /**
5278
- * A global which lets you configure the module loader (import/export/require).
5279
- * You can use these properties to add support for importing new filetypes.
5280
- *
5281
- * This global can also be used to identify whether an object is a module
5282
- * namespace record.
5276
+ * An object which lets you configure the module loader (import/export/require).
5277
+ * You can change these properties to add support for importing new filetypes.
5283
5278
  */
5284
- interface ModuleGlobal {
5285
- /**
5286
- * Returns true if `target` is a module namespace object.
5287
- */
5288
- [Symbol.hasInstance](target: any): target is {
5289
- [key: string | number | symbol]: any;
5290
- };
5291
-
5279
+ interface ModuleDelegate {
5292
5280
  /**
5293
5281
  * A list of filetype extensions that may be omitted from an import specifier
5294
5282
  * string.
@@ -5300,7 +5288,7 @@ interface ModuleGlobal {
5300
5288
  * See the doc comment on {@link require} for more information.
5301
5289
  *
5302
5290
  * NOTE: If you add a new extension to this array, you will likely also want
5303
- * to add to {@link Module.compilers}.
5291
+ * to add to {@link compilers}.
5304
5292
  */
5305
5293
  searchExtensions: Array<string>;
5306
5294
 
@@ -5327,7 +5315,7 @@ interface ModuleGlobal {
5327
5315
  * ```js
5328
5316
  * import * as std from "std";
5329
5317
  *
5330
- * Module.compilers[".txt"] = (filename, content) => {
5318
+ * ModuleDelegate.compilers[".txt"] = (filename, content) => {
5331
5319
  * return `export default ${JSON.stringify(content)}`;
5332
5320
  * }
5333
5321
  * ```
@@ -5341,24 +5329,20 @@ interface ModuleGlobal {
5341
5329
  * And `names` will be a string containing the contents of names.txt.
5342
5330
  *
5343
5331
  * NOTE: When adding to this object, you may also wish to add to
5344
- * {@link Module.searchExtensions}.
5332
+ * {@link searchExtensions}.
5345
5333
  */
5346
5334
  compilers: {
5347
5335
  [extensionWithDot: string]: (filename: string, content: string) => string;
5348
5336
  };
5349
5337
 
5350
5338
  /**
5351
- * Create a virtual built-in module whose exports consist of the own
5352
- * enumerable properties of `obj`.
5353
- */
5354
- define(name: string, obj: { [key: string]: any }): void;
5355
-
5356
- /**
5357
- * Resolves a require/import request from `fromFile` into a canonicalized path.
5339
+ * Resolves a require/import request from `fromFile` into a canonicalized
5340
+ * path.
5358
5341
  *
5359
5342
  * To change native module resolution behavior, replace this function with
5360
5343
  * your own implementation. Note that you must handle
5361
- * `Module.searchExtensions` yourself in your replacement implementation.
5344
+ * `ModuleDelegate.searchExtensions` yourself in your replacement
5345
+ * implementation.
5362
5346
  */
5363
5347
  resolve(name: string, fromFile: string): string;
5364
5348
 
@@ -5366,15 +5350,12 @@ interface ModuleGlobal {
5366
5350
  * Reads the contents of the given resolved module name into a string.
5367
5351
  *
5368
5352
  * To change native module loading behavior, replace this function with your
5369
- * own implementation. Note that you must handle `Module.compilers` yourself
5370
- * in your replacement implementation.
5353
+ * own implementation. Note that you must handle `ModuleDelegate.compilers`
5354
+ * yourself in your replacement implementation.
5371
5355
  */
5372
5356
  read(modulePath: string): string;
5373
5357
  }
5374
5358
 
5375
- // global added by QJMS_AddModuleGlobal
5376
- declare var Module: ModuleGlobal;
5377
-
5378
5359
  interface RequireFunction {
5379
5360
  /**
5380
5361
  * Synchronously import a module.
@@ -5383,8 +5364,8 @@ interface RequireFunction {
5383
5364
  *
5384
5365
  * If `source` does not have a file extension, and a file without an extension
5385
5366
  * cannot be found, the engine will check for files with the extensions in
5386
- * {@link Module.searchExtensions}, and use one of those if present. This
5387
- * behavior also happens when using normal `import` statements.
5367
+ * {@link ModuleDelegate.searchExtensions}, and use one of those if present.
5368
+ * This behavior also happens when using normal `import` statements.
5388
5369
  *
5389
5370
  * For example, if you write:
5390
5371
  *
@@ -5393,20 +5374,20 @@ interface RequireFunction {
5393
5374
  * ```
5394
5375
  *
5395
5376
  * but there's no file named `somewhere` in the same directory as the file
5396
- * where that import appears, and `Module.searchExtensions` is the default
5397
- * value:
5377
+ * where that import appears, and `ModuleDelegate.searchExtensions` is the
5378
+ * default value:
5398
5379
  *
5399
5380
  * ```js
5400
5381
  * [".js"]
5401
5382
  * ```
5402
5383
  *
5403
5384
  * then the engine will look for `somewhere.js`. If that doesn't exist, the
5404
- * engine will look for `somewhere/index.js`. If *that* doesn't exist, an error
5405
- * will be thrown.
5385
+ * engine will look for `somewhere/index.js`. If *that* doesn't exist, an
5386
+ * error will be thrown.
5406
5387
  *
5407
- * If you add more extensions to `Module.searchExtensions`, then the engine
5408
- * will use those, too. It will search in the same order as the strings appear
5409
- * in the `Module.searchExtensions` array.
5388
+ * If you add more extensions to `ModuleDelegate.searchExtensions`, then the
5389
+ * engine will use those, too. It will search in the same order as the strings
5390
+ * appear in the `ModuleDelegate.searchExtensions` array.
5410
5391
  */
5411
5392
  (source: string): any;
5412
5393
 
@@ -5416,7 +5397,7 @@ interface RequireFunction {
5416
5397
  resolve: (source: string) => string;
5417
5398
  }
5418
5399
 
5419
- // global added by QJMS_AddRequireGlobal
5400
+ // global added by QJMS_InitContext
5420
5401
  declare var require: RequireFunction;
5421
5402
 
5422
5403
  // gets set per-module by QJMS_SetModuleImportMeta
@@ -5446,16 +5427,17 @@ interface ImportMeta {
5446
5427
  *
5447
5428
  * Equivalent to `globalThis.require.resolve`.
5448
5429
  *
5449
- * Behaves similarly to [the browser import.meta.resolve](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve),
5430
+ * Behaves similarly to [the browser
5431
+ * import.meta.resolve](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve),
5450
5432
  * but it does not ensure that the returned string is a valid URL, because it
5451
- * delegates directly to {@link Module.resolve} to resolve the name. If you
5452
- * want this to return URL strings, change `Module.resolve` and `Module.read`
5453
- * to work with URL strings.
5433
+ * delegates directly to {@link ModuleDelegate.resolve} to resolve the name.
5434
+ * If you want this to return URL strings, change `ModuleDelegate.resolve` and
5435
+ * `ModuleDelegate.read` to work with URL strings.
5454
5436
  */
5455
5437
  resolve: RequireFunction["resolve"];
5456
5438
  }
5457
5439
 
5458
- declare module "quickjs:module" {
5440
+ declare module "quickjs:engine" {
5459
5441
  /**
5460
5442
  * Return whether the provided resolved module path is set as the main module.
5461
5443
  *
@@ -5526,6 +5508,34 @@ declare module "quickjs:module" {
5526
5508
  * @param stackLevels - How many levels up the stack to search for a filename. Defaults to 0, which uses the current stack frame.
5527
5509
  */
5528
5510
  export function getFileNameFromStack(stackLevels?: number): string;
5511
+
5512
+ /**
5513
+ * Returns true if `target` is a module namespace object.
5514
+ */
5515
+ export function isModuleNamespace(target: any): boolean;
5516
+
5517
+ /**
5518
+ * Create a virtual built-in module whose exports consist of the own
5519
+ * enumerable properties of `obj`.
5520
+ */
5521
+ export function defineBuiltinModule(
5522
+ name: string,
5523
+ obj: { [key: string]: any }
5524
+ ): void;
5525
+
5526
+ /**
5527
+ * An object which lets you configure the module loader (import/export/require).
5528
+ * You can change these properties to add support for importing new filetypes.
5529
+ */
5530
+ export const ModuleDelegate: ModuleDelegate;
5531
+
5532
+ /**
5533
+ * Manually invoke the cycle removal algorithm (garbage collector).
5534
+ *
5535
+ * The cycle removal algorithm is automatically started when needed, so this
5536
+ * function is useful in case of specific memory constraints or for testing.
5537
+ */
5538
+ export function gc(): void;
5529
5539
  }
5530
5540
 
5531
5541
  declare module "quickjs:bytecode" {
@@ -5536,7 +5546,11 @@ declare module "quickjs:bytecode" {
5536
5546
  */
5537
5547
  export function fromFile(
5538
5548
  path: string,
5539
- options?: { byteSwap?: boolean; sourceType?: "module" | "script" }
5549
+ options?: {
5550
+ byteSwap?: boolean;
5551
+ sourceType?: "module" | "script";
5552
+ encodedFileName?: string;
5553
+ }
5540
5554
  ): ArrayBuffer;
5541
5555
 
5542
5556
  /**
@@ -5614,9 +5628,6 @@ declare module "quickjs:context" {
5614
5628
  /** Enables `String.prototype.normalize`. Defaults to `true`. */
5615
5629
  stringNormalize?: boolean;
5616
5630
 
5617
- /** Enables `String.dedent`. Defaults to `true`. */
5618
- stringDedent?: boolean;
5619
-
5620
5631
  /** Enables `RegExp`. Defaults to `true`. */
5621
5632
  regExp?: boolean;
5622
5633
 
@@ -5692,7 +5703,7 @@ declare module "quickjs:context" {
5692
5703
  console?: boolean;
5693
5704
  /** Enables `print`. Defaults to `true`. */
5694
5705
  print?: boolean;
5695
- /** Enables `require` and `Module`. Defaults to `true`. */
5706
+ /** Enables `require`. Defaults to `true`. */
5696
5707
  moduleGlobals?: boolean;
5697
5708
  /**
5698
5709
  * Enables `setTimeout`, `clearTimeout`, `setInterval`, and
@@ -5710,8 +5721,10 @@ declare module "quickjs:context" {
5710
5721
  "quickjs:bytecode"?: boolean;
5711
5722
  /** Enables the "quickjs:context" module. Defaults to `true`. */
5712
5723
  "quickjs:context"?: boolean;
5713
- /** Enables the "quickjs:module" module. Defaults to `true`. */
5714
- "quickjs:module"?: boolean;
5724
+ /** Enables the "quickjs:engine" module. Defaults to `true`. */
5725
+ "quickjs:engine"?: boolean;
5726
+ /** Enables the "quickjs:encoding" module. Defaults to `true`. */
5727
+ "quickjs:encoding"?: boolean;
5715
5728
  };
5716
5729
  });
5717
5730
 
@@ -5731,5 +5744,16 @@ declare module "quickjs:context" {
5731
5744
  }
5732
5745
  }
5733
5746
 
5747
+ // WHATWG encoding spec at https://encoding.spec.whatwg.org/ would be better,
5748
+ // but this is better than nothing
5749
+ declare module "quickjs:encoding" {
5750
+ export function toUtf8(input: ArrayBuffer): string;
5751
+ export function fromUtf8(input: string): ArrayBuffer;
5752
+ }
5753
+
5734
5754
  declare const std: typeof import("quickjs:std");
5735
5755
  declare const os: typeof import("quickjs:os");
5756
+
5757
+ // undocumented from quickjs, but it's there
5758
+ /** Get the current unix timestamp with microsecond precision. */
5759
+ declare function __date_clock(): number;