yavascript 0.0.12 → 0.0.13
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 +124 -58
- package/bin/aarch64-apple-darwin/yavascript +0 -0
- package/bin/aarch64-unknown-linux-gnu/yavascript +0 -0
- package/bin/aarch64-unknown-linux-musl/yavascript +0 -0
- package/bin/aarch64-unknown-linux-static/yavascript +0 -0
- package/bin/x86_64-apple-darwin/yavascript +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-musl/yavascript +0 -0
- package/bin/x86_64-unknown-linux-static/yavascript +0 -0
- package/dist/index-arm64.js +7527 -6867
- package/dist/index-x86_64.js +7527 -6867
- package/dist/primordials-arm64.js +7816 -7159
- package/dist/primordials-x86_64.js +7816 -7159
- package/package.json +1 -1
- package/yavascript.d.ts +1820 -665
package/yavascript.d.ts
CHANGED
|
@@ -4,47 +4,19 @@
|
|
|
4
4
|
// ---------------
|
|
5
5
|
// ===============
|
|
6
6
|
/**
|
|
7
|
-
* Prints
|
|
7
|
+
* Prints a link to the YavaScript help docs for the currently-running version
|
|
8
|
+
* of YavaScript.
|
|
9
|
+
*
|
|
10
|
+
* For the latest help docs, see:
|
|
11
|
+
* https://github.com/suchipi/yavascript/blob/main/meta/generated-docs/README.md
|
|
8
12
|
*/
|
|
9
|
-
declare
|
|
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
|
-
* To set help text for the values `null` or `undefined`, `allowNullish`
|
|
29
|
-
* must be `true`.
|
|
30
|
-
*/
|
|
31
|
-
(value: object, text: string, allowNullish?: boolean): void;
|
|
13
|
+
declare function help(): void;
|
|
32
14
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* function will be called, and its result will be registered as the help
|
|
39
|
-
* text for the value. Afterwards, the function will not be called again;
|
|
40
|
-
* instead, it will re-use the text returned from the first time the
|
|
41
|
-
* function was called.
|
|
42
|
-
*/
|
|
43
|
-
lazy(value: object, getText: () => string): void;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/** Info about the currently-running yavascript binary */
|
|
15
|
+
/**
|
|
16
|
+
* The `yavascript` global contains metadata about the currently-running
|
|
17
|
+
* yavascript binary, as well as access to yavascript's compilers for
|
|
18
|
+
* compile-to-js languages.
|
|
19
|
+
*/
|
|
48
20
|
declare const yavascript: {
|
|
49
21
|
/**
|
|
50
22
|
* The version of the currently-running yavascript binary.
|
|
@@ -65,48 +37,107 @@ declare const yavascript: {
|
|
|
65
37
|
*/
|
|
66
38
|
version: string;
|
|
67
39
|
|
|
68
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* The processor architecture of the currently-running `yavascript` binary.
|
|
42
|
+
*/
|
|
69
43
|
arch: "x86_64" | "arm64";
|
|
70
44
|
|
|
71
45
|
/**
|
|
72
|
-
* The version of the ecma262 standard supported by the currently-running
|
|
46
|
+
* The version of the ecma262 standard supported by the currently-running
|
|
47
|
+
* yavascript binary.
|
|
73
48
|
*
|
|
74
|
-
*
|
|
49
|
+
* Currently, this is always "ES2020", but if future versions of yavascript
|
|
50
|
+
* support a newer version of the standard, this will change. In that event,
|
|
51
|
+
* this property will always be in the format of "ES" + a year, and will never
|
|
52
|
+
* be lower than ES2020.
|
|
75
53
|
*/
|
|
76
54
|
ecmaVersion: string;
|
|
77
55
|
|
|
78
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* The compilers yavascript uses internally to load files.
|
|
58
|
+
*
|
|
59
|
+
* Each function returns a JavaScript source code string.
|
|
60
|
+
*/
|
|
79
61
|
compilers: {
|
|
62
|
+
/**
|
|
63
|
+
* The function yavascript uses internally to load JavaScript files.
|
|
64
|
+
*
|
|
65
|
+
* You might think this would be a no-op, but we do some CommonJS/ECMAScript
|
|
66
|
+
* Module interop transformations here.
|
|
67
|
+
*/
|
|
80
68
|
js(
|
|
81
69
|
code: string,
|
|
82
70
|
options?: { filename?: string; expression?: boolean }
|
|
83
71
|
): string;
|
|
84
72
|
|
|
73
|
+
/**
|
|
74
|
+
* The function yavascript uses internally to load [TypeScript JSX](https://www.typescriptlang.org/docs/handbook/jsx.html) files.
|
|
75
|
+
*
|
|
76
|
+
* yavascript uses [Sucrase 3.35.0](https://sucrase.io/) to load TypeScript JSX syntax. yavascript doesn't do typechecking of TypeScript syntax.
|
|
77
|
+
*/
|
|
85
78
|
tsx(
|
|
86
79
|
code: string,
|
|
87
80
|
options?: { filename?: string; expression?: boolean }
|
|
88
81
|
): string;
|
|
89
82
|
|
|
83
|
+
/**
|
|
84
|
+
* The function yavascript uses internally to load [TypeScript](https://www.typescriptlang.org/) files.
|
|
85
|
+
*
|
|
86
|
+
* yavascript uses [Sucrase 3.35.0](https://sucrase.io/) to load TypeScript syntax. yavascript doesn't do typechecking of TypeScript syntax.
|
|
87
|
+
*/
|
|
90
88
|
ts(
|
|
91
89
|
code: string,
|
|
92
90
|
options?: { filename?: string; expression?: boolean }
|
|
93
91
|
): string;
|
|
94
92
|
|
|
93
|
+
/**
|
|
94
|
+
* The function yavascript uses internally to load JSX files.
|
|
95
|
+
*
|
|
96
|
+
* yavascript uses [Sucrase 3.35.0](https://sucrase.io/) to load JSX syntax.
|
|
97
|
+
*
|
|
98
|
+
* See {@link JSX} for info about configuring JSX pragma, swapping out the
|
|
99
|
+
* default `createElement` implementation, etc.
|
|
100
|
+
*/
|
|
95
101
|
jsx(
|
|
96
102
|
code: string,
|
|
97
103
|
options?: { filename?: string; expression?: boolean }
|
|
98
104
|
): string;
|
|
99
105
|
|
|
106
|
+
/**
|
|
107
|
+
* The function yavascript uses internally to load [CoffeeScript](https://coffeescript.org/) files.
|
|
108
|
+
*
|
|
109
|
+
* yavascript embeds CoffeeScript 2.7.0.
|
|
110
|
+
*/
|
|
100
111
|
coffee(
|
|
101
112
|
code: string,
|
|
102
113
|
options?: { filename?: string; expression?: boolean }
|
|
103
114
|
): string;
|
|
104
115
|
|
|
116
|
+
/**
|
|
117
|
+
* The function yavascript uses internally to load [Civet](https://civet.dev/) files.
|
|
118
|
+
*
|
|
119
|
+
* yavascript embeds Civet 0.9.0.
|
|
120
|
+
*/
|
|
105
121
|
civet(
|
|
106
122
|
code: string,
|
|
107
123
|
options?: { filename?: string; expression?: boolean }
|
|
108
124
|
): string;
|
|
109
125
|
|
|
126
|
+
/**
|
|
127
|
+
* The function yavascript uses internally to load files which don't have an
|
|
128
|
+
* extension.
|
|
129
|
+
*
|
|
130
|
+
* It tries to parse the file as each of the following languages, in order,
|
|
131
|
+
* until it finds one which doesn't have a syntax error:
|
|
132
|
+
*
|
|
133
|
+
* - JSX
|
|
134
|
+
* - TSX
|
|
135
|
+
* - Civet
|
|
136
|
+
* - CoffeeScript
|
|
137
|
+
*
|
|
138
|
+
* If none of the languages work, the file's original content gets used so
|
|
139
|
+
* that a syntax error can be reported to the user.
|
|
140
|
+
*/
|
|
110
141
|
autodetect(
|
|
111
142
|
code: string,
|
|
112
143
|
options?: { filename?: string; expression?: boolean }
|
|
@@ -123,9 +154,9 @@ declare const yavascript: {
|
|
|
123
154
|
declare const env: { [key: string]: string | undefined };
|
|
124
155
|
|
|
125
156
|
/**
|
|
126
|
-
*
|
|
127
|
-
* positional arguments. This function is opinionated; if it doesn't
|
|
128
|
-
* needs, you can parse the
|
|
157
|
+
* A function which parses command line `--flags` into an object of flags and an
|
|
158
|
+
* array of positional arguments. This function is opinionated; if it doesn't
|
|
159
|
+
* meet your needs, you can parse the {@link scriptArgs} global manually.
|
|
129
160
|
*
|
|
130
161
|
* Flags `--like-this`, `--like_this`, or `--LIKE_THIS` get converted into
|
|
131
162
|
* property names `likeThis` on the returned flags object.
|
|
@@ -136,34 +167,145 @@ declare const env: { [key: string]: string | undefined };
|
|
|
136
167
|
* Anything that appears after `--` is considered a positional argument instead
|
|
137
168
|
* of a flag. `--` is not present in the returned positional arguments Array.
|
|
138
169
|
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
170
|
+
* `parseScriptArgs` accepts two optional parameters: `hints` and `argv`.
|
|
171
|
+
*
|
|
172
|
+
* ## hints
|
|
173
|
+
*
|
|
174
|
+
* If present, `hints` should be an object whose keys are flag names (in
|
|
175
|
+
* lowerCamelCase) and whose values indicate what type to treat that flag as.
|
|
176
|
+
* Valid property values are `String`, `Boolean`, `Number`, and `Path`. `Path`
|
|
177
|
+
* will resolve relative paths into absolute paths for you. If no hints object
|
|
178
|
+
* is specified, `parseScriptArgs` will do its best to guess the types.
|
|
179
|
+
*
|
|
180
|
+
* ## argv
|
|
181
|
+
*
|
|
182
|
+
* The `argv` parameter, if present, should be an array containing the command
|
|
183
|
+
* line flags you want to parse. If you don't provide one, `scriptArgs.slice(2)`
|
|
184
|
+
* will be used (we slice 2 in order to skip the yavascript binary and script
|
|
185
|
+
* name). If you pass in an array here, it should only contain command-line
|
|
186
|
+
* flags, not the binary being called.
|
|
187
|
+
*
|
|
188
|
+
* ## Return Value
|
|
189
|
+
*
|
|
190
|
+
* `parseScriptArgs` returns an object with three properties: `flags`, `args`,
|
|
191
|
+
* and `metadata`.
|
|
141
192
|
*
|
|
142
|
-
*
|
|
193
|
+
* - `flags` is an object whose keys are lowerCamelCase flag names and whose
|
|
194
|
+
* values are strings, booleans, numbers, or `Path`s corresponding to the
|
|
195
|
+
* input command-line args.
|
|
196
|
+
* - `args` is an Array of positional arguments, as found on the command-line.
|
|
197
|
+
* - `metadata` contains information about what name and type the flags got
|
|
198
|
+
* mapped to.
|
|
199
|
+
*
|
|
200
|
+
* @param hints - An object whose keys are flag names (in lowerCamelCase) and
|
|
201
|
+
* whose values indicate what type to treat that flag as. Valid property values
|
|
202
|
+
* are `String`, `Boolean`, `Number`, and `Path`. `Path` will resolve relative
|
|
203
|
+
* paths into absolute paths for you. If no hints object is specified,
|
|
204
|
+
* `parseScriptArgs` will do its best to guess, based on the command-line args.
|
|
205
|
+
* @param argv - An array containing the command line flags you want to parse.
|
|
206
|
+
* If unspecified, `scriptArgs.slice(2)` will be used (we slice 2 in order to
|
|
207
|
+
* skip the yavascript binary and script name). If you pass in an array here, it
|
|
208
|
+
* should only contain command-line flags, not the binary being called.
|
|
209
|
+
*
|
|
210
|
+
* @returns A {@link ParseScriptArgsResult}, which is an object with three
|
|
211
|
+
* properties: `flags`, `args`, and `metadata`. `flags` is an object whose keys
|
|
212
|
+
* are camelCase flag names and whose values are strings, booleans, numbers, or
|
|
213
|
+
* `Path`s corresponding to the input command-line args. `args` is an Array of
|
|
214
|
+
* positional arguments, as found on the command-line. `metadata` contains
|
|
215
|
+
* information about what name and type the flags got mapped to.
|
|
143
216
|
*/
|
|
144
217
|
declare function parseScriptArgs(
|
|
145
218
|
hints?: {
|
|
146
219
|
[key: string]: typeof String | typeof Boolean | typeof Number | typeof Path;
|
|
147
220
|
},
|
|
148
221
|
args?: Array<string>
|
|
149
|
-
):
|
|
222
|
+
): ParseScriptArgsResult;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* The return type of {@link parseScriptArgs}.
|
|
226
|
+
*
|
|
227
|
+
* The `flags` property contains the values for any command-line `--flags`, with
|
|
228
|
+
* key names converted to `lowerCamelCase`.
|
|
229
|
+
*
|
|
230
|
+
* The `args` property contains an array of those command-line arguments which
|
|
231
|
+
* weren't associated with a flag.
|
|
232
|
+
*
|
|
233
|
+
* The `metadata` property contains information about the parsing process,
|
|
234
|
+
* including what case changes were applied to the keys, which hints were used,
|
|
235
|
+
* and which properties had their type guessed because no corresponding hint was
|
|
236
|
+
* available.
|
|
237
|
+
*/
|
|
238
|
+
declare interface ParseScriptArgsResult {
|
|
239
|
+
/**
|
|
240
|
+
* The values for any command-line `--flags`, with key names converted to `lowerCamelCase`.
|
|
241
|
+
*/
|
|
150
242
|
flags: { [key: string]: any };
|
|
243
|
+
/**
|
|
244
|
+
* An array of those command-line arguments which weren't associated with a flag.
|
|
245
|
+
*/
|
|
151
246
|
args: Array<string>;
|
|
247
|
+
/**
|
|
248
|
+
* Information about the parsing process, including what case changes were
|
|
249
|
+
* applied to the keys, which hints were used, and which properties had their
|
|
250
|
+
* type guessed because no corresponding hint was available.
|
|
251
|
+
*/
|
|
152
252
|
metadata: {
|
|
253
|
+
/**
|
|
254
|
+
* An object whose keys are the verbatim flags from the command-line, and
|
|
255
|
+
* whose values are the lowerCamelCase names they were converted to in the
|
|
256
|
+
* `flags` property of the {@link ParseScriptArgsResult}.
|
|
257
|
+
*/
|
|
153
258
|
keys: {
|
|
154
259
|
[key: string]: string | undefined;
|
|
155
260
|
};
|
|
261
|
+
/**
|
|
262
|
+
* An object whose keys are the lowerCamelCase flag names, and whose values
|
|
263
|
+
* are strings indicating the hint values that were specified for those
|
|
264
|
+
* flags.
|
|
265
|
+
*/
|
|
156
266
|
hints: {
|
|
157
|
-
[key: string]: string | undefined;
|
|
267
|
+
[key: string]: "path" | "number" | "boolean" | "string" | undefined;
|
|
158
268
|
};
|
|
269
|
+
/**
|
|
270
|
+
* An object indicating which flags we inferred the type of, because no
|
|
271
|
+
* corresponding hint was present.
|
|
272
|
+
*
|
|
273
|
+
* The keys are the lowerCamelCase flag names, and the values are strings
|
|
274
|
+
* indicating what type we guessed for that flag.
|
|
275
|
+
*
|
|
276
|
+
* If you're seeing incorrect inference, consider passing a `hints` argument
|
|
277
|
+
* to {@link parseScriptArgs}.
|
|
278
|
+
*/
|
|
159
279
|
guesses: {
|
|
160
|
-
[key: string]: string | undefined;
|
|
280
|
+
[key: string]: "number" | "boolean" | "string" | undefined;
|
|
161
281
|
};
|
|
162
282
|
};
|
|
163
|
-
}
|
|
283
|
+
}
|
|
164
284
|
|
|
165
285
|
/**
|
|
166
286
|
* Read the contents of a file from disk.
|
|
287
|
+
*
|
|
288
|
+
* With no options specified, it reads the file as UTF-8 and returns a string:
|
|
289
|
+
*
|
|
290
|
+
* ```ts
|
|
291
|
+
* const contents = readFile("README.md");
|
|
292
|
+
* console.log(contents);
|
|
293
|
+
* // "# yavascript\n\nYavaScript is a cross-platform bash-like script runner and repl which is distributed as a single\nstatically-linked binary..."
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* But, if you pass `{ binary: true }` as the second argument, it returns an
|
|
297
|
+
* ArrayBuffer containing the raw bytes from the file:
|
|
298
|
+
*
|
|
299
|
+
* ```ts
|
|
300
|
+
* const contents = readFile("README.md", { binary: true });
|
|
301
|
+
* console.log(contents);
|
|
302
|
+
* // ArrayBuffer {
|
|
303
|
+
* // │0x00000000│ 23 20 79 61 76 61 73 63 72 69 70 74 0A 0A 59 61
|
|
304
|
+
* // │0x00000010│ 76 61 53 63 72 69 70 74 20 69 73 20 61 20 63 72
|
|
305
|
+
* // │0x00000020│ 6F 73 73 2D 70 6C 61 74 66 6F 72 6D 20 62 61 73
|
|
306
|
+
* // │0x00000030│ 68 2D 6C 69 6B 65 20 73 63 72 69 70 74 20 72 75
|
|
307
|
+
* // ...
|
|
308
|
+
* ```
|
|
167
309
|
*/
|
|
168
310
|
declare const readFile: {
|
|
169
311
|
/**
|
|
@@ -252,6 +394,18 @@ declare function remove(path: string | Path): void;
|
|
|
252
394
|
*/
|
|
253
395
|
declare function exists(path: string | Path): boolean;
|
|
254
396
|
|
|
397
|
+
/**
|
|
398
|
+
* Copies a file or folder from one location to another.
|
|
399
|
+
* Folders are copied recursively.
|
|
400
|
+
*
|
|
401
|
+
* Provides the same functionality as the command `cp -R`.
|
|
402
|
+
*/
|
|
403
|
+
declare function copy(
|
|
404
|
+
from: string | Path,
|
|
405
|
+
to: string | Path,
|
|
406
|
+
options?: CopyOptions
|
|
407
|
+
): void;
|
|
408
|
+
|
|
255
409
|
/**
|
|
256
410
|
* Options for {@link copy}.
|
|
257
411
|
*/
|
|
@@ -294,18 +448,6 @@ declare type CopyOptions = {
|
|
|
294
448
|
};
|
|
295
449
|
};
|
|
296
450
|
|
|
297
|
-
/**
|
|
298
|
-
* Copies a file or folder from one location to another.
|
|
299
|
-
* Folders are copied recursively.
|
|
300
|
-
*
|
|
301
|
-
* Provides the same functionality as the command `cp -R`.
|
|
302
|
-
*/
|
|
303
|
-
declare function copy(
|
|
304
|
-
from: string | Path,
|
|
305
|
-
to: string | Path,
|
|
306
|
-
options?: CopyOptions
|
|
307
|
-
): void;
|
|
308
|
-
|
|
309
451
|
/**
|
|
310
452
|
* Rename the file or directory at the specified path.
|
|
311
453
|
*
|
|
@@ -313,32 +455,93 @@ declare function copy(
|
|
|
313
455
|
*/
|
|
314
456
|
declare function rename(from: string | Path, to: string | Path): void;
|
|
315
457
|
|
|
316
|
-
/**
|
|
458
|
+
/**
|
|
459
|
+
* A class which represents a filesystem path. The class contains various
|
|
460
|
+
* methods that make it easy to work with filesystem paths; there are methods
|
|
461
|
+
* for adding/removing path components, converting between absolute and relative
|
|
462
|
+
* paths, getting the basename and dirname, and more.
|
|
463
|
+
*
|
|
464
|
+
* All functions in yavascript which accept path strings as arguments also
|
|
465
|
+
* accept Path objects. As such, it is recommended that all filesystem paths in
|
|
466
|
+
* your programs are Path objects rather than strings.
|
|
467
|
+
*
|
|
468
|
+
* Every Path object has two properties: `segments` and `separator`. `segments`
|
|
469
|
+
* is an Array of strings containing all the non-slash portions of the path. For
|
|
470
|
+
* example, the path "one/two/three" would have segments `["one", "two",
|
|
471
|
+
* "three"]`. `separator` is which slash is used to separate the segments;
|
|
472
|
+
* either `"/"` or `"\"`.
|
|
473
|
+
*
|
|
474
|
+
* A Path object can represent either a POSIX-style path or a win32-style path.
|
|
475
|
+
* For the win32 style, UNC paths are supported. POSIX-style paths starting with
|
|
476
|
+
* "/" (eg. "/usr/bin") have an empty string at the beginning of their segments
|
|
477
|
+
* array to represent the left-hand-side of the leading slash. For instance,
|
|
478
|
+
* "/usr/bin" would have segments `["", "usr", "bin"]`.
|
|
479
|
+
*/
|
|
317
480
|
declare class Path {
|
|
318
|
-
/**
|
|
481
|
+
/**
|
|
482
|
+
* The character used to separate path segments on the current operating
|
|
483
|
+
* system where yavascript is running.
|
|
484
|
+
*
|
|
485
|
+
* Its value is either a forward slash (`"/"`) or a backslash (`"\"`). Its value
|
|
486
|
+
* is a backslash on windows, and a forward slash on all other operating
|
|
487
|
+
* systems.
|
|
488
|
+
*/
|
|
319
489
|
static readonly OS_SEGMENT_SEPARATOR: "/" | "\\";
|
|
320
490
|
|
|
321
491
|
/**
|
|
322
|
-
* The character used to separate entries within the PATH
|
|
323
|
-
* variable on
|
|
492
|
+
* The character used to separate entries within the system's `PATH`
|
|
493
|
+
* environment variable on the current operating system where yavascript is
|
|
494
|
+
* running.
|
|
495
|
+
*
|
|
496
|
+
* The `PATH` environment variable contains a list of folders wherein
|
|
497
|
+
* command-line programs can be found, separated by either a colon (`:`) or a
|
|
498
|
+
* semicolon (`;`). The value of `OS_ENV_VAR_SEPARATOR` is a semicolon on
|
|
499
|
+
* windows, and a colon on all other operating systems.
|
|
500
|
+
*
|
|
501
|
+
* The `PATH` environment variable can be accessed by yavascript programs via
|
|
502
|
+
* `env.PATH`. Therefore, one can contain a list of all entries in the `PATH`
|
|
503
|
+
* environment variable via:
|
|
504
|
+
*
|
|
505
|
+
* ```ts
|
|
506
|
+
* const folders: Array<string> = env.PATH.split(Path.OS_ENV_VAR_SEPARATOR);
|
|
507
|
+
* ```
|
|
324
508
|
*/
|
|
325
509
|
static readonly OS_ENV_VAR_SEPARATOR: ":" | ";";
|
|
326
510
|
|
|
327
511
|
/**
|
|
328
|
-
* A
|
|
329
|
-
*
|
|
512
|
+
* A Set of filename extension strings that command-line programs may end with
|
|
513
|
+
* on the current operating system where yavascript is running. For instance,
|
|
514
|
+
* on Windows, programs often end with ".exe". Each of these strings contains
|
|
515
|
+
* a leading dot (`.`).
|
|
516
|
+
*
|
|
517
|
+
* On windows, this value is based on the `PATHEXT` environment variable,
|
|
518
|
+
* which defaults to ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
|
|
519
|
+
* on Windows Vista and up. If `PATHEXT` is not defined, that default value is
|
|
520
|
+
* used.
|
|
330
521
|
*
|
|
331
|
-
* On
|
|
522
|
+
* On all other operating systems, this Set is empty.
|
|
332
523
|
*/
|
|
333
524
|
static readonly OS_PROGRAM_EXTENSIONS: ReadonlySet<string>;
|
|
334
525
|
|
|
335
|
-
/**
|
|
526
|
+
/**
|
|
527
|
+
* Converts a string (or array of strings) into an array of path segment
|
|
528
|
+
* strings (the parts between the slashes).
|
|
529
|
+
*
|
|
530
|
+
* Example:
|
|
531
|
+
*
|
|
532
|
+
* ```ts
|
|
533
|
+
* const input = ["hi", "there/every/one", "yeah\\yup"];
|
|
534
|
+
* const result = Path.splitToSegments(input);
|
|
535
|
+
* // result is ["hi", "there", "every", "one", "yeah", "yup"]
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
336
538
|
static splitToSegments(inputParts: Array<string> | string): Array<string>;
|
|
337
539
|
|
|
338
540
|
/**
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
541
|
+
* Searches the provided path string or strings for a path separator character
|
|
542
|
+
* (either forward slash or backslash), and returns the one it finds. If
|
|
543
|
+
* neither is found, it returns the `fallback` arg, which defaults to the
|
|
544
|
+
* current OS's path segment separator (`Path.OS_SEGMENT_SEPARATOR`).
|
|
342
545
|
*/
|
|
343
546
|
static detectSeparator<Fallback extends string | null = string>(
|
|
344
547
|
input: Array<string> | string,
|
|
@@ -347,19 +550,45 @@ declare class Path {
|
|
|
347
550
|
): string | Fallback;
|
|
348
551
|
|
|
349
552
|
/**
|
|
350
|
-
*
|
|
351
|
-
* `..` segments.
|
|
553
|
+
* Creates a new Path by concatenating the input path(s) and then resolving all
|
|
554
|
+
* non-leading `.` and `..` segments. In other words:
|
|
555
|
+
*
|
|
556
|
+
* - Segments containing `.` are removed
|
|
557
|
+
* - Segments containing `..` are removed, along with the segment preceding
|
|
558
|
+
* them.
|
|
559
|
+
*
|
|
560
|
+
* Note that any `.` or `..` segments at the beginning of the path (ie.
|
|
561
|
+
* "leading segments") are not removed.
|
|
352
562
|
*/
|
|
353
563
|
static normalize(
|
|
354
564
|
...inputs: Array<string | Path | Array<string | Path>>
|
|
355
565
|
): Path;
|
|
356
566
|
|
|
357
567
|
/**
|
|
358
|
-
*
|
|
359
|
-
* starts with either `/` or a drive letter
|
|
568
|
+
* Returns a boolean indicating whether the provided path is absolute; that
|
|
569
|
+
* is, whether it starts with either a slash (`/` or `\`) or a drive letter
|
|
570
|
+
* (ie `C:`).
|
|
571
|
+
*
|
|
572
|
+
* Note that Windows UNC Paths (eg. `\\MYSERVER\share$\`) are considered
|
|
573
|
+
* absolute.
|
|
360
574
|
*/
|
|
361
575
|
static isAbsolute(path: string | Path): boolean;
|
|
362
576
|
|
|
577
|
+
/**
|
|
578
|
+
* Creates a new Path containing the user-provided segments and separator. In
|
|
579
|
+
* most cases, you won't need to do this, and can use `new Path(...)` instead.
|
|
580
|
+
*
|
|
581
|
+
* If unspecified, the `separator` parameter defaults to
|
|
582
|
+
* `Path.OS_SEGMENT_SEPARATOR`.
|
|
583
|
+
*/
|
|
584
|
+
static fromRaw(segments: Array<string>, separator?: string): Path;
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Creates a new Path object using the provided input(s), which will be
|
|
588
|
+
* concatenated together in order left-to-right.
|
|
589
|
+
*/
|
|
590
|
+
constructor(...inputs: Array<string | Path | Array<string | Path>>);
|
|
591
|
+
|
|
363
592
|
/**
|
|
364
593
|
* An array of the path segments that make up this path.
|
|
365
594
|
*
|
|
@@ -372,96 +601,95 @@ declare class Path {
|
|
|
372
601
|
/**
|
|
373
602
|
* The path separator that should be used to turn this path into a string.
|
|
374
603
|
*
|
|
375
|
-
* Will be either
|
|
604
|
+
* Will be either `"/"` or `"\"`.
|
|
376
605
|
*/
|
|
377
606
|
separator: string;
|
|
378
607
|
|
|
379
|
-
/** Create a new Path object using the provided input(s). */
|
|
380
|
-
constructor(...inputs: Array<string | Path | Array<string | Path>>);
|
|
381
|
-
|
|
382
608
|
/**
|
|
383
|
-
*
|
|
609
|
+
* Creates a new Path by resolving all non-leading `.` and `..` segments in
|
|
610
|
+
* the target Path. In other words:
|
|
384
611
|
*
|
|
385
|
-
*
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
*
|
|
612
|
+
* - Segments containing `.` are removed
|
|
613
|
+
* - Segments containing `..` are removed, along with the segment preceding
|
|
614
|
+
* them.
|
|
615
|
+
*
|
|
616
|
+
* Note that any `.` or `..` segments at the beginning of the path (ie.
|
|
617
|
+
* "leading segments") are not removed.
|
|
391
618
|
*/
|
|
392
619
|
normalize(): Path;
|
|
393
620
|
|
|
394
621
|
/**
|
|
395
|
-
*
|
|
396
|
-
*
|
|
622
|
+
* Creates a new Path by appending additional path segments onto the end of
|
|
623
|
+
* the target Path's segments.
|
|
397
624
|
*
|
|
398
|
-
* The returned
|
|
625
|
+
* The returned Path will use the same separator as the target Path.
|
|
399
626
|
*/
|
|
400
627
|
concat(...other: Array<string | Path | Array<string | Path>>): Path;
|
|
401
628
|
|
|
402
629
|
/**
|
|
403
|
-
*
|
|
404
|
-
* either
|
|
630
|
+
* Returns a boolean indicating whether the target Path is absolute; that
|
|
631
|
+
* is, whether it starts with either a slash (`/` or `\`) or a drive letter
|
|
632
|
+
* (ie `C:`).
|
|
633
|
+
*
|
|
634
|
+
* Note that Windows UNC Paths (eg. `\\MYSERVER\share$\`) are considered
|
|
635
|
+
* absolute.
|
|
405
636
|
*/
|
|
406
637
|
isAbsolute(): boolean;
|
|
407
638
|
|
|
408
639
|
/**
|
|
409
|
-
*
|
|
410
|
-
*
|
|
640
|
+
* Creates a new Path object containing the same segments and separator as
|
|
641
|
+
* the target Path.
|
|
642
|
+
*
|
|
643
|
+
* Note that although it contains the same segments, the new Path does not use
|
|
644
|
+
* the same Array instance for segments as the target Path is was cloned from.
|
|
411
645
|
*/
|
|
412
646
|
clone(): this;
|
|
413
647
|
|
|
414
648
|
/**
|
|
415
|
-
*
|
|
649
|
+
* Creates a new Path which expresses the target Path relative to `dir`.
|
|
416
650
|
*
|
|
417
651
|
* @param dir - The directory to create a new path relative to.
|
|
418
|
-
* @param options - Options that affect the resulting path.
|
|
652
|
+
* @param options - Options that affect the resulting path (see {@link PathRelativeToOptions}).
|
|
419
653
|
*/
|
|
420
|
-
relativeTo(
|
|
421
|
-
dir: Path | string,
|
|
422
|
-
options?: {
|
|
423
|
-
/**
|
|
424
|
-
* Defaults to false. When true, a leading `./` will be omitted from the
|
|
425
|
-
* path, if present. Note that a leading `../` will never be omitted.
|
|
426
|
-
*/
|
|
427
|
-
noLeadingDot?: boolean;
|
|
428
|
-
}
|
|
429
|
-
): Path;
|
|
654
|
+
relativeTo(dir: Path | string, options?: PathRelativeToOptions): Path;
|
|
430
655
|
|
|
431
656
|
/**
|
|
432
|
-
*
|
|
657
|
+
* Turns the target Path into a string by joining its segments using its
|
|
658
|
+
* separator as the delimiter.
|
|
433
659
|
*/
|
|
434
660
|
toString(): string;
|
|
435
661
|
|
|
436
662
|
/**
|
|
437
|
-
* Alias for `toString
|
|
438
|
-
* they (or an object referencing them)
|
|
663
|
+
* Alias for `toString`. The presence of this method causes Path objects to be
|
|
664
|
+
* serialized as strings when they (or an object referencing them) get(s) passed
|
|
665
|
+
* into JSON.stringify.
|
|
439
666
|
*/
|
|
440
667
|
toJSON(): string;
|
|
441
668
|
|
|
442
669
|
/**
|
|
443
|
-
*
|
|
444
|
-
* segments,
|
|
670
|
+
* Returns the final segment of the target Path. If the target Path has no
|
|
671
|
+
* segments, an empty string (`""`) is returned.
|
|
445
672
|
*/
|
|
446
673
|
basename(): string;
|
|
447
674
|
|
|
448
675
|
/**
|
|
449
|
-
*
|
|
450
|
-
*
|
|
676
|
+
* Returns the trailing file extension of this path.
|
|
677
|
+
*
|
|
678
|
+
* @param options - Works the same as the options parameter for the global {@link extname} (see {@link ExtnameOptions}).
|
|
451
679
|
*/
|
|
452
|
-
extname(options?:
|
|
680
|
+
extname(options?: ExtnameOptions): string;
|
|
453
681
|
|
|
454
682
|
/**
|
|
455
|
-
*
|
|
456
|
-
* for the last one; ie. the path to the directory that contains
|
|
683
|
+
* Creates a new Path containing all of the segments in the target Path except
|
|
684
|
+
* for the last one; ie. the path to the directory that contains the target Path.
|
|
457
685
|
*/
|
|
458
686
|
dirname(): Path;
|
|
459
687
|
|
|
460
688
|
/**
|
|
461
|
-
*
|
|
462
|
-
* path segment at a time.
|
|
689
|
+
* Returns a boolean indicating whether the target Path starts with the
|
|
690
|
+
* provided value, by comparing one path segment at a time.
|
|
463
691
|
*
|
|
464
|
-
* The starting segments of
|
|
692
|
+
* The starting segments of the target Path must *exactly* match the segments in the
|
|
465
693
|
* provided value.
|
|
466
694
|
*
|
|
467
695
|
* This means that, given two Paths A and B:
|
|
@@ -476,10 +704,10 @@ declare class Path {
|
|
|
476
704
|
startsWith(value: string | Path | Array<string | Path>): boolean;
|
|
477
705
|
|
|
478
706
|
/**
|
|
479
|
-
*
|
|
480
|
-
* path segment at a time.
|
|
707
|
+
* Returns a boolean indicating whether the target Path ends with the provided
|
|
708
|
+
* value, by comparing one path segment at a time.
|
|
481
709
|
*
|
|
482
|
-
* The ending segments of
|
|
710
|
+
* The ending segments of the target Path must *exactly* match the segments in the
|
|
483
711
|
* provided value.
|
|
484
712
|
*
|
|
485
713
|
* This means that, given two Paths A and B:
|
|
@@ -494,11 +722,11 @@ declare class Path {
|
|
|
494
722
|
endsWith(value: string | Path | Array<string | Path>): boolean;
|
|
495
723
|
|
|
496
724
|
/**
|
|
497
|
-
*
|
|
498
|
-
* `-1` if
|
|
725
|
+
* Returns the index at which `value` appears in the target Path's segments,
|
|
726
|
+
* or `-1` if `value` doesn't appear in the target Path.
|
|
499
727
|
*
|
|
500
728
|
* @param value - The value to search for. If the value contains more than one path segment, the returned index will refer to the location of the value's first path segment.
|
|
501
|
-
* @param fromIndex - The index into
|
|
729
|
+
* @param fromIndex - The index into the target Path's segments to begin searching at. Defaults to `0`.
|
|
502
730
|
*/
|
|
503
731
|
indexOf(
|
|
504
732
|
value: string | Path | Array<string | Path>,
|
|
@@ -506,10 +734,10 @@ declare class Path {
|
|
|
506
734
|
): number;
|
|
507
735
|
|
|
508
736
|
/**
|
|
509
|
-
*
|
|
737
|
+
* Returns a boolean indicating whether `value` appears in the target Path.
|
|
510
738
|
*
|
|
511
739
|
* @param value - The value to search for.
|
|
512
|
-
* @param fromIndex - The index into
|
|
740
|
+
* @param fromIndex - The index into the target Path's segments to begin searching at. Defaults to `0`.
|
|
513
741
|
*/
|
|
514
742
|
includes(
|
|
515
743
|
value: string | Path | Array<string | Path>,
|
|
@@ -517,14 +745,18 @@ declare class Path {
|
|
|
517
745
|
): boolean;
|
|
518
746
|
|
|
519
747
|
/**
|
|
520
|
-
*
|
|
521
|
-
* the segments in `replacement`. If the segments in
|
|
522
|
-
* in
|
|
748
|
+
* Creates a new Path based on the target Path wherein the segments in `value`
|
|
749
|
+
* have been replaced with the segments in `replacement`. If the segments in
|
|
750
|
+
* `value` are not present in the target Path, a clone of the target Path is
|
|
751
|
+
* returned.
|
|
523
752
|
*
|
|
524
|
-
* Note that only the first match is replaced.
|
|
753
|
+
* Note that only the first match is replaced. To replace more than one match,
|
|
754
|
+
* use {@link Path.prototype.replaceAll}.
|
|
525
755
|
*
|
|
526
756
|
* @param value - What should be replaced
|
|
527
757
|
* @param replacement - What it should be replaced with
|
|
758
|
+
*
|
|
759
|
+
* See also {@link Path.prototype.replaceLast}.
|
|
528
760
|
*/
|
|
529
761
|
replace(
|
|
530
762
|
value: string | Path | Array<string | Path>,
|
|
@@ -532,12 +764,18 @@ declare class Path {
|
|
|
532
764
|
): Path;
|
|
533
765
|
|
|
534
766
|
/**
|
|
535
|
-
*
|
|
536
|
-
* been replaced with the segments in `replacement`.
|
|
537
|
-
* `value` are not present in
|
|
767
|
+
* Creates a new Path based on the target Path wherein all occurrences of the
|
|
768
|
+
* segments in `value` have been replaced with the segments in `replacement`.
|
|
769
|
+
* If the segments in `value` are not present in the target Path, a clone of
|
|
770
|
+
* the target Path is returned.
|
|
771
|
+
*
|
|
772
|
+
* Note that all matches are replaced. To replace only the first match,
|
|
773
|
+
* use {@link Path.prototype.replace}.
|
|
538
774
|
*
|
|
539
775
|
* @param value - What should be replaced
|
|
540
776
|
* @param replacement - What it should be replaced with
|
|
777
|
+
*
|
|
778
|
+
* See also {@link Path.prototype.replaceLast}.
|
|
541
779
|
*/
|
|
542
780
|
replaceAll(
|
|
543
781
|
value: string | Path | Array<string | Path>,
|
|
@@ -545,7 +783,11 @@ declare class Path {
|
|
|
545
783
|
): Path;
|
|
546
784
|
|
|
547
785
|
/**
|
|
548
|
-
*
|
|
786
|
+
* Creates a new Path based on the target Path but with the final segment
|
|
787
|
+
* replaced with `replacement`.
|
|
788
|
+
*
|
|
789
|
+
* If the target Path has no segments, the newly created Path will be the same
|
|
790
|
+
* as `new Path(replacement)`; ie. non-empty.
|
|
549
791
|
*
|
|
550
792
|
* @param replacement - The new final segment(s) for the returned Path
|
|
551
793
|
*/
|
|
@@ -553,16 +795,33 @@ declare class Path {
|
|
|
553
795
|
}
|
|
554
796
|
|
|
555
797
|
/**
|
|
556
|
-
*
|
|
798
|
+
* Options for {@link Path.prototype.relativeTo}.
|
|
799
|
+
*/
|
|
800
|
+
declare interface PathRelativeToOptions {
|
|
801
|
+
/**
|
|
802
|
+
* Defaults to false. When true, a leading `./` will be omitted from the
|
|
803
|
+
* path, if present. Note that a leading `../` will never be omitted.
|
|
804
|
+
*/
|
|
805
|
+
noLeadingDot?: boolean;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* The absolute path to the currently-executing file (whether script or module).
|
|
810
|
+
*
|
|
811
|
+
* Behaves the same as in Node.js, except that it's also present within ES
|
|
812
|
+
* modules.
|
|
557
813
|
*
|
|
558
|
-
*
|
|
814
|
+
* Example: `/home/suchipi/some-folder/some-file.js`
|
|
559
815
|
*/
|
|
560
816
|
declare var __filename: string;
|
|
561
817
|
|
|
562
818
|
/**
|
|
563
|
-
* The absolute path to the directory the
|
|
819
|
+
* The absolute path to the directory containing the currently-executing file.
|
|
564
820
|
*
|
|
565
|
-
* Behaves the same as in Node.js, except that it's also present within ES
|
|
821
|
+
* Behaves the same as in Node.js, except that it's also present within ES
|
|
822
|
+
* modules.
|
|
823
|
+
*
|
|
824
|
+
* Example: `/home/suchipi/some-folder`
|
|
566
825
|
*/
|
|
567
826
|
declare var __dirname: string;
|
|
568
827
|
|
|
@@ -570,12 +829,20 @@ declare var __dirname: string;
|
|
|
570
829
|
* Return the last component of a path string.
|
|
571
830
|
*
|
|
572
831
|
* Provides the same functionality as the unix binary of the same name.
|
|
832
|
+
*
|
|
833
|
+
* > Example: `basename("/home/suchipi/something")` returns `"something"`, the last part.
|
|
573
834
|
*/
|
|
574
835
|
declare function basename(path: string | Path): string;
|
|
575
836
|
|
|
576
837
|
/**
|
|
577
838
|
* Reads the contents of one or more files from disk as either one UTF-8 string
|
|
578
839
|
* or one ArrayBuffer.
|
|
840
|
+
*
|
|
841
|
+
* Provides the same functionality as the unix binary of the same name.
|
|
842
|
+
*
|
|
843
|
+
* > Example: If you have a file called `hi.txt` in the current working
|
|
844
|
+
* > directory, and it contains the text "hello", running `cat("hi.txt")`
|
|
845
|
+
* > returns `"hello"`.
|
|
579
846
|
*/
|
|
580
847
|
declare const cat: {
|
|
581
848
|
/**
|
|
@@ -606,66 +873,142 @@ declare const cat: {
|
|
|
606
873
|
};
|
|
607
874
|
|
|
608
875
|
/**
|
|
609
|
-
*
|
|
876
|
+
* Changes the process's current working directory to the specified path. If no
|
|
610
877
|
* path is specified, moves to the user's home directory.
|
|
611
878
|
*
|
|
612
879
|
* Provides the same functionality as the shell builtin of the same name.
|
|
613
880
|
*/
|
|
614
881
|
declare function cd(path?: string | Path): void;
|
|
615
882
|
|
|
616
|
-
/** A string representing who a permission applies to. */
|
|
617
|
-
declare type ChmodPermissionsWho =
|
|
618
|
-
| "user"
|
|
619
|
-
| "group"
|
|
620
|
-
| "others"
|
|
621
|
-
| "all"
|
|
622
|
-
| "u"
|
|
623
|
-
| "g"
|
|
624
|
-
| "o"
|
|
625
|
-
| "a"
|
|
626
|
-
| "ug"
|
|
627
|
-
| "go"
|
|
628
|
-
| "uo";
|
|
629
|
-
|
|
630
|
-
/** A string representing the access level for the given permission. */
|
|
631
|
-
declare type ChmodPermissionsWhat =
|
|
632
|
-
| "read"
|
|
633
|
-
| "write"
|
|
634
|
-
| "execute"
|
|
635
|
-
| "readwrite"
|
|
636
|
-
| "none"
|
|
637
|
-
| "full"
|
|
638
|
-
| "r"
|
|
639
|
-
| "w"
|
|
640
|
-
| "x"
|
|
641
|
-
| "rw"
|
|
642
|
-
| "rx"
|
|
643
|
-
| "wx"
|
|
644
|
-
| "rwx";
|
|
645
|
-
|
|
646
883
|
/**
|
|
647
884
|
* Set the permission bits for the specified file.
|
|
648
885
|
*
|
|
649
|
-
*
|
|
650
|
-
* @param path The path to the file.
|
|
886
|
+
* Provides the same functionality as the unix binary of the same name.
|
|
651
887
|
*/
|
|
652
|
-
declare
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
888
|
+
declare const chmod: Chmod;
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* The interface for the global function `chmod`, which has two call signatures.
|
|
892
|
+
*/
|
|
893
|
+
interface Chmod {
|
|
894
|
+
/**
|
|
895
|
+
* Set the permission bits for the specified file.
|
|
896
|
+
*
|
|
897
|
+
* Provides the same functionality as the unix binary of the same name.
|
|
898
|
+
*
|
|
899
|
+
* @param permissions The permission bits to set. This can be a number, or a string containing an octal number.
|
|
900
|
+
* @param path The path to the file.
|
|
901
|
+
*/
|
|
902
|
+
(permissions: number | string, path: string | Path): void;
|
|
903
|
+
|
|
904
|
+
/**
|
|
905
|
+
* Apply a change to the permission bits for the specified file.
|
|
906
|
+
*
|
|
907
|
+
* Provides the same functionality as the unix binary of the same name.
|
|
908
|
+
*
|
|
909
|
+
* @param operation What to do to the bits; can be "add", "set", or "remove".
|
|
910
|
+
* @param permissions An object describing the changes (see below).
|
|
911
|
+
* @param path The path to the file.
|
|
912
|
+
*
|
|
913
|
+
* Each of the `permissions` object's own property keys must be one of these
|
|
914
|
+
* strings:
|
|
915
|
+
*
|
|
916
|
+
* - `"user"`
|
|
917
|
+
* - `"group"`
|
|
918
|
+
* - `"others"`
|
|
919
|
+
* - `"all"` (meaning "user", "group", and "others")
|
|
920
|
+
* - `"u"` (alias for "user")
|
|
921
|
+
* - `"g"` (alias for "group")
|
|
922
|
+
* - `"o"` (alias for "others")
|
|
923
|
+
* - `"a"` (alias for "all")
|
|
924
|
+
* - `"ug"` ("user" plus "group")
|
|
925
|
+
* - `"go"` ("group" plus "others")
|
|
926
|
+
* - `"uo"` ("user" plus "others")
|
|
927
|
+
*
|
|
928
|
+
* and their values must be one of these strings:
|
|
929
|
+
*
|
|
930
|
+
* - `"read"` (permission to read the contents of the file)
|
|
931
|
+
* - `"write"` (permission to write to the file's contents)
|
|
932
|
+
* - `"execute"` (permission to run the file as an executable)
|
|
933
|
+
* - `"readwrite"` (both "read" and "write")
|
|
934
|
+
* - `"none"` (no permissions)
|
|
935
|
+
* - `"full"` ("read", "write", and "execute")
|
|
936
|
+
* - `"r"` (alias for "read")
|
|
937
|
+
* - `"w"` (alias for "write")
|
|
938
|
+
* - `"x"` (alias for "execute")
|
|
939
|
+
* - `"rw"` (alias for "readwrite")
|
|
940
|
+
* - `"rx"` ("read" and "execute")
|
|
941
|
+
* - `"wx"` ("write" and "execute")
|
|
942
|
+
* - `"rwx"` (alias for "full")
|
|
943
|
+
*
|
|
944
|
+
* Some example objects:
|
|
945
|
+
*
|
|
946
|
+
* ```json
|
|
947
|
+
* { user: "readwrite", group: "read", others: "none" }
|
|
948
|
+
* { ug: "rw", o: "w" }
|
|
949
|
+
* { all: "full" }
|
|
950
|
+
* ```
|
|
951
|
+
*/
|
|
952
|
+
(
|
|
953
|
+
operation: Chmod.Operation,
|
|
954
|
+
permissions: Record<Chmod.Who, Chmod.Permission>,
|
|
955
|
+
path: string | Path
|
|
956
|
+
): void;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
declare namespace Chmod {
|
|
960
|
+
/** A string representing who a permission applies to. */
|
|
961
|
+
export type Who =
|
|
962
|
+
| "user"
|
|
963
|
+
| "group"
|
|
964
|
+
| "others"
|
|
965
|
+
| "all"
|
|
966
|
+
| "u"
|
|
967
|
+
| "g"
|
|
968
|
+
| "o"
|
|
969
|
+
| "a"
|
|
970
|
+
| "ug"
|
|
971
|
+
| "go"
|
|
972
|
+
| "uo";
|
|
973
|
+
|
|
974
|
+
/** A string representing how the permissions should be changed. */
|
|
975
|
+
export type Operation = "add" | "set" | "remove";
|
|
976
|
+
|
|
977
|
+
/** A string representing the access level for the given permission. */
|
|
978
|
+
export type Permission =
|
|
979
|
+
| "read"
|
|
980
|
+
| "write"
|
|
981
|
+
| "execute"
|
|
982
|
+
| "readwrite"
|
|
983
|
+
| "none"
|
|
984
|
+
| "full"
|
|
985
|
+
| "r"
|
|
986
|
+
| "w"
|
|
987
|
+
| "x"
|
|
988
|
+
| "rw"
|
|
989
|
+
| "rx"
|
|
990
|
+
| "wx"
|
|
991
|
+
| "rwx";
|
|
992
|
+
}
|
|
659
993
|
|
|
660
994
|
/**
|
|
661
995
|
* Removes the final component from a path string.
|
|
662
996
|
*
|
|
663
997
|
* Provides the same functionality as the unix binary of the same name.
|
|
998
|
+
*
|
|
999
|
+
* > Example: `dirname("/home/suchipi/something")` returns
|
|
1000
|
+
* > `"/home/suchipi"`, everything except the last part.
|
|
664
1001
|
*/
|
|
665
1002
|
declare function dirname(path: string | Path): Path;
|
|
666
1003
|
|
|
667
1004
|
/**
|
|
668
1005
|
* Print one or more values to stdout.
|
|
1006
|
+
*
|
|
1007
|
+
* Provides the same functionality as the shell builtin of the same name.
|
|
1008
|
+
*
|
|
1009
|
+
* > NOTE: This can print any value, not just strings.
|
|
1010
|
+
*
|
|
1011
|
+
* `echo` is functionally identical to `console.log`.
|
|
669
1012
|
*/
|
|
670
1013
|
declare const echo: typeof console.log;
|
|
671
1014
|
|
|
@@ -679,6 +1022,9 @@ declare const echo: typeof console.log;
|
|
|
679
1022
|
*
|
|
680
1023
|
* `exit.code` will also be used as the exit status code for the yavascript
|
|
681
1024
|
* process if the process exits normally.
|
|
1025
|
+
*
|
|
1026
|
+
* > Attempting to call `exit` or set `exit.code` within a Worker will fail and
|
|
1027
|
+
* > throw an error.
|
|
682
1028
|
*/
|
|
683
1029
|
declare const exit: {
|
|
684
1030
|
(code?: number): never;
|
|
@@ -688,18 +1034,34 @@ declare const exit: {
|
|
|
688
1034
|
/**
|
|
689
1035
|
* Returns the file extension of the file at a given path.
|
|
690
1036
|
*
|
|
691
|
-
* If the file has no extension (eg `Makefile`, etc), then `''` will be
|
|
1037
|
+
* If the file has no extension (eg `Makefile`, etc), then `''` will be
|
|
1038
|
+
* returned.
|
|
692
1039
|
*
|
|
693
|
-
*
|
|
1040
|
+
* @param pathOrFilename The input path
|
|
1041
|
+
* @param options Options which affect the return value. See {@link ExtnameOptions}.
|
|
694
1042
|
*/
|
|
695
1043
|
declare function extname(
|
|
696
1044
|
pathOrFilename: string | Path,
|
|
697
|
-
options?:
|
|
1045
|
+
options?: ExtnameOptions
|
|
698
1046
|
): string;
|
|
699
1047
|
|
|
1048
|
+
/**
|
|
1049
|
+
* Options for {@link extname} and {@link Path.prototype.extname}.
|
|
1050
|
+
*/
|
|
1051
|
+
declare interface ExtnameOptions {
|
|
1052
|
+
/**
|
|
1053
|
+
* Whether to get compound extensions, like `.d.ts` or `.test.js`, instead of
|
|
1054
|
+
* just the final extension (`.ts` or `.js` in this example).
|
|
1055
|
+
*/
|
|
1056
|
+
full?: boolean;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
700
1059
|
/**
|
|
701
1060
|
* Returns the contents of a directory, as absolute paths. `.` and `..` are
|
|
702
1061
|
* omitted.
|
|
1062
|
+
*
|
|
1063
|
+
* If `ls()` is called with no directory, the present working directory
|
|
1064
|
+
* (`pwd()`) is used.
|
|
703
1065
|
*/
|
|
704
1066
|
declare function ls(dir?: string | Path): Array<Path>;
|
|
705
1067
|
|
|
@@ -741,9 +1103,10 @@ declare function mkdirp(
|
|
|
741
1103
|
/**
|
|
742
1104
|
* Print data to stdout using C-style format specifiers.
|
|
743
1105
|
*
|
|
744
|
-
* The same formats as the standard C library
|
|
745
|
-
*
|
|
746
|
-
*
|
|
1106
|
+
* The same formats as the [standard C library
|
|
1107
|
+
* printf](https://en.cppreference.com/w/c/io/fprintf) are supported. Integer
|
|
1108
|
+
* format types (e.g. `%d`) truncate the Numbers or BigInts to 32 bits. Use the
|
|
1109
|
+
* l modifier (e.g. `%ld`) to truncate to 64 bits.
|
|
747
1110
|
*/
|
|
748
1111
|
declare function printf(format: string, ...args: Array<any>): void;
|
|
749
1112
|
|
|
@@ -782,31 +1145,48 @@ declare function readlink(path: string | Path): Path;
|
|
|
782
1145
|
* The path's target file/directory must exist.
|
|
783
1146
|
*
|
|
784
1147
|
* Provides the same functionality as the unix binary of the same name.
|
|
1148
|
+
*
|
|
1149
|
+
* > If you want to convert a relative path to an absolute path, but the path's
|
|
1150
|
+
* > target might NOT exist, use {@link Path.normalize}.
|
|
785
1151
|
*/
|
|
786
1152
|
declare function realpath(path: string | Path): Path;
|
|
787
1153
|
|
|
788
1154
|
/**
|
|
789
|
-
*
|
|
790
|
-
*
|
|
1155
|
+
* `sleep` and `sleep.sync` block the current thread for at least the specified
|
|
1156
|
+
* number of milliseconds, but maybe a tiny bit longer.
|
|
791
1157
|
*
|
|
792
|
-
*
|
|
1158
|
+
* `sleep.async` returns a Promise which resolves in at least the specified
|
|
1159
|
+
* number of milliseconds, but maybe a tiny bit longer.
|
|
1160
|
+
*
|
|
1161
|
+
* `sleep` and `sleep.sync` block the current thread. `sleep.async` doesn't
|
|
1162
|
+
* block the current thread.
|
|
1163
|
+
*
|
|
1164
|
+
* "Blocking the thread" means no other JavaScript code can run while `sleep` or
|
|
1165
|
+
* `sleep.sync` is running. If this is not the behavior you want, use
|
|
1166
|
+
* `sleep.async` instead.
|
|
793
1167
|
*/
|
|
794
1168
|
declare var sleep: {
|
|
795
1169
|
/**
|
|
796
|
-
* Blocks the current thread for at least the specified number of
|
|
797
|
-
*
|
|
1170
|
+
* Blocks the current thread for at least the specified number of
|
|
1171
|
+
* milliseconds, but maybe a tiny bit longer.
|
|
798
1172
|
*
|
|
799
1173
|
* alias for `sleep.sync`.
|
|
800
1174
|
*
|
|
801
1175
|
* @param milliseconds - The number of milliseconds to block for.
|
|
1176
|
+
*
|
|
1177
|
+
* No other JavaScript code can run while `sleep()` is running. If this is
|
|
1178
|
+
* not the behavior you want, use `sleep.async` instead.
|
|
802
1179
|
*/
|
|
803
1180
|
(milliseconds: number): void;
|
|
804
1181
|
|
|
805
1182
|
/**
|
|
806
|
-
* Blocks the current thread for at least the specified number of
|
|
807
|
-
*
|
|
1183
|
+
* Blocks the current thread for at least the specified number of
|
|
1184
|
+
* milliseconds, but maybe a tiny bit longer.
|
|
808
1185
|
*
|
|
809
1186
|
* @param milliseconds - The number of milliseconds to block for.
|
|
1187
|
+
*
|
|
1188
|
+
* No other JavaScript code can run while `sleep.sync` is running. If this is
|
|
1189
|
+
* not the behavior you want, use `sleep.async` instead.
|
|
810
1190
|
*/
|
|
811
1191
|
sync(milliseconds: number): void;
|
|
812
1192
|
|
|
@@ -815,6 +1195,14 @@ declare var sleep: {
|
|
|
815
1195
|
* milliseconds, maybe a little longer.
|
|
816
1196
|
*
|
|
817
1197
|
* @param milliseconds - The number of milliseconds to wait before the returned Promise should be resolved.
|
|
1198
|
+
*
|
|
1199
|
+
* `sleep.async` doesn't block the current thread, so other JavaScript code
|
|
1200
|
+
* (registered event handlers, async functions, timers, etc) can run while
|
|
1201
|
+
* `sleep.async`'s return Promise is waiting to resolve. If this is not the
|
|
1202
|
+
* behavior you want, use `sleep.sync` instead.
|
|
1203
|
+
*
|
|
1204
|
+
* The Promise returned by `sleep.async` will never get rejected. It will only
|
|
1205
|
+
* ever get resolved.
|
|
818
1206
|
*/
|
|
819
1207
|
async(milliseconds: number): Promise<void>;
|
|
820
1208
|
};
|
|
@@ -839,42 +1227,129 @@ declare function touch(path: string | Path): void;
|
|
|
839
1227
|
* @param options.suffixes A list of filename extension suffixes to include in the search, ie [".exe"]. Defaults to `Path.OS_PROGRAM_EXTENSIONS`.
|
|
840
1228
|
* @param options.trace A logging function that will be called at various times during the execution of `which`. Defaults to {@link logger.trace}.
|
|
841
1229
|
*/
|
|
842
|
-
declare function which(
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
1230
|
+
declare function which(binaryName: string, options?: WhichOptions): Path | null;
|
|
1231
|
+
|
|
1232
|
+
declare type WhichOptions = {
|
|
1233
|
+
/**
|
|
1234
|
+
* A list of folders where programs may be found. Defaults to
|
|
1235
|
+
* `env.PATH?.split(Path.OS_ENV_VAR_SEPARATOR) || []`.
|
|
1236
|
+
*/
|
|
1237
|
+
searchPaths?: Array<Path | string>;
|
|
850
1238
|
|
|
1239
|
+
/**
|
|
1240
|
+
* A list of filename extension suffixes to include in the search, ie
|
|
1241
|
+
* `[".exe"]`. Defaults to {@link Path.OS_PROGRAM_EXTENSIONS}.
|
|
1242
|
+
*/
|
|
1243
|
+
suffixes?: Array<string>;
|
|
1244
|
+
|
|
1245
|
+
/** Options which control logging. */
|
|
1246
|
+
logging?: {
|
|
851
1247
|
/**
|
|
852
|
-
*
|
|
853
|
-
* `
|
|
1248
|
+
* If provided, this logging function will be called multiple times as
|
|
1249
|
+
* `which` runs, to help you understand what's going on and/or troubleshoot
|
|
1250
|
+
* things. In most cases, it makes sense to use a function from `console`
|
|
1251
|
+
* here, like so:
|
|
1252
|
+
*
|
|
1253
|
+
* ```js
|
|
1254
|
+
* which("bash", {
|
|
1255
|
+
* logging: { trace: console.log }
|
|
1256
|
+
* });
|
|
1257
|
+
* ```
|
|
1258
|
+
*
|
|
1259
|
+
* Defaults to the current value of {@link logger.trace}. `logger.trace`
|
|
1260
|
+
* defaults to a no-op function.
|
|
854
1261
|
*/
|
|
855
|
-
|
|
1262
|
+
trace?: (...args: Array<any>) => void;
|
|
1263
|
+
};
|
|
1264
|
+
};
|
|
856
1265
|
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
1266
|
+
/** The type of the return value of {@link whoami}. */
|
|
1267
|
+
declare interface WhoAmIResult {
|
|
1268
|
+
name: string;
|
|
1269
|
+
uid: number;
|
|
1270
|
+
gid: number;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
/**
|
|
1274
|
+
* Get info about the user the yavascript process is executing as.
|
|
1275
|
+
*
|
|
1276
|
+
* Provides functionality similar to the unix binaries `whoami` and `id`.
|
|
1277
|
+
*
|
|
1278
|
+
* NOTE: Doesn't work on Windows; throws an error.
|
|
1279
|
+
*/
|
|
1280
|
+
declare function whoami(): WhoAmIResult;
|
|
1281
|
+
|
|
1282
|
+
/**
|
|
1283
|
+
* Runs a child process and blocks until it exits. You can call it with either a
|
|
1284
|
+
* string or an array of strings.
|
|
1285
|
+
*
|
|
1286
|
+
* When calling `exec` with an array of strings, the first string in the array
|
|
1287
|
+
* is the program to run, and the rest of the strings in the array are arguments
|
|
1288
|
+
* to the program, eg:
|
|
1289
|
+
*
|
|
1290
|
+
* ```ts
|
|
1291
|
+
* exec(["echo", "hi", "there"]);
|
|
1292
|
+
* exec(["printf", "something with spaces\n"]);
|
|
1293
|
+
* ```
|
|
1294
|
+
*
|
|
1295
|
+
* When calling with a string instead of an array, the string will be split into
|
|
1296
|
+
* separate arguments using the following rules:
|
|
1297
|
+
*
|
|
1298
|
+
* - The program and its arguments will be determined by splitting the input
|
|
1299
|
+
* string on whitespace, except:
|
|
1300
|
+
* - Stuff in single or double-quotes will be preserved as a single argument
|
|
1301
|
+
* - Double and single quotes can be "glued" together (eg `"bla"'bla'` becomes
|
|
1302
|
+
* `blabla`)
|
|
1303
|
+
* - The escape sequences `\n`, `\r`, `\t`, `\v`, `\0`, and `\\` can be used
|
|
1304
|
+
* inside of quotes get replaced with newline, carriage return, tab,
|
|
1305
|
+
* vertical tab, nul, and `\` characters, respectively
|
|
1306
|
+
*
|
|
1307
|
+
* For example:
|
|
1308
|
+
*
|
|
1309
|
+
* ```ts
|
|
1310
|
+
* exec(`echo hi there`);
|
|
1311
|
+
* exec(`printf "something with spaces\n"`);
|
|
1312
|
+
* ```
|
|
1313
|
+
*
|
|
1314
|
+
* The intent is that it behaves similarly to what you would expect from a UNIX
|
|
1315
|
+
* shell, but only the "safe" features. "Unsafe" features like environment
|
|
1316
|
+
* variable expansion (`$VAR` or `${VAR}`), subshells (\`echo hi\` or `$(echo
|
|
1317
|
+
* hi)`), and redirection (`> /dev/null` or `2>&1 `) are not supported. To use
|
|
1318
|
+
* those features, shell out to `bash` or `sh` directly via eg `exec(['bash',
|
|
1319
|
+
* '-c', 'your command string'])`, but be aware of the security implications of
|
|
1320
|
+
* doing so.
|
|
1321
|
+
*
|
|
1322
|
+
* `exec` also supports a second argument, an options object which supports the
|
|
1323
|
+
* following keys (all are optional):
|
|
1324
|
+
*
|
|
1325
|
+
* | Property | Purpose |
|
|
1326
|
+
* | ------------------------------ | --------------------------------------------------- |
|
|
1327
|
+
* | cwd (string) | current working directory for the child process |
|
|
1328
|
+
* | env (object) | environment variables for the process |
|
|
1329
|
+
* | failOnNonZeroStatus (boolean) | whether to throw error on nonzero exit status |
|
|
1330
|
+
* | captureOutput (boolean/string) | controls how stdout/stderr is directed |
|
|
1331
|
+
* | logging (object) | controls how/whether info messages are logged |
|
|
1332
|
+
* | block (boolean) | whether to wait for child process exit now or later |
|
|
1333
|
+
*
|
|
1334
|
+
* The return value of `exec` varies depending on the options passed:
|
|
1335
|
+
*
|
|
1336
|
+
* - When `captureOutput` is true or "utf-8", an object will be returned with
|
|
1337
|
+
* `stdout` and `stderr` properties, both strings.
|
|
1338
|
+
* - When `captureOutput` is "arraybuffer", an object will be returned with
|
|
1339
|
+
* `stdout` and `stderr` properties, both `ArrayBuffer`s.
|
|
1340
|
+
* - When `failOnNonZeroStatus` is false, an object will be returned with
|
|
1341
|
+
* `status` (the exit code; number or undefined) and `signal` (the signal that
|
|
1342
|
+
* killed the process; number or undefined).
|
|
1343
|
+
* - When `captureOutput` is non-false and `failOnNonZeroStatus` is false, an
|
|
1344
|
+
* object will be returned with four properties (the two associated with
|
|
1345
|
+
* `failOnNonZeroStatus`, and the two associated with `captureOutput`).
|
|
1346
|
+
* - When `captureOutput` is false or unspecified, and `failOnNonZeroStatus` is
|
|
1347
|
+
* true or unspecified, undefined will be returned.
|
|
1348
|
+
* - If `block` is false, an object with a "wait" method is returned instead,
|
|
1349
|
+
* which blocks the calling thread until the process exits, and then returns
|
|
1350
|
+
* one of the values described above.
|
|
1351
|
+
*/
|
|
1352
|
+
declare const exec: Exec;
|
|
878
1353
|
|
|
879
1354
|
declare type BaseExecOptions = {
|
|
880
1355
|
/** Sets the current working directory for the child process. */
|
|
@@ -938,23 +1413,16 @@ declare type BaseExecOptions = {
|
|
|
938
1413
|
block?: boolean;
|
|
939
1414
|
};
|
|
940
1415
|
|
|
941
|
-
type ExecWaitResult<ExecOptions extends BaseExecOptions> = ExecOptions extends
|
|
942
|
-
| { captureOutput: true | "utf8" | "arraybuffer" }
|
|
943
|
-
| { failOnNonZeroStatus: false }
|
|
944
|
-
? (ExecOptions["captureOutput"] extends true | "utf8"
|
|
945
|
-
? { stdout: string; stderr: string }
|
|
946
|
-
: {}) &
|
|
947
|
-
(ExecOptions["captureOutput"] extends "arraybuffer"
|
|
948
|
-
? { stdout: ArrayBuffer; stderr: ArrayBuffer }
|
|
949
|
-
: {}) &
|
|
950
|
-
(ExecOptions["failOnNonZeroStatus"] extends false
|
|
951
|
-
?
|
|
952
|
-
| { status: number; signal: undefined }
|
|
953
|
-
| { status: undefined; signal: number }
|
|
954
|
-
: {})
|
|
955
|
-
: void;
|
|
956
|
-
|
|
957
1416
|
declare interface Exec {
|
|
1417
|
+
/**
|
|
1418
|
+
* Runs a child process using the provided arguments.
|
|
1419
|
+
*
|
|
1420
|
+
* When `args` is an Array, the first value in the Array is the program to
|
|
1421
|
+
* run.
|
|
1422
|
+
*
|
|
1423
|
+
* @param args - The command to run.
|
|
1424
|
+
* @param options - Options; see {@link BaseExecOptions}
|
|
1425
|
+
*/
|
|
958
1426
|
<
|
|
959
1427
|
ExecOptions extends BaseExecOptions = {
|
|
960
1428
|
failOnNonZeroStatus: true;
|
|
@@ -976,19 +1444,50 @@ declare interface Exec {
|
|
|
976
1444
|
}
|
|
977
1445
|
|
|
978
1446
|
/**
|
|
979
|
-
*
|
|
1447
|
+
* `$(...)` is an alias for `exec(..., { captureOutput: true, failOnNonZeroStatus: true })`.
|
|
1448
|
+
*
|
|
1449
|
+
* It's often used to capture the output of a program:
|
|
980
1450
|
*
|
|
981
|
-
*
|
|
1451
|
+
* ```ts
|
|
1452
|
+
* const result = $(`echo hi`).stdout;
|
|
1453
|
+
* // result is 'hi\n'
|
|
1454
|
+
* ```
|
|
1455
|
+
*
|
|
1456
|
+
* For more info, see {@link exec}.
|
|
982
1457
|
*/
|
|
983
|
-
declare const exec: Exec;
|
|
984
|
-
|
|
985
|
-
/** Alias for `exec(args, { captureOutput: true })` */
|
|
986
1458
|
declare function $(args: Array<string | Path | number> | string | Path): {
|
|
987
1459
|
stdout: string;
|
|
988
1460
|
stderr: string;
|
|
989
1461
|
};
|
|
990
1462
|
|
|
991
|
-
|
|
1463
|
+
type ExecWaitResult<ExecOptions extends BaseExecOptions> = ExecOptions extends
|
|
1464
|
+
| { captureOutput: true | "utf8" | "arraybuffer" }
|
|
1465
|
+
| { failOnNonZeroStatus: false }
|
|
1466
|
+
? (ExecOptions["captureOutput"] extends true | "utf8"
|
|
1467
|
+
? { stdout: string; stderr: string }
|
|
1468
|
+
: {}) &
|
|
1469
|
+
(ExecOptions["captureOutput"] extends "arraybuffer"
|
|
1470
|
+
? { stdout: ArrayBuffer; stderr: ArrayBuffer }
|
|
1471
|
+
: {}) &
|
|
1472
|
+
(ExecOptions["failOnNonZeroStatus"] extends false
|
|
1473
|
+
?
|
|
1474
|
+
| { status: number; signal: undefined }
|
|
1475
|
+
| { status: undefined; signal: number }
|
|
1476
|
+
: {})
|
|
1477
|
+
: void;
|
|
1478
|
+
|
|
1479
|
+
/**
|
|
1480
|
+
* A class which represents a child process. The process may or may not be
|
|
1481
|
+
* running.
|
|
1482
|
+
*
|
|
1483
|
+
* This class is the API used internally by the {@link exec} function to spawn child
|
|
1484
|
+
* processes.
|
|
1485
|
+
*
|
|
1486
|
+
* Generally, you should not need to use the `ChildProcess` class directly, and
|
|
1487
|
+
* should use {@link exec} or {@link $} instead. However, you may need to use it in some
|
|
1488
|
+
* special cases, like when specifying custom stdio for a process, or spawning a
|
|
1489
|
+
* non-blocking long-running process.
|
|
1490
|
+
*/
|
|
992
1491
|
declare interface ChildProcess {
|
|
993
1492
|
/**
|
|
994
1493
|
* The argv for the process. The first entry in this array is the program to
|
|
@@ -1082,6 +1581,32 @@ declare interface ChildProcessConstructor {
|
|
|
1082
1581
|
|
|
1083
1582
|
declare var ChildProcess: ChildProcessConstructor;
|
|
1084
1583
|
|
|
1584
|
+
/**
|
|
1585
|
+
* Searches the filesystem in order to resolve [UNIX-style glob
|
|
1586
|
+
* strings](https://man7.org/linux/man-pages/man7/glob.7.html) into an array of
|
|
1587
|
+
* matching filesystem paths.
|
|
1588
|
+
*
|
|
1589
|
+
* Glob strings assist in succinctly finding and describing a set of files on
|
|
1590
|
+
* disk. For instance, to find the path of every `.js` file in the `src` folder,
|
|
1591
|
+
* one might write `src/*.js`.
|
|
1592
|
+
*
|
|
1593
|
+
* The function `glob` can be used to turn one or more of these "glob strings" into an array of
|
|
1594
|
+
* `Path` objects.
|
|
1595
|
+
*
|
|
1596
|
+
* `glob` uses [minimatch](https://www.npmjs.com/package/minimatch) with its
|
|
1597
|
+
* default options, which means it supports features like brace expanstion,
|
|
1598
|
+
* "globstar" (**) matching, and other features you would expect from a modern
|
|
1599
|
+
* globbing solution.
|
|
1600
|
+
*
|
|
1601
|
+
* > When specifying more than one pattern string, paths must match ALL of the
|
|
1602
|
+
* > patterns to be included in the returned Array. In other words, it uses
|
|
1603
|
+
* > "logical AND" behavior when you give it more than one pattern.
|
|
1604
|
+
*/
|
|
1605
|
+
declare function glob(
|
|
1606
|
+
patterns: string | Array<string>,
|
|
1607
|
+
options?: GlobOptions
|
|
1608
|
+
): Array<Path>;
|
|
1609
|
+
|
|
1085
1610
|
/**
|
|
1086
1611
|
* Options for {@link glob}.
|
|
1087
1612
|
*/
|
|
@@ -1130,406 +1655,464 @@ declare type GlobOptions = {
|
|
|
1130
1655
|
};
|
|
1131
1656
|
|
|
1132
1657
|
/**
|
|
1133
|
-
*
|
|
1658
|
+
* Prints special ANSI escape characters to stdout which instruct your terminal
|
|
1659
|
+
* emulator to clear the screen and clear your terminal scrollback.
|
|
1134
1660
|
*
|
|
1135
|
-
*
|
|
1136
|
-
* options.
|
|
1137
|
-
*/
|
|
1138
|
-
declare function glob(
|
|
1139
|
-
patterns: string | Array<string>,
|
|
1140
|
-
options?: GlobOptions
|
|
1141
|
-
): Array<Path>;
|
|
1142
|
-
|
|
1143
|
-
/**
|
|
1144
|
-
* Clear the contents and scrollback buffer of the tty by printing special characters into stdout.
|
|
1661
|
+
* Identical to {@link console.clear}.
|
|
1145
1662
|
*/
|
|
1146
1663
|
declare function clear(): void;
|
|
1147
1664
|
|
|
1148
1665
|
interface Console {
|
|
1149
|
-
/**
|
|
1150
|
-
|
|
1666
|
+
/**
|
|
1667
|
+
* Logs its arguments to stdout, with a newline appended.
|
|
1668
|
+
*
|
|
1669
|
+
* Any value can be logged, not just strings. Non-string values will be
|
|
1670
|
+
* formatted using {@link inspect}.
|
|
1671
|
+
*
|
|
1672
|
+
* Functionally identical to {@link console.info}, {@link echo}, and
|
|
1673
|
+
* {@link print}. Contrast with {@link console.error}, which prints to stderr
|
|
1674
|
+
* instead of stdout.
|
|
1675
|
+
*/
|
|
1676
|
+
log(message?: any, ...optionalParams: any[]): void;
|
|
1677
|
+
|
|
1678
|
+
/**
|
|
1679
|
+
* Logs its arguments to stdout, with a newline appended.
|
|
1680
|
+
*
|
|
1681
|
+
* Any value can be logged, not just strings. Non-string values will be
|
|
1682
|
+
* formatted using {@link inspect}.
|
|
1683
|
+
*
|
|
1684
|
+
* Functionally identical to {@link console.log}, {@link echo}, and
|
|
1685
|
+
* {@link print}. Contrast with {@link console.error}, which prints to stderr
|
|
1686
|
+
* instead of stdout.
|
|
1687
|
+
*/
|
|
1688
|
+
info(message?: any, ...optionalParams: any[]): void;
|
|
1689
|
+
|
|
1690
|
+
/**
|
|
1691
|
+
* Logs its arguments to stderr, with a newline appended.
|
|
1692
|
+
*
|
|
1693
|
+
* Any value can be logged, not just strings. Non-string values will be
|
|
1694
|
+
* formatted using {@link inspect}.
|
|
1695
|
+
*
|
|
1696
|
+
* Functionally identical to {@link console.error}. Contrast with
|
|
1697
|
+
* {@link console.log}, which prints to stdout instead of stderr.
|
|
1698
|
+
*/
|
|
1699
|
+
warn(message?: any, ...optionalParams: any[]): void;
|
|
1700
|
+
|
|
1701
|
+
/**
|
|
1702
|
+
* Logs its arguments to stderr, with a newline appended.
|
|
1703
|
+
*
|
|
1704
|
+
* Any value can be logged, not just strings. Non-string values will be
|
|
1705
|
+
* formatted using {@link inspect}.
|
|
1706
|
+
*
|
|
1707
|
+
* Functionally identical to {@link console.warn}. Contrast with
|
|
1708
|
+
* {@link console.log}, which prints to stdout instead of stderr.
|
|
1709
|
+
*/
|
|
1710
|
+
error(message?: any, ...optionalParams: any[]): void;
|
|
1711
|
+
|
|
1712
|
+
/**
|
|
1713
|
+
* Prints special ANSI escape characters to stdout which instruct your terminal
|
|
1714
|
+
* emulator to clear the screen and clear your terminal scrollback.
|
|
1715
|
+
*
|
|
1716
|
+
* Identical to {@link clear}.
|
|
1717
|
+
*/
|
|
1718
|
+
clear(): void;
|
|
1151
1719
|
}
|
|
1152
1720
|
|
|
1721
|
+
declare var console: Console;
|
|
1722
|
+
|
|
1723
|
+
/**
|
|
1724
|
+
* `print` is an alias for {@link console.log}, which prints values to stdout.
|
|
1725
|
+
*
|
|
1726
|
+
* Any value can be logged, not just strings. Non-string values will be
|
|
1727
|
+
* formatted using {@link inspect}.
|
|
1728
|
+
*/
|
|
1729
|
+
declare function print(...args: any): void;
|
|
1730
|
+
|
|
1153
1731
|
/**
|
|
1154
|
-
*
|
|
1732
|
+
* Removes ANSI control characters from a string.
|
|
1155
1733
|
*/
|
|
1156
1734
|
declare function stripAnsi(input: string | number | Path): string;
|
|
1157
1735
|
|
|
1158
1736
|
/**
|
|
1159
|
-
*
|
|
1737
|
+
* Wraps a string in double quotes, and escapes any double-quotes inside using `\"`.
|
|
1160
1738
|
*/
|
|
1161
1739
|
declare function quote(input: string | number | Path): string;
|
|
1162
1740
|
|
|
1163
1741
|
// Colors
|
|
1164
1742
|
|
|
1165
|
-
/**
|
|
1743
|
+
/** Wraps a string with the ANSI control characters that will make it print as black text. */
|
|
1166
1744
|
declare function black(input: string | number | Path): string;
|
|
1167
|
-
/**
|
|
1745
|
+
/** Wraps a string with the ANSI control characters that will make it print as red text. */
|
|
1168
1746
|
declare function red(input: string | number | Path): string;
|
|
1169
|
-
/**
|
|
1747
|
+
/** Wraps a string with the ANSI control characters that will make it print as green text. */
|
|
1170
1748
|
declare function green(input: string | number | Path): string;
|
|
1171
|
-
/**
|
|
1749
|
+
/** Wraps a string with the ANSI control characters that will make it print as yellow text. */
|
|
1172
1750
|
declare function yellow(input: string | number | Path): string;
|
|
1173
|
-
/**
|
|
1751
|
+
/** Wraps a string with the ANSI control characters that will make it print as blue text. */
|
|
1174
1752
|
declare function blue(input: string | number | Path): string;
|
|
1175
|
-
/**
|
|
1753
|
+
/** Wraps a string with the ANSI control characters that will make it print as magenta text. */
|
|
1176
1754
|
declare function magenta(input: string | number | Path): string;
|
|
1177
|
-
/**
|
|
1755
|
+
/** Wraps a string with the ANSI control characters that will make it print as cyan text. */
|
|
1178
1756
|
declare function cyan(input: string | number | Path): string;
|
|
1179
|
-
/**
|
|
1757
|
+
/** Wraps a string with the ANSI control characters that will make it print as white text. */
|
|
1180
1758
|
declare function white(input: string | number | Path): string;
|
|
1181
|
-
/**
|
|
1759
|
+
/** Wraps a string with the ANSI control characters that will make it print as gray text. (Alias for {@link grey}.) */
|
|
1182
1760
|
declare function gray(input: string | number | Path): string;
|
|
1183
|
-
/**
|
|
1761
|
+
/** Wraps a string with the ANSI control characters that will make it print as grey text. (Alias for {@link gray}.) */
|
|
1184
1762
|
declare function grey(input: string | number | Path): string;
|
|
1185
1763
|
|
|
1186
1764
|
// Background Colors
|
|
1187
1765
|
|
|
1188
|
-
/**
|
|
1766
|
+
/** Wraps a string with the ANSI control characters that will make it have a black background when printed. */
|
|
1189
1767
|
declare function bgBlack(input: string | number | Path): string;
|
|
1190
|
-
/**
|
|
1768
|
+
/** Wraps a string with the ANSI control characters that will make it have a red background when printed. */
|
|
1191
1769
|
declare function bgRed(input: string | number | Path): string;
|
|
1192
|
-
/**
|
|
1770
|
+
/** Wraps a string with the ANSI control characters that will make it have a green background when printed. */
|
|
1193
1771
|
declare function bgGreen(input: string | number | Path): string;
|
|
1194
|
-
/**
|
|
1772
|
+
/** Wraps a string with the ANSI control characters that will make it have a yellow background when printed. */
|
|
1195
1773
|
declare function bgYellow(input: string | number | Path): string;
|
|
1196
|
-
/**
|
|
1774
|
+
/** Wraps a string with the ANSI control characters that will make it have a blue background when printed. */
|
|
1197
1775
|
declare function bgBlue(input: string | number | Path): string;
|
|
1198
|
-
/**
|
|
1776
|
+
/** Wraps a string with the ANSI control characters that will make it have a magenta background when printed. */
|
|
1199
1777
|
declare function bgMagenta(input: string | number | Path): string;
|
|
1200
|
-
/**
|
|
1778
|
+
/** Wraps a string with the ANSI control characters that will make it have a cyan background when printed. */
|
|
1201
1779
|
declare function bgCyan(input: string | number | Path): string;
|
|
1202
|
-
/**
|
|
1780
|
+
/** Wraps a string with the ANSI control characters that will make it have a white background when printed. */
|
|
1203
1781
|
declare function bgWhite(input: string | number | Path): string;
|
|
1204
1782
|
|
|
1205
1783
|
// Modifiers
|
|
1206
1784
|
|
|
1207
|
-
/**
|
|
1785
|
+
/** Prefixes a string with the ANSI control character that resets all styling. */
|
|
1208
1786
|
declare function reset(input: string | number | Path): string;
|
|
1209
|
-
/**
|
|
1787
|
+
/** Wraps a string with the ANSI control characters that will make it print with a bold style. */
|
|
1210
1788
|
declare function bold(input: string | number | Path): string;
|
|
1211
|
-
/**
|
|
1789
|
+
/** Wraps a string with the ANSI control characters that will make it print with a dimmed style. */
|
|
1212
1790
|
declare function dim(input: string | number | Path): string;
|
|
1213
|
-
/**
|
|
1791
|
+
/** Wraps a string with the ANSI control characters that will make it print italicized. */
|
|
1214
1792
|
declare function italic(input: string | number | Path): string;
|
|
1215
|
-
/**
|
|
1793
|
+
/** Wraps a string with the ANSI control characters that will make it print underlined. */
|
|
1216
1794
|
declare function underline(input: string | number | Path): string;
|
|
1217
|
-
/**
|
|
1795
|
+
/** Wraps a string with ANSI control characters that will make it print with its foreground (text) and background colors swapped. */
|
|
1218
1796
|
declare function inverse(input: string | number | Path): string;
|
|
1219
|
-
/**
|
|
1797
|
+
/** Wraps a string with ANSI control characters that will make it print as hidden. */
|
|
1220
1798
|
declare function hidden(input: string | number | Path): string;
|
|
1221
|
-
/**
|
|
1799
|
+
/** Wraps a string with the ANSI control characters that will make it print with a horizontal line through its center. */
|
|
1222
1800
|
declare function strikethrough(input: string | number | Path): string;
|
|
1223
1801
|
|
|
1224
|
-
/**
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
/** Split `str` on newline and then return lines NOT matching `pattern`. */
|
|
1237
|
-
(
|
|
1238
|
-
str: string,
|
|
1239
|
-
pattern: string | RegExp,
|
|
1240
|
-
options: { inverse: true }
|
|
1241
|
-
): Array<string>;
|
|
1242
|
-
|
|
1243
|
-
/** Split `str` on newline and then return lines matching `pattern`. */
|
|
1244
|
-
(
|
|
1245
|
-
str: string,
|
|
1246
|
-
pattern: string | RegExp,
|
|
1247
|
-
options: { details: false }
|
|
1248
|
-
): Array<string>;
|
|
1249
|
-
|
|
1250
|
-
/** Split `str` on newline and then return lines matching `pattern`. */
|
|
1251
|
-
(
|
|
1252
|
-
str: string,
|
|
1253
|
-
pattern: string | RegExp,
|
|
1254
|
-
options: { inverse: false; details: false }
|
|
1255
|
-
): Array<string>;
|
|
1256
|
-
|
|
1257
|
-
/** Split `str` on newline and then return lines NOT matching `pattern`. */
|
|
1258
|
-
(
|
|
1259
|
-
str: string,
|
|
1260
|
-
pattern: string | RegExp,
|
|
1261
|
-
options: { inverse: true; details: false }
|
|
1262
|
-
): Array<string>;
|
|
1263
|
-
|
|
1264
|
-
/** Split `str` on newline and then return info about lines matching `pattern`. */
|
|
1265
|
-
(str: string, pattern: string | RegExp, options: { details: true }): Array<{
|
|
1266
|
-
lineNumber: number;
|
|
1267
|
-
lineContent: string;
|
|
1268
|
-
matches: RegExpMatchArray;
|
|
1269
|
-
}>;
|
|
1270
|
-
|
|
1271
|
-
/** Split `str` on newline and then return info about lines matching `pattern`. */
|
|
1272
|
-
(
|
|
1273
|
-
str: string,
|
|
1274
|
-
pattern: string | RegExp,
|
|
1275
|
-
options: { inverse: false; details: true }
|
|
1276
|
-
): Array<string>;
|
|
1277
|
-
|
|
1278
|
-
/** Split `str` on newline and then return info about lines NOT matching `pattern`. */
|
|
1279
|
-
(
|
|
1280
|
-
str: string,
|
|
1281
|
-
pattern: string | RegExp,
|
|
1282
|
-
options: { inverse: true; details: true }
|
|
1283
|
-
): Array<{
|
|
1284
|
-
lineNumber: number;
|
|
1285
|
-
lineContent: string;
|
|
1286
|
-
matches: RegExpMatchArray;
|
|
1287
|
-
}>;
|
|
1288
|
-
};
|
|
1289
|
-
|
|
1290
|
-
/** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
|
|
1291
|
-
declare const grepFile: {
|
|
1292
|
-
/** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
|
|
1293
|
-
(path: string | Path, pattern: string | RegExp): Array<string>;
|
|
1294
|
-
|
|
1295
|
-
/** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
|
|
1296
|
-
(
|
|
1297
|
-
path: string | Path,
|
|
1298
|
-
pattern: string | RegExp,
|
|
1299
|
-
options: { inverse: false }
|
|
1300
|
-
): Array<string>;
|
|
1301
|
-
|
|
1302
|
-
/** Read the content at `path`, split it on newline, and then return lines NOT matching `pattern`. */
|
|
1303
|
-
(
|
|
1304
|
-
path: string | Path,
|
|
1305
|
-
pattern: string | RegExp,
|
|
1306
|
-
options: { inverse: true }
|
|
1307
|
-
): Array<string>;
|
|
1308
|
-
|
|
1309
|
-
/** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
|
|
1310
|
-
(
|
|
1311
|
-
path: string | Path,
|
|
1312
|
-
pattern: string | RegExp,
|
|
1313
|
-
options: { details: false }
|
|
1314
|
-
): Array<string>;
|
|
1315
|
-
|
|
1316
|
-
/** Read the content at `path`, split it on newline, and then return lines matching `pattern`. */
|
|
1317
|
-
(
|
|
1318
|
-
path: string | Path,
|
|
1319
|
-
pattern: string | RegExp,
|
|
1320
|
-
options: { inverse: false; details: false }
|
|
1321
|
-
): Array<string>;
|
|
1322
|
-
|
|
1323
|
-
/** Read the content at `path`, split it on newline, and then return lines NOT matching `pattern`. */
|
|
1802
|
+
/**
|
|
1803
|
+
* Splits the string passed into it on `\n` and then returns the lines matching
|
|
1804
|
+
* the specified pattern, as an array of strings or detail objects.
|
|
1805
|
+
*
|
|
1806
|
+
* @param str - The string to search through.
|
|
1807
|
+
* @param pattern - The pattern to find. Can be a string or a RegExp.
|
|
1808
|
+
* @param options - Options which control matching behavior.
|
|
1809
|
+
*
|
|
1810
|
+
* See also {@link grepFile} and {@link String.prototype.grep}.
|
|
1811
|
+
*/
|
|
1812
|
+
declare const grepString: {
|
|
1324
1813
|
(
|
|
1325
|
-
|
|
1814
|
+
str: string,
|
|
1326
1815
|
pattern: string | RegExp,
|
|
1327
|
-
options:
|
|
1328
|
-
): Array<
|
|
1816
|
+
options: GrepOptions & { details: true }
|
|
1817
|
+
): Array<GrepMatchDetail>;
|
|
1329
1818
|
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
path: string | Path,
|
|
1333
|
-
pattern: string | RegExp,
|
|
1334
|
-
options: { details: true }
|
|
1335
|
-
): Array<{
|
|
1336
|
-
lineNumber: number;
|
|
1337
|
-
lineContent: string;
|
|
1338
|
-
matches: RegExpMatchArray;
|
|
1339
|
-
}>;
|
|
1819
|
+
(str: string, pattern: string | RegExp, options?: GrepOptions): Array<string>;
|
|
1820
|
+
};
|
|
1340
1821
|
|
|
1341
|
-
|
|
1822
|
+
/**
|
|
1823
|
+
* Reads the file content at `path`, splits it on `\n`, and then returns the
|
|
1824
|
+
* lines matching the specified pattern, as an array of strings or detail objects.
|
|
1825
|
+
*
|
|
1826
|
+
* @param str - The string to search through.
|
|
1827
|
+
* @param pattern - The pattern to find. Can be a string or a RegExp.
|
|
1828
|
+
* @param options - Options which control matching behavior.
|
|
1829
|
+
*
|
|
1830
|
+
* See also {@link grepString} and {@link String.prototype.grep}.
|
|
1831
|
+
*/
|
|
1832
|
+
declare const grepFile: {
|
|
1342
1833
|
(
|
|
1343
1834
|
path: string | Path,
|
|
1344
1835
|
pattern: string | RegExp,
|
|
1345
|
-
options:
|
|
1346
|
-
): Array<
|
|
1836
|
+
options: GrepOptions & { details: true }
|
|
1837
|
+
): Array<GrepMatchDetail>;
|
|
1347
1838
|
|
|
1348
|
-
/** Read the content at `path`, split it on newline, and then return info about lines NOT matching `pattern`. */
|
|
1349
1839
|
(
|
|
1350
1840
|
path: string | Path,
|
|
1351
1841
|
pattern: string | RegExp,
|
|
1352
|
-
options
|
|
1353
|
-
): Array<
|
|
1354
|
-
lineNumber: number;
|
|
1355
|
-
lineContent: string;
|
|
1356
|
-
matches: RegExpMatchArray;
|
|
1357
|
-
}>;
|
|
1842
|
+
options?: GrepOptions
|
|
1843
|
+
): Array<string>;
|
|
1358
1844
|
};
|
|
1359
1845
|
|
|
1360
1846
|
interface String {
|
|
1361
1847
|
// Same as grepString but without the first argument.
|
|
1848
|
+
/**
|
|
1849
|
+
* Splits the target string on `\n` and then returns the lines matching the
|
|
1850
|
+
* specified pattern, as an array of strings or detail objects.
|
|
1851
|
+
*
|
|
1852
|
+
* @param str - The string to search through.
|
|
1853
|
+
* @param pattern - The pattern to find. Can be a string or a RegExp.
|
|
1854
|
+
* @param options - Options which control matching behavior.
|
|
1855
|
+
*
|
|
1856
|
+
* See also {@link grepString} and {@link grepFile}.
|
|
1857
|
+
*/
|
|
1362
1858
|
grep: {
|
|
1363
|
-
/** Split the string on newline and then return lines matching `pattern`. */
|
|
1364
|
-
(pattern: string | RegExp): Array<string>;
|
|
1365
|
-
|
|
1366
|
-
/** Split the string on newline and then return lines matching `pattern`. */
|
|
1367
|
-
(pattern: string | RegExp, options: { inverse: false }): Array<string>;
|
|
1368
|
-
|
|
1369
|
-
/** Split the string on newline and then return lines NOT matching `pattern`. */
|
|
1370
|
-
(pattern: string | RegExp, options: { inverse: true }): Array<string>;
|
|
1371
|
-
|
|
1372
|
-
/** Split the string on newline and then return lines matching `pattern`. */
|
|
1373
|
-
(pattern: string | RegExp, options: { details: false }): Array<string>;
|
|
1374
|
-
|
|
1375
|
-
/** Split the string on newline and then return lines matching `pattern`. */
|
|
1376
|
-
(
|
|
1377
|
-
pattern: string | RegExp,
|
|
1378
|
-
options: { inverse: false; details: false }
|
|
1379
|
-
): Array<string>;
|
|
1380
|
-
|
|
1381
|
-
/** Split the string on newline and then return lines NOT matching `pattern`. */
|
|
1382
|
-
(
|
|
1383
|
-
pattern: string | RegExp,
|
|
1384
|
-
options: { inverse: true; details: false }
|
|
1385
|
-
): Array<string>;
|
|
1386
|
-
|
|
1387
|
-
/** Split the string on newline and then return info about lines matching `pattern`. */
|
|
1388
|
-
(pattern: string | RegExp, options: { details: true }): Array<{
|
|
1389
|
-
lineNumber: number;
|
|
1390
|
-
lineContent: string;
|
|
1391
|
-
matches: RegExpMatchArray;
|
|
1392
|
-
}>;
|
|
1393
|
-
|
|
1394
|
-
/** Split the string on newline and then return info about lines matching `pattern`. */
|
|
1395
1859
|
(
|
|
1396
1860
|
pattern: string | RegExp,
|
|
1397
|
-
options:
|
|
1398
|
-
): Array<
|
|
1861
|
+
options: GrepOptions & { details: true }
|
|
1862
|
+
): Array<GrepMatchDetail>;
|
|
1399
1863
|
|
|
1400
|
-
|
|
1401
|
-
(
|
|
1402
|
-
pattern: string | RegExp,
|
|
1403
|
-
options: { inverse: true; details: true }
|
|
1404
|
-
): Array<{
|
|
1405
|
-
lineNumber: number;
|
|
1406
|
-
lineContent: string;
|
|
1407
|
-
matches: RegExpMatchArray;
|
|
1408
|
-
}>;
|
|
1864
|
+
(pattern: string | RegExp, options?: GrepOptions): Array<string>;
|
|
1409
1865
|
};
|
|
1410
1866
|
}
|
|
1411
1867
|
|
|
1412
|
-
declare
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
? TypeValidator<number>
|
|
1419
|
-
: V extends BooleanConstructor
|
|
1420
|
-
? TypeValidator<boolean>
|
|
1421
|
-
: V extends BigIntConstructor
|
|
1422
|
-
? TypeValidator<BigInt>
|
|
1423
|
-
: V extends SymbolConstructor
|
|
1424
|
-
? TypeValidator<Symbol>
|
|
1425
|
-
: V extends RegExpConstructor
|
|
1426
|
-
? TypeValidator<RegExp>
|
|
1427
|
-
: V extends ArrayConstructor
|
|
1428
|
-
? TypeValidator<Array<unknown>>
|
|
1429
|
-
: V extends SetConstructor
|
|
1430
|
-
? TypeValidator<Set<unknown>>
|
|
1431
|
-
: V extends MapConstructor
|
|
1432
|
-
? TypeValidator<Map<unknown, unknown>>
|
|
1433
|
-
: V extends ObjectConstructor
|
|
1434
|
-
? TypeValidator<{
|
|
1435
|
-
[key: string | number | symbol]: unknown;
|
|
1436
|
-
}>
|
|
1437
|
-
: V extends DateConstructor
|
|
1438
|
-
? TypeValidator<Date>
|
|
1439
|
-
: V extends FunctionConstructor
|
|
1440
|
-
? TypeValidator<Function>
|
|
1441
|
-
: V extends ArrayBufferConstructor
|
|
1442
|
-
? TypeValidator<ArrayBuffer>
|
|
1443
|
-
: V extends SharedArrayBufferConstructor
|
|
1444
|
-
? TypeValidator<SharedArrayBuffer>
|
|
1445
|
-
: V extends DataViewConstructor
|
|
1446
|
-
? TypeValidator<DataView>
|
|
1447
|
-
: V extends Int8ArrayConstructor
|
|
1448
|
-
? TypeValidator<Int8Array>
|
|
1449
|
-
: V extends Uint8ArrayConstructor
|
|
1450
|
-
? TypeValidator<Uint8Array>
|
|
1451
|
-
: V extends Uint8ClampedArrayConstructor
|
|
1452
|
-
? TypeValidator<Uint8ClampedArray>
|
|
1453
|
-
: V extends Int16ArrayConstructor
|
|
1454
|
-
? TypeValidator<Int16Array>
|
|
1455
|
-
: V extends Uint16ArrayConstructor
|
|
1456
|
-
? TypeValidator<Uint16Array>
|
|
1457
|
-
: V extends Int32ArrayConstructor
|
|
1458
|
-
? TypeValidator<Int32Array>
|
|
1459
|
-
: V extends Uint32ArrayConstructor
|
|
1460
|
-
? TypeValidator<Uint32Array>
|
|
1461
|
-
: V extends Float32ArrayConstructor
|
|
1462
|
-
? TypeValidator<Float32Array>
|
|
1463
|
-
: V extends Float64ArrayConstructor
|
|
1464
|
-
? TypeValidator<Float64Array>
|
|
1465
|
-
: V extends RegExp
|
|
1466
|
-
? TypeValidator<string>
|
|
1467
|
-
: V extends {}
|
|
1468
|
-
? TypeValidator<{
|
|
1469
|
-
[key in keyof V]: CoerceToTypeValidator<V[key]>;
|
|
1470
|
-
}>
|
|
1471
|
-
: V extends []
|
|
1472
|
-
? TypeValidator<[]>
|
|
1473
|
-
: V extends [any]
|
|
1474
|
-
? TypeValidator<Array<CoerceToTypeValidator<V[0]>>>
|
|
1475
|
-
: V extends Array<any>
|
|
1476
|
-
? TypeValidator<Array<unknown>>
|
|
1477
|
-
: V extends {
|
|
1478
|
-
new (...args: any): any;
|
|
1479
|
-
}
|
|
1480
|
-
? TypeValidator<InstanceType<V>>
|
|
1481
|
-
: TypeValidator<V>;
|
|
1868
|
+
declare interface GrepOptions {
|
|
1869
|
+
/**
|
|
1870
|
+
* When `inverse` is true, the grep function returns those lines which DON'T
|
|
1871
|
+
* match the pattern, instead of those which do. Defaults to `false`.
|
|
1872
|
+
*/
|
|
1873
|
+
inverse?: boolean;
|
|
1482
1874
|
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
| RegExp
|
|
1491
|
-
| StringConstructor
|
|
1492
|
-
| NumberConstructor
|
|
1493
|
-
| BooleanConstructor
|
|
1494
|
-
| BigIntConstructor
|
|
1495
|
-
| SymbolConstructor
|
|
1496
|
-
| RegExpConstructor
|
|
1497
|
-
| ArrayConstructor
|
|
1498
|
-
| SetConstructor
|
|
1499
|
-
| MapConstructor
|
|
1500
|
-
| ObjectConstructor
|
|
1501
|
-
| DateConstructor
|
|
1502
|
-
| FunctionConstructor
|
|
1503
|
-
| ArrayBufferConstructor
|
|
1504
|
-
| SharedArrayBufferConstructor
|
|
1505
|
-
| DataViewConstructor
|
|
1506
|
-
| Int8ArrayConstructor
|
|
1507
|
-
| Uint8ArrayConstructor
|
|
1508
|
-
| Uint8ClampedArrayConstructor
|
|
1509
|
-
| Int16ArrayConstructor
|
|
1510
|
-
| Uint16ArrayConstructor
|
|
1511
|
-
| Int32ArrayConstructor
|
|
1512
|
-
| Uint32ArrayConstructor
|
|
1513
|
-
| Float32ArrayConstructor
|
|
1514
|
-
| Float64ArrayConstructor
|
|
1515
|
-
| {}
|
|
1516
|
-
| []
|
|
1517
|
-
| [any]
|
|
1518
|
-
| Array<any>
|
|
1519
|
-
| {
|
|
1520
|
-
new (...args: any): any;
|
|
1521
|
-
};
|
|
1875
|
+
/**
|
|
1876
|
+
* When `details` is true, the grep function returns an array of
|
|
1877
|
+
* {@link GrepMatchDetail} objects instead of an array of strings. Defaults to
|
|
1878
|
+
* `false`.
|
|
1879
|
+
*/
|
|
1880
|
+
details?: boolean;
|
|
1881
|
+
}
|
|
1522
1882
|
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
:
|
|
1883
|
+
/**
|
|
1884
|
+
* When `grepString`, `grepFile`, or `String.prototype.grep` are called with the
|
|
1885
|
+
* `{ details: true }` option set, an Array of `GrepMatchDetail` objects is
|
|
1886
|
+
* returned.
|
|
1887
|
+
*/
|
|
1888
|
+
declare interface GrepMatchDetail {
|
|
1889
|
+
lineNumber: number;
|
|
1890
|
+
lineContent: string;
|
|
1891
|
+
matches: RegExpMatchArray;
|
|
1892
|
+
}
|
|
1532
1893
|
|
|
1894
|
+
/**
|
|
1895
|
+
* The `types` namespace object contains various functions which can be used to
|
|
1896
|
+
* identify the type of a value at runtime. It is based on
|
|
1897
|
+
* [pheno](https://github.com/suchipi/pheno), with some yavascript-specific
|
|
1898
|
+
* extensions.
|
|
1899
|
+
*
|
|
1900
|
+
* ## Usage
|
|
1901
|
+
*
|
|
1902
|
+
* To check that a value is of a type, use `is`. To assert that a value is of a
|
|
1903
|
+
* type, use `assert.type`:
|
|
1904
|
+
*
|
|
1905
|
+
* ```ts
|
|
1906
|
+
* is("hi", types.string); // true
|
|
1907
|
+
* is("hi", types.number); // false
|
|
1908
|
+
* is({ blah: 42 }, types.objectWithProperties({ blah: types.number })); // true
|
|
1909
|
+
*
|
|
1910
|
+
* assert.type("hi", types.string);
|
|
1911
|
+
* assert.type("hi", types.number); // throws
|
|
1912
|
+
* assert.type({ blah: 42 }, types.objectWithProperties({ blah: types.number }));
|
|
1913
|
+
* ```
|
|
1914
|
+
*
|
|
1915
|
+
* In many cases, you can use a "normal" JavaScript value for the type instead
|
|
1916
|
+
* of something from the `types` namespace. For instance, the following code
|
|
1917
|
+
* block is equivalent to the previous one:
|
|
1918
|
+
*
|
|
1919
|
+
* ```ts
|
|
1920
|
+
* is("hi", String); // true
|
|
1921
|
+
* is("hi", Number); // false
|
|
1922
|
+
* is({ blah: 42 }, { blah: Number }); // true
|
|
1923
|
+
*
|
|
1924
|
+
* assert.type("hi", String);
|
|
1925
|
+
* assert.type("hi", Number); // throws
|
|
1926
|
+
* assert.type({ blah: 42 }, { blah: Number });
|
|
1927
|
+
* ```
|
|
1928
|
+
*
|
|
1929
|
+
* For more info about using "normal" values, see the "Coercion" heading below.
|
|
1930
|
+
*
|
|
1931
|
+
* ## Explanation
|
|
1932
|
+
*
|
|
1933
|
+
* There are two kinds of function properties found on the `types` namespace:
|
|
1934
|
+
* those which return a boolean, and those which return a function. Functions
|
|
1935
|
+
* which return a boolean are called "type validators", and can be used to check
|
|
1936
|
+
* the type of a value. For example, `types.number` is a type validator:
|
|
1937
|
+
*
|
|
1938
|
+
* ```ts
|
|
1939
|
+
* is(42, types.number); // returns true
|
|
1940
|
+
* ```
|
|
1941
|
+
*
|
|
1942
|
+
* The other kind of function is a function which returns a function. These are
|
|
1943
|
+
* called "type validator constructors", because the function they return is a
|
|
1944
|
+
* type validator. They are used to construct complex type validators. For
|
|
1945
|
+
* example, `types.exactString` is a type validator constructor:
|
|
1946
|
+
*
|
|
1947
|
+
* ```ts
|
|
1948
|
+
* const myType = types.exactString("potato");
|
|
1949
|
+
* // myType is a function which returns true or false
|
|
1950
|
+
*
|
|
1951
|
+
* is("eggplant", myType); // returns false
|
|
1952
|
+
* is("potato", myType); // returns true
|
|
1953
|
+
* ```
|
|
1954
|
+
*
|
|
1955
|
+
* ## List of Functions
|
|
1956
|
+
*
|
|
1957
|
+
* ### Type Validators
|
|
1958
|
+
*
|
|
1959
|
+
* Here is a list of all the type validators:
|
|
1960
|
+
*
|
|
1961
|
+
* - `any`
|
|
1962
|
+
* - `anyArray`
|
|
1963
|
+
* - `anyFunction`
|
|
1964
|
+
* - `anyMap`
|
|
1965
|
+
* - `anyObject`
|
|
1966
|
+
* - `anySet`
|
|
1967
|
+
* - `anyTypeValidator`
|
|
1968
|
+
* - `array` (alias of `arrayOfUnknown`)
|
|
1969
|
+
* - `arrayOfAny`
|
|
1970
|
+
* - `arrayOfUnknown`
|
|
1971
|
+
* - `Array` (alias of `arrayOfUnknown`)
|
|
1972
|
+
* - `bigint`
|
|
1973
|
+
* - `BigInt` (alias of `bigint`)
|
|
1974
|
+
* - `boolean`
|
|
1975
|
+
* - `Boolean` (alias of `boolean`)
|
|
1976
|
+
* - `Date`
|
|
1977
|
+
* - `Error`
|
|
1978
|
+
* - `false`
|
|
1979
|
+
* - `falsy`
|
|
1980
|
+
* - `Function` (alias of `unknownFunction`)
|
|
1981
|
+
* - `Infinity`
|
|
1982
|
+
* - `integer`
|
|
1983
|
+
* - `map` (alias of `unknownMap`)
|
|
1984
|
+
* - `Map` (alias of `unknownMap`)
|
|
1985
|
+
* - `NaN`
|
|
1986
|
+
* - `NegativeInfinity`
|
|
1987
|
+
* - `never`
|
|
1988
|
+
* - `nonNullOrUndefined`
|
|
1989
|
+
* - `null`
|
|
1990
|
+
* - `nullish`
|
|
1991
|
+
* - `void` (alias of `nullish`)
|
|
1992
|
+
* - `number` (doesn't include NaN, Infinity, or -Infinity)
|
|
1993
|
+
* - `Number` (alias of `number`)
|
|
1994
|
+
* - `numberIncludingNanAndInfinities`
|
|
1995
|
+
* - `object` (alias of `unknownObject`)
|
|
1996
|
+
* - `Object` (alias of `unknownObject`)
|
|
1997
|
+
* - `objectOrNull`
|
|
1998
|
+
* - `RegExp`
|
|
1999
|
+
* - `set` (alias of `unknownSet`)
|
|
2000
|
+
* - `Set` (alias of `unknownSet`)
|
|
2001
|
+
* - `string`
|
|
2002
|
+
* - `String` (alias of `string`)
|
|
2003
|
+
* - `Symbol`
|
|
2004
|
+
* - `symbol` (alias of `Symbol`)
|
|
2005
|
+
* - `true`
|
|
2006
|
+
* - `truthy`
|
|
2007
|
+
* - `undefined`
|
|
2008
|
+
* - `unknown`
|
|
2009
|
+
* - `unknownFunction`
|
|
2010
|
+
* - `unknownMap`
|
|
2011
|
+
* - `unknownObject`
|
|
2012
|
+
* - `unknownSet`
|
|
2013
|
+
* - `unknownTypeValidator`
|
|
2014
|
+
* - `ArrayBuffer`
|
|
2015
|
+
* - `SharedArrayBuffer`
|
|
2016
|
+
* - `DataView`
|
|
2017
|
+
* - `TypedArray`
|
|
2018
|
+
* - `Int8Array`
|
|
2019
|
+
* - `Uint8Array`
|
|
2020
|
+
* - `Uint8ClampedArray`
|
|
2021
|
+
* - `Int16Array`
|
|
2022
|
+
* - `Uint16Array`
|
|
2023
|
+
* - `Int32Array`
|
|
2024
|
+
* - `Uint32Array`
|
|
2025
|
+
* - `Float32Array`
|
|
2026
|
+
* - `Float64Array`
|
|
2027
|
+
* - `FILE`
|
|
2028
|
+
* - `Path`
|
|
2029
|
+
* - `JSX.Element` (alias of `JSX.unknownElement`)
|
|
2030
|
+
* - `JSX.unknownElement`
|
|
2031
|
+
* - `JSX.anyElement`
|
|
2032
|
+
* - `JSX.Fragment`
|
|
2033
|
+
*
|
|
2034
|
+
* ### Type Validator Constructors
|
|
2035
|
+
*
|
|
2036
|
+
* And all the type validator constructors:
|
|
2037
|
+
*
|
|
2038
|
+
* - `and`
|
|
2039
|
+
* - `arrayOf`
|
|
2040
|
+
* - `exactBigInt`
|
|
2041
|
+
* - `exactNumber`
|
|
2042
|
+
* - `exactString`
|
|
2043
|
+
* - `exactSymbol`
|
|
2044
|
+
* - `hasClassName`
|
|
2045
|
+
* - `hasToStringTag`
|
|
2046
|
+
* - `instanceOf`
|
|
2047
|
+
* - `intersection`
|
|
2048
|
+
* - `mapOf`
|
|
2049
|
+
* - `mappingObjectOf`
|
|
2050
|
+
* - `maybe`
|
|
2051
|
+
* - `objectWithOnlyTheseProperties`
|
|
2052
|
+
* - `objectWithProperties`
|
|
2053
|
+
* - `or`
|
|
2054
|
+
* - `optional`
|
|
2055
|
+
* - `partialObjectWithProperties`
|
|
2056
|
+
* - `record`
|
|
2057
|
+
* - `setOf`
|
|
2058
|
+
* - `stringMatching`
|
|
2059
|
+
* - `symbolFor`
|
|
2060
|
+
* - `union`
|
|
2061
|
+
*
|
|
2062
|
+
* ## Coercion
|
|
2063
|
+
*
|
|
2064
|
+
* There is also a function, `types.coerce`, which returns an appropriate type
|
|
2065
|
+
* validator value for a given input value, using the following logic:
|
|
2066
|
+
*
|
|
2067
|
+
* | Input value | Output validator |
|
|
2068
|
+
* | ----------------------------- | ---------------------------------- |
|
|
2069
|
+
* | `String` or `string` global | `types.string` |
|
|
2070
|
+
* | `Number` or `number` global | `types.number` |
|
|
2071
|
+
* | `Boolean` or `boolean` global | `types.boolean` |
|
|
2072
|
+
* | `BigInt` or `bigint` global | `types.bigint` |
|
|
2073
|
+
* | `Symbol` global | `types.Symbol` |
|
|
2074
|
+
* | `RegExp` global | `types.RegExp` |
|
|
2075
|
+
* | `Array` global | `types.arrayOfUnknown` |
|
|
2076
|
+
* | `Set` global | `types.unknownSet` |
|
|
2077
|
+
* | `Map` global | `types.unknownMap` |
|
|
2078
|
+
* | `Object` global | `types.unknownObject` |
|
|
2079
|
+
* | `Date` global | `types.Date` |
|
|
2080
|
+
* | `Function` global | `types.unknownFunction` |
|
|
2081
|
+
* | `ArrayBuffer` global | `types.ArrayBuffer` |
|
|
2082
|
+
* | `SharedArrayBuffer` global | `types.SharedArrayBuffer` |
|
|
2083
|
+
* | `DataView` global | `types.DataView` |
|
|
2084
|
+
* | `Int8Array` global | `types.Int8Array` |
|
|
2085
|
+
* | `Uint8Array` global | `types.Uint8Array` |
|
|
2086
|
+
* | `Uint8ClampedArray` global | `types.Uint8ClampedArray` |
|
|
2087
|
+
* | `Int16Array` global | `types.Int16Array` |
|
|
2088
|
+
* | `Uint16Array` global | `types.Uint16Array` |
|
|
2089
|
+
* | `Int32Array` global | `types.Int32Array` |
|
|
2090
|
+
* | `Uint32Array` global | `types.Uint32Array` |
|
|
2091
|
+
* | `Float32Array` global | `types.Float32Array` |
|
|
2092
|
+
* | `Float64Array` global | `types.Float64Array` |
|
|
2093
|
+
* | `Path` global | `types.Path` |
|
|
2094
|
+
* | Any RegExp value | Validator for matching strings |
|
|
2095
|
+
* | Empty array | Validator for empty arrays |
|
|
2096
|
+
* | Array with one item | Validator for array of that item |
|
|
2097
|
+
* | Array with multiple items | Validator for tuple of those types |
|
|
2098
|
+
* | Class constructor function | Validator for instances of it |
|
|
2099
|
+
* | Any Object value | Validator for same-shaped object |
|
|
2100
|
+
* | null | `types.null` |
|
|
2101
|
+
* | undefined | `types.undefined` |
|
|
2102
|
+
* | true | `types.true` |
|
|
2103
|
+
* | false | `types.false` |
|
|
2104
|
+
* | NaN | `types.NaN` |
|
|
2105
|
+
* | Infinity | `types.Infinity` |
|
|
2106
|
+
* | `-Infinity` | `types.NegativeInfinity` |
|
|
2107
|
+
* | Any string value | `types.exactString(<the value>)` |
|
|
2108
|
+
* | Any 'normal' number value | `types.exactNumber(<the value>)` |
|
|
2109
|
+
* | Any Symbol value | `types.exactSymbol(<the value>)` |
|
|
2110
|
+
* | Any BigInt value | `types.exactBigInt(<the value>)` |
|
|
2111
|
+
*
|
|
2112
|
+
* > All type constructors, as well as `is` and `assert.type`, do coercion
|
|
2113
|
+
* > automatically! This means that in many cases, you do not need to access
|
|
2114
|
+
* > properties from the `types` namespace.
|
|
2115
|
+
*/
|
|
1533
2116
|
declare const types: {
|
|
1534
2117
|
// basic types
|
|
1535
2118
|
any: TypeValidator<any>;
|
|
@@ -2730,28 +3313,195 @@ declare const types: {
|
|
|
2730
3313
|
>;
|
|
2731
3314
|
};
|
|
2732
3315
|
|
|
2733
|
-
coerce: <V extends CoerceableToTypeValidator | TypeValidator<any> | unknown>(
|
|
2734
|
-
value: V
|
|
2735
|
-
) => TypeValidator<UnwrapTypeFromCoerceableOrValidator<V>>;
|
|
3316
|
+
coerce: <V extends CoerceableToTypeValidator | TypeValidator<any> | unknown>(
|
|
3317
|
+
value: V
|
|
3318
|
+
) => TypeValidator<UnwrapTypeFromCoerceableOrValidator<V>>;
|
|
3319
|
+
|
|
3320
|
+
FILE: TypeValidator<FILE>;
|
|
3321
|
+
Path: TypeValidator<Path>;
|
|
3322
|
+
JSX: {
|
|
3323
|
+
unknownElement: TypeValidator<
|
|
3324
|
+
JSX.Element<{ [key: string | symbol | number]: unknown }, unknown>
|
|
3325
|
+
>;
|
|
3326
|
+
anyElement: TypeValidator<JSX.Element<any, any>>;
|
|
3327
|
+
Element: TypeValidator<
|
|
3328
|
+
JSX.Element<{ [key: string | symbol | number]: unknown }, unknown>
|
|
3329
|
+
>;
|
|
3330
|
+
Fragment: TypeValidator<JSX.Fragment>;
|
|
3331
|
+
};
|
|
3332
|
+
};
|
|
3333
|
+
|
|
3334
|
+
declare type TypeValidator<T> = (value: any) => value is T;
|
|
3335
|
+
|
|
3336
|
+
declare type CoerceToTypeValidator<V extends CoerceableToTypeValidator> =
|
|
3337
|
+
V extends StringConstructor
|
|
3338
|
+
? TypeValidator<string>
|
|
3339
|
+
: V extends NumberConstructor
|
|
3340
|
+
? TypeValidator<number>
|
|
3341
|
+
: V extends BooleanConstructor
|
|
3342
|
+
? TypeValidator<boolean>
|
|
3343
|
+
: V extends BigIntConstructor
|
|
3344
|
+
? TypeValidator<BigInt>
|
|
3345
|
+
: V extends SymbolConstructor
|
|
3346
|
+
? TypeValidator<Symbol>
|
|
3347
|
+
: V extends RegExpConstructor
|
|
3348
|
+
? TypeValidator<RegExp>
|
|
3349
|
+
: V extends ArrayConstructor
|
|
3350
|
+
? TypeValidator<Array<unknown>>
|
|
3351
|
+
: V extends SetConstructor
|
|
3352
|
+
? TypeValidator<Set<unknown>>
|
|
3353
|
+
: V extends MapConstructor
|
|
3354
|
+
? TypeValidator<Map<unknown, unknown>>
|
|
3355
|
+
: V extends ObjectConstructor
|
|
3356
|
+
? TypeValidator<{
|
|
3357
|
+
[key: string | number | symbol]: unknown;
|
|
3358
|
+
}>
|
|
3359
|
+
: V extends DateConstructor
|
|
3360
|
+
? TypeValidator<Date>
|
|
3361
|
+
: V extends FunctionConstructor
|
|
3362
|
+
? TypeValidator<Function>
|
|
3363
|
+
: V extends ArrayBufferConstructor
|
|
3364
|
+
? TypeValidator<ArrayBuffer>
|
|
3365
|
+
: V extends SharedArrayBufferConstructor
|
|
3366
|
+
? TypeValidator<SharedArrayBuffer>
|
|
3367
|
+
: V extends DataViewConstructor
|
|
3368
|
+
? TypeValidator<DataView>
|
|
3369
|
+
: V extends Int8ArrayConstructor
|
|
3370
|
+
? TypeValidator<Int8Array>
|
|
3371
|
+
: V extends Uint8ArrayConstructor
|
|
3372
|
+
? TypeValidator<Uint8Array>
|
|
3373
|
+
: V extends Uint8ClampedArrayConstructor
|
|
3374
|
+
? TypeValidator<Uint8ClampedArray>
|
|
3375
|
+
: V extends Int16ArrayConstructor
|
|
3376
|
+
? TypeValidator<Int16Array>
|
|
3377
|
+
: V extends Uint16ArrayConstructor
|
|
3378
|
+
? TypeValidator<Uint16Array>
|
|
3379
|
+
: V extends Int32ArrayConstructor
|
|
3380
|
+
? TypeValidator<Int32Array>
|
|
3381
|
+
: V extends Uint32ArrayConstructor
|
|
3382
|
+
? TypeValidator<Uint32Array>
|
|
3383
|
+
: V extends Float32ArrayConstructor
|
|
3384
|
+
? TypeValidator<Float32Array>
|
|
3385
|
+
: V extends Float64ArrayConstructor
|
|
3386
|
+
? TypeValidator<Float64Array>
|
|
3387
|
+
: V extends RegExp
|
|
3388
|
+
? TypeValidator<string>
|
|
3389
|
+
: V extends {}
|
|
3390
|
+
? TypeValidator<{
|
|
3391
|
+
[key in keyof V]: CoerceToTypeValidator<V[key]>;
|
|
3392
|
+
}>
|
|
3393
|
+
: V extends []
|
|
3394
|
+
? TypeValidator<[]>
|
|
3395
|
+
: V extends [any]
|
|
3396
|
+
? TypeValidator<Array<CoerceToTypeValidator<V[0]>>>
|
|
3397
|
+
: V extends Array<any>
|
|
3398
|
+
? TypeValidator<Array<unknown>>
|
|
3399
|
+
: V extends {
|
|
3400
|
+
new (...args: any): any;
|
|
3401
|
+
}
|
|
3402
|
+
? TypeValidator<InstanceType<V>>
|
|
3403
|
+
: TypeValidator<V>;
|
|
3404
|
+
|
|
3405
|
+
declare type CoerceableToTypeValidator =
|
|
3406
|
+
| boolean
|
|
3407
|
+
| number
|
|
3408
|
+
| string
|
|
3409
|
+
| bigint
|
|
3410
|
+
| undefined
|
|
3411
|
+
| null
|
|
3412
|
+
| RegExp
|
|
3413
|
+
| StringConstructor
|
|
3414
|
+
| NumberConstructor
|
|
3415
|
+
| BooleanConstructor
|
|
3416
|
+
| BigIntConstructor
|
|
3417
|
+
| SymbolConstructor
|
|
3418
|
+
| RegExpConstructor
|
|
3419
|
+
| ArrayConstructor
|
|
3420
|
+
| SetConstructor
|
|
3421
|
+
| MapConstructor
|
|
3422
|
+
| ObjectConstructor
|
|
3423
|
+
| DateConstructor
|
|
3424
|
+
| FunctionConstructor
|
|
3425
|
+
| ArrayBufferConstructor
|
|
3426
|
+
| SharedArrayBufferConstructor
|
|
3427
|
+
| DataViewConstructor
|
|
3428
|
+
| Int8ArrayConstructor
|
|
3429
|
+
| Uint8ArrayConstructor
|
|
3430
|
+
| Uint8ClampedArrayConstructor
|
|
3431
|
+
| Int16ArrayConstructor
|
|
3432
|
+
| Uint16ArrayConstructor
|
|
3433
|
+
| Int32ArrayConstructor
|
|
3434
|
+
| Uint32ArrayConstructor
|
|
3435
|
+
| Float32ArrayConstructor
|
|
3436
|
+
| Float64ArrayConstructor
|
|
3437
|
+
| {}
|
|
3438
|
+
| []
|
|
3439
|
+
| [any]
|
|
3440
|
+
| Array<any>
|
|
3441
|
+
| {
|
|
3442
|
+
new (...args: any): any;
|
|
3443
|
+
};
|
|
2736
3444
|
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
>;
|
|
2747
|
-
Fragment: TypeValidator<JSX.Fragment>;
|
|
2748
|
-
};
|
|
2749
|
-
};
|
|
3445
|
+
declare type UnwrapTypeFromCoerceableOrValidator<
|
|
3446
|
+
V extends CoerceableToTypeValidator | TypeValidator<any> | unknown
|
|
3447
|
+
> = V extends TypeValidator<infer T>
|
|
3448
|
+
? T
|
|
3449
|
+
: V extends CoerceableToTypeValidator
|
|
3450
|
+
? CoerceToTypeValidator<V> extends TypeValidator<infer T>
|
|
3451
|
+
? T
|
|
3452
|
+
: never
|
|
3453
|
+
: unknown;
|
|
2750
3454
|
|
|
2751
3455
|
/**
|
|
2752
|
-
* Returns whether `value` is of type `type`. Useful for validating that values
|
|
3456
|
+
* Returns whether `value` is of type `type`. Useful for validating that values
|
|
3457
|
+
* have the correct type at runtime, in library functions or etc.
|
|
3458
|
+
*
|
|
3459
|
+
* The `type` parameter can be any of the following:
|
|
3460
|
+
*
|
|
3461
|
+
* - a TypeValidator function from the `types` namespace
|
|
3462
|
+
* - a global constructor like `String`, `Number`, `Boolean`, `Set`,
|
|
3463
|
+
* `Int8Array`, etc
|
|
3464
|
+
* - a user-defined class
|
|
3465
|
+
* - a primitive value like `true`, `false`, `null`, or `42`
|
|
3466
|
+
* - a Regular Expression (to match strings that match the regexp)
|
|
3467
|
+
* - an object or array containing any combination of the above
|
|
3468
|
+
*
|
|
3469
|
+
* Note that yavascript has the following global aliases defined, which are also
|
|
3470
|
+
* valid types:
|
|
3471
|
+
*
|
|
3472
|
+
* ```ts
|
|
3473
|
+
* const bigint = BigInt;
|
|
3474
|
+
* const boolean = Boolean;
|
|
3475
|
+
* const number = Number;
|
|
3476
|
+
* const string = String;
|
|
3477
|
+
* const symbol = Symbol;
|
|
3478
|
+
* ```
|
|
2753
3479
|
*
|
|
2754
|
-
*
|
|
3480
|
+
* ## Example
|
|
3481
|
+
*
|
|
3482
|
+
* ```ts
|
|
3483
|
+
* is(42, Number); // true
|
|
3484
|
+
* is(42, number); // true
|
|
3485
|
+
* is(42, types.number); // true
|
|
3486
|
+
*
|
|
3487
|
+
* is(42, String); // false
|
|
3488
|
+
* is(42, Set); // false
|
|
3489
|
+
* is(42, Array); // false
|
|
3490
|
+
*
|
|
3491
|
+
* is(42, 42); // true
|
|
3492
|
+
* is(42, 45); // false
|
|
3493
|
+
*
|
|
3494
|
+
* is({ kind: "success", data: 99 }, { kind: "success" }); // true
|
|
3495
|
+
* ```
|
|
3496
|
+
*
|
|
3497
|
+
* ```ts
|
|
3498
|
+
* // Defined in yavascript/src/api/is
|
|
3499
|
+
* declare function is(value: any, type: TypeValidator<any>): boolean;
|
|
3500
|
+
* ```
|
|
3501
|
+
*
|
|
3502
|
+
* See also {@link types} (which contains {@link TypeValidator}s that can be
|
|
3503
|
+
* used by `is`) and {@link assert.type} (which throws an error instead of
|
|
3504
|
+
* returning a boolean).
|
|
2755
3505
|
*/
|
|
2756
3506
|
declare const is: <T extends TypeValidator<any> | CoerceableToTypeValidator>(
|
|
2757
3507
|
value: any,
|
|
@@ -2759,7 +3509,8 @@ declare const is: <T extends TypeValidator<any> | CoerceableToTypeValidator>(
|
|
|
2759
3509
|
) => value is UnwrapTypeFromCoerceableOrValidator<T>;
|
|
2760
3510
|
|
|
2761
3511
|
/**
|
|
2762
|
-
* Alias to {@link is}, for Civet, because `is` is a
|
|
3512
|
+
* Alias to {@link is}, for when using the Civet language, because `is` is a
|
|
3513
|
+
* reserved keyword in Civet.
|
|
2763
3514
|
*/
|
|
2764
3515
|
declare const _is: typeof is;
|
|
2765
3516
|
|
|
@@ -2778,9 +3529,11 @@ declare const assert: {
|
|
|
2778
3529
|
: ValueType;
|
|
2779
3530
|
|
|
2780
3531
|
/**
|
|
2781
|
-
* Throws an error if
|
|
3532
|
+
* Throws an error if its argument isn't the correct type.
|
|
2782
3533
|
*
|
|
2783
|
-
*
|
|
3534
|
+
* @param value - The value to test the type of
|
|
3535
|
+
* @param type - The type that `value` should be, as either a `TypeValidator` (from the `types.*` namespace) or a value which can be coerced into a `TypeValidator` via the `types.coerce` function, like `String`, `Boolean`, etc.
|
|
3536
|
+
* @param message - An optional error message to use. If unspecified, a generic-but-descriptive message will be used.
|
|
2784
3537
|
*/
|
|
2785
3538
|
type: <T extends TypeValidator<any> | CoerceableToTypeValidator>(
|
|
2786
3539
|
value: any,
|
|
@@ -2789,6 +3542,9 @@ declare const assert: {
|
|
|
2789
3542
|
) => asserts value is UnwrapTypeFromCoerceableOrValidator<T>;
|
|
2790
3543
|
};
|
|
2791
3544
|
|
|
3545
|
+
/**
|
|
3546
|
+
* This API is a work-in-progress and is subject to change at any time.
|
|
3547
|
+
*/
|
|
2792
3548
|
interface InteractivePrompt {
|
|
2793
3549
|
prompt?: () => string;
|
|
2794
3550
|
printInput?: (input: string) => void;
|
|
@@ -2807,6 +3563,9 @@ interface InteractivePrompt {
|
|
|
2807
3563
|
start(): void;
|
|
2808
3564
|
}
|
|
2809
3565
|
|
|
3566
|
+
/**
|
|
3567
|
+
* This API is a work-in-progress and is subject to change at any time.
|
|
3568
|
+
*/
|
|
2810
3569
|
interface InteractivePromptConstructor {
|
|
2811
3570
|
new (
|
|
2812
3571
|
handleInput: (input: string) => void,
|
|
@@ -2829,14 +3588,16 @@ interface InteractivePromptConstructor {
|
|
|
2829
3588
|
prototype: InteractivePrompt;
|
|
2830
3589
|
}
|
|
2831
3590
|
|
|
2832
|
-
/**
|
|
3591
|
+
/**
|
|
3592
|
+
* This API is a work-in-progress and is subject to change at any time.
|
|
3593
|
+
*/
|
|
2833
3594
|
declare var InteractivePrompt: InteractivePromptConstructor;
|
|
2834
3595
|
|
|
2835
3596
|
/**
|
|
2836
3597
|
* Launch the Yavascript REPL (read-eval-print-loop).
|
|
2837
3598
|
*
|
|
2838
3599
|
* @param context Variables to make available as globals within the repl.
|
|
2839
|
-
* @param lang The
|
|
3600
|
+
* @param lang The language to use in the repl. Defaults to "javascript".
|
|
2840
3601
|
*/
|
|
2841
3602
|
declare const startRepl: {
|
|
2842
3603
|
(
|
|
@@ -2863,6 +3624,19 @@ declare const startRepl: {
|
|
|
2863
3624
|
/**
|
|
2864
3625
|
* An object that points to a git repository on disk and provides utility
|
|
2865
3626
|
* methods for getting information from that repo.
|
|
3627
|
+
*
|
|
3628
|
+
* To use it, construct a GitRepo object, passing in the path to the repo:
|
|
3629
|
+
*
|
|
3630
|
+
* ```ts
|
|
3631
|
+
* // The path here is just an example
|
|
3632
|
+
* const repo = new GitRepo("/home/suchipi/Code/yavascript");
|
|
3633
|
+
* ```
|
|
3634
|
+
*
|
|
3635
|
+
* Then, you can use methods/properties on the `repo` object:
|
|
3636
|
+
*
|
|
3637
|
+
* ```ts
|
|
3638
|
+
* console.log(repo.branchName() || repo.commitSHA());
|
|
3639
|
+
* ```
|
|
2866
3640
|
*/
|
|
2867
3641
|
declare class GitRepo {
|
|
2868
3642
|
/**
|
|
@@ -2870,6 +3644,88 @@ declare class GitRepo {
|
|
|
2870
3644
|
* directory ancestry to find a `.git` folder, then returns the Path that
|
|
2871
3645
|
* contains that `.git` folder. If no `.git` folder is found, an error will be
|
|
2872
3646
|
* thrown.
|
|
3647
|
+
*
|
|
3648
|
+
* For example, if you have a git repo at `/home/suchipi/Code/my-project`,
|
|
3649
|
+
* such that `/home/suchipi/Code/my-project/.git` exists, calling
|
|
3650
|
+
* `GitRepo.findRoot("/home/suchipi/Code/my-project/src/index.js")` will
|
|
3651
|
+
* return a `Path` object pointing to `/home/suchipi/Code/my-project`.
|
|
3652
|
+
*
|
|
3653
|
+
* This function can be useful in order to set the current working directory
|
|
3654
|
+
* of a script relative to the root of the git repo the script appears in. By
|
|
3655
|
+
* doing so, the script can be invoked from any directory.
|
|
3656
|
+
*
|
|
3657
|
+
* For instance, consider this theoretical filesystem layout:
|
|
3658
|
+
*
|
|
3659
|
+
* ```
|
|
3660
|
+
* my-project
|
|
3661
|
+
* - src
|
|
3662
|
+
* - my-script.js
|
|
3663
|
+
* - README.md
|
|
3664
|
+
* ```
|
|
3665
|
+
*
|
|
3666
|
+
* If `my-script.js` contained the following content:
|
|
3667
|
+
*
|
|
3668
|
+
* ```ts
|
|
3669
|
+
* #!/usr/bin/env yavascript
|
|
3670
|
+
*
|
|
3671
|
+
* cat("README.md");
|
|
3672
|
+
* ```
|
|
3673
|
+
*
|
|
3674
|
+
* Then running `src/my-script.js` would print the contents of the README as
|
|
3675
|
+
* expected.
|
|
3676
|
+
*
|
|
3677
|
+
* However, suppose someone ran the script from a different folder:
|
|
3678
|
+
*
|
|
3679
|
+
* ```sh
|
|
3680
|
+
* $ cd src
|
|
3681
|
+
* $ ./my-script.js
|
|
3682
|
+
* ```
|
|
3683
|
+
*
|
|
3684
|
+
* Now an error occurs!
|
|
3685
|
+
*
|
|
3686
|
+
* To make the script resilient against this, you can use `cd` at the top of
|
|
3687
|
+
* the script:
|
|
3688
|
+
*
|
|
3689
|
+
* ```ts
|
|
3690
|
+
* #!/usr/bin/env yavascript
|
|
3691
|
+
*
|
|
3692
|
+
* // __dirname is a special variable that refers to the folder the current script is in.
|
|
3693
|
+
* cd(__dirname);
|
|
3694
|
+
* cd("..");
|
|
3695
|
+
*
|
|
3696
|
+
* cat("README.md");
|
|
3697
|
+
* ```
|
|
3698
|
+
*
|
|
3699
|
+
* However, if the location of `my-script.js` later changes, you will have to
|
|
3700
|
+
* remember to update the script. For instance, if `src/my-script.js` got
|
|
3701
|
+
* moved to `src/tools/my-script.js`, you would need to update the script like
|
|
3702
|
+
* so:
|
|
3703
|
+
*
|
|
3704
|
+
* ```ts
|
|
3705
|
+
* #!/usr/bin/env yavascript
|
|
3706
|
+
*
|
|
3707
|
+
* cd(__dirname);
|
|
3708
|
+
* cd("../.."); // Changed this line
|
|
3709
|
+
*
|
|
3710
|
+
* cat("README.md");
|
|
3711
|
+
* ```
|
|
3712
|
+
*
|
|
3713
|
+
* Since `README.md` will always be in the repository root, using
|
|
3714
|
+
* `GitRepo.findRoot` would make the `cd` resilient against file moves:
|
|
3715
|
+
*
|
|
3716
|
+
* ```ts
|
|
3717
|
+
* #!/usr/bin/env yavascript
|
|
3718
|
+
*
|
|
3719
|
+
* cd(GitRepo.findRoot(__dirname));
|
|
3720
|
+
*
|
|
3721
|
+
* cat("README.md");
|
|
3722
|
+
* ```
|
|
3723
|
+
*
|
|
3724
|
+
* Depending on how you anticipate your codebase changing over time, and how
|
|
3725
|
+
* you expect others to use your scripts, it might make sense to use
|
|
3726
|
+
* `cd(__dirname)`, `cd(GitRepo.findRoot(__dirname))`, or no `cd` at all. Pick what
|
|
3727
|
+
* makes the most sense for your situation.
|
|
3728
|
+
*
|
|
2873
3729
|
*/
|
|
2874
3730
|
static findRoot(fromPath: string | Path): Path;
|
|
2875
3731
|
|
|
@@ -2885,9 +3741,24 @@ declare class GitRepo {
|
|
|
2885
3741
|
repoDir: Path;
|
|
2886
3742
|
|
|
2887
3743
|
/**
|
|
2888
|
-
* Returns the
|
|
3744
|
+
* Returns the full SHA-1 hash string associated with the repo's current
|
|
3745
|
+
* commit.
|
|
2889
3746
|
*
|
|
2890
|
-
*
|
|
3747
|
+
* For example:
|
|
3748
|
+
*
|
|
3749
|
+
* ```ts
|
|
3750
|
+
* const repo = new GitRepo(".");
|
|
3751
|
+
* const sha = repo.commitSHA();
|
|
3752
|
+
* console.log(sha);
|
|
3753
|
+
* // "2a0a15f9872406faebcac694562efeae3447a4ba"
|
|
3754
|
+
* ```
|
|
3755
|
+
*
|
|
3756
|
+
* To obtain this information, the command `git rev-parse HEAD` gets run
|
|
3757
|
+
* within the repo's directory.
|
|
3758
|
+
*
|
|
3759
|
+
* > If the repo has unstaged or uncommitted changes, that state will NOT be
|
|
3760
|
+
* > reflected in the SHA-1 hash. As such, it may be desirable to use this
|
|
3761
|
+
* > method in conjunction with `GitRepo.prototype.isWorkingTreeDirty`.
|
|
2891
3762
|
*/
|
|
2892
3763
|
commitSHA(): string;
|
|
2893
3764
|
|
|
@@ -2895,7 +3766,20 @@ declare class GitRepo {
|
|
|
2895
3766
|
* If the commit SHA the git repo is currently pointed at is the tip of a
|
|
2896
3767
|
* named branch, returns the branch name. Otherwise, returns `null`.
|
|
2897
3768
|
*
|
|
2898
|
-
* This is done by running `git rev-parse --abbrev-ref HEAD
|
|
3769
|
+
* This is done by running `git rev-parse --abbrev-ref HEAD` within the repo
|
|
3770
|
+
* directory.
|
|
3771
|
+
*
|
|
3772
|
+
* Example:
|
|
3773
|
+
*
|
|
3774
|
+
* ```ts
|
|
3775
|
+
* const repo = new GitRepo(".");
|
|
3776
|
+
* const branch = repo.branchName();
|
|
3777
|
+
* console.log(branch);
|
|
3778
|
+
* // "main"
|
|
3779
|
+
* ```
|
|
3780
|
+
*
|
|
3781
|
+
* > The most common situation where there is no current branch is when the
|
|
3782
|
+
* > repository is in "detached HEAD" state.
|
|
2899
3783
|
*/
|
|
2900
3784
|
branchName(): string | null;
|
|
2901
3785
|
|
|
@@ -2904,15 +3788,35 @@ declare class GitRepo {
|
|
|
2904
3788
|
* git repo. `true` means there are changes, `false` means there are no
|
|
2905
3789
|
* changes (ie. the repo is clean).
|
|
2906
3790
|
*
|
|
2907
|
-
* This is done by running `git status --quiet
|
|
3791
|
+
* This is done by running `git status --quiet` within the repo directory.
|
|
2908
3792
|
*/
|
|
2909
3793
|
isWorkingTreeDirty(): boolean;
|
|
2910
3794
|
|
|
2911
3795
|
/**
|
|
2912
|
-
* Returns whether the provided path is ignored by
|
|
3796
|
+
* Returns a boolean indicating whether the provided path is ignored by one or
|
|
3797
|
+
* more `.gitignore` files in the repository.
|
|
2913
3798
|
*
|
|
2914
|
-
*
|
|
2915
|
-
*
|
|
3799
|
+
* Example:
|
|
3800
|
+
*
|
|
3801
|
+
* ```ts
|
|
3802
|
+
* const repo = new GitRepo(".");
|
|
3803
|
+
* const ignoreStatus = repo.isIgnored("README.md");
|
|
3804
|
+
* console.log(ignoreStatus);
|
|
3805
|
+
* // false
|
|
3806
|
+
* ```
|
|
3807
|
+
*
|
|
3808
|
+
* To obtain this information, the command `git check-ignore <the-path>` gets
|
|
3809
|
+
* run within the repo's directory.
|
|
3810
|
+
*
|
|
3811
|
+
* An error will be thrown if the provided path is not within the repository's
|
|
3812
|
+
* directory tree. For instance, calling `gitRepo.isIgnored("/tmp")` on a
|
|
3813
|
+
* `gitRepo` pointed at `/home/suchipi/my-project` would throw an error,
|
|
3814
|
+
* because `/tmp` is not a child of `/home/suchipi/my-project`.
|
|
3815
|
+
*
|
|
3816
|
+
* > NOTE: When passing relative paths to `isIgnored`, they will be resolved
|
|
3817
|
+
* > relative to the repo root, NOT relative to `pwd()`. It's best practice to
|
|
3818
|
+
* > always pass around absolute paths in your program instead of relative
|
|
3819
|
+
* > ones so that this type of ambiguity is avoided.
|
|
2916
3820
|
*/
|
|
2917
3821
|
isIgnored(path: string | Path): boolean;
|
|
2918
3822
|
}
|
|
@@ -2946,24 +3850,81 @@ declare const logger: {
|
|
|
2946
3850
|
info: (...args: Array<any>) => void;
|
|
2947
3851
|
};
|
|
2948
3852
|
|
|
3853
|
+
/**
|
|
3854
|
+
* The properties of the `JSX` global can be modified to change how JSX syntax
|
|
3855
|
+
* gets compiled by yavascript. Those properties are:
|
|
3856
|
+
*
|
|
3857
|
+
* - `pragma` (string): The JavaScript expression that should be called to
|
|
3858
|
+
* create JSX elements. Defaults to "JSX.createElement".
|
|
3859
|
+
* - `pragmaFrag` (string): The JavaScript expression that should be used when
|
|
3860
|
+
* creating JSX fragments. Defaults to "JSX.Fragment".
|
|
3861
|
+
* - `createElement` (function): The function used to create JSX elements,
|
|
3862
|
+
* unless `JSX.pragma` has been changed.
|
|
3863
|
+
* - `Element` (symbol): used by the default `JSX.createElement` function to
|
|
3864
|
+
* identify JSX elements.
|
|
3865
|
+
* - `Fragment` (symbol): used by the default `JSX.createElement` function to
|
|
3866
|
+
* identify JSX fragments. Referenced by the default value for
|
|
3867
|
+
* `JSX.pragmaFrag`.
|
|
3868
|
+
*
|
|
3869
|
+
* Modifying these properties will change how JSX syntax gets compiled.
|
|
3870
|
+
*
|
|
3871
|
+
* For instance, to use React for JSX, you could either replace
|
|
3872
|
+
* `JSX.createElement` and `JSX.Fragment` with React's versions:
|
|
3873
|
+
*
|
|
3874
|
+
* ```ts
|
|
3875
|
+
* import * as React from "npm:react";
|
|
3876
|
+
*
|
|
3877
|
+
* JSX.createElement = React.createElement;
|
|
3878
|
+
* JSX.Fragment = React.Fragment;
|
|
3879
|
+
* ```
|
|
3880
|
+
*
|
|
3881
|
+
* Or, you could change `JSX.pragma` and `JSX.pragmaFrag` to reference React
|
|
3882
|
+
* directly:
|
|
3883
|
+
*
|
|
3884
|
+
* ```ts
|
|
3885
|
+
* JSX.pragma = "React.createElement";
|
|
3886
|
+
* JSX.pragmaFrag = "React.Fragment";
|
|
3887
|
+
* ```
|
|
3888
|
+
*
|
|
3889
|
+
* Note however, that changes to `pragma` and `pragmaFrag` will only affect JSX
|
|
3890
|
+
* appearing in files which are loaded _after_ the change, but changing
|
|
3891
|
+
* `createElement` and `Fragment` will affect all JSX syntax appearing after the
|
|
3892
|
+
* change, even within the same file.
|
|
3893
|
+
*
|
|
3894
|
+
* Whichever approach you take, you should also update `types.JSX.Element` and
|
|
3895
|
+
* `types.JSX.Fragment` such that the expression `types.JSX.Element(<a />) &&
|
|
3896
|
+
* types.JSX.Fragment(<></>)` is always `true`. To do that for React, you would
|
|
3897
|
+
* do:
|
|
3898
|
+
*
|
|
3899
|
+
* ```ts
|
|
3900
|
+
* types.JSX.Element = React.isValidElement;
|
|
3901
|
+
* types.JSX.Fragment = (value) => {
|
|
3902
|
+
* return React.isValidElement(value) && value.type === React.Fragment;
|
|
3903
|
+
* };
|
|
3904
|
+
* ```
|
|
3905
|
+
*/
|
|
2949
3906
|
declare namespace JSX {
|
|
2950
3907
|
/**
|
|
3908
|
+
*
|
|
2951
3909
|
* A string containing the expression that should be called to create JSX
|
|
2952
3910
|
* elements. yavascript's internals use this string to transpile JSX syntax.
|
|
2953
3911
|
*
|
|
2954
|
-
*
|
|
3912
|
+
* The default value is "JSX.createElement".
|
|
2955
3913
|
*
|
|
2956
|
-
* If changed, any JSX code loaded afterwards will use a different
|
|
2957
|
-
* expression.
|
|
3914
|
+
* If changed, any JSX code loaded afterwards will use a different expression.
|
|
2958
3915
|
*
|
|
2959
3916
|
* Note that if you change this, you need to verify that the following
|
|
2960
|
-
* expression always evaluates to `true` (by changing
|
|
2961
|
-
*
|
|
3917
|
+
* expression always evaluates to `true` (by changing `types.JSX.Element` and
|
|
3918
|
+
* `types.JSX.Fragment`):
|
|
3919
|
+
*
|
|
2962
3920
|
* ```jsx
|
|
2963
|
-
* types.JSX.Element(<a />) && types.JSX.Fragment(<></>)
|
|
3921
|
+
* types.JSX.Element(<a />) && types.JSX.Fragment(<></>);
|
|
2964
3922
|
* ```
|
|
2965
3923
|
*
|
|
2966
3924
|
* Failure to uphold this guarantee indicates a bug.
|
|
3925
|
+
*
|
|
3926
|
+
* For more info, including info on how to change how JSX is compiled, see
|
|
3927
|
+
* {@link JSX}.
|
|
2967
3928
|
*/
|
|
2968
3929
|
export let pragma: string;
|
|
2969
3930
|
|
|
@@ -2974,22 +3935,66 @@ declare namespace JSX {
|
|
|
2974
3935
|
*
|
|
2975
3936
|
* Defaults to "JSX.Fragment".
|
|
2976
3937
|
*
|
|
2977
|
-
* If changed, any JSX code loaded afterwards will use a different
|
|
2978
|
-
* expression.
|
|
3938
|
+
* If changed, any JSX code loaded afterwards will use a different expression.
|
|
2979
3939
|
*
|
|
2980
3940
|
* Note that if you change this, you need to verify that the following
|
|
2981
|
-
* expression always evaluates to `true` (by changing
|
|
2982
|
-
*
|
|
3941
|
+
* expression always evaluates to `true` (by changing `types.JSX.Element` and
|
|
3942
|
+
* `types.JSX.Fragment`):
|
|
3943
|
+
*
|
|
2983
3944
|
* ```jsx
|
|
2984
|
-
* types.JSX.Element(<a />) && types.JSX.Fragment(<></>)
|
|
3945
|
+
* types.JSX.Element(<a />) && types.JSX.Fragment(<></>);
|
|
2985
3946
|
* ```
|
|
2986
3947
|
*
|
|
2987
3948
|
* Failure to uphold this guarantee indicates a bug.
|
|
3949
|
+
*
|
|
3950
|
+
* For more info, including info on how to change how JSX is compiled, see
|
|
3951
|
+
* {@link JSX}.
|
|
2988
3952
|
*/
|
|
2989
3953
|
export let pragmaFrag: string;
|
|
2990
3954
|
|
|
3955
|
+
/**
|
|
3956
|
+
* `JSX.Element` is a Symbol. The default implementation of
|
|
3957
|
+
* `JSX.createElement` creates objects whose `$$typeof` property is set to
|
|
3958
|
+
* `JSX.Element`, and type validator functions under the `types.JSX.*`
|
|
3959
|
+
* namespace look for this property in order to determine whether an object is
|
|
3960
|
+
* a JSX element, as created via `JSX.createElement` or JSX syntax.
|
|
3961
|
+
*
|
|
3962
|
+
* ```jsx
|
|
3963
|
+
* // This gets compiled internally by yavascript into:
|
|
3964
|
+
* // const a = JSX.createElement('a', null);
|
|
3965
|
+
* const a = <a />;
|
|
3966
|
+
*
|
|
3967
|
+
* console.log(a);
|
|
3968
|
+
* // {
|
|
3969
|
+
* // $$typeof: Symbol(JSX.Element)
|
|
3970
|
+
* // type: "a"
|
|
3971
|
+
* // props: null
|
|
3972
|
+
* // key: null
|
|
3973
|
+
* // }
|
|
3974
|
+
*
|
|
3975
|
+
* console.log(a.$$typeof === JSX.Element);
|
|
3976
|
+
* // true
|
|
3977
|
+
* ```
|
|
3978
|
+
*
|
|
3979
|
+
* There is also a TypeScript type called `JSX.Element` which is a type for
|
|
3980
|
+
* the JSX element objects as created by `JSX.createElement` or JSX syntax.
|
|
3981
|
+
*
|
|
3982
|
+
* If you modify properties on the JSX global such that the default
|
|
3983
|
+
* implementation of `JSX.createElement` is no longer used (eg. by replacing
|
|
3984
|
+
* it with `React.createElement`), this value may no longer be relevant.
|
|
3985
|
+
* However, the default JSX element object shape is designed to match
|
|
3986
|
+
* React/Preact/etc.
|
|
3987
|
+
*
|
|
3988
|
+
* For more info, including info on how to change how JSX is compiled, see
|
|
3989
|
+
* {@link JSX}.
|
|
3990
|
+
*
|
|
3991
|
+
*/
|
|
2991
3992
|
export const Element: unique symbol;
|
|
2992
3993
|
|
|
3994
|
+
/**
|
|
3995
|
+
* The TypeScript type for JSX Element objects created by the default
|
|
3996
|
+
* implementation of `JSX.createElement`.
|
|
3997
|
+
*/
|
|
2993
3998
|
export interface Element<
|
|
2994
3999
|
Props = { [key: string | symbol | number]: any },
|
|
2995
4000
|
Type = any
|
|
@@ -3001,26 +4006,69 @@ declare namespace JSX {
|
|
|
3001
4006
|
}
|
|
3002
4007
|
|
|
3003
4008
|
/**
|
|
3004
|
-
*
|
|
3005
|
-
*
|
|
3006
|
-
*
|
|
4009
|
+
*
|
|
4010
|
+
* `JSX.Fragment` is a Symbol which is used to indicate whether a JSX element
|
|
4011
|
+
* is a JSX fragment.
|
|
4012
|
+
*
|
|
4013
|
+
* ```jsx
|
|
4014
|
+
* // This gets compiled internally by yavascript into:
|
|
4015
|
+
* // const a = JSX.createElement(JSX.Fragment, null);
|
|
4016
|
+
* const frag = <></>;
|
|
4017
|
+
*
|
|
4018
|
+
* console.log(frag);
|
|
4019
|
+
* // {
|
|
4020
|
+
* // $$typeof: Symbol(JSX.Element)
|
|
4021
|
+
* // type: Symbol(JSX.Fragment)
|
|
4022
|
+
* // props: null
|
|
4023
|
+
* // key: null
|
|
4024
|
+
* // }
|
|
4025
|
+
*
|
|
4026
|
+
* console.log(a.type === JSX.Fragment);
|
|
4027
|
+
* // true
|
|
4028
|
+
* ```
|
|
4029
|
+
*
|
|
4030
|
+
* There is also a TypeScript type called `JSX.Fragment` which is a type for
|
|
4031
|
+
* the JSX fragment element objects as created by `JSX.createElement` or JSX
|
|
4032
|
+
* syntax.
|
|
4033
|
+
*
|
|
4034
|
+
* If you modify properties on the JSX global such that `JSX.Fragment` is no
|
|
4035
|
+
* longer used (eg. by replacing it with `React.Fragment`), this value may no
|
|
4036
|
+
* longer be relevant.
|
|
4037
|
+
*
|
|
4038
|
+
* For more info, including info on how to change how JSX is compiled, see
|
|
4039
|
+
* {@link JSX}.
|
|
3007
4040
|
*/
|
|
3008
4041
|
export const Fragment: unique symbol;
|
|
3009
4042
|
|
|
4043
|
+
/**
|
|
4044
|
+
* The TypeScript type for JSX Element objects whose type is `JSX.Fragment`,
|
|
4045
|
+
* which is what yavascript creates internally when JSX fragment syntax
|
|
4046
|
+
* (`<></>`) is used.
|
|
4047
|
+
*
|
|
4048
|
+
* If you modify properties on the JSX global such that `JSX.Fragment` is no
|
|
4049
|
+
* longer used (eg. by replacing it with `React.Fragment`), this type may no
|
|
4050
|
+
* longer be relevant.
|
|
4051
|
+
*/
|
|
3010
4052
|
export type Fragment = Element<{}, typeof Fragment>;
|
|
3011
4053
|
|
|
3012
4054
|
/**
|
|
3013
|
-
* The JSX element builder function, which gets invoked
|
|
3014
|
-
* used (unless
|
|
4055
|
+
* The JSX element builder function, which gets invoked internally by
|
|
4056
|
+
* yavascript whenever JSX syntax is used (unless `JSX.pragma` gets changed by
|
|
4057
|
+
* the user).
|
|
3015
4058
|
*
|
|
3016
4059
|
* Note that if you change this, you need to verify that the following
|
|
3017
|
-
* expression always evaluates to `true` (by changing
|
|
3018
|
-
*
|
|
4060
|
+
* expression always evaluates to `true` (by changing `types.JSX.Element` and
|
|
4061
|
+
* `types.JSX.Fragment`):
|
|
4062
|
+
*
|
|
3019
4063
|
* ```jsx
|
|
3020
|
-
* types.JSX.Element(<a />) && types.JSX.Fragment(<></>)
|
|
4064
|
+
* types.JSX.Element(<a />) && types.JSX.Fragment(<></>);
|
|
3021
4065
|
* ```
|
|
3022
4066
|
*
|
|
3023
4067
|
* Failure to uphold this guarantee indicates a bug.
|
|
4068
|
+
*
|
|
4069
|
+
* For more info, including info on how to change how JSX is compiled, see
|
|
4070
|
+
* {@link JSX}.
|
|
4071
|
+
*
|
|
3024
4072
|
*/
|
|
3025
4073
|
export let createElement: {
|
|
3026
4074
|
<Type extends string | typeof Fragment | ((...args: any) => any)>(
|
|
@@ -3054,9 +4102,14 @@ declare namespace JSX {
|
|
|
3054
4102
|
};
|
|
3055
4103
|
}
|
|
3056
4104
|
|
|
4105
|
+
/**
|
|
4106
|
+
* The `YAML` namespace contains functions which can serialize and deserialize
|
|
4107
|
+
* YAML documents, following the same pattern as JavaScript's `JSON` builtin.
|
|
4108
|
+
*/
|
|
3057
4109
|
declare const YAML: {
|
|
3058
4110
|
/**
|
|
3059
|
-
*
|
|
4111
|
+
* Converts a YAML document string into a JavaScript value. It works the same
|
|
4112
|
+
* way that `JSON.parse` does, but for YAML.
|
|
3060
4113
|
*/
|
|
3061
4114
|
parse(
|
|
3062
4115
|
input: string,
|
|
@@ -3064,7 +4117,8 @@ declare const YAML: {
|
|
|
3064
4117
|
): any;
|
|
3065
4118
|
|
|
3066
4119
|
/**
|
|
3067
|
-
*
|
|
4120
|
+
* Converts a JavaScript value into a YAML document string. It works the same
|
|
4121
|
+
* way that `JSON.stringify` does, but for YAML.
|
|
3068
4122
|
*/
|
|
3069
4123
|
stringify(
|
|
3070
4124
|
input: any,
|
|
@@ -3076,6 +4130,18 @@ declare const YAML: {
|
|
|
3076
4130
|
): string;
|
|
3077
4131
|
};
|
|
3078
4132
|
|
|
4133
|
+
/**
|
|
4134
|
+
* Serializes or deserializes CSV data.
|
|
4135
|
+
*
|
|
4136
|
+
* The `CSV` object contains a `parse` function and a `stringify` function which
|
|
4137
|
+
* can be used to parse strings of CSV (comma-separated values) data into
|
|
4138
|
+
* arrays-of-arrays-of-strings and serialize arrays-of-arrays-of-strings into
|
|
4139
|
+
* strings of CSV data.
|
|
4140
|
+
*
|
|
4141
|
+
* Its interface is similar to `JSON.parse` and `JSON.stringify`, but CSV does
|
|
4142
|
+
* not support the spacing/replacer/reviver options that `JSON.parse` and
|
|
4143
|
+
* `JSON.stringify` have.
|
|
4144
|
+
*/
|
|
3079
4145
|
declare const CSV: {
|
|
3080
4146
|
/**
|
|
3081
4147
|
* Parse a CSV string into an Array of Arrays of strings.
|
|
@@ -3094,9 +4160,18 @@ declare const CSV: {
|
|
|
3094
4160
|
stringify(input: Array<Array<string>>): string;
|
|
3095
4161
|
};
|
|
3096
4162
|
|
|
4163
|
+
/**
|
|
4164
|
+
* An object with a `parse` function and a `stringify` function which can be
|
|
4165
|
+
* used to parse TOML document strings into objects and serialize objects into
|
|
4166
|
+
* TOML document strings.
|
|
4167
|
+
*
|
|
4168
|
+
* Its interface is similar to `JSON.parse` and `JSON.stringify`, but
|
|
4169
|
+
* `TOML.parse` and `TOML.stringify` do not support the spacing/replacer/reviver
|
|
4170
|
+
* options that `JSON.parse` and `JSON.stringify` do.
|
|
4171
|
+
*/
|
|
3097
4172
|
declare var TOML: {
|
|
3098
4173
|
/**
|
|
3099
|
-
* Parse a TOML document (`data`) into an object.
|
|
4174
|
+
* Parse a TOML document string (`data`) into an object.
|
|
3100
4175
|
*/
|
|
3101
4176
|
parse(data: string): { [key: string]: any };
|
|
3102
4177
|
/**
|
|
@@ -3106,31 +4181,43 @@ declare var TOML: {
|
|
|
3106
4181
|
};
|
|
3107
4182
|
|
|
3108
4183
|
interface RegExpConstructor {
|
|
3109
|
-
/**
|
|
4184
|
+
/**
|
|
4185
|
+
* The function `RegExp.escape` accepts an input string and prefixes with `\`
|
|
4186
|
+
* those characters in that string which have a special meaning when appearing
|
|
4187
|
+
* in a regular expression.
|
|
4188
|
+
*
|
|
4189
|
+
* The implementation is based on the stage 2 ECMAScript proposal of the same
|
|
4190
|
+
* name: https://github.com/tc39/proposal-regex-escaping
|
|
4191
|
+
*/
|
|
3110
4192
|
escape(str: any): string;
|
|
3111
4193
|
}
|
|
3112
4194
|
|
|
3113
4195
|
interface StringConstructor {
|
|
3114
4196
|
/**
|
|
3115
|
-
*
|
|
3116
|
-
*
|
|
4197
|
+
* The function `String.dedent` can be used to remove leading indentation from
|
|
4198
|
+
* a string. It is commonly used as a tagged template function, but you can
|
|
4199
|
+
* also call it and pass in a string.
|
|
3117
4200
|
*
|
|
3118
|
-
*
|
|
4201
|
+
* Note that the first line of the string must be empty.
|
|
4202
|
+
*
|
|
4203
|
+
* `String.dedent` is the default export from the npm package `string-dedent`.
|
|
4204
|
+
* See its readme on npm for more info:
|
|
4205
|
+
* https://www.npmjs.com/package/string-dedent
|
|
3119
4206
|
*/
|
|
3120
4207
|
dedent: {
|
|
3121
4208
|
/**
|
|
3122
|
-
*
|
|
3123
|
-
* The first line of
|
|
4209
|
+
* Removes leading minimum indentation from the string `input`.
|
|
4210
|
+
* The first line of `input` MUST be empty.
|
|
3124
4211
|
*
|
|
3125
|
-
* https://
|
|
4212
|
+
* For more info, see: https://www.npmjs.com/package/string-dedent#usage
|
|
3126
4213
|
*/
|
|
3127
4214
|
(input: string): string;
|
|
3128
4215
|
|
|
3129
4216
|
/**
|
|
3130
|
-
*
|
|
3131
|
-
* The first line of the
|
|
4217
|
+
* Removes leading minimum indentation from the tagged template literal.
|
|
4218
|
+
* The first line of the template literal MUST be empty.
|
|
3132
4219
|
*
|
|
3133
|
-
* https://
|
|
4220
|
+
* For more info, see: https://www.npmjs.com/package/string-dedent#usage
|
|
3134
4221
|
*/
|
|
3135
4222
|
(
|
|
3136
4223
|
strings: readonly string[] | ArrayLike<string>,
|
|
@@ -3141,7 +4228,7 @@ interface StringConstructor {
|
|
|
3141
4228
|
* Wrap another template tag function such that tagged literals
|
|
3142
4229
|
* become dedented before being passed to the wrapped function.
|
|
3143
4230
|
*
|
|
3144
|
-
* https://www.npmjs.com/package/string-dedent#usage
|
|
4231
|
+
* For more info, see: https://www.npmjs.com/package/string-dedent#usage
|
|
3145
4232
|
*/
|
|
3146
4233
|
<
|
|
3147
4234
|
Func extends (
|
|
@@ -3154,6 +4241,24 @@ interface StringConstructor {
|
|
|
3154
4241
|
};
|
|
3155
4242
|
}
|
|
3156
4243
|
|
|
4244
|
+
/**
|
|
4245
|
+
* Opens the resource at the given path or URL using the operating system's
|
|
4246
|
+
* default application or handler.
|
|
4247
|
+
*
|
|
4248
|
+
* Examples:
|
|
4249
|
+
*
|
|
4250
|
+
* ```ts
|
|
4251
|
+
* openUrl("/home/me/stuff/code.txt"); // opens code.txt in your default text editor
|
|
4252
|
+
* openUrl("code.txt"); // same as above, using relative path
|
|
4253
|
+
* openUrl("file:///home/me/stuff/code.txt"); // same as above, using file:// url
|
|
4254
|
+
*
|
|
4255
|
+
* openUrl("IMG_001.jpg"); // opens IMG_001.jpg in your default image viewer
|
|
4256
|
+
*
|
|
4257
|
+
* openUrl("https://example.com/") // opens example.com in your default web browser
|
|
4258
|
+
* ```
|
|
4259
|
+
*/
|
|
4260
|
+
declare function openUrl(urlOrFilePath: string | Path): void;
|
|
4261
|
+
|
|
3157
4262
|
// prettier-ignore
|
|
3158
4263
|
/** Any integer in the range [0, 255]. */
|
|
3159
4264
|
declare type byte =
|
|
@@ -3206,6 +4311,53 @@ interface ErrorOptions {
|
|
|
3206
4311
|
[key: string]: any;
|
|
3207
4312
|
}
|
|
3208
4313
|
|
|
4314
|
+
/**
|
|
4315
|
+
* For compatibility with Node.js scripts, the global object is accessible via
|
|
4316
|
+
* the global variable named "global".
|
|
4317
|
+
*/
|
|
4318
|
+
declare var global: typeof globalThis;
|
|
4319
|
+
|
|
4320
|
+
/**
|
|
4321
|
+
* A `process` global is provided for rudimentary compatibility with Node.js
|
|
4322
|
+
* scripts. It contains a subset of the properties found on the Node.js
|
|
4323
|
+
* `process` global, which each forward to their corresponding yavascript API.
|
|
4324
|
+
*
|
|
4325
|
+
* For instance, `process.env` is a getter that returns {@link env}, and
|
|
4326
|
+
* `process.argv` is a getter that returns {@link scriptArgs}.
|
|
4327
|
+
*
|
|
4328
|
+
* If you are writing yavascript-specific code, you should use yavascript's APIs
|
|
4329
|
+
* instead of `process`.
|
|
4330
|
+
*/
|
|
4331
|
+
declare var process: {
|
|
4332
|
+
version: string;
|
|
4333
|
+
versions: {
|
|
4334
|
+
node: string;
|
|
4335
|
+
yavascript: string;
|
|
4336
|
+
unicode: string;
|
|
4337
|
+
};
|
|
4338
|
+
arch: string;
|
|
4339
|
+
/** Same as the global {@link env}. */
|
|
4340
|
+
readonly env: { [key: string]: string | undefined };
|
|
4341
|
+
/** Same as the global {@link scriptArgs}. */
|
|
4342
|
+
readonly argv: Array<string>;
|
|
4343
|
+
/** Same as `scriptArgs[0]`. */
|
|
4344
|
+
readonly argv0: string;
|
|
4345
|
+
/**
|
|
4346
|
+
* Shortcut for `os.realpath(os.execPath())`, using the QuickJS {@link os}
|
|
4347
|
+
* module.
|
|
4348
|
+
*/
|
|
4349
|
+
readonly execPath: string;
|
|
4350
|
+
/**
|
|
4351
|
+
* Uses `std.getExitCode()` and `std.setExitCode()` from the QuickJS
|
|
4352
|
+
* {@link std} module.
|
|
4353
|
+
*/
|
|
4354
|
+
exitCode: number;
|
|
4355
|
+
/**
|
|
4356
|
+
* Uses `std.exit()` from the QuickJS {@link std} module.
|
|
4357
|
+
*/
|
|
4358
|
+
exit(code?: number | null | undefined): void;
|
|
4359
|
+
};
|
|
4360
|
+
|
|
3209
4361
|
// ==========================================
|
|
3210
4362
|
// ------------------------------------------
|
|
3211
4363
|
// QuickJS APIs, which YavaScript builds upon
|
|
@@ -4083,33 +5235,6 @@ interface BigDecimal {
|
|
|
4083
5235
|
// TypeScript will not understand or handle unary/binary operators for BigFloat
|
|
4084
5236
|
// and BigDecimal properly.
|
|
4085
5237
|
|
|
4086
|
-
/**
|
|
4087
|
-
* Print the arguments separated by spaces and a trailing newline.
|
|
4088
|
-
*
|
|
4089
|
-
* Non-string args are coerced into a string via [ToString](https://tc39.es/ecma262/#sec-tostring).
|
|
4090
|
-
* Objects can override the default `ToString` behavior by defining a `toString` method.
|
|
4091
|
-
*/
|
|
4092
|
-
declare var print: (...args: Array<any>) => void;
|
|
4093
|
-
|
|
4094
|
-
/**
|
|
4095
|
-
* Object that provides functions for logging information.
|
|
4096
|
-
*/
|
|
4097
|
-
interface Console {
|
|
4098
|
-
/** Same as {@link print}(). */
|
|
4099
|
-
log: typeof print;
|
|
4100
|
-
|
|
4101
|
-
/** Same as {@link print}(). */
|
|
4102
|
-
warn: typeof print;
|
|
4103
|
-
|
|
4104
|
-
/** Same as {@link print}(). */
|
|
4105
|
-
error: typeof print;
|
|
4106
|
-
|
|
4107
|
-
/** Same as {@link print}(). */
|
|
4108
|
-
info: typeof print;
|
|
4109
|
-
}
|
|
4110
|
-
|
|
4111
|
-
declare var console: Console;
|
|
4112
|
-
|
|
4113
5238
|
/** npm: @suchipi/print@2.5.0. License: ISC */
|
|
4114
5239
|
/* (with some QuickJS-specific modifications) */
|
|
4115
5240
|
|
|
@@ -4550,6 +5675,27 @@ declare module "quickjs:std" {
|
|
|
4550
5675
|
*/
|
|
4551
5676
|
export function getegid(): number;
|
|
4552
5677
|
|
|
5678
|
+
/** The type of the object returned by {@link getpwuid}. */
|
|
5679
|
+
export interface PasswdEntry {
|
|
5680
|
+
name: string;
|
|
5681
|
+
passwd: string;
|
|
5682
|
+
uid: number;
|
|
5683
|
+
gid: number;
|
|
5684
|
+
gecos: string;
|
|
5685
|
+
dir: string;
|
|
5686
|
+
shell: string;
|
|
5687
|
+
}
|
|
5688
|
+
|
|
5689
|
+
/**
|
|
5690
|
+
* Get information from the passwd file entry for the specified user id.
|
|
5691
|
+
*
|
|
5692
|
+
* See https://linux.die.net/man/3/getpwuid.
|
|
5693
|
+
*
|
|
5694
|
+
* This function throws an error on windows, because windows doesn't support
|
|
5695
|
+
* the same uid/gid paradigm as Unix-like operating systems.
|
|
5696
|
+
*/
|
|
5697
|
+
export function getpwuid(id: number): PasswdEntry;
|
|
5698
|
+
|
|
4553
5699
|
interface UrlGet {
|
|
4554
5700
|
/**
|
|
4555
5701
|
* Download `url` using the `curl` command line utility. Returns string
|
|
@@ -5335,6 +6481,15 @@ interface ModuleDelegate {
|
|
|
5335
6481
|
[extensionWithDot: string]: (filename: string, content: string) => string;
|
|
5336
6482
|
};
|
|
5337
6483
|
|
|
6484
|
+
/**
|
|
6485
|
+
* An Array containing the names of all the built-in modules, such as
|
|
6486
|
+
* "quickjs:std", "quickjs:bytecode", etc.
|
|
6487
|
+
*
|
|
6488
|
+
* `quickjs:engine`'s `defineBuiltinModule` function adds to the end of this
|
|
6489
|
+
* array.
|
|
6490
|
+
*/
|
|
6491
|
+
builtinModuleNames: Array<string>;
|
|
6492
|
+
|
|
5338
6493
|
/**
|
|
5339
6494
|
* Resolves a require/import request from `fromFile` into a canonicalized
|
|
5340
6495
|
* path.
|