Passed
Push — master ( b0778e...060fe5 )
by Roy
04:01 queued 02:31
created

src/types/deno.d.ts   F

Complexity

Total Complexity 222
Complexity/F 1

Size

Lines of Code 4020
Function Count 222

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 222
eloc 1618
mnd 0
bc 0
fnc 222
dl 0
loc 4020
rs 0.8
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

210 Functions

Rating   Name   Duplication   Size   Complexity  
A deno.d.ts ➔ makeTempDirSync 0 20 1
A URLSearchParams.delete 0 10 1
A Response.arrayBuffer 0 4 1
A Event.composedPath 0 5 1
A Blob.stream 0 1 1
A deno.d.ts ➔ listenTls 0 10 1
A Performance.getEntries 0 2 1
A deno.d.ts ➔ prompt 0 11 1
A deno.d.ts ➔ readFile 0 13 1
A deno.d.ts ➔ compile 0 10 1
A Global.valueOf 0 3 1
A Event.stopImmediatePropagation 0 4 1
A deno.d.ts ➔ copyFile 0 12 1
A WebSocket.removeEventListener 0 5 1
A deno.d.ts ➔ create 0 11 1
A deno.d.ts ➔ mkdir 0 13 1
A Request.clone 0 1 2
A deno.d.ts ➔ run 0 34 1
A ByteLengthQueuingStrategy.size 0 1 1
A deno.d.ts ➔ realPath 0 16 1
A deno.d.ts ➔ listen 0 12 1
A Response.blob 0 4 1
A Event.stopPropagation 0 3 1
A deno.d.ts ➔ readDir 0 14 1
A URL.toJSON 0 1 1
A TextEncoder.encodeInto 0 1 1
A Headers.get 0 4 1
A URLSearchParams.append 0 10 1
A deno.d.ts ➔ readDirSync 0 14 1
A Module.exports 0 3 1
A deno.d.ts ➔ createSync 0 11 1
A Headers.set 0 4 1
A deno.d.ts ➔ chmod 0 30 1
A deno.d.ts ➔ truncateSync 0 19 1
A WebSocket.addEventListener 0 5 1
A Module.customSections 0 6 1
A deno.d.ts ➔ queueMicrotask 0 10 1
A CountQueuingStrategy.size 0 1 1
A File.read 0 1 1
A TextDecoder.decode 0 2 1
A deno.d.ts ➔ writeFileSync 0 21 1
A deno.d.ts ➔ writeAll 0 22 1
A Headers.append 0 5 1
A Response.clone 0 1 1
A deno.d.ts ➔ stat 0 12 1
A deno.d.ts ➔ addEventListener 0 13 1
A deno.d.ts ➔ writeAllSync 0 23 1
A FormData.set 0 1 1
A Process.status 0 2 1
A Worker.terminate 0 1 1
A EventTarget.removeEventListener 0 7 1
A Table.get 0 3 1
A Worker.addEventListener 0 5 1
A Table.grow 0 3 1
A File.close 0 1 1
A Process.kill 0 8 1
A deno.d.ts ➔ seek 0 28 1
A FormData.keys 0 1 1
A deno.d.ts ➔ readLinkSync 0 12 1
A Window.new 0 1 1
A deno.d.ts ➔ connectTls 0 16 1
A Response.text 0 4 1
A deno.d.ts ➔ readLink 0 12 1
A deno.d.ts ➔ truncate 0 18 1
A deno.d.ts ➔ chown 0 17 1
A Request.json 0 4 1
A Performance.getEntriesByType 0 1 1
A deno.d.ts ➔ realPathSync 0 16 1
A Buffer.bytes 0 10 1
A WebSocket.close 0 4 1
A URLSearchParams.sort 0 10 1
A File.writeSync 0 1 1
A deno.d.ts ➔ alert 0 7 1
A deno.d.ts ➔ cwd 0 16 1
A deno.d.ts ➔ seekSync 0 29 1
A deno.d.ts ➔ fsyncSync 0 12 1
A deno.d.ts ➔ watchFs 0 23 1
A Table.set 0 3 1
A FormData.entries 0 1 1
A deno.d.ts ➔ dispatchEvent 0 9 1
A FormData.get 0 1 1
A deno.d.ts ➔ resources 0 14 1
A Event.preventDefault 0 5 1
A AbortController.abort 0 3 1
A URLSearchParams.entries 0 12 1
A deno.d.ts ➔ readSync 0 24 1
A Buffer.read 0 8 1
A deno.d.ts ➔ chownSync 0 17 1
A deno.d.ts ➔ copy 0 23 1
A URLSearchParams.toString 0 1 2
A EventTarget.addEventListener 0 28 1
A deno.d.ts ➔ clearTimeout 0 8 1
A Performance.clearMeasures 0 3 1
A deno.d.ts ➔ writeSync 0 20 1
A Request.formData 0 4 1
A Response.redirect 0 1 1
A deno.d.ts ➔ clearInterval 0 9 1
A deno.d.ts ➔ readFileSync 0 13 1
A FormData.delete 0 1 1
A deno.d.ts ➔ iter 0 36 1
A EventTarget.dispatchEvent 0 4 1
A deno.d.ts ➔ copyFileSync 0 12 1
A deno.d.ts ➔ makeTempDir 0 20 1
A FormData.append 0 2 1
A deno.d.ts ➔ remove 0 13 1
A Buffer.write 0 3 1
A deno.d.ts ➔ makeTempFile 0 19 1
A deno.d.ts ➔ instantiateStreaming 0 12 1
A WritableStream.getWriter 0 1 1
A deno.d.ts ➔ compileStreaming 0 10 1
A Response.json 0 4 1
A TextEncoder.encode 0 2 1
A Buffer.grow 0 8 1
A deno.d.ts ➔ readTextFileSync 0 11 1
A Headers.entries 0 5 1
A URL.createObjectURL 0 1 1
A deno.d.ts ➔ chdir 0 17 1
A WebSocket.send 0 4 1
A Blob.arrayBuffer 0 1 1
A Response.formData 0 4 1
A File.write 0 1 1
A Worker.removeEventListener 0 5 1
A deno.d.ts ➔ open 0 15 1
A deno.d.ts ➔ readTextFile 0 11 1
A Blob.slice 0 1 1
A deno.d.ts ➔ execPath 0 11 1
A Performance.clearMarks 0 3 1
A Headers.delete 0 2 1
A deno.d.ts ➔ lstat 0 13 1
A deno.d.ts ➔ read 0 24 1
A FormData.values 0 1 1
A deno.d.ts ➔ openSync 0 15 1
A URLSearchParams.values 0 12 1
A deno.d.ts ➔ makeTempFileSync 0 19 1
A Buffer.reset 0 3 1
A deno.d.ts ➔ atob 0 6 1
A URLSearchParams.getAll 0 9 1
A deno.d.ts ➔ write 0 19 1
A Buffer.readFromSync 0 7 1
A deno.d.ts ➔ connect 0 14 1
A deno.d.ts ➔ iterSync 0 36 1
A Headers.values 0 4 1
A deno.d.ts ➔ lstatSync 0 12 1
A PerformanceEntry.toJSON 0 1 1
A WritableStream.abort 0 1 1
A URLSearchParams.has 0 9 1
A deno.d.ts ➔ validate 0 9 1
A URLSearchParams.get 0 8 1
A Process.close 0 1 1
A deno.d.ts ➔ rename 0 17 1
A URL.revokeObjectURL 0 1 1
A WritableStream.close 0 1 1
A deno.d.ts ➔ fsync 0 12 1
A Response.error 0 1 1
A deno.d.ts ➔ removeEventListener 0 12 1
A FormData.getAll 0 1 1
A Module.imports 0 3 1
A Request.blob 0 4 1
A deno.d.ts ➔ test 0 33 1
A Process.stderrOutput 0 6 1
A deno.d.ts ➔ instantiate 0 16 1
A deno.d.ts ➔ inspect 0 34 1
A deno.d.ts ➔ removeSync 0 13 1
A Headers.forEach 0 1 1
A deno.d.ts ➔ setTimeout 0 14 1
A Memory.grow 0 6 1
A Request.text 0 4 1
A deno.d.ts ➔ renameSync 0 17 1
A Worker.postMessage 0 1 1
A File.seekSync 0 1 1
A Headers.keys 0 4 1
A deno.d.ts ➔ close 0 12 1
A Buffer.readSync 0 4 1
A File.readSync 0 1 1
A FormData.forEach 0 4 2
A Headers.has 0 4 1
A deno.d.ts ➔ statSync 0 12 1
A deno.d.ts ➔ isatty 0 16 1
A deno.d.ts ➔ readAll 0 21 1
A deno.d.ts ➔ confirm 0 8 1
A deno.d.ts ➔ setInterval 0 14 1
A FormData.has 0 1 1
A File.seek 0 1 1
A URLSearchParams.keys 0 12 1
A deno.d.ts ➔ writeTextFileSync 0 15 1
A deno.d.ts ➔ btoa 0 6 1
A Buffer.truncate 0 4 1
A deno.d.ts ➔ writeTextFile 0 15 1
A Request.arrayBuffer 0 4 1
A URLSearchParams.set 0 11 1
A deno.d.ts ➔ mkdirSync 0 13 1
A Buffer.writeSync 0 1 1
A Performance.getEntriesByName 0 1 1
A deno.d.ts ➔ writeFile 0 20 1
A URL.toString 0 1 1
A Buffer.readFrom 0 7 1
A Performance.measure 0 4 1
A deno.d.ts ➔ metrics 0 23 1
A Performance.now 0 11 1
A Performance.mark 0 3 1
A deno.d.ts ➔ readAllSync 0 21 1
A deno.d.ts ➔ chmodSync 0 14 1
A Buffer.empty 0 2 1
A deno.d.ts ➔ fdatasync 0 11 1
A deno.d.ts ➔ fdatasyncSync 0 11 1
A Process.output 0 6 1
A deno.d.ts ➔ fetch 0 10 1
A URLSearchParams.forEach 0 14 1
A Blob.text 0 1 1
A deno.d.ts ➔ exit 0 9 1

How to fix   Complexity   

Complexity

Complex classes like src/types/deno.d.ts often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
/* eslint-disable eslint-comments/no-unlimited-disable */
2
/* eslint-disable */
3
/* spell-checker:ignore (abbrev/names) Deno Deno's LLVM WASM nayeemrmn */
4
/* spell-checker:ignore (words) WASM backpressure blocksize encoding's entrypoint global's inode lowercased lstnr newpath oldpath options's roadmap runtimes signo subprotocol subresource unixpacket unwritable */
5
6
// `deno types > deno.d.ts` (for deno v1.6.1)
7
8
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
9
10
/// <reference no-default-lib="true" />
11
/// <reference lib="esnext" />
12
13
/** Deno provides extra properties on `import.meta`.  These are included here
14
 * to ensure that these are still available when using the Deno namespace in
15
 * conjunction with other type libs, like `dom`. */
16
declare interface ImportMeta {
17
	/** A string representation of the fully qualified module URL. */
18
	url: string;
19
20
	/** A flag that indicates if the current module is the main module that was
21
	 * called when starting the program under Deno.
22
	 *
23
	 * ```ts
24
	 * if (import.meta.main) {
25
	 *   // this was loaded as the main module, maybe do some bootstrapping
26
	 * }
27
	 * ```
28
	 */
29
	main: boolean;
30
}
31
32
/** Deno supports user timing Level 3 (see: https://w3c.github.io/user-timing)
33
 * which is not widely supported yet in other runtimes.  These types are here
34
 * so that these features are still available when using the Deno namespace
35
 * in conjunction with other type libs, like `dom`. */
36
declare interface Performance {
37
	/** Stores a timestamp with the associated name (a "mark"). */
38
	mark(markName: string, options?: PerformanceMarkOptions): PerformanceMark;
39
40
	/** Stores the `DOMHighResTimeStamp` duration between two marks along with the
41
	 * associated name (a "measure"). */
42
	measure(measureName: string, options?: PerformanceMeasureOptions): PerformanceMeasure;
43
}
44
45
declare interface PerformanceMarkOptions {
46
	/** Metadata to be included in the mark. */
47
	// deno-lint-ignore no-explicit-any
48
	detail?: any;
49
50
	/** Timestamp to be used as the mark time. */
51
	startTime?: number;
52
}
53
54
declare interface PerformanceMeasureOptions {
55
	/** Metadata to be included in the measure. */
56
	// deno-lint-ignore no-explicit-any
57
	detail?: any;
58
59
	/** Timestamp to be used as the start time or string to be used as start
60
	 * mark.*/
61
	start?: string | number;
62
63
	/** Duration between the start and end times. */
64
	duration?: number;
65
66
	/** Timestamp to be used as the end time or string to be used as end mark. */
67
	end?: string | number;
68
}
69
70
declare namespace Deno {
71
	/** A set of error constructors that are raised by Deno APIs. */
72
	export const errors: {
73
		NotFound: ErrorConstructor;
74
		PermissionDenied: ErrorConstructor;
75
		ConnectionRefused: ErrorConstructor;
76
		ConnectionReset: ErrorConstructor;
77
		ConnectionAborted: ErrorConstructor;
78
		NotConnected: ErrorConstructor;
79
		AddrInUse: ErrorConstructor;
80
		AddrNotAvailable: ErrorConstructor;
81
		BrokenPipe: ErrorConstructor;
82
		AlreadyExists: ErrorConstructor;
83
		InvalidData: ErrorConstructor;
84
		TimedOut: ErrorConstructor;
85
		Interrupted: ErrorConstructor;
86
		WriteZero: ErrorConstructor;
87
		UnexpectedEof: ErrorConstructor;
88
		BadResource: ErrorConstructor;
89
		Http: ErrorConstructor;
90
		Busy: ErrorConstructor;
91
	};
92
93
	/** The current process id of the runtime. */
94
	export const pid: number;
95
96
	/** Reflects the `NO_COLOR` environment variable.
97
	 *
98
	 * See: https://no-color.org/ */
99
	export const noColor: boolean;
100
101
	export interface TestDefinition {
102
		fn: () => void | Promise<void>;
103
		name: string;
104
		ignore?: boolean;
105
		/** If at lease one test has `only` set to true, only run tests that have
106
		 * `only` set to true and fail the test suite. */
107
		only?: boolean;
108
		/** Check that the number of async completed ops after the test is the same
109
		 * as number of dispatched ops. Defaults to true.*/
110
		sanitizeOps?: boolean;
111
		/** Ensure the test case does not "leak" resources - ie. the resource table
112
		 * after the test has exactly the same contents as before the test. Defaults
113
		 * to true. */
114
		sanitizeResources?: boolean;
115
	}
116
117
	/** Register a test which will be run when `deno test` is used on the command
118
	 * line and the containing module looks like a test module.
119
	 * `fn` can be async if required.
120
	 * ```ts
121
	 * import {assert, fail, assertEquals} from "https://deno.land/std/testing/asserts.ts";
122
	 *
123
	 * Deno.test({
124
	 *   name: "example test",
125
	 *   fn(): void {
126
	 *     assertEquals("world", "world");
127
	 *   },
128
	 * });
129
	 *
130
	 * Deno.test({
131
	 *   name: "example ignored test",
132
	 *   ignore: Deno.build.os === "windows",
133
	 *   fn(): void {
134
	 *     // This test is ignored only on Windows machines
135
	 *   },
136
	 * });
137
	 *
138
	 * Deno.test({
139
	 *   name: "example async test",
140
	 *   async fn() {
141
	 *     const decoder = new TextDecoder("utf-8");
142
	 *     const data = await Deno.readFile("hello_world.txt");
143
	 *     assertEquals(decoder.decode(data), "Hello world");
144
	 *   }
145
	 * });
146
	 * ```
147
	 */
148
	export function test(t: TestDefinition): void;
149
150
	/** Register a test which will be run when `deno test` is used on the command
151
	 * line and the containing module looks like a test module.
152
	 * `fn` can be async if required.
153
	 *
154
	 * ```ts
155
	 * import {assert, fail, assertEquals} from "https://deno.land/std/testing/asserts.ts";
156
	 *
157
	 * Deno.test("My test description", ():void => {
158
	 *   assertEquals("hello", "hello");
159
	 * });
160
	 *
161
	 * Deno.test("My async test description", async ():Promise<void> => {
162
	 *   const decoder = new TextDecoder("utf-8");
163
	 *   const data = await Deno.readFile("hello_world.txt");
164
	 *   assertEquals(decoder.decode(data), "Hello world");
165
	 * });
166
	 * ```
167
	 * */
168
	export function test(name: string, fn: () => void | Promise<void>): void;
169
170
	/** Exit the Deno process with optional exit code. If no exit code is supplied
171
	 * then Deno will exit with return code of 0.
172
	 *
173
	 * ```ts
174
	 * Deno.exit(5);
175
	 * ```
176
	 */
177
	export function exit(code?: number): never;
178
179
	export const env: {
180
		/** Retrieve the value of an environment variable. Returns undefined if that
181
		 * key doesn't exist.
182
		 *
183
		 * ```ts
184
		 * console.log(Deno.env.get("HOME"));  // e.g. outputs "/home/alice"
185
		 * console.log(Deno.env.get("MADE_UP_VAR"));  // outputs "Undefined"
186
		 * ```
187
		 * Requires `allow-env` permission. */
188
		get(key: string): string | undefined;
189
190
		/** Set the value of an environment variable.
191
		 *
192
		 * ```ts
193
		 * Deno.env.set("SOME_VAR", "Value"));
194
		 * Deno.env.get("SOME_VAR");  // outputs "Value"
195
		 * ```
196
		 *
197
		 * Requires `allow-env` permission. */
198
		set(key: string, value: string): void;
199
200
		/** Delete the value of an environment variable.
201
		 *
202
		 * ```ts
203
		 * Deno.env.set("SOME_VAR", "Value"));
204
		 * Deno.env.delete("SOME_VAR");  // outputs "Undefined"
205
		 * ```
206
		 *
207
		 * Requires `allow-env` permission. */
208
		delete(key: string): void;
209
210
		/** Returns a snapshot of the environment variables at invocation.
211
		 *
212
		 * ```ts
213
		 * Deno.env.set("TEST_VAR", "A");
214
		 * const myEnv = Deno.env.toObject();
215
		 * console.log(myEnv.SHELL);
216
		 * Deno.env.set("TEST_VAR", "B");
217
		 * console.log(myEnv.TEST_VAR);  // outputs "A"
218
		 * ```
219
		 *
220
		 * Requires `allow-env` permission. */
221
		toObject(): { [index: string]: string };
222
	};
223
224
	/**
225
	 * Returns the path to the current deno executable.
226
	 *
227
	 * ```ts
228
	 * console.log(Deno.execPath());  // e.g. "/home/alice/.local/bin/deno"
229
	 * ```
230
	 *
231
	 * Requires `allow-read` permission.
232
	 */
233
	export function execPath(): string;
234
235
	/**
236
	 * Change the current working directory to the specified path.
237
	 *
238
	 * ```ts
239
	 * Deno.chdir("/home/userA");
240
	 * Deno.chdir("../userB");
241
	 * Deno.chdir("C:\\Program Files (x86)\\Java");
242
	 * ```
243
	 *
244
	 * Throws `Deno.errors.NotFound` if directory not found.
245
	 * Throws `Deno.errors.PermissionDenied` if the user does not have access
246
	 * rights
247
	 *
248
	 * Requires --allow-read.
249
	 */
250
	export function chdir(directory: string): void;
251
252
	/**
253
	 * Return a string representing the current working directory.
254
	 *
255
	 * If the current directory can be reached via multiple paths (due to symbolic
256
	 * links), `cwd()` may return any one of them.
257
	 *
258
	 * ```ts
259
	 * const currentWorkingDirectory = Deno.cwd();
260
	 * ```
261
	 *
262
	 * Throws `Deno.errors.NotFound` if directory not available.
263
	 *
264
	 * Requires --allow-read
265
	 */
266
	export function cwd(): string;
267
268
	export enum SeekMode {
269
		Start = 0,
270
		Current = 1,
271
		End = 2,
272
	}
273
274
	export interface Reader {
275
		/** Reads up to `p.byteLength` bytes into `p`. It resolves to the number of
276
		 * bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error
277
		 * encountered. Even if `read()` resolves to `n` < `p.byteLength`, it may
278
		 * use all of `p` as scratch space during the call. If some data is
279
		 * available but not `p.byteLength` bytes, `read()` conventionally resolves
280
		 * to what is available instead of waiting for more.
281
		 *
282
		 * When `read()` encounters end-of-file condition, it resolves to EOF
283
		 * (`null`).
284
		 *
285
		 * When `read()` encounters an error, it rejects with an error.
286
		 *
287
		 * Callers should always process the `n` > `0` bytes returned before
288
		 * considering the EOF (`null`). Doing so correctly handles I/O errors that
289
		 * happen after reading some bytes and also both of the allowed EOF
290
		 * behaviors.
291
		 *
292
		 * Implementations should not retain a reference to `p`.
293
		 *
294
		 * Use Deno.iter() to turn a Reader into an AsyncIterator.
295
		 */
296
		read(p: Uint8Array): Promise<number | null>;
297
	}
298
299
	export interface ReaderSync {
300
		/** Reads up to `p.byteLength` bytes into `p`. It resolves to the number
301
		 * of bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error
302
		 * encountered. Even if `read()` returns `n` < `p.byteLength`, it may use
303
		 * all of `p` as scratch space during the call. If some data is available
304
		 * but not `p.byteLength` bytes, `read()` conventionally returns what is
305
		 * available instead of waiting for more.
306
		 *
307
		 * When `readSync()` encounters end-of-file condition, it returns EOF
308
		 * (`null`).
309
		 *
310
		 * When `readSync()` encounters an error, it throws with an error.
311
		 *
312
		 * Callers should always process the `n` > `0` bytes returned before
313
		 * considering the EOF (`null`). Doing so correctly handles I/O errors that happen
314
		 * after reading some bytes and also both of the allowed EOF behaviors.
315
		 *
316
		 * Implementations should not retain a reference to `p`.
317
		 *
318
		 * Use Deno.iterSync() to turn a ReaderSync into an Iterator.
319
		 */
320
		readSync(p: Uint8Array): number | null;
321
	}
322
323
	export interface Writer {
324
		/** Writes `p.byteLength` bytes from `p` to the underlying data stream. It
325
		 * resolves to the number of bytes written from `p` (`0` <= `n` <=
326
		 * `p.byteLength`) or reject with the error encountered that caused the
327
		 * write to stop early. `write()` must reject with a non-null error if
328
		 * would resolve to `n` < `p.byteLength`. `write()` must not modify the
329
		 * slice data, even temporarily.
330
		 *
331
		 * Implementations should not retain a reference to `p`.
332
		 */
333
		write(p: Uint8Array): Promise<number>;
334
	}
335
336
	export interface WriterSync {
337
		/** Writes `p.byteLength` bytes from `p` to the underlying data
338
		 * stream. It returns the number of bytes written from `p` (`0` <= `n`
339
		 * <= `p.byteLength`) and any error encountered that caused the write to
340
		 * stop early. `writeSync()` must throw a non-null error if it returns `n` <
341
		 * `p.byteLength`. `writeSync()` must not modify the slice data, even
342
		 * temporarily.
343
		 *
344
		 * Implementations should not retain a reference to `p`.
345
		 */
346
		writeSync(p: Uint8Array): number;
347
	}
348
349
	export interface Closer {
350
		close(): void;
351
	}
352
353
	export interface Seeker {
354
		/** Seek sets the offset for the next `read()` or `write()` to offset,
355
		 * interpreted according to `whence`: `Start` means relative to the
356
		 * start of the file, `Current` means relative to the current offset,
357
		 * and `End` means relative to the end. Seek resolves to the new offset
358
		 * relative to the start of the file.
359
		 *
360
		 * Seeking to an offset before the start of the file is an error. Seeking to
361
		 * any positive offset is legal, but the behavior of subsequent I/O
362
		 * operations on the underlying object is implementation-dependent.
363
		 * It returns the number of cursor position.
364
		 */
365
		seek(offset: number, whence: SeekMode): Promise<number>;
366
	}
367
368
	export interface SeekerSync {
369
		/** Seek sets the offset for the next `readSync()` or `writeSync()` to
370
		 * offset, interpreted according to `whence`: `Start` means relative
371
		 * to the start of the file, `Current` means relative to the current
372
		 * offset, and `End` means relative to the end.
373
		 *
374
		 * Seeking to an offset before the start of the file is an error. Seeking to
375
		 * any positive offset is legal, but the behavior of subsequent I/O
376
		 * operations on the underlying object is implementation-dependent.
377
		 */
378
		seekSync(offset: number, whence: SeekMode): number;
379
	}
380
381
	/** Copies from `src` to `dst` until either EOF (`null`) is read from `src` or
382
	 * an error occurs. It resolves to the number of bytes copied or rejects with
383
	 * the first error encountered while copying.
384
	 *
385
	 * ```ts
386
	 * const source = await Deno.open("my_file.txt");
387
	 * const buffer = new Deno.Buffer()
388
	 * const bytesCopied1 = await Deno.copy(source, Deno.stdout);
389
	 * const bytesCopied2 = await Deno.copy(source, buffer);
390
	 * ```
391
	 *
392
	 * @param src The source to copy from
393
	 * @param dst The destination to copy to
394
	 * @param options Can be used to tune size of the buffer. Default size is 32kB
395
	 */
396
	export function copy(
397
		src: Reader,
398
		dst: Writer,
399
		options?: {
400
			bufSize?: number;
401
		}
402
	): Promise<number>;
403
404
	/** Turns a Reader, `r`, into an async iterator.
405
	 *
406
	 * ```ts
407
	 * let f = await Deno.open("/etc/passwd");
408
	 * for await (const chunk of Deno.iter(f)) {
409
	 *   console.log(chunk);
410
	 * }
411
	 * f.close();
412
	 * ```
413
	 *
414
	 * Second argument can be used to tune size of a buffer.
415
	 * Default size of the buffer is 32kB.
416
	 *
417
	 * ```ts
418
	 * let f = await Deno.open("/etc/passwd");
419
	 * const iter = Deno.iter(f, {
420
	 *   bufSize: 1024 * 1024
421
	 * });
422
	 * for await (const chunk of iter) {
423
	 *   console.log(chunk);
424
	 * }
425
	 * f.close();
426
	 * ```
427
	 *
428
	 * Iterator uses an internal buffer of fixed size for efficiency; it returns
429
	 * a view on that buffer on each iteration. It is therefore caller's
430
	 * responsibility to copy contents of the buffer if needed; otherwise the
431
	 * next iteration will overwrite contents of previously returned chunk.
432
	 */
433
	export function iter(
434
		r: Reader,
435
		options?: {
436
			bufSize?: number;
437
		}
438
	): AsyncIterableIterator<Uint8Array>;
439
440
	/** Turns a ReaderSync, `r`, into an iterator.
441
	 *
442
	 * ```ts
443
	 * let f = Deno.openSync("/etc/passwd");
444
	 * for (const chunk of Deno.iterSync(f)) {
445
	 *   console.log(chunk);
446
	 * }
447
	 * f.close();
448
	 * ```
449
	 *
450
	 * Second argument can be used to tune size of a buffer.
451
	 * Default size of the buffer is 32kB.
452
	 *
453
	 * ```ts
454
	 * let f = await Deno.open("/etc/passwd");
455
	 * const iter = Deno.iterSync(f, {
456
	 *   bufSize: 1024 * 1024
457
	 * });
458
	 * for (const chunk of iter) {
459
	 *   console.log(chunk);
460
	 * }
461
	 * f.close();
462
	 * ```
463
	 *
464
	 * Iterator uses an internal buffer of fixed size for efficiency; it returns
465
	 * a view on that buffer on each iteration. It is therefore caller's
466
	 * responsibility to copy contents of the buffer if needed; otherwise the
467
	 * next iteration will overwrite contents of previously returned chunk.
468
	 */
469
	export function iterSync(
470
		r: ReaderSync,
471
		options?: {
472
			bufSize?: number;
473
		}
474
	): IterableIterator<Uint8Array>;
475
476
	/** Synchronously open a file and return an instance of `Deno.File`.  The
477
	 * file does not need to previously exist if using the `create` or `createNew`
478
	 * open options.  It is the callers responsibility to close the file when finished
479
	 * with it.
480
	 *
481
	 * ```ts
482
	 * const file = Deno.openSync("/foo/bar.txt", { read: true, write: true });
483
	 * // Do work with file
484
	 * Deno.close(file.rid);
485
	 * ```
486
	 *
487
	 * Requires `allow-read` and/or `allow-write` permissions depending on options.
488
	 */
489
	export function openSync(path: string | URL, options?: OpenOptions): File;
490
491
	/** Open a file and resolve to an instance of `Deno.File`.  The
492
	 * file does not need to previously exist if using the `create` or `createNew`
493
	 * open options.  It is the callers responsibility to close the file when finished
494
	 * with it.
495
	 *
496
	 * ```ts
497
	 * const file = await Deno.open("/foo/bar.txt", { read: true, write: true });
498
	 * // Do work with file
499
	 * Deno.close(file.rid);
500
	 * ```
501
	 *
502
	 * Requires `allow-read` and/or `allow-write` permissions depending on options.
503
	 */
504
	export function open(path: string | URL, options?: OpenOptions): Promise<File>;
505
506
	/** Creates a file if none exists or truncates an existing file and returns
507
	 *  an instance of `Deno.File`.
508
	 *
509
	 * ```ts
510
	 * const file = Deno.createSync("/foo/bar.txt");
511
	 * ```
512
	 *
513
	 * Requires `allow-read` and `allow-write` permissions.
514
	 */
515
	export function createSync(path: string | URL): File;
516
517
	/** Creates a file if none exists or truncates an existing file and resolves to
518
	 *  an instance of `Deno.File`.
519
	 *
520
	 * ```ts
521
	 * const file = await Deno.create("/foo/bar.txt");
522
	 * ```
523
	 *
524
	 * Requires `allow-read` and `allow-write` permissions.
525
	 */
526
	export function create(path: string | URL): Promise<File>;
527
528
	/** Synchronously read from a resource ID (`rid`) into an array buffer (`buffer`).
529
	 *
530
	 * Returns either the number of bytes read during the operation or EOF
531
	 * (`null`) if there was nothing more to read.
532
	 *
533
	 * It is possible for a read to successfully return with `0` bytes. This does
534
	 * not indicate EOF.
535
	 *
536
	 * This function is one of the lowest level APIs and most users should not
537
	 * work with this directly, but rather use Deno.readAllSync() instead.
538
	 *
539
	 * **It is not guaranteed that the full buffer will be read in a single call.**
540
	 *
541
	 * ```ts
542
	 * // if "/foo/bar.txt" contains the text "hello world":
543
	 * const file = Deno.openSync("/foo/bar.txt");
544
	 * const buf = new Uint8Array(100);
545
	 * const numberOfBytesRead = Deno.readSync(file.rid, buf); // 11 bytes
546
	 * const text = new TextDecoder().decode(buf);  // "hello world"
547
	 * Deno.close(file.rid);
548
	 * ```
549
	 */
550
	export function readSync(rid: number, buffer: Uint8Array): number | null;
551
552
	/** Read from a resource ID (`rid`) into an array buffer (`buffer`).
553
	 *
554
	 * Resolves to either the number of bytes read during the operation or EOF
555
	 * (`null`) if there was nothing more to read.
556
	 *
557
	 * It is possible for a read to successfully return with `0` bytes. This does
558
	 * not indicate EOF.
559
	 *
560
	 * This function is one of the lowest level APIs and most users should not
561
	 * work with this directly, but rather use Deno.readAll() instead.
562
	 *
563
	 * **It is not guaranteed that the full buffer will be read in a single call.**
564
	 *
565
	 * ```ts
566
	 * // if "/foo/bar.txt" contains the text "hello world":
567
	 * const file = await Deno.open("/foo/bar.txt");
568
	 * const buf = new Uint8Array(100);
569
	 * const numberOfBytesRead = await Deno.read(file.rid, buf); // 11 bytes
570
	 * const text = new TextDecoder().decode(buf);  // "hello world"
571
	 * Deno.close(file.rid);
572
	 * ```
573
	 */
574
	export function read(rid: number, buffer: Uint8Array): Promise<number | null>;
575
576
	/** Synchronously write to the resource ID (`rid`) the contents of the array
577
	 * buffer (`data`).
578
	 *
579
	 * Returns the number of bytes written.  This function is one of the lowest
580
	 * level APIs and most users should not work with this directly, but rather use
581
	 * Deno.writeAllSync() instead.
582
	 *
583
	 * **It is not guaranteed that the full buffer will be written in a single
584
	 * call.**
585
	 *
586
	 * ```ts
587
	 * const encoder = new TextEncoder();
588
	 * const data = encoder.encode("Hello world");
589
	 * const file = Deno.openSync("/foo/bar.txt", {write: true});
590
	 * const bytesWritten = Deno.writeSync(file.rid, data); // 11
591
	 * Deno.close(file.rid);
592
	 * ```
593
	 */
594
	export function writeSync(rid: number, data: Uint8Array): number;
595
596
	/** Write to the resource ID (`rid`) the contents of the array buffer (`data`).
597
	 *
598
	 * Resolves to the number of bytes written.  This function is one of the lowest
599
	 * level APIs and most users should not work with this directly, but rather use
600
	 * Deno.writeAll() instead.
601
	 *
602
	 * **It is not guaranteed that the full buffer will be written in a single
603
	 * call.**
604
	 *
605
	 * ```ts
606
	 * const encoder = new TextEncoder();
607
	 * const data = encoder.encode("Hello world");
608
	 * const file = await Deno.open("/foo/bar.txt", { write: true });
609
	 * const bytesWritten = await Deno.write(file.rid, data); // 11
610
	 * Deno.close(file.rid);
611
	 * ```
612
	 */
613
	export function write(rid: number, data: Uint8Array): Promise<number>;
614
615
	/** Synchronously seek a resource ID (`rid`) to the given `offset` under mode
616
	 * given by `whence`.  The new position within the resource (bytes from the
617
	 * start) is returned.
618
	 *
619
	 * ```ts
620
	 * const file = Deno.openSync('hello.txt', {read: true, write: true, truncate: true, create: true});
621
	 * Deno.writeSync(file.rid, new TextEncoder().encode("Hello world"));
622
	 * // advance cursor 6 bytes
623
	 * const cursorPosition = Deno.seekSync(file.rid, 6, Deno.SeekMode.Start);
624
	 * console.log(cursorPosition);  // 6
625
	 * const buf = new Uint8Array(100);
626
	 * file.readSync(buf);
627
	 * console.log(new TextDecoder().decode(buf)); // "world"
628
	 * ```
629
	 *
630
	 * The seek modes work as follows:
631
	 *
632
	 * ```ts
633
	 * // Given file.rid pointing to file with "Hello world", which is 11 bytes long:
634
	 * // Seek 6 bytes from the start of the file
635
	 * console.log(Deno.seekSync(file.rid, 6, Deno.SeekMode.Start)); // "6"
636
	 * // Seek 2 more bytes from the current position
637
	 * console.log(Deno.seekSync(file.rid, 2, Deno.SeekMode.Current)); // "8"
638
	 * // Seek backwards 2 bytes from the end of the file
639
	 * console.log(Deno.seekSync(file.rid, -2, Deno.SeekMode.End)); // "9" (e.g. 11-2)
640
	 * ```
641
	 */
642
	export function seekSync(rid: number, offset: number, whence: SeekMode): number;
643
644
	/** Seek a resource ID (`rid`) to the given `offset` under mode given by `whence`.
645
	 * The call resolves to the new position within the resource (bytes from the start).
646
	 *
647
	 * ```ts
648
	 * const file = await Deno.open('hello.txt', {read: true, write: true, truncate: true, create: true});
649
	 * await Deno.write(file.rid, new TextEncoder().encode("Hello world"));
650
	 * // advance cursor 6 bytes
651
	 * const cursorPosition = await Deno.seek(file.rid, 6, Deno.SeekMode.Start);
652
	 * console.log(cursorPosition);  // 6
653
	 * const buf = new Uint8Array(100);
654
	 * await file.read(buf);
655
	 * console.log(new TextDecoder().decode(buf)); // "world"
656
	 * ```
657
	 *
658
	 * The seek modes work as follows:
659
	 *
660
	 * ```ts
661
	 * // Given file.rid pointing to file with "Hello world", which is 11 bytes long:
662
	 * // Seek 6 bytes from the start of the file
663
	 * console.log(await Deno.seek(file.rid, 6, Deno.SeekMode.Start)); // "6"
664
	 * // Seek 2 more bytes from the current position
665
	 * console.log(await Deno.seek(file.rid, 2, Deno.SeekMode.Current)); // "8"
666
	 * // Seek backwards 2 bytes from the end of the file
667
	 * console.log(await Deno.seek(file.rid, -2, Deno.SeekMode.End)); // "9" (e.g. 11-2)
668
	 * ```
669
	 */
670
	export function seek(rid: number, offset: number, whence: SeekMode): Promise<number>;
671
672
	/**
673
	 * Synchronously flushes any pending data and metadata operations of the given file stream to disk.
674
	 *  ```ts
675
	 * const file = Deno.openSync("my_file.txt", { read: true, write: true, create: true });
676
	 * Deno.writeSync(file.rid, new TextEncoder().encode("Hello World"));
677
	 * Deno.ftruncateSync(file.rid, 1);
678
	 * Deno.fsyncSync(file.rid);
679
	 * console.log(new TextDecoder().decode(Deno.readFileSync("my_file.txt"))); // H
680
	 * ```
681
	 */
682
	export function fsyncSync(rid: number): void;
683
684
	/**
685
	 * Flushes any pending data and metadata operations of the given file stream to disk.
686
	 *  ```ts
687
	 * const file = await Deno.open("my_file.txt", { read: true, write: true, create: true });
688
	 * await Deno.write(file.rid, new TextEncoder().encode("Hello World"));
689
	 * await Deno.ftruncate(file.rid, 1);
690
	 * await Deno.fsync(file.rid);
691
	 * console.log(new TextDecoder().decode(await Deno.readFile("my_file.txt"))); // H
692
	 * ```
693
	 */
694
	export function fsync(rid: number): Promise<void>;
695
696
	/*
697
	 * Synchronously flushes any pending data operations of the given file stream to disk.
698
	 *  ```ts
699
	 * const file = Deno.openSync("my_file.txt", { read: true, write: true, create: true });
700
	 * Deno.writeSync(file.rid, new TextEncoder().encode("Hello World"));
701
	 * Deno.fdatasyncSync(file.rid);
702
	 * console.log(new TextDecoder().decode(Deno.readFileSync("my_file.txt"))); // Hello World
703
	 * ```
704
	 */
705
	export function fdatasyncSync(rid: number): void;
706
707
	/**
708
	 * Flushes any pending data operations of the given file stream to disk.
709
	 *  ```ts
710
	 * const file = await Deno.open("my_file.txt", { read: true, write: true, create: true });
711
	 * await Deno.write(file.rid, new TextEncoder().encode("Hello World"));
712
	 * await Deno.fdatasync(file.rid);
713
	 * console.log(new TextDecoder().decode(await Deno.readFile("my_file.txt"))); // Hello World
714
	 * ```
715
	 */
716
	export function fdatasync(rid: number): Promise<void>;
717
718
	/** Close the given resource ID (rid) which has been previously opened, such
719
	 * as via opening or creating a file.  Closing a file when you are finished
720
	 * with it is important to avoid leaking resources.
721
	 *
722
	 * ```ts
723
	 * const file = await Deno.open("my_file.txt");
724
	 * // do work with "file" object
725
	 * Deno.close(file.rid);
726
	 * ````
727
	 */
728
	export function close(rid: number): void;
729
730
	/** The Deno abstraction for reading and writing files. */
731
	export class File implements Reader, ReaderSync, Writer, WriterSync, Seeker, SeekerSync, Closer {
732
		readonly rid: number;
733
		constructor(rid: number);
734
		write(p: Uint8Array): Promise<number>;
735
		writeSync(p: Uint8Array): number;
736
		read(p: Uint8Array): Promise<number | null>;
737
		readSync(p: Uint8Array): number | null;
738
		seek(offset: number, whence: SeekMode): Promise<number>;
739
		seekSync(offset: number, whence: SeekMode): number;
740
		close(): void;
741
	}
742
743
	/** A handle for `stdin`. */
744
	export const stdin: Reader & ReaderSync & Closer & { readonly rid: number };
745
	/** A handle for `stdout`. */
746
	export const stdout: Writer & WriterSync & Closer & { readonly rid: number };
747
	/** A handle for `stderr`. */
748
	export const stderr: Writer & WriterSync & Closer & { readonly rid: number };
749
750
	export interface OpenOptions {
751
		/** Sets the option for read access. This option, when `true`, means that the
752
		 * file should be read-able if opened. */
753
		read?: boolean;
754
		/** Sets the option for write access. This option, when `true`, means that
755
		 * the file should be write-able if opened. If the file already exists,
756
		 * any write calls on it will overwrite its contents, by default without
757
		 * truncating it. */
758
		write?: boolean;
759
		/**Sets the option for the append mode. This option, when `true`, means that
760
		 * writes will append to a file instead of overwriting previous contents.
761
		 * Note that setting `{ write: true, append: true }` has the same effect as
762
		 * setting only `{ append: true }`. */
763
		append?: boolean;
764
		/** Sets the option for truncating a previous file. If a file is
765
		 * successfully opened with this option set it will truncate the file to `0`
766
		 * size if it already exists. The file must be opened with write access
767
		 * for truncate to work. */
768
		truncate?: boolean;
769
		/** Sets the option to allow creating a new file, if one doesn't already
770
		 * exist at the specified path. Requires write or append access to be
771
		 * used. */
772
		create?: boolean;
773
		/** Defaults to `false`. If set to `true`, no file, directory, or symlink is
774
		 * allowed to exist at the target location. Requires write or append
775
		 * access to be used. When createNew is set to `true`, create and truncate
776
		 * are ignored. */
777
		createNew?: boolean;
778
		/** Permissions to use if creating the file (defaults to `0o666`, before
779
		 * the process's umask).
780
		 * Ignored on Windows. */
781
		mode?: number;
782
	}
783
784
	/**
785
	 *
786
	 *  Check if a given resource id (`rid`) is a TTY.
787
	 *
788
	 * ```ts
789
	 * // This example is system and context specific
790
	 * const nonTTYRid = Deno.openSync("my_file.txt").rid;
791
	 * const ttyRid = Deno.openSync("/dev/tty6").rid;
792
	 * console.log(Deno.isatty(nonTTYRid)); // false
793
	 * console.log(Deno.isatty(ttyRid)); // true
794
	 * Deno.close(nonTTYRid);
795
	 * Deno.close(ttyRid);
796
	 * ```
797
	 */
798
	export function isatty(rid: number): boolean;
799
800
	/** A variable-sized buffer of bytes with `read()` and `write()` methods.
801
	 *
802
	 * Deno.Buffer is almost always used with some I/O like files and sockets. It
803
	 * allows one to buffer up a download from a socket. Buffer grows and shrinks
804
	 * as necessary.
805
	 *
806
	 * Deno.Buffer is NOT the same thing as Node's Buffer. Node's Buffer was
807
	 * created in 2009 before JavaScript had the concept of ArrayBuffers. It's
808
	 * simply a non-standard ArrayBuffer.
809
	 *
810
	 * ArrayBuffer is a fixed memory allocation. Deno.Buffer is implemented on top
811
	 * of ArrayBuffer.
812
	 *
813
	 * Based on [Go Buffer](https://golang.org/pkg/bytes/#Buffer). */
814
	export class Buffer implements Reader, ReaderSync, Writer, WriterSync {
815
		constructor(ab?: ArrayBuffer);
816
		/** Returns a slice holding the unread portion of the buffer.
817
		 *
818
		 * The slice is valid for use only until the next buffer modification (that
819
		 * is, only until the next call to a method like `read()`, `write()`,
820
		 * `reset()`, or `truncate()`). If `options.copy` is false the slice aliases the buffer content at
821
		 * least until the next buffer modification, so immediate changes to the
822
		 * slice will affect the result of future reads.
823
		 * @param options Defaults to `{ copy: true }`
824
		 */
825
		bytes(options?: { copy?: boolean }): Uint8Array;
826
		/** Returns whether the unread portion of the buffer is empty. */
827
		empty(): boolean;
828
		/** A read only number of bytes of the unread portion of the buffer. */
829
		readonly length: number;
830
		/** The read only capacity of the buffer's underlying byte slice, that is,
831
		 * the total space allocated for the buffer's data. */
832
		readonly capacity: number;
833
		/** Discards all but the first `n` unread bytes from the buffer but
834
		 * continues to use the same allocated storage. It throws if `n` is
835
		 * negative or greater than the length of the buffer. */
836
		truncate(n: number): void;
837
		/** Resets the buffer to be empty, but it retains the underlying storage for
838
		 * use by future writes. `.reset()` is the same as `.truncate(0)`. */
839
		reset(): void;
840
		/** Reads the next `p.length` bytes from the buffer or until the buffer is
841
		 * drained. Returns the number of bytes read. If the buffer has no data to
842
		 * return, the return is EOF (`null`). */
843
		readSync(p: Uint8Array): number | null;
844
		/** Reads the next `p.length` bytes from the buffer or until the buffer is
845
		 * drained. Resolves to the number of bytes read. If the buffer has no
846
		 * data to return, resolves to EOF (`null`).
847
		 *
848
		 * NOTE: This methods reads bytes synchronously; it's provided for
849
		 * compatibility with `Reader` interfaces.
850
		 */
851
		read(p: Uint8Array): Promise<number | null>;
852
		writeSync(p: Uint8Array): number;
853
		/** NOTE: This methods writes bytes synchronously; it's provided for
854
		 * compatibility with `Writer` interface. */
855
		write(p: Uint8Array): Promise<number>;
856
		/** Grows the buffer's capacity, if necessary, to guarantee space for
857
		 * another `n` bytes. After `.grow(n)`, at least `n` bytes can be written to
858
		 * the buffer without another allocation. If `n` is negative, `.grow()` will
859
		 * throw. If the buffer can't grow it will throw an error.
860
		 *
861
		 * Based on Go Lang's
862
		 * [Buffer.Grow](https://golang.org/pkg/bytes/#Buffer.Grow). */
863
		grow(n: number): void;
864
		/** Reads data from `r` until EOF (`null`) and appends it to the buffer,
865
		 * growing the buffer as needed. It resolves to the number of bytes read.
866
		 * If the buffer becomes too large, `.readFrom()` will reject with an error.
867
		 *
868
		 * Based on Go Lang's
869
		 * [Buffer.ReadFrom](https://golang.org/pkg/bytes/#Buffer.ReadFrom). */
870
		readFrom(r: Reader): Promise<number>;
871
		/** Reads data from `r` until EOF (`null`) and appends it to the buffer,
872
		 * growing the buffer as needed. It returns the number of bytes read. If the
873
		 * buffer becomes too large, `.readFromSync()` will throw an error.
874
		 *
875
		 * Based on Go Lang's
876
		 * [Buffer.ReadFrom](https://golang.org/pkg/bytes/#Buffer.ReadFrom). */
877
		readFromSync(r: ReaderSync): number;
878
	}
879
880
	/** Read Reader `r` until EOF (`null`) and resolve to the content as
881
	 * Uint8Array`.
882
	 *
883
	 * ```ts
884
	 * // Example from stdin
885
	 * const stdinContent = await Deno.readAll(Deno.stdin);
886
	 *
887
	 * // Example from file
888
	 * const file = await Deno.open("my_file.txt", {read: true});
889
	 * const myFileContent = await Deno.readAll(file);
890
	 * Deno.close(file.rid);
891
	 *
892
	 * // Example from buffer
893
	 * const myData = new Uint8Array(100);
894
	 * // ... fill myData array with data
895
	 * const reader = new Deno.Buffer(myData.buffer as ArrayBuffer);
896
	 * const bufferContent = await Deno.readAll(reader);
897
	 * ```
898
	 */
899
	export function readAll(r: Reader): Promise<Uint8Array>;
900
901
	/** Synchronously reads Reader `r` until EOF (`null`) and returns the content
902
	 * as `Uint8Array`.
903
	 *
904
	 * ```ts
905
	 * // Example from stdin
906
	 * const stdinContent = Deno.readAllSync(Deno.stdin);
907
	 *
908
	 * // Example from file
909
	 * const file = Deno.openSync("my_file.txt", {read: true});
910
	 * const myFileContent = Deno.readAllSync(file);
911
	 * Deno.close(file.rid);
912
	 *
913
	 * // Example from buffer
914
	 * const myData = new Uint8Array(100);
915
	 * // ... fill myData array with data
916
	 * const reader = new Deno.Buffer(myData.buffer as ArrayBuffer);
917
	 * const bufferContent = Deno.readAllSync(reader);
918
	 * ```
919
	 */
920
	export function readAllSync(r: ReaderSync): Uint8Array;
921
922
	/** Write all the content of the array buffer (`arr`) to the writer (`w`).
923
	 *
924
	 * ```ts
925
	 * // Example writing to stdout
926
	 * const contentBytes = new TextEncoder().encode("Hello World");
927
	 * await Deno.writeAll(Deno.stdout, contentBytes);
928
	 *
929
	 * // Example writing to file
930
	 * const contentBytes = new TextEncoder().encode("Hello World");
931
	 * const file = await Deno.open('test.file', {write: true});
932
	 * await Deno.writeAll(file, contentBytes);
933
	 * Deno.close(file.rid);
934
	 *
935
	 * // Example writing to buffer
936
	 * const contentBytes = new TextEncoder().encode("Hello World");
937
	 * const writer = new Deno.Buffer();
938
	 * await Deno.writeAll(writer, contentBytes);
939
	 * console.log(writer.bytes().length);  // 11
940
	 * ```
941
	 */
942
	export function writeAll(w: Writer, arr: Uint8Array): Promise<void>;
943
944
	/** Synchronously write all the content of the array buffer (`arr`) to the
945
	 * writer (`w`).
946
	 *
947
	 * ```ts
948
	 * // Example writing to stdout
949
	 * const contentBytes = new TextEncoder().encode("Hello World");
950
	 * Deno.writeAllSync(Deno.stdout, contentBytes);
951
	 *
952
	 * // Example writing to file
953
	 * const contentBytes = new TextEncoder().encode("Hello World");
954
	 * const file = Deno.openSync('test.file', {write: true});
955
	 * Deno.writeAllSync(file, contentBytes);
956
	 * Deno.close(file.rid);
957
	 *
958
	 * // Example writing to buffer
959
	 * const contentBytes = new TextEncoder().encode("Hello World");
960
	 * const writer = new Deno.Buffer();
961
	 * Deno.writeAllSync(writer, contentBytes);
962
	 * console.log(writer.bytes().length);  // 11
963
	 * ```
964
	 */
965
	export function writeAllSync(w: WriterSync, arr: Uint8Array): void;
966
967
	export interface MkdirOptions {
968
		/** Defaults to `false`. If set to `true`, means that any intermediate
969
		 * directories will also be created (as with the shell command `mkdir -p`).
970
		 * Intermediate directories are created with the same permissions.
971
		 * When recursive is set to `true`, succeeds silently (without changing any
972
		 * permissions) if a directory already exists at the path, or if the path
973
		 * is a symlink to an existing directory. */
974
		recursive?: boolean;
975
		/** Permissions to use when creating the directory (defaults to `0o777`,
976
		 * before the process's umask).
977
		 * Ignored on Windows. */
978
		mode?: number;
979
	}
980
981
	/** Synchronously creates a new directory with the specified path.
982
	 *
983
	 * ```ts
984
	 * Deno.mkdirSync("new_dir");
985
	 * Deno.mkdirSync("nested/directories", { recursive: true });
986
	 * Deno.mkdirSync("restricted_access_dir", { mode: 0o700 });
987
	 * ```
988
	 *
989
	 * Defaults to throwing error if the directory already exists.
990
	 *
991
	 * Requires `allow-write` permission. */
992
	export function mkdirSync(path: string | URL, options?: MkdirOptions): void;
993
994
	/** Creates a new directory with the specified path.
995
	 *
996
	 * ```ts
997
	 * await Deno.mkdir("new_dir");
998
	 * await Deno.mkdir("nested/directories", { recursive: true });
999
	 * await Deno.mkdir("restricted_access_dir", { mode: 0o700 });
1000
	 * ```
1001
	 *
1002
	 * Defaults to throwing error if the directory already exists.
1003
	 *
1004
	 * Requires `allow-write` permission. */
1005
	export function mkdir(path: string | URL, options?: MkdirOptions): Promise<void>;
1006
1007
	export interface MakeTempOptions {
1008
		/** Directory where the temporary directory should be created (defaults to
1009
		 * the env variable TMPDIR, or the system's default, usually /tmp).
1010
		 *
1011
		 * Note that if the passed `dir` is relative, the path returned by
1012
		 * makeTempFile() and makeTempDir() will also be relative. Be mindful of
1013
		 * this when changing working directory. */
1014
		dir?: string;
1015
		/** String that should precede the random portion of the temporary
1016
		 * directory's name. */
1017
		prefix?: string;
1018
		/** String that should follow the random portion of the temporary
1019
		 * directory's name. */
1020
		suffix?: string;
1021
	}
1022
1023
	/** Synchronously creates a new temporary directory in the default directory
1024
	 * for temporary files, unless `dir` is specified. Other optional options
1025
	 * include prefixing and suffixing the directory name with `prefix` and
1026
	 * `suffix` respectively.
1027
	 *
1028
	 * The full path to the newly created directory is returned.
1029
	 *
1030
	 * Multiple programs calling this function simultaneously will create different
1031
	 * directories. It is the caller's responsibility to remove the directory when
1032
	 * no longer needed.
1033
	 *
1034
	 * ```ts
1035
	 * const tempDirName0 = Deno.makeTempDirSync();  // e.g. /tmp/2894ea76
1036
	 * const tempDirName1 = Deno.makeTempDirSync({ prefix: 'my_temp' });  // e.g. /tmp/my_temp339c944d
1037
	 * ```
1038
	 *
1039
	 * Requires `allow-write` permission. */
1040
	// TODO(ry) Doesn't check permissions.
1041
	export function makeTempDirSync(options?: MakeTempOptions): string;
1042
1043
	/** Creates a new temporary directory in the default directory for temporary
1044
	 * files, unless `dir` is specified. Other optional options include
1045
	 * prefixing and suffixing the directory name with `prefix` and `suffix`
1046
	 * respectively.
1047
	 *
1048
	 * This call resolves to the full path to the newly created directory.
1049
	 *
1050
	 * Multiple programs calling this function simultaneously will create different
1051
	 * directories. It is the caller's responsibility to remove the directory when
1052
	 * no longer needed.
1053
	 *
1054
	 * ```ts
1055
	 * const tempDirName0 = await Deno.makeTempDir();  // e.g. /tmp/2894ea76
1056
	 * const tempDirName1 = await Deno.makeTempDir({ prefix: 'my_temp' }); // e.g. /tmp/my_temp339c944d
1057
	 * ```
1058
	 *
1059
	 * Requires `allow-write` permission. */
1060
	// TODO(ry) Doesn't check permissions.
1061
	export function makeTempDir(options?: MakeTempOptions): Promise<string>;
1062
1063
	/** Synchronously creates a new temporary file in the default directory for
1064
	 * temporary files, unless `dir` is specified.
1065
	 * Other optional options include prefixing and suffixing the directory name
1066
	 * with `prefix` and `suffix` respectively.
1067
	 *
1068
	 * The full path to the newly created file is returned.
1069
	 *
1070
	 * Multiple programs calling this function simultaneously will create different
1071
	 * files. It is the caller's responsibility to remove the file when no longer
1072
	 * needed.
1073
	 *
1074
	 * ```ts
1075
	 * const tempFileName0 = Deno.makeTempFileSync(); // e.g. /tmp/419e0bf2
1076
	 * const tempFileName1 = Deno.makeTempFileSync({ prefix: 'my_temp' });  // e.g. /tmp/my_temp754d3098
1077
	 * ```
1078
	 *
1079
	 * Requires `allow-write` permission. */
1080
	export function makeTempFileSync(options?: MakeTempOptions): string;
1081
1082
	/** Creates a new temporary file in the default directory for temporary
1083
	 * files, unless `dir` is specified.  Other
1084
	 * optional options include prefixing and suffixing the directory name with
1085
	 * `prefix` and `suffix` respectively.
1086
	 *
1087
	 * This call resolves to the full path to the newly created file.
1088
	 *
1089
	 * Multiple programs calling this function simultaneously will create different
1090
	 * files. It is the caller's responsibility to remove the file when no longer
1091
	 * needed.
1092
	 *
1093
	 * ```ts
1094
	 * const tmpFileName0 = await Deno.makeTempFile();  // e.g. /tmp/419e0bf2
1095
	 * const tmpFileName1 = await Deno.makeTempFile({ prefix: 'my_temp' });  // e.g. /tmp/my_temp754d3098
1096
	 * ```
1097
	 *
1098
	 * Requires `allow-write` permission. */
1099
	export function makeTempFile(options?: MakeTempOptions): Promise<string>;
1100
1101
	/** Synchronously changes the permission of a specific file/directory of
1102
	 * specified path.  Ignores the process's umask.
1103
	 *
1104
	 * ```ts
1105
	 * Deno.chmodSync("/path/to/file", 0o666);
1106
	 * ```
1107
	 *
1108
	 * For a full description, see [chmod](#Deno.chmod)
1109
	 *
1110
	 * NOTE: This API currently throws on Windows
1111
	 *
1112
	 * Requires `allow-write` permission. */
1113
	export function chmodSync(path: string | URL, mode: number): void;
1114
1115
	/** Changes the permission of a specific file/directory of specified path.
1116
	 * Ignores the process's umask.
1117
	 *
1118
	 * ```ts
1119
	 * await Deno.chmod("/path/to/file", 0o666);
1120
	 * ```
1121
	 *
1122
	 * The mode is a sequence of 3 octal numbers.  The first/left-most number
1123
	 * specifies the permissions for the owner.  The second number specifies the
1124
	 * permissions for the group. The last/right-most number specifies the
1125
	 * permissions for others.  For example, with a mode of 0o764, the owner (7) can
1126
	 * read/write/execute, the group (6) can read/write and everyone else (4) can
1127
	 * read only.
1128
	 *
1129
	 * | Number | Description |
1130
	 * | ------ | ----------- |
1131
	 * | 7      | read, write, and execute |
1132
	 * | 6      | read and write |
1133
	 * | 5      | read and execute |
1134
	 * | 4      | read only |
1135
	 * | 3      | write and execute |
1136
	 * | 2      | write only |
1137
	 * | 1      | execute only |
1138
	 * | 0      | no permission |
1139
	 *
1140
	 * NOTE: This API currently throws on Windows
1141
	 *
1142
	 * Requires `allow-write` permission. */
1143
	export function chmod(path: string | URL, mode: number): Promise<void>;
1144
1145
	/** Synchronously change owner of a regular file or directory. This functionality
1146
	 * is not available on Windows.
1147
	 *
1148
	 * ```ts
1149
	 * Deno.chownSync("myFile.txt", 1000, 1002);
1150
	 * ```
1151
	 *
1152
	 * Requires `allow-write` permission.
1153
	 *
1154
	 * Throws Error (not implemented) if executed on Windows
1155
	 *
1156
	 * @param path path to the file
1157
	 * @param uid user id (UID) of the new owner, or `null` for no change
1158
	 * @param gid group id (GID) of the new owner, or `null` for no change
1159
	 */
1160
	export function chownSync(path: string | URL, uid: number | null, gid: number | null): void;
1161
1162
	/** Change owner of a regular file or directory. This functionality
1163
	 * is not available on Windows.
1164
	 *
1165
	 * ```ts
1166
	 * await Deno.chown("myFile.txt", 1000, 1002);
1167
	 * ```
1168
	 *
1169
	 * Requires `allow-write` permission.
1170
	 *
1171
	 * Throws Error (not implemented) if executed on Windows
1172
	 *
1173
	 * @param path path to the file
1174
	 * @param uid user id (UID) of the new owner, or `null` for no change
1175
	 * @param gid group id (GID) of the new owner, or `null` for no change
1176
	 */
1177
	export function chown(path: string | URL, uid: number | null, gid: number | null): Promise<void>;
1178
1179
	export interface RemoveOptions {
1180
		/** Defaults to `false`. If set to `true`, path will be removed even if
1181
		 * it's a non-empty directory. */
1182
		recursive?: boolean;
1183
	}
1184
1185
	/** Synchronously removes the named file or directory.
1186
	 *
1187
	 * ```ts
1188
	 * Deno.removeSync("/path/to/empty_dir/or/file");
1189
	 * Deno.removeSync("/path/to/populated_dir/or/file", { recursive: true });
1190
	 * ```
1191
	 *
1192
	 * Throws error if permission denied, path not found, or path is a non-empty
1193
	 * directory and the `recursive` option isn't set to `true`.
1194
	 *
1195
	 * Requires `allow-write` permission. */
1196
	export function removeSync(path: string | URL, options?: RemoveOptions): void;
1197
1198
	/** Removes the named file or directory.
1199
	 *
1200
	 * ```ts
1201
	 * await Deno.remove("/path/to/empty_dir/or/file");
1202
	 * await Deno.remove("/path/to/populated_dir/or/file", { recursive: true });
1203
	 * ```
1204
	 *
1205
	 * Throws error if permission denied, path not found, or path is a non-empty
1206
	 * directory and the `recursive` option isn't set to `true`.
1207
	 *
1208
	 * Requires `allow-write` permission. */
1209
	export function remove(path: string | URL, options?: RemoveOptions): Promise<void>;
1210
1211
	/** Synchronously renames (moves) `oldpath` to `newpath`. Paths may be files or
1212
	 * directories.  If `newpath` already exists and is not a directory,
1213
	 * `renameSync()` replaces it. OS-specific restrictions may apply when
1214
	 * `oldpath` and `newpath` are in different directories.
1215
	 *
1216
	 * ```ts
1217
	 * Deno.renameSync("old/path", "new/path");
1218
	 * ```
1219
	 *
1220
	 * On Unix, this operation does not follow symlinks at either path.
1221
	 *
1222
	 * It varies between platforms when the operation throws errors, and if so what
1223
	 * they are. It's always an error to rename anything to a non-empty directory.
1224
	 *
1225
	 * Requires `allow-read` and `allow-write` permissions. */
1226
	export function renameSync(oldpath: string, newpath: string): void;
1227
1228
	/** Renames (moves) `oldpath` to `newpath`.  Paths may be files or directories.
1229
	 * If `newpath` already exists and is not a directory, `rename()` replaces it.
1230
	 * OS-specific restrictions may apply when `oldpath` and `newpath` are in
1231
	 * different directories.
1232
	 *
1233
	 * ```ts
1234
	 * await Deno.rename("old/path", "new/path");
1235
	 * ```
1236
	 *
1237
	 * On Unix, this operation does not follow symlinks at either path.
1238
	 *
1239
	 * It varies between platforms when the operation throws errors, and if so what
1240
	 * they are. It's always an error to rename anything to a non-empty directory.
1241
	 *
1242
	 * Requires `allow-read` and `allow-write` permission. */
1243
	export function rename(oldpath: string, newpath: string): Promise<void>;
1244
1245
	/** Synchronously reads and returns the entire contents of a file as utf8
1246
	 *  encoded string. Reading a directory throws an error.
1247
	 *
1248
	 * ```ts
1249
	 * const data = Deno.readTextFileSync("hello.txt");
1250
	 * console.log(data);
1251
	 * ```
1252
	 *
1253
	 * Requires `allow-read` permission. */
1254
	export function readTextFileSync(path: string | URL): string;
1255
1256
	/** Asynchronously reads and returns the entire contents of a file as utf8
1257
	 *  encoded string. Reading a directory throws an error.
1258
	 *
1259
	 * ```ts
1260
	 * const data = await Deno.readTextFile("hello.txt");
1261
	 * console.log(data);
1262
	 * ```
1263
	 *
1264
	 * Requires `allow-read` permission. */
1265
	export function readTextFile(path: string | URL): Promise<string>;
1266
1267
	/** Synchronously reads and returns the entire contents of a file as an array
1268
	 * of bytes. `TextDecoder` can be used to transform the bytes to string if
1269
	 * required.  Reading a directory returns an empty data array.
1270
	 *
1271
	 * ```ts
1272
	 * const decoder = new TextDecoder("utf-8");
1273
	 * const data = Deno.readFileSync("hello.txt");
1274
	 * console.log(decoder.decode(data));
1275
	 * ```
1276
	 *
1277
	 * Requires `allow-read` permission. */
1278
	export function readFileSync(path: string | URL): Uint8Array;
1279
1280
	/** Reads and resolves to the entire contents of a file as an array of bytes.
1281
	 * `TextDecoder` can be used to transform the bytes to string if required.
1282
	 * Reading a directory returns an empty data array.
1283
	 *
1284
	 * ```ts
1285
	 * const decoder = new TextDecoder("utf-8");
1286
	 * const data = await Deno.readFile("hello.txt");
1287
	 * console.log(decoder.decode(data));
1288
	 * ```
1289
	 *
1290
	 * Requires `allow-read` permission. */
1291
	export function readFile(path: string | URL): Promise<Uint8Array>;
1292
1293
	/** A FileInfo describes a file and is returned by `stat`, `lstat`,
1294
	 * `statSync`, `lstatSync`. */
1295
	export interface FileInfo {
1296
		/** True if this is info for a regular file. Mutually exclusive to
1297
		 * `FileInfo.isDirectory` and `FileInfo.isSymlink`. */
1298
		isFile: boolean;
1299
		/** True if this is info for a regular directory. Mutually exclusive to
1300
		 * `FileInfo.isFile` and `FileInfo.isSymlink`. */
1301
		isDirectory: boolean;
1302
		/** True if this is info for a symlink. Mutually exclusive to
1303
		 * `FileInfo.isFile` and `FileInfo.isDirectory`. */
1304
		isSymlink: boolean;
1305
		/** The size of the file, in bytes. */
1306
		size: number;
1307
		/** The last modification time of the file. This corresponds to the `mtime`
1308
		 * field from `stat` on Linux/Mac OS and `ftLastWriteTime` on Windows. This
1309
		 * may not be available on all platforms. */
1310
		mtime: Date | null;
1311
		/** The last access time of the file. This corresponds to the `atime`
1312
		 * field from `stat` on Unix and `ftLastAccessTime` on Windows. This may not
1313
		 * be available on all platforms. */
1314
		atime: Date | null;
1315
		/** The creation time of the file. This corresponds to the `birthtime`
1316
		 * field from `stat` on Mac/BSD and `ftCreationTime` on Windows. This may
1317
		 * not be available on all platforms. */
1318
		birthtime: Date | null;
1319
		/** ID of the device containing the file.
1320
		 *
1321
		 * _Linux/Mac OS only._ */
1322
		dev: number | null;
1323
		/** Inode number.
1324
		 *
1325
		 * _Linux/Mac OS only._ */
1326
		ino: number | null;
1327
		/** **UNSTABLE**: Match behavior with Go on Windows for `mode`.
1328
		 *
1329
		 * The underlying raw `st_mode` bits that contain the standard Unix
1330
		 * permissions for this file/directory. */
1331
		mode: number | null;
1332
		/** Number of hard links pointing to this file.
1333
		 *
1334
		 * _Linux/Mac OS only._ */
1335
		nlink: number | null;
1336
		/** User ID of the owner of this file.
1337
		 *
1338
		 * _Linux/Mac OS only._ */
1339
		uid: number | null;
1340
		/** Group ID of the owner of this file.
1341
		 *
1342
		 * _Linux/Mac OS only._ */
1343
		gid: number | null;
1344
		/** Device ID of this file.
1345
		 *
1346
		 * _Linux/Mac OS only._ */
1347
		rdev: number | null;
1348
		/** Blocksize for filesystem I/O.
1349
		 *
1350
		 * _Linux/Mac OS only._ */
1351
		blksize: number | null;
1352
		/** Number of blocks allocated to the file, in 512-byte units.
1353
		 *
1354
		 * _Linux/Mac OS only._ */
1355
		blocks: number | null;
1356
	}
1357
1358
	/** Returns absolute normalized path, with symbolic links resolved.
1359
	 *
1360
	 * ```ts
1361
	 * // e.g. given /home/alice/file.txt and current directory /home/alice
1362
	 * Deno.symlinkSync("file.txt", "symlink_file.txt");
1363
	 * const realPath = Deno.realPathSync("./file.txt");
1364
	 * const realSymLinkPath = Deno.realPathSync("./symlink_file.txt");
1365
	 * console.log(realPath);  // outputs "/home/alice/file.txt"
1366
	 * console.log(realSymLinkPath);  // outputs "/home/alice/file.txt"
1367
	 * ```
1368
	 *
1369
	 * Requires `allow-read` permission for the target path.
1370
	 * Also requires `allow-read` permission for the CWD if the target path is
1371
	 * relative.*/
1372
	export function realPathSync(path: string): string;
1373
1374
	/** Resolves to the absolute normalized path, with symbolic links resolved.
1375
	 *
1376
	 * ```ts
1377
	 * // e.g. given /home/alice/file.txt and current directory /home/alice
1378
	 * await Deno.symlink("file.txt", "symlink_file.txt");
1379
	 * const realPath = await Deno.realPath("./file.txt");
1380
	 * const realSymLinkPath = await Deno.realPath("./symlink_file.txt");
1381
	 * console.log(realPath);  // outputs "/home/alice/file.txt"
1382
	 * console.log(realSymLinkPath);  // outputs "/home/alice/file.txt"
1383
	 * ```
1384
	 *
1385
	 * Requires `allow-read` permission for the target path.
1386
	 * Also requires `allow-read` permission for the CWD if the target path is
1387
	 * relative.*/
1388
	export function realPath(path: string): Promise<string>;
1389
1390
	export interface DirEntry {
1391
		name: string;
1392
		isFile: boolean;
1393
		isDirectory: boolean;
1394
		isSymlink: boolean;
1395
	}
1396
1397
	/** Synchronously reads the directory given by `path` and returns an iterable
1398
	 * of `Deno.DirEntry`.
1399
	 *
1400
	 * ```ts
1401
	 * for (const dirEntry of Deno.readDirSync("/")) {
1402
	 *   console.log(dirEntry.name);
1403
	 * }
1404
	 * ```
1405
	 *
1406
	 * Throws error if `path` is not a directory.
1407
	 *
1408
	 * Requires `allow-read` permission. */
1409
	export function readDirSync(path: string | URL): Iterable<DirEntry>;
1410
1411
	/** Reads the directory given by `path` and returns an async iterable of
1412
	 * `Deno.DirEntry`.
1413
	 *
1414
	 * ```ts
1415
	 * for await (const dirEntry of Deno.readDir("/")) {
1416
	 *   console.log(dirEntry.name);
1417
	 * }
1418
	 * ```
1419
	 *
1420
	 * Throws error if `path` is not a directory.
1421
	 *
1422
	 * Requires `allow-read` permission. */
1423
	export function readDir(path: string | URL): AsyncIterable<DirEntry>;
1424
1425
	/** Synchronously copies the contents and permissions of one file to another
1426
	 * specified path, by default creating a new file if needed, else overwriting.
1427
	 * Fails if target path is a directory or is unwritable.
1428
	 *
1429
	 * ```ts
1430
	 * Deno.copyFileSync("from.txt", "to.txt");
1431
	 * ```
1432
	 *
1433
	 * Requires `allow-read` permission on fromPath.
1434
	 * Requires `allow-write` permission on toPath. */
1435
	export function copyFileSync(fromPath: string | URL, toPath: string | URL): void;
1436
1437
	/** Copies the contents and permissions of one file to another specified path,
1438
	 * by default creating a new file if needed, else overwriting. Fails if target
1439
	 * path is a directory or is unwritable.
1440
	 *
1441
	 * ```ts
1442
	 * await Deno.copyFile("from.txt", "to.txt");
1443
	 * ```
1444
	 *
1445
	 * Requires `allow-read` permission on fromPath.
1446
	 * Requires `allow-write` permission on toPath. */
1447
	export function copyFile(fromPath: string | URL, toPath: string | URL): Promise<void>;
1448
1449
	/** Returns the full path destination of the named symbolic link.
1450
	 *
1451
	 * ```ts
1452
	 * Deno.symlinkSync("./test.txt", "./test_link.txt");
1453
	 * const target = Deno.readLinkSync("./test_link.txt"); // full path of ./test.txt
1454
	 * ```
1455
	 *
1456
	 * Throws TypeError if called with a hard link
1457
	 *
1458
	 * Requires `allow-read` permission. */
1459
	export function readLinkSync(path: string | URL): string;
1460
1461
	/** Resolves to the full path destination of the named symbolic link.
1462
	 *
1463
	 * ```ts
1464
	 * await Deno.symlink("./test.txt", "./test_link.txt");
1465
	 * const target = await Deno.readLink("./test_link.txt"); // full path of ./test.txt
1466
	 * ```
1467
	 *
1468
	 * Throws TypeError if called with a hard link
1469
	 *
1470
	 * Requires `allow-read` permission. */
1471
	export function readLink(path: string | URL): Promise<string>;
1472
1473
	/** Resolves to a `Deno.FileInfo` for the specified `path`. If `path` is a
1474
	 * symlink, information for the symlink will be returned instead of what it
1475
	 * points to.
1476
	 *
1477
	 * ```ts
1478
	 * import { assert } from "https://deno.land/std/testing/asserts.ts";
1479
	 * const fileInfo = await Deno.lstat("hello.txt");
1480
	 * assert(fileInfo.isFile);
1481
	 * ```
1482
	 *
1483
	 * Requires `allow-read` permission. */
1484
	export function lstat(path: string | URL): Promise<FileInfo>;
1485
1486
	/** Synchronously returns a `Deno.FileInfo` for the specified `path`. If
1487
	 * `path` is a symlink, information for the symlink will be returned instead of
1488
	 * what it points to..
1489
	 *
1490
	 * ```ts
1491
	 * const fileInfo = Deno.lstatSync("hello.txt");
1492
	 * assert(fileInfo.isFile);
1493
	 * ```
1494
	 *
1495
	 * Requires `allow-read` permission. */
1496
	export function lstatSync(path: string | URL): FileInfo;
1497
1498
	/** Resolves to a `Deno.FileInfo` for the specified `path`. Will always
1499
	 * follow symlinks.
1500
	 *
1501
	 * ```ts
1502
	 * import { assert } from "https://deno.land/std/testing/asserts.ts";
1503
	 * const fileInfo = await Deno.stat("hello.txt");
1504
	 * assert(fileInfo.isFile);
1505
	 * ```
1506
	 *
1507
	 * Requires `allow-read` permission. */
1508
	export function stat(path: string | URL): Promise<FileInfo>;
1509
1510
	/** Synchronously returns a `Deno.FileInfo` for the specified `path`. Will
1511
	 * always follow symlinks.
1512
	 *
1513
	 * ```ts
1514
	 * import { assert } from "https://deno.land/std/testing/asserts.ts";
1515
	 * const fileInfo = Deno.statSync("hello.txt");
1516
	 * assert(fileInfo.isFile);
1517
	 * ```
1518
	 *
1519
	 * Requires `allow-read` permission. */
1520
	export function statSync(path: string | URL): FileInfo;
1521
1522
	/** Options for writing to a file. */
1523
	export interface WriteFileOptions {
1524
		/** Defaults to `false`. If set to `true`, will append to a file instead of
1525
		 * overwriting previous contents. */
1526
		append?: boolean;
1527
		/** Sets the option to allow creating a new file, if one doesn't already
1528
		 * exist at the specified path (defaults to `true`). */
1529
		create?: boolean;
1530
		/** Permissions always applied to file. */
1531
		mode?: number;
1532
	}
1533
1534
	/** Synchronously write `data` to the given `path`, by default creating a new
1535
	 * file if needed, else overwriting.
1536
	 *
1537
	 * ```ts
1538
	 * const encoder = new TextEncoder();
1539
	 * const data = encoder.encode("Hello world\n");
1540
	 * Deno.writeFileSync("hello1.txt", data);  // overwrite "hello1.txt" or create it
1541
	 * Deno.writeFileSync("hello2.txt", data, {create: false});  // only works if "hello2.txt" exists
1542
	 * Deno.writeFileSync("hello3.txt", data, {mode: 0o777});  // set permissions on new file
1543
	 * Deno.writeFileSync("hello4.txt", data, {append: true});  // add data to the end of the file
1544
	 * ```
1545
	 *
1546
	 * Requires `allow-write` permission, and `allow-read` if `options.create` is
1547
	 * `false`.
1548
	 */
1549
	export function writeFileSync(
1550
		path: string | URL,
1551
		data: Uint8Array,
1552
		options?: WriteFileOptions
1553
	): void;
1554
1555
	/** Write `data` to the given `path`, by default creating a new file if needed,
1556
	 * else overwriting.
1557
	 *
1558
	 * ```ts
1559
	 * const encoder = new TextEncoder();
1560
	 * const data = encoder.encode("Hello world\n");
1561
	 * await Deno.writeFile("hello1.txt", data);  // overwrite "hello1.txt" or create it
1562
	 * await Deno.writeFile("hello2.txt", data, {create: false});  // only works if "hello2.txt" exists
1563
	 * await Deno.writeFile("hello3.txt", data, {mode: 0o777});  // set permissions on new file
1564
	 * await Deno.writeFile("hello4.txt", data, {append: true});  // add data to the end of the file
1565
	 * ```
1566
	 *
1567
	 * Requires `allow-write` permission, and `allow-read` if `options.create` is `false`.
1568
	 */
1569
	export function writeFile(
1570
		path: string | URL,
1571
		data: Uint8Array,
1572
		options?: WriteFileOptions
1573
	): Promise<void>;
1574
1575
	/** Synchronously write string `data` to the given `path`, by default creating a new file if needed,
1576
	 * else overwriting.
1577
	 *
1578
	 * ```ts
1579
	 * Deno.writeTextFileSync("hello1.txt", "Hello world\n");  // overwrite "hello1.txt" or create it
1580
	 * ```
1581
	 *
1582
	 * Requires `allow-write` permission, and `allow-read` if `options.create` is `false`.
1583
	 */
1584
	export function writeTextFileSync(
1585
		path: string | URL,
1586
		data: string,
1587
		options?: WriteFileOptions
1588
	): void;
1589
1590
	/** Asynchronously write string `data` to the given `path`, by default creating a new file if needed,
1591
	 * else overwriting.
1592
	 *
1593
	 * ```ts
1594
	 * await Deno.writeTextFile("hello1.txt", "Hello world\n");  // overwrite "hello1.txt" or create it
1595
	 * ```
1596
	 *
1597
	 * Requires `allow-write` permission, and `allow-read` if `options.create` is `false`.
1598
	 */
1599
	export function writeTextFile(
1600
		path: string | URL,
1601
		data: string,
1602
		options?: WriteFileOptions
1603
	): Promise<void>;
1604
1605
	/** Synchronously truncates or extends the specified file, to reach the
1606
	 * specified `len`.  If `len` is not specified then the entire file contents
1607
	 * are truncated.
1608
	 *
1609
	 * ```ts
1610
	 * // truncate the entire file
1611
	 * Deno.truncateSync("my_file.txt");
1612
	 *
1613
	 * // truncate part of the file
1614
	 * const file = Deno.makeTempFileSync();
1615
	 * Deno.writeFileSync(file, new TextEncoder().encode("Hello World"));
1616
	 * Deno.truncateSync(file, 7);
1617
	 * const data = Deno.readFileSync(file);
1618
	 * console.log(new TextDecoder().decode(data));
1619
	 * ```
1620
	 *
1621
	 * Requires `allow-write` permission. */
1622
	export function truncateSync(name: string, len?: number): void;
1623
1624
	/** Truncates or extends the specified file, to reach the specified `len`. If
1625
	 * `len` is not specified then the entire file contents are truncated.
1626
	 *
1627
	 * ```ts
1628
	 * // truncate the entire file
1629
	 * await Deno.truncate("my_file.txt");
1630
	 *
1631
	 * // truncate part of the file
1632
	 * const file = await Deno.makeTempFile();
1633
	 * await Deno.writeFile(file, new TextEncoder().encode("Hello World"));
1634
	 * await Deno.truncate(file, 7);
1635
	 * const data = await Deno.readFile(file);
1636
	 * console.log(new TextDecoder().decode(data));  // "Hello W"
1637
	 * ```
1638
	 *
1639
	 * Requires `allow-write` permission. */
1640
	export function truncate(name: string, len?: number): Promise<void>;
1641
1642
	export interface NetAddr {
1643
		transport: 'tcp' | 'udp';
1644
		hostname: string;
1645
		port: number;
1646
	}
1647
1648
	export interface UnixAddr {
1649
		transport: 'unix' | 'unixpacket';
1650
		path: string;
1651
	}
1652
1653
	export type Addr = NetAddr | UnixAddr;
1654
1655
	/** A generic network listener for stream-oriented protocols. */
1656
	export interface Listener extends AsyncIterable<Conn> {
1657
		/** Waits for and resolves to the next connection to the `Listener`. */
1658
		accept(): Promise<Conn>;
1659
		/** Close closes the listener. Any pending accept promises will be rejected
1660
		 * with errors. */
1661
		close(): void;
1662
		/** Return the address of the `Listener`. */
1663
		readonly addr: Addr;
1664
1665
		/** Return the rid of the `Listener`. */
1666
		readonly rid: number;
1667
1668
		[Symbol.asyncIterator](): AsyncIterableIterator<Conn>;
1669
	}
1670
1671
	export interface Conn extends Reader, Writer, Closer {
1672
		/** The local address of the connection. */
1673
		readonly localAddr: Addr;
1674
		/** The remote address of the connection. */
1675
		readonly remoteAddr: Addr;
1676
		/** The resource ID of the connection. */
1677
		readonly rid: number;
1678
		/** Shuts down (`shutdown(2)`) the writing side of the TCP connection. Most
1679
		 * callers should just use `close()`.
1680
		 *
1681
		 * **Unstable** because of lack of testing and because Deno.shutdown is also
1682
		 * unstable.
1683
		 * */
1684
		closeWrite(): void;
1685
	}
1686
1687
	export interface ListenOptions {
1688
		/** The port to listen on. */
1689
		port: number;
1690
		/** A literal IP address or host name that can be resolved to an IP address.
1691
		 * If not specified, defaults to `0.0.0.0`. */
1692
		hostname?: string;
1693
	}
1694
1695
	/** Listen announces on the local transport address.
1696
	 *
1697
	 * ```ts
1698
	 * const listener1 = Deno.listen({ port: 80 })
1699
	 * const listener2 = Deno.listen({ hostname: "192.0.2.1", port: 80 })
1700
	 * const listener3 = Deno.listen({ hostname: "[2001:db8::1]", port: 80 });
1701
	 * const listener4 = Deno.listen({ hostname: "golang.org", port: 80, transport: "tcp" });
1702
	 * ```
1703
	 *
1704
	 * Requires `allow-net` permission. */
1705
	export function listen(options: ListenOptions & { transport?: 'tcp' }): Listener;
1706
1707
	export interface ListenTlsOptions extends ListenOptions {
1708
		/** Server certificate file. */
1709
		certFile: string;
1710
		/** Server public key file. */
1711
		keyFile: string;
1712
1713
		transport?: 'tcp';
1714
	}
1715
1716
	/** Listen announces on the local transport address over TLS (transport layer
1717
	 * security).
1718
	 *
1719
	 * ```ts
1720
	 * const lstnr = Deno.listenTls({ port: 443, certFile: "./server.crt", keyFile: "./server.key" });
1721
	 * ```
1722
	 *
1723
	 * Requires `allow-net` permission. */
1724
	export function listenTls(options: ListenTlsOptions): Listener;
1725
1726
	export interface ConnectOptions {
1727
		/** The port to connect to. */
1728
		port: number;
1729
		/** A literal IP address or host name that can be resolved to an IP address.
1730
		 * If not specified, defaults to `127.0.0.1`. */
1731
		hostname?: string;
1732
		transport?: 'tcp';
1733
	}
1734
1735
	/**
1736
	 * Connects to the hostname (default is "127.0.0.1") and port on the named
1737
	 * transport (default is "tcp"), and resolves to the connection (`Conn`).
1738
	 *
1739
	 * ```ts
1740
	 * const conn1 = await Deno.connect({ port: 80 });
1741
	 * const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 });
1742
	 * const conn3 = await Deno.connect({ hostname: "[2001:db8::1]", port: 80 });
1743
	 * const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" });
1744
	 * ```
1745
	 *
1746
	 * Requires `allow-net` permission for "tcp". */
1747
	export function connect(options: ConnectOptions): Promise<Conn>;
1748
1749
	export interface ConnectTlsOptions {
1750
		/** The port to connect to. */
1751
		port: number;
1752
		/** A literal IP address or host name that can be resolved to an IP address.
1753
		 * If not specified, defaults to `127.0.0.1`. */
1754
		hostname?: string;
1755
		/** Server certificate file. */
1756
		certFile?: string;
1757
	}
1758
1759
	/** Establishes a secure connection over TLS (transport layer security) using
1760
	 * an optional cert file, hostname (default is "127.0.0.1") and port.  The
1761
	 * cert file is optional and if not included Mozilla's root certificates will
1762
	 * be used (see also https://github.com/ctz/webpki-roots for specifics)
1763
	 *
1764
	 * ```ts
1765
	 * const conn1 = await Deno.connectTls({ port: 80 });
1766
	 * const conn2 = await Deno.connectTls({ certFile: "./certs/my_custom_root_CA.pem", hostname: "192.0.2.1", port: 80 });
1767
	 * const conn3 = await Deno.connectTls({ hostname: "[2001:db8::1]", port: 80 });
1768
	 * const conn4 = await Deno.connectTls({ certFile: "./certs/my_custom_root_CA.pem", hostname: "golang.org", port: 80});
1769
	 * ```
1770
	 *
1771
	 * Requires `allow-net` permission.
1772
	 */
1773
	export function connectTls(options: ConnectTlsOptions): Promise<Conn>;
1774
1775
	export interface Metrics {
1776
		opsDispatched: number;
1777
		opsDispatchedSync: number;
1778
		opsDispatchedAsync: number;
1779
		opsDispatchedAsyncUnref: number;
1780
		opsCompleted: number;
1781
		opsCompletedSync: number;
1782
		opsCompletedAsync: number;
1783
		opsCompletedAsyncUnref: number;
1784
		bytesSentControl: number;
1785
		bytesSentData: number;
1786
		bytesReceived: number;
1787
	}
1788
1789
	/** Receive metrics from the privileged side of Deno. This is primarily used
1790
	 * in the development of Deno. 'Ops', also called 'bindings', are the go-between
1791
	 * between Deno JavaScript and Deno Rust.
1792
	 *
1793
	 *      > console.table(Deno.metrics())
1794
	 *      ┌─────────────────────────┬────────┐
1795
	 *      │         (index)         │ Values │
1796
	 *      ├─────────────────────────┼────────┤
1797
	 *      │      opsDispatched      │   3    │
1798
	 *      │    opsDispatchedSync    │   2    │
1799
	 *      │   opsDispatchedAsync    │   1    │
1800
	 *      │ opsDispatchedAsyncUnref │   0    │
1801
	 *      │      opsCompleted       │   3    │
1802
	 *      │    opsCompletedSync     │   2    │
1803
	 *      │    opsCompletedAsync    │   1    │
1804
	 *      │ opsCompletedAsyncUnref  │   0    │
1805
	 *      │    bytesSentControl     │   73   │
1806
	 *      │      bytesSentData      │   0    │
1807
	 *      │      bytesReceived      │  375   │
1808
	 *      └─────────────────────────┴────────┘
1809
	 */
1810
	export function metrics(): Metrics;
1811
1812
	interface ResourceMap {
1813
		// deno-lint-ignore no-explicit-any
1814
		[rid: number]: any;
1815
	}
1816
1817
	/** Returns a map of open resource ids (rid) along with their string
1818
	 * representations. This is an internal API and as such resource
1819
	 * representation has `any` type; that means it can change any time.
1820
	 *
1821
	 * ```ts
1822
	 * console.log(Deno.resources());
1823
	 * // { 0: "stdin", 1: "stdout", 2: "stderr" }
1824
	 * Deno.openSync('../test.file');
1825
	 * console.log(Deno.resources());
1826
	 * // { 0: "stdin", 1: "stdout", 2: "stderr", 3: "fsFile" }
1827
	 * ```
1828
	 */
1829
	export function resources(): ResourceMap;
1830
1831
	export interface FsEvent {
1832
		kind: 'any' | 'access' | 'create' | 'modify' | 'remove';
1833
		paths: string[];
1834
	}
1835
1836
	/** Watch for file system events against one or more `paths`, which can be files
1837
	 * or directories.  These paths must exist already.  One user action (e.g.
1838
	 * `touch test.file`) can  generate multiple file system events.  Likewise,
1839
	 * one user action can result in multiple file paths in one event (e.g. `mv
1840
	 * old_name.txt new_name.txt`).  Recursive option is `true` by default and,
1841
	 * for directories, will watch the specified directory and all sub directories.
1842
	 * Note that the exact ordering of the events can vary between operating systems.
1843
	 *
1844
	 * ```ts
1845
	 * const watcher = Deno.watchFs("/");
1846
	 * for await (const event of watcher) {
1847
	 *    console.log(">>>> event", event);
1848
	 *    // { kind: "create", paths: [ "/foo.txt" ] }
1849
	 * }
1850
	 *```
1851
	 *
1852
	 * Requires `allow-read` permission.
1853
	 */
1854
	export function watchFs(
1855
		paths: string | string[],
1856
		options?: { recursive: boolean }
1857
	): AsyncIterableIterator<FsEvent>;
1858
1859
	export class Process<T extends RunOptions = RunOptions> {
1860
		readonly rid: number;
1861
		readonly pid: number;
1862
		readonly stdin: T['stdin'] extends 'piped' ? Writer & Closer : (Writer & Closer) | null;
1863
		readonly stdout: T['stdout'] extends 'piped' ? Reader & Closer : (Reader & Closer) | null;
1864
		readonly stderr: T['stderr'] extends 'piped' ? Reader & Closer : (Reader & Closer) | null;
1865
		/** Resolves to the current status of the process. */
1866
		status(): Promise<ProcessStatus>;
1867
		/** Buffer the stdout until EOF and return it as `Uint8Array`.
1868
		 *
1869
		 * You must set stdout to `"piped"` when creating the process.
1870
		 *
1871
		 * This calls `close()` on stdout after its done. */
1872
		output(): Promise<Uint8Array>;
1873
		/** Buffer the stderr until EOF and return it as `Uint8Array`.
1874
		 *
1875
		 * You must set stderr to `"piped"` when creating the process.
1876
		 *
1877
		 * This calls `close()` on stderr after its done. */
1878
		stderrOutput(): Promise<Uint8Array>;
1879
		close(): void;
1880
1881
		/** **UNSTABLE**: The `signo` argument may change to require the Deno.Signal
1882
		 * enum.
1883
		 *
1884
		 * Send a signal to process. This functionality currently only works on
1885
		 * Linux and Mac OS.
1886
		 */
1887
		kill(signo: number): void;
1888
	}
1889
1890
	export type ProcessStatus =
1891
		| {
1892
				success: true;
1893
				code: 0;
1894
				signal?: undefined;
1895
		  }
1896
		| {
1897
				success: false;
1898
				code: number;
1899
				signal?: number;
1900
		  };
1901
1902
	export interface RunOptions {
1903
		/** Arguments to pass. Note, the first element needs to be a path to the
1904
		 * binary */
1905
		cmd: string[] | [URL, ...string[]];
1906
		cwd?: string;
1907
		env?: {
1908
			[key: string]: string;
1909
		};
1910
		stdout?: 'inherit' | 'piped' | 'null' | number;
1911
		stderr?: 'inherit' | 'piped' | 'null' | number;
1912
		stdin?: 'inherit' | 'piped' | 'null' | number;
1913
	}
1914
1915
	/** Spawns new subprocess.  RunOptions must contain at a minimum the `opt.cmd`,
1916
	 * an array of program arguments, the first of which is the binary.
1917
	 *
1918
	 * ```ts
1919
	 * const p = Deno.run({
1920
	 *   cmd: ["echo", "hello"],
1921
	 * });
1922
	 * ```
1923
	 *
1924
	 * Subprocess uses same working directory as parent process unless `opt.cwd`
1925
	 * is specified.
1926
	 *
1927
	 * Environmental variables for subprocess can be specified using `opt.env`
1928
	 * mapping.
1929
	 *
1930
	 * By default subprocess inherits stdio of parent process. To change that
1931
	 * `opt.stdout`, `opt.stderr` and `opt.stdin` can be specified independently -
1932
	 * they can be set to either an rid of open file or set to "inherit" "piped"
1933
	 * or "null":
1934
	 *
1935
	 * `"inherit"` The default if unspecified. The child inherits from the
1936
	 * corresponding parent descriptor.
1937
	 *
1938
	 * `"piped"` A new pipe should be arranged to connect the parent and child
1939
	 * sub-processes.
1940
	 *
1941
	 * `"null"` This stream will be ignored. This is the equivalent of attaching
1942
	 * the stream to `/dev/null`.
1943
	 *
1944
	 * Details of the spawned process are returned.
1945
	 *
1946
	 * Requires `allow-run` permission. */
1947
	export function run<T extends RunOptions = RunOptions>(opt: T): Process<T>;
1948
1949
	export interface InspectOptions {
1950
		/** Stylize output with ANSI colors. Defaults to false. */
1951
		colors?: boolean;
1952
		/** Try to fit more than one entry of a collection on the same line.
1953
		 * Defaults to true. */
1954
		compact?: boolean;
1955
		/** Traversal depth for nested objects. Defaults to 4. */
1956
		depth?: number;
1957
		/** The maximum number of iterable entries to print. Defaults to 100. */
1958
		iterableLimit?: number;
1959
		/** Show a Proxy's target and handler. Defaults to false. */
1960
		showProxy?: boolean;
1961
		/** Sort Object, Set and Map entries by key. Defaults to false. */
1962
		sorted?: boolean;
1963
		/** Add a trailing comma for multiline collections. Defaults to false. */
1964
		trailingComma?: boolean;
1965
		/*** Evaluate the result of calling getters. Defaults to false. */
1966
		getters?: boolean;
1967
	}
1968
1969
	/** Converts the input into a string that has the same format as printed by
1970
	 * `console.log()`.
1971
	 *
1972
	 * ```ts
1973
	 * const obj = {};
1974
	 * obj.propA = 10;
1975
	 * obj.propB = "hello";
1976
	 * const objAsString = Deno.inspect(obj); // { propA: 10, propB: "hello" }
1977
	 * console.log(obj);  // prints same value as objAsString, e.g. { propA: 10, propB: "hello" }
1978
	 * ```
1979
	 *
1980
	 * You can also register custom inspect functions, via the `customInspect` Deno
1981
	 * symbol on objects, to control and customize the output.
1982
	 *
1983
	 * ```ts
1984
	 * class A {
1985
	 *   x = 10;
1986
	 *   y = "hello";
1987
	 *   [Deno.customInspect](): string {
1988
	 *     return "x=" + this.x + ", y=" + this.y;
1989
	 *   }
1990
	 * }
1991
	 * ```
1992
	 *
1993
	 *      const inStringFormat = Deno.inspect(new A()); // "x=10, y=hello"
1994
	 *      console.log(inStringFormat);  // prints "x=10, y=hello"
1995
	 *
1996
	 * Finally, you can also specify the depth to which it will format.
1997
	 *
1998
	 *      Deno.inspect({a: {b: {c: {d: 'hello'}}}}, {depth: 2}); // { a: { b: [Object] } }
1999
	 *
2000
	 */
2001
	export function inspect(value: unknown, options?: InspectOptions): string;
2002
2003
	/** Build related information. */
2004
	export const build: {
2005
		/** The LLVM target triple */
2006
		target: string;
2007
		/** Instruction set architecture */
2008
		arch: 'x86_64';
2009
		/** Operating system */
2010
		os: 'darwin' | 'linux' | 'windows';
2011
		/** Computer vendor */
2012
		vendor: string;
2013
		/** Optional environment */
2014
		env?: string;
2015
	};
2016
2017
	/** Version related information. */
2018
	export const version: {
2019
		/** Deno's version. For example: `"1.0.0"` */
2020
		deno: string;
2021
		/** The V8 version used by Deno. For example: `"8.0.0.0"` */
2022
		v8: string;
2023
		/** The TypeScript version used by Deno. For example: `"4.0.0"` */
2024
		typescript: string;
2025
	};
2026
2027
	/** Returns the script arguments to the program. If for example we run a
2028
	 * program:
2029
	 *
2030
	 * deno run --allow-read https://deno.land/std/examples/cat.ts /etc/passwd
2031
	 *
2032
	 * Then `Deno.args` will contain:
2033
	 *
2034
	 * [ "/etc/passwd" ]
2035
	 */
2036
	export const args: string[];
2037
2038
	/** A symbol which can be used as a key for a custom method which will be
2039
	 * called when `Deno.inspect()` is called, or when the object is logged to
2040
	 * the console. */
2041
	export const customInspect: unique symbol;
2042
2043
	/** The URL of the entrypoint module entered from the command-line. */
2044
	export const mainModule: string;
2045
}
2046
2047
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
2048
2049
// deno-lint-ignore-file no-explicit-any
2050
2051
/// <reference no-default-lib="true" />
2052
/// <reference lib="esnext" />
2053
2054
declare class DOMException extends Error {
2055
	constructor(message?: string, name?: string);
2056
	readonly name: string;
2057
	readonly message: string;
2058
}
2059
2060
interface EventInit {
2061
	bubbles?: boolean;
2062
	cancelable?: boolean;
2063
	composed?: boolean;
2064
}
2065
2066
/** An event which takes place in the DOM. */
2067
declare class Event {
2068
	constructor(type: string, eventInitDict?: EventInit);
2069
	/** Returns true or false depending on how event was initialized. True if
2070
	 * event goes through its target's ancestors in reverse tree order, and
2071
	 * false otherwise. */
2072
	readonly bubbles: boolean;
2073
	cancelBubble: boolean;
2074
	/** Returns true or false depending on how event was initialized. Its return
2075
	 * value does not always carry meaning, but true can indicate that part of the
2076
	 * operation during which event was dispatched, can be canceled by invoking
2077
	 * the preventDefault() method. */
2078
	readonly cancelable: boolean;
2079
	/** Returns true or false depending on how event was initialized. True if
2080
	 * event invokes listeners past a ShadowRoot node that is the root of its
2081
	 * target, and false otherwise. */
2082
	readonly composed: boolean;
2083
	/** Returns the object whose event listener's callback is currently being
2084
	 * invoked. */
2085
	readonly currentTarget: EventTarget | null;
2086
	/** Returns true if preventDefault() was invoked successfully to indicate
2087
	 * cancellation, and false otherwise. */
2088
	readonly defaultPrevented: boolean;
2089
	/** Returns the event's phase, which is one of NONE, CAPTURING_PHASE,
2090
	 * AT_TARGET, and BUBBLING_PHASE. */
2091
	readonly eventPhase: number;
2092
	/** Returns true if event was dispatched by the user agent, and false
2093
	 * otherwise. */
2094
	readonly isTrusted: boolean;
2095
	/** Returns the object to which event is dispatched (its target). */
2096
	readonly target: EventTarget | null;
2097
	/** Returns the event's timestamp as the number of milliseconds measured
2098
	 * relative to the time origin. */
2099
	readonly timeStamp: number;
2100
	/** Returns the type of event, e.g. "click", "hashchange", or "submit". */
2101
	readonly type: string;
2102
	/** Returns the invocation target objects of event's path (objects on which
2103
	 * listeners will be invoked), except for any nodes in shadow trees of which
2104
	 * the shadow root's mode is "closed" that are not reachable from event's
2105
	 * currentTarget. */
2106
	composedPath(): EventTarget[];
2107
	/** If invoked when the cancelable attribute value is true, and while
2108
	 * executing a listener for the event with passive set to false, signals to
2109
	 * the operation that caused event to be dispatched that it needs to be
2110
	 * canceled. */
2111
	preventDefault(): void;
2112
	/** Invoking this method prevents event from reaching any registered event
2113
	 * listeners after the current one finishes running and, when dispatched in a
2114
	 * tree, also prevents event from reaching any other objects. */
2115
	stopImmediatePropagation(): void;
2116
	/** When dispatched in a tree, invoking this method prevents event from
2117
	 * reaching any objects other than the current object. */
2118
	stopPropagation(): void;
2119
	readonly AT_TARGET: number;
2120
	readonly BUBBLING_PHASE: number;
2121
	readonly CAPTURING_PHASE: number;
2122
	readonly NONE: number;
2123
	static readonly AT_TARGET: number;
2124
	static readonly BUBBLING_PHASE: number;
2125
	static readonly CAPTURING_PHASE: number;
2126
	static readonly NONE: number;
2127
}
2128
2129
/**
2130
 * EventTarget is a DOM interface implemented by objects that can receive events
2131
 * and may have listeners for them.
2132
 */
2133
declare class EventTarget {
2134
	/** Appends an event listener for events whose type attribute value is type.
2135
	 * The callback argument sets the callback that will be invoked when the event
2136
	 * is dispatched.
2137
	 *
2138
	 * The options argument sets listener-specific options. For compatibility this
2139
	 * can be a boolean, in which case the method behaves exactly as if the value
2140
	 * was specified as options's capture.
2141
	 *
2142
	 * When set to true, options's capture prevents callback from being invoked
2143
	 * when the event's eventPhase attribute value is BUBBLING_PHASE. When false
2144
	 * (or not present), callback will not be invoked when event's eventPhase
2145
	 * attribute value is CAPTURING_PHASE. Either way, callback will be invoked if
2146
	 * event's eventPhase attribute value is AT_TARGET.
2147
	 *
2148
	 * When set to true, options's passive indicates that the callback will not
2149
	 * cancel the event by invoking preventDefault(). This is used to enable
2150
	 * performance optimizations described in § 2.8 Observing event listeners.
2151
	 *
2152
	 * When set to true, options's once indicates that the callback will only be
2153
	 * invoked once after which the event listener will be removed.
2154
	 *
2155
	 * The event listener is appended to target's event listener list and is not
2156
	 * appended if it has the same type, callback, and capture. */
2157
	addEventListener(
2158
		type: string,
2159
		listener: EventListenerOrEventListenerObject | null,
2160
		options?: boolean | AddEventListenerOptions
2161
	): void;
2162
	/** Dispatches a synthetic event event to target and returns true if either
2163
	 * event's cancelable attribute value is false or its preventDefault() method
2164
	 * was not invoked, and false otherwise. */
2165
	dispatchEvent(event: Event): boolean;
2166
	/** Removes the event listener in target's event listener list with the same
2167
	 * type, callback, and options. */
2168
	removeEventListener(
2169
		type: string,
2170
		callback: EventListenerOrEventListenerObject | null,
2171
		options?: EventListenerOptions | boolean
2172
	): void;
2173
	[Symbol.toStringTag]: string;
2174
}
2175
2176
interface EventListener {
2177
	(evt: Event): void | Promise<void>;
2178
}
2179
2180
interface EventListenerObject {
2181
	handleEvent(evt: Event): void | Promise<void>;
2182
}
2183
2184
declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
2185
2186
interface AddEventListenerOptions extends EventListenerOptions {
2187
	once?: boolean;
2188
	passive?: boolean;
2189
}
2190
2191
interface EventListenerOptions {
2192
	capture?: boolean;
2193
}
2194
2195
/** Decodes a string of data which has been encoded using base-64 encoding.
2196
 *
2197
 *     console.log(atob("aGVsbG8gd29ybGQ=")); // outputs 'hello world'
2198
 */
2199
declare function atob(s: string): string;
2200
2201
/** Creates a base-64 ASCII encoded string from the input string.
2202
 *
2203
 *     console.log(btoa("hello world"));  // outputs "aGVsbG8gd29ybGQ="
2204
 */
2205
declare function btoa(s: string): string;
2206
2207
declare class TextDecoder {
2208
	/** Returns encoding's name, lowercased. */
2209
	readonly encoding: string;
2210
	/** Returns `true` if error mode is "fatal", and `false` otherwise. */
2211
	readonly fatal: boolean;
2212
	/** Returns `true` if ignore BOM flag is set, and `false` otherwise. */
2213
	readonly ignoreBOM = false;
2214
	constructor(label?: string, options?: { fatal?: boolean; ignoreBOM?: boolean });
2215
	/** Returns the result of running encoding's decoder. */
2216
	decode(input?: BufferSource, options?: { stream?: false }): string;
2217
	readonly [Symbol.toStringTag]: string;
2218
}
2219
2220
declare class TextEncoder {
2221
	/** Returns "utf-8". */
2222
	readonly encoding = 'utf-8';
2223
	/** Returns the result of running UTF-8's encoder. */
2224
	encode(input?: string): Uint8Array;
2225
	encodeInto(input: string, dest: Uint8Array): { read: number; written: number };
2226
	readonly [Symbol.toStringTag]: string;
2227
}
2228
2229
/** A controller object that allows you to abort one or more DOM requests as and
2230
 * when desired. */
2231
declare class AbortController {
2232
	/** Returns the AbortSignal object associated with this object. */
2233
	readonly signal: AbortSignal;
2234
	/** Invoking this method will set this object's AbortSignal's aborted flag and
2235
	 * signal to any observers that the associated activity is to be aborted. */
2236
	abort(): void;
2237
}
2238
2239
interface AbortSignalEventMap {
2240
	abort: Event;
2241
}
2242
2243
/** A signal object that allows you to communicate with a DOM request (such as a
2244
 * Fetch) and abort it if required via an AbortController object. */
2245
interface AbortSignal extends EventTarget {
2246
	/** Returns true if this AbortSignal's AbortController has signaled to abort,
2247
	 * and false otherwise. */
2248
	readonly aborted: boolean;
2249
	onabort: ((this: AbortSignal, ev: Event) => any) | null;
2250
	addEventListener<K extends keyof AbortSignalEventMap>(
2251
		type: K,
2252
		listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any,
2253
		options?: boolean | AddEventListenerOptions
2254
	): void;
2255
	addEventListener(
2256
		type: string,
2257
		listener: EventListenerOrEventListenerObject,
2258
		options?: boolean | AddEventListenerOptions
2259
	): void;
2260
	removeEventListener<K extends keyof AbortSignalEventMap>(
2261
		type: K,
2262
		listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any,
2263
		options?: boolean | EventListenerOptions
2264
	): void;
2265
	removeEventListener(
2266
		type: string,
2267
		listener: EventListenerOrEventListenerObject,
2268
		options?: boolean | EventListenerOptions
2269
	): void;
2270
}
2271
2272
declare var AbortSignal: {
2273
	prototype: AbortSignal;
2274
	new (): AbortSignal;
2275
};
2276
2277
interface FileReaderEventMap {
2278
	abort: ProgressEvent<FileReader>;
2279
	error: ProgressEvent<FileReader>;
2280
	load: ProgressEvent<FileReader>;
2281
	loadend: ProgressEvent<FileReader>;
2282
	loadstart: ProgressEvent<FileReader>;
2283
	progress: ProgressEvent<FileReader>;
2284
}
2285
2286
/** Lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user's computer, using File or Blob objects to specify the file or data to read. */
2287
interface FileReader extends EventTarget {
2288
	readonly error: DOMException | null;
2289
	onabort: ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null;
2290
	onerror: ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null;
2291
	onload: ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null;
2292
	onloadend: ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null;
2293
	onloadstart: ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null;
2294
	onprogress: ((this: FileReader, ev: ProgressEvent<FileReader>) => any) | null;
2295
	readonly readyState: number;
2296
	readonly result: string | ArrayBuffer | null;
2297
	abort(): void;
2298
	readAsArrayBuffer(blob: Blob): void;
2299
	readAsBinaryString(blob: Blob): void;
2300
	readAsDataURL(blob: Blob): void;
2301
	readAsText(blob: Blob, encoding?: string): void;
2302
	readonly DONE: number;
2303
	readonly EMPTY: number;
2304
	readonly LOADING: number;
2305
	addEventListener<K extends keyof FileReaderEventMap>(
2306
		type: K,
2307
		listener: (this: FileReader, ev: FileReaderEventMap[K]) => any,
2308
		options?: boolean | AddEventListenerOptions
2309
	): void;
2310
	addEventListener(
2311
		type: string,
2312
		listener: EventListenerOrEventListenerObject,
2313
		options?: boolean | AddEventListenerOptions
2314
	): void;
2315
	removeEventListener<K extends keyof FileReaderEventMap>(
2316
		type: K,
2317
		listener: (this: FileReader, ev: FileReaderEventMap[K]) => any,
2318
		options?: boolean | EventListenerOptions
2319
	): void;
2320
	removeEventListener(
2321
		type: string,
2322
		listener: EventListenerOrEventListenerObject,
2323
		options?: boolean | EventListenerOptions
2324
	): void;
2325
}
2326
2327
declare var FileReader: {
2328
	prototype: FileReader;
2329
	new (): FileReader;
2330
	readonly DONE: number;
2331
	readonly EMPTY: number;
2332
	readonly LOADING: number;
2333
};
2334
2335
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
2336
2337
// deno-lint-ignore-file no-explicit-any
2338
2339
/// <reference no-default-lib="true" />
2340
/// <reference lib="esnext" />
2341
2342
interface DomIterable<K, V> {
2343
	keys(): IterableIterator<K>;
2344
	values(): IterableIterator<V>;
2345
	entries(): IterableIterator<[K, V]>;
2346
	[Symbol.iterator](): IterableIterator<[K, V]>;
2347
	forEach(callback: (value: V, key: K, parent: this) => void, thisArg?: any): void;
2348
}
2349
2350
interface ReadableStreamReadDoneResult<T> {
2351
	done: true;
2352
	value?: T;
2353
}
2354
2355
interface ReadableStreamReadValueResult<T> {
2356
	done: false;
2357
	value: T;
2358
}
2359
2360
type ReadableStreamReadResult<T> =
2361
	| ReadableStreamReadValueResult<T>
2362
	| ReadableStreamReadDoneResult<T>;
2363
2364
interface ReadableStreamDefaultReader<R = any> {
2365
	readonly closed: Promise<void>;
2366
	cancel(reason?: any): Promise<void>;
2367
	read(): Promise<ReadableStreamReadResult<R>>;
2368
	releaseLock(): void;
2369
}
2370
2371
interface ReadableStreamReader<R = any> {
2372
	cancel(): Promise<void>;
2373
	read(): Promise<ReadableStreamReadResult<R>>;
2374
	releaseLock(): void;
2375
}
2376
2377
interface ReadableByteStreamControllerCallback {
2378
	(controller: ReadableByteStreamController): void | PromiseLike<void>;
2379
}
2380
2381
interface UnderlyingByteSource {
2382
	autoAllocateChunkSize?: number;
2383
	cancel?: ReadableStreamErrorCallback;
2384
	pull?: ReadableByteStreamControllerCallback;
2385
	start?: ReadableByteStreamControllerCallback;
2386
	type: 'bytes';
2387
}
2388
2389
interface UnderlyingSource<R = any> {
2390
	cancel?: ReadableStreamErrorCallback;
2391
	pull?: ReadableStreamDefaultControllerCallback<R>;
2392
	start?: ReadableStreamDefaultControllerCallback<R>;
2393
	type?: undefined;
2394
}
2395
2396
interface ReadableStreamErrorCallback {
2397
	(reason: any): void | PromiseLike<void>;
2398
}
2399
2400
interface ReadableStreamDefaultControllerCallback<R> {
2401
	(controller: ReadableStreamDefaultController<R>): void | PromiseLike<void>;
2402
}
2403
2404
interface ReadableStreamDefaultController<R = any> {
2405
	readonly desiredSize: number | null;
2406
	close(): void;
2407
	enqueue(chunk: R): void;
2408
	error(error?: any): void;
2409
}
2410
2411
interface ReadableByteStreamController {
2412
	readonly byobRequest: undefined;
2413
	readonly desiredSize: number | null;
2414
	close(): void;
2415
	enqueue(chunk: ArrayBufferView): void;
2416
	error(error?: any): void;
2417
}
2418
2419
interface PipeOptions {
2420
	preventAbort?: boolean;
2421
	preventCancel?: boolean;
2422
	preventClose?: boolean;
2423
	signal?: AbortSignal;
2424
}
2425
2426
interface QueuingStrategySizeCallback<T = any> {
2427
	(chunk: T): number;
2428
}
2429
2430
interface QueuingStrategy<T = any> {
2431
	highWaterMark?: number;
2432
	size?: QueuingStrategySizeCallback<T>;
2433
}
2434
2435
/** This Streams API interface provides a built-in byte length queuing strategy
2436
 * that can be used when constructing streams. */
2437
declare class CountQueuingStrategy implements QueuingStrategy {
2438
	constructor(options: { highWaterMark: number });
2439
	highWaterMark: number;
2440
	size(chunk: any): 1;
2441
}
2442
2443
declare class ByteLengthQueuingStrategy implements QueuingStrategy<ArrayBufferView> {
2444
	constructor(options: { highWaterMark: number });
2445
	highWaterMark: number;
2446
	size(chunk: ArrayBufferView): number;
2447
}
2448
2449
/** This Streams API interface represents a readable stream of byte data. The
2450
 * Fetch API offers a concrete instance of a ReadableStream through the body
2451
 * property of a Response object. */
2452
interface ReadableStream<R = any> {
2453
	readonly locked: boolean;
2454
	cancel(reason?: any): Promise<void>;
2455
	getIterator(options?: { preventCancel?: boolean }): AsyncIterableIterator<R>;
2456
	// getReader(options: { mode: "byob" }): ReadableStreamBYOBReader;
2457
	getReader(): ReadableStreamDefaultReader<R>;
2458
	pipeThrough<T>(
2459
		{
2460
			writable,
2461
			readable,
2462
		}: {
2463
			writable: WritableStream<R>;
2464
			readable: ReadableStream<T>;
2465
		},
2466
		options?: PipeOptions
2467
	): ReadableStream<T>;
2468
	pipeTo(dest: WritableStream<R>, options?: PipeOptions): Promise<void>;
2469
	tee(): [ReadableStream<R>, ReadableStream<R>];
2470
	[Symbol.asyncIterator](options?: { preventCancel?: boolean }): AsyncIterableIterator<R>;
2471
}
2472
2473
declare var ReadableStream: {
2474
	prototype: ReadableStream;
2475
	new (
2476
		underlyingSource: UnderlyingByteSource,
2477
		strategy?: { highWaterMark?: number; size?: undefined }
2478
	): ReadableStream<Uint8Array>;
2479
	new <R = any>(
2480
		underlyingSource?: UnderlyingSource<R>,
2481
		strategy?: QueuingStrategy<R>
2482
	): ReadableStream<R>;
2483
};
2484
2485
interface WritableStreamDefaultControllerCloseCallback {
2486
	(): void | PromiseLike<void>;
2487
}
2488
2489
interface WritableStreamDefaultControllerStartCallback {
2490
	(controller: WritableStreamDefaultController): void | PromiseLike<void>;
2491
}
2492
2493
interface WritableStreamDefaultControllerWriteCallback<W> {
2494
	(chunk: W, controller: WritableStreamDefaultController): void | PromiseLike<void>;
2495
}
2496
2497
interface WritableStreamErrorCallback {
2498
	(reason: any): void | PromiseLike<void>;
2499
}
2500
2501
interface UnderlyingSink<W = any> {
2502
	abort?: WritableStreamErrorCallback;
2503
	close?: WritableStreamDefaultControllerCloseCallback;
2504
	start?: WritableStreamDefaultControllerStartCallback;
2505
	type?: undefined;
2506
	write?: WritableStreamDefaultControllerWriteCallback<W>;
2507
}
2508
2509
/** This Streams API interface provides a standard abstraction for writing
2510
 * streaming data to a destination, known as a sink. This object comes with
2511
 * built-in backpressure and queuing. */
2512
declare class WritableStream<W = any> {
2513
	constructor(underlyingSink?: UnderlyingSink<W>, strategy?: QueuingStrategy<W>);
2514
	readonly locked: boolean;
2515
	abort(reason?: any): Promise<void>;
2516
	close(): Promise<void>;
2517
	getWriter(): WritableStreamDefaultWriter<W>;
2518
}
2519
2520
/** This Streams API interface represents a controller allowing control of a
2521
 * WritableStream's state. When constructing a WritableStream, the underlying
2522
 * sink is given a corresponding WritableStreamDefaultController instance to
2523
 * manipulate. */
2524
interface WritableStreamDefaultController {
2525
	error(error?: any): void;
2526
}
2527
2528
/** This Streams API interface is the object returned by
2529
 * WritableStream.getWriter() and once created locks the < writer to the
2530
 * WritableStream ensuring that no other streams can write to the underlying
2531
 * sink. */
2532
interface WritableStreamDefaultWriter<W = any> {
2533
	readonly closed: Promise<void>;
2534
	readonly desiredSize: number | null;
2535
	readonly ready: Promise<void>;
2536
	abort(reason?: any): Promise<void>;
2537
	close(): Promise<void>;
2538
	releaseLock(): void;
2539
	write(chunk: W): Promise<void>;
2540
}
2541
2542
declare class TransformStream<I = any, O = any> {
2543
	constructor(
2544
		transformer?: Transformer<I, O>,
2545
		writableStrategy?: QueuingStrategy<I>,
2546
		readableStrategy?: QueuingStrategy<O>
2547
	);
2548
	readonly readable: ReadableStream<O>;
2549
	readonly writable: WritableStream<I>;
2550
}
2551
2552
interface TransformStreamDefaultController<O = any> {
2553
	readonly desiredSize: number | null;
2554
	enqueue(chunk: O): void;
2555
	error(reason?: any): void;
2556
	terminate(): void;
2557
}
2558
2559
interface Transformer<I = any, O = any> {
2560
	flush?: TransformStreamDefaultControllerCallback<O>;
2561
	readableType?: undefined;
2562
	start?: TransformStreamDefaultControllerCallback<O>;
2563
	transform?: TransformStreamDefaultControllerTransformCallback<I, O>;
2564
	writableType?: undefined;
2565
}
2566
2567
interface TransformStreamDefaultControllerCallback<O> {
2568
	(controller: TransformStreamDefaultController<O>): void | PromiseLike<void>;
2569
}
2570
2571
interface TransformStreamDefaultControllerTransformCallback<I, O> {
2572
	(chunk: I, controller: TransformStreamDefaultController<O>): void | PromiseLike<void>;
2573
}
2574
2575
type BlobPart = BufferSource | Blob | string;
2576
2577
interface BlobPropertyBag {
2578
	type?: string;
2579
	ending?: 'transparent' | 'native';
2580
}
2581
2582
/** A file-like object of immutable, raw data. Blobs represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system. */
2583
declare class Blob {
2584
	constructor(blobParts?: BlobPart[], options?: BlobPropertyBag);
2585
2586
	readonly size: number;
2587
	readonly type: string;
2588
	arrayBuffer(): Promise<ArrayBuffer>;
2589
	slice(start?: number, end?: number, contentType?: string): Blob;
2590
	stream(): ReadableStream;
2591
	text(): Promise<string>;
2592
}
2593
2594
interface FilePropertyBag extends BlobPropertyBag {
2595
	lastModified?: number;
2596
}
2597
2598
/** Provides information about files and allows JavaScript in a web page to
2599
 * access their content. */
2600
declare class File extends Blob {
2601
	constructor(fileBits: BlobPart[], fileName: string, options?: FilePropertyBag);
2602
2603
	readonly lastModified: number;
2604
	readonly name: string;
2605
}
2606
2607
type FormDataEntryValue = File | string;
2608
2609
/** Provides a way to easily construct a set of key/value pairs representing
2610
 * form fields and their values, which can then be easily sent using the
2611
 * XMLHttpRequest.send() method. It uses the same format a form would use if the
2612
 * encoding type were set to "multipart/form-data". */
2613
declare class FormData implements DomIterable<string, FormDataEntryValue> {
2614
	// TODO(ry) FormData constructor is non-standard.
2615
	// new(form?: HTMLFormElement): FormData;
2616
	constructor();
2617
2618
	append(name: string, value: string | Blob, fileName?: string): void;
2619
	delete(name: string): void;
2620
	get(name: string): FormDataEntryValue | null;
2621
	getAll(name: string): FormDataEntryValue[];
2622
	has(name: string): boolean;
2623
	set(name: string, value: string | Blob, fileName?: string): void;
2624
	keys(): IterableIterator<string>;
2625
	values(): IterableIterator<string>;
2626
	entries(): IterableIterator<[string, FormDataEntryValue]>;
2627
	[Symbol.iterator](): IterableIterator<[string, FormDataEntryValue]>;
2628
	forEach(
2629
		callback: (value: FormDataEntryValue, key: string, parent: this) => void,
2630
		thisArg?: any
2631
	): void;
2632
}
2633
2634
interface Body {
2635
	/** A simple getter used to expose a `ReadableStream` of the body contents. */
2636
	readonly body: ReadableStream<Uint8Array> | null;
2637
	/** Stores a `Boolean` that declares whether the body has been used in a
2638
	 * response yet.
2639
	 */
2640
	readonly bodyUsed: boolean;
2641
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2642
	 * that resolves with an `ArrayBuffer`.
2643
	 */
2644
	arrayBuffer(): Promise<ArrayBuffer>;
2645
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2646
	 * that resolves with a `Blob`.
2647
	 */
2648
	blob(): Promise<Blob>;
2649
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2650
	 * that resolves with a `FormData` object.
2651
	 */
2652
	formData(): Promise<FormData>;
2653
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2654
	 * that resolves with the result of parsing the body text as JSON.
2655
	 */
2656
	json(): Promise<any>;
2657
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2658
	 * that resolves with a `USVString` (text).
2659
	 */
2660
	text(): Promise<string>;
2661
}
2662
2663
type HeadersInit = Headers | string[][] | Record<string, string>;
2664
2665
/** This Fetch API interface allows you to perform various actions on HTTP
2666
 * request and response headers. These actions include retrieving, setting,
2667
 * adding to, and removing. A Headers object has an associated header list,
2668
 * which is initially empty and consists of zero or more name and value pairs.
2669
 * You can add to this using methods like append() (see Examples). In all
2670
 * methods of this interface, header names are matched by case-insensitive byte
2671
 * sequence. */
2672
interface Headers {
2673
	append(name: string, value: string): void;
2674
	delete(name: string): void;
2675
	get(name: string): string | null;
2676
	has(name: string): boolean;
2677
	set(name: string, value: string): void;
2678
	forEach(callbackfn: (value: string, key: string, parent: Headers) => void, thisArg?: any): void;
2679
}
2680
2681
declare class Headers implements DomIterable<string, string> {
2682
	constructor(init?: HeadersInit);
2683
2684
	/** Appends a new value onto an existing header inside a `Headers` object, or
2685
	 * adds the header if it does not already exist.
2686
	 */
2687
	append(name: string, value: string): void;
2688
	/** Deletes a header from a `Headers` object. */
2689
	delete(name: string): void;
2690
	/** Returns an iterator allowing to go through all key/value pairs
2691
	 * contained in this Headers object. The both the key and value of each pairs
2692
	 * are ByteString objects.
2693
	 */
2694
	entries(): IterableIterator<[string, string]>;
2695
	/** Returns a `ByteString` sequence of all the values of a header within a
2696
	 * `Headers` object with a given name.
2697
	 */
2698
	get(name: string): string | null;
2699
	/** Returns a boolean stating whether a `Headers` object contains a certain
2700
	 * header.
2701
	 */
2702
	has(name: string): boolean;
2703
	/** Returns an iterator allowing to go through all keys contained in
2704
	 * this Headers object. The keys are ByteString objects.
2705
	 */
2706
	keys(): IterableIterator<string>;
2707
	/** Sets a new value for an existing header inside a Headers object, or adds
2708
	 * the header if it does not already exist.
2709
	 */
2710
	set(name: string, value: string): void;
2711
	/** Returns an iterator allowing to go through all values contained in
2712
	 * this Headers object. The values are ByteString objects.
2713
	 */
2714
	values(): IterableIterator<string>;
2715
	forEach(callbackfn: (value: string, key: string, parent: this) => void, thisArg?: any): void;
2716
	/** The Symbol.iterator well-known symbol specifies the default
2717
	 * iterator for this Headers object
2718
	 */
2719
	[Symbol.iterator](): IterableIterator<[string, string]>;
2720
}
2721
2722
type RequestInfo = Request | string;
2723
type RequestCache =
2724
	| 'default'
2725
	| 'force-cache'
2726
	| 'no-cache'
2727
	| 'no-store'
2728
	| 'only-if-cached'
2729
	| 'reload';
2730
type RequestCredentials = 'include' | 'omit' | 'same-origin';
2731
type RequestMode = 'cors' | 'navigate' | 'no-cors' | 'same-origin';
2732
type RequestRedirect = 'error' | 'follow' | 'manual';
2733
type ReferrerPolicy =
2734
	| ''
2735
	| 'no-referrer'
2736
	| 'no-referrer-when-downgrade'
2737
	| 'origin'
2738
	| 'origin-when-cross-origin'
2739
	| 'same-origin'
2740
	| 'strict-origin'
2741
	| 'strict-origin-when-cross-origin'
2742
	| 'unsafe-url';
2743
type BodyInit =
2744
	| Blob
2745
	| BufferSource
2746
	| FormData
2747
	| URLSearchParams
2748
	| ReadableStream<Uint8Array>
2749
	| string;
2750
type RequestDestination =
2751
	| ''
2752
	| 'audio'
2753
	| 'audioworklet'
2754
	| 'document'
2755
	| 'embed'
2756
	| 'font'
2757
	| 'image'
2758
	| 'manifest'
2759
	| 'object'
2760
	| 'paintworklet'
2761
	| 'report'
2762
	| 'script'
2763
	| 'sharedworker'
2764
	| 'style'
2765
	| 'track'
2766
	| 'video'
2767
	| 'worker'
2768
	| 'xslt';
2769
2770
interface RequestInit {
2771
	/**
2772
	 * A BodyInit object or null to set request's body.
2773
	 */
2774
	body?: BodyInit | null;
2775
	/**
2776
	 * A string indicating how the request will interact with the browser's cache
2777
	 * to set request's cache.
2778
	 */
2779
	cache?: RequestCache;
2780
	/**
2781
	 * A string indicating whether credentials will be sent with the request
2782
	 * always, never, or only when sent to a same-origin URL. Sets request's
2783
	 * credentials.
2784
	 */
2785
	credentials?: RequestCredentials;
2786
	/**
2787
	 * A Headers object, an object literal, or an array of two-item arrays to set
2788
	 * request's headers.
2789
	 */
2790
	headers?: HeadersInit;
2791
	/**
2792
	 * A cryptographic hash of the resource to be fetched by request. Sets
2793
	 * request's integrity.
2794
	 */
2795
	integrity?: string;
2796
	/**
2797
	 * A boolean to set request's keepalive.
2798
	 */
2799
	keepalive?: boolean;
2800
	/**
2801
	 * A string to set request's method.
2802
	 */
2803
	method?: string;
2804
	/**
2805
	 * A string to indicate whether the request will use CORS, or will be
2806
	 * restricted to same-origin URLs. Sets request's mode.
2807
	 */
2808
	mode?: RequestMode;
2809
	/**
2810
	 * A string indicating whether request follows redirects, results in an error
2811
	 * upon encountering a redirect, or returns the redirect (in an opaque
2812
	 * fashion). Sets request's redirect.
2813
	 */
2814
	redirect?: RequestRedirect;
2815
	/**
2816
	 * A string whose value is a same-origin URL, "about:client", or the empty
2817
	 * string, to set request's referrer.
2818
	 */
2819
	referrer?: string;
2820
	/**
2821
	 * A referrer policy to set request's referrerPolicy.
2822
	 */
2823
	referrerPolicy?: ReferrerPolicy;
2824
	/**
2825
	 * An AbortSignal to set request's signal.
2826
	 */
2827
	signal?: AbortSignal | null;
2828
	/**
2829
	 * Can only be null. Used to disassociate request from any Window.
2830
	 */
2831
	window?: any;
2832
}
2833
2834
/** This Fetch API interface represents a resource request. */
2835
declare class Request implements Body {
2836
	constructor(input: RequestInfo, init?: RequestInit);
2837
2838
	/**
2839
	 * Returns the cache mode associated with request, which is a string
2840
	 * indicating how the request will interact with the browser's cache when
2841
	 * fetching.
2842
	 */
2843
	readonly cache: RequestCache;
2844
	/**
2845
	 * Returns the credentials mode associated with request, which is a string
2846
	 * indicating whether credentials will be sent with the request always, never,
2847
	 * or only when sent to a same-origin URL.
2848
	 */
2849
	readonly credentials: RequestCredentials;
2850
	/**
2851
	 * Returns the kind of resource requested by request, e.g., "document" or "script".
2852
	 */
2853
	readonly destination: RequestDestination;
2854
	/**
2855
	 * Returns a Headers object consisting of the headers associated with request.
2856
	 * Note that headers added in the network layer by the user agent will not be
2857
	 * accounted for in this object, e.g., the "Host" header.
2858
	 */
2859
	readonly headers: Headers;
2860
	/**
2861
	 * Returns request's subresource integrity metadata, which is a cryptographic
2862
	 * hash of the resource being fetched. Its value consists of multiple hashes
2863
	 * separated by whitespace. [SRI]
2864
	 */
2865
	readonly integrity: string;
2866
	/**
2867
	 * Returns a boolean indicating whether or not request is for a history
2868
	 * navigation (a.k.a. back-forward navigation).
2869
	 */
2870
	readonly isHistoryNavigation: boolean;
2871
	/**
2872
	 * Returns a boolean indicating whether or not request is for a reload
2873
	 * navigation.
2874
	 */
2875
	readonly isReloadNavigation: boolean;
2876
	/**
2877
	 * Returns a boolean indicating whether or not request can outlive the global
2878
	 * in which it was created.
2879
	 */
2880
	readonly keepalive: boolean;
2881
	/**
2882
	 * Returns request's HTTP method, which is "GET" by default.
2883
	 */
2884
	readonly method: string;
2885
	/**
2886
	 * Returns the mode associated with request, which is a string indicating
2887
	 * whether the request will use CORS, or will be restricted to same-origin
2888
	 * URLs.
2889
	 */
2890
	readonly mode: RequestMode;
2891
	/**
2892
	 * Returns the redirect mode associated with request, which is a string
2893
	 * indicating how redirects for the request will be handled during fetching. A
2894
	 * request will follow redirects by default.
2895
	 */
2896
	readonly redirect: RequestRedirect;
2897
	/**
2898
	 * Returns the referrer of request. Its value can be a same-origin URL if
2899
	 * explicitly set in init, the empty string to indicate no referrer, and
2900
	 * "about:client" when defaulting to the global's default. This is used during
2901
	 * fetching to determine the value of the `Referer` header of the request
2902
	 * being made.
2903
	 */
2904
	readonly referrer: string;
2905
	/**
2906
	 * Returns the referrer policy associated with request. This is used during
2907
	 * fetching to compute the value of the request's referrer.
2908
	 */
2909
	readonly referrerPolicy: ReferrerPolicy;
2910
	/**
2911
	 * Returns the signal associated with request, which is an AbortSignal object
2912
	 * indicating whether or not request has been aborted, and its abort event
2913
	 * handler.
2914
	 */
2915
	readonly signal: AbortSignal;
2916
	/**
2917
	 * Returns the URL of request as a string.
2918
	 */
2919
	readonly url: string;
2920
	clone(): Request;
2921
2922
	/** A simple getter used to expose a `ReadableStream` of the body contents. */
2923
	readonly body: ReadableStream<Uint8Array> | null;
2924
	/** Stores a `Boolean` that declares whether the body has been used in a
2925
	 * response yet.
2926
	 */
2927
	readonly bodyUsed: boolean;
2928
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2929
	 * that resolves with an `ArrayBuffer`.
2930
	 */
2931
	arrayBuffer(): Promise<ArrayBuffer>;
2932
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2933
	 * that resolves with a `Blob`.
2934
	 */
2935
	blob(): Promise<Blob>;
2936
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2937
	 * that resolves with a `FormData` object.
2938
	 */
2939
	formData(): Promise<FormData>;
2940
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2941
	 * that resolves with the result of parsing the body text as JSON.
2942
	 */
2943
	json(): Promise<any>;
2944
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2945
	 * that resolves with a `USVString` (text).
2946
	 */
2947
	text(): Promise<string>;
2948
}
2949
2950
interface ResponseInit {
2951
	headers?: HeadersInit;
2952
	status?: number;
2953
	statusText?: string;
2954
}
2955
2956
type ResponseType = 'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect';
2957
2958
/** This Fetch API interface represents the response to a request. */
2959
declare class Response implements Body {
2960
	constructor(body?: BodyInit | null, init?: ResponseInit);
2961
	static error(): Response;
2962
	static redirect(url: string, status?: number): Response;
2963
2964
	readonly headers: Headers;
2965
	readonly ok: boolean;
2966
	readonly redirected: boolean;
2967
	readonly status: number;
2968
	readonly statusText: string;
2969
	readonly trailer: Promise<Headers>;
2970
	readonly type: ResponseType;
2971
	readonly url: string;
2972
	clone(): Response;
2973
2974
	/** A simple getter used to expose a `ReadableStream` of the body contents. */
2975
	readonly body: ReadableStream<Uint8Array> | null;
2976
	/** Stores a `Boolean` that declares whether the body has been used in a
2977
	 * response yet.
2978
	 */
2979
	readonly bodyUsed: boolean;
2980
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2981
	 * that resolves with an `ArrayBuffer`.
2982
	 */
2983
	arrayBuffer(): Promise<ArrayBuffer>;
2984
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2985
	 * that resolves with a `Blob`.
2986
	 */
2987
	blob(): Promise<Blob>;
2988
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2989
	 * that resolves with a `FormData` object.
2990
	 */
2991
	formData(): Promise<FormData>;
2992
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2993
	 * that resolves with the result of parsing the body text as JSON.
2994
	 */
2995
	json(): Promise<any>;
2996
	/** Takes a `Response` stream and reads it to completion. It returns a promise
2997
	 * that resolves with a `USVString` (text).
2998
	 */
2999
	text(): Promise<string>;
3000
}
3001
3002
/** Fetch a resource from the network. It returns a Promise that resolves to the
3003
 * Response to that request, whether it is successful or not.
3004
 *
3005
 *     const response = await fetch("http://my.json.host/data.json");
3006
 *     console.log(response.status);  // e.g. 200
3007
 *     console.log(response.statusText); // e.g. "OK"
3008
 *     const jsonData = await response.json();
3009
 */
3010
declare function fetch(input: Request | URL | string, init?: RequestInit): Promise<Response>;
3011
3012
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
3013
3014
// Documentation partially adapted from [MDN](https://developer.mozilla.org/),
3015
// by Mozilla Contributors, which is licensed under CC-BY-SA 2.5.
3016
3017
/// <reference no-default-lib="true" />
3018
/// <reference lib="esnext" />
3019
/// <reference lib="deno.web" />
3020
/// <reference lib="deno.fetch" />
3021
3022
declare namespace WebAssembly {
3023
	/**
3024
	 * The `WebAssembly.CompileError` object indicates an error during WebAssembly decoding or validation.
3025
	 *
3026
	 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
3027
	 */
3028
	export class CompileError extends Error {
3029
		/** Creates a new `WebAssembly.CompileError` object. */
3030
		constructor();
3031
	}
3032
3033
	/**
3034
	 * A `WebAssembly.Global` object represents a global variable instance, accessible from
3035
	 * both JavaScript and importable/exportable across one or more `WebAssembly.Module`
3036
	 * instances. This allows dynamic linking of multiple modules.
3037
	 *
3038
	 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
3039
	 */
3040
	export class Global {
3041
		/** Creates a new `Global` object. */
3042
		constructor(descriptor: GlobalDescriptor, v?: any);
3043
3044
		/**
3045
		 * The value contained inside the global variable — this can be used to directly set
3046
		 * and get the global's value.
3047
		 */
3048
		value: any;
3049
3050
		/** Old-style method that returns the value contained inside the global variable. */
3051
		valueOf(): any;
3052
	}
3053
3054
	/**
3055
	 * A `WebAssembly.Instance` object is a stateful, executable instance of a `WebAssembly.Module`.
3056
	 * Instance objects contain all the Exported WebAssembly functions that allow calling into
3057
	 * WebAssembly code from JavaScript.
3058
	 *
3059
	 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
3060
	 */
3061
	export class Instance {
3062
		/** Creates a new Instance object. */
3063
		constructor(module: Module, importObject?: Imports);
3064
3065
		/**
3066
		 * Returns an object containing as its members all the functions exported from the
3067
		 * WebAssembly module instance, to allow them to be accessed and used by JavaScript.
3068
		 * Read-only.
3069
		 */
3070
		readonly exports: Exports;
3071
	}
3072
3073
	/**
3074
	 * The `WebAssembly.LinkError` object indicates an error during module instantiation
3075
	 * (besides traps from the start function).
3076
	 *
3077
	 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
3078
	 */
3079
	export class LinkError extends Error {
3080
		/** Creates a new WebAssembly.LinkError object. */
3081
		constructor();
3082
	}
3083
3084
	/**
3085
	 * The `WebAssembly.Memory` object is a resizable `ArrayBuffer` or `SharedArrayBuffer` that
3086
	 * holds the raw bytes of memory accessed by a WebAssembly Instance.
3087
	 *
3088
	 * A memory created by JavaScript or in WebAssembly code will be accessible and mutable
3089
	 * from both JavaScript and WebAssembly.
3090
	 *
3091
	 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
3092
	 */
3093
	export class Memory {
3094
		/** Creates a new `Memory` object. */
3095
		constructor(descriptor: MemoryDescriptor);
3096
3097
		/** An accessor property that returns the buffer contained in the memory. */
3098
		readonly buffer: ArrayBuffer;
3099
3100
		/**
3101
		 * Increases the size of the memory instance by a specified number of WebAssembly
3102
		 * pages (each one is 64KB in size).
3103
		 */
3104
		grow(delta: number): number;
3105
	}
3106
3107
	/**
3108
	 * A `WebAssembly.Module` object contains stateless WebAssembly code that has already been compiled
3109
	 * by the browser — this can be efficiently shared with Workers, and instantiated multiple times.
3110
	 *
3111
	 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
3112
	 */
3113
	export class Module {
3114
		/** Creates a new `Module` object. */
3115
		constructor(bytes: BufferSource);
3116
3117
		/**
3118
		 * Given a `Module` and string, returns a copy of the contents of all custom sections in the
3119
		 * module with the given string name.
3120
		 * */
3121
		static customSections(moduleObject: Module, sectionName: string): ArrayBuffer[];
3122
3123
		/** Given a `Module`, returns an array containing descriptions of all the declared exports. */
3124
		static exports(moduleObject: Module): ModuleExportDescriptor[];
3125
3126
		/** Given a `Module`, returns an array containing descriptions of all the declared imports. */
3127
		static imports(moduleObject: Module): ModuleImportDescriptor[];
3128
	}
3129
3130
	/**
3131
	 * The `WebAssembly.RuntimeError` object is the error type that is thrown whenever WebAssembly
3132
	 * specifies a trap.
3133
	 *
3134
	 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
3135
	 */
3136
	export class RuntimeError extends Error {
3137
		/** Creates a new `WebAssembly.RuntimeError` object. */
3138
		constructor();
3139
	}
3140
3141
	/**
3142
	 * The `WebAssembly.Table()` object is a JavaScript wrapper object — an array-like structure
3143
	 * representing a WebAssembly Table, which stores function references. A table created by
3144
	 * JavaScript or in WebAssembly code will be accessible and mutable from both JavaScript
3145
	 * and WebAssembly.
3146
	 *
3147
	 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
3148
	 */
3149
	export class Table {
3150
		/** Creates a new `Table` object. */
3151
		constructor(descriptor: TableDescriptor);
3152
3153
		/** Returns the length of the table, i.e. the number of elements. */
3154
		readonly length: number;
3155
3156
		/** Accessor function — gets the element stored at a given index. */
3157
		get(index: number): Function | null;
3158
3159
		/** Increases the size of the `Table` instance by a specified number of elements. */
3160
		grow(delta: number): number;
3161
3162
		/** Sets an element stored at a given index to a given value. */
3163
		set(index: number, value: Function | null): void;
3164
	}
3165
3166
	/** The `GlobalDescriptor` describes the options you can pass to `new WebAssembly.Global()`. */
3167
	export interface GlobalDescriptor {
3168
		mutable?: boolean;
3169
		value: ValueType;
3170
	}
3171
3172
	/** The `MemoryDescriptor` describes the options you can pass to `new WebAssembly.Memory()`. */
3173
	export interface MemoryDescriptor {
3174
		initial: number;
3175
		maximum?: number;
3176
	}
3177
3178
	/** A `ModuleExportDescriptor` is the description of a declared export in a `WebAssembly.Module`. */
3179
	export interface ModuleExportDescriptor {
3180
		kind: ImportExportKind;
3181
		name: string;
3182
	}
3183
3184
	/** A `ModuleImportDescriptor` is the description of a declared import in a `WebAssembly.Module`. */
3185
	export interface ModuleImportDescriptor {
3186
		kind: ImportExportKind;
3187
		module: string;
3188
		name: string;
3189
	}
3190
3191
	/** The `TableDescriptor` describes the options you can pass to `new WebAssembly.Table()`. */
3192
	export interface TableDescriptor {
3193
		element: TableKind;
3194
		initial: number;
3195
		maximum?: number;
3196
	}
3197
3198
	/** The value returned from `WebAssembly.instantiate` and `WebAssembly.instantiateStreaming`. */
3199
	export interface WebAssemblyInstantiatedSource {
3200
		/* A `WebAssembly.Instance` object that contains all the exported WebAssembly functions. */
3201
		instance: Instance;
3202
3203
		/**
3204
		 * A `WebAssembly.Module` object representing the compiled WebAssembly module.
3205
		 * This `Module` can be instantiated again, or shared via postMessage().
3206
		 */
3207
		module: Module;
3208
	}
3209
3210
	export type ImportExportKind = 'function' | 'global' | 'memory' | 'table';
3211
	export type TableKind = 'anyfunc';
3212
	export type ValueType = 'f32' | 'f64' | 'i32' | 'i64';
3213
	export type ExportValue = Function | Global | Memory | Table;
3214
	export type Exports = Record<string, ExportValue>;
3215
	export type ImportValue = ExportValue | number;
3216
	export type ModuleImports = Record<string, ImportValue>;
3217
	export type Imports = Record<string, ModuleImports>;
3218
3219
	/**
3220
	 * The `WebAssembly.compile()` function compiles WebAssembly binary code into a
3221
	 * `WebAssembly.Module` object. This function is useful if it is necessary to compile
3222
	 * a module before it can be instantiated (otherwise, the `WebAssembly.instantiate()`
3223
	 * function should be used).
3224
	 *
3225
	 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
3226
	 */
3227
	export function compile(bytes: BufferSource): Promise<Module>;
3228
3229
	/**
3230
	 * The `WebAssembly.compileStreaming()` function compiles a `WebAssembly.Module`
3231
	 * directly from a streamed underlying source.  This function is useful if it
3232
	 * is necessary to a compile a module before it can be instantiated (otherwise,
3233
	 * the `WebAssembly.instantiateStreaming()` function should be used).
3234
	 *
3235
	 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
3236
	 */
3237
	export function compileStreaming(source: Response | Promise<Response>): Promise<Module>;
3238
3239
	/**
3240
	 * The WebAssembly.instantiate() function allows you to compile and instantiate
3241
	 * WebAssembly code.
3242
	 *
3243
	 * This overload takes the WebAssembly binary code, in the form of a typed
3244
	 * array or ArrayBuffer, and performs both compilation and instantiation in one step.
3245
	 * The returned Promise resolves to both a compiled WebAssembly.Module and its first
3246
	 * WebAssembly.Instance.
3247
	 *
3248
	 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
3249
	 */
3250
	export function instantiate(
3251
		bytes: BufferSource,
3252
		importObject?: Imports
3253
	): Promise<WebAssemblyInstantiatedSource>;
3254
3255
	/**
3256
	 * The WebAssembly.instantiate() function allows you to compile and instantiate
3257
	 * WebAssembly code.
3258
	 *
3259
	 * This overload takes an already-compiled WebAssembly.Module and returns
3260
	 * a Promise that resolves to an Instance of that Module. This overload is useful
3261
	 * if the Module has already been compiled.
3262
	 *
3263
	 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
3264
	 */
3265
	export function instantiate(moduleObject: Module, importObject?: Imports): Promise<Instance>;
3266
3267
	/**
3268
	 * The `WebAssembly.instantiateStreaming()` function compiles and instantiates a
3269
	 * WebAssembly module directly from a streamed underlying source. This is the most
3270
	 * efficient, optimized way to load WebAssembly code.
3271
	 *
3272
	 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
3273
	 */
3274
	export function instantiateStreaming(
3275
		response: Response | PromiseLike<Response>,
3276
		importObject?: Imports
3277
	): Promise<WebAssemblyInstantiatedSource>;
3278
3279
	/**
3280
	 * The `WebAssembly.validate()` function validates a given typed array of
3281
	 * WebAssembly binary code, returning whether the bytes form a valid wasm
3282
	 * module (`true`) or not (`false`).
3283
	 *
3284
	 * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
3285
	 */
3286
	export function validate(bytes: BufferSource): boolean;
3287
}
3288
3289
/** Sets a timer which executes a function once after the timer expires. Returns
3290
 * an id which may be used to cancel the timeout.
3291
 *
3292
 *     setTimeout(() => { console.log('hello'); }, 500);
3293
 */
3294
declare function setTimeout(
3295
	/** callback function to execute when timer expires */
3296
	cb: (...args: any[]) => void,
3297
	/** delay in ms */
3298
	delay?: number,
3299
	/** arguments passed to callback function */
3300
	...args: any[]
3301
): number;
3302
3303
/** Repeatedly calls a function , with a fixed time delay between each call.
3304
 *
3305
 *     // Outputs 'hello' to the console every 500ms
3306
 *     setInterval(() => { console.log('hello'); }, 500);
3307
 */
3308
declare function setInterval(
3309
	/** callback function to execute when timer expires */
3310
	cb: (...args: any[]) => void,
3311
	/** delay in ms */
3312
	delay?: number,
3313
	/** arguments passed to callback function */
3314
	...args: any[]
3315
): number;
3316
3317
/** Cancels a timed, repeating action which was previously started by a call
3318
 * to `setInterval()`
3319
 *
3320
 *     const id = setInterval(()= > {console.log('hello');}, 500);
3321
 *     ...
3322
 *     clearInterval(id);
3323
 */
3324
declare function clearInterval(id?: number): void;
3325
3326
/** Cancels a scheduled action initiated by `setTimeout()`
3327
 *
3328
 *     const id = setTimeout(()= > {console.log('hello');}, 500);
3329
 *     ...
3330
 *     clearTimeout(id);
3331
 */
3332
declare function clearTimeout(id?: number): void;
3333
3334
interface VoidFunction {
3335
	(): void;
3336
}
3337
3338
/** A microtask is a short function which is executed after the function or
3339
 * module which created it exits and only if the JavaScript execution stack is
3340
 * empty, but before returning control to the event loop being used to drive the
3341
 * script's execution environment. This event loop may be either the main event
3342
 * loop or the event loop driving a web worker.
3343
 *
3344
 *     queueMicrotask(() => { console.log('This event loop stack is complete'); });
3345
 */
3346
declare function queueMicrotask(func: VoidFunction): void;
3347
3348
declare var crypto: Crypto;
3349
3350
/** Registers an event listener in the global scope, which will be called
3351
 * synchronously whenever the event `type` is dispatched.
3352
 *
3353
 *     addEventListener('unload', () => { console.log('All finished!'); });
3354
 *     ...
3355
 *     dispatchEvent(new Event('unload'));
3356
 */
3357
declare function addEventListener(
3358
	type: string,
3359
	callback: EventListenerOrEventListenerObject | null,
3360
	options?: boolean | AddEventListenerOptions | undefined
3361
): void;
3362
3363
/** Dispatches an event in the global scope, synchronously invoking any
3364
 * registered event listeners for this event in the appropriate order. Returns
3365
 * false if event is cancelable and at least one of the event handlers which
3366
 * handled this event called Event.preventDefault(). Otherwise it returns true.
3367
 *
3368
 *     dispatchEvent(new Event('unload'));
3369
 */
3370
declare function dispatchEvent(event: Event): boolean;
3371
3372
/** Remove a previously registered event listener from the global scope
3373
 *
3374
 *     const lstnr = () => { console.log('hello'); };
3375
 *     addEventListener('load', lstnr);
3376
 *     removeEventListener('load', lstnr);
3377
 */
3378
declare function removeEventListener(
3379
	type: string,
3380
	callback: EventListenerOrEventListenerObject | null,
3381
	options?: boolean | EventListenerOptions | undefined
3382
): void;
3383
3384
interface DOMStringList {
3385
	/** Returns the number of strings in strings. */
3386
	readonly length: number;
3387
	/** Returns true if strings contains string, and false otherwise. */
3388
	contains(string: string): boolean;
3389
	/** Returns the string with index index from strings. */
3390
	item(index: number): string | null;
3391
	[index: number]: string;
3392
}
3393
3394
type BufferSource = ArrayBufferView | ArrayBuffer;
3395
3396
declare interface Console {
3397
	assert(condition?: boolean, ...data: any[]): void;
3398
	clear(): void;
3399
	count(label?: string): void;
3400
	countReset(label?: string): void;
3401
	debug(...data: any[]): void;
3402
	dir(item?: any, options?: any): void;
3403
	dirxml(...data: any[]): void;
3404
	error(...data: any[]): void;
3405
	group(...data: any[]): void;
3406
	groupCollapsed(...data: any[]): void;
3407
	groupEnd(): void;
3408
	info(...data: any[]): void;
3409
	log(...data: any[]): void;
3410
	table(tabularData?: any, properties?: string[]): void;
3411
	time(label?: string): void;
3412
	timeEnd(label?: string): void;
3413
	timeLog(label?: string, ...data: any[]): void;
3414
	timeStamp(label?: string): void;
3415
	trace(...data: any[]): void;
3416
	warn(...data: any[]): void;
3417
}
3418
3419
declare var console: Console;
3420
3421
declare interface Crypto {
3422
	readonly subtle: null;
3423
	getRandomValues<
3424
		T extends
3425
			| Int8Array
3426
			| Int16Array
3427
			| Int32Array
3428
			| Uint8Array
3429
			| Uint16Array
3430
			| Uint32Array
3431
			| Uint8ClampedArray
3432
			| Float32Array
3433
			| Float64Array
3434
			| DataView
3435
			| null
3436
	>(
3437
		array: T
3438
	): T;
3439
}
3440
3441
declare class URLSearchParams {
3442
	constructor(init?: string[][] | Record<string, string> | string | URLSearchParams);
3443
	static toString(): string;
3444
3445
	/** Appends a specified key/value pair as a new search parameter.
3446
	 *
3447
	 * ```ts
3448
	 * let searchParams = new URLSearchParams();
3449
	 * searchParams.append('name', 'first');
3450
	 * searchParams.append('name', 'second');
3451
	 * ```
3452
	 */
3453
	append(name: string, value: string): void;
3454
3455
	/** Deletes the given search parameter and its associated value,
3456
	 * from the list of all search parameters.
3457
	 *
3458
	 * ```ts
3459
	 * let searchParams = new URLSearchParams([['name', 'value']]);
3460
	 * searchParams.delete('name');
3461
	 * ```
3462
	 */
3463
	delete(name: string): void;
3464
3465
	/** Returns all the values associated with a given search parameter
3466
	 * as an array.
3467
	 *
3468
	 * ```ts
3469
	 * searchParams.getAll('name');
3470
	 * ```
3471
	 */
3472
	getAll(name: string): string[];
3473
3474
	/** Returns the first value associated to the given search parameter.
3475
	 *
3476
	 * ```ts
3477
	 * searchParams.get('name');
3478
	 * ```
3479
	 */
3480
	get(name: string): string | null;
3481
3482
	/** Returns a Boolean that indicates whether a parameter with the
3483
	 * specified name exists.
3484
	 *
3485
	 * ```ts
3486
	 * searchParams.has('name');
3487
	 * ```
3488
	 */
3489
	has(name: string): boolean;
3490
3491
	/** Sets the value associated with a given search parameter to the
3492
	 * given value. If there were several matching values, this method
3493
	 * deletes the others. If the search parameter doesn't exist, this
3494
	 * method creates it.
3495
	 *
3496
	 * ```ts
3497
	 * searchParams.set('name', 'value');
3498
	 * ```
3499
	 */
3500
	set(name: string, value: string): void;
3501
3502
	/** Sort all key/value pairs contained in this object in place and
3503
	 * return undefined. The sort order is according to Unicode code
3504
	 * points of the keys.
3505
	 *
3506
	 * ```ts
3507
	 * searchParams.sort();
3508
	 * ```
3509
	 */
3510
	sort(): void;
3511
3512
	/** Calls a function for each element contained in this object in
3513
	 * place and return undefined. Optionally accepts an object to use
3514
	 * as this when executing callback as second argument.
3515
	 *
3516
	 * ```ts
3517
	 * const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
3518
	 * params.forEach((value, key, parent) => {
3519
	 *   console.log(value, key, parent);
3520
	 * });
3521
	 * ```
3522
	 *
3523
	 */
3524
	forEach(callbackfn: (value: string, key: string, parent: this) => void, thisArg?: any): void;
3525
3526
	/** Returns an iterator allowing to go through all keys contained
3527
	 * in this object.
3528
	 *
3529
	 * ```ts
3530
	 * const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
3531
	 * for (const key of params.keys()) {
3532
	 *   console.log(key);
3533
	 * }
3534
	 * ```
3535
	 */
3536
	keys(): IterableIterator<string>;
3537
3538
	/** Returns an iterator allowing to go through all values contained
3539
	 * in this object.
3540
	 *
3541
	 * ```ts
3542
	 * const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
3543
	 * for (const value of params.values()) {
3544
	 *   console.log(value);
3545
	 * }
3546
	 * ```
3547
	 */
3548
	values(): IterableIterator<string>;
3549
3550
	/** Returns an iterator allowing to go through all key/value
3551
	 * pairs contained in this object.
3552
	 *
3553
	 * ```ts
3554
	 * const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
3555
	 * for (const [key, value] of params.entries()) {
3556
	 *   console.log(key, value);
3557
	 * }
3558
	 * ```
3559
	 */
3560
	entries(): IterableIterator<[string, string]>;
3561
3562
	/** Returns an iterator allowing to go through all key/value
3563
	 * pairs contained in this object.
3564
	 *
3565
	 * ```ts
3566
	 * const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
3567
	 * for (const [key, value] of params) {
3568
	 *   console.log(key, value);
3569
	 * }
3570
	 * ```
3571
	 */
3572
	[Symbol.iterator](): IterableIterator<[string, string]>;
3573
3574
	/** Returns a query string suitable for use in a URL.
3575
	 *
3576
	 * ```ts
3577
	 * searchParams.toString();
3578
	 * ```
3579
	 */
3580
	toString(): string;
3581
}
3582
3583
/** The URL interface represents an object providing static methods used for creating object URLs. */
3584
declare class URL {
3585
	constructor(url: string, base?: string | URL);
3586
	createObjectURL(object: any): string;
3587
	revokeObjectURL(url: string): void;
3588
3589
	hash: string;
3590
	host: string;
3591
	hostname: string;
3592
	href: string;
3593
	toString(): string;
3594
	readonly origin: string;
3595
	password: string;
3596
	pathname: string;
3597
	port: string;
3598
	protocol: string;
3599
	search: string;
3600
	readonly searchParams: URLSearchParams;
3601
	username: string;
3602
	toJSON(): string;
3603
}
3604
3605
interface MessageEventInit<T = any> extends EventInit {
3606
	data?: T;
3607
	origin?: string;
3608
	lastEventId?: string;
3609
}
3610
3611
declare class MessageEvent<T = any> extends Event {
3612
	/**
3613
	 * Returns the data of the message.
3614
	 */
3615
	readonly data: T;
3616
	/**
3617
	 * Returns the last event ID string, for server-sent events.
3618
	 */
3619
	readonly lastEventId: string;
3620
	constructor(type: string, eventInitDict?: MessageEventInit);
3621
}
3622
3623
interface ErrorEventInit extends EventInit {
3624
	message?: string;
3625
	filename?: string;
3626
	lineno?: number;
3627
	colno?: number;
3628
	error?: any;
3629
}
3630
3631
declare class ErrorEvent extends Event {
3632
	readonly message: string;
3633
	readonly filename: string;
3634
	readonly lineno: number;
3635
	readonly colno: number;
3636
	readonly error: any;
3637
	constructor(type: string, eventInitDict?: ErrorEventInit);
3638
}
3639
3640
interface PostMessageOptions {
3641
	transfer?: any[];
3642
}
3643
3644
interface ProgressEventInit extends EventInit {
3645
	lengthComputable?: boolean;
3646
	loaded?: number;
3647
	total?: number;
3648
}
3649
3650
interface AbstractWorkerEventMap {
3651
	error: ErrorEvent;
3652
}
3653
3654
interface WorkerEventMap extends AbstractWorkerEventMap {
3655
	message: MessageEvent;
3656
	messageerror: MessageEvent;
3657
}
3658
3659
declare class Worker extends EventTarget {
3660
	onerror?: (e: ErrorEvent) => void;
3661
	onmessage?: (e: MessageEvent) => void;
3662
	onmessageerror?: (e: MessageEvent) => void;
3663
	constructor(
3664
		specifier: string,
3665
		options?: {
3666
			type?: 'classic' | 'module';
3667
			name?: string;
3668
			/** UNSTABLE: New API. Expect many changes; most likely this
3669
			 * field will be made into an object for more granular
3670
			 * configuration of worker thread (permissions, import map, etc.).
3671
			 *
3672
			 * Set to `true` to make `Deno` namespace and all of its methods
3673
			 * available to worker thread.
3674
			 *
3675
			 * Currently worker inherits permissions from main thread (permissions
3676
			 * given using `--allow-*` flags).
3677
			 * Configurable permissions are on the roadmap to be implemented.
3678
			 *
3679
			 * Example:
3680
			 *
3681
			 * ```ts
3682
			 * // mod.ts
3683
			 * const worker = new Worker(
3684
			 *   new URL("deno_worker.ts", import.meta.url).href,
3685
			 *   { type: "module", deno: true }
3686
			 * );
3687
			 * worker.postMessage({ cmd: "readFile", fileName: "./log.txt" });
3688
			 *
3689
			 * // deno_worker.ts
3690
			 *
3691
			 *
3692
			 * self.onmessage = async function (e) {
3693
			 *     const { cmd, fileName } = e.data;
3694
			 *     if (cmd !== "readFile") {
3695
			 *         throw new Error("Invalid command");
3696
			 *     }
3697
			 *     const buf = await Deno.readFile(fileName);
3698
			 *     const fileContents = new TextDecoder().decode(buf);
3699
			 *     console.log(fileContents);
3700
			 * }
3701
			 * ```
3702
			 *
3703
			 * // log.txt
3704
			 * hello world
3705
			 * hello world 2
3706
			 *
3707
			 * // run program
3708
			 * $ deno run --allow-read mod.ts
3709
			 * hello world
3710
			 * hello world2
3711
			 *
3712
			 */
3713
			deno?: boolean;
3714
		}
3715
	);
3716
	postMessage(message: any, transfer: ArrayBuffer[]): void;
3717
	postMessage(message: any, options?: PostMessageOptions): void;
3718
	addEventListener<K extends keyof WorkerEventMap>(
3719
		type: K,
3720
		listener: (this: Worker, ev: WorkerEventMap[K]) => any,
3721
		options?: boolean | AddEventListenerOptions
3722
	): void;
3723
	addEventListener(
3724
		type: string,
3725
		listener: EventListenerOrEventListenerObject,
3726
		options?: boolean | AddEventListenerOptions
3727
	): void;
3728
	removeEventListener<K extends keyof WorkerEventMap>(
3729
		type: K,
3730
		listener: (this: Worker, ev: WorkerEventMap[K]) => any,
3731
		options?: boolean | EventListenerOptions
3732
	): void;
3733
	removeEventListener(
3734
		type: string,
3735
		listener: EventListenerOrEventListenerObject,
3736
		options?: boolean | EventListenerOptions
3737
	): void;
3738
	terminate(): void;
3739
}
3740
3741
declare type PerformanceEntryList = PerformanceEntry[];
3742
3743
declare class Performance {
3744
	constructor();
3745
3746
	/** Removes the stored timestamp with the associated name. */
3747
	clearMarks(markName?: string): void;
3748
3749
	/** Removes stored timestamp with the associated name. */
3750
	clearMeasures(measureName?: string): void;
3751
3752
	getEntries(): PerformanceEntryList;
3753
	getEntriesByName(name: string, type?: string): PerformanceEntryList;
3754
	getEntriesByType(type: string): PerformanceEntryList;
3755
3756
	/** Stores a timestamp with the associated name (a "mark"). */
3757
	mark(markName: string, options?: PerformanceMarkOptions): PerformanceMark;
3758
3759
	/** Stores the `DOMHighResTimeStamp` duration between two marks along with the
3760
	 * associated name (a "measure"). */
3761
	measure(measureName: string, options?: PerformanceMeasureOptions): PerformanceMeasure;
3762
	/** Stores the `DOMHighResTimeStamp` duration between two marks along with the
3763
	 * associated name (a "measure"). */
3764
	measure(measureName: string, startMark?: string, endMark?: string): PerformanceMeasure;
3765
3766
	/** Returns a current time from Deno's start in milliseconds.
3767
	 *
3768
	 * Use the permission flag `--allow-hrtime` return a precise value.
3769
	 *
3770
	 * ```ts
3771
	 * const t = performance.now();
3772
	 * console.log(`${t} ms since start!`);
3773
	 * ```
3774
	 */
3775
	now(): number;
3776
}
3777
3778
declare var performance: Performance;
3779
3780
declare interface PerformanceMarkOptions {
3781
	/** Metadata to be included in the mark. */
3782
	detail?: any;
3783
3784
	/** Timestamp to be used as the mark time. */
3785
	startTime?: number;
3786
}
3787
3788
declare interface PerformanceMeasureOptions {
3789
	/** Metadata to be included in the measure. */
3790
	detail?: any;
3791
3792
	/** Timestamp to be used as the start time or string to be used as start
3793
	 * mark.*/
3794
	start?: string | number;
3795
3796
	/** Duration between the start and end times. */
3797
	duration?: number;
3798
3799
	/** Timestamp to be used as the end time or string to be used as end mark. */
3800
	end?: string | number;
3801
}
3802
3803
/** Encapsulates a single performance metric that is part of the performance
3804
 * timeline. A performance entry can be directly created by making a performance
3805
 * mark or measure (for example by calling the `.mark()` method) at an explicit
3806
 * point in an application. */
3807
declare class PerformanceEntry {
3808
	readonly duration: number;
3809
	readonly entryType: string;
3810
	readonly name: string;
3811
	readonly startTime: number;
3812
	toJSON(): any;
3813
}
3814
3815
/** `PerformanceMark` is an abstract interface for `PerformanceEntry` objects
3816
 * with an entryType of `"mark"`. Entries of this type are created by calling
3817
 * `performance.mark()` to add a named `DOMHighResTimeStamp` (the mark) to the
3818
 * performance timeline. */
3819
declare class PerformanceMark extends PerformanceEntry {
3820
	readonly detail: any;
3821
	readonly entryType: 'mark';
3822
	constructor(name: string, options?: PerformanceMarkOptions);
3823
}
3824
3825
/** `PerformanceMeasure` is an abstract interface for `PerformanceEntry` objects
3826
 * with an entryType of `"measure"`. Entries of this type are created by calling
3827
 * `performance.measure()` to add a named `DOMHighResTimeStamp` (the measure)
3828
 * between two marks to the performance timeline. */
3829
declare class PerformanceMeasure extends PerformanceEntry {
3830
	readonly detail: any;
3831
	readonly entryType: 'measure';
3832
}
3833
3834
/** Events measuring progress of an underlying process, like an HTTP request
3835
 * (for an XMLHttpRequest, or the loading of the underlying resource of an
3836
 * <img>, <audio>, <video>, <style> or <link>). */
3837
declare class ProgressEvent<T extends EventTarget = EventTarget> extends Event {
3838
	constructor(type: string, eventInitDict?: ProgressEventInit);
3839
	readonly lengthComputable: boolean;
3840
	readonly loaded: number;
3841
	readonly target: T | null;
3842
	readonly total: number;
3843
}
3844
3845
declare interface CustomEventInit<T = any> extends EventInit {
3846
	detail?: T;
3847
}
3848
3849
declare class CustomEvent<T = any> extends Event {
3850
	constructor(typeArg: string, eventInitDict?: CustomEventInit<T>);
3851
	/** Returns any custom data event was created with. Typically used for
3852
	 * synthetic events. */
3853
	readonly detail: T;
3854
}
3855
3856
interface ErrorConstructor {
3857
	/** See https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions. */
3858
	captureStackTrace(error: Object, constructor?: Function): void;
3859
	// TODO(nayeemrmn): Support `Error.prepareStackTrace()`. We currently use this
3860
	// internally in a way that makes it unavailable for users.
3861
}
3862
3863
interface CloseEventInit extends EventInit {
3864
	code?: number;
3865
	reason?: string;
3866
	wasClean?: boolean;
3867
}
3868
3869
declare class CloseEvent extends Event {
3870
	constructor(type: string, eventInitDict?: CloseEventInit);
3871
	/**
3872
	 * Returns the WebSocket connection close code provided by the server.
3873
	 */
3874
	readonly code: number;
3875
	/**
3876
	 * Returns the WebSocket connection close reason provided by the server.
3877
	 */
3878
	readonly reason: string;
3879
	/**
3880
	 * Returns true if the connection closed cleanly; false otherwise.
3881
	 */
3882
	readonly wasClean: boolean;
3883
}
3884
3885
interface WebSocketEventMap {
3886
	close: CloseEvent;
3887
	error: Event;
3888
	message: MessageEvent;
3889
	open: Event;
3890
}
3891
3892
/** Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection. */
3893
declare class WebSocket extends EventTarget {
3894
	constructor(url: string, protocols?: string | string[]);
3895
3896
	static readonly CLOSED: number;
3897
	static readonly CLOSING: number;
3898
	static readonly CONNECTING: number;
3899
	static readonly OPEN: number;
3900
3901
	/**
3902
	 * Returns a string that indicates how binary data from the WebSocket object is exposed to scripts:
3903
	 *
3904
	 * Can be set, to change how binary data is returned. The default is "blob".
3905
	 */
3906
	binaryType: BinaryType;
3907
	/**
3908
	 * Returns the number of bytes of application data (UTF-8 text and binary data) that have been queued using send() but not yet been transmitted to the network.
3909
	 *
3910
	 * If the WebSocket connection is closed, this attribute's value will only increase with each call to the send() method. (The number does not reset to zero once the connection closes.)
3911
	 */
3912
	readonly bufferedAmount: number;
3913
	/**
3914
	 * Returns the extensions selected by the server, if any.
3915
	 */
3916
	readonly extensions: string;
3917
	onclose: ((this: WebSocket, ev: CloseEvent) => any) | null;
3918
	onerror: ((this: WebSocket, ev: Event | ErrorEvent) => any) | null;
3919
	onmessage: ((this: WebSocket, ev: MessageEvent) => any) | null;
3920
	onopen: ((this: WebSocket, ev: Event) => any) | null;
3921
	/**
3922
	 * Returns the subprotocol selected by the server, if any. It can be used in conjunction with the array form of the constructor's second argument to perform subprotocol negotiation.
3923
	 */
3924
	readonly protocol: string;
3925
	/**
3926
	 * Returns the state of the WebSocket object's connection. It can have the values described below.
3927
	 */
3928
	readonly readyState: number;
3929
	/**
3930
	 * Returns the URL that was used to establish the WebSocket connection.
3931
	 */
3932
	readonly url: string;
3933
	/**
3934
	 * Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason.
3935
	 */
3936
	close(code?: number, reason?: string): void;
3937
	/**
3938
	 * Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
3939
	 */
3940
	send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
3941
	readonly CLOSED: number;
3942
	readonly CLOSING: number;
3943
	readonly CONNECTING: number;
3944
	readonly OPEN: number;
3945
	addEventListener<K extends keyof WebSocketEventMap>(
3946
		type: K,
3947
		listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any,
3948
		options?: boolean | AddEventListenerOptions
3949
	): void;
3950
	addEventListener(
3951
		type: string,
3952
		listener: EventListenerOrEventListenerObject,
3953
		options?: boolean | AddEventListenerOptions
3954
	): void;
3955
	removeEventListener<K extends keyof WebSocketEventMap>(
3956
		type: K,
3957
		listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any,
3958
		options?: boolean | EventListenerOptions
3959
	): void;
3960
	removeEventListener(
3961
		type: string,
3962
		listener: EventListenerOrEventListenerObject,
3963
		options?: boolean | EventListenerOptions
3964
	): void;
3965
}
3966
3967
type BinaryType = 'arraybuffer' | 'blob';
3968
3969
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
3970
3971
/// <reference no-default-lib="true" />
3972
/// <reference lib="deno.ns" />
3973
/// <reference lib="deno.shared_globals" />
3974
/// <reference lib="esnext" />
3975
3976
declare class Window extends EventTarget {
3977
	new(): Window;
3978
	readonly window: Window & typeof globalThis;
3979
	readonly self: Window & typeof globalThis;
3980
	onload: ((this: Window, ev: Event) => any) | null;
3981
	onunload: ((this: Window, ev: Event) => any) | null;
3982
	close: () => void;
3983
	readonly closed: boolean;
3984
	alert: (message?: string) => void;
3985
	confirm: (message?: string) => boolean;
3986
	prompt: (message?: string, defaultValue?: string) => string | null;
3987
	Deno: typeof Deno;
3988
}
3989
3990
declare var window: Window & typeof globalThis;
3991
declare var self: Window & typeof globalThis;
3992
declare var onload: ((this: Window, ev: Event) => any) | null;
3993
declare var onunload: ((this: Window, ev: Event) => any) | null;
3994
3995
/**
3996
 * Shows the given message and waits for the enter key pressed.
3997
 * If the stdin is not interactive, it does nothing.
3998
 * @param message
3999
 */
4000
declare function alert(message?: string): void;
4001
4002
/**
4003
 * Shows the given message and waits for the answer. Returns the user's answer as boolean.
4004
 * Only `y` and `Y` are considered as true.
4005
 * If the stdin is not interactive, it returns false.
4006
 * @param message
4007
 */
4008
declare function confirm(message?: string): boolean;
4009
4010
/**
4011
 * Shows the given message and waits for the user's input. Returns the user's input as string.
4012
 * If the default value is given and the user inputs the empty string, then it returns the given
4013
 * default value.
4014
 * If the default value is not given and the user inputs the empty string, it returns null.
4015
 * If the stdin is not interactive, it returns null.
4016
 * @param message
4017
 * @param defaultValue
4018
 */
4019
declare function prompt(message?: string, defaultValue?: string): string | null;
4020