yavascript 0.0.0 → 0.0.1

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.
Binary file
Binary file
Binary file
@@ -0,0 +1,14 @@
1
+ var path = require("path");
2
+
3
+ var binaryPath;
4
+ if (process.platform === "win32") {
5
+ binaryPath = path.resolve(__dirname, "..", "bin", "win32", "yavascript.exe");
6
+ } else if (process.platform === "darwin") {
7
+ binaryPath = path.resolve(__dirname, "..", "bin", "darwin", "yavascript");
8
+ } else if (process.platform === "linux") {
9
+ binaryPath = path.resolve(__dirname, "..", "bin", "linux", "yavascript");
10
+ } else {
11
+ throw new Error("Unsupported platform: " + process.platform);
12
+ }
13
+
14
+ module.exports = binaryPath;
package/lib/cli.js ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ var child_process = require("child_process");
3
+ var binaryPath = require("./binary-path");
4
+
5
+ try {
6
+ child_process.execFileSync(binaryPath, process.argv.slice(2), {
7
+ cwd: process.cwd(),
8
+ stdio: "inherit",
9
+ });
10
+ } catch (err) {
11
+ process.exitCode = 1;
12
+ }
package/lib/index.js ADDED
@@ -0,0 +1,7 @@
1
+ const binaryPath = require("./binary-path");
2
+ const version = require("./package.json").version;
3
+
4
+ module.exports = {
5
+ binaryPath,
6
+ version,
7
+ };
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "yavascript",
3
- "version": "0.0.0",
4
- "main": "index.js",
3
+ "version": "0.0.1",
4
+ "main": "lib/index.js",
5
+ "bin": "lib/cli.js",
6
+ "types": "yavascript.d.ts",
7
+ "author": "Lily Scott <me@suchipi.com>",
5
8
  "license": "MIT"
6
9
  }
@@ -0,0 +1,940 @@
1
+
2
+ // ---------------
3
+ // YavaScript APIs
4
+ // ---------------
5
+
6
+ declare const env: { [key: string]: string | undefined };
7
+
8
+ interface Exec {
9
+ (args: Array<string>): void;
10
+
11
+ (args: Array<string>, options: Record<string, never>): void;
12
+
13
+ (
14
+ args: Array<string>,
15
+ options: {
16
+ /**
17
+ * Whether an Error should be thrown when the process exits with a nonzero
18
+ * status code.
19
+ *
20
+ * Defaults to true.
21
+ */
22
+ failOnNonZeroStatus: true;
23
+ /**
24
+ * If true, stdout and stderr will be collected into strings and returned
25
+ * instead of being printed to the screen.
26
+ *
27
+ * Defaults to false.
28
+ */
29
+ captureOutput: false;
30
+ }
31
+ ): void;
32
+
33
+ (
34
+ args: Array<string>,
35
+ options: {
36
+ /**
37
+ * Whether an Error should be thrown when the process exits with a nonzero
38
+ * status code.
39
+ *
40
+ * Defaults to true.
41
+ */
42
+ failOnNonZeroStatus: false;
43
+ /**
44
+ * If true, stdout and stderr will be collected into strings and returned
45
+ * instead of being printed to the screen.
46
+ *
47
+ * Defaults to false.
48
+ */
49
+ captureOutput: false;
50
+ }
51
+ ): { status: number };
52
+
53
+ (
54
+ args: Array<string>,
55
+ options: {
56
+ /**
57
+ * Whether an Error should be thrown when the process exits with a nonzero
58
+ * status code.
59
+ *
60
+ * Defaults to true.
61
+ */
62
+ failOnNonZeroStatus: false;
63
+ }
64
+ ): { status: number };
65
+
66
+ (
67
+ args: Array<string>,
68
+ options: {
69
+ /**
70
+ * Whether an Error should be thrown when the process exits with a nonzero
71
+ * status code.
72
+ *
73
+ * Defaults to true.
74
+ */
75
+ failOnNonZeroStatus: true;
76
+ /**
77
+ * If true, stdout and stderr will be collected into strings and returned
78
+ * instead of being printed to the screen.
79
+ *
80
+ * Defaults to false.
81
+ */
82
+ captureOutput: true;
83
+ }
84
+ ): { stdout: string; stderr: string };
85
+
86
+ (
87
+ args: Array<string>,
88
+ options: {
89
+ /**
90
+ * If true, stdout and stderr will be collected into strings and returned
91
+ * instead of being printed to the screen.
92
+ *
93
+ * Defaults to false.
94
+ */
95
+ captureOutput: true;
96
+ }
97
+ ): { stdout: string; stderr: string };
98
+
99
+ (
100
+ args: Array<string>,
101
+ options: {
102
+ /**
103
+ * Whether an Error should be thrown when the process exits with a nonzero
104
+ * status code.
105
+ *
106
+ * Defaults to true.
107
+ */
108
+ failOnNonZeroStatus: false;
109
+ captureOutput: true;
110
+ }
111
+ ): { stdout: string; stderr: string; status: number };
112
+ }
113
+
114
+ /** Run a child process using the provided arguments. The first value in the arguments array is the program to run. */
115
+ declare const exec: Exec;
116
+
117
+ /** Alias for `exec(args, { captureOutput: true, failOnNonZeroStatus: false })` */
118
+ declare function $(args: Array<string>): {
119
+ stdout: string;
120
+ stderr: string;
121
+ status: number;
122
+ };
123
+
124
+ /** Read the contents of a file from disk, as a string. */
125
+ declare function readFile(path: string): string;
126
+
127
+ /** Write the contents of a string or ArrayBuffer to a file. */
128
+ declare function writeFile(path: string, data: string | ArrayBuffer): void;
129
+
130
+ /** Returns true if the path points to a directory, or if the path points to a symlink which points to a directory. */
131
+ declare function isDir(path: string): boolean;
132
+
133
+ /** Delete the file or directory at the specified path. If the directory isn't empty, its contents will be deleted, too. */
134
+ declare function remove(path: string): void;
135
+
136
+ /** Returns true if a file or directory exists at the specified path. */
137
+ declare function exists(path: string): boolean;
138
+
139
+ /** Change the process's current working directory to the specified path. */
140
+ declare function cd(path: string): void;
141
+
142
+ /** Return the process's current working directory. */
143
+ declare function pwd(): string;
144
+
145
+ /**
146
+ * Search the filesystem for files matching the specified glob patterns. Uses [minimatch](https://www.npmjs.com/package/minimatch) with its default options.
147
+ *
148
+ * `followSymlinks` defaults to false.
149
+ */
150
+ declare function glob(
151
+ dir: string,
152
+ patterns: Array<string>,
153
+ options?: { followSymlinks?: boolean }
154
+ ): Array<string>;
155
+
156
+ /** Print a value or values to stdout. */
157
+ declare const echo: typeof console.log;
158
+
159
+ /** Convert a value to a string, using the same logic as `echo` and `console.log`. */
160
+ declare function inspect(value: any): string;
161
+
162
+ /** Remove ANSI control characters from a string. */
163
+ declare function stripAnsi(input: string): string;
164
+
165
+ /** Wrap a string in double quotes, and escape any double-quotes inside with `\"`. */
166
+ declare function quote(input: string): string;
167
+
168
+ // Colors
169
+
170
+ /** Wrap a string with the ANSI control characters that will make it print as black text. */
171
+ declare function black(input: string | number): string;
172
+ /** Wrap a string with the ANSI control characters that will make it print as red text. */
173
+ declare function red(input: string | number): string;
174
+ /** Wrap a string with the ANSI control characters that will make it print as green text. */
175
+ declare function green(input: string | number): string;
176
+ /** Wrap a string with the ANSI control characters that will make it print as yellow text. */
177
+ declare function yellow(input: string | number): string;
178
+ /** Wrap a string with the ANSI control characters that will make it print as blue text. */
179
+ declare function blue(input: string | number): string;
180
+ /** Wrap a string with the ANSI control characters that will make it print as magenta text. */
181
+ declare function magenta(input: string | number): string;
182
+ /** Wrap a string with the ANSI control characters that will make it print as cyan text. */
183
+ declare function cyan(input: string | number): string;
184
+ /** Wrap a string with the ANSI control characters that will make it print as white text. */
185
+ declare function white(input: string | number): string;
186
+ /** Wrap a string with the ANSI control characters that will make it print as gray text. */
187
+ declare function gray(input: string | number): string;
188
+ /** Wrap a string with the ANSI control characters that will make it print as grey text. */
189
+ declare function grey(input: string | number): string;
190
+
191
+ // Background Colors
192
+
193
+ /** Wrap a string with the ANSI control characters that will make it have a black background. */
194
+ declare function bgBlack(input: string | number): string;
195
+ /** Wrap a string with the ANSI control characters that will make it have a red background. */
196
+ declare function bgRed(input: string | number): string;
197
+ /** Wrap a string with the ANSI control characters that will make it have a green background. */
198
+ declare function bgGreen(input: string | number): string;
199
+ /** Wrap a string with the ANSI control characters that will make it have a yellow background. */
200
+ declare function bgYellow(input: string | number): string;
201
+ /** Wrap a string with the ANSI control characters that will make it have a blue background. */
202
+ declare function bgBlue(input: string | number): string;
203
+ /** Wrap a string with the ANSI control characters that will make it have a magenta background. */
204
+ declare function bgMagenta(input: string | number): string;
205
+ /** Wrap a string with the ANSI control characters that will make it have a cyan background. */
206
+ declare function bgCyan(input: string | number): string;
207
+ /** Wrap a string with the ANSI control characters that will make it have a white background. */
208
+ declare function bgWhite(input: string | number): string;
209
+
210
+ // Modifiers
211
+
212
+ /** Wrap a string with the ANSI control character that resets all styling. */
213
+ declare function reset(input: string | number): string;
214
+ /** Wrap a string with the ANSI control characters that will make it print with a bold style. */
215
+ declare function bold(input: string | number): string;
216
+ /** Wrap a string with the ANSI control characters that will make it print with a dimmed style. */
217
+ declare function dim(input: string | number): string;
218
+ /** Wrap a string with the ANSI control characters that will make it print italicized. */
219
+ declare function italic(input: string | number): string;
220
+ /** Wrap a string with the ANSI control characters that will make it print underlined. */
221
+ declare function underline(input: string | number): string;
222
+ /** Wrap a string with ANSI control characters such that its foreground (text) and background colors are swapped. */
223
+ declare function inverse(input: string | number): string;
224
+ /** Wrap a string with ANSI control characters such that it is hidden. */
225
+ declare function hidden(input: string | number): string;
226
+ /** Wrap a string with the ANSI control characters that will make it print with a horizontal line through its center. */
227
+ declare function strikethrough(input: string | number): string;
228
+
229
+ // ------------------------------------------
230
+ // QuickJS APIs, which YavaScript builds upon
231
+ // ------------------------------------------
232
+
233
+ // Definitions of the globals and modules added by quickjs-libc
234
+
235
+ /**
236
+ * Provides the command line arguments. The first argument is the script name.
237
+ */
238
+ declare var scriptArgs: Array<string>;
239
+
240
+ /**
241
+ * Print the arguments separated by spaces and a trailing newline.
242
+ *
243
+ * Non-string args are coerced into a string via [ToString](https://tc39.es/ecma262/#sec-tostring).
244
+ * Objects can override the default `ToString` behavior by defining a `toString` method.
245
+ */
246
+ declare var print: (...args: Array<any>) => void;
247
+
248
+ /**
249
+ * Object that provides functions for logging information.
250
+ */
251
+ declare var console: {
252
+ /** Same as {@link print}(). */
253
+ log: typeof print;
254
+ };
255
+
256
+ declare module "std" {
257
+ /**
258
+ * Exit the process with the provided status code.
259
+ *
260
+ * @param statusCode The exit code; 0 for success, nonzero for failure.
261
+ */
262
+ export function exit(statusCode: number): void;
263
+
264
+ /**
265
+ * Evaluate the string `code` as a script (global eval).
266
+ *
267
+ * @param code - The code to evaluate.
268
+ * @param options - An optional object containing the following optional properties:
269
+ * @property backtraceBarrier - Boolean (default = false). If true, error backtraces do not list the stack frames below the evalScript.
270
+ * @returns The result of the evaluation.
271
+ */
272
+ export function evalScript(
273
+ code: string,
274
+ options?: { backtraceBarrier?: boolean }
275
+ ): any;
276
+
277
+ /**
278
+ * Evaluate the file `filename` as a script (global eval).
279
+ *
280
+ * @param filename - The relative or absolute path to the file to load. Relative paths are resolved relative to the process's current working directory.
281
+ * @returns The result of the evaluation.
282
+ */
283
+ export function loadScript(filename: string): any;
284
+
285
+ /**
286
+ * Evaluate the file `filename` as a module. Effectively a synchronous dynamic `import()`.
287
+ *
288
+ * @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.
289
+ * @param basename - If present and `filename` is a relative path, `filename` will be resolved relative to this basename.
290
+ * @returns The result of the evaluation (module namespace object).
291
+ */
292
+ export function importModule(
293
+ filename: string,
294
+ basename?: string
295
+ ): { [key: string]: any };
296
+
297
+ /**
298
+ * Load the file `filename` and return it as a string assuming UTF-8 encoding.
299
+ *
300
+ * @param filename - The relative or absolute path to the file to load. Relative paths are resolved relative to the process's current working directory.
301
+ */
302
+ export function loadFile(filename: string): string;
303
+
304
+ /**
305
+ * Open a file (wrapper to the libc `fopen()`).
306
+ * Return the FILE object.
307
+ *
308
+ * @param filename - The relative or absolute path to the file to open. Relative paths are resolved relative to the process's current working directory.
309
+ * @param flags - A string containing any combination of the characters 'r', 'w', 'a', '+', and/or 'b'.
310
+ * @returns The opened FILE object.
311
+ */
312
+ export function open(filename: string, flags: string): FILE;
313
+
314
+ /**
315
+ * Open a process by creating a pipe (wrapper to the libc `popen()`).
316
+ * Return the FILE object.
317
+ *
318
+ * @param command - The command line to execute. Gets passed via `/bin/sh -c`.
319
+ * @param flags - A string containing any combination of the characters 'r', 'w', 'a', '+', and/or 'b'.
320
+ * @returns The opened FILE object.
321
+ */
322
+ export function popen(command: string, flags: string): FILE;
323
+
324
+ /**
325
+ * Open a file from a file handle (wrapper to the libc `fdopen()`).
326
+ * Return the FILE object.
327
+ *
328
+ * @param fd - The file handle to open.
329
+ * @param flags - A string containing any combination of the characters 'r', 'w', 'a', '+', and/or 'b'.
330
+ * @returns The opened FILE object.
331
+ */
332
+ export function fdopen(fd: number, flags: string): FILE;
333
+
334
+ /**
335
+ * Open a temporary file.
336
+ * Return the FILE object.
337
+ *
338
+ * @returns The opened FILE object.
339
+ */
340
+ export function tmpfile(): FILE;
341
+
342
+ /** Equivalent to `std.out.puts(str)`. */
343
+ export function puts(str: string): void;
344
+
345
+ /** Equivalent to `std.out.printf(fmt, ...args)` */
346
+ export function printf(fmt: string, ...args: Array<any>): void;
347
+
348
+ /** Equivalent to the libc sprintf(). */
349
+ export function sprintf(fmt: string, ...args: Array<any>): void;
350
+
351
+ /** Wrapper to the libc file stdin. */
352
+ var in_: FILE;
353
+
354
+ export { in_ as in };
355
+
356
+ /** Wrapper to the libc file stdout. */
357
+ export var out: FILE;
358
+
359
+ /** Wrapper to the libc file stderr. */
360
+ export var err: FILE;
361
+
362
+ /** Constant for {@link FILE.seek}. Declares that pointer offset should be relative to the beginning of the file. See also libc `fseek()`. */
363
+ export var SEEK_SET: number;
364
+
365
+ /** Constant for {@link FILE.seek}. Declares that the offset should be relative to the current position of the FILE handle. See also libc `fseek()`. */
366
+ export var SEEK_CUR: number;
367
+
368
+ /** Constant for {@link FILE.seek}. Declares that the offset should be relative to the end of the file. See also libc `fseek()`. */
369
+ export var SEEK_END: number;
370
+
371
+ /** 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. */
372
+ export function gc(): void;
373
+
374
+ /** Return the value of the environment variable `name` or `undefined` if it is not defined. */
375
+ export function getenv(name: string): string | undefined;
376
+
377
+ /** Set the value of the environment variable `name` to the string `value`. */
378
+ export function setenv(name: string, value: string): void;
379
+
380
+ /** Delete the environment variable `name`. */
381
+ export function unsetenv(name: string): void;
382
+
383
+ /** Return an object containing the environment variables as key-value pairs. */
384
+ export function getenviron(): { [key: string]: string | undefined };
385
+
386
+ interface UrlGet {
387
+ /**
388
+ * Download `url` using the `curl` command line utility. Returns string
389
+ * when the http status code is between 200 and 299, and throws otherwise.
390
+ *
391
+ * Pass an object with { full: true } as the second argument to get
392
+ * response headers and status code.
393
+ */
394
+ (url: string): string;
395
+
396
+ /**
397
+ * Download `url` using the `curl` command line utility. Returns string
398
+ * when the http status code is between 200 and 299, and throws otherwise.
399
+ *
400
+ * Pass an object with { full: true } as the second argument to get
401
+ * response headers and status code.
402
+ */
403
+ (url: string, options: { binary: false }): string;
404
+
405
+ /**
406
+ * Download `url` using the `curl` command line utility. Returns string
407
+ * when the http status code is between 200 and 299, and throws otherwise.
408
+ *
409
+ * Pass an object with { full: true } as the second argument to get
410
+ * response headers and status code.
411
+ */
412
+ (url: string, options: { full: false }): string;
413
+
414
+ /**
415
+ * Download `url` using the `curl` command line utility. Returns string
416
+ * when the http status code is between 200 and 299, and throws otherwise.
417
+ *
418
+ * Pass an object with { full: true } as the second argument to get
419
+ * response headers and status code.
420
+ */
421
+ (url: string, options: { binary: false; full: false }): string;
422
+
423
+ /**
424
+ * Download `url` using the `curl` command line utility. Returns
425
+ * ArrayBuffer when the http status code is between 200 and 299, and throws
426
+ * otherwise.
427
+ *
428
+ * Pass an object with { full: true } as the second argument to get
429
+ * response headers and status code.
430
+ */
431
+ (url: string, options: { binary: true }): ArrayBuffer;
432
+
433
+ /**
434
+ * Download `url` using the `curl` command line utility. Returns
435
+ * ArrayBuffer when the http status code is between 200 and 299, and throws
436
+ * otherwise.
437
+ *
438
+ * Pass an object with { full: true } as the second argument to get
439
+ * response headers and status code.
440
+ */
441
+ (url: string, options: { binary: true; full: false }): ArrayBuffer;
442
+
443
+ /**
444
+ * Download `url` using the `curl` command line utility.
445
+ *
446
+ * Returns an object with three properties:
447
+ *
448
+ * - `response`: response body content (string)
449
+ * - `responseHeaders`: headers separated by CRLF (string)
450
+ * - `status`: status code (number)
451
+ */
452
+ (url: string, options: { full: true }): {
453
+ status: number;
454
+ response: string;
455
+ responseHeaders: string;
456
+ };
457
+
458
+ /**
459
+ * Download `url` using the `curl` command line utility.
460
+ *
461
+ * Returns an object with three properties:
462
+ *
463
+ * - `response`: response body content (string)
464
+ * - `responseHeaders`: headers separated by CRLF (string)
465
+ * - `status`: status code (number)
466
+ */
467
+ (url: string, options: { full: true; binary: false }): {
468
+ status: number;
469
+ response: string;
470
+ responseHeaders: string;
471
+ };
472
+
473
+ /**
474
+ * Download `url` using the `curl` command line utility.
475
+ *
476
+ * Returns an object with three properties:
477
+ *
478
+ * - `response`: response body content (ArrayBuffer)
479
+ * - `responseHeaders`: headers separated by CRLF (string)
480
+ * - `status`: status code (number)
481
+ */
482
+ (url: string, options: { full: true; binary: true }): {
483
+ status: number;
484
+ response: ArrayBuffer;
485
+ responseHeaders: string;
486
+ };
487
+ }
488
+
489
+ export var urlGet: UrlGet;
490
+
491
+ /**
492
+ * Parse `str` using a superset of JSON.parse. The following extensions are accepted:
493
+ *
494
+ * - Single line and multiline comments
495
+ * - unquoted properties (ASCII-only Javascript identifiers)
496
+ * - trailing comma in array and object definitions
497
+ * - single quoted strings
498
+ * - `\f` and `\v` are accepted as space characters
499
+ * - leading plus in numbers
500
+ * - octal (0o prefix) and hexadecimal (0x prefix) numbers
501
+ */
502
+ export function parseExtJSON(str: string): any;
503
+
504
+ /** An object representing a file handle. */
505
+ export class FILE {
506
+ /** Close the file. */
507
+ close(): void;
508
+
509
+ /** Outputs the string with the UTF-8 encoding. */
510
+ puts(str: string): void;
511
+
512
+ /**
513
+ * Formatted printf.
514
+ *
515
+ * 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.
516
+ */
517
+ printf(fmt: string, ...args: Array<any>): void;
518
+
519
+ /** Flush the buffered file. Wrapper for C `fflush`. */
520
+ flush(): void;
521
+
522
+ /** Sync the buffered file to disk. Wrapper for C `fsync`. */
523
+ sync(): void;
524
+
525
+ /**
526
+ * Seek to a given file position (whence is `std.SEEK_*`).
527
+ *
528
+ * `offset` can be a number or a bigint.
529
+ */
530
+ seek(
531
+ offset: number,
532
+ whence: typeof SEEK_SET | typeof SEEK_CUR | typeof SEEK_END
533
+ ): void;
534
+
535
+ /** Return the current file position. */
536
+ tell(): number;
537
+
538
+ /** Return the current file position as a bigint. */
539
+ tello(): BigInt;
540
+
541
+ /** Return true if end of file. */
542
+ eof(): boolean;
543
+
544
+ /** Return the associated OS handle. */
545
+ fileno(): number;
546
+
547
+ /** 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. */
548
+ read(buffer: ArrayBuffer, position: number, length: number): number;
549
+
550
+ /** Write `length` bytes from the file to the ArrayBuffer `buffer` at byte position `position` (wrapper to the libc `fwrite`). Returns the number of bytes written. */
551
+ write(buffer: ArrayBuffer, position: number, length: number): number;
552
+
553
+ /** Return the next line from the file, assuming UTF-8 encoding, excluding the trailing line feed. */
554
+ getline(): string;
555
+
556
+ /** 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. */
557
+ readAsString(maxSize?: number): string;
558
+
559
+ /** Return the next byte from the file. Return -1 if the end of file is reached. */
560
+ getByte(): number;
561
+
562
+ /** Write one byte to the file. */
563
+ putByte(value: number): void;
564
+ }
565
+ }
566
+
567
+ declare module "os" {
568
+ /**
569
+ * Open a file handle. Returns a number; the file descriptor.
570
+ *
571
+ * @param filename - The path to the file to open.
572
+ * @param flags - Numeric flags that set the mode to use when opening the file. See `os.O_*`
573
+ * @param mode - Octal access mask. Defaults to 0o666.
574
+ */
575
+ export function open(filename: string, flags: number, mode?: number): number;
576
+
577
+ /** POSIX open flag, used in {@link open}. */
578
+ export var O_RDONLY: number;
579
+
580
+ /** POSIX open flag, used in {@link open}. */
581
+ export var O_WRONLY: number;
582
+
583
+ /** POSIX open flag, used in {@link open}. */
584
+ export var O_RDWR: number;
585
+
586
+ /** POSIX open flag, used in {@link open}. */
587
+ export var O_APPEND: number;
588
+
589
+ /** POSIX open flag, used in {@link open}. */
590
+ export var O_CREAT: number;
591
+
592
+ /** POSIX open flag, used in {@link open}. */
593
+ export var O_EXCL: number;
594
+
595
+ /** POSIX open flag, used in {@link open}. */
596
+ export var O_TRUNC: number;
597
+
598
+ /** Windows-specific open flag: open the file in text mode. The default is binary mode. Used in {@link open}. */
599
+ export var O_TEXT: number;
600
+
601
+ /** Close the file with descriptor `fd`. */
602
+ export function close(fd: number): void;
603
+
604
+ interface OsSeek {
605
+ /** 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. */
606
+ (fd: number, offset: number, whence: number): number;
607
+
608
+ /** 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. */
609
+ (fd: number, offset: BigInt, whence: number): BigInt;
610
+ }
611
+
612
+ /** 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. */
613
+ export var seek: OsSeek;
614
+
615
+ /** Read `length` bytes from the file with descriptor `fd` to the ArrayBuffer `buffer` at byte position `offset`. Return the number of read bytes. */
616
+ export function read(
617
+ fd: number,
618
+ buffer: ArrayBuffer,
619
+ offset: number,
620
+ length: number
621
+ ): number;
622
+
623
+ /** Write `length` bytes to the file with descriptor `fd` from the ArrayBuffer `buffer` at byte position `offset`. Return the number of written bytes. */
624
+ export function write(
625
+ fd: number,
626
+ buffer: ArrayBuffer,
627
+ offset: number,
628
+ length: number
629
+ ): number;
630
+
631
+ /** Return `true` if the file opened with descriptor `fd` is a TTY (terminal). */
632
+ export function isatty(fd: number): boolean;
633
+
634
+ /** Return the TTY size as `[width, height]` or `null` if not available. */
635
+ export function ttyGetWinSize(fd: number): null | [number, number];
636
+
637
+ /** Set the TTY in raw mode. */
638
+ export function ttySetRaw(fd: number): void;
639
+
640
+ /** Remove a file. */
641
+ export function remove(filename: string): void;
642
+
643
+ /** Rename a file. */
644
+ export function rename(oldname: string, newname: string): void;
645
+
646
+ /** Return the canonicalized absolute pathname of `path`. */
647
+ export function realpath(path: string): string;
648
+
649
+ /** Return the current working directory. */
650
+ export function getcwd(): string;
651
+
652
+ /** Change the current directory. */
653
+ export function chdir(path: string): void;
654
+
655
+ /** Create a directory at `path`. */
656
+ export function mkdir(path: string, mode?: number): void;
657
+
658
+ export type Stats = {
659
+ dev: number;
660
+ ino: number;
661
+ mode: number;
662
+ nlink: number;
663
+ uid: number;
664
+ gid: number;
665
+ rdev: number;
666
+ size: number;
667
+ blocks: number;
668
+ atime: number;
669
+ mtime: number;
670
+ ctime: number;
671
+ };
672
+
673
+ /**
674
+ * Return a stats object with the following fields:
675
+ *
676
+ * - `dev`
677
+ * - `ino`
678
+ * - `mode`
679
+ * - `nlink`
680
+ * - `uid`
681
+ * - `gid`
682
+ * - `rdev`
683
+ * - `size`
684
+ * - `blocks`
685
+ * - `atime`
686
+ * - `mtime`
687
+ * - `ctime`
688
+ *
689
+ * The times are specified in milliseconds since 1970. `lstat()` is the same as `stat()` except that it returns information about the link itself.
690
+ */
691
+ export function stat(path: string): Stats;
692
+
693
+ /**
694
+ * Return a stats object with the following fields:
695
+ *
696
+ * - `dev`
697
+ * - `ino`
698
+ * - `mode`
699
+ * - `nlink`
700
+ * - `uid`
701
+ * - `gid`
702
+ * - `rdev`
703
+ * - `size`
704
+ * - `blocks`
705
+ * - `atime`
706
+ * - `mtime`
707
+ * - `ctime`
708
+ *
709
+ * The times are specified in milliseconds since 1970. `lstat()` is the same as `stat()` except that it returns information about the link itself.
710
+ */
711
+ export function lstat(path: string): Stats;
712
+
713
+ /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
714
+ export var S_IFMT: number;
715
+ /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
716
+ export var S_IFIFO: number;
717
+ /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
718
+ export var S_IFCHR: number;
719
+ /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
720
+ export var S_IFDIR: number;
721
+ /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
722
+ export var S_IFBLK: number;
723
+ /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
724
+ export var S_IFREG: number;
725
+ /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
726
+ export var S_IFSOCK: number;
727
+ /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
728
+ export var S_IFLNK: number;
729
+ /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
730
+ export var S_ISGID: number;
731
+ /** Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`. */
732
+ export var S_ISUID: 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
+ /** Send the signal `sig` to the process `pid`. Use `os.SIG*` constants. */
781
+ export function kill(pid: number, sig: number): void;
782
+
783
+ export type ExecOptions = {
784
+ /** 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. */
785
+ block?: boolean;
786
+
787
+ /** Boolean (default = true). If true, the file is searched in the `PATH` environment variable. */
788
+ usePath?: boolean;
789
+
790
+ /** String (default = `args[0]`). Set the file to be executed. */
791
+ file?: string;
792
+
793
+ /** String. If present, set the working directory of the new process. */
794
+ cwd?: string;
795
+
796
+ /** If present, set the file descriptor in the child for stdin. */
797
+ stdin?: number;
798
+
799
+ /** If present, set the file descriptor in the child for stdout. */
800
+ stdout?: number;
801
+
802
+ /** If present, set the file descriptor in the child for stderr. */
803
+ stderr?: number;
804
+
805
+ /** 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()`. */
806
+ env?: { [key: string | number]: string | number | boolean };
807
+
808
+ /** Integer. If present, the process uid with `setuid`. */
809
+ uid?: number;
810
+
811
+ /** Integer. If present, the process gid with `setgid`. */
812
+ gid?: number;
813
+ };
814
+
815
+ /** Execute a process with the arguments args, and the provided options (if any). */
816
+ export function exec(args: Array<string>, options?: ExecOptions): number;
817
+
818
+ /**
819
+ * `waitpid` Unix system call. Returns the array [ret, status].
820
+ *
821
+ * From man waitpid(2):
822
+ *
823
+ * 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.
824
+ */
825
+ export function waitpid(pid: number, options?: number): [number, number];
826
+
827
+ /** Constant for the `options` argument of `waitpid`. */
828
+ export var WNOHANG: number;
829
+
830
+ /** `dup` Unix system call. */
831
+ export function dup(fd: number): number;
832
+
833
+ /** `dup2` Unix system call. */
834
+ export function dup2(oldfd: number, newfd: number): number;
835
+
836
+ /** `pipe` Unix system call. Return two handles as `[read_fd, write_fd]`. */
837
+ export function pipe(): null | [number, number];
838
+
839
+ /** Sleep for `delay_ms` milliseconds. */
840
+ export function sleep(delay_ms: number): void;
841
+
842
+ export type Timer = number & { __is: "Timer" };
843
+
844
+ /** Call the function func after delay ms. Return a handle to the timer. */
845
+ export function setTimeout(func: () => void, delay: number): Timer;
846
+
847
+ /** Cancel a timer. */
848
+ export function clearTimeout(handle: Timer): void;
849
+
850
+ /** Return a string representing the platform: "linux", "darwin", "win32" or "js". */
851
+ export var platform: "linux" | "darwin" | "win32" | "js";
852
+
853
+ /**
854
+ * Things that can be put into Worker.postMessage.
855
+ *
856
+ * NOTE: This is effectively the same stuff as supported by the structured
857
+ * clone algorithm, but without support for Map/Set (not supported in
858
+ * QuickJS yet).
859
+ */
860
+ export type StructuredClonable =
861
+ | string
862
+ | number
863
+ | boolean
864
+ | null
865
+ | undefined
866
+ | Boolean
867
+ | String
868
+ | Date
869
+ | RegExp
870
+ | ArrayBuffer
871
+ | Int8Array
872
+ | Uint8Array
873
+ | Uint8ClampedArray
874
+ | Int16Array
875
+ | Uint16Array
876
+ | Int32Array
877
+ | Uint32Array
878
+ | Float32Array
879
+ | Float64Array
880
+ | BigInt64Array
881
+ | BigUint64Array
882
+ | DataView
883
+ | Array<StructuredClonable>
884
+ | SharedArrayBuffer
885
+ // Map and Set not yet supported
886
+ // | Map<StructuredClonable, StructuredClonable>
887
+ // | Set<StructuredClonable>
888
+ | { [key: string | number]: StructuredClonable };
889
+
890
+ export class Worker {
891
+ /**
892
+ * Constructor to create a new thread (worker) with an API close to the
893
+ * `WebWorkers`. `moduleFilename` is a string specifying the module
894
+ * filename which is executed in the newly created thread. As for
895
+ * dynamically imported module, it is relative to the current script or
896
+ * module path. Threads normally don’t share any data and communicate
897
+ * between each other with messages. Nested workers are not supported.
898
+ */
899
+ constructor(moduleFilename: string);
900
+
901
+ /**
902
+ * In the created worker, Worker.parent represents the parent worker and is
903
+ * used to send or receive messages.
904
+ */
905
+ static parent: Worker;
906
+
907
+ /**
908
+ * Send a message to the corresponding worker. msg is cloned in the
909
+ * destination worker using an algorithm similar to the HTML structured
910
+ * clone algorithm. SharedArrayBuffer are shared between workers.
911
+ *
912
+ * Current limitations: Map and Set are not supported yet.
913
+ */
914
+ postMessage(msg: StructuredClonable): void;
915
+
916
+ /**
917
+ * Set a function which is called each time a message is received. The
918
+ * function is called with a single argument. It is an object with a data
919
+ * property containing the received message. The thread is not terminated
920
+ * if there is at least one non null onmessage handler.
921
+ */
922
+ onmessage: null | ((event: { data: StructuredClonable }) => void);
923
+ }
924
+
925
+ /** constant for {@link access}(); test for read permission. */
926
+ export var R_OK: number;
927
+
928
+ /** constant for {@link access}(); test for write permission. */
929
+ export var W_OK: number;
930
+
931
+ /** constant for {@link access}(); test for execute (search) permission. */
932
+ export var X_OK: number;
933
+
934
+ /** constant for {@link access}(); test for existence of file. */
935
+ export var F_OK: number;
936
+
937
+ /** `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. */
938
+ export function access(path: string, accessMode: number): void;
939
+ }
940
+
package/index.js DELETED
File without changes