-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
lib.deno.shared_globals.d.ts
977 lines (872 loc) · 31.2 KB
/
lib.deno.shared_globals.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
// Documentation partially adapted from [MDN](https://developer.mozilla.org/),
// by Mozilla Contributors, which is licensed under CC-BY-SA 2.5.
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
/// <reference lib="deno.web" />
/// <reference lib="deno.fetch" />
declare namespace WebAssembly {
/**
* The `WebAssembly.CompileError` object indicates an error during WebAssembly decoding or validation.
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
*/
export class CompileError extends Error {
/** Creates a new `WebAssembly.CompileError` object. */
constructor();
}
/**
* A `WebAssembly.Global` object represents a global variable instance, accessible from
* both JavaScript and importable/exportable across one or more `WebAssembly.Module`
* instances. This allows dynamic linking of multiple modules.
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
*/
export class Global {
/** Creates a new `Global` object. */
constructor(descriptor: GlobalDescriptor, v?: any);
/**
* The value contained inside the global variable — this can be used to directly set
* and get the global's value.
*/
value: any;
/** Old-style method that returns the value contained inside the global variable. */
valueOf(): any;
}
/**
* A `WebAssembly.Instance` object is a stateful, executable instance of a `WebAssembly.Module`.
* Instance objects contain all the Exported WebAssembly functions that allow calling into
* WebAssembly code from JavaScript.
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
*/
export class Instance {
/** Creates a new Instance object. */
constructor(module: Module, importObject?: Imports);
/**
* Returns an object containing as its members all the functions exported from the
* WebAssembly module instance, to allow them to be accessed and used by JavaScript.
* Read-only.
*/
readonly exports: Exports;
}
/**
* The `WebAssembly.LinkError` object indicates an error during module instantiation
* (besides traps from the start function).
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
*/
export class LinkError extends Error {
/** Creates a new WebAssembly.LinkError object. */
constructor();
}
/**
* The `WebAssembly.Memory` object is a resizable `ArrayBuffer` or `SharedArrayBuffer` that
* holds the raw bytes of memory accessed by a WebAssembly Instance.
*
* A memory created by JavaScript or in WebAssembly code will be accessible and mutable
* from both JavaScript and WebAssembly.
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
*/
export class Memory {
/** Creates a new `Memory` object. */
constructor(descriptor: MemoryDescriptor);
/** An accessor property that returns the buffer contained in the memory. */
readonly buffer: ArrayBuffer;
/**
* Increases the size of the memory instance by a specified number of WebAssembly
* pages (each one is 64KB in size).
*/
grow(delta: number): number;
}
/**
* A `WebAssembly.Module` object contains stateless WebAssembly code that has already been compiled
* by the browser — this can be efficiently shared with Workers, and instantiated multiple times.
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
*/
export class Module {
/** Creates a new `Module` object. */
constructor(bytes: BufferSource);
/**
* Given a `Module` and string, returns a copy of the contents of all custom sections in the
* module with the given string name.
* */
static customSections(
moduleObject: Module,
sectionName: string,
): ArrayBuffer[];
/** Given a `Module`, returns an array containing descriptions of all the declared exports. */
static exports(moduleObject: Module): ModuleExportDescriptor[];
/** Given a `Module`, returns an array containing descriptions of all the declared imports. */
static imports(moduleObject: Module): ModuleImportDescriptor[];
}
/**
* The `WebAssembly.RuntimeError` object is the error type that is thrown whenever WebAssembly
* specifies a trap.
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
*/
export class RuntimeError extends Error {
/** Creates a new `WebAssembly.RuntimeError` object. */
constructor();
}
/**
* The `WebAssembly.Table()` object is a JavaScript wrapper object — an array-like structure
* representing a WebAssembly Table, which stores function references. A table created by
* JavaScript or in WebAssembly code will be accessible and mutable from both JavaScript
* and WebAssembly.
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
*/
export class Table {
/** Creates a new `Table` object. */
constructor(descriptor: TableDescriptor);
/** Returns the length of the table, i.e. the number of elements. */
readonly length: number;
/** Accessor function — gets the element stored at a given index. */
get(index: number): Function | null;
/** Increases the size of the `Table` instance by a specified number of elements. */
grow(delta: number): number;
/** Sets an element stored at a given index to a given value. */
set(index: number, value: Function | null): void;
}
/** The `GlobalDescriptor` describes the options you can pass to `new WebAssembly.Global()`. */
export interface GlobalDescriptor {
mutable?: boolean;
value: ValueType;
}
/** The `MemoryDescriptor` describes the options you can pass to `new WebAssembly.Memory()`. */
export interface MemoryDescriptor {
initial: number;
maximum?: number;
}
/** A `ModuleExportDescriptor` is the description of a declared export in a `WebAssembly.Module`. */
export interface ModuleExportDescriptor {
kind: ImportExportKind;
name: string;
}
/** A `ModuleImportDescriptor` is the description of a declared import in a `WebAssembly.Module`. */
export interface ModuleImportDescriptor {
kind: ImportExportKind;
module: string;
name: string;
}
/** The `TableDescriptor` describes the options you can pass to `new WebAssembly.Table()`. */
export interface TableDescriptor {
element: TableKind;
initial: number;
maximum?: number;
}
/** The value returned from `WebAssembly.instantiate` and `WebAssembly.instantiateStreaming`. */
export interface WebAssemblyInstantiatedSource {
/* A `WebAssembly.Instance` object that contains all the exported WebAssembly functions. */
instance: Instance;
/**
* A `WebAssembly.Module` object representing the compiled WebAssembly module.
* This `Module` can be instantiated again, or shared via postMessage().
*/
module: Module;
}
export type ImportExportKind = "function" | "global" | "memory" | "table";
export type TableKind = "anyfunc";
export type ValueType = "f32" | "f64" | "i32" | "i64";
export type ExportValue = Function | Global | Memory | Table;
export type Exports = Record<string, ExportValue>;
export type ImportValue = ExportValue | number;
export type ModuleImports = Record<string, ImportValue>;
export type Imports = Record<string, ModuleImports>;
/**
* The `WebAssembly.compile()` function compiles WebAssembly binary code into a
* `WebAssembly.Module` object. This function is useful if it is necessary to compile
* a module before it can be instantiated (otherwise, the `WebAssembly.instantiate()`
* function should be used).
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
*/
export function compile(bytes: BufferSource): Promise<Module>;
/**
* The `WebAssembly.compileStreaming()` function compiles a `WebAssembly.Module`
* directly from a streamed underlying source. This function is useful if it
* is necessary to a compile a module before it can be instantiated (otherwise,
* the `WebAssembly.instantiateStreaming()` function should be used).
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
*/
export function compileStreaming(
source: Response | Promise<Response>,
): Promise<Module>;
/**
* The WebAssembly.instantiate() function allows you to compile and instantiate
* WebAssembly code.
*
* This overload takes the WebAssembly binary code, in the form of a typed
* array or ArrayBuffer, and performs both compilation and instantiation in one step.
* The returned Promise resolves to both a compiled WebAssembly.Module and its first
* WebAssembly.Instance.
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
*/
export function instantiate(
bytes: BufferSource,
importObject?: Imports,
): Promise<WebAssemblyInstantiatedSource>;
/**
* The WebAssembly.instantiate() function allows you to compile and instantiate
* WebAssembly code.
*
* This overload takes an already-compiled WebAssembly.Module and returns
* a Promise that resolves to an Instance of that Module. This overload is useful
* if the Module has already been compiled.
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
*/
export function instantiate(
moduleObject: Module,
importObject?: Imports,
): Promise<Instance>;
/**
* The `WebAssembly.instantiateStreaming()` function compiles and instantiates a
* WebAssembly module directly from a streamed underlying source. This is the most
* efficient, optimized way to load WebAssembly code.
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
*/
export function instantiateStreaming(
response: Response | PromiseLike<Response>,
importObject?: Imports,
): Promise<WebAssemblyInstantiatedSource>;
/**
* The `WebAssembly.validate()` function validates a given typed array of
* WebAssembly binary code, returning whether the bytes form a valid wasm
* module (`true`) or not (`false`).
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
*/
export function validate(bytes: BufferSource): boolean;
}
/** Sets a timer which executes a function once after the timer expires. Returns
* an id which may be used to cancel the timeout.
*
* setTimeout(() => { console.log('hello'); }, 500);
*/
declare function setTimeout(
/** callback function to execute when timer expires */
cb: (...args: any[]) => void,
/** delay in ms */
delay?: number,
/** arguments passed to callback function */
...args: any[]
): number;
/** Repeatedly calls a function , with a fixed time delay between each call.
*
* // Outputs 'hello' to the console every 500ms
* setInterval(() => { console.log('hello'); }, 500);
*/
declare function setInterval(
/** callback function to execute when timer expires */
cb: (...args: any[]) => void,
/** delay in ms */
delay?: number,
/** arguments passed to callback function */
...args: any[]
): number;
/** Cancels a timed, repeating action which was previously started by a call
* to `setInterval()`
*
* const id = setInterval(()= > {console.log('hello');}, 500);
* ...
* clearInterval(id);
*/
declare function clearInterval(id?: number): void;
/** Cancels a scheduled action initiated by `setTimeout()`
*
* const id = setTimeout(()= > {console.log('hello');}, 500);
* ...
* clearTimeout(id);
*/
declare function clearTimeout(id?: number): void;
interface VoidFunction {
(): void;
}
/** A microtask is a short function which is executed after the function or
* module which created it exits and only if the JavaScript execution stack is
* empty, but before returning control to the event loop being used to drive the
* script's execution environment. This event loop may be either the main event
* loop or the event loop driving a web worker.
*
* queueMicrotask(() => { console.log('This event loop stack is complete'); });
*/
declare function queueMicrotask(func: VoidFunction): void;
declare var crypto: Crypto;
/** Registers an event listener in the global scope, which will be called
* synchronously whenever the event `type` is dispatched.
*
* addEventListener('unload', () => { console.log('All finished!'); });
* ...
* dispatchEvent(new Event('unload'));
*/
declare function addEventListener(
type: string,
callback: EventListenerOrEventListenerObject | null,
options?: boolean | AddEventListenerOptions | undefined,
): void;
/** Dispatches an event in the global scope, synchronously invoking any
* registered event listeners for this event in the appropriate order. Returns
* false if event is cancelable and at least one of the event handlers which
* handled this event called Event.preventDefault(). Otherwise it returns true.
*
* dispatchEvent(new Event('unload'));
*/
declare function dispatchEvent(event: Event): boolean;
/** Remove a previously registered event listener from the global scope
*
* const lstnr = () => { console.log('hello'); };
* addEventListener('load', lstnr);
* removeEventListener('load', lstnr);
*/
declare function removeEventListener(
type: string,
callback: EventListenerOrEventListenerObject | null,
options?: boolean | EventListenerOptions | undefined,
): void;
interface DOMStringList {
/** Returns the number of strings in strings. */
readonly length: number;
/** Returns true if strings contains string, and false otherwise. */
contains(string: string): boolean;
/** Returns the string with index index from strings. */
item(index: number): string | null;
[index: number]: string;
}
type BufferSource = ArrayBufferView | ArrayBuffer;
declare interface Console {
assert(condition?: boolean, ...data: any[]): void;
clear(): void;
count(label?: string): void;
countReset(label?: string): void;
debug(...data: any[]): void;
dir(item?: any, options?: any): void;
dirxml(...data: any[]): void;
error(...data: any[]): void;
group(...data: any[]): void;
groupCollapsed(...data: any[]): void;
groupEnd(): void;
info(...data: any[]): void;
log(...data: any[]): void;
table(tabularData?: any, properties?: string[]): void;
time(label?: string): void;
timeEnd(label?: string): void;
timeLog(label?: string, ...data: any[]): void;
timeStamp(label?: string): void;
trace(...data: any[]): void;
warn(...data: any[]): void;
}
declare var console: Console;
declare interface Crypto {
readonly subtle: null;
getRandomValues<
T extends
| Int8Array
| Int16Array
| Int32Array
| Uint8Array
| Uint16Array
| Uint32Array
| Uint8ClampedArray
| Float32Array
| Float64Array
| DataView
| null,
>(
array: T,
): T;
}
declare class URLSearchParams {
constructor(
init?: string[][] | Record<string, string> | string | URLSearchParams,
);
static toString(): string;
/** Appends a specified key/value pair as a new search parameter.
*
* ```ts
* let searchParams = new URLSearchParams();
* searchParams.append('name', 'first');
* searchParams.append('name', 'second');
* ```
*/
append(name: string, value: string): void;
/** Deletes the given search parameter and its associated value,
* from the list of all search parameters.
*
* ```ts
* let searchParams = new URLSearchParams([['name', 'value']]);
* searchParams.delete('name');
* ```
*/
delete(name: string): void;
/** Returns all the values associated with a given search parameter
* as an array.
*
* ```ts
* searchParams.getAll('name');
* ```
*/
getAll(name: string): string[];
/** Returns the first value associated to the given search parameter.
*
* ```ts
* searchParams.get('name');
* ```
*/
get(name: string): string | null;
/** Returns a Boolean that indicates whether a parameter with the
* specified name exists.
*
* ```ts
* searchParams.has('name');
* ```
*/
has(name: string): boolean;
/** Sets the value associated with a given search parameter to the
* given value. If there were several matching values, this method
* deletes the others. If the search parameter doesn't exist, this
* method creates it.
*
* ```ts
* searchParams.set('name', 'value');
* ```
*/
set(name: string, value: string): void;
/** Sort all key/value pairs contained in this object in place and
* return undefined. The sort order is according to Unicode code
* points of the keys.
*
* ```ts
* searchParams.sort();
* ```
*/
sort(): void;
/** Calls a function for each element contained in this object in
* place and return undefined. Optionally accepts an object to use
* as this when executing callback as second argument.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* params.forEach((value, key, parent) => {
* console.log(value, key, parent);
* });
* ```
*
*/
forEach(
callbackfn: (value: string, key: string, parent: this) => void,
thisArg?: any,
): void;
/** Returns an iterator allowing to go through all keys contained
* in this object.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const key of params.keys()) {
* console.log(key);
* }
* ```
*/
keys(): IterableIterator<string>;
/** Returns an iterator allowing to go through all values contained
* in this object.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const value of params.values()) {
* console.log(value);
* }
* ```
*/
values(): IterableIterator<string>;
/** Returns an iterator allowing to go through all key/value
* pairs contained in this object.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const [key, value] of params.entries()) {
* console.log(key, value);
* }
* ```
*/
entries(): IterableIterator<[string, string]>;
/** Returns an iterator allowing to go through all key/value
* pairs contained in this object.
*
* ```ts
* const params = new URLSearchParams([["a", "b"], ["c", "d"]]);
* for (const [key, value] of params) {
* console.log(key, value);
* }
* ```
*/
[Symbol.iterator](): IterableIterator<[string, string]>;
/** Returns a query string suitable for use in a URL.
*
* ```ts
* searchParams.toString();
* ```
*/
toString(): string;
}
/** The URL interface represents an object providing static methods used for creating object URLs. */
declare class URL {
constructor(url: string, base?: string | URL);
createObjectURL(object: any): string;
revokeObjectURL(url: string): void;
hash: string;
host: string;
hostname: string;
href: string;
toString(): string;
readonly origin: string;
password: string;
pathname: string;
port: string;
protocol: string;
search: string;
readonly searchParams: URLSearchParams;
username: string;
toJSON(): string;
}
interface MessageEventInit<T = any> extends EventInit {
data?: T;
origin?: string;
lastEventId?: string;
}
declare class MessageEvent<T = any> extends Event {
/**
* Returns the data of the message.
*/
readonly data: T;
/**
* Returns the last event ID string, for server-sent events.
*/
readonly lastEventId: string;
constructor(type: string, eventInitDict?: MessageEventInit);
}
interface ErrorEventInit extends EventInit {
message?: string;
filename?: string;
lineno?: number;
colno?: number;
error?: any;
}
declare class ErrorEvent extends Event {
readonly message: string;
readonly filename: string;
readonly lineno: number;
readonly colno: number;
readonly error: any;
constructor(type: string, eventInitDict?: ErrorEventInit);
}
interface PostMessageOptions {
transfer?: any[];
}
interface ProgressEventInit extends EventInit {
lengthComputable?: boolean;
loaded?: number;
total?: number;
}
interface AbstractWorkerEventMap {
"error": ErrorEvent;
}
interface WorkerEventMap extends AbstractWorkerEventMap {
"message": MessageEvent;
"messageerror": MessageEvent;
}
declare class Worker extends EventTarget {
onerror?: (e: ErrorEvent) => void;
onmessage?: (e: MessageEvent) => void;
onmessageerror?: (e: MessageEvent) => void;
constructor(
specifier: string,
options?: {
type?: "classic" | "module";
name?: string;
/** UNSTABLE: New API. Expect many changes; most likely this
* field will be made into an object for more granular
* configuration of worker thread (permissions, import map, etc.).
*
* Set to `true` to make `Deno` namespace and all of its methods
* available to worker thread.
*
* Currently worker inherits permissions from main thread (permissions
* given using `--allow-*` flags).
* Configurable permissions are on the roadmap to be implemented.
*
* Example:
*
* ```ts
* // mod.ts
* const worker = new Worker(
* new URL("deno_worker.ts", import.meta.url).href,
* { type: "module", deno: true }
* );
* worker.postMessage({ cmd: "readFile", fileName: "./log.txt" });
*
* // deno_worker.ts
*
*
* self.onmessage = async function (e) {
* const { cmd, fileName } = e.data;
* if (cmd !== "readFile") {
* throw new Error("Invalid command");
* }
* const buf = await Deno.readFile(fileName);
* const fileContents = new TextDecoder().decode(buf);
* console.log(fileContents);
* }
* ```
*
* // log.txt
* hello world
* hello world 2
*
* // run program
* $ deno run --allow-read mod.ts
* hello world
* hello world2
*
*/
deno?: boolean;
},
);
postMessage(message: any, transfer: ArrayBuffer[]): void;
postMessage(message: any, options?: PostMessageOptions): void;
addEventListener<K extends keyof WorkerEventMap>(
type: K,
listener: (this: Worker, ev: WorkerEventMap[K]) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
removeEventListener<K extends keyof WorkerEventMap>(
type: K,
listener: (this: Worker, ev: WorkerEventMap[K]) => any,
options?: boolean | EventListenerOptions,
): void;
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void;
terminate(): void;
}
declare type PerformanceEntryList = PerformanceEntry[];
declare class Performance {
constructor();
/** Removes the stored timestamp with the associated name. */
clearMarks(markName?: string): void;
/** Removes stored timestamp with the associated name. */
clearMeasures(measureName?: string): void;
getEntries(): PerformanceEntryList;
getEntriesByName(name: string, type?: string): PerformanceEntryList;
getEntriesByType(type: string): PerformanceEntryList;
/** Stores a timestamp with the associated name (a "mark"). */
mark(markName: string, options?: PerformanceMarkOptions): PerformanceMark;
/** Stores the `DOMHighResTimeStamp` duration between two marks along with the
* associated name (a "measure"). */
measure(
measureName: string,
options?: PerformanceMeasureOptions,
): PerformanceMeasure;
/** Stores the `DOMHighResTimeStamp` duration between two marks along with the
* associated name (a "measure"). */
measure(
measureName: string,
startMark?: string,
endMark?: string,
): PerformanceMeasure;
/** Returns a current time from Deno's start in milliseconds.
*
* Use the permission flag `--allow-hrtime` return a precise value.
*
* ```ts
* const t = performance.now();
* console.log(`${t} ms since start!`);
* ```
*/
now(): number;
}
declare var performance: Performance;
declare interface PerformanceMarkOptions {
/** Metadata to be included in the mark. */
detail?: any;
/** Timestamp to be used as the mark time. */
startTime?: number;
}
declare interface PerformanceMeasureOptions {
/** Metadata to be included in the measure. */
detail?: any;
/** Timestamp to be used as the start time or string to be used as start
* mark.*/
start?: string | number;
/** Duration between the start and end times. */
duration?: number;
/** Timestamp to be used as the end time or string to be used as end mark. */
end?: string | number;
}
/** Encapsulates a single performance metric that is part of the performance
* timeline. A performance entry can be directly created by making a performance
* mark or measure (for example by calling the `.mark()` method) at an explicit
* point in an application. */
declare class PerformanceEntry {
readonly duration: number;
readonly entryType: string;
readonly name: string;
readonly startTime: number;
toJSON(): any;
}
/** `PerformanceMark` is an abstract interface for `PerformanceEntry` objects
* with an entryType of `"mark"`. Entries of this type are created by calling
* `performance.mark()` to add a named `DOMHighResTimeStamp` (the mark) to the
* performance timeline. */
declare class PerformanceMark extends PerformanceEntry {
readonly detail: any;
readonly entryType: "mark";
constructor(name: string, options?: PerformanceMarkOptions);
}
/** `PerformanceMeasure` is an abstract interface for `PerformanceEntry` objects
* with an entryType of `"measure"`. Entries of this type are created by calling
* `performance.measure()` to add a named `DOMHighResTimeStamp` (the measure)
* between two marks to the performance timeline. */
declare class PerformanceMeasure extends PerformanceEntry {
readonly detail: any;
readonly entryType: "measure";
}
/** Events measuring progress of an underlying process, like an HTTP request
* (for an XMLHttpRequest, or the loading of the underlying resource of an
* <img>, <audio>, <video>, <style> or <link>). */
declare class ProgressEvent<T extends EventTarget = EventTarget> extends Event {
constructor(type: string, eventInitDict?: ProgressEventInit);
readonly lengthComputable: boolean;
readonly loaded: number;
readonly target: T | null;
readonly total: number;
}
declare interface CustomEventInit<T = any> extends EventInit {
detail?: T;
}
declare class CustomEvent<T = any> extends Event {
constructor(typeArg: string, eventInitDict?: CustomEventInit<T>);
/** Returns any custom data event was created with. Typically used for
* synthetic events. */
readonly detail: T;
}
interface ErrorConstructor {
/** See https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions. */
// eslint-disable-next-line @typescript-eslint/ban-types
captureStackTrace(error: Object, constructor?: Function): void;
// TODO(nayeemrmn): Support `Error.prepareStackTrace()`. We currently use this
// internally in a way that makes it unavailable for users.
}
interface CloseEventInit extends EventInit {
code?: number;
reason?: string;
wasClean?: boolean;
}
declare class CloseEvent extends Event {
constructor(type: string, eventInitDict?: CloseEventInit);
/**
* Returns the WebSocket connection close code provided by the server.
*/
readonly code: number;
/**
* Returns the WebSocket connection close reason provided by the server.
*/
readonly reason: string;
/**
* Returns true if the connection closed cleanly; false otherwise.
*/
readonly wasClean: boolean;
}
interface WebSocketEventMap {
close: CloseEvent;
error: Event;
message: MessageEvent;
open: Event;
}
/** Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection. */
declare class WebSocket extends EventTarget {
constructor(url: string, protocols?: string | string[]);
static readonly CLOSED: number;
static readonly CLOSING: number;
static readonly CONNECTING: number;
static readonly OPEN: number;
/**
* Returns a string that indicates how binary data from the WebSocket object is exposed to scripts:
*
* Can be set, to change how binary data is returned. The default is "blob".
*/
binaryType: BinaryType;
/**
* 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.
*
* 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.)
*/
readonly bufferedAmount: number;
/**
* Returns the extensions selected by the server, if any.
*/
readonly extensions: string;
onclose: ((this: WebSocket, ev: CloseEvent) => any) | null;
onerror: ((this: WebSocket, ev: Event | ErrorEvent) => any) | null;
onmessage: ((this: WebSocket, ev: MessageEvent) => any) | null;
onopen: ((this: WebSocket, ev: Event) => any) | null;
/**
* 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.
*/
readonly protocol: string;
/**
* Returns the state of the WebSocket object's connection. It can have the values described below.
*/
readonly readyState: number;
/**
* Returns the URL that was used to establish the WebSocket connection.
*/
readonly url: string;
/**
* Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason.
*/
close(code?: number, reason?: string): void;
/**
* Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView.
*/
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
readonly CLOSED: number;
readonly CLOSING: number;
readonly CONNECTING: number;
readonly OPEN: number;
addEventListener<K extends keyof WebSocketEventMap>(
type: K,
listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
removeEventListener<K extends keyof WebSocketEventMap>(
type: K,
listener: (this: WebSocket, ev: WebSocketEventMap[K]) => any,
options?: boolean | EventListenerOptions,
): void;
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void;
}
type BinaryType = "arraybuffer" | "blob";