yavascript 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/bin/aarch64-apple-darwin/yavascript +0 -0
- package/bin/aarch64-apple-darwin/yavascript-bootstrap +0 -0
- package/bin/aarch64-unknown-linux-gnu/yavascript +0 -0
- package/bin/aarch64-unknown-linux-gnu/yavascript-bootstrap +0 -0
- package/bin/aarch64-unknown-linux-musl/yavascript +0 -0
- package/bin/aarch64-unknown-linux-musl/yavascript-bootstrap +0 -0
- package/bin/aarch64-unknown-linux-static/yavascript +0 -0
- package/bin/aarch64-unknown-linux-static/yavascript-bootstrap +0 -0
- package/bin/x86_64-apple-darwin/yavascript +0 -0
- package/bin/x86_64-apple-darwin/yavascript-bootstrap +0 -0
- package/bin/x86_64-pc-windows-static/yavascript-bootstrap.exe +0 -0
- package/bin/x86_64-pc-windows-static/yavascript.exe +0 -0
- package/bin/x86_64-unknown-linux-gnu/yavascript +0 -0
- package/bin/x86_64-unknown-linux-gnu/yavascript-bootstrap +0 -0
- package/bin/x86_64-unknown-linux-musl/yavascript +0 -0
- package/bin/x86_64-unknown-linux-musl/yavascript-bootstrap +0 -0
- package/bin/x86_64-unknown-linux-static/yavascript +0 -0
- package/bin/x86_64-unknown-linux-static/yavascript-bootstrap +0 -0
- package/dist/index-arm64.js +66737 -0
- package/dist/index-x86_64.js +66737 -0
- package/dist/primordials-arm64.js +65803 -0
- package/dist/primordials-x86_64.js +65803 -0
- package/lib/binary-path.js +5 -5
- package/package.json +1 -1
- package/yavascript.d.ts +1931 -323
- package/bin/darwin-arm64/yavascript +0 -0
- package/bin/darwin-x86_64/yavascript +0 -0
- package/bin/linux-aarch64/yavascript +0 -0
- package/bin/linux-amd64/yavascript +0 -0
- package/bin/windows-x86_64/yavascript.exe +0 -0
package/yavascript.d.ts
CHANGED
|
@@ -3,6 +3,44 @@
|
|
|
3
3
|
// YavaScript APIs
|
|
4
4
|
// ---------------
|
|
5
5
|
// ===============
|
|
6
|
+
/**
|
|
7
|
+
* Prints help and usage text about the provided value, if any is available.
|
|
8
|
+
*/
|
|
9
|
+
declare var help: {
|
|
10
|
+
/**
|
|
11
|
+
* Prints help and usage text about the provided value, if any is available.
|
|
12
|
+
*/
|
|
13
|
+
(value?: any): void;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Set the help text for the provided value to the provided string.
|
|
17
|
+
*
|
|
18
|
+
* If the value is later passed into the `help` function, the provided text
|
|
19
|
+
* will be printed.
|
|
20
|
+
*/
|
|
21
|
+
setHelpText: {
|
|
22
|
+
/**
|
|
23
|
+
* Set the help text for the provided value to the provided string.
|
|
24
|
+
*
|
|
25
|
+
* If the value is later passed into the `help` function, the provided text
|
|
26
|
+
* will be printed.
|
|
27
|
+
*/
|
|
28
|
+
(value: object, text: string): void;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Lazily sets the help text for the provided value using the provided
|
|
32
|
+
* string-returning function.
|
|
33
|
+
*
|
|
34
|
+
* The first time help text is requested for the value, the string-returning
|
|
35
|
+
* function will be called, and its result will be registered as the help
|
|
36
|
+
* text for the value. Afterwards, the function will not be called again;
|
|
37
|
+
* instead, it will re-use the text returned from the first time the
|
|
38
|
+
* function was called.
|
|
39
|
+
*/
|
|
40
|
+
lazy(value: object, getText: () => string): void;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
6
44
|
/** Info about the currently-running yavascript binary */
|
|
7
45
|
declare const yavascript: {
|
|
8
46
|
/**
|
|
@@ -90,72 +128,30 @@ declare const env: { [key: string]: string | undefined };
|
|
|
90
128
|
* Anything that appears after `--` is considered a positional argument instead
|
|
91
129
|
* of a flag. `--` is not present in the returned positional arguments Array.
|
|
92
130
|
*
|
|
93
|
-
*
|
|
94
|
-
* flags must have two leading dashes.
|
|
95
|
-
*
|
|
96
|
-
* Flags with equals signs in them (eg. `--something=42`) are not supported.
|
|
97
|
-
* Write `--something 42` instead.
|
|
98
|
-
*
|
|
99
|
-
* Flags where you specify them multiple times, like `-vvv`, are not supported.
|
|
100
|
-
* Write something like `-v 3` instead.
|
|
101
|
-
*
|
|
102
|
-
* @param hints - An object whose keys are flag names (in camelCase) and whose values indicate what type to treat that flag as. Valid property values are `String`, `Boolean`, `Number`, and `parseScriptArgs.Path`. `parseScriptArgs.Path` will resolve relative paths into absolute paths for you. If no hints object is specified, `parseScriptArgs` will do its best to guess, based on the command-line args.
|
|
131
|
+
* @param hints - An object whose keys are flag names (in camelCase) and whose values indicate what type to treat that flag as. Valid property values are `String`, `Boolean`, `Number`, and `Path`. `Path` will resolve relative paths into absolute paths for you. If no hints object is specified, `parseScriptArgs` will do its best to guess, based on the command-line args.
|
|
103
132
|
* @param argv - An array containing the command line flags you want to parse. If unspecified, `scriptArgs.slice(2)` will be used (we slice 2 in order to skip the yavascript binary and script name). If you pass in an array here, it should only contain command-line flags, not the binary being called.
|
|
104
133
|
*
|
|
105
|
-
* @returns An object with
|
|
134
|
+
* @returns An object with three properties: `flags`, `args`, and `metadata`. `flags` is an object whose keys are camelCase flag names and whose values are strings, booleans, numbers, or `Path`s corresponding to the input command-line args. `args` is an Array of positional arguments, as found on the command-line. `metadata` contains information about what name and type the flags got mapped to.
|
|
106
135
|
*/
|
|
107
|
-
declare
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
* Flags with equals signs in them (eg. `--something=42`) are not supported.
|
|
126
|
-
* Write `--something 42` instead.
|
|
127
|
-
*
|
|
128
|
-
* Flags where you specify them multiple times, like `-vvv`, are not supported.
|
|
129
|
-
* Write something like `-v 3` instead.
|
|
130
|
-
*
|
|
131
|
-
* @param hints - An object whose keys are flag names (in camelCase) and whose values indicate what type to treat that flag as. Valid property values are `String`, `Boolean`, `Number`, and `parseScriptArgs.Path`. `parseScriptArgs.Path` will resolve relative paths into absolute paths for you. If no hints object is specified, `parseScriptArgs` will do its best to guess, based on the command-line args.
|
|
132
|
-
* @param args - An array containing the command line flags you want to parse. If unspecified, `scriptArgs.slice(2)` will be used (we slice 2 in order to skip the yavascript binary and script name). If you pass in an array here, it should only contain command-line flags, not the binary being called.
|
|
133
|
-
*
|
|
134
|
-
* @returns An object with two properties: `flags` and `args`. `flags` is an object whose keys are camelCase flag names and whose values are strings, booleans, or numbers corresponding to the input command-line args. `args` is an Array of positional arguments, as found on the command-line.
|
|
135
|
-
*/
|
|
136
|
-
(
|
|
137
|
-
hints?: {
|
|
138
|
-
[key: string]:
|
|
139
|
-
| typeof String
|
|
140
|
-
| typeof Boolean
|
|
141
|
-
| typeof Number
|
|
142
|
-
| typeof parseScriptArgs["Path"];
|
|
143
|
-
},
|
|
144
|
-
args?: Array<string>
|
|
145
|
-
): {
|
|
146
|
-
flags: { [key: string]: any };
|
|
147
|
-
args: Array<string>;
|
|
136
|
+
declare function parseScriptArgs(
|
|
137
|
+
hints?: {
|
|
138
|
+
[key: string]: typeof String | typeof Boolean | typeof Number | typeof Path;
|
|
139
|
+
},
|
|
140
|
+
args?: Array<string>
|
|
141
|
+
): {
|
|
142
|
+
flags: { [key: string]: any };
|
|
143
|
+
args: Array<string>;
|
|
144
|
+
metadata: {
|
|
145
|
+
keys: {
|
|
146
|
+
[key: string]: string | undefined;
|
|
147
|
+
};
|
|
148
|
+
hints: {
|
|
149
|
+
[key: string]: string | undefined;
|
|
150
|
+
};
|
|
151
|
+
guesses: {
|
|
152
|
+
[key: string]: string | undefined;
|
|
153
|
+
};
|
|
148
154
|
};
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* A hint value for {@link parseScriptArgs}. Behaves similar to the hint value
|
|
152
|
-
* `String`, except that it also resolves relative paths into absolute paths,
|
|
153
|
-
* using the following rules:
|
|
154
|
-
*
|
|
155
|
-
* - paths `./like/this` or `../like/this` get resolved relative to `pwd()`.
|
|
156
|
-
* - paths `like/this` or `this` get resolved relative to `pwd()` as if they had a leading `./`.
|
|
157
|
-
*/
|
|
158
|
-
readonly Path: unique symbol;
|
|
159
155
|
};
|
|
160
156
|
|
|
161
157
|
/**
|
|
@@ -165,22 +161,22 @@ declare const readFile: {
|
|
|
165
161
|
/**
|
|
166
162
|
* Read the contents of a file from disk, as a UTF-8 string.
|
|
167
163
|
*/
|
|
168
|
-
(path: string): string;
|
|
164
|
+
(path: string | Path): string;
|
|
169
165
|
|
|
170
166
|
/**
|
|
171
167
|
* Read the contents of a file from disk, as a UTF-8 string.
|
|
172
168
|
*/
|
|
173
|
-
(path: string, options: {}): string;
|
|
169
|
+
(path: string | Path, options: {}): string;
|
|
174
170
|
|
|
175
171
|
/**
|
|
176
172
|
* Read the contents of a file from disk, as a UTF-8 string.
|
|
177
173
|
*/
|
|
178
|
-
(path: string, options: { binary: false }): string;
|
|
174
|
+
(path: string | Path, options: { binary: false }): string;
|
|
179
175
|
|
|
180
176
|
/**
|
|
181
177
|
* Read the contents of a file from disk, as an ArrayBuffer.
|
|
182
178
|
*/
|
|
183
|
-
(path: string, options: { binary: true }): ArrayBuffer;
|
|
179
|
+
(path: string | Path, options: { binary: true }): ArrayBuffer;
|
|
184
180
|
};
|
|
185
181
|
|
|
186
182
|
/**
|
|
@@ -188,37 +184,49 @@ declare const readFile: {
|
|
|
188
184
|
*
|
|
189
185
|
* Strings are written using the UTF-8 encoding.
|
|
190
186
|
*/
|
|
191
|
-
declare function writeFile(
|
|
187
|
+
declare function writeFile(
|
|
188
|
+
path: string | Path,
|
|
189
|
+
data: string | ArrayBuffer
|
|
190
|
+
): void;
|
|
192
191
|
|
|
193
192
|
/**
|
|
194
|
-
* Function which returns true if the path points to a
|
|
195
|
-
* path points to a symlink which points to a directory. Otherwise, it returns
|
|
196
|
-
* false.
|
|
193
|
+
* Function which returns true if the path points to a regular file.
|
|
197
194
|
*/
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Returns true if the path points to a directory, or if the path points to
|
|
201
|
-
* a symlink which points to a directory. Otherwise, returns false.
|
|
202
|
-
*/
|
|
203
|
-
(path: string): boolean;
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Maximum number of symlinks to follow before erroring. Defaults to 100.
|
|
207
|
-
*/
|
|
208
|
-
symlinkLimit: number;
|
|
209
|
-
}
|
|
195
|
+
declare function isFile(path: string | Path): boolean;
|
|
210
196
|
|
|
211
197
|
/**
|
|
212
198
|
* Function which returns true if the path points to a directory, or if the
|
|
213
199
|
* path points to a symlink which points to a directory. Otherwise, it returns
|
|
214
200
|
* false.
|
|
215
201
|
*/
|
|
216
|
-
declare
|
|
202
|
+
declare function isDir(path: string | Path): boolean;
|
|
217
203
|
|
|
218
204
|
/**
|
|
219
205
|
* Returns true if the path points to a symlink.
|
|
220
206
|
*/
|
|
221
|
-
declare function isLink(path: string): boolean;
|
|
207
|
+
declare function isLink(path: string | Path): boolean;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Returns true if the resource at the provided path can be executed by the
|
|
211
|
+
* current user.
|
|
212
|
+
*
|
|
213
|
+
* If nothing exists at that path, an error will be thrown.
|
|
214
|
+
*/
|
|
215
|
+
declare function isExecutable(path: string | Path): boolean;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Returns true if the resource at the provided path can be read by the current
|
|
219
|
+
* user.
|
|
220
|
+
*
|
|
221
|
+
* If nothing exists at that path, an error will be thrown.
|
|
222
|
+
*/
|
|
223
|
+
declare function isReadable(path: string | Path): boolean;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Returns true if a resource at the provided path could be written to by the
|
|
227
|
+
* current user.
|
|
228
|
+
*/
|
|
229
|
+
declare function isWritable(path: string | Path): boolean;
|
|
222
230
|
|
|
223
231
|
/**
|
|
224
232
|
* Delete the file or directory at the specified path.
|
|
@@ -227,22 +235,22 @@ declare function isLink(path: string): boolean;
|
|
|
227
235
|
*
|
|
228
236
|
* Provides the same functionality as the command `rm -rf`.
|
|
229
237
|
*/
|
|
230
|
-
declare function remove(path: string): void;
|
|
238
|
+
declare function remove(path: string | Path): void;
|
|
231
239
|
|
|
232
240
|
/**
|
|
233
241
|
* Returns true if a file or directory exists at the specified path.
|
|
234
242
|
*
|
|
235
243
|
* Provides the same functionality as the command `test -e`.
|
|
236
244
|
*/
|
|
237
|
-
declare function exists(path: string): boolean;
|
|
245
|
+
declare function exists(path: string | Path): boolean;
|
|
238
246
|
|
|
239
247
|
/**
|
|
240
|
-
*
|
|
248
|
+
* Creates directories for each of the provided path components,
|
|
241
249
|
* if they don't already exist.
|
|
242
250
|
*
|
|
243
251
|
* Provides the same functionality as the command `mkdir -p`.
|
|
244
252
|
*/
|
|
245
|
-
declare function ensureDir(path: string): string;
|
|
253
|
+
declare function ensureDir(path: string | Path): string;
|
|
246
254
|
|
|
247
255
|
/**
|
|
248
256
|
* Options for {@link copy}.
|
|
@@ -270,12 +278,23 @@ declare type CopyOptions = {
|
|
|
270
278
|
};
|
|
271
279
|
|
|
272
280
|
/**
|
|
273
|
-
*
|
|
281
|
+
* Copies a file or folder from one location to another.
|
|
274
282
|
* Folders are copied recursively.
|
|
275
283
|
*
|
|
276
284
|
* Provides the same functionality as the command `cp -R`.
|
|
277
285
|
*/
|
|
278
|
-
declare function copy(
|
|
286
|
+
declare function copy(
|
|
287
|
+
from: string | Path,
|
|
288
|
+
to: string | Path,
|
|
289
|
+
options?: CopyOptions
|
|
290
|
+
): void;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Rename the file or directory at the specified path.
|
|
294
|
+
*
|
|
295
|
+
* Provides the same functionality as the command `mv`.
|
|
296
|
+
*/
|
|
297
|
+
declare function rename(from: string | Path, to: string | Path): void;
|
|
279
298
|
|
|
280
299
|
/** An object that represents a filesystem path. */
|
|
281
300
|
declare class Path {
|
|
@@ -323,10 +342,10 @@ declare class Path {
|
|
|
323
342
|
): string;
|
|
324
343
|
|
|
325
344
|
/**
|
|
326
|
-
* Return whether the provided path
|
|
345
|
+
* Return whether the provided path is absolute; that is, whether it
|
|
327
346
|
* starts with either `/` or a drive letter (ie `C:`).
|
|
328
347
|
*/
|
|
329
|
-
static isAbsolute(path: string): boolean;
|
|
348
|
+
static isAbsolute(path: string | Path): boolean;
|
|
330
349
|
|
|
331
350
|
/** A tagged template literal function that creates a `Path` object. */
|
|
332
351
|
static tag(
|
|
@@ -390,25 +409,52 @@ declare class Path {
|
|
|
390
409
|
*/
|
|
391
410
|
isAbsolute(): boolean;
|
|
392
411
|
|
|
412
|
+
/**
|
|
413
|
+
* Make a second Path object containing the same information as this one.
|
|
414
|
+
*/
|
|
415
|
+
clone(): this;
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Express this path relative to `dir`.
|
|
419
|
+
*
|
|
420
|
+
* @param dir - The directory to create a new path relative to.
|
|
421
|
+
* @param options - Options that affect the resulting path.
|
|
422
|
+
*/
|
|
423
|
+
relativeTo(
|
|
424
|
+
dir: Path | string,
|
|
425
|
+
options?: {
|
|
426
|
+
/**
|
|
427
|
+
* Defaults to false. When true, a leading `./` will be omitted from the
|
|
428
|
+
* path, if present. Note that a leading `../` will never be omitted.
|
|
429
|
+
*/
|
|
430
|
+
noLeadingDot?: boolean;
|
|
431
|
+
}
|
|
432
|
+
): Path;
|
|
433
|
+
|
|
393
434
|
/**
|
|
394
435
|
* Turn this path into a string by joining its segments using its separator.
|
|
395
436
|
*/
|
|
396
437
|
toString(): string;
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Alias for `toString`; causes Path objects to be serialized as strings.
|
|
441
|
+
*/
|
|
442
|
+
toJSON(): string;
|
|
397
443
|
}
|
|
398
444
|
|
|
399
445
|
/**
|
|
400
446
|
* The absolute path to the current file (whether script or module).
|
|
401
447
|
*
|
|
402
|
-
* Behaves the same as in Node.js, except that it's present within ES modules.
|
|
448
|
+
* Behaves the same as in Node.js, except that it's also present within ES modules.
|
|
403
449
|
*/
|
|
404
|
-
declare
|
|
450
|
+
declare var __filename: string;
|
|
405
451
|
|
|
406
452
|
/**
|
|
407
453
|
* The absolute path to the directory the current file is inside of.
|
|
408
454
|
*
|
|
409
|
-
* Behaves the same as in Node.js, except that it's present within ES modules.
|
|
455
|
+
* Behaves the same as in Node.js, except that it's also present within ES modules.
|
|
410
456
|
*/
|
|
411
|
-
declare
|
|
457
|
+
declare var __dirname: string;
|
|
412
458
|
|
|
413
459
|
/**
|
|
414
460
|
* Return the last component of a path string.
|
|
@@ -500,7 +546,7 @@ declare function extname(
|
|
|
500
546
|
): string;
|
|
501
547
|
|
|
502
548
|
/**
|
|
503
|
-
*
|
|
549
|
+
* Returns the contents of a directory, as absolute paths. `.` and `..` are
|
|
504
550
|
* omitted.
|
|
505
551
|
*
|
|
506
552
|
* Use the `relativePaths` option to get relative paths instead (relative to
|
|
@@ -513,18 +559,22 @@ declare function ls(
|
|
|
513
559
|
|
|
514
560
|
/**
|
|
515
561
|
* Print data to stdout using C-style format specifiers.
|
|
562
|
+
*
|
|
563
|
+
* The same formats as the standard C library printf are supported. Integer
|
|
564
|
+
* format types (e.g. `%d`) truncate the Numbers or BigInts to 32 bits. Use the l
|
|
565
|
+
* modifier (e.g. `%ld`) to truncate to 64 bits.
|
|
516
566
|
*/
|
|
517
567
|
declare function printf(format: string, ...args: Array<any>): void;
|
|
518
568
|
|
|
519
569
|
/**
|
|
520
|
-
*
|
|
570
|
+
* Returns the process's current working directory.
|
|
521
571
|
*
|
|
522
572
|
* Provides the same functionality as the shell builtin of the same name.
|
|
523
573
|
*/
|
|
524
574
|
declare function pwd(): string;
|
|
525
575
|
|
|
526
576
|
/**
|
|
527
|
-
*
|
|
577
|
+
* Reads a symlink.
|
|
528
578
|
*
|
|
529
579
|
* Returns the target of the symlink, which may be absolute or relative.
|
|
530
580
|
*
|
|
@@ -541,6 +591,40 @@ declare function readlink(path: string | Path): string;
|
|
|
541
591
|
*/
|
|
542
592
|
declare function realpath(path: string | Path): string;
|
|
543
593
|
|
|
594
|
+
/**
|
|
595
|
+
* Blocks the current thread for at least the specified number of milliseconds,
|
|
596
|
+
* or maybe a tiny bit longer.
|
|
597
|
+
*
|
|
598
|
+
* alias for `sleep.sync`.
|
|
599
|
+
*/
|
|
600
|
+
declare var sleep: {
|
|
601
|
+
/**
|
|
602
|
+
* Blocks the current thread for at least the specified number of milliseconds,
|
|
603
|
+
* or maybe a tiny bit longer.
|
|
604
|
+
*
|
|
605
|
+
* alias for `sleep.sync`.
|
|
606
|
+
*
|
|
607
|
+
* @param milliseconds - The number of milliseconds to block for.
|
|
608
|
+
*/
|
|
609
|
+
(milliseconds: number): void;
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Blocks the current thread for at least the specified number of milliseconds,
|
|
613
|
+
* or maybe a tiny bit longer.
|
|
614
|
+
*
|
|
615
|
+
* @param milliseconds - The number of milliseconds to block for.
|
|
616
|
+
*/
|
|
617
|
+
sync(milliseconds: number): void;
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Returns a Promise which resolves in at least the specified number of
|
|
621
|
+
* milliseconds, maybe a little longer.
|
|
622
|
+
*
|
|
623
|
+
* @param milliseconds - The number of milliseconds to wait before the returned Promise should be resolved.
|
|
624
|
+
*/
|
|
625
|
+
async(milliseconds: number): Promise<void>;
|
|
626
|
+
};
|
|
627
|
+
|
|
544
628
|
/**
|
|
545
629
|
* If the file at `path` exists, update its creation/modification timestamps.
|
|
546
630
|
*
|
|
@@ -552,7 +636,7 @@ declare function touch(path: string | Path): void;
|
|
|
552
636
|
|
|
553
637
|
declare type BaseExecOptions = {
|
|
554
638
|
/** Sets the current working directory for the child process. */
|
|
555
|
-
cwd?: string;
|
|
639
|
+
cwd?: string | Path;
|
|
556
640
|
|
|
557
641
|
/** Sets environment variables within the process. */
|
|
558
642
|
env?: { [key: string | number]: string | number | boolean };
|
|
@@ -567,29 +651,29 @@ declare type BaseExecOptions = {
|
|
|
567
651
|
* ```
|
|
568
652
|
*/
|
|
569
653
|
trace?: (...args: Array<any>) => void;
|
|
570
|
-
};
|
|
571
654
|
|
|
572
|
-
|
|
573
|
-
|
|
655
|
+
/**
|
|
656
|
+
* Whether an Error should be thrown when the process exits with a nonzero
|
|
657
|
+
* status code.
|
|
658
|
+
*
|
|
659
|
+
* Defaults to true.
|
|
660
|
+
*/
|
|
661
|
+
failOnNonZeroStatus?: boolean;
|
|
574
662
|
|
|
575
|
-
|
|
663
|
+
/**
|
|
664
|
+
* If true, stdout and stderr will be collected into strings or array buffers
|
|
665
|
+
* and returned instead of being printed to the screen.
|
|
666
|
+
*
|
|
667
|
+
* Defaults to false. true is an alias for "utf8".
|
|
668
|
+
*/
|
|
669
|
+
captureOutput?: boolean | "utf8" | "arraybuffer";
|
|
670
|
+
};
|
|
576
671
|
|
|
672
|
+
declare interface Exec {
|
|
577
673
|
(
|
|
578
674
|
args: Array<string> | string,
|
|
579
675
|
options: BaseExecOptions & {
|
|
580
|
-
/**
|
|
581
|
-
* Whether an Error should be thrown when the process exits with a nonzero
|
|
582
|
-
* status code.
|
|
583
|
-
*
|
|
584
|
-
* Defaults to true.
|
|
585
|
-
*/
|
|
586
676
|
failOnNonZeroStatus: true;
|
|
587
|
-
/**
|
|
588
|
-
* If true, stdout and stderr will be collected into strings and returned
|
|
589
|
-
* instead of being printed to the screen.
|
|
590
|
-
*
|
|
591
|
-
* Defaults to false.
|
|
592
|
-
*/
|
|
593
677
|
captureOutput: false;
|
|
594
678
|
}
|
|
595
679
|
): void;
|
|
@@ -597,19 +681,7 @@ declare interface Exec {
|
|
|
597
681
|
(
|
|
598
682
|
args: Array<string> | string,
|
|
599
683
|
options: BaseExecOptions & {
|
|
600
|
-
/**
|
|
601
|
-
* Whether an Error should be thrown when the process exits with a nonzero
|
|
602
|
-
* status code.
|
|
603
|
-
*
|
|
604
|
-
* Defaults to true.
|
|
605
|
-
*/
|
|
606
684
|
failOnNonZeroStatus: false;
|
|
607
|
-
/**
|
|
608
|
-
* If true, stdout and stderr will be collected into strings and returned
|
|
609
|
-
* instead of being printed to the screen.
|
|
610
|
-
*
|
|
611
|
-
* Defaults to false.
|
|
612
|
-
*/
|
|
613
685
|
captureOutput: false;
|
|
614
686
|
}
|
|
615
687
|
):
|
|
@@ -619,69 +691,115 @@ declare interface Exec {
|
|
|
619
691
|
(
|
|
620
692
|
args: Array<string> | string,
|
|
621
693
|
options: BaseExecOptions & {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
* status code.
|
|
625
|
-
*
|
|
626
|
-
* Defaults to true.
|
|
627
|
-
*/
|
|
628
|
-
failOnNonZeroStatus: false;
|
|
694
|
+
failOnNonZeroStatus: true;
|
|
695
|
+
captureOutput: true;
|
|
629
696
|
}
|
|
630
|
-
):
|
|
631
|
-
| { status: number; signal: undefined }
|
|
632
|
-
| { status: undefined; signal: number };
|
|
697
|
+
): { stdout: string; stderr: string };
|
|
633
698
|
|
|
634
699
|
(
|
|
635
700
|
args: Array<string> | string,
|
|
636
701
|
options: BaseExecOptions & {
|
|
637
|
-
/**
|
|
638
|
-
* Whether an Error should be thrown when the process exits with a nonzero
|
|
639
|
-
* status code.
|
|
640
|
-
*
|
|
641
|
-
* Defaults to true.
|
|
642
|
-
*/
|
|
643
702
|
failOnNonZeroStatus: true;
|
|
644
|
-
|
|
645
|
-
* If true, stdout and stderr will be collected into strings and returned
|
|
646
|
-
* instead of being printed to the screen.
|
|
647
|
-
*
|
|
648
|
-
* Defaults to false.
|
|
649
|
-
*/
|
|
650
|
-
captureOutput: true;
|
|
703
|
+
captureOutput: "utf8";
|
|
651
704
|
}
|
|
652
705
|
): { stdout: string; stderr: string };
|
|
653
706
|
|
|
654
707
|
(
|
|
655
708
|
args: Array<string> | string,
|
|
656
709
|
options: BaseExecOptions & {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
* instead of being printed to the screen.
|
|
660
|
-
*
|
|
661
|
-
* Defaults to false.
|
|
662
|
-
*/
|
|
663
|
-
captureOutput: true;
|
|
710
|
+
failOnNonZeroStatus: true;
|
|
711
|
+
captureOutput: "arraybuffer";
|
|
664
712
|
}
|
|
665
|
-
): { stdout:
|
|
713
|
+
): { stdout: ArrayBuffer; stderr: ArrayBuffer };
|
|
666
714
|
|
|
667
715
|
(
|
|
668
716
|
args: Array<string> | string,
|
|
669
717
|
options: BaseExecOptions & {
|
|
670
|
-
/**
|
|
671
|
-
* Whether an Error should be thrown when the process exits with a nonzero
|
|
672
|
-
* status code.
|
|
673
|
-
*
|
|
674
|
-
* Defaults to true.
|
|
675
|
-
*/
|
|
676
718
|
failOnNonZeroStatus: false;
|
|
677
719
|
captureOutput: true;
|
|
678
720
|
}
|
|
679
721
|
):
|
|
680
722
|
| { stdout: string; stderr: string; status: number; signal: undefined }
|
|
681
723
|
| { stdout: string; stderr: string; status: undefined; signal: number };
|
|
724
|
+
|
|
725
|
+
(
|
|
726
|
+
args: Array<string> | string,
|
|
727
|
+
options: BaseExecOptions & {
|
|
728
|
+
failOnNonZeroStatus: false;
|
|
729
|
+
captureOutput: "utf-8";
|
|
730
|
+
}
|
|
731
|
+
):
|
|
732
|
+
| { stdout: string; stderr: string; status: number; signal: undefined }
|
|
733
|
+
| { stdout: string; stderr: string; status: undefined; signal: number };
|
|
734
|
+
|
|
735
|
+
(
|
|
736
|
+
args: Array<string> | string,
|
|
737
|
+
options: BaseExecOptions & {
|
|
738
|
+
failOnNonZeroStatus: false;
|
|
739
|
+
captureOutput: "arraybuffer";
|
|
740
|
+
}
|
|
741
|
+
):
|
|
742
|
+
| {
|
|
743
|
+
stdout: ArrayBuffer;
|
|
744
|
+
stderr: ArrayBuffer;
|
|
745
|
+
status: number;
|
|
746
|
+
signal: undefined;
|
|
747
|
+
}
|
|
748
|
+
| {
|
|
749
|
+
stdout: ArrayBuffer;
|
|
750
|
+
stderr: ArrayBuffer;
|
|
751
|
+
status: undefined;
|
|
752
|
+
signal: number;
|
|
753
|
+
};
|
|
754
|
+
|
|
755
|
+
(
|
|
756
|
+
args: Array<string> | string,
|
|
757
|
+
options: BaseExecOptions & {
|
|
758
|
+
failOnNonZeroStatus: true;
|
|
759
|
+
}
|
|
760
|
+
): void;
|
|
761
|
+
|
|
762
|
+
(
|
|
763
|
+
args: Array<string> | string,
|
|
764
|
+
options: BaseExecOptions & {
|
|
765
|
+
failOnNonZeroStatus: false;
|
|
766
|
+
}
|
|
767
|
+
):
|
|
768
|
+
| { status: number; signal: undefined }
|
|
769
|
+
| { status: undefined; signal: number };
|
|
770
|
+
|
|
771
|
+
(
|
|
772
|
+
args: Array<string> | string,
|
|
773
|
+
options: BaseExecOptions & {
|
|
774
|
+
captureOutput: true;
|
|
775
|
+
}
|
|
776
|
+
): { stdout: string; stderr: string };
|
|
777
|
+
|
|
778
|
+
(
|
|
779
|
+
args: Array<string> | string,
|
|
780
|
+
options: BaseExecOptions & {
|
|
781
|
+
captureOutput: "utf8";
|
|
782
|
+
}
|
|
783
|
+
): { stdout: string; stderr: string };
|
|
784
|
+
|
|
785
|
+
(
|
|
786
|
+
args: Array<string> | string,
|
|
787
|
+
options: BaseExecOptions & {
|
|
788
|
+
captureOutput: "arraybuffer";
|
|
789
|
+
}
|
|
790
|
+
): { stdout: ArrayBuffer; stderr: ArrayBuffer };
|
|
791
|
+
|
|
792
|
+
(
|
|
793
|
+
args: Array<string> | string,
|
|
794
|
+
options: BaseExecOptions & {
|
|
795
|
+
captureOutput: false;
|
|
796
|
+
}
|
|
797
|
+
): void;
|
|
798
|
+
|
|
799
|
+
(args: Array<string> | string, options?: BaseExecOptions): void;
|
|
682
800
|
}
|
|
683
801
|
|
|
684
|
-
/**
|
|
802
|
+
/** Runs a child process using the provided arguments. The first value in the arguments array is the program to run. */
|
|
685
803
|
declare const exec: Exec;
|
|
686
804
|
|
|
687
805
|
/** Alias for `exec(args, { captureOutput: true })` */
|
|
@@ -690,6 +808,100 @@ declare function $(args: Array<string> | string): {
|
|
|
690
808
|
stderr: string;
|
|
691
809
|
};
|
|
692
810
|
|
|
811
|
+
/** A class which represents a child process. The process may or may not be running. */
|
|
812
|
+
declare interface ChildProcess {
|
|
813
|
+
/**
|
|
814
|
+
* The argv for the process. The first entry in this array is the program to
|
|
815
|
+
* run.
|
|
816
|
+
*/
|
|
817
|
+
args: Array<string>;
|
|
818
|
+
|
|
819
|
+
/** The current working directory for the process. */
|
|
820
|
+
cwd: string;
|
|
821
|
+
|
|
822
|
+
/** The environment variables for the process. */
|
|
823
|
+
env: { [key: string]: string };
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* The standard I/O streams for the process. Generally these are the same as
|
|
827
|
+
* `std.in`, `std.out`, and `std.err`, but they can be customized to write
|
|
828
|
+
* output elsewhere.
|
|
829
|
+
*/
|
|
830
|
+
stdio: {
|
|
831
|
+
/** Where the process reads stdin from */
|
|
832
|
+
in: FILE;
|
|
833
|
+
/** Where the process writes stdout to */
|
|
834
|
+
out: FILE;
|
|
835
|
+
/** Where the process writes stderr to */
|
|
836
|
+
err: FILE;
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Optional trace function which, if present, will be called at various times
|
|
841
|
+
* to provide information about the lifecycle of the process.
|
|
842
|
+
*/
|
|
843
|
+
trace?: (...args: Array<any>) => void;
|
|
844
|
+
|
|
845
|
+
pid: number | null;
|
|
846
|
+
|
|
847
|
+
/** Spawns the process and returns its pid (process id). */
|
|
848
|
+
start(): number;
|
|
849
|
+
|
|
850
|
+
/** Blocks the calling thread until the process exits or is killed. */
|
|
851
|
+
waitUntilComplete():
|
|
852
|
+
| { status: number; signal: undefined }
|
|
853
|
+
| { status: undefined; signal: number };
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* Options to be passed to the ChildProcess constructor. Their purposes and
|
|
858
|
+
* types match the same-named properties found on the resulting ChildProcess.
|
|
859
|
+
*/
|
|
860
|
+
declare type ChildProcessOptions = {
|
|
861
|
+
/** The current working directory for the process. */
|
|
862
|
+
cwd?: string;
|
|
863
|
+
|
|
864
|
+
/** The environment variables for the process. */
|
|
865
|
+
env?: { [key: string]: string };
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* The standard I/O streams for the process. Generally these are the same as
|
|
869
|
+
* `std.in`, `std.out`, and `std.err`, but they can be customized to write
|
|
870
|
+
* output elsewhere.
|
|
871
|
+
*/
|
|
872
|
+
stdio?: {
|
|
873
|
+
/** Where the process reads stdin from */
|
|
874
|
+
in?: FILE;
|
|
875
|
+
/** Where the process writes stdout to */
|
|
876
|
+
out?: FILE;
|
|
877
|
+
/** Where the process writes stderr to */
|
|
878
|
+
err?: FILE;
|
|
879
|
+
};
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* Optional trace function which, if present, will be called at various times
|
|
883
|
+
* to provide information about the lifecycle of the process.
|
|
884
|
+
*/
|
|
885
|
+
trace?: (...args: Array<any>) => void;
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
declare interface ChildProcessConstructor {
|
|
889
|
+
/**
|
|
890
|
+
* Construct a new ChildProcess.
|
|
891
|
+
*
|
|
892
|
+
* @param args - The argv for the process. The first entry in this array is the program to run.
|
|
893
|
+
* @param options - Options for the process (cwd, env, stdio, etc)
|
|
894
|
+
*/
|
|
895
|
+
new (
|
|
896
|
+
args: string | Array<string>,
|
|
897
|
+
options?: ChildProcessOptions
|
|
898
|
+
): ChildProcess;
|
|
899
|
+
|
|
900
|
+
readonly prototype: ChildProcess;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
declare var ChildProcess: ChildProcessConstructor;
|
|
904
|
+
|
|
693
905
|
/**
|
|
694
906
|
* Options for {@link glob}.
|
|
695
907
|
*/
|
|
@@ -717,7 +929,7 @@ declare type GlobOptions = {
|
|
|
717
929
|
/**
|
|
718
930
|
* Directory to interpret glob patterns relative to. Defaults to `pwd()`.
|
|
719
931
|
*/
|
|
720
|
-
dir?: string;
|
|
932
|
+
dir?: string | Path;
|
|
721
933
|
};
|
|
722
934
|
|
|
723
935
|
/**
|
|
@@ -729,7 +941,17 @@ declare type GlobOptions = {
|
|
|
729
941
|
declare function glob(
|
|
730
942
|
patterns: string | Array<string>,
|
|
731
943
|
options?: GlobOptions
|
|
732
|
-
): Array<
|
|
944
|
+
): Array<Path>;
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* Clear the contents and scrollback buffer of the tty by printing special characters into stdout.
|
|
948
|
+
*/
|
|
949
|
+
declare function clear(): void;
|
|
950
|
+
|
|
951
|
+
interface Console {
|
|
952
|
+
/** Same as {@link clear}(). */
|
|
953
|
+
clear: typeof clear;
|
|
954
|
+
}
|
|
733
955
|
|
|
734
956
|
/**
|
|
735
957
|
* Remove ANSI control characters from a string.
|
|
@@ -741,11 +963,6 @@ declare function stripAnsi(input: string): string;
|
|
|
741
963
|
*/
|
|
742
964
|
declare function quote(input: string): string;
|
|
743
965
|
|
|
744
|
-
/**
|
|
745
|
-
* Clear the contents and scrollback buffer of the tty by printing special characters into stdout.
|
|
746
|
-
*/
|
|
747
|
-
declare function clear(): void;
|
|
748
|
-
|
|
749
966
|
// Colors
|
|
750
967
|
|
|
751
968
|
/** Wrap a string with the ANSI control characters that will make it print as black text. */
|
|
@@ -866,51 +1083,59 @@ declare const grepString: {
|
|
|
866
1083
|
str: string,
|
|
867
1084
|
pattern: string | RegExp,
|
|
868
1085
|
options: { inverse: true; details: true }
|
|
869
|
-
): Array<
|
|
1086
|
+
): Array<{
|
|
1087
|
+
lineNumber: number;
|
|
1088
|
+
lineContent: string;
|
|
1089
|
+
matches: RegExpMatchArray;
|
|
1090
|
+
}>;
|
|
870
1091
|
};
|
|
871
1092
|
|
|
872
1093
|
/** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
|
|
873
1094
|
declare const grepFile: {
|
|
874
1095
|
/** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
|
|
875
|
-
(path: string, pattern: string | RegExp): Array<string>;
|
|
1096
|
+
(path: string | Path, pattern: string | RegExp): Array<string>;
|
|
876
1097
|
|
|
877
1098
|
/** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
|
|
878
1099
|
(
|
|
879
|
-
path: string,
|
|
1100
|
+
path: string | Path,
|
|
880
1101
|
pattern: string | RegExp,
|
|
881
1102
|
options: { inverse: false }
|
|
882
1103
|
): Array<string>;
|
|
883
1104
|
|
|
884
1105
|
/** Read the content at `path`, split it on newline, and then return lines NOT matching `pattern`. */
|
|
885
1106
|
(
|
|
886
|
-
path: string,
|
|
1107
|
+
path: string | Path,
|
|
887
1108
|
pattern: string | RegExp,
|
|
888
1109
|
options: { inverse: true }
|
|
889
1110
|
): Array<string>;
|
|
890
1111
|
|
|
891
1112
|
/** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
|
|
892
1113
|
(
|
|
893
|
-
path: string,
|
|
1114
|
+
path: string | Path,
|
|
894
1115
|
pattern: string | RegExp,
|
|
895
1116
|
options: { details: false }
|
|
896
1117
|
): Array<string>;
|
|
897
1118
|
|
|
898
1119
|
/** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
|
|
899
1120
|
(
|
|
900
|
-
path: string,
|
|
1121
|
+
path: string | Path,
|
|
901
1122
|
pattern: string | RegExp,
|
|
902
1123
|
options: { inverse: false; details: false }
|
|
903
1124
|
): Array<string>;
|
|
904
1125
|
|
|
905
1126
|
/** Read the content at `path`, split it on newline, and then return lines NOT matching `pattern`. */
|
|
906
1127
|
(
|
|
907
|
-
path: string,
|
|
1128
|
+
path: string | Path,
|
|
908
1129
|
pattern: string | RegExp,
|
|
909
1130
|
options: { inverse: true; details: false }
|
|
910
1131
|
): Array<string>;
|
|
911
1132
|
|
|
912
1133
|
/** Read the content at `path`, split it on newline, and then return info about lines matching `pattern`. */
|
|
913
|
-
(
|
|
1134
|
+
(
|
|
1135
|
+
path: string | Path,
|
|
1136
|
+
pattern: string | RegExp,
|
|
1137
|
+
options: { details: true }
|
|
1138
|
+
): Array<{
|
|
914
1139
|
lineNumber: number;
|
|
915
1140
|
lineContent: string;
|
|
916
1141
|
matches: RegExpMatchArray;
|
|
@@ -918,17 +1143,21 @@ declare const grepFile: {
|
|
|
918
1143
|
|
|
919
1144
|
/** Read the content at `path`, split it on newline, and then return info about lines matching `pattern`. */
|
|
920
1145
|
(
|
|
921
|
-
path: string,
|
|
1146
|
+
path: string | Path,
|
|
922
1147
|
pattern: string | RegExp,
|
|
923
1148
|
options: { inverse: false; details: true }
|
|
924
1149
|
): Array<string>;
|
|
925
1150
|
|
|
926
1151
|
/** Read the content at `path`, split it on newline, and then return info about lines NOT matching `pattern`. */
|
|
927
1152
|
(
|
|
928
|
-
path: string,
|
|
1153
|
+
path: string | Path,
|
|
929
1154
|
pattern: string | RegExp,
|
|
930
1155
|
options: { inverse: true; details: true }
|
|
931
|
-
): Array<
|
|
1156
|
+
): Array<{
|
|
1157
|
+
lineNumber: number;
|
|
1158
|
+
lineContent: string;
|
|
1159
|
+
matches: RegExpMatchArray;
|
|
1160
|
+
}>;
|
|
932
1161
|
};
|
|
933
1162
|
|
|
934
1163
|
interface String {
|
|
@@ -975,7 +1204,11 @@ interface String {
|
|
|
975
1204
|
(
|
|
976
1205
|
pattern: string | RegExp,
|
|
977
1206
|
options: { inverse: true; details: true }
|
|
978
|
-
): Array<
|
|
1207
|
+
): Array<{
|
|
1208
|
+
lineNumber: number;
|
|
1209
|
+
lineContent: string;
|
|
1210
|
+
matches: RegExpMatchArray;
|
|
1211
|
+
}>;
|
|
979
1212
|
};
|
|
980
1213
|
}
|
|
981
1214
|
|
|
@@ -2365,7 +2598,7 @@ declare const assert: {
|
|
|
2365
2598
|
* - Use `maxLength` to limit how much data to read.
|
|
2366
2599
|
* - Use `until` to stop reading once a certain byte or character has been
|
|
2367
2600
|
* read.
|
|
2368
|
-
* - Use `path` or `fd` to open a file.
|
|
2601
|
+
* - Use `path` or `fd` to open a file (or pass a FILE or Path object).
|
|
2369
2602
|
*/
|
|
2370
2603
|
declare type PipeSource =
|
|
2371
2604
|
| { data: string; maxLength?: number; until?: string | byte }
|
|
@@ -2378,12 +2611,9 @@ declare type PipeSource =
|
|
|
2378
2611
|
| DataView
|
|
2379
2612
|
| { data: DataView; maxLength?: number; until?: string | byte }
|
|
2380
2613
|
| FILE
|
|
2381
|
-
| {
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
until?: string | byte;
|
|
2385
|
-
}
|
|
2386
|
-
| { path: string; maxLength?: number; until?: string | byte }
|
|
2614
|
+
| { data: FILE; maxLength?: number; until?: string | byte }
|
|
2615
|
+
| Path
|
|
2616
|
+
| { path: Path | string; maxLength?: number; until?: string | byte }
|
|
2387
2617
|
| { fd: number; maxLength?: number; until?: string | byte };
|
|
2388
2618
|
|
|
2389
2619
|
/**
|
|
@@ -2399,6 +2629,7 @@ declare type PipeDestination =
|
|
|
2399
2629
|
| SharedArrayBuffer
|
|
2400
2630
|
| DataView
|
|
2401
2631
|
| TypedArray
|
|
2632
|
+
| Path
|
|
2402
2633
|
| FILE
|
|
2403
2634
|
| ArrayBufferConstructor
|
|
2404
2635
|
| SharedArrayBufferConstructor
|
|
@@ -2437,39 +2668,132 @@ declare function pipe<Dest extends PipeDestination>(
|
|
|
2437
2668
|
: never;
|
|
2438
2669
|
};
|
|
2439
2670
|
|
|
2671
|
+
interface InteractivePrompt {
|
|
2672
|
+
prompt?: () => string;
|
|
2673
|
+
printInput?: (input: string) => void;
|
|
2674
|
+
historyFileName?: string;
|
|
2675
|
+
getCompletions?: (
|
|
2676
|
+
line: string,
|
|
2677
|
+
pos: number
|
|
2678
|
+
) => {
|
|
2679
|
+
// TODO refactor these to have better key names
|
|
2680
|
+
tab: Array<string>;
|
|
2681
|
+
pos: number;
|
|
2682
|
+
ctx: { [key: string | number | symbol]: any };
|
|
2683
|
+
};
|
|
2684
|
+
|
|
2685
|
+
handleInput: (input: string) => void;
|
|
2686
|
+
start(): void;
|
|
2687
|
+
}
|
|
2688
|
+
|
|
2689
|
+
interface InteractivePromptConstructor {
|
|
2690
|
+
new (
|
|
2691
|
+
handleInput: (input: string) => void,
|
|
2692
|
+
options?: {
|
|
2693
|
+
prompt?: () => string;
|
|
2694
|
+
printInput?: (input: string) => void;
|
|
2695
|
+
historyFileName?: string;
|
|
2696
|
+
getCompletions?: (
|
|
2697
|
+
line: string,
|
|
2698
|
+
pos: number
|
|
2699
|
+
) => {
|
|
2700
|
+
// TODO refactor these to have better key names
|
|
2701
|
+
tab: Array<string>;
|
|
2702
|
+
pos: number;
|
|
2703
|
+
ctx: { [key: string | number | symbol]: any };
|
|
2704
|
+
};
|
|
2705
|
+
}
|
|
2706
|
+
): InteractivePrompt;
|
|
2707
|
+
|
|
2708
|
+
prototype: InteractivePrompt;
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
/** wip experimental use at your own risk */
|
|
2712
|
+
declare var InteractivePrompt: InteractivePromptConstructor;
|
|
2713
|
+
|
|
2440
2714
|
/**
|
|
2441
2715
|
* Launch the Yavascript REPL (read-eval-print-loop).
|
|
2442
2716
|
*
|
|
2443
2717
|
* @param context Variables to make available as globals within the repl.
|
|
2444
2718
|
* @param lang The langauge to use in the repl. Defaults to "javascript".
|
|
2445
2719
|
*/
|
|
2446
|
-
declare
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2720
|
+
declare const startRepl: {
|
|
2721
|
+
(
|
|
2722
|
+
context?: { [key: string]: any },
|
|
2723
|
+
lang?:
|
|
2724
|
+
| "js"
|
|
2725
|
+
| "javascript"
|
|
2726
|
+
| "ts"
|
|
2727
|
+
| "typescript"
|
|
2728
|
+
| "jsx"
|
|
2729
|
+
| "tsx"
|
|
2730
|
+
| "coffee"
|
|
2731
|
+
| "coffeescript"
|
|
2732
|
+
): void;
|
|
2458
2733
|
|
|
2459
|
-
/**
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
* that folder instead of in `pwd()`.
|
|
2466
|
-
*/
|
|
2467
|
-
declare function repoRoot(relativeTo?: string): string;
|
|
2734
|
+
/**
|
|
2735
|
+
* A special value; when expressions result in this value, the repl will
|
|
2736
|
+
* print nothing instead of printing this value.
|
|
2737
|
+
*/
|
|
2738
|
+
NOTHING: symbol;
|
|
2739
|
+
};
|
|
2468
2740
|
|
|
2469
2741
|
/**
|
|
2470
|
-
*
|
|
2742
|
+
* An object that points to a git repository on disk and provides utility
|
|
2743
|
+
* methods for getting information from that repo.
|
|
2471
2744
|
*/
|
|
2472
|
-
declare
|
|
2745
|
+
declare class GitRepo {
|
|
2746
|
+
/**
|
|
2747
|
+
* Given a path to a file or folder on disk, searches upwards through the
|
|
2748
|
+
* directory ancestry to find a `.git` folder, then returns the Path that
|
|
2749
|
+
* contains that `.git` folder. If no `.git` folder is found, an error will be
|
|
2750
|
+
* thrown.
|
|
2751
|
+
*/
|
|
2752
|
+
static findRoot(fromPath: string | Path): Path;
|
|
2753
|
+
|
|
2754
|
+
/**
|
|
2755
|
+
* Creates a new `GitRepo` object for the given repo on disk.
|
|
2756
|
+
*/
|
|
2757
|
+
constructor(repoDir: string | Path);
|
|
2758
|
+
|
|
2759
|
+
/**
|
|
2760
|
+
* The root folder of the git repo that this `GitRepo` object represents (the
|
|
2761
|
+
* folder that contains the '.git' folder).
|
|
2762
|
+
*/
|
|
2763
|
+
repoDir: Path;
|
|
2764
|
+
|
|
2765
|
+
/**
|
|
2766
|
+
* Returns the commit SHA the git repo is currently pointed at.
|
|
2767
|
+
*
|
|
2768
|
+
* This is done by running `git rev-parse HEAD`.
|
|
2769
|
+
*/
|
|
2770
|
+
commitSHA(): string;
|
|
2771
|
+
|
|
2772
|
+
/**
|
|
2773
|
+
* If the commit SHA the git repo is currently pointed at is the tip of a
|
|
2774
|
+
* named branch, returns the branch name. Otherwise, returns `null`.
|
|
2775
|
+
*
|
|
2776
|
+
* This is done by running `git rev-parse --abbrev-ref HEAD`.
|
|
2777
|
+
*/
|
|
2778
|
+
branchName(): string | null;
|
|
2779
|
+
|
|
2780
|
+
/**
|
|
2781
|
+
* Returns a boolean indicating whether there are uncommited changes in the
|
|
2782
|
+
* git repo. `true` means there are changes, `false` means there are no
|
|
2783
|
+
* changes (ie. the repo is clean).
|
|
2784
|
+
*
|
|
2785
|
+
* This is done by running `git status --quiet`.
|
|
2786
|
+
*/
|
|
2787
|
+
isWorkingTreeDirty(): boolean;
|
|
2788
|
+
|
|
2789
|
+
/**
|
|
2790
|
+
* Returns whether the provided path is ignored by git.
|
|
2791
|
+
*
|
|
2792
|
+
* If `path` is an absolute path, it must be a child directory of this GitRepo
|
|
2793
|
+
* object's `repoDir`, or else an error will be thrown.
|
|
2794
|
+
*/
|
|
2795
|
+
isIgnored(path: string | Path): boolean;
|
|
2796
|
+
}
|
|
2473
2797
|
|
|
2474
2798
|
/**
|
|
2475
2799
|
* Configures the default value of `trace` in functions which receive `trace`
|
|
@@ -2689,6 +3013,866 @@ declare type TypedArrayConstructor =
|
|
|
2689
3013
|
// QuickJS APIs, which YavaScript builds upon
|
|
2690
3014
|
// ------------------------------------------
|
|
2691
3015
|
// ==========================================
|
|
3016
|
+
interface ObjectConstructor {
|
|
3017
|
+
/**
|
|
3018
|
+
* Convert the specified value to a primitive value.
|
|
3019
|
+
*
|
|
3020
|
+
* The provided hint indicates a preferred return type, which may or may not
|
|
3021
|
+
* be respected by the engine.
|
|
3022
|
+
*
|
|
3023
|
+
* See the abstract operation "ToPrimitive" in the ECMAScript standard for
|
|
3024
|
+
* more info.
|
|
3025
|
+
*/
|
|
3026
|
+
toPrimitive(
|
|
3027
|
+
input: any,
|
|
3028
|
+
hint: "string" | "number" | "default"
|
|
3029
|
+
): string | number | bigint | boolean | undefined | symbol | null;
|
|
3030
|
+
|
|
3031
|
+
/**
|
|
3032
|
+
* Returns a boolean indicating whether the specified value is a primitive value.
|
|
3033
|
+
*/
|
|
3034
|
+
isPrimitive(input: any): boolean;
|
|
3035
|
+
}
|
|
3036
|
+
|
|
3037
|
+
interface SymbolConstructor {
|
|
3038
|
+
/**
|
|
3039
|
+
* A method that changes the result of using the `typeof` operator on the
|
|
3040
|
+
* object. Called by the semantics of the typeof operator.
|
|
3041
|
+
*
|
|
3042
|
+
* Note that the following semantics will come into play when use of the
|
|
3043
|
+
* `typeof` operator causes the engine to call a `Symbol.typeofValue` method
|
|
3044
|
+
* on an object:
|
|
3045
|
+
*
|
|
3046
|
+
* - If the method returns any value other than one of the string values
|
|
3047
|
+
* which are normally the result of using the `typeof` operator, the engine
|
|
3048
|
+
* behaves as if no `Symbol.typeofValue` method was present on the object.
|
|
3049
|
+
* - If an error is thrown from this method, or an error is thrown while
|
|
3050
|
+
* accessing this property, the error will be silently ignored, and the
|
|
3051
|
+
* engine will behave as if no `Symbol.typeofValue` method was present on
|
|
3052
|
+
* the object.
|
|
3053
|
+
* - If this property is present on an object, but the value of that property
|
|
3054
|
+
* is not a function, the engine will not consider that value when
|
|
3055
|
+
* determining the result of the `typeof` operation (it'll ignore it).
|
|
3056
|
+
*/
|
|
3057
|
+
readonly typeofValue: unique symbol;
|
|
3058
|
+
|
|
3059
|
+
/**
|
|
3060
|
+
* To override operators (+, -, ==, etc) for an object, set its
|
|
3061
|
+
* `Symbol.operatorSet` property to an `OperatorSet` object, which can be
|
|
3062
|
+
* created via `Operators.create`.
|
|
3063
|
+
*/
|
|
3064
|
+
readonly operatorSet: unique symbol;
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
/**
|
|
3068
|
+
* An object that, if placed on another object's `Symbol.operatorSet` property,
|
|
3069
|
+
* will overload its operators to behave as defined by the functions this
|
|
3070
|
+
* OperatorSet was constructed with.
|
|
3071
|
+
*
|
|
3072
|
+
* You can create an OperatorSet via `Operators(...)` or
|
|
3073
|
+
* `Operators.create(...)`.
|
|
3074
|
+
*/
|
|
3075
|
+
declare type OperatorSet = {
|
|
3076
|
+
/**
|
|
3077
|
+
* This property is not here at runtime; we just use it to make this type
|
|
3078
|
+
* differ from an empty object.
|
|
3079
|
+
*/
|
|
3080
|
+
__is__: "OperatorSet";
|
|
3081
|
+
};
|
|
3082
|
+
|
|
3083
|
+
interface OperatorFunctions<Left, Right> {
|
|
3084
|
+
"+": (left: Left, right: Right) => any;
|
|
3085
|
+
"-": (left: Left, right: Right) => any;
|
|
3086
|
+
"*": (left: Left, right: Right) => any;
|
|
3087
|
+
"/": (left: Left, right: Right) => any;
|
|
3088
|
+
"%": (left: Left, right: Right) => any;
|
|
3089
|
+
"**": (left: Left, right: Right) => any;
|
|
3090
|
+
"|": (left: Left, right: Right) => any;
|
|
3091
|
+
"&": (left: Left, right: Right) => any;
|
|
3092
|
+
"^": (left: Left, right: Right) => any;
|
|
3093
|
+
"<<": (left: Left, right: Right) => any;
|
|
3094
|
+
">>": (left: Left, right: Right) => any;
|
|
3095
|
+
">>>": (left: Left, right: Right) => any;
|
|
3096
|
+
"==": (left: Left, right: Right) => any;
|
|
3097
|
+
"<": (left: Left, right: Right) => any;
|
|
3098
|
+
pos: (left: Left, right: Right) => any;
|
|
3099
|
+
neg: (left: Left, right: Right) => any;
|
|
3100
|
+
"++": (left: Left, right: Right) => any;
|
|
3101
|
+
"--": (left: Left, right: Right) => any;
|
|
3102
|
+
"~": (left: Left, right: Right) => any;
|
|
3103
|
+
}
|
|
3104
|
+
|
|
3105
|
+
interface SelfOperators<T> extends Partial<OperatorFunctions<T, T>> {
|
|
3106
|
+
left?: undefined;
|
|
3107
|
+
right?: undefined;
|
|
3108
|
+
}
|
|
3109
|
+
|
|
3110
|
+
interface LeftOperators<T, Left> extends Partial<OperatorFunctions<Left, T>> {
|
|
3111
|
+
left: {};
|
|
3112
|
+
right?: undefined;
|
|
3113
|
+
}
|
|
3114
|
+
|
|
3115
|
+
interface RightOperators<T, Right>
|
|
3116
|
+
extends Partial<OperatorFunctions<T, Right>> {
|
|
3117
|
+
left?: undefined;
|
|
3118
|
+
right: {};
|
|
3119
|
+
}
|
|
3120
|
+
|
|
3121
|
+
interface OperatorsConstructor {
|
|
3122
|
+
/**
|
|
3123
|
+
* Creates a new OperatorSet object, which should be placed on an object's
|
|
3124
|
+
* Symbol.operatorSet property.
|
|
3125
|
+
*/
|
|
3126
|
+
<T>(
|
|
3127
|
+
selfOperators?: SelfOperators<T>,
|
|
3128
|
+
...otherOperators: Array<LeftOperators<T, any> | RightOperators<T, any>>
|
|
3129
|
+
): OperatorSet;
|
|
3130
|
+
|
|
3131
|
+
/**
|
|
3132
|
+
* Creates a new OperatorSet object, which should be placed on an object's
|
|
3133
|
+
* Symbol.operatorSet property.
|
|
3134
|
+
*/
|
|
3135
|
+
create: <T>(
|
|
3136
|
+
selfOperators?: SelfOperators<T>,
|
|
3137
|
+
...otherOperators: Array<LeftOperators<T, any> | RightOperators<T, any>>
|
|
3138
|
+
) => OperatorSet;
|
|
3139
|
+
|
|
3140
|
+
/**
|
|
3141
|
+
* In math mode, the BigInt division and power operators can be overloaded by
|
|
3142
|
+
* using this function.
|
|
3143
|
+
*/
|
|
3144
|
+
updateBigIntOperators(
|
|
3145
|
+
ops: Pick<OperatorFunctions<BigInt, BigInt>, "/" | "**">
|
|
3146
|
+
): void;
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
declare var Operators: OperatorsConstructor;
|
|
3150
|
+
|
|
3151
|
+
interface Number {
|
|
3152
|
+
[Symbol.operatorSet]: OperatorSet;
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3155
|
+
interface Boolean {
|
|
3156
|
+
[Symbol.operatorSet]: OperatorSet;
|
|
3157
|
+
}
|
|
3158
|
+
|
|
3159
|
+
interface String {
|
|
3160
|
+
[Symbol.operatorSet]: OperatorSet;
|
|
3161
|
+
}
|
|
3162
|
+
|
|
3163
|
+
interface BigInt {
|
|
3164
|
+
[Symbol.operatorSet]: OperatorSet;
|
|
3165
|
+
}
|
|
3166
|
+
|
|
3167
|
+
interface BigIntConstructor {
|
|
3168
|
+
/**
|
|
3169
|
+
* Return trunc(a/b).
|
|
3170
|
+
*
|
|
3171
|
+
* b = 0 raises a RangeError exception.
|
|
3172
|
+
*/
|
|
3173
|
+
tdiv(a: bigint, b: bigint): bigint;
|
|
3174
|
+
|
|
3175
|
+
/**
|
|
3176
|
+
* Return \lfloor a/b \rfloor.
|
|
3177
|
+
*
|
|
3178
|
+
* b = 0 raises a RangeError exception.
|
|
3179
|
+
*/
|
|
3180
|
+
fdiv(a: bigint, b: bigint): bigint;
|
|
3181
|
+
|
|
3182
|
+
/**
|
|
3183
|
+
* Return \lceil a/b \rceil.
|
|
3184
|
+
*
|
|
3185
|
+
* b = 0 raises a RangeError exception.
|
|
3186
|
+
*/
|
|
3187
|
+
cdiv(a: bigint, b: bigint): bigint;
|
|
3188
|
+
|
|
3189
|
+
/**
|
|
3190
|
+
* Return sgn(b) \lfloor a/{|b|} \rfloor (Euclidian division).
|
|
3191
|
+
*
|
|
3192
|
+
* b = 0 raises a RangeError exception.
|
|
3193
|
+
*/
|
|
3194
|
+
ediv(a: bigint, b: bigint): bigint;
|
|
3195
|
+
|
|
3196
|
+
/**
|
|
3197
|
+
* Perform trunc(a/b) and return an array of two elements. The first element
|
|
3198
|
+
* is the quotient, the second is the remainder.
|
|
3199
|
+
*
|
|
3200
|
+
* b = 0 raises a RangeError exception.
|
|
3201
|
+
*/
|
|
3202
|
+
tdivrem(a: bigint, b: bigint): [bigint, bigint];
|
|
3203
|
+
|
|
3204
|
+
/**
|
|
3205
|
+
* Perform \lfloor a/b \rfloor and return an array of two elements. The first
|
|
3206
|
+
* element is the quotient, the second is the remainder.
|
|
3207
|
+
*
|
|
3208
|
+
* b = 0 raises a RangeError exception.
|
|
3209
|
+
*/
|
|
3210
|
+
fdivrem(a: bigint, b: bigint): [bigint, bigint];
|
|
3211
|
+
|
|
3212
|
+
/**
|
|
3213
|
+
* Perform \lceil a/b \rceil and return an array of two elements. The first
|
|
3214
|
+
* element is the quotient, the second is the remainder.
|
|
3215
|
+
*
|
|
3216
|
+
* b = 0 raises a RangeError exception.
|
|
3217
|
+
*/
|
|
3218
|
+
cdivrem(a: bigint, b: bigint): [bigint, bigint];
|
|
3219
|
+
|
|
3220
|
+
/**
|
|
3221
|
+
* Perform sgn(b) \lfloor a/{|b|} \rfloor (Euclidian division) and return an
|
|
3222
|
+
* array of two elements. The first element is the quotient, the second is
|
|
3223
|
+
* the remainder.
|
|
3224
|
+
*
|
|
3225
|
+
* b = 0 raises a RangeError exception.
|
|
3226
|
+
*/
|
|
3227
|
+
edivrem(a: bigint, b: bigint): [bigint, bigint];
|
|
3228
|
+
|
|
3229
|
+
/**
|
|
3230
|
+
* Return \lfloor \sqrt(a) \rfloor.
|
|
3231
|
+
*
|
|
3232
|
+
* A RangeError exception is raised if a < 0.
|
|
3233
|
+
*/
|
|
3234
|
+
sqrt(a: bigint): bigint;
|
|
3235
|
+
|
|
3236
|
+
/**
|
|
3237
|
+
* Return an array of two elements. The first element is
|
|
3238
|
+
* \lfloor \sqrt{a} \rfloor. The second element is
|
|
3239
|
+
* a-\lfloor \sqrt{a} \rfloor^2.
|
|
3240
|
+
*
|
|
3241
|
+
* A RangeError exception is raised if a < 0.
|
|
3242
|
+
*/
|
|
3243
|
+
sqrtrem(a: bigint): [bigint, bigint];
|
|
3244
|
+
|
|
3245
|
+
/**
|
|
3246
|
+
* Return -1 if a \leq 0 otherwise return \lfloor \log2(a) \rfloor.
|
|
3247
|
+
*/
|
|
3248
|
+
floorLog2(a: bigint): bigint;
|
|
3249
|
+
|
|
3250
|
+
/**
|
|
3251
|
+
* Return the number of trailing zeros in the two’s complement binary representation of a.
|
|
3252
|
+
*
|
|
3253
|
+
* Return -1 if a=0.
|
|
3254
|
+
*/
|
|
3255
|
+
ctz(a: bigint): bigint;
|
|
3256
|
+
}
|
|
3257
|
+
|
|
3258
|
+
declare type BigFloatRoundingMode = number & {
|
|
3259
|
+
/**
|
|
3260
|
+
* This property is not here at runtime; we just use it to make this type
|
|
3261
|
+
* differ from a normal number
|
|
3262
|
+
*/
|
|
3263
|
+
__is__: "BigFloatRoundingMode";
|
|
3264
|
+
};
|
|
3265
|
+
|
|
3266
|
+
interface BigFloatEnvConstructor {
|
|
3267
|
+
/**
|
|
3268
|
+
* Creates a new floating point environment. Its status flags are reset.
|
|
3269
|
+
*
|
|
3270
|
+
* - If unspecified, `precision` defaults to the precision from the global floating point environment.
|
|
3271
|
+
* - If unspecified, `roundingMode` defaults to RNDN.
|
|
3272
|
+
*/
|
|
3273
|
+
new (precision?: number, roundingMode?: BigFloatRoundingMode): BigFloatEnv;
|
|
3274
|
+
|
|
3275
|
+
/**
|
|
3276
|
+
* The mantissa precision in bits of the global floating point environment.
|
|
3277
|
+
*
|
|
3278
|
+
* The initial value is 113.
|
|
3279
|
+
*/
|
|
3280
|
+
get prec(): number;
|
|
3281
|
+
|
|
3282
|
+
/**
|
|
3283
|
+
* The exponent size in bits of the global floating point environment,
|
|
3284
|
+
* assuming an IEEE 754 representation.
|
|
3285
|
+
*
|
|
3286
|
+
* The initial value is 15.
|
|
3287
|
+
*/
|
|
3288
|
+
get expBits(): number;
|
|
3289
|
+
|
|
3290
|
+
/**
|
|
3291
|
+
* Sets the mantissa precision of the global floating point environment to
|
|
3292
|
+
* `prec` and the exponent size to `expBits`, then calls the function `func`.
|
|
3293
|
+
* Then the precision and exponent size are reset to their previous values
|
|
3294
|
+
* and the return value of `func` is returned (or an exception is raised if
|
|
3295
|
+
* `func` raised an exception).
|
|
3296
|
+
*
|
|
3297
|
+
* If expBits is undefined, it is set to {@link BigFloatEnv.expBitsMax}.
|
|
3298
|
+
*
|
|
3299
|
+
* @param func The function to call within the modified environment
|
|
3300
|
+
* @param prec The mantissa precision (in bits) to use in the modified environment
|
|
3301
|
+
* @param expBits The exponent size (in bits) to use in the modified environment. Defaults to {@link BigFloatEnv.expBitsMax}.
|
|
3302
|
+
*/
|
|
3303
|
+
setPrec<Ret>(func: () => Ret, prec: number, expBits?: number): Ret;
|
|
3304
|
+
|
|
3305
|
+
/**
|
|
3306
|
+
* Integer; the minimum allowed precision. Must be at least 2.
|
|
3307
|
+
*/
|
|
3308
|
+
readonly precMin: number;
|
|
3309
|
+
|
|
3310
|
+
/**
|
|
3311
|
+
* Integer; the maximum allowed precision. Must be at least 113.
|
|
3312
|
+
*/
|
|
3313
|
+
readonly precMax: number;
|
|
3314
|
+
|
|
3315
|
+
/**
|
|
3316
|
+
* Integer; the minimum allowed exponent size in bits. Must be at least 3.
|
|
3317
|
+
*/
|
|
3318
|
+
readonly expBitsMin: number;
|
|
3319
|
+
|
|
3320
|
+
/**
|
|
3321
|
+
* Integer; the maximum allowed exponent size in bits. Must be at least 15.
|
|
3322
|
+
*/
|
|
3323
|
+
readonly expBitsMax: number;
|
|
3324
|
+
|
|
3325
|
+
/**
|
|
3326
|
+
* Round to nearest, with ties to even rounding mode.
|
|
3327
|
+
*/
|
|
3328
|
+
readonly RNDN: BigFloatRoundingMode;
|
|
3329
|
+
|
|
3330
|
+
/**
|
|
3331
|
+
* Round to zero rounding mode.
|
|
3332
|
+
*/
|
|
3333
|
+
readonly RNDZ: BigFloatRoundingMode;
|
|
3334
|
+
|
|
3335
|
+
/**
|
|
3336
|
+
* Round to -Infinity rounding mode.
|
|
3337
|
+
*/
|
|
3338
|
+
readonly RNDD: BigFloatRoundingMode;
|
|
3339
|
+
|
|
3340
|
+
/**
|
|
3341
|
+
* Round to +Infinity rounding mode.
|
|
3342
|
+
*/
|
|
3343
|
+
readonly RNDU: BigFloatRoundingMode;
|
|
3344
|
+
|
|
3345
|
+
/**
|
|
3346
|
+
* Round to nearest, with ties away from zero rounding mode.
|
|
3347
|
+
*/
|
|
3348
|
+
readonly RNDNA: BigFloatRoundingMode;
|
|
3349
|
+
|
|
3350
|
+
/**
|
|
3351
|
+
* Round away from zero rounding mode.
|
|
3352
|
+
*/
|
|
3353
|
+
readonly RNDA: BigFloatRoundingMode;
|
|
3354
|
+
|
|
3355
|
+
/**
|
|
3356
|
+
* Faithful rounding mode. The result is non-deterministically rounded to
|
|
3357
|
+
* -Infinity or +Infinity.
|
|
3358
|
+
*
|
|
3359
|
+
* This rounding mode usually gives a faster and deterministic running time
|
|
3360
|
+
* for the floating point operations.
|
|
3361
|
+
*/
|
|
3362
|
+
readonly RNDF: BigFloatRoundingMode;
|
|
3363
|
+
|
|
3364
|
+
prototype: BigFloatEnv;
|
|
3365
|
+
}
|
|
3366
|
+
|
|
3367
|
+
declare var BigFloatEnv: BigFloatEnvConstructor;
|
|
3368
|
+
|
|
3369
|
+
/**
|
|
3370
|
+
* A BigFloatEnv contains:
|
|
3371
|
+
*
|
|
3372
|
+
* - the mantissa precision in bits
|
|
3373
|
+
* - the exponent size in bits assuming an IEEE 754 representation;
|
|
3374
|
+
* - the subnormal flag (if true, subnormal floating point numbers can be generated by the floating point operations).
|
|
3375
|
+
* - the rounding mode
|
|
3376
|
+
* - the floating point status. The status flags can only be set by the floating point operations. They can be reset with BigFloatEnv.prototype.clearStatus() or with the various status flag setters.
|
|
3377
|
+
*/
|
|
3378
|
+
interface BigFloatEnv {
|
|
3379
|
+
/**
|
|
3380
|
+
* The mantissa precision, in bits.
|
|
3381
|
+
*
|
|
3382
|
+
* If precision was not specified as an argument to the BigFloatEnv
|
|
3383
|
+
* constructor, defaults to the precision value of the global floating-point
|
|
3384
|
+
* environment ({@link BigFloatEnv.prec}).
|
|
3385
|
+
*/
|
|
3386
|
+
get prec(): number;
|
|
3387
|
+
set prec(newValue: number);
|
|
3388
|
+
|
|
3389
|
+
/**
|
|
3390
|
+
* The exponent size in bits assuming an IEEE 754 representation.
|
|
3391
|
+
*
|
|
3392
|
+
* Defaults to the exponent size of the global floating-point environment
|
|
3393
|
+
* ({@link BigFloatEnv.expBits}).
|
|
3394
|
+
*/
|
|
3395
|
+
get expBits(): number;
|
|
3396
|
+
set expBits(newValue: number);
|
|
3397
|
+
|
|
3398
|
+
/**
|
|
3399
|
+
* The rounding mode.
|
|
3400
|
+
*
|
|
3401
|
+
* If the rounding mode was not specified as an argument to the BigFloatEnv
|
|
3402
|
+
* constructor, defaults to {@link BigFloatEnv.RNDN}.
|
|
3403
|
+
*/
|
|
3404
|
+
get rndMode(): BigFloatRoundingMode;
|
|
3405
|
+
set rndMode(newMode: BigFloatRoundingMode);
|
|
3406
|
+
|
|
3407
|
+
/** subnormal flag. It is false when expBits = expBitsMax. Defaults to false. */
|
|
3408
|
+
get subnormal(): boolean;
|
|
3409
|
+
set subnormal(newValue: boolean);
|
|
3410
|
+
|
|
3411
|
+
/** Status flag; cleared by `clearStatus`. */
|
|
3412
|
+
get invalidOperation(): boolean;
|
|
3413
|
+
set invalidOperation(newValue: boolean);
|
|
3414
|
+
|
|
3415
|
+
/** Status flag; cleared by `clearStatus`. */
|
|
3416
|
+
get divideByZero(): boolean;
|
|
3417
|
+
set divideByZero(newValue: boolean);
|
|
3418
|
+
|
|
3419
|
+
/** Status flag; cleared by `clearStatus`. */
|
|
3420
|
+
get overflow(): boolean;
|
|
3421
|
+
set overflow(newValue: boolean);
|
|
3422
|
+
|
|
3423
|
+
/** Status flag; cleared by `clearStatus`. */
|
|
3424
|
+
get underflow(): boolean;
|
|
3425
|
+
set underflow(newValue: boolean);
|
|
3426
|
+
|
|
3427
|
+
/** Status flag; cleared by `clearStatus`. */
|
|
3428
|
+
get inexact(): boolean;
|
|
3429
|
+
set inexact(newValue: boolean);
|
|
3430
|
+
|
|
3431
|
+
/**
|
|
3432
|
+
* Clear the status flags (invalidOperation, divideByZero, overflow,
|
|
3433
|
+
* underflow, and inexact).
|
|
3434
|
+
*/
|
|
3435
|
+
clearStatus(): void;
|
|
3436
|
+
}
|
|
3437
|
+
|
|
3438
|
+
interface BigFloatConstructor {
|
|
3439
|
+
/**
|
|
3440
|
+
* If `value` is a numeric type, it is converted to BigFloat without rounding.
|
|
3441
|
+
*
|
|
3442
|
+
* If `value`` is a string, it is converted to BigFloat using the precision of the global floating point environment ({@link BigFloatEnv.prec}).
|
|
3443
|
+
*/
|
|
3444
|
+
(value: number | string | BigInt | BigFloat): BigFloat;
|
|
3445
|
+
|
|
3446
|
+
prototype: BigFloat;
|
|
3447
|
+
|
|
3448
|
+
/**
|
|
3449
|
+
* The value of {@link Math.LN2} rounded to nearest, ties to even with the
|
|
3450
|
+
* current global precision.
|
|
3451
|
+
*
|
|
3452
|
+
* The constant values are cached for small precisions.
|
|
3453
|
+
*/
|
|
3454
|
+
get LN2(): BigFloat;
|
|
3455
|
+
|
|
3456
|
+
/**
|
|
3457
|
+
* The value of {@link Math.PI} rounded to nearest, ties to even with
|
|
3458
|
+
* the current global precision.
|
|
3459
|
+
*
|
|
3460
|
+
* The constant values are cached for small precisions.
|
|
3461
|
+
*/
|
|
3462
|
+
get PI(): BigFloat;
|
|
3463
|
+
|
|
3464
|
+
/**
|
|
3465
|
+
* The value of {@link Number.MIN_VALUE} as a BigFloat.
|
|
3466
|
+
*/
|
|
3467
|
+
get MIN_VALUE(): BigFloat;
|
|
3468
|
+
|
|
3469
|
+
/**
|
|
3470
|
+
* The value of {@link Number.MAX_VALUE} as a BigFloat.
|
|
3471
|
+
*/
|
|
3472
|
+
get MAX_VALUE(): BigFloat;
|
|
3473
|
+
|
|
3474
|
+
/**
|
|
3475
|
+
* The value of {@link Number.EPSILON} as a BigFloat.
|
|
3476
|
+
*/
|
|
3477
|
+
get EPSILON(): BigFloat;
|
|
3478
|
+
|
|
3479
|
+
/**
|
|
3480
|
+
* Rounds the floating point number `a` according to the floating point
|
|
3481
|
+
* environment `e` or the global environment if `e` is undefined.
|
|
3482
|
+
*/
|
|
3483
|
+
fpRound(a: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3484
|
+
|
|
3485
|
+
/**
|
|
3486
|
+
* Parses the string `a` as a floating point number in radix `radix`.
|
|
3487
|
+
*
|
|
3488
|
+
* The radix is 0 (default) or from 2 to 36. The radix 0 means radix 10
|
|
3489
|
+
* unless there is a hexadecimal or binary prefix.
|
|
3490
|
+
*
|
|
3491
|
+
* The result is rounded according to the floating point environment `e` or
|
|
3492
|
+
* the global environment if `e` is undefined.
|
|
3493
|
+
*/
|
|
3494
|
+
parseFloat(a: string, radix?: number, e?: BigFloatEnv): BigFloat;
|
|
3495
|
+
|
|
3496
|
+
/**
|
|
3497
|
+
* Returns true if `a` is a finite bigfloat. Returns false otherwise.
|
|
3498
|
+
*/
|
|
3499
|
+
isFinite(a: BigFloat): boolean;
|
|
3500
|
+
|
|
3501
|
+
/**
|
|
3502
|
+
* Returns true if a is a NaN bigfloat. Returns false otherwise.
|
|
3503
|
+
*/
|
|
3504
|
+
isNaN(a: BigFloat): boolean;
|
|
3505
|
+
|
|
3506
|
+
/**
|
|
3507
|
+
* Adds `a` and `b` together and rounds the resulting floating point number
|
|
3508
|
+
* according to the floating point environment `e`, or the global environment
|
|
3509
|
+
* if e is undefined.
|
|
3510
|
+
*
|
|
3511
|
+
* If `e` is specified, the floating point status flags on `e` are updated.
|
|
3512
|
+
*/
|
|
3513
|
+
add(a: BigFloat, b: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3514
|
+
|
|
3515
|
+
/**
|
|
3516
|
+
* Subtracts `b` from `a` and rounds the resulting floating point number
|
|
3517
|
+
* according to the floating point environment `e`, or the global environment
|
|
3518
|
+
* if e is undefined.
|
|
3519
|
+
*
|
|
3520
|
+
* If `e` is specified, the floating point status flags on `e` are updated.
|
|
3521
|
+
*/
|
|
3522
|
+
sub(a: BigFloat, b: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3523
|
+
|
|
3524
|
+
/**
|
|
3525
|
+
* Multiplies `a` and `b` together and rounds the resulting floating point
|
|
3526
|
+
* number according to the floating point environment `e`, or the global
|
|
3527
|
+
* environment if e is undefined.
|
|
3528
|
+
*
|
|
3529
|
+
* If `e` is specified, the floating point status flags on `e` are updated.
|
|
3530
|
+
*/
|
|
3531
|
+
mul(a: BigFloat, b: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3532
|
+
|
|
3533
|
+
/**
|
|
3534
|
+
* Divides `a` by `b` and rounds the resulting floating point number
|
|
3535
|
+
* according to the floating point environment `e`, or the global environment
|
|
3536
|
+
* if e is undefined.
|
|
3537
|
+
*
|
|
3538
|
+
* If `e` is specified, the floating point status flags on `e` are updated.
|
|
3539
|
+
*/
|
|
3540
|
+
div(a: BigFloat, b: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3541
|
+
|
|
3542
|
+
/**
|
|
3543
|
+
* Rounds `x` down to the nearest integer.
|
|
3544
|
+
*
|
|
3545
|
+
* No additional rounding (ie. BigFloatEnv-related rounding) is performed.
|
|
3546
|
+
*/
|
|
3547
|
+
floor(x: BigFloat): BigFloat;
|
|
3548
|
+
|
|
3549
|
+
/**
|
|
3550
|
+
* Rounds `x` up to the nearest integer.
|
|
3551
|
+
*
|
|
3552
|
+
* No additional rounding (ie. BigFloatEnv-related rounding) is performed.
|
|
3553
|
+
*/
|
|
3554
|
+
ceil(x: BigFloat): BigFloat;
|
|
3555
|
+
|
|
3556
|
+
/**
|
|
3557
|
+
* Rounds `x` to the nearest integer.
|
|
3558
|
+
*
|
|
3559
|
+
* No additional rounding (ie. BigFloatEnv-related rounding) is performed.
|
|
3560
|
+
*/
|
|
3561
|
+
round(x: BigFloat): BigFloat;
|
|
3562
|
+
|
|
3563
|
+
/**
|
|
3564
|
+
* Truncates the fractional part of `x`, resulting in an integer.
|
|
3565
|
+
*
|
|
3566
|
+
* No additional rounding (ie. BigFloatEnv-related rounding) is performed.
|
|
3567
|
+
*/
|
|
3568
|
+
trunc(x: BigFloat): BigFloat;
|
|
3569
|
+
|
|
3570
|
+
/**
|
|
3571
|
+
* Returns the absolute value of `x`.
|
|
3572
|
+
*
|
|
3573
|
+
* No additional rounding (ie. BigFloatEnv-related rounding) is performed.
|
|
3574
|
+
*/
|
|
3575
|
+
abs(x: BigFloat): BigFloat;
|
|
3576
|
+
|
|
3577
|
+
/**
|
|
3578
|
+
* Floating point remainder. The quotient is truncated to zero.
|
|
3579
|
+
*
|
|
3580
|
+
* `e` is an optional floating point environment.
|
|
3581
|
+
*/
|
|
3582
|
+
fmod(x: BigFloat, y: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3583
|
+
|
|
3584
|
+
/**
|
|
3585
|
+
* Floating point remainder. The quotient is rounded to the nearest integer
|
|
3586
|
+
* with ties to even.
|
|
3587
|
+
*
|
|
3588
|
+
* `e` is an optional floating point environment.
|
|
3589
|
+
*/
|
|
3590
|
+
remainder(x: BigFloat, y: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3591
|
+
|
|
3592
|
+
/**
|
|
3593
|
+
* Square root. Returns a rounded floating point number.
|
|
3594
|
+
*
|
|
3595
|
+
* e is an optional floating point environment.
|
|
3596
|
+
*/
|
|
3597
|
+
sqrt(x: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3598
|
+
|
|
3599
|
+
/**
|
|
3600
|
+
* Returns a rounded floating point number.
|
|
3601
|
+
*
|
|
3602
|
+
* `e` is an optional floating point environment.
|
|
3603
|
+
*/
|
|
3604
|
+
sin(x: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3605
|
+
|
|
3606
|
+
/**
|
|
3607
|
+
* Returns a rounded floating point number.
|
|
3608
|
+
*
|
|
3609
|
+
* `e` is an optional floating point environment.
|
|
3610
|
+
*/
|
|
3611
|
+
cos(x: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3612
|
+
|
|
3613
|
+
/**
|
|
3614
|
+
* Returns a rounded floating point number.
|
|
3615
|
+
*
|
|
3616
|
+
* `e` is an optional floating point environment.
|
|
3617
|
+
*/
|
|
3618
|
+
tan(x: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3619
|
+
|
|
3620
|
+
/**
|
|
3621
|
+
* Returns a rounded floating point number.
|
|
3622
|
+
*
|
|
3623
|
+
* `e` is an optional floating point environment.
|
|
3624
|
+
*/
|
|
3625
|
+
asin(x: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3626
|
+
|
|
3627
|
+
/**
|
|
3628
|
+
* Returns a rounded floating point number.
|
|
3629
|
+
*
|
|
3630
|
+
* `e` is an optional floating point environment.
|
|
3631
|
+
*/
|
|
3632
|
+
acos(x: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3633
|
+
|
|
3634
|
+
/**
|
|
3635
|
+
* Returns a rounded floating point number.
|
|
3636
|
+
*
|
|
3637
|
+
* `e` is an optional floating point environment.
|
|
3638
|
+
*/
|
|
3639
|
+
atan(x: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3640
|
+
|
|
3641
|
+
/**
|
|
3642
|
+
* Returns a rounded floating point number.
|
|
3643
|
+
*
|
|
3644
|
+
* `e` is an optional floating point environment.
|
|
3645
|
+
*/
|
|
3646
|
+
atan2(x: BigFloat, y: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3647
|
+
|
|
3648
|
+
/**
|
|
3649
|
+
* Returns a rounded floating point number.
|
|
3650
|
+
*
|
|
3651
|
+
* `e` is an optional floating point environment.
|
|
3652
|
+
*/
|
|
3653
|
+
exp(x: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3654
|
+
|
|
3655
|
+
/**
|
|
3656
|
+
* Returns a rounded floating point number.
|
|
3657
|
+
*
|
|
3658
|
+
* `e` is an optional floating point environment.
|
|
3659
|
+
*/
|
|
3660
|
+
log(x: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3661
|
+
|
|
3662
|
+
/**
|
|
3663
|
+
* Returns a rounded floating point number.
|
|
3664
|
+
*
|
|
3665
|
+
* `e` is an optional floating point environment.
|
|
3666
|
+
*/
|
|
3667
|
+
pow(x: BigFloat, y: BigFloat, e?: BigFloatEnv): BigFloat;
|
|
3668
|
+
}
|
|
3669
|
+
|
|
3670
|
+
declare var BigFloat: BigFloatConstructor;
|
|
3671
|
+
|
|
3672
|
+
/**
|
|
3673
|
+
* The BigFloat type represents floating point numbers in base 2 with the IEEE 754 semantics.
|
|
3674
|
+
*
|
|
3675
|
+
* A floating point number is represented as a sign, mantissa and exponent.
|
|
3676
|
+
*
|
|
3677
|
+
* The special values NaN, +/-Infinity, +0 and -0 are supported.
|
|
3678
|
+
*
|
|
3679
|
+
* The mantissa and exponent can have any bit length with an implementation specific minimum and maximum.
|
|
3680
|
+
*/
|
|
3681
|
+
interface BigFloat {
|
|
3682
|
+
valueOf(): BigFloat;
|
|
3683
|
+
|
|
3684
|
+
/** radix must be between 2 and 36 */
|
|
3685
|
+
toString(radix?: number): string;
|
|
3686
|
+
|
|
3687
|
+
/**
|
|
3688
|
+
* Returns a string containing a number represented either in exponential or
|
|
3689
|
+
* fixed-point notation with a specified number of digits.
|
|
3690
|
+
*
|
|
3691
|
+
* @param precision Number of significant digits. There is no range limit on this number.
|
|
3692
|
+
* @param roundingMode The rounding mode to use when representing the value. Defaults to {@link BigFloatEnv.RNDNA}.
|
|
3693
|
+
* @param radix The base to use when representing the value. Must be an integer between 2 and 36. Defaults to 10.
|
|
3694
|
+
*/
|
|
3695
|
+
toPrecision(
|
|
3696
|
+
precision: number,
|
|
3697
|
+
roundingMode?: BigFloatRoundingMode,
|
|
3698
|
+
radix?: number
|
|
3699
|
+
): string;
|
|
3700
|
+
|
|
3701
|
+
/**
|
|
3702
|
+
* Returns a string representing a number in fixed-point notation.
|
|
3703
|
+
*
|
|
3704
|
+
* @param fractionDigits Number of digits after the decimal point. There is no range limit on this number.
|
|
3705
|
+
* @param roundingMode The rounding mode to use when representing the value. Defaults to {@link BigFloatEnv.RNDNA}.
|
|
3706
|
+
* @param radix The base to use when representing the value. Must be an integer between 2 and 36. Defaults to 10.
|
|
3707
|
+
*/
|
|
3708
|
+
toFixed(
|
|
3709
|
+
fractionDigits: number,
|
|
3710
|
+
roundingMode?: BigFloatRoundingMode,
|
|
3711
|
+
radix?: number
|
|
3712
|
+
): string;
|
|
3713
|
+
|
|
3714
|
+
/**
|
|
3715
|
+
* Returns a string containing a number represented in exponential notation.
|
|
3716
|
+
*
|
|
3717
|
+
* @param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.
|
|
3718
|
+
* @param roundingMode The rounding mode to use when representing the value. Defaults to {@link BigFloatEnv.RNDNA}.
|
|
3719
|
+
* @param radix The base to use when representing the value. Must be an integer between 2 and 36. Defaults to 10.
|
|
3720
|
+
*/
|
|
3721
|
+
toExponential(
|
|
3722
|
+
fractionDigits: number,
|
|
3723
|
+
roundingMode?: BigFloatRoundingMode,
|
|
3724
|
+
radix?: number
|
|
3725
|
+
): string;
|
|
3726
|
+
|
|
3727
|
+
[Symbol.typeofValue]: () => "bigfloat";
|
|
3728
|
+
}
|
|
3729
|
+
|
|
3730
|
+
declare type BigDecimalRoundingMode =
|
|
3731
|
+
| "floor"
|
|
3732
|
+
| "ceiling"
|
|
3733
|
+
| "down"
|
|
3734
|
+
| "up"
|
|
3735
|
+
| "half-even"
|
|
3736
|
+
| "half-up";
|
|
3737
|
+
|
|
3738
|
+
declare type BigDecimalRoundingObject =
|
|
3739
|
+
| {
|
|
3740
|
+
/** must be >= 1 */
|
|
3741
|
+
maximumSignificantDigits: number;
|
|
3742
|
+
roundingMode: BigDecimalRoundingMode;
|
|
3743
|
+
}
|
|
3744
|
+
| {
|
|
3745
|
+
/** must be >= 0 */
|
|
3746
|
+
maximumFractionDigits: number;
|
|
3747
|
+
roundingMode: BigDecimalRoundingMode;
|
|
3748
|
+
};
|
|
3749
|
+
|
|
3750
|
+
interface BigDecimalConstructor {
|
|
3751
|
+
(): BigDecimal;
|
|
3752
|
+
(value: number | string | BigInt | BigFloat): BigDecimal;
|
|
3753
|
+
|
|
3754
|
+
/**
|
|
3755
|
+
* Adds together `a` and `b` and rounds the result according to the rounding
|
|
3756
|
+
* object `e`. If the rounding object is not present, the operation is
|
|
3757
|
+
* executed with infinite precision; in other words, no rounding occurs when
|
|
3758
|
+
* the rounding object is not present.
|
|
3759
|
+
*/
|
|
3760
|
+
add(a: BigDecimal, b: BigDecimal, e?: BigDecimalRoundingObject): BigDecimal;
|
|
3761
|
+
|
|
3762
|
+
/**
|
|
3763
|
+
* Subtracts `b` from `a` and rounds the result according to the rounding
|
|
3764
|
+
* object `e`. If the rounding object is not present, the operation is
|
|
3765
|
+
* executed with infinite precision; in other words, no rounding occurs when
|
|
3766
|
+
* the rounding object is not present.
|
|
3767
|
+
*/
|
|
3768
|
+
sub(a: BigDecimal, b: BigDecimal, e?: BigDecimalRoundingObject): BigDecimal;
|
|
3769
|
+
|
|
3770
|
+
/**
|
|
3771
|
+
* Multiplies together `a` and `b` and rounds the result according to the
|
|
3772
|
+
* rounding object `e`. If the rounding object is not present, the operation
|
|
3773
|
+
* is executed with infinite precision; in other words, no rounding occurs
|
|
3774
|
+
* when the rounding object is not present.
|
|
3775
|
+
*/
|
|
3776
|
+
mul(a: BigDecimal, b: BigDecimal, e?: BigDecimalRoundingObject): BigDecimal;
|
|
3777
|
+
|
|
3778
|
+
/**
|
|
3779
|
+
* Divides `a` by `b` and rounds the result according to the rounding object
|
|
3780
|
+
* `e`.
|
|
3781
|
+
*
|
|
3782
|
+
* If the rounding object is not present, an attempt is made to perform the
|
|
3783
|
+
* operation with infinite precision. However, not all quotients can be
|
|
3784
|
+
* represented with infinite precision. If the quotient cannot be represented
|
|
3785
|
+
* with infinite precision, a RangeError is thrown.
|
|
3786
|
+
*
|
|
3787
|
+
* A RangeError is thrown when dividing by zero.
|
|
3788
|
+
*/
|
|
3789
|
+
div(a: BigDecimal, b: BigDecimal, e?: BigDecimalRoundingObject): BigDecimal;
|
|
3790
|
+
|
|
3791
|
+
/**
|
|
3792
|
+
* Perform the modulo operation of `a` by `b` and round the result according
|
|
3793
|
+
* to the rounding object `e`. If the rounding object is not present, the
|
|
3794
|
+
* operation is executed with infinite precision; in other words, no rounding
|
|
3795
|
+
* occurs when the rounding object is not present.
|
|
3796
|
+
*/
|
|
3797
|
+
mod(a: BigDecimal, b: BigDecimal, e?: BigDecimalRoundingObject): BigDecimal;
|
|
3798
|
+
|
|
3799
|
+
/**
|
|
3800
|
+
* Obtain the square root of `a`, rounding the result according to the
|
|
3801
|
+
* rounding object `e`.
|
|
3802
|
+
*
|
|
3803
|
+
* If `a` is less than zero, a RangeError will be thrown.
|
|
3804
|
+
*
|
|
3805
|
+
* Note that the rounding object is *required*.
|
|
3806
|
+
*/
|
|
3807
|
+
sqrt(a: BigDecimal, e: BigDecimalRoundingObject): BigDecimal;
|
|
3808
|
+
|
|
3809
|
+
/**
|
|
3810
|
+
* Rounds `a` using the rounding object `e`.
|
|
3811
|
+
*/
|
|
3812
|
+
round(a: BigDecimal, e: BigDecimalRoundingObject): BigDecimal;
|
|
3813
|
+
|
|
3814
|
+
prototype: BigDecimal;
|
|
3815
|
+
}
|
|
3816
|
+
|
|
3817
|
+
declare var BigDecimal: BigDecimalConstructor;
|
|
3818
|
+
|
|
3819
|
+
/**
|
|
3820
|
+
* The BigDecimal type represents floating point numbers in base 10.
|
|
3821
|
+
*
|
|
3822
|
+
* It is inspired from the proposal available at https://github.com/littledan/proposal-bigdecimal.
|
|
3823
|
+
*
|
|
3824
|
+
* The BigDecimal floating point numbers are always normalized and finite.
|
|
3825
|
+
* There is no concept of -0, Infinity or NaN. By default, all the computations
|
|
3826
|
+
* are done with infinite precision.
|
|
3827
|
+
*/
|
|
3828
|
+
interface BigDecimal {
|
|
3829
|
+
/**
|
|
3830
|
+
* Returns the bigdecimal primitive value corresponding to this BigDecimal.
|
|
3831
|
+
*/
|
|
3832
|
+
valueOf(): BigDecimal;
|
|
3833
|
+
|
|
3834
|
+
/**
|
|
3835
|
+
* Converts this BigDecimal to a string with infinite precision in base 10.
|
|
3836
|
+
*/
|
|
3837
|
+
toString(): string;
|
|
3838
|
+
|
|
3839
|
+
/**
|
|
3840
|
+
* Returns a string containing a number represented either in exponential or
|
|
3841
|
+
* fixed-point notation with a specified number of digits.
|
|
3842
|
+
*
|
|
3843
|
+
* @param precision Number of significant digits. There is no range limit on this number.
|
|
3844
|
+
* @param roundingMode The rounding mode to use when representing the value. Defaults to "half-up".
|
|
3845
|
+
*/
|
|
3846
|
+
toPrecision(precision: number, roundingMode?: BigDecimalRoundingMode): string;
|
|
3847
|
+
|
|
3848
|
+
/**
|
|
3849
|
+
* Returns a string representing a number in fixed-point notation.
|
|
3850
|
+
*
|
|
3851
|
+
* @param fractionDigits Number of digits after the decimal point. There is no range limit on this number.
|
|
3852
|
+
* @param roundingMode The rounding mode to use when representing the value. Defaults to "half-up".
|
|
3853
|
+
*/
|
|
3854
|
+
toFixed(
|
|
3855
|
+
fractionDigits: number,
|
|
3856
|
+
roundingMode?: BigDecimalRoundingMode
|
|
3857
|
+
): string;
|
|
3858
|
+
|
|
3859
|
+
/**
|
|
3860
|
+
* Returns a string containing a number represented in exponential notation.
|
|
3861
|
+
*
|
|
3862
|
+
* @param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.
|
|
3863
|
+
* @param roundingMode The rounding mode to use when representing the value. Defaults to "half-up".
|
|
3864
|
+
*/
|
|
3865
|
+
toExponential(
|
|
3866
|
+
fractionDigits: number,
|
|
3867
|
+
roundingMode?: BigDecimalRoundingMode
|
|
3868
|
+
): string;
|
|
3869
|
+
}
|
|
3870
|
+
|
|
3871
|
+
// Note that BigFloat and BigDecimal have custom operator overloads defined in
|
|
3872
|
+
// QuickJS, but TypeScript does not support operator overloading. As such,
|
|
3873
|
+
// TypeScript will not understand or handle unary/binary operators for BigFloat
|
|
3874
|
+
// and BigDecimal properly.
|
|
3875
|
+
|
|
2692
3876
|
// Definitions of the globals and modules added by quickjs-libc
|
|
2693
3877
|
|
|
2694
3878
|
/**
|
|
@@ -2707,7 +3891,7 @@ declare var print: (...args: Array<any>) => void;
|
|
|
2707
3891
|
/**
|
|
2708
3892
|
* Object that provides functions for logging information.
|
|
2709
3893
|
*/
|
|
2710
|
-
|
|
3894
|
+
interface Console {
|
|
2711
3895
|
/** Same as {@link print}(). */
|
|
2712
3896
|
log: typeof print;
|
|
2713
3897
|
|
|
@@ -2719,7 +3903,9 @@ declare var console: {
|
|
|
2719
3903
|
|
|
2720
3904
|
/** Same as {@link print}(). */
|
|
2721
3905
|
info: typeof print;
|
|
2722
|
-
}
|
|
3906
|
+
}
|
|
3907
|
+
|
|
3908
|
+
declare var console: Console;
|
|
2723
3909
|
|
|
2724
3910
|
/** An object representing a file handle. */
|
|
2725
3911
|
declare interface FILE {
|
|
@@ -2804,6 +3990,16 @@ declare interface FILE {
|
|
|
2804
3990
|
|
|
2805
3991
|
/** Write one byte to the file. */
|
|
2806
3992
|
putByte(value: number): void;
|
|
3993
|
+
|
|
3994
|
+
/**
|
|
3995
|
+
* Set the buffering mode and buffer size for the file stream (wrapper to the libc `setvbuf()`).
|
|
3996
|
+
*
|
|
3997
|
+
* Note that unlike the libc setvbuf, the "buffer" argument is not supported, and therefore is not present.
|
|
3998
|
+
*
|
|
3999
|
+
* @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.
|
|
4000
|
+
* @param size The size to resize the internal in-memory buffer for this file to.
|
|
4001
|
+
*/
|
|
4002
|
+
setvbuf(mode: number, size: number): void;
|
|
2807
4003
|
}
|
|
2808
4004
|
|
|
2809
4005
|
declare module "quickjs:std" {
|
|
@@ -2820,11 +4016,12 @@ declare module "quickjs:std" {
|
|
|
2820
4016
|
* @param code - The code to evaluate.
|
|
2821
4017
|
* @param options - An optional object containing the following optional properties:
|
|
2822
4018
|
* @property backtraceBarrier - Boolean (default = false). If true, error backtraces do not list the stack frames below the evalScript.
|
|
4019
|
+
* @property filename - String (default = "<evalScript>"). The filename to associate with the code being executed.
|
|
2823
4020
|
* @returns The result of the evaluation.
|
|
2824
4021
|
*/
|
|
2825
4022
|
export function evalScript(
|
|
2826
4023
|
code: string,
|
|
2827
|
-
options?: { backtraceBarrier?: boolean }
|
|
4024
|
+
options?: { backtraceBarrier?: boolean; filename?: string }
|
|
2828
4025
|
): any;
|
|
2829
4026
|
|
|
2830
4027
|
/**
|
|
@@ -2947,6 +4144,15 @@ declare module "quickjs:std" {
|
|
|
2947
4144
|
/** Constant for {@link FILE.seek}. Declares that the offset should be relative to the end of the file. See also libc `fseek()`. */
|
|
2948
4145
|
export var SEEK_END: number;
|
|
2949
4146
|
|
|
4147
|
+
/** Constant for {@link FILE.setvbuf}. Declares that the buffer mode should be 'full buffering'. */
|
|
4148
|
+
export var _IOFBF: number;
|
|
4149
|
+
|
|
4150
|
+
/** Constant for {@link FILE.setvbuf}. Declares that the buffer mode should be 'line buffering'. */
|
|
4151
|
+
export var _IOLBF: number;
|
|
4152
|
+
|
|
4153
|
+
/** Constant for {@link FILE.setvbuf}. Declares that the buffer mode should be 'no buffering'. */
|
|
4154
|
+
export var _IONBF: number;
|
|
4155
|
+
|
|
2950
4156
|
/** Manually invoke the cycle removal algorithm (garbage collector). The cycle removal algorithm is automatically started when needed, so this function is useful in case of specific memory constraints or for testing. */
|
|
2951
4157
|
export function gc(): void;
|
|
2952
4158
|
|
|
@@ -2962,6 +4168,38 @@ declare module "quickjs:std" {
|
|
|
2962
4168
|
/** Return an object containing the environment variables as key-value pairs. */
|
|
2963
4169
|
export function getenviron(): { [key: string]: string | undefined };
|
|
2964
4170
|
|
|
4171
|
+
/**
|
|
4172
|
+
* Return the real user ID of the calling process.
|
|
4173
|
+
*
|
|
4174
|
+
* This function throws an error on windows, because windows doesn't support
|
|
4175
|
+
* the same uid/gid paradigm as Unix-like operating systems.
|
|
4176
|
+
*/
|
|
4177
|
+
export function getuid(): number;
|
|
4178
|
+
|
|
4179
|
+
/**
|
|
4180
|
+
* Return the effective user ID of the calling process.
|
|
4181
|
+
*
|
|
4182
|
+
* This function throws an error on windows, because windows doesn't support
|
|
4183
|
+
* the same uid/gid paradigm as Unix-like operating systems.
|
|
4184
|
+
*/
|
|
4185
|
+
export function geteuid(): number;
|
|
4186
|
+
|
|
4187
|
+
/**
|
|
4188
|
+
* Return the real group ID of the calling process.
|
|
4189
|
+
*
|
|
4190
|
+
* This function throws an error on windows, because windows doesn't support
|
|
4191
|
+
* the same uid/gid paradigm as Unix-like operating systems.
|
|
4192
|
+
*/
|
|
4193
|
+
export function getgid(): number;
|
|
4194
|
+
|
|
4195
|
+
/**
|
|
4196
|
+
* Return the effective group ID of the calling process.
|
|
4197
|
+
*
|
|
4198
|
+
* This function throws an error on windows, because windows doesn't support
|
|
4199
|
+
* the same uid/gid paradigm as Unix-like operating systems.
|
|
4200
|
+
*/
|
|
4201
|
+
export function getegid(): number;
|
|
4202
|
+
|
|
2965
4203
|
interface UrlGet {
|
|
2966
4204
|
/**
|
|
2967
4205
|
* Download `url` using the `curl` command line utility. Returns string
|
|
@@ -3079,6 +4317,20 @@ declare module "quickjs:std" {
|
|
|
3079
4317
|
* - octal (0o prefix) and hexadecimal (0x prefix) numbers
|
|
3080
4318
|
*/
|
|
3081
4319
|
export function parseExtJSON(str: string): any;
|
|
4320
|
+
|
|
4321
|
+
/**
|
|
4322
|
+
* A wrapper around the standard C [strftime](https://en.cppreference.com/w/c/chrono/strftime).
|
|
4323
|
+
* Formats a time/date into a format as specified by the user.
|
|
4324
|
+
*
|
|
4325
|
+
* @param maxBytes - The number of bytes to allocate for the string that will be returned
|
|
4326
|
+
* @param format - Format string, using `%`-prefixed sequences as found in [this table](https://en.cppreference.com/w/c/chrono/strftime#Format_string).
|
|
4327
|
+
* @param time - The Date object (or unix timestamp, in ms) to render.
|
|
4328
|
+
*/
|
|
4329
|
+
export function strftime(
|
|
4330
|
+
maxBytes: number,
|
|
4331
|
+
format: string,
|
|
4332
|
+
time: Date | number
|
|
4333
|
+
): string;
|
|
3082
4334
|
}
|
|
3083
4335
|
|
|
3084
4336
|
declare module "quickjs:os" {
|
|
@@ -3112,8 +4364,19 @@ declare module "quickjs:os" {
|
|
|
3112
4364
|
/** POSIX open flag, used in {@link open}. */
|
|
3113
4365
|
export var O_TRUNC: number;
|
|
3114
4366
|
|
|
3115
|
-
/**
|
|
3116
|
-
|
|
4367
|
+
/**
|
|
4368
|
+
* Windows-specific open flag: open the file in binary mode (which is the default). Used in {@link open}.
|
|
4369
|
+
*
|
|
4370
|
+
* NOTE: this property is only present on windows
|
|
4371
|
+
*/
|
|
4372
|
+
export var O_BINARY: number | undefined;
|
|
4373
|
+
|
|
4374
|
+
/**
|
|
4375
|
+
* Windows-specific open flag: open the file in text mode. The default is binary mode. Used in {@link open}.
|
|
4376
|
+
*
|
|
4377
|
+
* NOTE: this property is only present on windows
|
|
4378
|
+
*/
|
|
4379
|
+
export var O_TEXT: number | undefined;
|
|
3117
4380
|
|
|
3118
4381
|
/** Close the file with descriptor `fd`. */
|
|
3119
4382
|
export function close(fd: number): void;
|
|
@@ -3227,26 +4490,167 @@ declare module "quickjs:os" {
|
|
|
3227
4490
|
*/
|
|
3228
4491
|
export function lstat(path: string): Stats;
|
|
3229
4492
|
|
|
3230
|
-
/**
|
|
4493
|
+
/**
|
|
4494
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4495
|
+
*
|
|
4496
|
+
* Mask for getting type of file from mode.
|
|
4497
|
+
*/
|
|
3231
4498
|
export var S_IFMT: number;
|
|
3232
|
-
|
|
4499
|
+
|
|
4500
|
+
/**
|
|
4501
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4502
|
+
*
|
|
4503
|
+
* File type: named pipe (fifo)
|
|
4504
|
+
*/
|
|
3233
4505
|
export var S_IFIFO: number;
|
|
3234
|
-
|
|
4506
|
+
|
|
4507
|
+
/**
|
|
4508
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4509
|
+
*
|
|
4510
|
+
* File type: character special
|
|
4511
|
+
*/
|
|
3235
4512
|
export var S_IFCHR: number;
|
|
3236
|
-
|
|
4513
|
+
|
|
4514
|
+
/**
|
|
4515
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4516
|
+
*
|
|
4517
|
+
* File type: directory
|
|
4518
|
+
*/
|
|
3237
4519
|
export var S_IFDIR: number;
|
|
3238
|
-
|
|
4520
|
+
|
|
4521
|
+
/**
|
|
4522
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4523
|
+
*
|
|
4524
|
+
* File type: block special
|
|
4525
|
+
*/
|
|
3239
4526
|
export var S_IFBLK: number;
|
|
3240
|
-
|
|
4527
|
+
|
|
4528
|
+
/**
|
|
4529
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4530
|
+
*
|
|
4531
|
+
* File type: regular
|
|
4532
|
+
*/
|
|
3241
4533
|
export var S_IFREG: number;
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
4534
|
+
|
|
4535
|
+
/**
|
|
4536
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4537
|
+
*
|
|
4538
|
+
* File type: socket
|
|
4539
|
+
*
|
|
4540
|
+
* NOTE: this property is not present on windows
|
|
4541
|
+
*/
|
|
4542
|
+
export var S_IFSOCK: number | undefined;
|
|
4543
|
+
|
|
4544
|
+
/**
|
|
4545
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4546
|
+
*
|
|
4547
|
+
* File type: symbolic link
|
|
4548
|
+
*
|
|
4549
|
+
* NOTE: this property is not present on windows
|
|
4550
|
+
*/
|
|
4551
|
+
export var S_IFLNK: number | undefined;
|
|
4552
|
+
|
|
4553
|
+
/**
|
|
4554
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4555
|
+
*
|
|
4556
|
+
* Flag: set group id on execution
|
|
4557
|
+
*
|
|
4558
|
+
* NOTE: this property is not present on windows
|
|
4559
|
+
*/
|
|
4560
|
+
export var S_ISGID: number | undefined;
|
|
4561
|
+
|
|
4562
|
+
/**
|
|
4563
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4564
|
+
*
|
|
4565
|
+
* Flag: set user id on execution
|
|
4566
|
+
*
|
|
4567
|
+
* NOTE: this property is not present on windows
|
|
4568
|
+
*/
|
|
4569
|
+
export var S_ISUID: number | undefined;
|
|
4570
|
+
|
|
4571
|
+
/**
|
|
4572
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4573
|
+
*
|
|
4574
|
+
* Mask for getting RWX permissions for owner
|
|
4575
|
+
*/
|
|
4576
|
+
export var S_IRWXU: number;
|
|
4577
|
+
|
|
4578
|
+
/**
|
|
4579
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4580
|
+
*
|
|
4581
|
+
* Permission: read for owner
|
|
4582
|
+
*/
|
|
4583
|
+
export var S_IRUSR: number;
|
|
4584
|
+
|
|
4585
|
+
/**
|
|
4586
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4587
|
+
*
|
|
4588
|
+
* Permission: write for owner
|
|
4589
|
+
*/
|
|
4590
|
+
export var S_IWUSR: number;
|
|
4591
|
+
|
|
4592
|
+
/**
|
|
4593
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4594
|
+
*
|
|
4595
|
+
* Permission: execute for owner
|
|
4596
|
+
*/
|
|
4597
|
+
export var S_IXUSR: number;
|
|
4598
|
+
|
|
4599
|
+
/**
|
|
4600
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4601
|
+
*
|
|
4602
|
+
* Mask for getting RWX permissions for group
|
|
4603
|
+
*/
|
|
4604
|
+
export var S_IRWXG: number;
|
|
4605
|
+
|
|
4606
|
+
/**
|
|
4607
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4608
|
+
*
|
|
4609
|
+
* Permission: read for group
|
|
4610
|
+
*/
|
|
4611
|
+
export var S_IRGRP: number;
|
|
4612
|
+
|
|
4613
|
+
/**
|
|
4614
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4615
|
+
*
|
|
4616
|
+
* Permission: write for group
|
|
4617
|
+
*/
|
|
4618
|
+
export var S_IWGRP: number;
|
|
4619
|
+
|
|
4620
|
+
/**
|
|
4621
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4622
|
+
*
|
|
4623
|
+
* Permission: execute for group
|
|
4624
|
+
*/
|
|
4625
|
+
export var S_IXGRP: number;
|
|
4626
|
+
|
|
4627
|
+
/**
|
|
4628
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4629
|
+
*
|
|
4630
|
+
* Mask for getting RWX permissions for others
|
|
4631
|
+
*/
|
|
4632
|
+
export var S_IRWXO: number;
|
|
4633
|
+
|
|
4634
|
+
/**
|
|
4635
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4636
|
+
*
|
|
4637
|
+
* Permission: read for others
|
|
4638
|
+
*/
|
|
4639
|
+
export var S_IROTH: number;
|
|
4640
|
+
|
|
4641
|
+
/**
|
|
4642
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4643
|
+
*
|
|
4644
|
+
* Permission: write for others
|
|
4645
|
+
*/
|
|
4646
|
+
export var S_IWOTH: number;
|
|
4647
|
+
|
|
4648
|
+
/**
|
|
4649
|
+
* Constant to interpret the `mode` property returned by `stat()`. Has the same value as in the C system header `sys/stat.h`.
|
|
4650
|
+
*
|
|
4651
|
+
* Permission: execute for others
|
|
4652
|
+
*/
|
|
4653
|
+
export var S_IXOTH: number;
|
|
3250
4654
|
|
|
3251
4655
|
/**
|
|
3252
4656
|
* Change the access and modification times of the file path.
|
|
@@ -3294,6 +4698,39 @@ declare module "quickjs:os" {
|
|
|
3294
4698
|
/** POSIX signal number. */
|
|
3295
4699
|
export var SIGTERM: number;
|
|
3296
4700
|
|
|
4701
|
+
/** POSIX signal number. NOTE: this signal is not present on windows. */
|
|
4702
|
+
export var SIGQUIT: number | undefined;
|
|
4703
|
+
|
|
4704
|
+
/** POSIX signal number. NOTE: this signal is not present on windows. */
|
|
4705
|
+
export var SIGPIPE: number | undefined;
|
|
4706
|
+
|
|
4707
|
+
/** POSIX signal number. NOTE: this signal is not present on windows. */
|
|
4708
|
+
export var SIGALRM: number | undefined;
|
|
4709
|
+
|
|
4710
|
+
/** POSIX signal number. NOTE: this signal is not present on windows. */
|
|
4711
|
+
export var SIGUSR1: number | undefined;
|
|
4712
|
+
|
|
4713
|
+
/** POSIX signal number. NOTE: this signal is not present on windows. */
|
|
4714
|
+
export var SIGUSR2: number | undefined;
|
|
4715
|
+
|
|
4716
|
+
/** POSIX signal number. NOTE: this signal is not present on windows. */
|
|
4717
|
+
export var SIGCHLD: number | undefined;
|
|
4718
|
+
|
|
4719
|
+
/** POSIX signal number. NOTE: this signal is not present on windows. */
|
|
4720
|
+
export var SIGCONT: number | undefined;
|
|
4721
|
+
|
|
4722
|
+
/** POSIX signal number. NOTE: this signal is not present on windows. */
|
|
4723
|
+
export var SIGSTOP: number | undefined;
|
|
4724
|
+
|
|
4725
|
+
/** POSIX signal number. NOTE: this signal is not present on windows. */
|
|
4726
|
+
export var SIGTSTP: number | undefined;
|
|
4727
|
+
|
|
4728
|
+
/** POSIX signal number. NOTE: this signal is not present on windows. */
|
|
4729
|
+
export var SIGTTIN: number | undefined;
|
|
4730
|
+
|
|
4731
|
+
/** POSIX signal number. NOTE: this signal is not present on windows. */
|
|
4732
|
+
export var SIGTTOU: number | undefined;
|
|
4733
|
+
|
|
3297
4734
|
/** Send the signal `sig` to the process `pid`. Use `os.SIG*` constants. */
|
|
3298
4735
|
export function kill(pid: number, sig: number): void;
|
|
3299
4736
|
|
|
@@ -3588,29 +5025,19 @@ declare interface InspectFunction {
|
|
|
3588
5025
|
declare var inspect: InspectFunction;
|
|
3589
5026
|
|
|
3590
5027
|
/**
|
|
3591
|
-
* A
|
|
3592
|
-
*
|
|
3593
|
-
* obtained from `import * as`, `import()`, `std.importModule`, or `require`.
|
|
5028
|
+
* A global which lets you configure the module loader (import/export/require).
|
|
5029
|
+
* You can use these properties to add support for importing new filetypes.
|
|
3594
5030
|
*
|
|
3595
|
-
*
|
|
3596
|
-
*
|
|
3597
|
-
* importing new filetypes.
|
|
5031
|
+
* This global can also be used to identify whether an object is a module
|
|
5032
|
+
* namespace record.
|
|
3598
5033
|
*/
|
|
3599
|
-
|
|
3600
|
-
/** A module namespace object has arbitrary exports. */
|
|
3601
|
-
[key: string | number | symbol]: any;
|
|
3602
|
-
|
|
3603
|
-
/**
|
|
3604
|
-
* Module objects are not constructable.
|
|
3605
|
-
*
|
|
3606
|
-
* You must instead obtain them using import or require.
|
|
3607
|
-
*/
|
|
3608
|
-
private constructor();
|
|
3609
|
-
|
|
5034
|
+
interface ModuleGlobal {
|
|
3610
5035
|
/**
|
|
3611
5036
|
* Returns true if `target` is a module namespace object.
|
|
3612
5037
|
*/
|
|
3613
|
-
|
|
5038
|
+
[Symbol.hasInstance](target: any): target is {
|
|
5039
|
+
[key: string | number | symbol]: any;
|
|
5040
|
+
};
|
|
3614
5041
|
|
|
3615
5042
|
/**
|
|
3616
5043
|
* A list of filetype extensions that may be omitted from an import specifier
|
|
@@ -3625,7 +5052,7 @@ declare class Module {
|
|
|
3625
5052
|
* NOTE: If you add a new extension to this array, you will likely also want
|
|
3626
5053
|
* to add to {@link Module.compilers}.
|
|
3627
5054
|
*/
|
|
3628
|
-
|
|
5055
|
+
searchExtensions: Array<string>;
|
|
3629
5056
|
|
|
3630
5057
|
/**
|
|
3631
5058
|
* User-defined functions which will handle getting the JavaScript code
|
|
@@ -3666,7 +5093,7 @@ declare class Module {
|
|
|
3666
5093
|
* NOTE: When adding to this object, you may also wish to add to
|
|
3667
5094
|
* {@link Module.searchExtensions}.
|
|
3668
5095
|
*/
|
|
3669
|
-
|
|
5096
|
+
compilers: {
|
|
3670
5097
|
[extensionWithDot: string]: (filename: string, content: string) => string;
|
|
3671
5098
|
};
|
|
3672
5099
|
|
|
@@ -3674,63 +5101,75 @@ declare class Module {
|
|
|
3674
5101
|
* Create a virtual built-in module whose exports consist of the own
|
|
3675
5102
|
* enumerable properties of `obj`.
|
|
3676
5103
|
*/
|
|
3677
|
-
|
|
5104
|
+
define(name: string, obj: { [key: string]: any }): void;
|
|
3678
5105
|
|
|
3679
5106
|
/**
|
|
3680
5107
|
* Resolves a require/import request from `fromFile` into a canonicalized path.
|
|
3681
5108
|
*
|
|
3682
5109
|
* To change native module resolution behavior, replace this function with
|
|
3683
|
-
* your own implementation.
|
|
5110
|
+
* your own implementation. Note that you must handle
|
|
5111
|
+
* `Module.searchExtensions` yourself in your replacement implementation.
|
|
3684
5112
|
*/
|
|
3685
|
-
|
|
5113
|
+
resolve(name: string, fromFile: string): string;
|
|
3686
5114
|
|
|
3687
5115
|
/**
|
|
3688
5116
|
* Reads the contents of the given resolved module name into a string.
|
|
3689
5117
|
*
|
|
3690
5118
|
* To change native module loading behavior, replace this function with your
|
|
3691
|
-
* own implementation.
|
|
5119
|
+
* own implementation. Note that you must handle `Module.compilers` yourself
|
|
5120
|
+
* in your replacement implementation.
|
|
3692
5121
|
*/
|
|
3693
|
-
|
|
5122
|
+
read(modulePath: string): string;
|
|
3694
5123
|
}
|
|
3695
5124
|
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
5125
|
+
declare var Module: ModuleGlobal;
|
|
5126
|
+
|
|
5127
|
+
interface RequireFunction {
|
|
5128
|
+
/**
|
|
5129
|
+
* Synchronously import a module.
|
|
5130
|
+
*
|
|
5131
|
+
* `source` will be resolved relative to the calling file.
|
|
5132
|
+
*
|
|
5133
|
+
* If `source` does not have a file extension, and a file without an extension
|
|
5134
|
+
* cannot be found, the engine will check for files with the extensions in
|
|
5135
|
+
* {@link Module.searchExtensions}, and use one of those if present. This
|
|
5136
|
+
* behavior also happens when using normal `import` statements.
|
|
5137
|
+
*
|
|
5138
|
+
* For example, if you write:
|
|
5139
|
+
*
|
|
5140
|
+
* ```js
|
|
5141
|
+
* import something from "./somewhere";
|
|
5142
|
+
* ```
|
|
5143
|
+
*
|
|
5144
|
+
* but there's no file named `somewhere` in the same directory as the file
|
|
5145
|
+
* where that import appears, and `Module.searchExtensions` is the default
|
|
5146
|
+
* value:
|
|
5147
|
+
*
|
|
5148
|
+
* ```js
|
|
5149
|
+
* [".js"]
|
|
5150
|
+
* ```
|
|
5151
|
+
*
|
|
5152
|
+
* then the engine will look for `somewhere.js`. If that doesn't exist, the
|
|
5153
|
+
* engine will look for `somewhere/index.js`. If *that* doesn't exist, an error
|
|
5154
|
+
* will be thrown.
|
|
5155
|
+
*
|
|
5156
|
+
* If you add more extensions to `Module.searchExtensions`, then the engine
|
|
5157
|
+
* will use those, too. It will search in the same order as the strings appear
|
|
5158
|
+
* in the `Module.searchExtensions` array.
|
|
5159
|
+
*/
|
|
5160
|
+
(source: string): any;
|
|
5161
|
+
|
|
3729
5162
|
/**
|
|
3730
5163
|
* Resolves the normalized path to a modules, relative to the calling file.
|
|
3731
5164
|
*/
|
|
3732
5165
|
resolve: (source: string) => string;
|
|
3733
|
-
}
|
|
5166
|
+
}
|
|
5167
|
+
|
|
5168
|
+
declare var require: RequireFunction;
|
|
5169
|
+
|
|
5170
|
+
interface ImportMeta {
|
|
5171
|
+
require: RequireFunction;
|
|
5172
|
+
}
|
|
3734
5173
|
|
|
3735
5174
|
declare var setTimeout: typeof import("quickjs:os").setTimeout;
|
|
3736
5175
|
declare var clearTimeout: typeof import("quickjs:os").clearTimeout;
|
|
@@ -3794,41 +5233,210 @@ interface StringConstructor {
|
|
|
3794
5233
|
};
|
|
3795
5234
|
}
|
|
3796
5235
|
|
|
3797
|
-
|
|
5236
|
+
declare module "quickjs:bytecode" {
|
|
3798
5237
|
/**
|
|
3799
|
-
* Convert the
|
|
5238
|
+
* Convert the module or script in the specified file into bytecode.
|
|
3800
5239
|
*
|
|
3801
|
-
*
|
|
3802
|
-
* be respected by the engine.
|
|
3803
|
-
*
|
|
3804
|
-
* See the abstract operation "ToPrimitive" in the ECMAScript standard for
|
|
3805
|
-
* more info.
|
|
5240
|
+
* When converted back to a value, it will be a function.
|
|
3806
5241
|
*/
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
):
|
|
5242
|
+
export function fromFile(
|
|
5243
|
+
path: string,
|
|
5244
|
+
options?: { byteSwap?: boolean; sourceType?: "module" | "script" }
|
|
5245
|
+
): ArrayBuffer;
|
|
5246
|
+
|
|
5247
|
+
/**
|
|
5248
|
+
* Convert the provided value into bytecode. Doesn't work with all values.
|
|
5249
|
+
*/
|
|
5250
|
+
export function fromValue(
|
|
5251
|
+
value: any,
|
|
5252
|
+
options?: { byteSwap?: boolean }
|
|
5253
|
+
): ArrayBuffer;
|
|
5254
|
+
|
|
5255
|
+
/**
|
|
5256
|
+
* Convert the provided bytecode into a value.
|
|
5257
|
+
*/
|
|
5258
|
+
export function toValue(bytecode: ArrayBuffer): any;
|
|
3811
5259
|
}
|
|
3812
5260
|
|
|
3813
|
-
|
|
5261
|
+
declare module "quickjs:context" {
|
|
3814
5262
|
/**
|
|
3815
|
-
* A
|
|
3816
|
-
* object. Called by the semantics of the typeof operator.
|
|
3817
|
-
*
|
|
3818
|
-
* Note that the following semantics will come into play when use of the
|
|
3819
|
-
* `typeof` operator causes the engine to call a `Symbol.typeofValue` method
|
|
3820
|
-
* on an object:
|
|
3821
|
-
*
|
|
3822
|
-
* - If the method returns any value other than one of the string values
|
|
3823
|
-
* which are normally the result of using the `typeof` operator, the engine
|
|
3824
|
-
* behaves as if no `Symbol.typeofValue` method was present on the object.
|
|
3825
|
-
* - If an error is thrown from this method, or an error is thrown while
|
|
3826
|
-
* accessing this property, the error will be silently ignored, and the
|
|
3827
|
-
* engine will behave as if no `Symbol.typeofValue` method was present on
|
|
3828
|
-
* the object.
|
|
3829
|
-
* - If this property is present on an object, but the value of that property
|
|
3830
|
-
* is not a function, the engine will not consider that value when
|
|
3831
|
-
* determining the result of the `typeof` operation (it'll ignore it).
|
|
5263
|
+
* A separate global context (or 'realm') within which code can be executed.
|
|
3832
5264
|
*/
|
|
3833
|
-
|
|
5265
|
+
export class Context {
|
|
5266
|
+
/**
|
|
5267
|
+
* Create a new global context (or 'realm') within code can be executed.
|
|
5268
|
+
*
|
|
5269
|
+
* @param options Options for what globals/modules/etc to make available within the context.
|
|
5270
|
+
*
|
|
5271
|
+
* The following globals are always present, regardless of options:
|
|
5272
|
+
*
|
|
5273
|
+
* - Object
|
|
5274
|
+
* - Function
|
|
5275
|
+
* - Error
|
|
5276
|
+
* - EvalError
|
|
5277
|
+
* - RangeError
|
|
5278
|
+
* - ReferenceError
|
|
5279
|
+
* - SyntaxError
|
|
5280
|
+
* - TypeError
|
|
5281
|
+
* - URIError
|
|
5282
|
+
* - InternalError
|
|
5283
|
+
* - AggregateError
|
|
5284
|
+
* - Array
|
|
5285
|
+
* - parseInt
|
|
5286
|
+
* - parseFloat
|
|
5287
|
+
* - isNaN
|
|
5288
|
+
* - isFinite
|
|
5289
|
+
* - decodeURI
|
|
5290
|
+
* - decodeURIComponent
|
|
5291
|
+
* - encodeURI
|
|
5292
|
+
* - encodeURIComponent
|
|
5293
|
+
* - escape
|
|
5294
|
+
* - unescape
|
|
5295
|
+
* - Infinity
|
|
5296
|
+
* - NaN
|
|
5297
|
+
* - undefined
|
|
5298
|
+
* - __date_clock
|
|
5299
|
+
* - Number
|
|
5300
|
+
* - Boolean
|
|
5301
|
+
* - String
|
|
5302
|
+
* - Math
|
|
5303
|
+
* - Reflect
|
|
5304
|
+
* - Symbol
|
|
5305
|
+
* - eval (but it doesn't work unless the `eval` option is enabled)
|
|
5306
|
+
* - globalThis
|
|
5307
|
+
*/
|
|
5308
|
+
constructor(options?: {
|
|
5309
|
+
/** Enables `Date`. Defaults to `true` */
|
|
5310
|
+
date?: boolean;
|
|
5311
|
+
|
|
5312
|
+
/** Enables `eval`. Defaults to `true` */
|
|
5313
|
+
eval?: boolean;
|
|
5314
|
+
|
|
5315
|
+
/** Enables `String.prototype.normalize`. Defaults to `true`. */
|
|
5316
|
+
stringNormalize?: boolean;
|
|
5317
|
+
|
|
5318
|
+
/** Enables `RegExp`. Defaults to `true`. */
|
|
5319
|
+
regExp?: boolean;
|
|
5320
|
+
|
|
5321
|
+
/** Enables `JSON`. Defaults to `true`. */
|
|
5322
|
+
json?: boolean;
|
|
5323
|
+
|
|
5324
|
+
/** Enables `Proxy`. Defaults to `true`. */
|
|
5325
|
+
proxy?: boolean;
|
|
5326
|
+
|
|
5327
|
+
/** Enables `Map` and `Set`. Defaults to `true`. */
|
|
5328
|
+
mapSet?: boolean;
|
|
5329
|
+
|
|
5330
|
+
/**
|
|
5331
|
+
* Enables:
|
|
5332
|
+
*
|
|
5333
|
+
* - ArrayBuffer
|
|
5334
|
+
* - SharedArrayBuffer
|
|
5335
|
+
* - Uint8ClampedArray
|
|
5336
|
+
* - Int8Array
|
|
5337
|
+
* - Uint8Array
|
|
5338
|
+
* - Int16Array
|
|
5339
|
+
* - Uint16Array
|
|
5340
|
+
* - Int32Array
|
|
5341
|
+
* - Uint32Array
|
|
5342
|
+
* - BigInt64Array
|
|
5343
|
+
* - BigUint64Array
|
|
5344
|
+
* - Float32Array
|
|
5345
|
+
* - Float64Array
|
|
5346
|
+
* - DataView
|
|
5347
|
+
*
|
|
5348
|
+
* Defaults to `true`.
|
|
5349
|
+
*/
|
|
5350
|
+
typedArrays?: boolean;
|
|
5351
|
+
|
|
5352
|
+
/**
|
|
5353
|
+
* Enables:
|
|
5354
|
+
*
|
|
5355
|
+
* - Promise
|
|
5356
|
+
* - async functions
|
|
5357
|
+
* - async iterators
|
|
5358
|
+
* - async generators
|
|
5359
|
+
*
|
|
5360
|
+
* Defaults to `true`.
|
|
5361
|
+
*/
|
|
5362
|
+
promise?: boolean;
|
|
5363
|
+
|
|
5364
|
+
/** Enables `BigInt`. Defaults to `true`. */
|
|
5365
|
+
bigint?: boolean;
|
|
5366
|
+
|
|
5367
|
+
/** Enables `BigFloat`. Defaults to `true`. */
|
|
5368
|
+
bigfloat?: boolean;
|
|
5369
|
+
|
|
5370
|
+
/** Enables `BigDecimal`. Defaults to `true`. */
|
|
5371
|
+
bigdecimal?: boolean;
|
|
5372
|
+
|
|
5373
|
+
/**
|
|
5374
|
+
* Enables:
|
|
5375
|
+
*
|
|
5376
|
+
* - Operators
|
|
5377
|
+
* - OperatorSet creation
|
|
5378
|
+
* - operator overloading
|
|
5379
|
+
*
|
|
5380
|
+
* Defaults to `true`.
|
|
5381
|
+
*/
|
|
5382
|
+
operators?: boolean;
|
|
5383
|
+
|
|
5384
|
+
/** Enables "use math". Defaults to `true`. */
|
|
5385
|
+
useMath?: boolean;
|
|
5386
|
+
|
|
5387
|
+
/**
|
|
5388
|
+
* Enables:
|
|
5389
|
+
*
|
|
5390
|
+
* - inspect
|
|
5391
|
+
* - console
|
|
5392
|
+
* - print
|
|
5393
|
+
* - require (and require.resolve)
|
|
5394
|
+
* - setTimeout
|
|
5395
|
+
* - clearTimeout
|
|
5396
|
+
* - setInterval
|
|
5397
|
+
* - clearInterval
|
|
5398
|
+
* - String.cooked
|
|
5399
|
+
* - String.dedent
|
|
5400
|
+
*
|
|
5401
|
+
* Defaults to `true`.
|
|
5402
|
+
*
|
|
5403
|
+
* NOTE: The following globals, normally part of `js_std_add_helpers`, are NEVER added:
|
|
5404
|
+
*
|
|
5405
|
+
* - Module
|
|
5406
|
+
* - scriptArgs
|
|
5407
|
+
*
|
|
5408
|
+
* If you need them in the new context, copy them over from your context's globalThis onto the child context's globalThis.
|
|
5409
|
+
*/
|
|
5410
|
+
stdHelpers?: boolean;
|
|
5411
|
+
|
|
5412
|
+
/** Enable builtin modules. */
|
|
5413
|
+
modules?: {
|
|
5414
|
+
/** Enables the "quickjs:std" module. Defaults to `true`. */
|
|
5415
|
+
"quickjs:std"?: boolean;
|
|
5416
|
+
/** Enables the "quickjs:os" module. Defaults to `true`. */
|
|
5417
|
+
"quickjs:os"?: boolean;
|
|
5418
|
+
/** Enables the "quickjs:bytecode" module. Defaults to `true`. */
|
|
5419
|
+
"quickjs:bytecode"?: boolean;
|
|
5420
|
+
/** Enables the "quickjs:context" module. Defaults to `true`. */
|
|
5421
|
+
"quickjs:context"?: boolean;
|
|
5422
|
+
};
|
|
5423
|
+
});
|
|
5424
|
+
|
|
5425
|
+
/**
|
|
5426
|
+
* The `globalThis` object used by this context.
|
|
5427
|
+
*
|
|
5428
|
+
* You can add to or remove from it to change what is visible to the context.
|
|
5429
|
+
*/
|
|
5430
|
+
globalThis: typeof globalThis;
|
|
5431
|
+
|
|
5432
|
+
/**
|
|
5433
|
+
* Runs code within the context and returns the result.
|
|
5434
|
+
*
|
|
5435
|
+
* @param code The code to run.
|
|
5436
|
+
*/
|
|
5437
|
+
eval(code: string): any;
|
|
5438
|
+
}
|
|
3834
5439
|
}
|
|
5440
|
+
|
|
5441
|
+
declare const std: typeof import("quickjs:std");
|
|
5442
|
+
declare const os: typeof import("quickjs:os");
|