├── .editorconfig
├── .gitignore
├── LICENSE
├── README.md
├── deno.d.ts
├── fixtures
└── sample.txt
├── package.json
├── src
├── __tests__
│ ├── fs.test.ts
│ ├── io.test.ts
│ └── os.test.ts
├── buffer.ts
├── deno.ts
├── encoding.ts
├── file.ts
├── net.ts
├── polyfill.ts
├── process.ts
├── resources.ts
└── util.ts
├── tsconfig.json
└── yarn.lock
/.editorconfig:
--------------------------------------------------------------------------------
1 | [*]
2 | indent_size = 2
3 |
4 | [Makefile]
5 | indent_style = tab
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_store
3 | .idea
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Yusuke Sakurai
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # [WIP] denode
2 | Deno polyfill for Node.js
3 |
--------------------------------------------------------------------------------
/deno.d.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
2 |
3 | /* eslint-disable @typescript-eslint/no-explicit-any */
4 | /* eslint-disable @typescript-eslint/no-empty-interface */
5 |
6 | ///
7 | ///
8 |
9 | declare namespace Deno {
10 | // @url js/os.d.ts
11 |
12 | /** The current process id of the runtime. */
13 | export let pid: number;
14 | /** Reflects the NO_COLOR environment variable: https://no-color.org/ */
15 | export let noColor: boolean;
16 | /** Check if running in terminal.
17 | *
18 | * console.log(Deno.isTTY().stdout);
19 | */
20 | export function isTTY(): {
21 | stdin: boolean;
22 | stdout: boolean;
23 | stderr: boolean;
24 | };
25 | /** Get the hostname.
26 | * Requires the `--allow-env` flag.
27 | *
28 | * console.log(Deno.hostname());
29 | */
30 | export function hostname(): string;
31 | /** Exit the Deno process with optional exit code. */
32 | export function exit(code?: number): never;
33 | /** Returns a snapshot of the environment variables at invocation. Mutating a
34 | * property in the object will set that variable in the environment for
35 | * the process. The environment object will only accept `string`s
36 | * as values.
37 | *
38 | * const myEnv = Deno.env();
39 | * console.log(myEnv.SHELL);
40 | * myEnv.TEST_VAR = "HELLO";
41 | * const newEnv = Deno.env();
42 | * console.log(myEnv.TEST_VAR == newEnv.TEST_VAR);
43 | */
44 | export function env(): {
45 | [index: string]: string;
46 | };
47 | /** Returns the value of an environment variable at invocation.
48 | * If the variable is not present, `undefined` will be returned.
49 | *
50 | * const myEnv = Deno.env();
51 | * console.log(myEnv.SHELL);
52 | * myEnv.TEST_VAR = "HELLO";
53 | * const newEnv = Deno.env();
54 | * console.log(myEnv.TEST_VAR == newEnv.TEST_VAR);
55 | */
56 | export function env(key: string): string | undefined;
57 | /**
58 | * Returns the current user's home directory.
59 | * Requires the `--allow-env` flag.
60 | */
61 | export function homeDir(): string;
62 | /**
63 | * Returns the path to the current deno executable.
64 | * Requires the `--allow-env` flag.
65 | */
66 | export function execPath(): string;
67 |
68 | // @url js/dir.d.ts
69 |
70 | /**
71 | * `cwd()` Return a string representing the current working directory.
72 | * If the current directory can be reached via multiple paths
73 | * (due to symbolic links), `cwd()` may return
74 | * any one of them.
75 | * throws `NotFound` exception if directory not available
76 | */
77 | export function cwd(): string;
78 | /**
79 | * `chdir()` Change the current working directory to path.
80 | * throws `NotFound` exception if directory not available
81 | */
82 | export function chdir(directory: string): void;
83 |
84 | // @url js/io.d.ts
85 |
86 | export const EOF: unique symbol;
87 | export type EOF = typeof EOF;
88 | export enum SeekMode {
89 | SEEK_START = 0,
90 | SEEK_CURRENT = 1,
91 | SEEK_END = 2
92 | }
93 | export interface Reader {
94 | /** Reads up to p.byteLength bytes into `p`. It resolves to the number
95 | * of bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error encountered.
96 | * Even if `read()` returns `n` < `p.byteLength`, it may use all of `p` as
97 | * scratch space during the call. If some data is available but not
98 | * `p.byteLength` bytes, `read()` conventionally returns what is available
99 | * instead of waiting for more.
100 | *
101 | * When `read()` encounters end-of-file condition, it returns EOF symbol.
102 | *
103 | * When `read()` encounters an error, it rejects with an error.
104 | *
105 | * Callers should always process the `n` > `0` bytes returned before
106 | * considering the EOF. Doing so correctly handles I/O errors that happen
107 | * after reading some bytes and also both of the allowed EOF behaviors.
108 | *
109 | * Implementations must not retain `p`.
110 | */
111 | read(p: Uint8Array): Promise;
112 | }
113 | export interface SyncReader {
114 | readSync(p: Uint8Array): number | EOF;
115 | }
116 | export interface Writer {
117 | /** Writes `p.byteLength` bytes from `p` to the underlying data
118 | * stream. It resolves to the number of bytes written from `p` (`0` <= `n` <=
119 | * `p.byteLength`) and any error encountered that caused the write to stop
120 | * early. `write()` must return a non-null error if it returns `n` <
121 | * `p.byteLength`. write() must not modify the slice data, even temporarily.
122 | *
123 | * Implementations must not retain `p`.
124 | */
125 | write(p: Uint8Array): Promise;
126 | }
127 | export interface SyncWriter {
128 | writeSync(p: Uint8Array): number;
129 | }
130 | export interface Closer {
131 | close(): void;
132 | }
133 | export interface Seeker {
134 | /** Seek sets the offset for the next `read()` or `write()` to offset,
135 | * interpreted according to `whence`: `SeekStart` means relative to the start
136 | * of the file, `SeekCurrent` means relative to the current offset, and
137 | * `SeekEnd` means relative to the end. Seek returns the new offset relative
138 | * to the start of the file and an error, if any.
139 | *
140 | * Seeking to an offset before the start of the file is an error. Seeking to
141 | * any positive offset is legal, but the behavior of subsequent I/O operations
142 | * on the underlying object is implementation-dependent.
143 | */
144 | seek(offset: number, whence: SeekMode): Promise;
145 | }
146 | export interface SyncSeeker {
147 | seekSync(offset: number, whence: SeekMode): void;
148 | }
149 | export interface ReadCloser extends Reader, Closer {}
150 | export interface WriteCloser extends Writer, Closer {}
151 | export interface ReadSeeker extends Reader, Seeker {}
152 | export interface WriteSeeker extends Writer, Seeker {}
153 | export interface ReadWriteCloser extends Reader, Writer, Closer {}
154 | export interface ReadWriteSeeker extends Reader, Writer, Seeker {}
155 | /** Copies from `src` to `dst` until either `EOF` is reached on `src`
156 | * or an error occurs. It returns the number of bytes copied and the first
157 | * error encountered while copying, if any.
158 | *
159 | * Because `copy()` is defined to read from `src` until `EOF`, it does not
160 | * treat an `EOF` from `read()` as an error to be reported.
161 | */
162 | export function copy(dst: Writer, src: Reader): Promise;
163 | /** Turns `r` into async iterator.
164 | *
165 | * for await (const chunk of toAsyncIterator(reader)) {
166 | * console.log(chunk)
167 | * }
168 | */
169 | export function toAsyncIterator(r: Reader): AsyncIterableIterator;
170 |
171 | // @url js/files.d.ts
172 |
173 | /** Open a file and return an instance of the `File` object
174 | * synchronously.
175 | *
176 | * const file = Deno.openSync("/foo/bar.txt");
177 | */
178 | export function openSync(filename: string, mode?: OpenMode): File;
179 | /** Open a file and return an instance of the `File` object.
180 | *
181 | * (async () => {
182 | * const file = await Deno.open("/foo/bar.txt");
183 | * })();
184 | */
185 | export function open(filename: string, mode?: OpenMode): Promise;
186 | /** Read synchronously from a file ID into an array buffer.
187 | *
188 | * Return `number | EOF` for the operation.
189 | *
190 | * const file = Deno.openSync("/foo/bar.txt");
191 | * const buf = new Uint8Array(100);
192 | * const nread = Deno.readSync(file.rid, buf);
193 | * const text = new TextDecoder().decode(buf);
194 | *
195 | */
196 | export function readSync(rid: number, p: Uint8Array): number | EOF;
197 | /** Read from a file ID into an array buffer.
198 | *
199 | * Resolves with the `number | EOF` for the operation.
200 | *
201 | * (async () => {
202 | * const file = await Deno.open("/foo/bar.txt");
203 | * const buf = new Uint8Array(100);
204 | * const nread = await Deno.read(file.rid, buf);
205 | * const text = new TextDecoder().decode(buf);
206 | * })();
207 | */
208 | export function read(rid: number, p: Uint8Array): Promise;
209 | /** Write synchronously to the file ID the contents of the array buffer.
210 | *
211 | * Resolves with the number of bytes written.
212 | *
213 | * const encoder = new TextEncoder();
214 | * const data = encoder.encode("Hello world\n");
215 | * const file = Deno.openSync("/foo/bar.txt");
216 | * Deno.writeSync(file.rid, data);
217 | */
218 | export function writeSync(rid: number, p: Uint8Array): number;
219 | /** Write to the file ID the contents of the array buffer.
220 | *
221 | * Resolves with the number of bytes written.
222 | *
223 | * (async () => {
224 | * const encoder = new TextEncoder();
225 | * const data = encoder.encode("Hello world\n");
226 | * const file = await Deno.open("/foo/bar.txt");
227 | * await Deno.write(file.rid, data);
228 | * })();
229 | *
230 | */
231 | export function write(rid: number, p: Uint8Array): Promise;
232 | /** Seek a file ID synchronously to the given offset under mode given by `whence`.
233 | *
234 | * const file = Deno.openSync("/foo/bar.txt");
235 | * Deno.seekSync(file.rid, 0, 0);
236 | */
237 | export function seekSync(rid: number, offset: number, whence: SeekMode): void;
238 | /** Seek a file ID to the given offset under mode given by `whence`.
239 | *
240 | * (async () => {
241 | * const file = await Deno.open("/foo/bar.txt");
242 | * await Deno.seek(file.rid, 0, 0);
243 | * })();
244 | */
245 | export function seek(
246 | rid: number,
247 | offset: number,
248 | whence: SeekMode
249 | ): Promise;
250 | /** Close the file ID. */
251 | export function close(rid: number): void;
252 | /** The Deno abstraction for reading and writing files. */
253 | export class File
254 | implements
255 | Reader,
256 | SyncReader,
257 | Writer,
258 | SyncWriter,
259 | Seeker,
260 | SyncSeeker,
261 | Closer {
262 | readonly rid: number;
263 | constructor(rid: number);
264 | write(p: Uint8Array): Promise;
265 | writeSync(p: Uint8Array): number;
266 | read(p: Uint8Array): Promise;
267 | readSync(p: Uint8Array): number | EOF;
268 | seek(offset: number, whence: SeekMode): Promise;
269 | seekSync(offset: number, whence: SeekMode): void;
270 | close(): void;
271 | }
272 | /** An instance of `File` for stdin. */
273 | export const stdin: File;
274 | /** An instance of `File` for stdout. */
275 | export const stdout: File;
276 | /** An instance of `File` for stderr. */
277 | export const stderr: File;
278 | export type OpenMode =
279 | | "r"
280 | /** Read-write. Start at beginning of file. */
281 | | "r+"
282 | /** Write-only. Opens and truncates existing file or creates new one for
283 | * writing only.
284 | */
285 | | "w"
286 | /** Read-write. Opens and truncates existing file or creates new one for
287 | * writing and reading.
288 | */
289 | | "w+"
290 | /** Write-only. Opens existing file or creates new one. Each write appends
291 | * content to the end of file.
292 | */
293 | | "a"
294 | /** Read-write. Behaves like "a" and allows to read from file. */
295 | | "a+"
296 | /** Write-only. Exclusive create - creates new file only if one doesn't exist
297 | * already.
298 | */
299 | | "x"
300 | /** Read-write. Behaves like `x` and allows to read from file. */
301 | | "x+";
302 |
303 | // @url js/buffer.d.ts
304 |
305 | /** A Buffer is a variable-sized buffer of bytes with read() and write()
306 | * methods. Based on https://golang.org/pkg/bytes/#Buffer
307 | */
308 | export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
309 | private buf;
310 | private off;
311 | constructor(ab?: ArrayBuffer);
312 | /** bytes() returns a slice holding the unread portion of the buffer.
313 | * The slice is valid for use only until the next buffer modification (that
314 | * is, only until the next call to a method like read(), write(), reset(), or
315 | * truncate()). The slice aliases the buffer content at least until the next
316 | * buffer modification, so immediate changes to the slice will affect the
317 | * result of future reads.
318 | */
319 | bytes(): Uint8Array;
320 | /** toString() returns the contents of the unread portion of the buffer
321 | * as a string. Warning - if multibyte characters are present when data is
322 | * flowing through the buffer, this method may result in incorrect strings
323 | * due to a character being split.
324 | */
325 | toString(): string;
326 | /** empty() returns whether the unread portion of the buffer is empty. */
327 | empty(): boolean;
328 | /** length is a getter that returns the number of bytes of the unread
329 | * portion of the buffer
330 | */
331 | readonly length: number;
332 | /** Returns the capacity of the buffer's underlying byte slice, that is,
333 | * the total space allocated for the buffer's data.
334 | */
335 | readonly capacity: number;
336 | /** truncate() discards all but the first n unread bytes from the buffer but
337 | * continues to use the same allocated storage. It throws if n is negative or
338 | * greater than the length of the buffer.
339 | */
340 | truncate(n: number): void;
341 | /** reset() resets the buffer to be empty, but it retains the underlying
342 | * storage for use by future writes. reset() is the same as truncate(0)
343 | */
344 | reset(): void;
345 | /** _tryGrowByReslice() is a version of grow for the fast-case
346 | * where the internal buffer only needs to be resliced. It returns the index
347 | * where bytes should be written and whether it succeeded.
348 | * It returns -1 if a reslice was not needed.
349 | */
350 | private _tryGrowByReslice;
351 | private _reslice;
352 | /** readSync() reads the next len(p) bytes from the buffer or until the buffer
353 | * is drained. The return value n is the number of bytes read. If the
354 | * buffer has no data to return, eof in the response will be true.
355 | */
356 | readSync(p: Uint8Array): number | EOF;
357 | read(p: Uint8Array): Promise;
358 | writeSync(p: Uint8Array): number;
359 | write(p: Uint8Array): Promise;
360 | /** _grow() grows the buffer to guarantee space for n more bytes.
361 | * It returns the index where bytes should be written.
362 | * If the buffer can't grow it will throw with ErrTooLarge.
363 | */
364 | private _grow;
365 | /** grow() grows the buffer's capacity, if necessary, to guarantee space for
366 | * another n bytes. After grow(n), at least n bytes can be written to the
367 | * buffer without another allocation. If n is negative, grow() will panic. If
368 | * the buffer can't grow it will throw ErrTooLarge.
369 | * Based on https://golang.org/pkg/bytes/#Buffer.Grow
370 | */
371 | grow(n: number): void;
372 | /** readFrom() reads data from r until EOF and appends it to the buffer,
373 | * growing the buffer as needed. It returns the number of bytes read. If the
374 | * buffer becomes too large, readFrom will panic with ErrTooLarge.
375 | * Based on https://golang.org/pkg/bytes/#Buffer.ReadFrom
376 | */
377 | readFrom(r: Reader): Promise;
378 | /** Sync version of `readFrom`
379 | */
380 | readFromSync(r: SyncReader): number;
381 | }
382 | /** Read `r` until EOF and return the content as `Uint8Array`.
383 | */
384 | export function readAll(r: Reader): Promise;
385 | /** Read synchronously `r` until EOF and return the content as `Uint8Array`.
386 | */
387 | export function readAllSync(r: SyncReader): Uint8Array;
388 | /** Write all the content of `arr` to `w`.
389 | */
390 | export function writeAll(w: Writer, arr: Uint8Array): Promise;
391 | /** Write synchronously all the content of `arr` to `w`.
392 | */
393 | export function writeAllSync(w: SyncWriter, arr: Uint8Array): void;
394 |
395 | // @url js/mkdir.d.ts
396 |
397 | /** Creates a new directory with the specified path synchronously.
398 | * If `recursive` is set to true, nested directories will be created (also known
399 | * as "mkdir -p").
400 | * `mode` sets permission bits (before umask) on UNIX and does nothing on
401 | * Windows.
402 | *
403 | * Deno.mkdirSync("new_dir");
404 | * Deno.mkdirSync("nested/directories", true);
405 | */
406 | export function mkdirSync(
407 | path: string,
408 | recursive?: boolean,
409 | mode?: number
410 | ): void;
411 | /** Creates a new directory with the specified path.
412 | * If `recursive` is set to true, nested directories will be created (also known
413 | * as "mkdir -p").
414 | * `mode` sets permission bits (before umask) on UNIX and does nothing on
415 | * Windows.
416 | *
417 | * await Deno.mkdir("new_dir");
418 | * await Deno.mkdir("nested/directories", true);
419 | */
420 | export function mkdir(
421 | path: string,
422 | recursive?: boolean,
423 | mode?: number
424 | ): Promise;
425 |
426 | // @url js/make_temp_dir.d.ts
427 |
428 | export interface MakeTempDirOptions {
429 | dir?: string;
430 | prefix?: string;
431 | suffix?: string;
432 | }
433 | /** makeTempDirSync is the synchronous version of `makeTempDir`.
434 | *
435 | * const tempDirName0 = Deno.makeTempDirSync();
436 | * const tempDirName1 = Deno.makeTempDirSync({ prefix: 'my_temp' });
437 | */
438 | export function makeTempDirSync(options?: MakeTempDirOptions): string;
439 | /** makeTempDir creates a new temporary directory in the directory `dir`, its
440 | * name beginning with `prefix` and ending with `suffix`.
441 | * It returns the full path to the newly created directory.
442 | * If `dir` is unspecified, tempDir uses the default directory for temporary
443 | * files. Multiple programs calling tempDir simultaneously will not choose the
444 | * same directory. It is the caller's responsibility to remove the directory
445 | * when no longer needed.
446 | *
447 | * const tempDirName0 = await Deno.makeTempDir();
448 | * const tempDirName1 = await Deno.makeTempDir({ prefix: 'my_temp' });
449 | */
450 | export function makeTempDir(options?: MakeTempDirOptions): Promise;
451 |
452 | // @url js/chmod.d.ts
453 |
454 | /** Changes the permission of a specific file/directory of specified path
455 | * synchronously.
456 | *
457 | * Deno.chmodSync("/path/to/file", 0o666);
458 | */
459 | export function chmodSync(path: string, mode: number): void;
460 | /** Changes the permission of a specific file/directory of specified path.
461 | *
462 | * await Deno.chmod("/path/to/file", 0o666);
463 | */
464 | export function chmod(path: string, mode: number): Promise;
465 |
466 | // @url js/chown.d.ts
467 |
468 | /**
469 | * Change owner of a regular file or directory synchronously. Unix only at the moment.
470 | * @param path path to the file
471 | * @param uid user id of the new owner
472 | * @param gid group id of the new owner
473 | */
474 | export function chownSync(path: string, uid: number, gid: number): void;
475 | /**
476 | * Change owner of a regular file or directory asynchronously. Unix only at the moment.
477 | * @param path path to the file
478 | * @param uid user id of the new owner
479 | * @param gid group id of the new owner
480 | */
481 | export function chown(path: string, uid: number, gid: number): Promise;
482 |
483 | // @url js/utime.d.ts
484 |
485 | /** Synchronously changes the access and modification times of a file system
486 | * object referenced by `filename`. Given times are either in seconds
487 | * (Unix epoch time) or as `Date` objects.
488 | *
489 | * Deno.utimeSync("myfile.txt", 1556495550, new Date());
490 | */
491 | export function utimeSync(
492 | filename: string,
493 | atime: number | Date,
494 | mtime: number | Date
495 | ): void;
496 | /** Changes the access and modification times of a file system object
497 | * referenced by `filename`. Given times are either in seconds
498 | * (Unix epoch time) or as `Date` objects.
499 | *
500 | * await Deno.utime("myfile.txt", 1556495550, new Date());
501 | */
502 | export function utime(
503 | filename: string,
504 | atime: number | Date,
505 | mtime: number | Date
506 | ): Promise;
507 |
508 | // @url js/remove.d.ts
509 |
510 | export interface RemoveOption {
511 | recursive?: boolean;
512 | }
513 | /** Removes the named file or directory synchronously. Would throw
514 | * error if permission denied, not found, or directory not empty if `recursive`
515 | * set to false.
516 | * `recursive` is set to false by default.
517 | *
518 | * Deno.removeSync("/path/to/dir/or/file", {recursive: false});
519 | */
520 | export function removeSync(path: string, options?: RemoveOption): void;
521 | /** Removes the named file or directory. Would throw error if
522 | * permission denied, not found, or directory not empty if `recursive` set
523 | * to false.
524 | * `recursive` is set to false by default.
525 | *
526 | * await Deno.remove("/path/to/dir/or/file", {recursive: false});
527 | */
528 | export function remove(path: string, options?: RemoveOption): Promise;
529 |
530 | // @url js/rename.d.ts
531 |
532 | /** Synchronously renames (moves) `oldpath` to `newpath`. If `newpath` already
533 | * exists and is not a directory, `renameSync()` replaces it. OS-specific
534 | * restrictions may apply when `oldpath` and `newpath` are in different
535 | * directories.
536 | *
537 | * Deno.renameSync("old/path", "new/path");
538 | */
539 | export function renameSync(oldpath: string, newpath: string): void;
540 | /** Renames (moves) `oldpath` to `newpath`. If `newpath` already exists and is
541 | * not a directory, `rename()` replaces it. OS-specific restrictions may apply
542 | * when `oldpath` and `newpath` are in different directories.
543 | *
544 | * await Deno.rename("old/path", "new/path");
545 | */
546 | export function rename(oldpath: string, newpath: string): Promise;
547 |
548 | // @url js/read_file.d.ts
549 |
550 | /** Read the entire contents of a file synchronously.
551 | *
552 | * const decoder = new TextDecoder("utf-8");
553 | * const data = Deno.readFileSync("hello.txt");
554 | * console.log(decoder.decode(data));
555 | */
556 | export function readFileSync(filename: string): Uint8Array;
557 | /** Read the entire contents of a file.
558 | *
559 | * const decoder = new TextDecoder("utf-8");
560 | * const data = await Deno.readFile("hello.txt");
561 | * console.log(decoder.decode(data));
562 | */
563 | export function readFile(filename: string): Promise;
564 |
565 | /** Synchronously write string `data` to the given `path`, by default creating a new file if needed,
566 | * else overwriting.
567 | *
568 | * ```ts
569 | * await Deno.writeTextFileSync("hello1.txt", "Hello world\n"); // overwrite "hello1.txt" or create it
570 | * ```
571 | *
572 | * Requires `allow-write` permission, and `allow-read` if `options.create` is `false`.
573 | */
574 |
575 | /** Synchronously reads and returns the entire contents of a file as utf8 encoded string
576 | * encoded string. Reading a directory returns an empty string.
577 | *
578 | * ```ts
579 | * const data = Deno.readTextFileSync("hello.txt");
580 | * console.log(data);
581 | * ```
582 | *
583 | * Requires `allow-read` permission. */
584 | export function readTextFileSync(path: string): string;
585 |
586 | /** Asynchronously reads and returns the entire contents of a file as a utf8
587 | * encoded string. Reading a directory returns an empty data array.
588 | *
589 | * ```ts
590 | * const data = await Deno.readTextFile("hello.txt");
591 | * console.log(data);
592 | * ```
593 | *
594 | * Requires `allow-read` permission. */
595 |
596 | export function readTextFile(path: string): Promise;
597 |
598 | /** Asynchronously write string `data` to the given `path`, by default creating a new file if needed,
599 | * else overwriting.
600 | *
601 | * ```ts
602 | * await Deno.writeTextFile("hello1.txt", "Hello world\n"); // overwrite "hello1.txt" or create it
603 | * ```
604 | *
605 | * Requires `allow-write` permission, and `allow-read` if `options.create` is `false`.
606 | */
607 |
608 | export function writeTextFileSync(
609 | path: string | URL,
610 | data: string,
611 | options?: WriteFileOptions
612 | ): void;
613 |
614 | /** Asynchronously write string `data` to the given `path`, by default creating a new file if needed,
615 | * else overwriting.
616 | *
617 | * ```ts
618 | * await Deno.writeTextFile("hello1.txt", "Hello world\n"); // overwrite "hello1.txt" or create it
619 | * ```
620 | *
621 | * Requires `allow-write` permission, and `allow-read` if `options.create` is `false`.
622 | */
623 | export function writeTextFile(
624 | path: string | URL,
625 | data: string,
626 | options?: WriteFileOptions
627 | ): Promise;
628 |
629 | // @url js/file_info.d.ts
630 |
631 | /** A FileInfo describes a file and is returned by `stat`, `lstat`,
632 | * `statSync`, `lstatSync`.
633 | */
634 | export interface FileInfo {
635 | /** The size of the file, in bytes. */
636 | len: number;
637 | /** The last modification time of the file. This corresponds to the `mtime`
638 | * field from `stat` on Unix and `ftLastWriteTime` on Windows. This may not
639 | * be available on all platforms.
640 | */
641 | modified: number | null;
642 | /** The last access time of the file. This corresponds to the `atime`
643 | * field from `stat` on Unix and `ftLastAccessTime` on Windows. This may not
644 | * be available on all platforms.
645 | */
646 | accessed: number | null;
647 | /** The last access time of the file. This corresponds to the `birthtime`
648 | * field from `stat` on Unix and `ftCreationTime` on Windows. This may not
649 | * be available on all platforms.
650 | */
651 | created: number | null;
652 | /** The underlying raw st_mode bits that contain the standard Unix permissions
653 | * for this file/directory. TODO Match behavior with Go on windows for mode.
654 | */
655 | mode: number | null;
656 | /** The file or directory name. */
657 | name: string | null;
658 | /** Returns whether this is info for a regular file. This result is mutually
659 | * exclusive to `FileInfo.isDirectory` and `FileInfo.isSymlink`.
660 | */
661 | isFile(): boolean;
662 | /** Returns whether this is info for a regular directory. This result is
663 | * mutually exclusive to `FileInfo.isFile` and `FileInfo.isSymlink`.
664 | */
665 | isDirectory(): boolean;
666 | /** Returns whether this is info for a symlink. This result is
667 | * mutually exclusive to `FileInfo.isFile` and `FileInfo.isDirectory`.
668 | */
669 | isSymlink(): boolean;
670 | }
671 |
672 | // @url js/read_dir.d.ts
673 |
674 | /** Reads the directory given by path and returns a list of file info
675 | * synchronously.
676 | *
677 | * const files = Deno.readDirSync("/");
678 | */
679 | export function readDirSync(path: string): FileInfo[];
680 | /** Reads the directory given by path and returns a list of file info.
681 | *
682 | * const files = await Deno.readDir("/");
683 | */
684 | export function readDir(path: string): Promise;
685 |
686 | // @url js/copy_file.d.ts
687 |
688 | /** Copies the contents of a file to another by name synchronously.
689 | * Creates a new file if target does not exists, and if target exists,
690 | * overwrites original content of the target file.
691 | *
692 | * It would also copy the permission of the original file
693 | * to the destination.
694 | *
695 | * Deno.copyFileSync("from.txt", "to.txt");
696 | */
697 | export function copyFileSync(from: string, to: string): void;
698 | /** Copies the contents of a file to another by name.
699 | *
700 | * Creates a new file if target does not exists, and if target exists,
701 | * overwrites original content of the target file.
702 | *
703 | * It would also copy the permission of the original file
704 | * to the destination.
705 | *
706 | * await Deno.copyFile("from.txt", "to.txt");
707 | */
708 | export function copyFile(from: string, to: string): Promise;
709 |
710 | // @url js/read_link.d.ts
711 |
712 | /** Returns the destination of the named symbolic link synchronously.
713 | *
714 | * const targetPath = Deno.readlinkSync("symlink/path");
715 | */
716 | export function readlinkSync(name: string): string;
717 | /** Returns the destination of the named symbolic link.
718 | *
719 | * const targetPath = await Deno.readlink("symlink/path");
720 | */
721 | export function readlink(name: string): Promise;
722 |
723 | // @url js/stat.d.ts
724 |
725 | interface StatResponse {
726 | isFile: boolean;
727 | isSymlink: boolean;
728 | len: number;
729 | modified: number;
730 | accessed: number;
731 | created: number;
732 | mode: number;
733 | hasMode: boolean;
734 | name: string | null;
735 | }
736 | /** Queries the file system for information on the path provided. If the given
737 | * path is a symlink information about the symlink will be returned.
738 | *
739 | * const fileInfo = await Deno.lstat("hello.txt");
740 | * assert(fileInfo.isFile());
741 | */
742 | export function lstat(filename: string): Promise;
743 | /** Queries the file system for information on the path provided synchronously.
744 | * If the given path is a symlink information about the symlink will be
745 | * returned.
746 | *
747 | * const fileInfo = Deno.lstatSync("hello.txt");
748 | * assert(fileInfo.isFile());
749 | */
750 | export function lstatSync(filename: string): FileInfo;
751 | /** Queries the file system for information on the path provided. `stat` Will
752 | * always follow symlinks.
753 | *
754 | * const fileInfo = await Deno.stat("hello.txt");
755 | * assert(fileInfo.isFile());
756 | */
757 | export function stat(filename: string): Promise;
758 | /** Queries the file system for information on the path provided synchronously.
759 | * `statSync` Will always follow symlinks.
760 | *
761 | * const fileInfo = Deno.statSync("hello.txt");
762 | * assert(fileInfo.isFile());
763 | */
764 | export function statSync(filename: string): FileInfo;
765 |
766 | // @url js/link.d.ts
767 |
768 | /** Synchronously creates `newname` as a hard link to `oldname`.
769 | *
770 | * Deno.linkSync("old/name", "new/name");
771 | */
772 | export function linkSync(oldname: string, newname: string): void;
773 | /** Creates `newname` as a hard link to `oldname`.
774 | *
775 | * await Deno.link("old/name", "new/name");
776 | */
777 | export function link(oldname: string, newname: string): Promise;
778 |
779 | // @url js/symlink.d.ts
780 |
781 | /** Synchronously creates `newname` as a symbolic link to `oldname`. The type
782 | * argument can be set to `dir` or `file` and is only available on Windows
783 | * (ignored on other platforms).
784 | *
785 | * Deno.symlinkSync("old/name", "new/name");
786 | */
787 | export function symlinkSync(
788 | oldname: string,
789 | newname: string,
790 | type?: string
791 | ): void;
792 | /** Creates `newname` as a symbolic link to `oldname`. The type argument can be
793 | * set to `dir` or `file` and is only available on Windows (ignored on other
794 | * platforms).
795 | *
796 | * await Deno.symlink("old/name", "new/name");
797 | */
798 | export function symlink(
799 | oldname: string,
800 | newname: string,
801 | type?: string
802 | ): Promise;
803 |
804 | // @url js/write_file.d.ts
805 |
806 | /** Options for writing to a file.
807 | * `perm` would change the file's permission if set.
808 | * `create` decides if the file should be created if not exists (default: true)
809 | * `append` decides if the file should be appended (default: false)
810 | */
811 | export interface WriteFileOptions {
812 | perm?: number;
813 | create?: boolean;
814 | append?: boolean;
815 | }
816 | /** Write a new file, with given filename and data synchronously.
817 | *
818 | * const encoder = new TextEncoder();
819 | * const data = encoder.encode("Hello world\n");
820 | * Deno.writeFileSync("hello.txt", data);
821 | */
822 | export function writeFileSync(
823 | filename: string,
824 | data: Uint8Array,
825 | options?: WriteFileOptions
826 | ): void;
827 | /** Write a new file, with given filename and data.
828 | *
829 | * const encoder = new TextEncoder();
830 | * const data = encoder.encode("Hello world\n");
831 | * await Deno.writeFile("hello.txt", data);
832 | */
833 | export function writeFile(
834 | filename: string,
835 | data: Uint8Array,
836 | options?: WriteFileOptions
837 | ): Promise;
838 |
839 | // @url js/error_stack.d.ts
840 |
841 | interface Location {
842 | /** The full url for the module, e.g. `file://some/file.ts` or
843 | * `https://some/file.ts`. */
844 | filename: string;
845 | /** The line number in the file. It is assumed to be 1-indexed. */
846 | line: number;
847 | /** The column number in the file. It is assumed to be 1-indexed. */
848 | column: number;
849 | }
850 | /** Given a current location in a module, lookup the source location and
851 | * return it.
852 | *
853 | * When Deno transpiles code, it keep source maps of the transpiled code. This
854 | * function can be used to lookup the original location. This is automatically
855 | * done when accessing the `.stack` of an error, or when an uncaught error is
856 | * logged. This function can be used to perform the lookup for creating better
857 | * error handling.
858 | *
859 | * **Note:** `line` and `column` are 1 indexed, which matches display
860 | * expectations, but is not typical of most index numbers in Deno.
861 | *
862 | * An example:
863 | *
864 | * const orig = Deno.applySourceMap({
865 | * location: "file://my/module.ts",
866 | * line: 5,
867 | * column: 15
868 | * });
869 | * console.log(`${orig.filename}:${orig.line}:${orig.column}`);
870 | *
871 | */
872 | export function applySourceMap(location: Location): Location;
873 |
874 | // @url js/errors.d.ts
875 |
876 | /** A Deno specific error. The `kind` property is set to a specific error code
877 | * which can be used to in application logic.
878 | *
879 | * try {
880 | * somethingThatMightThrow();
881 | * } catch (e) {
882 | * if (
883 | * e instanceof Deno.DenoError &&
884 | * e.kind === Deno.ErrorKind.Overflow
885 | * ) {
886 | * console.error("Overflow error!");
887 | * }
888 | * }
889 | *
890 | */
891 | export class DenoError extends Error {
892 | readonly kind: T;
893 | constructor(kind: T, msg: string);
894 | }
895 | export enum ErrorKind {
896 | NoError = 0,
897 | NotFound = 1,
898 | PermissionDenied = 2,
899 | ConnectionRefused = 3,
900 | ConnectionReset = 4,
901 | ConnectionAborted = 5,
902 | NotConnected = 6,
903 | AddrInUse = 7,
904 | AddrNotAvailable = 8,
905 | BrokenPipe = 9,
906 | AlreadyExists = 10,
907 | WouldBlock = 11,
908 | InvalidInput = 12,
909 | InvalidData = 13,
910 | TimedOut = 14,
911 | Interrupted = 15,
912 | WriteZero = 16,
913 | Other = 17,
914 | UnexpectedEof = 18,
915 | BadResource = 19,
916 | CommandFailed = 20,
917 | EmptyHost = 21,
918 | IdnaError = 22,
919 | InvalidPort = 23,
920 | InvalidIpv4Address = 24,
921 | InvalidIpv6Address = 25,
922 | InvalidDomainCharacter = 26,
923 | RelativeUrlWithoutBase = 27,
924 | RelativeUrlWithCannotBeABaseBase = 28,
925 | SetHostOnCannotBeABaseUrl = 29,
926 | Overflow = 30,
927 | HttpUser = 31,
928 | HttpClosed = 32,
929 | HttpCanceled = 33,
930 | HttpParse = 34,
931 | HttpOther = 35,
932 | TooLarge = 36,
933 | InvalidUri = 37,
934 | InvalidSeekMode = 38,
935 | OpNotAvailable = 39,
936 | WorkerInitFailed = 40,
937 | UnixError = 41,
938 | NoAsyncSupport = 42,
939 | NoSyncSupport = 43,
940 | ImportMapError = 44,
941 | InvalidPath = 45,
942 | ImportPrefixMissing = 46,
943 | UnsupportedFetchScheme = 47,
944 | TooManyRedirects = 48,
945 | Diagnostic = 49,
946 | JSError = 50
947 | }
948 |
949 | // @url js/permissions.d.ts
950 | /** Permissions as granted by the caller
951 | * See: https://w3c.github.io/permissions/#permission-registry
952 | */
953 | export type PermissionName =
954 | | "run"
955 | | "read"
956 | | "write"
957 | | "net"
958 | | "env"
959 | | "hrtime";
960 | /** https://w3c.github.io/permissions/#status-of-a-permission */
961 | export type PermissionState = "granted" | "denied" | "prompt";
962 | interface RunPermissionDescriptor {
963 | name: "run";
964 | }
965 | interface ReadWritePermissionDescriptor {
966 | name: "read" | "write";
967 | path?: string;
968 | }
969 | interface NetPermissionDescriptor {
970 | name: "net";
971 | url?: string;
972 | }
973 | interface EnvPermissionDescriptor {
974 | name: "env";
975 | }
976 | interface HrtimePermissionDescriptor {
977 | name: "hrtime";
978 | }
979 | /** See: https://w3c.github.io/permissions/#permission-descriptor */
980 | type PermissionDescriptor =
981 | | RunPermissionDescriptor
982 | | ReadWritePermissionDescriptor
983 | | NetPermissionDescriptor
984 | | EnvPermissionDescriptor
985 | | HrtimePermissionDescriptor;
986 |
987 | export class Permissions {
988 | /** Queries the permission.
989 | * const status = await Deno.permissions.query({ name: "read", path: "/etc" });
990 | * if (status.state === "granted") {
991 | * data = await Deno.readFile("/etc/passwd");
992 | * }
993 | */
994 | query(d: PermissionDescriptor): Promise;
995 | /** Revokes the permission.
996 | * const status = await Deno.permissions.revoke({ name: "run" });
997 | * assert(status.state !== "granted")
998 | */
999 | revoke(d: PermissionDescriptor): Promise;
1000 | }
1001 | export const permissions: Permissions;
1002 |
1003 | /** https://w3c.github.io/permissions/#permissionstatus */
1004 | export class PermissionStatus {
1005 | state: PermissionState;
1006 | constructor(state: PermissionState);
1007 | }
1008 |
1009 | // @url js/truncate.d.ts
1010 |
1011 | /** Truncates or extends the specified file synchronously, updating the size of
1012 | * this file to become size.
1013 | *
1014 | * Deno.truncateSync("hello.txt", 10);
1015 | */
1016 | export function truncateSync(name: string, len?: number): void;
1017 | /**
1018 | * Truncates or extends the specified file, updating the size of this file to
1019 | * become size.
1020 | *
1021 | * await Deno.truncate("hello.txt", 10);
1022 | */
1023 | export function truncate(name: string, len?: number): Promise;
1024 |
1025 | // @url js/net.d.ts
1026 |
1027 | type Transport = "tcp";
1028 | interface Addr {
1029 | transport: Transport;
1030 | address: string;
1031 | }
1032 |
1033 | /** A Listener is a generic network listener for stream-oriented protocols. */
1034 | export interface Listener extends AsyncIterator {
1035 | /** Waits for and resolves to the next connection to the `Listener`. */
1036 | accept(): Promise;
1037 | /** Close closes the listener. Any pending accept promises will be rejected
1038 | * with errors.
1039 | */
1040 | close(): void;
1041 | /** Return the address of the `Listener`. */
1042 | addr(): Addr;
1043 | [Symbol.asyncIterator](): AsyncIterator;
1044 | }
1045 | export interface Conn extends Reader, Writer, Closer {
1046 | /** The local address of the connection. */
1047 | localAddr: string;
1048 | /** The remote address of the connection. */
1049 | remoteAddr: string;
1050 | /** The resource ID of the connection. */
1051 | rid: number;
1052 | /** Shuts down (`shutdown(2)`) the reading side of the TCP connection. Most
1053 | * callers should just use `close()`.
1054 | */
1055 | closeRead(): void;
1056 | /** Shuts down (`shutdown(2)`) the writing side of the TCP connection. Most
1057 | * callers should just use `close()`.
1058 | */
1059 | closeWrite(): void;
1060 | }
1061 |
1062 | export interface ListenOptions {
1063 | port: number;
1064 | hostname?: string;
1065 | transport?: Transport;
1066 | }
1067 |
1068 | /** Listen announces on the local transport address.
1069 | *
1070 | * @param options
1071 | * @param options.port The port to connect to. (Required.)
1072 | * @param options.hostname A literal IP address or host name that can be
1073 | * resolved to an IP address. If not specified, defaults to 0.0.0.0
1074 | * @param options.transport Defaults to "tcp". Later we plan to add "tcp4",
1075 | * "tcp6", "udp", "udp4", "udp6", "ip", "ip4", "ip6", "unix", "unixgram" and
1076 | * "unixpacket".
1077 | *
1078 | * Examples:
1079 | *
1080 | * listen({ port: 80 })
1081 | * listen({ hostname: "192.0.2.1", port: 80 })
1082 | * listen({ hostname: "[2001:db8::1]", port: 80 });
1083 | * listen({ hostname: "golang.org", port: 80, transport: "tcp" })
1084 | */
1085 | export function listen(options: ListenOptions): Listener;
1086 |
1087 | export interface ListenTLSOptions {
1088 | port: number;
1089 | hostname?: string;
1090 | transport?: Transport;
1091 | certFile: string;
1092 | keyFile: string;
1093 | }
1094 |
1095 | /** Listen announces on the local transport address over TLS (transport layer security).
1096 | *
1097 | * @param options
1098 | * @param options.port The port to connect to. (Required.)
1099 | * @param options.hostname A literal IP address or host name that can be
1100 | * resolved to an IP address. If not specified, defaults to 0.0.0.0
1101 | * @param options.certFile Server certificate file
1102 | * @param options.keyFile Server public key file
1103 | *
1104 | * Examples:
1105 | *
1106 | * Deno.listenTLS({ port: 443, certFile: "./my_server.crt", keyFile: "./my_server.key" })
1107 | */
1108 | export function listenTLS(options: ListenTLSOptions): Listener;
1109 |
1110 | export interface DialOptions {
1111 | port: number;
1112 | hostname?: string;
1113 | transport?: Transport;
1114 | }
1115 |
1116 | /** Dial connects to the address on the named transport.
1117 | *
1118 | * @param options
1119 | * @param options.port The port to connect to. (Required.)
1120 | * @param options.hostname A literal IP address or host name that can be
1121 | * resolved to an IP address. If not specified, defaults to 127.0.0.1
1122 | * @param options.transport Defaults to "tcp". Later we plan to add "tcp4",
1123 | * "tcp6", "udp", "udp4", "udp6", "ip", "ip4", "ip6", "unix", "unixgram" and
1124 | * "unixpacket".
1125 | *
1126 | * Examples:
1127 | *
1128 | * dial({ port: 80 })
1129 | * dial({ hostname: "192.0.2.1", port: 80 })
1130 | * dial({ hostname: "[2001:db8::1]", port: 80 });
1131 | * dial({ hostname: "golang.org", port: 80, transport: "tcp" })
1132 | */
1133 | export function dial(options: DialOptions): Promise;
1134 |
1135 | export interface DialTLSOptions {
1136 | port: number;
1137 | hostname?: string;
1138 | certFile?: string;
1139 | }
1140 |
1141 | /**
1142 | * dialTLS establishes a secure connection over TLS (transport layer security).
1143 | */
1144 | export function dialTLS(options: DialTLSOptions): Promise;
1145 |
1146 | // @url js/metrics.d.ts
1147 | export interface Metrics {
1148 | opsDispatched: number;
1149 | opsCompleted: number;
1150 | bytesSentControl: number;
1151 | bytesSentData: number;
1152 | bytesReceived: number;
1153 | }
1154 | /** Receive metrics from the privileged side of Deno.
1155 | *
1156 | * > console.table(Deno.metrics())
1157 | * ┌──────────────────┬────────┐
1158 | * │ (index) │ Values │
1159 | * ├──────────────────┼────────┤
1160 | * │ opsDispatched │ 9 │
1161 | * │ opsCompleted │ 9 │
1162 | * │ bytesSentControl │ 504 │
1163 | * │ bytesSentData │ 0 │
1164 | * │ bytesReceived │ 856 │
1165 | * └──────────────────┴────────┘
1166 | */
1167 | export function metrics(): Metrics;
1168 |
1169 | // @url js/resources.d.ts
1170 |
1171 | interface ResourceMap {
1172 | [rid: number]: string;
1173 | }
1174 | /** Returns a map of open _file like_ resource ids along with their string
1175 | * representation.
1176 | */
1177 | export function resources(): ResourceMap;
1178 |
1179 | // @url js/process.d.ts
1180 |
1181 | /** How to handle subprocess stdio.
1182 | *
1183 | * "inherit" The default if unspecified. The child inherits from the
1184 | * corresponding parent descriptor.
1185 | *
1186 | * "piped" A new pipe should be arranged to connect the parent and child
1187 | * subprocesses.
1188 | *
1189 | * "null" This stream will be ignored. This is the equivalent of attaching the
1190 | * stream to /dev/null.
1191 | */
1192 | type ProcessStdio = "inherit" | "piped" | "null";
1193 | export interface RunOptions {
1194 | args: string[];
1195 | cwd?: string;
1196 | env?: {
1197 | [key: string]: string;
1198 | };
1199 | stdout?: ProcessStdio | number;
1200 | stderr?: ProcessStdio | number;
1201 | stdin?: ProcessStdio | number;
1202 | }
1203 | /** Send a signal to process under given PID. Unix only at this moment.
1204 | * If pid is negative, the signal will be sent to the process group identified
1205 | * by -pid.
1206 | * Requires the `--allow-run` flag.
1207 | */
1208 | export function kill(pid: number, signo: number): void;
1209 | export class Process {
1210 | readonly rid: number;
1211 | readonly pid: number;
1212 | readonly stdin?: WriteCloser;
1213 | readonly stdout?: ReadCloser;
1214 | readonly stderr?: ReadCloser;
1215 | status(): Promise;
1216 | /** Buffer the stdout and return it as Uint8Array after EOF.
1217 | * You must set stdout to "piped" when creating the process.
1218 | * This calls close() on stdout after its done.
1219 | */
1220 | output(): Promise;
1221 | /** Buffer the stderr and return it as Uint8Array after EOF.
1222 | * You must set stderr to "piped" when creating the process.
1223 | * This calls close() on stderr after its done.
1224 | */
1225 | stderrOutput(): Promise;
1226 | close(): void;
1227 | kill(signo: number): void;
1228 | }
1229 | export interface ProcessStatus {
1230 | success: boolean;
1231 | code?: number;
1232 | signal?: number;
1233 | }
1234 | /**
1235 | * Spawns new subprocess.
1236 | *
1237 | * Subprocess uses same working directory as parent process unless `opt.cwd`
1238 | * is specified.
1239 | *
1240 | * Environmental variables for subprocess can be specified using `opt.env`
1241 | * mapping.
1242 | *
1243 | * By default subprocess inherits stdio of parent process. To change that
1244 | * `opt.stdout`, `opt.stderr` and `opt.stdin` can be specified independently -
1245 | * they can be set to either `ProcessStdio` or `rid` of open file.
1246 | */
1247 | export function run(opt: RunOptions): Process;
1248 | enum LinuxSignal {
1249 | SIGHUP = 1,
1250 | SIGINT = 2,
1251 | SIGQUIT = 3,
1252 | SIGILL = 4,
1253 | SIGTRAP = 5,
1254 | SIGABRT = 6,
1255 | SIGBUS = 7,
1256 | SIGFPE = 8,
1257 | SIGKILL = 9,
1258 | SIGUSR1 = 10,
1259 | SIGSEGV = 11,
1260 | SIGUSR2 = 12,
1261 | SIGPIPE = 13,
1262 | SIGALRM = 14,
1263 | SIGTERM = 15,
1264 | SIGSTKFLT = 16,
1265 | SIGCHLD = 17,
1266 | SIGCONT = 18,
1267 | SIGSTOP = 19,
1268 | SIGTSTP = 20,
1269 | SIGTTIN = 21,
1270 | SIGTTOU = 22,
1271 | SIGURG = 23,
1272 | SIGXCPU = 24,
1273 | SIGXFSZ = 25,
1274 | SIGVTALRM = 26,
1275 | SIGPROF = 27,
1276 | SIGWINCH = 28,
1277 | SIGIO = 29,
1278 | SIGPWR = 30,
1279 | SIGSYS = 31
1280 | }
1281 | enum MacOSSignal {
1282 | SIGHUP = 1,
1283 | SIGINT = 2,
1284 | SIGQUIT = 3,
1285 | SIGILL = 4,
1286 | SIGTRAP = 5,
1287 | SIGABRT = 6,
1288 | SIGEMT = 7,
1289 | SIGFPE = 8,
1290 | SIGKILL = 9,
1291 | SIGBUS = 10,
1292 | SIGSEGV = 11,
1293 | SIGSYS = 12,
1294 | SIGPIPE = 13,
1295 | SIGALRM = 14,
1296 | SIGTERM = 15,
1297 | SIGURG = 16,
1298 | SIGSTOP = 17,
1299 | SIGTSTP = 18,
1300 | SIGCONT = 19,
1301 | SIGCHLD = 20,
1302 | SIGTTIN = 21,
1303 | SIGTTOU = 22,
1304 | SIGIO = 23,
1305 | SIGXCPU = 24,
1306 | SIGXFSZ = 25,
1307 | SIGVTALRM = 26,
1308 | SIGPROF = 27,
1309 | SIGWINCH = 28,
1310 | SIGINFO = 29,
1311 | SIGUSR1 = 30,
1312 | SIGUSR2 = 31
1313 | }
1314 | /** Signals numbers. This is platform dependent.
1315 | */
1316 | export const Signal: typeof MacOSSignal | typeof LinuxSignal;
1317 | export {};
1318 |
1319 | // @url js/console.d.ts
1320 |
1321 | type ConsoleOptions = Partial<{
1322 | showHidden: boolean;
1323 | depth: number;
1324 | colors: boolean;
1325 | indentLevel: number;
1326 | }>;
1327 | /** A symbol which can be used as a key for a custom method which will be called
1328 | * when `Deno.inspect()` is called, or when the object is logged to the console.
1329 | */
1330 | export const customInspect: unique symbol;
1331 | /**
1332 | * `inspect()` converts input into string that has the same format
1333 | * as printed by `console.log(...)`;
1334 | */
1335 | export function inspect(value: unknown, options?: ConsoleOptions): string;
1336 |
1337 | // @url js/build.d.ts
1338 |
1339 | export type OperatingSystem = "mac" | "win" | "linux";
1340 | export type Arch = "x64" | "arm64";
1341 | /** Build related information */
1342 | interface BuildInfo {
1343 | /** The CPU architecture. */
1344 | arch: Arch;
1345 | /** The operating system. */
1346 | os: OperatingSystem;
1347 | }
1348 | export const build: BuildInfo;
1349 |
1350 | // @url js/version.d.ts
1351 |
1352 | interface Version {
1353 | deno: string;
1354 | v8: string;
1355 | typescript: string;
1356 | }
1357 | export const version: Version;
1358 | export {};
1359 |
1360 | // @url js/deno.d.ts
1361 |
1362 | export const args: string[];
1363 | }
1364 | // @url js/globals.ts
1365 |
1366 | declare interface Window {
1367 | window: Window & typeof globalThis;
1368 | atob: typeof textEncoding.atob;
1369 | btoa: typeof textEncoding.btoa;
1370 | fetch: typeof fetchTypes.fetch;
1371 | clearTimeout: typeof timers.clearTimeout;
1372 | clearInterval: typeof timers.clearInterval;
1373 | console: consoleTypes.Console;
1374 | setTimeout: typeof timers.setTimeout;
1375 | setInterval: typeof timers.setInterval;
1376 | location: domTypes.Location;
1377 | onload: Function | undefined;
1378 | onunload: Function | undefined;
1379 | crypto: Crypto;
1380 | Blob: typeof blob.DenoBlob;
1381 | File: domTypes.DomFileConstructor;
1382 | CustomEvent: typeof customEvent.CustomEvent;
1383 | Event: typeof event.Event;
1384 | EventTarget: typeof eventTarget.EventTarget;
1385 | URL: typeof url.URL;
1386 | URLSearchParams: typeof urlSearchParams.URLSearchParams;
1387 | Headers: domTypes.HeadersConstructor;
1388 | FormData: domTypes.FormDataConstructor;
1389 | TextEncoder: typeof textEncoding.TextEncoder;
1390 | TextDecoder: typeof textEncoding.TextDecoder;
1391 | Request: domTypes.RequestConstructor;
1392 | Response: typeof fetchTypes.Response;
1393 | performance: performanceUtil.Performance;
1394 | onmessage: (e: { data: any }) => void;
1395 | workerMain: typeof workers.workerMain;
1396 | workerClose: typeof workers.workerClose;
1397 | postMessage: typeof workers.postMessage;
1398 | Worker: typeof workers.WorkerImpl;
1399 | addEventListener: (
1400 | type: string,
1401 | callback: (event: domTypes.Event) => void | null,
1402 | options?: boolean | domTypes.AddEventListenerOptions | undefined
1403 | ) => void;
1404 | dispatchEvent: (event: domTypes.Event) => boolean;
1405 | removeEventListener: (
1406 | type: string,
1407 | callback: (event: domTypes.Event) => void | null,
1408 | options?: boolean | domTypes.EventListenerOptions | undefined
1409 | ) => void;
1410 | queueMicrotask: (task: () => void) => void;
1411 | Deno: typeof Deno;
1412 | }
1413 |
1414 | declare const window: Window & typeof globalThis;
1415 | declare const atob: typeof textEncoding.atob;
1416 | declare const btoa: typeof textEncoding.btoa;
1417 | declare const fetch: typeof fetchTypes.fetch;
1418 | declare const clearTimeout: typeof timers.clearTimeout;
1419 | declare const clearInterval: typeof timers.clearInterval;
1420 | declare const console: consoleTypes.Console;
1421 | declare const setTimeout: typeof timers.setTimeout;
1422 | declare const setInterval: typeof timers.setInterval;
1423 | declare const location: domTypes.Location;
1424 | declare const onload: Function | undefined;
1425 | declare const onunload: Function | undefined;
1426 | declare const crypto: Crypto;
1427 | declare const Blob: typeof blob.DenoBlob;
1428 | declare const File: domTypes.DomFileConstructor;
1429 | declare const CustomEventInit: typeof customEvent.CustomEventInit;
1430 | declare const CustomEvent: typeof customEvent.CustomEvent;
1431 | declare const EventInit: typeof event.EventInit;
1432 | declare const Event: typeof event.Event;
1433 | declare const EventListener: typeof eventTarget.EventListener;
1434 | declare const EventTarget: typeof eventTarget.EventTarget;
1435 | declare const URL: typeof url.URL;
1436 | declare const URLSearchParams: typeof urlSearchParams.URLSearchParams;
1437 | declare const Headers: domTypes.HeadersConstructor;
1438 | declare const FormData: domTypes.FormDataConstructor;
1439 | declare const TextEncoder: typeof textEncoding.TextEncoder;
1440 | declare const TextDecoder: typeof textEncoding.TextDecoder;
1441 | declare const Request: domTypes.RequestConstructor;
1442 | declare const Response: typeof fetchTypes.Response;
1443 | declare const performance: performanceUtil.Performance;
1444 | declare let onmessage: (e: { data: any }) => void;
1445 | declare const workerMain: typeof workers.workerMain;
1446 | declare const workerClose: typeof workers.workerClose;
1447 | declare const postMessage: typeof workers.postMessage;
1448 | declare const Worker: typeof workers.WorkerImpl;
1449 | declare const addEventListener: (
1450 | type: string,
1451 | callback: (event: domTypes.Event) => void | null,
1452 | options?: boolean | domTypes.AddEventListenerOptions | undefined
1453 | ) => void;
1454 | declare const dispatchEvent: (event: domTypes.Event) => boolean;
1455 | declare const removeEventListener: (
1456 | type: string,
1457 | callback: (event: domTypes.Event) => void | null,
1458 | options?: boolean | domTypes.EventListenerOptions | undefined
1459 | ) => void;
1460 |
1461 | declare type Blob = domTypes.Blob;
1462 | declare type Body = domTypes.Body;
1463 | declare type File = domTypes.DomFile;
1464 | declare type CustomEventInit = domTypes.CustomEventInit;
1465 | declare type CustomEvent = domTypes.CustomEvent;
1466 | declare type EventInit = domTypes.EventInit;
1467 | declare type Event = domTypes.Event;
1468 | declare type EventListener = domTypes.EventListener;
1469 | declare type EventTarget = domTypes.EventTarget;
1470 | declare type URL = url.URL;
1471 | declare type URLSearchParams = domTypes.URLSearchParams;
1472 | declare type Headers = domTypes.Headers;
1473 | declare type FormData = domTypes.FormData;
1474 | declare type TextEncoder = textEncoding.TextEncoder;
1475 | declare type TextDecoder = textEncoding.TextDecoder;
1476 | declare type Request = domTypes.Request;
1477 | declare type Response = domTypes.Response;
1478 | declare type Worker = workers.Worker;
1479 |
1480 | declare interface ImportMeta {
1481 | url: string;
1482 | main: boolean;
1483 | }
1484 |
1485 | declare interface Crypto {
1486 | readonly subtle: null;
1487 | getRandomValues: <
1488 | T extends
1489 | | Int8Array
1490 | | Uint8Array
1491 | | Uint8ClampedArray
1492 | | Int16Array
1493 | | Uint16Array
1494 | | Int32Array
1495 | | Uint32Array
1496 | >(
1497 | typedArray: T
1498 | ) => T;
1499 | }
1500 |
1501 | declare namespace domTypes {
1502 | // @url js/dom_types.d.ts
1503 |
1504 | export type BufferSource = ArrayBufferView | ArrayBuffer;
1505 | export type HeadersInit =
1506 | | Headers
1507 | | Array<[string, string]>
1508 | | Record;
1509 | export type URLSearchParamsInit =
1510 | | string
1511 | | string[][]
1512 | | Record;
1513 | type BodyInit =
1514 | | Blob
1515 | | BufferSource
1516 | | FormData
1517 | | URLSearchParams
1518 | | ReadableStream
1519 | | string;
1520 | export type RequestInfo = Request | string;
1521 | type ReferrerPolicy =
1522 | | ""
1523 | | "no-referrer"
1524 | | "no-referrer-when-downgrade"
1525 | | "origin-only"
1526 | | "origin-when-cross-origin"
1527 | | "unsafe-url";
1528 | export type BlobPart = BufferSource | Blob | string;
1529 | export type FormDataEntryValue = DomFile | string;
1530 | export interface DomIterable {
1531 | keys(): IterableIterator;
1532 | values(): IterableIterator;
1533 | entries(): IterableIterator<[K, V]>;
1534 | [Symbol.iterator](): IterableIterator<[K, V]>;
1535 | forEach(
1536 | callback: (value: V, key: K, parent: this) => void,
1537 | thisArg?: any
1538 | ): void;
1539 | }
1540 | type EndingType = "transparent" | "native";
1541 | export interface BlobPropertyBag {
1542 | type?: string;
1543 | ending?: EndingType;
1544 | }
1545 | interface AbortSignalEventMap {
1546 | abort: ProgressEvent;
1547 | }
1548 | export enum NodeType {
1549 | ELEMENT_NODE = 1,
1550 | TEXT_NODE = 3,
1551 | DOCUMENT_FRAGMENT_NODE = 11
1552 | }
1553 | export const eventTargetHost: unique symbol;
1554 | export const eventTargetListeners: unique symbol;
1555 | export const eventTargetMode: unique symbol;
1556 | export const eventTargetNodeType: unique symbol;
1557 | export interface EventTarget {
1558 | [eventTargetHost]: EventTarget | null;
1559 | [eventTargetListeners]: { [type in string]: EventListener[] };
1560 | [eventTargetMode]: string;
1561 | [eventTargetNodeType]: NodeType;
1562 | addEventListener(
1563 | type: string,
1564 | callback: (event: Event) => void | null,
1565 | options?: boolean | AddEventListenerOptions
1566 | ): void;
1567 | dispatchEvent(event: Event): boolean;
1568 | removeEventListener(
1569 | type: string,
1570 | callback?: (event: Event) => void | null,
1571 | options?: EventListenerOptions | boolean
1572 | ): void;
1573 | }
1574 | export interface ProgressEventInit extends EventInit {
1575 | lengthComputable?: boolean;
1576 | loaded?: number;
1577 | total?: number;
1578 | }
1579 | export interface URLSearchParams extends DomIterable {
1580 | /**
1581 | * Appends a specified key/value pair as a new search parameter.
1582 | */
1583 | append(name: string, value: string): void;
1584 | /**
1585 | * Deletes the given search parameter, and its associated value,
1586 | * from the list of all search parameters.
1587 | */
1588 | delete(name: string): void;
1589 | /**
1590 | * Returns the first value associated to the given search parameter.
1591 | */
1592 | get(name: string): string | null;
1593 | /**
1594 | * Returns all the values association with a given search parameter.
1595 | */
1596 | getAll(name: string): string[];
1597 | /**
1598 | * Returns a Boolean indicating if such a search parameter exists.
1599 | */
1600 | has(name: string): boolean;
1601 | /**
1602 | * Sets the value associated to a given search parameter to the given value.
1603 | * If there were several values, delete the others.
1604 | */
1605 | set(name: string, value: string): void;
1606 | /**
1607 | * Sort all key/value pairs contained in this object in place
1608 | * and return undefined. The sort order is according to Unicode
1609 | * code points of the keys.
1610 | */
1611 | sort(): void;
1612 | /**
1613 | * Returns a query string suitable for use in a URL.
1614 | */
1615 | toString(): string;
1616 | /**
1617 | * Iterates over each name-value pair in the query
1618 | * and invokes the given function.
1619 | */
1620 | forEach(
1621 | callbackfn: (value: string, key: string, parent: this) => void,
1622 | thisArg?: any
1623 | ): void;
1624 | }
1625 | export interface EventListener {
1626 | handleEvent(event: Event): void;
1627 | readonly callback: (event: Event) => void | null;
1628 | readonly options: boolean | AddEventListenerOptions;
1629 | }
1630 | export interface EventInit {
1631 | bubbles?: boolean;
1632 | cancelable?: boolean;
1633 | composed?: boolean;
1634 | }
1635 | export interface CustomEventInit extends EventInit {
1636 | detail?: any;
1637 | }
1638 | export enum EventPhase {
1639 | NONE = 0,
1640 | CAPTURING_PHASE = 1,
1641 | AT_TARGET = 2,
1642 | BUBBLING_PHASE = 3
1643 | }
1644 | export interface EventPath {
1645 | item: EventTarget;
1646 | itemInShadowTree: boolean;
1647 | relatedTarget: EventTarget | null;
1648 | rootOfClosedTree: boolean;
1649 | slotInClosedTree: boolean;
1650 | target: EventTarget | null;
1651 | touchTargetList: EventTarget[];
1652 | }
1653 | export interface Event {
1654 | readonly type: string;
1655 | target: EventTarget | null;
1656 | currentTarget: EventTarget | null;
1657 | composedPath(): EventPath[];
1658 | eventPhase: number;
1659 | stopPropagation(): void;
1660 | stopImmediatePropagation(): void;
1661 | readonly bubbles: boolean;
1662 | readonly cancelable: boolean;
1663 | preventDefault(): void;
1664 | readonly defaultPrevented: boolean;
1665 | readonly composed: boolean;
1666 | isTrusted: boolean;
1667 | readonly timeStamp: Date;
1668 | dispatched: boolean;
1669 | readonly initialized: boolean;
1670 | inPassiveListener: boolean;
1671 | cancelBubble: boolean;
1672 | cancelBubbleImmediately: boolean;
1673 | path: EventPath[];
1674 | relatedTarget: EventTarget | null;
1675 | }
1676 | export interface CustomEvent extends Event {
1677 | readonly detail: any;
1678 | initCustomEvent(
1679 | type: string,
1680 | bubbles?: boolean,
1681 | cancelable?: boolean,
1682 | detail?: any | null
1683 | ): void;
1684 | }
1685 | export interface DomFile extends Blob {
1686 | readonly lastModified: number;
1687 | readonly name: string;
1688 | }
1689 | export interface DomFileConstructor {
1690 | new (
1691 | bits: BlobPart[],
1692 | filename: string,
1693 | options?: FilePropertyBag
1694 | ): DomFile;
1695 | prototype: DomFile;
1696 | }
1697 | export interface FilePropertyBag extends BlobPropertyBag {
1698 | lastModified?: number;
1699 | }
1700 | interface ProgressEvent extends Event {
1701 | readonly lengthComputable: boolean;
1702 | readonly loaded: number;
1703 | readonly total: number;
1704 | }
1705 | export interface EventListenerOptions {
1706 | capture: boolean;
1707 | }
1708 | export interface AddEventListenerOptions extends EventListenerOptions {
1709 | once: boolean;
1710 | passive: boolean;
1711 | }
1712 | interface AbortSignal extends EventTarget {
1713 | readonly aborted: boolean;
1714 | onabort: ((this: AbortSignal, ev: ProgressEvent) => any) | null;
1715 | addEventListener(
1716 | type: K,
1717 | listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any,
1718 | options?: boolean | AddEventListenerOptions
1719 | ): void;
1720 | addEventListener(
1721 | type: string,
1722 | listener: EventListener,
1723 | options?: boolean | AddEventListenerOptions
1724 | ): void;
1725 | removeEventListener(
1726 | type: K,
1727 | listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any,
1728 | options?: boolean | EventListenerOptions
1729 | ): void;
1730 | removeEventListener(
1731 | type: string,
1732 | listener: EventListener,
1733 | options?: boolean | EventListenerOptions
1734 | ): void;
1735 | }
1736 | export interface ReadableStream {
1737 | readonly locked: boolean;
1738 | cancel(): Promise;
1739 | getReader(): ReadableStreamReader;
1740 | tee(): [ReadableStream, ReadableStream];
1741 | }
1742 | export interface ReadableStreamReader {
1743 | cancel(): Promise;
1744 | read(): Promise;
1745 | releaseLock(): void;
1746 | }
1747 | export interface FormData extends DomIterable {
1748 | append(name: string, value: string | Blob, fileName?: string): void;
1749 | delete(name: string): void;
1750 | get(name: string): FormDataEntryValue | null;
1751 | getAll(name: string): FormDataEntryValue[];
1752 | has(name: string): boolean;
1753 | set(name: string, value: string | Blob, fileName?: string): void;
1754 | }
1755 | export interface FormDataConstructor {
1756 | new (): FormData;
1757 | prototype: FormData;
1758 | }
1759 | /** A blob object represents a file-like object of immutable, raw data. */
1760 | export interface Blob {
1761 | /** The size, in bytes, of the data contained in the `Blob` object. */
1762 | readonly size: number;
1763 | /** A string indicating the media type of the data contained in the `Blob`.
1764 | * If the type is unknown, this string is empty.
1765 | */
1766 | readonly type: string;
1767 | /** Returns a new `Blob` object containing the data in the specified range of
1768 | * bytes of the source `Blob`.
1769 | */
1770 | slice(start?: number, end?: number, contentType?: string): Blob;
1771 | }
1772 | export interface Body {
1773 | /** A simple getter used to expose a `ReadableStream` of the body contents. */
1774 | readonly body: ReadableStream | null;
1775 | /** Stores a `Boolean` that declares whether the body has been used in a
1776 | * response yet.
1777 | */
1778 | readonly bodyUsed: boolean;
1779 | /** Takes a `Response` stream and reads it to completion. It returns a promise
1780 | * that resolves with an `ArrayBuffer`.
1781 | */
1782 | arrayBuffer(): Promise;
1783 | /** Takes a `Response` stream and reads it to completion. It returns a promise
1784 | * that resolves with a `Blob`.
1785 | */
1786 | blob(): Promise;
1787 | /** Takes a `Response` stream and reads it to completion. It returns a promise
1788 | * that resolves with a `FormData` object.
1789 | */
1790 | formData(): Promise;
1791 | /** Takes a `Response` stream and reads it to completion. It returns a promise
1792 | * that resolves with the result of parsing the body text as JSON.
1793 | */
1794 | json(): Promise;
1795 | /** Takes a `Response` stream and reads it to completion. It returns a promise
1796 | * that resolves with a `USVString` (text).
1797 | */
1798 | text(): Promise;
1799 | }
1800 | export interface Headers extends DomIterable {
1801 | /** Appends a new value onto an existing header inside a `Headers` object, or
1802 | * adds the header if it does not already exist.
1803 | */
1804 | append(name: string, value: string): void;
1805 | /** Deletes a header from a `Headers` object. */
1806 | delete(name: string): void;
1807 | /** Returns an iterator allowing to go through all key/value pairs
1808 | * contained in this Headers object. The both the key and value of each pairs
1809 | * are ByteString objects.
1810 | */
1811 | entries(): IterableIterator<[string, string]>;
1812 | /** Returns a `ByteString` sequence of all the values of a header within a
1813 | * `Headers` object with a given name.
1814 | */
1815 | get(name: string): string | null;
1816 | /** Returns a boolean stating whether a `Headers` object contains a certain
1817 | * header.
1818 | */
1819 | has(name: string): boolean;
1820 | /** Returns an iterator allowing to go through all keys contained in
1821 | * this Headers object. The keys are ByteString objects.
1822 | */
1823 | keys(): IterableIterator;
1824 | /** Sets a new value for an existing header inside a Headers object, or adds
1825 | * the header if it does not already exist.
1826 | */
1827 | set(name: string, value: string): void;
1828 | /** Returns an iterator allowing to go through all values contained in
1829 | * this Headers object. The values are ByteString objects.
1830 | */
1831 | values(): IterableIterator;
1832 | forEach(
1833 | callbackfn: (value: string, key: string, parent: this) => void,
1834 | thisArg?: any
1835 | ): void;
1836 | /** The Symbol.iterator well-known symbol specifies the default
1837 | * iterator for this Headers object
1838 | */
1839 | [Symbol.iterator](): IterableIterator<[string, string]>;
1840 | }
1841 | export interface HeadersConstructor {
1842 | new (init?: HeadersInit): Headers;
1843 | prototype: Headers;
1844 | }
1845 | type RequestCache =
1846 | | "default"
1847 | | "no-store"
1848 | | "reload"
1849 | | "no-cache"
1850 | | "force-cache"
1851 | | "only-if-cached";
1852 | type RequestCredentials = "omit" | "same-origin" | "include";
1853 | type RequestDestination =
1854 | | ""
1855 | | "audio"
1856 | | "audioworklet"
1857 | | "document"
1858 | | "embed"
1859 | | "font"
1860 | | "image"
1861 | | "manifest"
1862 | | "object"
1863 | | "paintworklet"
1864 | | "report"
1865 | | "script"
1866 | | "sharedworker"
1867 | | "style"
1868 | | "track"
1869 | | "video"
1870 | | "worker"
1871 | | "xslt";
1872 | type RequestMode = "navigate" | "same-origin" | "no-cors" | "cors";
1873 | type RequestRedirect = "follow" | "error" | "manual";
1874 | type ResponseType =
1875 | | "basic"
1876 | | "cors"
1877 | | "default"
1878 | | "error"
1879 | | "opaque"
1880 | | "opaqueredirect";
1881 | export interface RequestInit {
1882 | body?: BodyInit | null;
1883 | cache?: RequestCache;
1884 | credentials?: RequestCredentials;
1885 | headers?: HeadersInit;
1886 | integrity?: string;
1887 | keepalive?: boolean;
1888 | method?: string;
1889 | mode?: RequestMode;
1890 | redirect?: RequestRedirect;
1891 | referrer?: string;
1892 | referrerPolicy?: ReferrerPolicy;
1893 | signal?: AbortSignal | null;
1894 | window?: any;
1895 | }
1896 | export interface ResponseInit {
1897 | headers?: HeadersInit;
1898 | status?: number;
1899 | statusText?: string;
1900 | }
1901 | export interface RequestConstructor {
1902 | new (input: RequestInfo, init?: RequestInit): Request;
1903 | prototype: Request;
1904 | }
1905 | export interface Request extends Body {
1906 | /** Returns the cache mode associated with request, which is a string
1907 | * indicating how the the request will interact with the browser's cache when
1908 | * fetching.
1909 | */
1910 | readonly cache?: RequestCache;
1911 | /** Returns the credentials mode associated with request, which is a string
1912 | * indicating whether credentials will be sent with the request always, never,
1913 | * or only when sent to a same-origin URL.
1914 | */
1915 | readonly credentials?: RequestCredentials;
1916 | /** Returns the kind of resource requested by request, (e.g., `document` or
1917 | * `script`).
1918 | */
1919 | readonly destination?: RequestDestination;
1920 | /** Returns a Headers object consisting of the headers associated with
1921 | * request.
1922 | *
1923 | * Note that headers added in the network layer by the user agent
1924 | * will not be accounted for in this object, (e.g., the `Host` header).
1925 | */
1926 | readonly headers: Headers;
1927 | /** Returns request's subresource integrity metadata, which is a cryptographic
1928 | * hash of the resource being fetched. Its value consists of multiple hashes
1929 | * separated by whitespace. [SRI]
1930 | */
1931 | readonly integrity?: string;
1932 | /** Returns a boolean indicating whether or not request is for a history
1933 | * navigation (a.k.a. back-forward navigation).
1934 | */
1935 | readonly isHistoryNavigation?: boolean;
1936 | /** Returns a boolean indicating whether or not request is for a reload
1937 | * navigation.
1938 | */
1939 | readonly isReloadNavigation?: boolean;
1940 | /** Returns a boolean indicating whether or not request can outlive the global
1941 | * in which it was created.
1942 | */
1943 | readonly keepalive?: boolean;
1944 | /** Returns request's HTTP method, which is `GET` by default. */
1945 | readonly method: string;
1946 | /** Returns the mode associated with request, which is a string indicating
1947 | * whether the request will use CORS, or will be restricted to same-origin
1948 | * URLs.
1949 | */
1950 | readonly mode?: RequestMode;
1951 | /** Returns the redirect mode associated with request, which is a string
1952 | * indicating how redirects for the request will be handled during fetching.
1953 | *
1954 | * A request will follow redirects by default.
1955 | */
1956 | readonly redirect?: RequestRedirect;
1957 | /** Returns the referrer of request. Its value can be a same-origin URL if
1958 | * explicitly set in init, the empty string to indicate no referrer, and
1959 | * `about:client` when defaulting to the global's default.
1960 | *
1961 | * This is used during fetching to determine the value of the `Referer`
1962 | * header of the request being made.
1963 | */
1964 | readonly referrer?: string;
1965 | /** Returns the referrer policy associated with request. This is used during
1966 | * fetching to compute the value of the request's referrer.
1967 | */
1968 | readonly referrerPolicy?: ReferrerPolicy;
1969 | /** Returns the signal associated with request, which is an AbortSignal object
1970 | * indicating whether or not request has been aborted, and its abort event
1971 | * handler.
1972 | */
1973 | readonly signal?: AbortSignal;
1974 | /** Returns the URL of request as a string. */
1975 | readonly url: string;
1976 | clone(): Request;
1977 | }
1978 | export interface Response extends Body {
1979 | /** Contains the `Headers` object associated with the response. */
1980 | readonly headers: Headers;
1981 | /** Contains a boolean stating whether the response was successful (status in
1982 | * the range 200-299) or not.
1983 | */
1984 | readonly ok: boolean;
1985 | /** Indicates whether or not the response is the result of a redirect; that
1986 | * is, its URL list has more than one entry.
1987 | */
1988 | readonly redirected: boolean;
1989 | /** Contains the status code of the response (e.g., `200` for a success). */
1990 | readonly status: number;
1991 | /** Contains the status message corresponding to the status code (e.g., `OK`
1992 | * for `200`).
1993 | */
1994 | readonly statusText: string;
1995 | readonly trailer: Promise;
1996 | /** Contains the type of the response (e.g., `basic`, `cors`). */
1997 | readonly type: ResponseType;
1998 | /** Contains the URL of the response. */
1999 | readonly url: string;
2000 | /** Creates a clone of a `Response` object. */
2001 | clone(): Response;
2002 | }
2003 | export interface Location {
2004 | /**
2005 | * Returns a DOMStringList object listing the origins of the ancestor browsing
2006 | * contexts, from the parent browsing context to the top-level browsing
2007 | * context.
2008 | */
2009 | readonly ancestorOrigins: string[];
2010 | /**
2011 | * Returns the Location object's URL's fragment (includes leading "#" if
2012 | * non-empty).
2013 | * Can be set, to navigate to the same URL with a changed fragment (ignores
2014 | * leading "#").
2015 | */
2016 | hash: string;
2017 | /**
2018 | * Returns the Location object's URL's host and port (if different from the
2019 | * default port for the scheme). Can be set, to navigate to the same URL with
2020 | * a changed host and port.
2021 | */
2022 | host: string;
2023 | /**
2024 | * Returns the Location object's URL's host. Can be set, to navigate to the
2025 | * same URL with a changed host.
2026 | */
2027 | hostname: string;
2028 | /**
2029 | * Returns the Location object's URL. Can be set, to navigate to the given
2030 | * URL.
2031 | */
2032 | href: string;
2033 | /** Returns the Location object's URL's origin. */
2034 | readonly origin: string;
2035 | /**
2036 | * Returns the Location object's URL's path.
2037 | * Can be set, to navigate to the same URL with a changed path.
2038 | */
2039 | pathname: string;
2040 | /**
2041 | * Returns the Location object's URL's port.
2042 | * Can be set, to navigate to the same URL with a changed port.
2043 | */
2044 | port: string;
2045 | /**
2046 | * Returns the Location object's URL's scheme.
2047 | * Can be set, to navigate to the same URL with a changed scheme.
2048 | */
2049 | protocol: string;
2050 | /**
2051 | * Returns the Location object's URL's query (includes leading "?" if
2052 | * non-empty). Can be set, to navigate to the same URL with a changed query
2053 | * (ignores leading "?").
2054 | */
2055 | search: string;
2056 | /**
2057 | * Navigates to the given URL.
2058 | */
2059 | assign(url: string): void;
2060 | /**
2061 | * Reloads the current page.
2062 | */
2063 | reload(): void;
2064 | /** @deprecated */
2065 | reload(forcedReload: boolean): void;
2066 | /**
2067 | * Removes the current page from the session history and navigates to the
2068 | * given URL.
2069 | */
2070 | replace(url: string): void;
2071 | }
2072 | }
2073 |
2074 | declare namespace blob {
2075 | // @url js/blob.d.ts
2076 |
2077 | export const bytesSymbol: unique symbol;
2078 | export const blobBytesWeakMap: WeakMap;
2079 | export class DenoBlob implements domTypes.Blob {
2080 | private readonly [bytesSymbol];
2081 | readonly size: number;
2082 | readonly type: string;
2083 | /** A blob object represents a file-like object of immutable, raw data. */
2084 | constructor(
2085 | blobParts?: domTypes.BlobPart[],
2086 | options?: domTypes.BlobPropertyBag
2087 | );
2088 | slice(start?: number, end?: number, contentType?: string): DenoBlob;
2089 | }
2090 | }
2091 |
2092 | declare namespace consoleTypes {
2093 | // @url js/console.d.ts
2094 |
2095 | type ConsoleOptions = Partial<{
2096 | showHidden: boolean;
2097 | depth: number;
2098 | colors: boolean;
2099 | indentLevel: number;
2100 | }>;
2101 | export class CSI {
2102 | static kClear: string;
2103 | static kClearScreenDown: string;
2104 | }
2105 | const isConsoleInstance: unique symbol;
2106 | export class Console {
2107 | private printFunc;
2108 | indentLevel: number;
2109 | [isConsoleInstance]: boolean;
2110 | /** Writes the arguments to stdout */
2111 | log: (...args: unknown[]) => void;
2112 | /** Writes the arguments to stdout */
2113 | debug: (...args: unknown[]) => void;
2114 | /** Writes the arguments to stdout */
2115 | info: (...args: unknown[]) => void;
2116 | /** Writes the properties of the supplied `obj` to stdout */
2117 | dir: (
2118 | obj: unknown,
2119 | options?: Partial<{
2120 | showHidden: boolean;
2121 | depth: number;
2122 | colors: boolean;
2123 | indentLevel: number;
2124 | }>
2125 | ) => void;
2126 |
2127 | /** From MDN:
2128 | * Displays an interactive tree of the descendant elements of
2129 | * the specified XML/HTML element. If it is not possible to display
2130 | * as an element the JavaScript Object view is shown instead.
2131 | * The output is presented as a hierarchical listing of expandable
2132 | * nodes that let you see the contents of child nodes.
2133 | *
2134 | * Since we write to stdout, we can't display anything interactive
2135 | * we just fall back to `console.dir`.
2136 | */
2137 | dirxml: (
2138 | obj: unknown,
2139 | options?: Partial<{
2140 | showHidden: boolean;
2141 | depth: number;
2142 | colors: boolean;
2143 | indentLevel: number;
2144 | }>
2145 | ) => void;
2146 |
2147 | /** Writes the arguments to stdout */
2148 | warn: (...args: unknown[]) => void;
2149 | /** Writes the arguments to stdout */
2150 | error: (...args: unknown[]) => void;
2151 | /** Writes an error message to stdout if the assertion is `false`. If the
2152 | * assertion is `true`, nothing happens.
2153 | *
2154 | * ref: https://console.spec.whatwg.org/#assert
2155 | */
2156 | assert: (condition?: boolean, ...args: unknown[]) => void;
2157 | count: (label?: string) => void;
2158 | countReset: (label?: string) => void;
2159 | table: (data: unknown, properties?: string[] | undefined) => void;
2160 | time: (label?: string) => void;
2161 | timeLog: (label?: string, ...args: unknown[]) => void;
2162 | timeEnd: (label?: string) => void;
2163 | group: (...label: unknown[]) => void;
2164 | groupCollapsed: (...label: unknown[]) => void;
2165 | groupEnd: () => void;
2166 | clear: () => void;
2167 | trace: (...args: unknown[]) => void;
2168 | static [Symbol.hasInstance](instance: Console): boolean;
2169 | }
2170 | /** A symbol which can be used as a key for a custom method which will be called
2171 | * when `Deno.inspect()` is called, or when the object is logged to the console.
2172 | */
2173 | export const customInspect: unique symbol;
2174 | /**
2175 | * `inspect()` converts input into string that has the same format
2176 | * as printed by `console.log(...)`;
2177 | */
2178 | export function inspect(value: unknown, options?: ConsoleOptions): string;
2179 | }
2180 |
2181 | declare namespace event {
2182 | // @url js/event.d.ts
2183 |
2184 | export const eventAttributes: WeakMap