@suchipi/quickjs 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/LICENSE +40 -0
  2. package/README.md +145 -0
  3. package/build/aarch64-apple-darwin/bin/qjs +0 -0
  4. package/build/aarch64-apple-darwin/bin/qjsbootstrap +0 -0
  5. package/build/aarch64-apple-darwin/bin/qjsbootstrap-bytecode +0 -0
  6. package/build/aarch64-apple-darwin/bin/qjsc +0 -0
  7. package/build/aarch64-apple-darwin/bin/quickjs-run +0 -0
  8. package/build/aarch64-apple-darwin/dts/inspect.d.ts +123 -0
  9. package/build/aarch64-apple-darwin/dts/quickjs-libbytecode.d.ts +24 -0
  10. package/build/aarch64-apple-darwin/dts/quickjs-libc.d.ts +1309 -0
  11. package/build/aarch64-apple-darwin/dts/quickjs-libcontext.d.ts +179 -0
  12. package/build/aarch64-apple-darwin/dts/quickjs.d.ts +859 -0
  13. package/build/aarch64-apple-darwin/lib/quickjs-core.a +0 -0
  14. package/build/aarch64-apple-darwin/lib/quickjs-full.a +0 -0
  15. package/build/aarch64-unknown-linux-gnu/bin/qjs +0 -0
  16. package/build/aarch64-unknown-linux-gnu/bin/qjsbootstrap +0 -0
  17. package/build/aarch64-unknown-linux-gnu/bin/qjsbootstrap-bytecode +0 -0
  18. package/build/aarch64-unknown-linux-gnu/bin/qjsc +0 -0
  19. package/build/aarch64-unknown-linux-gnu/bin/quickjs-run +0 -0
  20. package/build/aarch64-unknown-linux-gnu/dts/inspect.d.ts +123 -0
  21. package/build/aarch64-unknown-linux-gnu/dts/quickjs-libbytecode.d.ts +24 -0
  22. package/build/aarch64-unknown-linux-gnu/dts/quickjs-libc.d.ts +1309 -0
  23. package/build/aarch64-unknown-linux-gnu/dts/quickjs-libcontext.d.ts +179 -0
  24. package/build/aarch64-unknown-linux-gnu/dts/quickjs.d.ts +859 -0
  25. package/build/aarch64-unknown-linux-gnu/lib/quickjs-core.a +0 -0
  26. package/build/aarch64-unknown-linux-gnu/lib/quickjs-full.a +0 -0
  27. package/build/aarch64-unknown-linux-musl/bin/qjs +0 -0
  28. package/build/aarch64-unknown-linux-musl/bin/qjsbootstrap +0 -0
  29. package/build/aarch64-unknown-linux-musl/bin/qjsbootstrap-bytecode +0 -0
  30. package/build/aarch64-unknown-linux-musl/bin/qjsc +0 -0
  31. package/build/aarch64-unknown-linux-musl/bin/quickjs-run +0 -0
  32. package/build/aarch64-unknown-linux-musl/dts/inspect.d.ts +123 -0
  33. package/build/aarch64-unknown-linux-musl/dts/quickjs-libbytecode.d.ts +24 -0
  34. package/build/aarch64-unknown-linux-musl/dts/quickjs-libc.d.ts +1309 -0
  35. package/build/aarch64-unknown-linux-musl/dts/quickjs-libcontext.d.ts +179 -0
  36. package/build/aarch64-unknown-linux-musl/dts/quickjs.d.ts +859 -0
  37. package/build/aarch64-unknown-linux-musl/lib/quickjs-core.a +0 -0
  38. package/build/aarch64-unknown-linux-musl/lib/quickjs-full.a +0 -0
  39. package/build/aarch64-unknown-linux-static/bin/qjs +0 -0
  40. package/build/aarch64-unknown-linux-static/bin/qjsbootstrap +0 -0
  41. package/build/aarch64-unknown-linux-static/bin/qjsbootstrap-bytecode +0 -0
  42. package/build/aarch64-unknown-linux-static/bin/qjsc +0 -0
  43. package/build/aarch64-unknown-linux-static/bin/quickjs-run +0 -0
  44. package/build/aarch64-unknown-linux-static/dts/inspect.d.ts +123 -0
  45. package/build/aarch64-unknown-linux-static/dts/quickjs-libbytecode.d.ts +24 -0
  46. package/build/aarch64-unknown-linux-static/dts/quickjs-libc.d.ts +1309 -0
  47. package/build/aarch64-unknown-linux-static/dts/quickjs-libcontext.d.ts +179 -0
  48. package/build/aarch64-unknown-linux-static/dts/quickjs.d.ts +859 -0
  49. package/build/aarch64-unknown-linux-static/lib/quickjs-core.a +0 -0
  50. package/build/aarch64-unknown-linux-static/lib/quickjs-full.a +0 -0
  51. package/build/x86_64-apple-darwin/bin/qjs +0 -0
  52. package/build/x86_64-apple-darwin/bin/qjsbootstrap +0 -0
  53. package/build/x86_64-apple-darwin/bin/qjsbootstrap-bytecode +0 -0
  54. package/build/x86_64-apple-darwin/bin/qjsc +0 -0
  55. package/build/x86_64-apple-darwin/bin/quickjs-run +0 -0
  56. package/build/x86_64-apple-darwin/dts/inspect.d.ts +123 -0
  57. package/build/x86_64-apple-darwin/dts/quickjs-libbytecode.d.ts +24 -0
  58. package/build/x86_64-apple-darwin/dts/quickjs-libc.d.ts +1309 -0
  59. package/build/x86_64-apple-darwin/dts/quickjs-libcontext.d.ts +179 -0
  60. package/build/x86_64-apple-darwin/dts/quickjs.d.ts +859 -0
  61. package/build/x86_64-apple-darwin/lib/quickjs-core.a +0 -0
  62. package/build/x86_64-apple-darwin/lib/quickjs-full.a +0 -0
  63. package/build/x86_64-pc-windows-static/bin/qjs.exe +0 -0
  64. package/build/x86_64-pc-windows-static/bin/qjsbootstrap-bytecode.exe +0 -0
  65. package/build/x86_64-pc-windows-static/bin/qjsbootstrap.exe +0 -0
  66. package/build/x86_64-pc-windows-static/bin/qjsc.exe +0 -0
  67. package/build/x86_64-pc-windows-static/bin/quickjs-run.exe +0 -0
  68. package/build/x86_64-pc-windows-static/dts/inspect.d.ts +123 -0
  69. package/build/x86_64-pc-windows-static/dts/quickjs-libbytecode.d.ts +24 -0
  70. package/build/x86_64-pc-windows-static/dts/quickjs-libc.d.ts +1309 -0
  71. package/build/x86_64-pc-windows-static/dts/quickjs-libcontext.d.ts +179 -0
  72. package/build/x86_64-pc-windows-static/dts/quickjs.d.ts +859 -0
  73. package/build/x86_64-pc-windows-static/lib/quickjs-core.a +0 -0
  74. package/build/x86_64-pc-windows-static/lib/quickjs-full.a +0 -0
  75. package/build/x86_64-unknown-linux-gnu/bin/qjs +0 -0
  76. package/build/x86_64-unknown-linux-gnu/bin/qjsbootstrap +0 -0
  77. package/build/x86_64-unknown-linux-gnu/bin/qjsbootstrap-bytecode +0 -0
  78. package/build/x86_64-unknown-linux-gnu/bin/qjsc +0 -0
  79. package/build/x86_64-unknown-linux-gnu/bin/quickjs-run +0 -0
  80. package/build/x86_64-unknown-linux-gnu/dts/inspect.d.ts +123 -0
  81. package/build/x86_64-unknown-linux-gnu/dts/quickjs-libbytecode.d.ts +24 -0
  82. package/build/x86_64-unknown-linux-gnu/dts/quickjs-libc.d.ts +1309 -0
  83. package/build/x86_64-unknown-linux-gnu/dts/quickjs-libcontext.d.ts +179 -0
  84. package/build/x86_64-unknown-linux-gnu/dts/quickjs.d.ts +859 -0
  85. package/build/x86_64-unknown-linux-gnu/lib/quickjs-core.a +0 -0
  86. package/build/x86_64-unknown-linux-gnu/lib/quickjs-full.a +0 -0
  87. package/build/x86_64-unknown-linux-musl/bin/qjs +0 -0
  88. package/build/x86_64-unknown-linux-musl/bin/qjsbootstrap +0 -0
  89. package/build/x86_64-unknown-linux-musl/bin/qjsbootstrap-bytecode +0 -0
  90. package/build/x86_64-unknown-linux-musl/bin/qjsc +0 -0
  91. package/build/x86_64-unknown-linux-musl/bin/quickjs-run +0 -0
  92. package/build/x86_64-unknown-linux-musl/dts/inspect.d.ts +123 -0
  93. package/build/x86_64-unknown-linux-musl/dts/quickjs-libbytecode.d.ts +24 -0
  94. package/build/x86_64-unknown-linux-musl/dts/quickjs-libc.d.ts +1309 -0
  95. package/build/x86_64-unknown-linux-musl/dts/quickjs-libcontext.d.ts +179 -0
  96. package/build/x86_64-unknown-linux-musl/dts/quickjs.d.ts +859 -0
  97. package/build/x86_64-unknown-linux-musl/lib/quickjs-core.a +0 -0
  98. package/build/x86_64-unknown-linux-musl/lib/quickjs-full.a +0 -0
  99. package/build/x86_64-unknown-linux-static/bin/qjs +0 -0
  100. package/build/x86_64-unknown-linux-static/bin/qjsbootstrap +0 -0
  101. package/build/x86_64-unknown-linux-static/bin/qjsbootstrap-bytecode +0 -0
  102. package/build/x86_64-unknown-linux-static/bin/qjsc +0 -0
  103. package/build/x86_64-unknown-linux-static/bin/quickjs-run +0 -0
  104. package/build/x86_64-unknown-linux-static/dts/inspect.d.ts +123 -0
  105. package/build/x86_64-unknown-linux-static/dts/quickjs-libbytecode.d.ts +24 -0
  106. package/build/x86_64-unknown-linux-static/dts/quickjs-libc.d.ts +1309 -0
  107. package/build/x86_64-unknown-linux-static/dts/quickjs-libcontext.d.ts +179 -0
  108. package/build/x86_64-unknown-linux-static/dts/quickjs.d.ts +859 -0
  109. package/build/x86_64-unknown-linux-static/lib/quickjs-core.a +0 -0
  110. package/build/x86_64-unknown-linux-static/lib/quickjs-full.a +0 -0
  111. package/npm/cli/qjs.js +4 -0
  112. package/npm/cli/qjsc.js +4 -0
  113. package/npm/cli/quickjs-run.js +4 -0
  114. package/npm/cli/run-binary.js +17 -0
  115. package/npm/index.js +68 -0
  116. package/package.json +35 -0
  117. package/tsconfig.json +19 -0
@@ -0,0 +1,1309 @@
1
+ // Definitions of the globals and modules added by quickjs-libc
2
+
3
+ /**
4
+ * Provides the command line arguments. The first argument is the script name.
5
+ */
6
+ declare var scriptArgs: Array<string>;
7
+
8
+ /**
9
+ * Print the arguments separated by spaces and a trailing newline.
10
+ *
11
+ * Non-string args are coerced into a string via [ToString](https://tc39.es/ecma262/#sec-tostring).
12
+ * Objects can override the default `ToString` behavior by defining a `toString` method.
13
+ */
14
+ declare var print: (...args: Array<any>) => void;
15
+
16
+ /**
17
+ * Object that provides functions for logging information.
18
+ */
19
+ interface Console {
20
+ /** Same as {@link print}(). */
21
+ log: typeof print;
22
+
23
+ /** Same as {@link print}(). */
24
+ warn: typeof print;
25
+
26
+ /** Same as {@link print}(). */
27
+ error: typeof print;
28
+
29
+ /** Same as {@link print}(). */
30
+ info: typeof print;
31
+ }
32
+
33
+ declare var console: Console;
34
+
35
+ /** An object representing a file handle. */
36
+ declare interface FILE {
37
+ /**
38
+ * Human-readable description of where this FILE points.
39
+ *
40
+ * If `target` is a number, the FILE was opened with fdopen, and `target` is
41
+ * the fd. Otherwise, `target` will be an arbitrary string that describes the
42
+ * file; it may be the absolute path to the file, the relative path to the
43
+ * file at time of its opening, or some other string like "stdin" or
44
+ * "tmpfile".
45
+ *
46
+ * You should *not* use this property for anything other than logging and
47
+ * debugging. It is *only* provided for debugging and/or troubleshooting
48
+ * purposes. The value of this property could change at any time when
49
+ * upgrading yavascript, even if upgrading by a minor or patch release.
50
+ */
51
+ target: string | number;
52
+
53
+ /**
54
+ * Close the file handle. Note that for files other than stdin/stdout/stderr,
55
+ * the file will be closed automatically when the `FILE` object is
56
+ * garbage-collected.
57
+ */
58
+ close(): void;
59
+
60
+ /** Outputs the string with the UTF-8 encoding. */
61
+ puts(...strings: Array<string>): void;
62
+
63
+ /**
64
+ * Formatted printf.
65
+ *
66
+ * The same formats as the standard C library `printf` are supported. Integer format types (e.g. `%d`) truncate the Numbers or BigInts to 32 bits. Use the `l` modifier (e.g. `%ld`) to truncate to 64 bits.
67
+ */
68
+ printf(fmt: string, ...args: Array<any>): void;
69
+
70
+ /** Flush the buffered file. Wrapper for C `fflush`. */
71
+ flush(): void;
72
+
73
+ /** Sync the buffered file to disk. Wrapper for C `fsync`. */
74
+ sync(): void;
75
+
76
+ /**
77
+ * Seek to a given file position (whence is `std.SEEK_*`).
78
+ *
79
+ * `offset` can be a number or a bigint.
80
+ */
81
+ seek(offset: number, whence: number): void;
82
+
83
+ /** Return the current file position. */
84
+ tell(): number;
85
+
86
+ /** Return the current file position as a bigint. */
87
+ tello(): BigInt;
88
+
89
+ /** Return true if end of file. */
90
+ eof(): boolean;
91
+
92
+ /** Return the associated OS handle. */
93
+ fileno(): number;
94
+
95
+ /** Read `length` bytes from the file to the ArrayBuffer `buffer` at byte position `position` (wrapper to the libc `fread`). Returns the number of bytes read, or `0` if the end of the file has been reached. */
96
+ read(buffer: ArrayBuffer, position: number, length: number): number;
97
+
98
+ /** 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. */
99
+ write(buffer: ArrayBuffer, position: number, length: number): number;
100
+
101
+ /**
102
+ * Return the next line from the file, assuming UTF-8 encoding, excluding the trailing line feed or EOF.
103
+ *
104
+ * If the end of the file has been reached, then `null` will be returned instead of a string.
105
+ *
106
+ * Note: Although the trailing line feed has been removed, a carriage return (`\r`) may still be present.
107
+ */
108
+ getline(): string | null;
109
+
110
+ /** Read `maxSize` bytes from the file and return them as a string assuming UTF-8 encoding. If `maxSize` is not present, the file is read up its end. */
111
+ readAsString(maxSize?: number): string;
112
+
113
+ /** Return the next byte from the file. Return -1 if the end of file is reached. */
114
+ getByte(): number;
115
+
116
+ /** Write one byte to the file. */
117
+ putByte(value: number): void;
118
+
119
+ /**
120
+ * Set the buffering mode and buffer size for the file stream (wrapper to the libc `setvbuf()`).
121
+ *
122
+ * Note that unlike the libc setvbuf, the "buffer" argument is not supported, and therefore is not present.
123
+ *
124
+ * @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.
125
+ * @param size The size to resize the internal in-memory buffer for this file to.
126
+ */
127
+ setvbuf(mode: number, size: number): void;
128
+ }
129
+
130
+ declare module "quickjs:std" {
131
+ /**
132
+ * Exit the process with the provided status code.
133
+ *
134
+ * @param statusCode The exit code; 0 for success, nonzero for failure.
135
+ */
136
+ export function exit(statusCode: number): void;
137
+
138
+ /**
139
+ * Evaluate the string `code` as a script (global eval).
140
+ *
141
+ * @param code - The code to evaluate.
142
+ * @param options - An optional object containing the following optional properties:
143
+ * @property backtraceBarrier - Boolean (default = false). If true, error backtraces do not list the stack frames below the evalScript.
144
+ * @property filename - String (default = "<evalScript>"). The filename to associate with the code being executed.
145
+ * @returns The result of the evaluation.
146
+ */
147
+ export function evalScript(
148
+ code: string,
149
+ options?: { backtraceBarrier?: boolean; filename?: string }
150
+ ): any;
151
+
152
+ /**
153
+ * Evaluate the file `filename` as a script (global eval).
154
+ *
155
+ * @param filename - The relative or absolute path to the file to load. Relative paths are resolved relative to the process's current working directory.
156
+ * @returns The result of the evaluation.
157
+ */
158
+ export function loadScript(filename: string): any;
159
+
160
+ /**
161
+ * Evaluate the file `filename` as a module. Effectively a synchronous dynamic `import()`.
162
+ *
163
+ * @param filename - The relative or absolute path to the file to import. Relative paths are resolved relative to the file calling `importModule`, or `basename` if present.
164
+ * @param basename - If present and `filename` is a relative path, `filename` will be resolved relative to this basename.
165
+ * @returns The result of the evaluation (module namespace object).
166
+ */
167
+ export function importModule(
168
+ filename: string,
169
+ basename?: string
170
+ ): { [key: string]: any };
171
+
172
+ /**
173
+ * Return the resolved path to a module.
174
+ *
175
+ * @param filename - The relative or absolute path to the file to import. Relative paths are resolved relative to the file calling `importModule`, or `basename` if present.
176
+ * @param basename - If present and `filename` is a relative path, `filename` will be resolved relative to this basename.
177
+ * @returns The resolved module path.
178
+ */
179
+ export function resolveModule(filename: string, basename?: string): string;
180
+
181
+ /**
182
+ * Load the file `filename` and return it as a string assuming UTF-8 encoding.
183
+ *
184
+ * @param filename - The relative or absolute path to the file to load. Relative paths are resolved relative to the process's current working directory.
185
+ */
186
+ export function loadFile(filename: string): string;
187
+
188
+ /**
189
+ * Read the script of module filename from an active stack frame, then return it as a string.
190
+ *
191
+ * If there isn't a valid filename for the specified stack frame, an error will be thrown.
192
+ *
193
+ * @param stackLevels - How many levels up the stack to search for a filename. Defaults to 0, which uses the current stack frame.
194
+ */
195
+ export function getFileNameFromStack(stackLevels?: number): string;
196
+
197
+ /**
198
+ * Return a boolean indicating whether the provided value is a FILE object.
199
+ *
200
+ * @param value - The value to check.
201
+ * @returns Whether the value was a `FILE` or not.
202
+ */
203
+ export function isFILE(value: any): boolean;
204
+
205
+ /**
206
+ * Open a file (wrapper to the libc `fopen()`).
207
+ * Return the FILE object.
208
+ *
209
+ * @param filename - The relative or absolute path to the file to open. Relative paths are resolved relative to the process's current working directory.
210
+ * @param flags - A string containing any combination of the characters 'r', 'w', 'a', '+', and/or 'b'.
211
+ * @returns The opened FILE object.
212
+ */
213
+ export function open(filename: string, flags: string): FILE;
214
+
215
+ /**
216
+ * Open a process by creating a pipe (wrapper to the libc `popen()`).
217
+ * Return the FILE object.
218
+ *
219
+ * @param command - The command line to execute. Gets passed via `/bin/sh -c`.
220
+ * @param flags - A string containing any combination of the characters 'r', 'w', 'a', '+', and/or 'b'.
221
+ * @returns The opened FILE object.
222
+ */
223
+ export function popen(command: string, flags: string): FILE;
224
+
225
+ /**
226
+ * Open a file from a file handle (wrapper to the libc `fdopen()`).
227
+ * Return the FILE object.
228
+ *
229
+ * @param fd - The file handle to open.
230
+ * @param flags - A string containing any combination of the characters 'r', 'w', 'a', '+', and/or 'b'.
231
+ * @returns The opened FILE object.
232
+ */
233
+ export function fdopen(fd: number, flags: string): FILE;
234
+
235
+ /**
236
+ * Open a temporary file.
237
+ * Return the FILE object.
238
+ *
239
+ * @returns The opened FILE object.
240
+ */
241
+ export function tmpfile(): FILE;
242
+
243
+ /** Equivalent to `std.out.puts(str)`. */
244
+ export function puts(...strings: Array<string>): void;
245
+
246
+ /** Equivalent to `std.out.printf(fmt, ...args)` */
247
+ export function printf(fmt: string, ...args: Array<any>): void;
248
+
249
+ /** Equivalent to the libc sprintf(). */
250
+ export function sprintf(fmt: string, ...args: Array<any>): void;
251
+
252
+ /** Wrapper to the libc file stdin. */
253
+ var in_: FILE;
254
+
255
+ export { in_ as in };
256
+
257
+ /** Wrapper to the libc file stdout. */
258
+ export var out: FILE;
259
+
260
+ /** Wrapper to the libc file stderr. */
261
+ export var err: FILE;
262
+
263
+ /** Constant for {@link FILE.seek}. Declares that pointer offset should be relative to the beginning of the file. See also libc `fseek()`. */
264
+ export var SEEK_SET: number;
265
+
266
+ /** Constant for {@link FILE.seek}. Declares that the offset should be relative to the current position of the FILE handle. See also libc `fseek()`. */
267
+ export var SEEK_CUR: number;
268
+
269
+ /** Constant for {@link FILE.seek}. Declares that the offset should be relative to the end of the file. See also libc `fseek()`. */
270
+ export var SEEK_END: number;
271
+
272
+ /** Constant for {@link FILE.setvbuf}. Declares that the buffer mode should be 'full buffering'. */
273
+ export var _IOFBF: number;
274
+
275
+ /** Constant for {@link FILE.setvbuf}. Declares that the buffer mode should be 'line buffering'. */
276
+ export var _IOLBF: number;
277
+
278
+ /** Constant for {@link FILE.setvbuf}. Declares that the buffer mode should be 'no buffering'. */
279
+ export var _IONBF: number;
280
+
281
+ /** 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. */
282
+ export function gc(): void;
283
+
284
+ /** Return the value of the environment variable `name` or `undefined` if it is not defined. */
285
+ export function getenv(name: string): string | undefined;
286
+
287
+ /** Set the value of the environment variable `name` to the string `value`. */
288
+ export function setenv(name: string, value: string): void;
289
+
290
+ /** Delete the environment variable `name`. */
291
+ export function unsetenv(name: string): void;
292
+
293
+ /** Return an object containing the environment variables as key-value pairs. */
294
+ export function getenviron(): { [key: string]: string | undefined };
295
+
296
+ interface UrlGet {
297
+ /**
298
+ * Download `url` using the `curl` command line utility. Returns string
299
+ * when the http status code is between 200 and 299, and throws otherwise.
300
+ *
301
+ * Pass an object with { full: true } as the second argument to get
302
+ * response headers and status code.
303
+ */
304
+ (url: string): string;
305
+
306
+ /**
307
+ * Download `url` using the `curl` command line utility. Returns string
308
+ * when the http status code is between 200 and 299, and throws otherwise.
309
+ *
310
+ * Pass an object with { full: true } as the second argument to get
311
+ * response headers and status code.
312
+ */
313
+ (url: string, options: { binary: false }): string;
314
+
315
+ /**
316
+ * Download `url` using the `curl` command line utility. Returns string
317
+ * when the http status code is between 200 and 299, and throws otherwise.
318
+ *
319
+ * Pass an object with { full: true } as the second argument to get
320
+ * response headers and status code.
321
+ */
322
+ (url: string, options: { full: false }): string;
323
+
324
+ /**
325
+ * Download `url` using the `curl` command line utility. Returns string
326
+ * when the http status code is between 200 and 299, and throws otherwise.
327
+ *
328
+ * Pass an object with { full: true } as the second argument to get
329
+ * response headers and status code.
330
+ */
331
+ (url: string, options: { binary: false; full: false }): string;
332
+
333
+ /**
334
+ * Download `url` using the `curl` command line utility. Returns
335
+ * ArrayBuffer when the http status code is between 200 and 299, and throws
336
+ * otherwise.
337
+ *
338
+ * Pass an object with { full: true } as the second argument to get
339
+ * response headers and status code.
340
+ */
341
+ (url: string, options: { binary: true }): ArrayBuffer;
342
+
343
+ /**
344
+ * Download `url` using the `curl` command line utility. Returns
345
+ * ArrayBuffer when the http status code is between 200 and 299, and throws
346
+ * otherwise.
347
+ *
348
+ * Pass an object with { full: true } as the second argument to get
349
+ * response headers and status code.
350
+ */
351
+ (url: string, options: { binary: true; full: false }): ArrayBuffer;
352
+
353
+ /**
354
+ * Download `url` using the `curl` command line utility.
355
+ *
356
+ * Returns an object with three properties:
357
+ *
358
+ * - `response`: response body content (string)
359
+ * - `responseHeaders`: headers separated by CRLF (string)
360
+ * - `status`: status code (number)
361
+ */
362
+ (url: string, options: { full: true }): {
363
+ status: number;
364
+ response: string;
365
+ responseHeaders: string;
366
+ };
367
+
368
+ /**
369
+ * Download `url` using the `curl` command line utility.
370
+ *
371
+ * Returns an object with three properties:
372
+ *
373
+ * - `response`: response body content (string)
374
+ * - `responseHeaders`: headers separated by CRLF (string)
375
+ * - `status`: status code (number)
376
+ */
377
+ (url: string, options: { full: true; binary: false }): {
378
+ status: number;
379
+ response: string;
380
+ responseHeaders: string;
381
+ };
382
+
383
+ /**
384
+ * Download `url` using the `curl` command line utility.
385
+ *
386
+ * Returns an object with three properties:
387
+ *
388
+ * - `response`: response body content (ArrayBuffer)
389
+ * - `responseHeaders`: headers separated by CRLF (string)
390
+ * - `status`: status code (number)
391
+ */
392
+ (url: string, options: { full: true; binary: true }): {
393
+ status: number;
394
+ response: ArrayBuffer;
395
+ responseHeaders: string;
396
+ };
397
+ }
398
+
399
+ export var urlGet: UrlGet;
400
+
401
+ /**
402
+ * Parse `str` using a superset of JSON.parse. The following extensions are accepted:
403
+ *
404
+ * - Single line and multiline comments
405
+ * - unquoted properties (ASCII-only Javascript identifiers)
406
+ * - trailing comma in array and object definitions
407
+ * - single quoted strings
408
+ * - `\f` and `\v` are accepted as space characters
409
+ * - leading plus in numbers
410
+ * - octal (0o prefix) and hexadecimal (0x prefix) numbers
411
+ */
412
+ export function parseExtJSON(str: string): any;
413
+ }
414
+
415
+ declare module "quickjs:os" {
416
+ /**
417
+ * Open a file handle. Returns a number; the file descriptor.
418
+ *
419
+ * @param filename - The path to the file to open.
420
+ * @param flags - Numeric flags that set the mode to use when opening the file. See `os.O_*`
421
+ * @param mode - Octal access mask. Defaults to 0o666.
422
+ */
423
+ export function open(filename: string, flags: number, mode?: number): number;
424
+
425
+ /** POSIX open flag, used in {@link open}. */
426
+ export var O_RDONLY: number;
427
+
428
+ /** POSIX open flag, used in {@link open}. */
429
+ export var O_WRONLY: number;
430
+
431
+ /** POSIX open flag, used in {@link open}. */
432
+ export var O_RDWR: number;
433
+
434
+ /** POSIX open flag, used in {@link open}. */
435
+ export var O_APPEND: number;
436
+
437
+ /** POSIX open flag, used in {@link open}. */
438
+ export var O_CREAT: number;
439
+
440
+ /** POSIX open flag, used in {@link open}. */
441
+ export var O_EXCL: number;
442
+
443
+ /** POSIX open flag, used in {@link open}. */
444
+ export var O_TRUNC: number;
445
+
446
+ /**
447
+ * Windows-specific open flag: open the file in binary mode (which is the default). Used in {@link open}.
448
+ *
449
+ * NOTE: this property is only present on windows
450
+ */
451
+ export var O_BINARY: number | undefined;
452
+
453
+ /**
454
+ * Windows-specific open flag: open the file in text mode. The default is binary mode. Used in {@link open}.
455
+ *
456
+ * NOTE: this property is only present on windows
457
+ */
458
+ export var O_TEXT: number | undefined;
459
+
460
+ /** Close the file with descriptor `fd`. */
461
+ export function close(fd: number): void;
462
+
463
+ interface OsSeek {
464
+ /** Seek in the file. Use `std.SEEK_*` for `whence`. `offset` is either a number or a bigint. If `offset` is a bigint, a bigint is returned too. */
465
+ (fd: number, offset: number, whence: number): number;
466
+
467
+ /** Seek in the file. Use `std.SEEK_*` for `whence`. `offset` is either a number or a bigint. If `offset` is a bigint, a bigint is returned too. */
468
+ (fd: number, offset: BigInt, whence: number): BigInt;
469
+ }
470
+
471
+ /** Seek in the file. Use `std.SEEK_*` for `whence`. `offset` is either a number or a bigint. If `offset` is a bigint, a bigint is returned too. */
472
+ export var seek: OsSeek;
473
+
474
+ /** Read `length` bytes from the file with descriptor `fd` to the ArrayBuffer `buffer` at byte position `offset`. Return the number of read bytes. */
475
+ export function read(
476
+ fd: number,
477
+ buffer: ArrayBuffer,
478
+ offset: number,
479
+ length: number
480
+ ): number;
481
+
482
+ /** Write `length` bytes to the file with descriptor `fd` from the ArrayBuffer `buffer` at byte position `offset`. Return the number of written bytes. */
483
+ export function write(
484
+ fd: number,
485
+ buffer: ArrayBuffer,
486
+ offset: number,
487
+ length: number
488
+ ): number;
489
+
490
+ /** Return `true` if the file opened with descriptor `fd` is a TTY (terminal). */
491
+ export function isatty(fd: number): boolean;
492
+
493
+ /** Return the TTY size as `[width, height]` or `null` if not available. */
494
+ export function ttyGetWinSize(fd: number): null | [number, number];
495
+
496
+ /** Set the TTY in raw mode. */
497
+ export function ttySetRaw(fd: number): void;
498
+
499
+ /** Remove a file. */
500
+ export function remove(filename: string): void;
501
+
502
+ /** Rename a file. */
503
+ export function rename(oldname: string, newname: string): void;
504
+
505
+ /** Return the canonicalized absolute pathname of `path`. */
506
+ export function realpath(path: string): string;
507
+
508
+ /** Return the current working directory. */
509
+ export function getcwd(): string;
510
+
511
+ /** Change the current directory. */
512
+ export function chdir(path: string): void;
513
+
514
+ /** Create a directory at `path`. */
515
+ export function mkdir(path: string, mode?: number): void;
516
+
517
+ export type Stats = {
518
+ dev: number;
519
+ ino: number;
520
+ mode: number;
521
+ nlink: number;
522
+ uid: number;
523
+ gid: number;
524
+ rdev: number;
525
+ size: number;
526
+ blocks: number;
527
+ atime: number;
528
+ mtime: number;
529
+ ctime: number;
530
+ };
531
+
532
+ /**
533
+ * Return a stats object with the following fields:
534
+ *
535
+ * - `dev`
536
+ * - `ino`
537
+ * - `mode`
538
+ * - `nlink`
539
+ * - `uid`
540
+ * - `gid`
541
+ * - `rdev`
542
+ * - `size`
543
+ * - `blocks`
544
+ * - `atime`
545
+ * - `mtime`
546
+ * - `ctime`
547
+ *
548
+ * The times are specified in milliseconds since 1970. `lstat()` is the same as `stat()` except that it returns information about the link itself.
549
+ */
550
+ export function stat(path: string): Stats;
551
+
552
+ /**
553
+ * Return a stats object with the following fields:
554
+ *
555
+ * - `dev`
556
+ * - `ino`
557
+ * - `mode`
558
+ * - `nlink`
559
+ * - `uid`
560
+ * - `gid`
561
+ * - `rdev`
562
+ * - `size`
563
+ * - `blocks`
564
+ * - `atime`
565
+ * - `mtime`
566
+ * - `ctime`
567
+ *
568
+ * The times are specified in milliseconds since 1970. `lstat()` is the same as `stat()` except that it returns information about the link itself.
569
+ */
570
+ export function lstat(path: string): Stats;
571
+
572
+ /**
573
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
574
+ *
575
+ * Mask for getting type of file from mode.
576
+ */
577
+ export var S_IFMT: number;
578
+
579
+ /**
580
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
581
+ *
582
+ * File type: named pipe (fifo)
583
+ */
584
+ export var S_IFIFO: number;
585
+
586
+ /**
587
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
588
+ *
589
+ * File type: character special
590
+ */
591
+ export var S_IFCHR: number;
592
+
593
+ /**
594
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
595
+ *
596
+ * File type: directory
597
+ */
598
+ export var S_IFDIR: number;
599
+
600
+ /**
601
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
602
+ *
603
+ * File type: block special
604
+ */
605
+ export var S_IFBLK: number;
606
+
607
+ /**
608
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
609
+ *
610
+ * File type: regular
611
+ */
612
+ export var S_IFREG: number;
613
+
614
+ /**
615
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
616
+ *
617
+ * File type: socket
618
+ *
619
+ * NOTE: this property is not present on windows
620
+ */
621
+ export var S_IFSOCK: number | undefined;
622
+
623
+ /**
624
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
625
+ *
626
+ * File type: symbolic link
627
+ *
628
+ * NOTE: this property is not present on windows
629
+ */
630
+ export var S_IFLNK: number | undefined;
631
+
632
+ /**
633
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
634
+ *
635
+ * Flag: set group id on execution
636
+ *
637
+ * NOTE: this property is not present on windows
638
+ */
639
+ export var S_ISGID: number | undefined;
640
+
641
+ /**
642
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
643
+ *
644
+ * Flag: set user id on execution
645
+ *
646
+ * NOTE: this property is not present on windows
647
+ */
648
+ export var S_ISUID: number | undefined;
649
+
650
+ /**
651
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
652
+ *
653
+ * Mask for getting RWX permissions for owner
654
+ */
655
+ export var S_IRWXU: number;
656
+
657
+ /**
658
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
659
+ *
660
+ * Permission: read for owner
661
+ */
662
+ export var S_IRUSR: number;
663
+
664
+ /**
665
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
666
+ *
667
+ * Permission: write for owner
668
+ */
669
+ export var S_IWUSR: number;
670
+
671
+ /**
672
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
673
+ *
674
+ * Permission: execute for owner
675
+ */
676
+ export var S_IXUSR: number;
677
+
678
+ /**
679
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
680
+ *
681
+ * Mask for getting RWX permissions for group
682
+ */
683
+ export var S_IRWXG: number;
684
+
685
+ /**
686
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
687
+ *
688
+ * Permission: read for group
689
+ */
690
+ export var S_IRGRP: number;
691
+
692
+ /**
693
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
694
+ *
695
+ * Permission: write for group
696
+ */
697
+ export var S_IWGRP: number;
698
+
699
+ /**
700
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
701
+ *
702
+ * Permission: execute for group
703
+ */
704
+ export var S_IXGRP: number;
705
+
706
+ /**
707
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
708
+ *
709
+ * Mask for getting RWX permissions for others
710
+ */
711
+ export var S_IRWXO: number;
712
+
713
+ /**
714
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
715
+ *
716
+ * Permission: read for others
717
+ */
718
+ export var S_IROTH: number;
719
+
720
+ /**
721
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
722
+ *
723
+ * Permission: write for others
724
+ */
725
+ export var S_IWOTH: number;
726
+
727
+ /**
728
+ * Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
729
+ *
730
+ * Permission: execute for others
731
+ */
732
+ export var S_IXOTH: number;
733
+
734
+ /**
735
+ * Change the access and modification times of the file path.
736
+ *
737
+ * The times are specified in milliseconds since 1970.
738
+ */
739
+ export function utimes(path: string, atime: number, mtime: number): void;
740
+
741
+ /** Create a link at `linkpath` containing the string `target`. */
742
+ export function symlink(target: string, linkpath: string): void;
743
+
744
+ /** Return the link target. */
745
+ export function readlink(path: string): string;
746
+
747
+ /** Return an array of strings containing the filenames of the directory `path`. */
748
+ export function readdir(path: string): Array<string>;
749
+
750
+ /** Add a read handler to the file with descriptor `fd`. `func` is called each time there is data pending for `fd`. A single read handler per file handle is supported. Use `func = null` to remove the handler. */
751
+ export function setReadHandler(fd: number, func: null | (() => void)): void;
752
+
753
+ /** Add a write handler to the file with descriptor `fd`. `func` is called each time data can be written to `fd`. A single write handler per file handle is supported. Use `func = null` to remove the handler. */
754
+ export function setWriteHandler(fd: number, func: null | (() => void)): void;
755
+
756
+ /** Call the function `func` when the signal `signal` happens. Only a single handler per signal number is supported. Use `null` to set the default handler or `undefined` to ignore the signal. Signal handlers can only be defined in the main thread. */
757
+ export function signal(
758
+ signal: number,
759
+ func: null | undefined | (() => void)
760
+ ): void;
761
+
762
+ /** POSIX signal number. */
763
+ export var SIGINT: number;
764
+
765
+ /** POSIX signal number. */
766
+ export var SIGABRT: number;
767
+
768
+ /** POSIX signal number. */
769
+ export var SIGFPE: number;
770
+
771
+ /** POSIX signal number. */
772
+ export var SIGILL: number;
773
+
774
+ /** POSIX signal number. */
775
+ export var SIGSEGV: number;
776
+
777
+ /** POSIX signal number. */
778
+ export var SIGTERM: number;
779
+
780
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
781
+ export var SIGQUIT: number | undefined;
782
+
783
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
784
+ export var SIGPIPE: number | undefined;
785
+
786
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
787
+ export var SIGALRM: number | undefined;
788
+
789
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
790
+ export var SIGUSR1: number | undefined;
791
+
792
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
793
+ export var SIGUSR2: number | undefined;
794
+
795
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
796
+ export var SIGCHLD: number | undefined;
797
+
798
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
799
+ export var SIGCONT: number | undefined;
800
+
801
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
802
+ export var SIGSTOP: number | undefined;
803
+
804
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
805
+ export var SIGTSTP: number | undefined;
806
+
807
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
808
+ export var SIGTTIN: number | undefined;
809
+
810
+ /** POSIX signal number. NOTE: this signal is not present on windows. */
811
+ export var SIGTTOU: number | undefined;
812
+
813
+ /** Send the signal `sig` to the process `pid`. Use `os.SIG*` constants. */
814
+ export function kill(pid: number, sig: number): void;
815
+
816
+ export type ExecOptions = {
817
+ /** Boolean (default = true). If true, wait until the process is terminated. In this case, `exec` returns the exit code if positive or the negated signal number if the process was interrupted by a signal. If false, do not block and return the process id of the child. */
818
+ block?: boolean;
819
+
820
+ /** Boolean (default = true). If true, the file is searched in the `PATH` environment variable. */
821
+ usePath?: boolean;
822
+
823
+ /** String (default = `args[0]`). Set the file to be executed. */
824
+ file?: string;
825
+
826
+ /** String. If present, set the working directory of the new process. */
827
+ cwd?: string;
828
+
829
+ /** If present, set the file descriptor in the child for stdin. */
830
+ stdin?: number;
831
+
832
+ /** If present, set the file descriptor in the child for stdout. */
833
+ stdout?: number;
834
+
835
+ /** If present, set the file descriptor in the child for stderr. */
836
+ stderr?: number;
837
+
838
+ /** Object. If present, set the process environment from the object key-value pairs. Otherwise use the same environment as the current process. To get the current process's environment variables as on object, use `std.getenviron()`. */
839
+ env?: { [key: string | number]: string | number | boolean };
840
+
841
+ /** Integer. If present, the process uid with `setuid`. */
842
+ uid?: number;
843
+
844
+ /** Integer. If present, the process gid with `setgid`. */
845
+ gid?: number;
846
+ };
847
+
848
+ /** Execute a process with the arguments args, and the provided options (if any). */
849
+ export function exec(args: Array<string>, options?: ExecOptions): number;
850
+
851
+ /**
852
+ * `waitpid` Unix system call. Returns the array [ret, status].
853
+ *
854
+ * From man waitpid(2):
855
+ *
856
+ * waitpid(): on success, returns the process ID of the child whose state has changed; if WNOHANG was specified and one or more child(ren) specified by pid exist, but have not yet changed state, then 0 is returned.
857
+ */
858
+ export function waitpid(pid: number, options?: number): [number, number];
859
+
860
+ /** Constant for the `options` argument of `waitpid`. */
861
+ export var WNOHANG: number;
862
+ /** Constant for the `options` argument of `waitpid`. */
863
+ export var WUNTRACED: number;
864
+
865
+ /** Function to be used to interpret the 'status' return value of `waitpid`. */
866
+ export function WEXITSTATUS(status: number): number;
867
+ /** Function to be used to interpret the 'status' return value of `waitpid`. */
868
+ export function WTERMSIG(status: number): number;
869
+ /** Function to be used to interpret the 'status' return value of `waitpid`. */
870
+ export function WSTOPSIG(status: number): number;
871
+
872
+ /** Function to be used to interpret the 'status' return value of `waitpid`. */
873
+ export function WIFEXITED(status: number): boolean;
874
+ /** Function to be used to interpret the 'status' return value of `waitpid`. */
875
+ export function WIFSIGNALED(status: number): boolean;
876
+ /** Function to be used to interpret the 'status' return value of `waitpid`. */
877
+ export function WIFSTOPPED(status: number): boolean;
878
+ /** Function to be used to interpret the 'status' return value of `waitpid`. */
879
+ export function WIFCONTINUED(status: number): boolean;
880
+
881
+ /** `dup` Unix system call. */
882
+ export function dup(fd: number): number;
883
+
884
+ /** `dup2` Unix system call. */
885
+ export function dup2(oldfd: number, newfd: number): number;
886
+
887
+ /** `pipe` Unix system call. Return two handles as `[read_fd, write_fd]`. */
888
+ export function pipe(): null | [number, number];
889
+
890
+ /** Sleep for `delay_ms` milliseconds. */
891
+ export function sleep(delay_ms: number): void;
892
+
893
+ export type OSTimer = { [Symbol.toStringTag]: "OSTimer" };
894
+
895
+ /** Call the function func after delay ms. Return a handle to the timer. */
896
+ export function setTimeout(
897
+ func: (...args: any) => any,
898
+ delay: number
899
+ ): OSTimer;
900
+
901
+ /** Cancel a timer. */
902
+ export function clearTimeout(handle: OSTimer): void;
903
+
904
+ /** Return a string representing the platform: "linux", "darwin", "win32", "freebsd", or "js" (emscripten). */
905
+ export var platform: "linux" | "darwin" | "win32" | "freebsd" | "js";
906
+
907
+ /**
908
+ * Things that can be put into Worker.postMessage.
909
+ *
910
+ * NOTE: This is effectively the same stuff as supported by the structured
911
+ * clone algorithm, but without support for Map/Set (not supported in
912
+ * QuickJS yet).
913
+ */
914
+ export type StructuredClonable =
915
+ | string
916
+ | number
917
+ | boolean
918
+ | null
919
+ | undefined
920
+ | Boolean
921
+ | String
922
+ | Date
923
+ | RegExp
924
+ | ArrayBuffer
925
+ | Int8Array
926
+ | Uint8Array
927
+ | Uint8ClampedArray
928
+ | Int16Array
929
+ | Uint16Array
930
+ | Int32Array
931
+ | Uint32Array
932
+ | Float32Array
933
+ | Float64Array
934
+ | BigInt64Array
935
+ | BigUint64Array
936
+ | DataView
937
+ | Array<StructuredClonable>
938
+ | SharedArrayBuffer
939
+ // Map and Set not yet supported
940
+ // | Map<StructuredClonable, StructuredClonable>
941
+ // | Set<StructuredClonable>
942
+ | { [key: string | number]: StructuredClonable };
943
+
944
+ export class Worker {
945
+ /**
946
+ * Constructor to create a new thread (worker) with an API close to the
947
+ * `WebWorkers`. `moduleFilename` is a string specifying the module
948
+ * filename which is executed in the newly created thread. As for
949
+ * dynamically imported module, it is relative to the current script or
950
+ * module path. Threads normally don’t share any data and communicate
951
+ * between each other with messages. Nested workers are not supported.
952
+ */
953
+ constructor(moduleFilename: string);
954
+
955
+ /**
956
+ * In the created worker, Worker.parent represents the parent worker and is
957
+ * used to send or receive messages.
958
+ */
959
+ static parent: Worker;
960
+
961
+ /**
962
+ * Send a message to the corresponding worker. msg is cloned in the
963
+ * destination worker using an algorithm similar to the HTML structured
964
+ * clone algorithm. SharedArrayBuffer are shared between workers.
965
+ *
966
+ * Current limitations: Map and Set are not supported yet.
967
+ */
968
+ postMessage(msg: StructuredClonable): void;
969
+
970
+ /**
971
+ * Set a function which is called each time a message is received. The
972
+ * function is called with a single argument. It is an object with a data
973
+ * property containing the received message. The thread is not terminated
974
+ * if there is at least one non null onmessage handler.
975
+ */
976
+ onmessage: null | ((event: { data: StructuredClonable }) => void);
977
+ }
978
+
979
+ /** constant for {@link access}(); test for read permission. */
980
+ export var R_OK: number;
981
+
982
+ /** constant for {@link access}(); test for write permission. */
983
+ export var W_OK: number;
984
+
985
+ /** constant for {@link access}(); test for execute (search) permission. */
986
+ export var X_OK: number;
987
+
988
+ /** constant for {@link access}(); test for existence of file. */
989
+ export var F_OK: number;
990
+
991
+ /** `access` Unix system call; checks if a file is readable, writable, executable, and/or exists (use {@link R_OK}, {@link W_OK}, {@link X_OK}, and/or {@link F_OK} for `accessMode`). Throws a descriptive error (with errno property) if the requested access is not available; otherwise, returns undefined. */
992
+ export function access(path: string, accessMode: number): void;
993
+
994
+ /** gets the path to the executable which is executing this JS code. might be a relative path or symlink. */
995
+ export function execPath(): string;
996
+
997
+ /** changes the access permission bits of the file at `path` using the octal number `mode`. */
998
+ export function chmod(path: string, mode: number): void;
999
+ }
1000
+
1001
+ /**
1002
+ * Options for {@link inspect}.
1003
+ */
1004
+ declare interface InspectOptions {
1005
+ /** Whether to display non-enumerable properties. Defaults to false. */
1006
+ all?: boolean;
1007
+
1008
+ /** Whether to invoke getter functions. Defaults to false. */
1009
+ followGetters?: boolean;
1010
+
1011
+ /** Whether to display the indexes of iterable entries. Defaults to false. */
1012
+ indexes?: boolean;
1013
+
1014
+ /** Hide object details after 𝑁 recursions. Defaults to Infinity. */
1015
+ maxDepth?: number;
1016
+
1017
+ /** If true, don't identify well-known symbols as `@@…`. Defaults to false. */
1018
+ noAmp?: boolean;
1019
+
1020
+ /** If true, don't format byte-arrays as hexadecimal. Defaults to false. */
1021
+ noHex?: boolean;
1022
+
1023
+ /** If true, don't display function source code. Defaults to false. */
1024
+ noSource?: boolean;
1025
+
1026
+ /** Whether to show `__proto__` properties if possible. Defaults to false. */
1027
+ proto?: boolean;
1028
+
1029
+ /** Whether to sort properties alphabetically. When false, properties are sorted by creation order. Defaults to false. */
1030
+ sort?: boolean;
1031
+
1032
+ /** Options that control whether and how ANSI terminal escape sequences for colours should be added to the output. Defaults to false, meaning no colours. */
1033
+ colours?: boolean | 256 | 8 | InspectColours;
1034
+
1035
+ /** Prefix string to use for indentation. Defaults to '\t'. */
1036
+ indent?: string;
1037
+ }
1038
+
1039
+ declare interface InspectColours {
1040
+ off?: string | number;
1041
+ red?: string | number;
1042
+ grey?: string | number;
1043
+ green?: string | number;
1044
+ darkGreen?: string | number;
1045
+ punct?: string | number;
1046
+ keys?: string | number;
1047
+ keyEscape?: string | number;
1048
+ typeColour?: string | number;
1049
+ primitive?: string | number;
1050
+ escape?: string | number;
1051
+ date?: string | number;
1052
+ hexBorder?: string | number;
1053
+ hexValue?: string | number;
1054
+ hexOffset?: string | number;
1055
+ reference?: string | number;
1056
+ srcBorder?: string | number;
1057
+ srcRowNum?: string | number;
1058
+ srcRowText?: string | number;
1059
+ nul?: string | number;
1060
+ nulProt?: string | number;
1061
+ undef?: string | number;
1062
+ noExts?: string | number;
1063
+ frozen?: string | number;
1064
+ sealed?: string | number;
1065
+ regex?: string | number;
1066
+ string?: string | number;
1067
+ symbol?: string | number;
1068
+ symbolFade?: string | number;
1069
+ braces?: string | number;
1070
+ quotes?: string | number;
1071
+ empty?: string | number;
1072
+ dot?: string | number;
1073
+ }
1074
+
1075
+ declare interface InspectFunction {
1076
+ /**
1077
+ * Generate a human-readable representation of a value.
1078
+ *
1079
+ * @param value - Value to inspect
1080
+ * @param options - Additional settings for refining output
1081
+ * @returns A string representation of `value`.
1082
+ */
1083
+ (value: any, options?: InspectOptions): string;
1084
+
1085
+ /**
1086
+ * Generate a human-readable representation of a value.
1087
+ *
1088
+ * @param value - Value to inspect
1089
+ * @param key - The value's corresponding member name
1090
+ * @param options - Additional settings for refining output
1091
+ * @returns A string representation of `value`.
1092
+ */
1093
+ (value: any, key?: string | symbol, options?: InspectOptions): string;
1094
+ }
1095
+
1096
+ /**
1097
+ * Generate a human-readable representation of a value.
1098
+ *
1099
+ * @param value - Value to inspect
1100
+ * @param key - The value's corresponding member name
1101
+ * @param options - Additional settings for refining output
1102
+ * @returns A string representation of `value`.
1103
+ */
1104
+ declare var inspect: InspectFunction;
1105
+
1106
+ /**
1107
+ * A global which lets you configure the module loader (import/export/require).
1108
+ * You can use these properties to add support for importing new filetypes.
1109
+ *
1110
+ * This global can also be used to identify whether an object is a module
1111
+ * namespace record.
1112
+ */
1113
+ interface ModuleGlobal {
1114
+ /**
1115
+ * Returns true if `target` is a module namespace object.
1116
+ */
1117
+ [Symbol.hasInstance](target: any): target is {
1118
+ [key: string | number | symbol]: any;
1119
+ };
1120
+
1121
+ /**
1122
+ * A list of filetype extensions that may be omitted from an import specifier
1123
+ * string.
1124
+ *
1125
+ * Defaults to `[".js"]`. You can add more strings to this array to
1126
+ * make the engine search for additional files when resolving a
1127
+ * require/import.
1128
+ *
1129
+ * See the doc comment on {@link require} for more information.
1130
+ *
1131
+ * NOTE: If you add a new extension to this array, you will likely also want
1132
+ * to add to {@link Module.compilers}.
1133
+ */
1134
+ searchExtensions: Array<string>;
1135
+
1136
+ /**
1137
+ * User-defined functions which will handle getting the JavaScript code
1138
+ * associated with a module.
1139
+ *
1140
+ * The key for each property in this object should be a file extension
1141
+ * string with a leading dot, eg `".jsx"`. The value for each property should
1142
+ * be a function which receives (1) the filepath to a module, and (2) that
1143
+ * file's content as a UTF-8 string, and the function should return a string
1144
+ * containing JavaScript code that corresponds to that module. In most cases,
1145
+ * these functions will compile the contents of the file from one format into JavaScript.
1146
+ *
1147
+ * The function does not have to use the second 'content' argument it
1148
+ * receives (ie. when loading binary files).
1149
+ *
1150
+ * By adding to this object, you can make it possible to import non-js
1151
+ * filetypes; compile-to-JS languages like JSX, TypeScript, and CoffeeScript
1152
+ * can be compiled at import time, and asset files like .txt files or .png
1153
+ * files can be converted into an appropriate data structure at import time.
1154
+ *
1155
+ * As an example, to make it possible to import .txt files, you might do:
1156
+ * ```js
1157
+ * import * as std from "std";
1158
+ *
1159
+ * Module.compilers[".txt"] = (filename, content) => {
1160
+ * return `export default ${JSON.stringify(content)}`;
1161
+ * }
1162
+ * ```
1163
+ * (leveraging `JSON.stringify`'s ability to escape quotes).
1164
+ *
1165
+ * Then, later in your code, you can do:
1166
+ * ```js
1167
+ * import names from "./names.txt";
1168
+ * ```
1169
+ *
1170
+ * And `names` will be a string containing the contents of names.txt.
1171
+ *
1172
+ * NOTE: When adding to this object, you may also wish to add to
1173
+ * {@link Module.searchExtensions}.
1174
+ */
1175
+ compilers: {
1176
+ [extensionWithDot: string]: (filename: string, content: string) => string;
1177
+ };
1178
+
1179
+ /**
1180
+ * Create a virtual built-in module whose exports consist of the own
1181
+ * enumerable properties of `obj`.
1182
+ */
1183
+ define(name: string, obj: { [key: string]: any }): void;
1184
+
1185
+ /**
1186
+ * Resolves a require/import request from `fromFile` into a canonicalized path.
1187
+ *
1188
+ * To change native module resolution behavior, replace this function with
1189
+ * your own implementation. Note that you must handle
1190
+ * `Module.searchExtensions` yourself in your replacement implementation.
1191
+ */
1192
+ resolve(name: string, fromFile: string): string;
1193
+
1194
+ /**
1195
+ * Reads the contents of the given resolved module name into a string.
1196
+ *
1197
+ * To change native module loading behavior, replace this function with your
1198
+ * own implementation. Note that you must handle `Module.compilers` yourself
1199
+ * in your replacement implementation.
1200
+ */
1201
+ read(modulePath: string): string;
1202
+ }
1203
+
1204
+ declare var Module: ModuleGlobal;
1205
+
1206
+ interface RequireFunction {
1207
+ /**
1208
+ * Synchronously import a module.
1209
+ *
1210
+ * `source` will be resolved relative to the calling file.
1211
+ *
1212
+ * If `source` does not have a file extension, and a file without an extension
1213
+ * cannot be found, the engine will check for files with the extensions in
1214
+ * {@link Module.searchExtensions}, and use one of those if present. This
1215
+ * behavior also happens when using normal `import` statements.
1216
+ *
1217
+ * For example, if you write:
1218
+ *
1219
+ * ```js
1220
+ * import something from "./somewhere";
1221
+ * ```
1222
+ *
1223
+ * but there's no file named `somewhere` in the same directory as the file
1224
+ * where that import appears, and `Module.searchExtensions` is the default
1225
+ * value:
1226
+ *
1227
+ * ```js
1228
+ * [".js"]
1229
+ * ```
1230
+ *
1231
+ * then the engine will look for `somewhere.js`. If that doesn't exist, the
1232
+ * engine will look for `somewhere/index.js`. If *that* doesn't exist, an error
1233
+ * will be thrown.
1234
+ *
1235
+ * If you add more extensions to `Module.searchExtensions`, then the engine
1236
+ * will use those, too. It will search in the same order as the strings appear
1237
+ * in the `Module.searchExtensions` array.
1238
+ */
1239
+ (source: string): any;
1240
+
1241
+ /**
1242
+ * Resolves the normalized path to a modules, relative to the calling file.
1243
+ */
1244
+ resolve: (source: string) => string;
1245
+ }
1246
+
1247
+ declare var require: RequireFunction;
1248
+
1249
+ declare var setTimeout: typeof import("quickjs:os").setTimeout;
1250
+ declare var clearTimeout: typeof import("quickjs:os").clearTimeout;
1251
+
1252
+ declare type Interval = { [Symbol.toStringTag]: "Interval" };
1253
+
1254
+ declare function setInterval(func: (...args: any) => any, ms: number): Interval;
1255
+ declare function clearInterval(interval: Interval): void;
1256
+
1257
+ interface StringConstructor {
1258
+ /**
1259
+ * A no-op template literal tag.
1260
+ *
1261
+ * https://github.com/tc39/proposal-string-cooked
1262
+ */
1263
+ cooked(
1264
+ strings: readonly string[] | ArrayLike<string>,
1265
+ ...substitutions: any[]
1266
+ ): string;
1267
+
1268
+ /**
1269
+ * Remove leading minimum indentation from the string.
1270
+ * The first line of the string must be empty.
1271
+ *
1272
+ * https://github.com/tc39/proposal-string-dedent
1273
+ */
1274
+ dedent: {
1275
+ /**
1276
+ * Remove leading minimum indentation from the string.
1277
+ * The first line of the string must be empty.
1278
+ *
1279
+ * https://github.com/tc39/proposal-string-dedent
1280
+ */
1281
+ (input: string): string;
1282
+
1283
+ /**
1284
+ * Remove leading minimum indentation from the template literal.
1285
+ * The first line of the string must be empty.
1286
+ *
1287
+ * https://github.com/tc39/proposal-string-dedent
1288
+ */
1289
+ (
1290
+ strings: readonly string[] | ArrayLike<string>,
1291
+ ...substitutions: any[]
1292
+ ): string;
1293
+
1294
+ /**
1295
+ * Wrap another template tag function such that tagged literals
1296
+ * become dedented before being passed to the wrapped function.
1297
+ *
1298
+ * https://www.npmjs.com/package/string-dedent#usage
1299
+ */
1300
+ <
1301
+ Func extends (
1302
+ strings: readonly string[] | ArrayLike<string>,
1303
+ ...substitutions: any[]
1304
+ ) => string
1305
+ >(
1306
+ input: Func
1307
+ ): Func;
1308
+ };
1309
+ }