2020-01-24 14:15:01 -05:00
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
2020-04-11 11:42:02 -04:00
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, no-var */
2020-01-24 14:15:01 -05:00
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
2020-02-23 09:40:44 -05:00
// This follows the WebIDL at: https://webassembly.github.io/spec/js-api/
// and: https://webassembly.github.io/spec/web-api/
declare namespace WebAssembly {
interface WebAssemblyInstantiatedSource {
module : Module ;
instance : Instance ;
}
/ * * C o m p i l e s a ` W e b A s s e m b l y . M o d u l e ` f r o m W e b A s s e m b l y b i n a r y c o d e . T h i s
* function is useful if it is necessary to a compile a module before it can
* be instantiated ( otherwise , the ` WebAssembly.instantiate() ` function
* should be used ) . * /
2020-04-08 13:21:04 -04:00
function compile ( bufferSource : BufferSource ) : Promise < Module > ;
2020-02-23 09:40:44 -05:00
/ * * C o m p i l e s a ` W e b A s s e m b l y . M o d u l e ` d i r e c t l y f r o m a s t r e a m e d u n d e r l y i n g
* 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 ) . * /
2020-04-10 09:51:17 -04:00
function compileStreaming ( source : Promise < Response > ) : Promise < Module > ;
2020-02-23 09:40:44 -05:00
/ * * T a k e s t h e W e b A s s e m b l y b i n a r y c o d e , i n t h e f o r m o f a t y p e d a r r a y o r
* ` 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 ` . * /
function instantiate (
2020-04-08 13:21:04 -04:00
bufferSource : BufferSource ,
2020-02-23 09:40:44 -05:00
importObject? : object
) : Promise < WebAssemblyInstantiatedSource > ;
/ * * T a k e s a n a l r e a d y - c o m p i l e d ` W e b A s s e m b l y . M o d u l e ` a n d r e t u r n s a ` P r o m i s e `
* that resolves to an ` Instance ` of that ` Module ` . This overload is useful if
* the ` Module ` has already been compiled . * /
function instantiate (
module : Module ,
importObject? : object
) : Promise < Instance > ;
/ * * C o m p i l e s a n d i n s t a n t i a t e s a W e b A s s e m b l y m o d u l e d i r e c t l y f r o m a s t r e a m e d
* underlying source . This is the most efficient , optimized way to load wasm
* code . * /
function instantiateStreaming (
2020-04-10 09:51:17 -04:00
source : Promise < Response > ,
2020-02-23 09:40:44 -05:00
importObject? : object
) : Promise < WebAssemblyInstantiatedSource > ;
/ * * V a l i d a t e s a g i v e n t y p e d a r r a y o f W e b A s s e m b l y b i n a r y c o d e , r e t u r n i n g
* whether the bytes form a valid wasm module ( ` true ` ) or not ( ` false ` ) . * /
2020-04-08 13:21:04 -04:00
function validate ( bufferSource : BufferSource ) : boolean ;
2020-02-23 09:40:44 -05:00
type ImportExportKind = "function" | "table" | "memory" | "global" ;
interface ModuleExportDescriptor {
name : string ;
kind : ImportExportKind ;
}
interface ModuleImportDescriptor {
module : string ;
name : string ;
kind : ImportExportKind ;
}
class Module {
2020-04-08 13:21:04 -04:00
constructor ( bufferSource : BufferSource ) ;
2020-02-23 09:40:44 -05:00
/ * * G i v e n a ` M o d u l e ` a n d s t r i n g , r e t u r n s a c o p y o f t h e c o n t e n t s o f a l l
* custom sections in the module with the given string name . * /
static customSections (
moduleObject : Module ,
sectionName : string
) : ArrayBuffer ;
/ * * G i v e n a ` M o d u l e ` , r e t u r n s a n a r r a y c o n t a i n i n g d e s c r i p t i o n s o f a l l t h e
* declared exports . * /
static exports ( moduleObject : Module ) : ModuleExportDescriptor [ ] ;
/ * * G i v e n a ` M o d u l e ` , r e t u r n s a n a r r a y c o n t a i n i n g d e s c r i p t i o n s o f a l l t h e
* declared imports . * /
static imports ( moduleObject : Module ) : ModuleImportDescriptor [ ] ;
}
class Instance < T extends object = { [ key : string ] : any } > {
constructor ( module : Module , importObject? : object ) ;
/ * * A n o b j e c t c o n t a i n i n g a s i t s m e m b e r s a l l t h e f u n c t i o n s e x p o r t e d f r o m t h e
* WebAssembly module instance , to allow them to be accessed and used by
* JavaScript . * /
readonly exports : T ;
}
interface MemoryDescriptor {
initial : number ;
maximum? : number ;
}
class Memory {
constructor ( descriptor : MemoryDescriptor ) ;
/** An accessor property that returns the buffer contained in the memory. */
readonly buffer : ArrayBuffer ;
/ * * I n c r e a s e s t h e s i z e o f t h e m e m o r y i n s t a n c e b y a s p e c i f i e d n u m b e r o f
* WebAssembly pages ( each one is 64 KB in size ) . * /
grow ( delta : number ) : number ;
}
type TableKind = "anyfunc" ;
interface TableDescriptor {
element : TableKind ;
initial : number ;
maximum? : number ;
}
class Table {
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 ) : ( . . . args : any [ ] ) = > any ;
/ * * I n c r e a s e s t h e s i z e o f t h e T a b l e i n s t a n c e b y a s p e c i f i e d n u m b e r o f
* elements . * /
grow ( delta : number ) : number ;
/** Sets an element stored at a given index to a given value. */
set ( index : number , value : ( . . . args : any [ ] ) = > any ) : void ;
}
type ValueType = "i32" | "i64" | "f32" | "f64" ;
interface GlobalDescriptor {
value : ValueType ;
mutable? : boolean ;
}
/ * * R e p r e s e n t s a g l o b a l v a r i a b l e i n s t a n c e , a c c e s s i b l e f r o m b o t h J a v a S c r i p t a n d
* importable / exportable across one or more ` WebAssembly.Module ` instances .
* This allows dynamic linking of multiple modules . * /
class Global {
constructor ( descriptor : GlobalDescriptor , value? : any ) ;
/ * * O l d - s t y l e m e t h o d t h a t r e t u r n s t h e v a l u e c o n t a i n e d i n s i d e t h e g l o b a l
* variable . * /
valueOf ( ) : any ;
/ * * T h e v a l u e c o n t a i n e d i n s i d e t h e g l o b a l v a r i a b l e — t h i s c a n b e u s e d t o
* directly set and get the global ' s value . * /
value : any ;
}
/** Indicates an error during WebAssembly decoding or validation */
class CompileError extends Error {
constructor ( message : string , fileName? : string , lineNumber? : string ) ;
}
/ * * I n d i c a t e s a n e r r o r d u r i n g m o d u l e i n s t a n t i a t i o n ( b e s i d e s t r a p s f r o m t h e
* start function ) . * /
class LinkError extends Error {
constructor ( message : string , fileName? : string , lineNumber? : string ) ;
}
/** Is thrown whenever WebAssembly specifies a trap. */
class RuntimeError extends Error {
constructor ( message : string , fileName? : string , lineNumber? : string ) ;
}
}
2020-05-30 11:19:16 -04:00
/ * * S e t s a t i m e r w h i c h e x e c u t e s a f u n c t i o n o n c e a f t e r t h e t i m e r e x p i r e s . R e t u r n s
* an id which may be used to cancel the timeout .
*
* setTimeout ( ( ) = > { console . log ( 'hello' ) ; } , 500 ) ;
* /
2020-04-07 11:12:31 -04:00
declare function setTimeout (
2020-05-30 11:19:16 -04:00
/** callback function to execute when timer expires */
2020-05-15 09:51:49 -04:00
cb : ( . . . args : any [ ] ) = > void ,
2020-05-30 11:19:16 -04:00
/** delay in ms */
2020-04-07 11:12:31 -04:00
delay? : number ,
2020-05-30 11:19:16 -04:00
/** arguments passed to callback function */
2020-05-15 09:51:49 -04:00
. . . args : any [ ]
2020-04-07 11:12:31 -04:00
) : number ;
2020-04-11 11:42:02 -04:00
2020-05-30 11:19:16 -04:00
/ * * R e p e a t e d l y c a l l s a f u n c t i o n , w i t h a f i x e d t i m e d e l a y b e t w e e n e a c h c a l l .
*
* // Outputs 'hello' to the console every 500ms
* setInterval ( ( ) = > { console . log ( 'hello' ) ; } , 500 ) ;
* /
2020-04-07 11:12:31 -04:00
declare function setInterval (
2020-05-30 11:19:16 -04:00
/** callback function to execute when timer expires */
2020-05-15 09:51:49 -04:00
cb : ( . . . args : any [ ] ) = > void ,
2020-05-30 11:19:16 -04:00
/** delay in ms */
2020-04-07 11:12:31 -04:00
delay? : number ,
2020-05-30 11:19:16 -04:00
/** arguments passed to callback function */
2020-05-15 09:51:49 -04:00
. . . args : any [ ]
2020-04-07 11:12:31 -04:00
) : number ;
2020-05-30 11:19:16 -04:00
/ * * C a n c e l s a t i m e d , r e p e a t i n g a c t i o n w h i c h w a s p r e v i o u s l y s t a r t e d b y a c a l l
* to ` setInterval() `
*
* const id = setInterval ( ( ) = > { console . log ( 'hello' ) ; } , 500 ) ;
* . . .
* clearInterval ( id ) ;
* /
2020-04-07 11:12:31 -04:00
declare function clearInterval ( id? : number ) : void ;
2020-05-30 11:19:16 -04:00
/ * * C a n c e l s a s c h e d u l e d a c t i o n i n i t i a t e d b y ` s e t T i m e o u t ( ) `
*
* const id = setTimeout ( ( ) = > { console . log ( 'hello' ) ; } , 500 ) ;
* . . .
* clearTimeout ( id ) ;
* /
declare function clearTimeout ( id? : number ) : void ;
/ * * A m i c r o t a s k i s a s h o r t f u n c t i o n w h i c h i s e x e c u t e d a f t e r t h e f u n c t i o n o r
* 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' ) ; } ) ;
* /
2020-04-07 11:12:31 -04:00
declare function queueMicrotask ( func : Function ) : void ;
2020-01-29 12:54:23 -05:00
2020-04-11 11:42:02 -04:00
declare var console : Console ;
2020-05-08 08:30:53 -04:00
declare var crypto : Crypto ;
2020-01-29 12:54:23 -05:00
2020-05-30 11:19:16 -04:00
/ * * R e g i s t e r s a n e v e n t l i s t e n e r i n t h e g l o b a l s c o p e , w h i c h w i l l b e c a l l e d
* synchronously whenever the event ` type ` is dispatched .
*
* addEventListener ( 'unload' , ( ) = > { console . log ( 'All finished!' ) ; } ) ;
* . . .
* dispatchEvent ( new Event ( 'unload' ) ) ;
* /
2020-04-08 13:21:04 -04:00
declare function addEventListener (
2020-01-24 14:15:01 -05:00
type : string ,
2020-04-09 06:03:44 -04:00
callback : EventListenerOrEventListenerObject | null ,
options? : boolean | AddEventListenerOptions | undefined
2020-04-08 13:21:04 -04:00
) : void ;
2020-05-30 11:19:16 -04:00
/ * * D i s p a t c h e s a n e v e n t i n t h e g l o b a l s c o p e , s y n c h r o n o u s l y i n v o k i n g a n y
* 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' ) ) ;
* /
2020-04-09 06:03:44 -04:00
declare function dispatchEvent ( event : Event ) : boolean ;
2020-04-08 13:21:04 -04:00
2020-05-30 11:19:16 -04:00
/ * * R e m o v e a p r e v i o u s l y r e g i s t e r e d e v e n t l i s t e n e r f r o m t h e g l o b a l s c o p e
*
* const lstnr = ( ) = > { console . log ( 'hello' ) ; } ;
* addEventListener ( 'load' , lstnr ) ;
* removeEventListener ( 'load' , lstnr ) ;
* /
2020-04-08 13:21:04 -04:00
declare function removeEventListener (
2020-01-24 14:15:01 -05:00
type : string ,
2020-04-09 06:03:44 -04:00
callback : EventListenerOrEventListenerObject | null ,
options? : boolean | EventListenerOptions | undefined
2020-04-08 13:21:04 -04:00
) : void ;
2020-01-24 14:15:01 -05:00
declare interface ImportMeta {
url : string ;
main : boolean ;
}
2020-04-10 14:24:42 -04:00
interface DomIterable < K , V > {
keys ( ) : IterableIterator < K > ;
values ( ) : IterableIterator < V > ;
entries ( ) : IterableIterator < [ K , V ] > ;
[ Symbol . iterator ] ( ) : IterableIterator < [ K , V ] > ;
forEach (
callback : ( value : V , key : K , parent : this ) = > void ,
thisArg? : any
) : void ;
}
2020-04-03 14:55:23 -04:00
2020-04-10 14:24:42 -04:00
interface ReadableStreamReadDoneResult < T > {
done : true ;
value? : T ;
}
2020-04-03 14:55:23 -04:00
2020-04-10 14:24:42 -04:00
interface ReadableStreamReadValueResult < T > {
done : false ;
value : T ;
}
2020-04-03 14:55:23 -04:00
2020-04-10 14:24:42 -04:00
type ReadableStreamReadResult < T > =
| ReadableStreamReadValueResult < T >
| ReadableStreamReadDoneResult < T > ;
2020-04-03 14:55:23 -04:00
2020-04-10 14:24:42 -04:00
interface ReadableStreamDefaultReader < R = any > {
readonly closed : Promise < void > ;
cancel ( reason? : any ) : Promise < void > ;
read ( ) : Promise < ReadableStreamReadResult < R > > ;
releaseLock ( ) : void ;
}
2020-04-03 14:55:23 -04:00
2020-04-22 10:06:51 -04:00
interface ReadableStreamReader < R = any > {
cancel ( ) : Promise < void > ;
read ( ) : Promise < ReadableStreamReadResult < R > > ;
releaseLock ( ) : void ;
}
interface ReadableByteStreamControllerCallback {
( controller : ReadableByteStreamController ) : void | PromiseLike < void > ;
}
interface UnderlyingByteSource {
autoAllocateChunkSize? : number ;
cancel? : ReadableStreamErrorCallback ;
pull? : ReadableByteStreamControllerCallback ;
start? : ReadableByteStreamControllerCallback ;
type : "bytes" ;
}
2020-04-10 14:24:42 -04:00
interface UnderlyingSource < R = any > {
cancel? : ReadableStreamErrorCallback ;
pull? : ReadableStreamDefaultControllerCallback < R > ;
start? : ReadableStreamDefaultControllerCallback < R > ;
type ? : undefined ;
}
interface ReadableStreamErrorCallback {
( reason : any ) : void | PromiseLike < void > ;
}
interface ReadableStreamDefaultControllerCallback < R > {
( controller : ReadableStreamDefaultController < R > ) : void | PromiseLike < void > ;
}
2020-04-22 10:06:51 -04:00
interface ReadableStreamDefaultController < R = any > {
readonly desiredSize : number | null ;
close ( ) : void ;
enqueue ( chunk : R ) : void ;
error ( error? : any ) : void ;
}
interface ReadableByteStreamController {
readonly byobRequest : undefined ;
readonly desiredSize : number | null ;
2020-04-10 14:24:42 -04:00
close ( ) : void ;
2020-04-22 10:06:51 -04:00
enqueue ( chunk : ArrayBufferView ) : void ;
error ( error? : any ) : void ;
}
interface PipeOptions {
preventAbort? : boolean ;
preventCancel? : boolean ;
preventClose? : boolean ;
signal? : AbortSignal ;
}
interface QueuingStrategySizeCallback < T = any > {
( chunk : T ) : number ;
}
interface QueuingStrategy < T = any > {
highWaterMark? : number ;
size? : QueuingStrategySizeCallback < T > ;
2020-04-10 14:24:42 -04:00
}
2020-04-30 10:40:10 -04:00
/ * * T h i s S t r e a m s A P I i n t e r f a c e p r o v i d e s a b u i l t - i n b y t e l e n g t h q u e u i n g s t r a t e g y
* that can be used when constructing streams . * /
declare class CountQueuingStrategy implements QueuingStrategy {
constructor ( options : { highWaterMark : number } ) ;
highWaterMark : number ;
size ( chunk : any ) : 1 ;
}
declare class ByteLengthQueuingStrategy
implements QueuingStrategy < ArrayBufferView > {
constructor ( options : { highWaterMark : number } ) ;
highWaterMark : number ;
size ( chunk : ArrayBufferView ) : number ;
}
2020-04-10 14:24:42 -04:00
/ * * T h i s S t r e a m s A P I i n t e r f a c e r e p r e s e n t s a r e a d a b l e s t r e a m o f b y t e d a t a . T h e
* Fetch API offers a concrete instance of a ReadableStream through the body
* property of a Response object . * /
interface ReadableStream < R = any > {
readonly locked : boolean ;
cancel ( reason? : any ) : Promise < void > ;
2020-04-22 10:06:51 -04:00
getIterator ( options ? : { preventCancel? : boolean } ) : AsyncIterableIterator < R > ;
2020-04-10 14:24:42 -04:00
// getReader(options: { mode: "byob" }): ReadableStreamBYOBReader;
getReader ( ) : ReadableStreamDefaultReader < R > ;
2020-04-22 10:06:51 -04:00
pipeThrough < T > (
{
writable ,
readable ,
} : {
writable : WritableStream < R > ;
readable : ReadableStream < T > ;
} ,
options? : PipeOptions
) : ReadableStream < T > ;
pipeTo ( dest : WritableStream < R > , options? : PipeOptions ) : Promise < void > ;
2020-04-10 14:24:42 -04:00
tee ( ) : [ ReadableStream < R > , ReadableStream < R > ] ;
2020-04-22 10:06:51 -04:00
[ Symbol . asyncIterator ] ( options ? : {
preventCancel? : boolean ;
} ) : AsyncIterableIterator < R > ;
2020-04-10 14:24:42 -04:00
}
2020-04-22 10:06:51 -04:00
declare var ReadableStream : {
2020-04-10 14:24:42 -04:00
prototype : ReadableStream ;
2020-04-22 10:06:51 -04:00
new (
underlyingSource : UnderlyingByteSource ,
strategy ? : { highWaterMark? : number ; size? : undefined }
) : ReadableStream < Uint8Array > ;
new < R = any > (
underlyingSource? : UnderlyingSource < R > ,
strategy? : QueuingStrategy < R >
) : ReadableStream < R > ;
2020-04-10 14:24:42 -04:00
} ;
2020-04-30 10:40:10 -04:00
interface WritableStreamDefaultControllerCloseCallback {
( ) : void | PromiseLike < void > ;
}
interface WritableStreamDefaultControllerStartCallback {
( controller : WritableStreamDefaultController ) : void | PromiseLike < void > ;
}
interface WritableStreamDefaultControllerWriteCallback < W > {
( chunk : W , controller : WritableStreamDefaultController ) : void | PromiseLike <
void
> ;
}
interface WritableStreamErrorCallback {
( reason : any ) : void | PromiseLike < void > ;
}
interface UnderlyingSink < W = any > {
abort? : WritableStreamErrorCallback ;
close? : WritableStreamDefaultControllerCloseCallback ;
start? : WritableStreamDefaultControllerStartCallback ;
type ? : undefined ;
write? : WritableStreamDefaultControllerWriteCallback < W > ;
}
/ * * T h i s S t r e a m s A P I i n t e r f a c e p r o v i d e s a s t a n d a r d a b s t r a c t i o n f o r w r i t i n g
* streaming data to a destination , known as a sink . This object comes with
* built - in backpressure and queuing . * /
declare class WritableStream < W = any > {
constructor (
underlyingSink? : UnderlyingSink < W > ,
strategy? : QueuingStrategy < W >
) ;
2020-04-10 14:24:42 -04:00
readonly locked : boolean ;
abort ( reason? : any ) : Promise < void > ;
2020-04-30 10:40:10 -04:00
close ( ) : Promise < void > ;
2020-04-10 14:24:42 -04:00
getWriter ( ) : WritableStreamDefaultWriter < W > ;
}
2020-04-30 10:40:10 -04:00
/ * * T h i s S t r e a m s A P I i n t e r f a c e r e p r e s e n t s a c o n t r o l l e r a l l o w i n g c o n t r o l o f a
* WritableStream ' s state . When constructing a WritableStream , the underlying
* sink is given a corresponding WritableStreamDefaultController instance to
* manipulate . * /
interface WritableStreamDefaultController {
error ( error? : any ) : void ;
}
/ * * T h i s S t r e a m s A P I i n t e r f a c e i s t h e o b j e c t r e t u r n e d b y
* WritableStream . getWriter ( ) and once created locks the < writer to the
* WritableStream ensuring that no other streams can write to the underlying
* sink . * /
2020-04-10 14:24:42 -04:00
interface WritableStreamDefaultWriter < W = any > {
readonly closed : Promise < void > ;
readonly desiredSize : number | null ;
readonly ready : Promise < void > ;
abort ( reason? : any ) : Promise < void > ;
close ( ) : Promise < void > ;
releaseLock ( ) : void ;
write ( chunk : W ) : Promise < void > ;
}
2020-05-03 15:10:52 -04:00
declare class TransformStream < I = any , O = any > {
constructor (
transformer? : Transformer < I , O > ,
writableStrategy? : QueuingStrategy < I > ,
readableStrategy? : QueuingStrategy < O >
) ;
readonly readable : ReadableStream < O > ;
readonly writable : WritableStream < I > ;
}
interface TransformStreamDefaultController < O = any > {
readonly desiredSize : number | null ;
enqueue ( chunk : O ) : void ;
error ( reason? : any ) : void ;
terminate ( ) : void ;
}
interface Transformer < I = any , O = any > {
flush? : TransformStreamDefaultControllerCallback < O > ;
readableType? : undefined ;
start? : TransformStreamDefaultControllerCallback < O > ;
transform? : TransformStreamDefaultControllerTransformCallback < I , O > ;
writableType? : undefined ;
}
interface TransformStreamDefaultControllerCallback < O > {
( controller : TransformStreamDefaultController < O > ) : void | PromiseLike < void > ;
}
interface TransformStreamDefaultControllerTransformCallback < I , O > {
(
chunk : I ,
controller : TransformStreamDefaultController < O >
) : void | PromiseLike < void > ;
}
2020-04-10 14:24:42 -04:00
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 ;
}
2020-04-11 11:42:02 -04:00
declare class DOMException extends Error {
constructor ( message? : string , name? : string ) ;
readonly name : string ;
readonly message : string ;
}
2020-04-08 13:21:04 -04:00
type BufferSource = ArrayBufferView | ArrayBuffer ;
type BlobPart = BufferSource | Blob | string ;
interface BlobPropertyBag {
type ? : string ;
ending ? : "transparent" | "native" ;
2020-01-24 14:15:01 -05:00
}
2020-04-08 13:21:04 -04:00
/** A file-like object of immutable, raw data. Blobs represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system. */
interface Blob {
readonly size : number ;
readonly type : string ;
arrayBuffer ( ) : Promise < ArrayBuffer > ;
slice ( start? : number , end? : number , contentType? : string ) : Blob ;
stream ( ) : ReadableStream ;
text ( ) : Promise < string > ;
}
declare const Blob : {
prototype : Blob ;
new ( blobParts? : BlobPart [ ] , options? : BlobPropertyBag ) : Blob ;
} ;
2020-04-10 09:51:17 -04:00
interface FilePropertyBag extends BlobPropertyBag {
lastModified? : number ;
}
/ * * P r o v i d e s i n f o r m a t i o n a b o u t f i l e s a n d a l l o w s J a v a S c r i p t i n a w e b p a g e t o
* access their content . * /
interface File extends Blob {
readonly lastModified : number ;
readonly name : string ;
}
declare const File : {
prototype : File ;
new ( fileBits : BlobPart [ ] , fileName : string , options? : FilePropertyBag ) : File ;
} ;
2020-04-08 13:21:04 -04:00
declare const isConsoleInstance : unique symbol ;
declare class Console {
indentLevel : number ;
[ isConsoleInstance ] : boolean ;
/** Writes the arguments to stdout */
log : ( . . . args : unknown [ ] ) = > void ;
/** Writes the arguments to stdout */
debug : ( . . . args : unknown [ ] ) = > void ;
/** Writes the arguments to stdout */
info : ( . . . args : unknown [ ] ) = > void ;
/** Writes the properties of the supplied `obj` to stdout */
dir : (
obj : unknown ,
options? : Partial < {
depth : number ;
indentLevel : number ;
} >
) = > void ;
/ * * F r o m M D N :
* Displays an interactive tree of the descendant elements of
* the specified XML / HTML element . If it is not possible to display
* as an element the JavaScript Object view is shown instead .
* The output is presented as a hierarchical listing of expandable
* nodes that let you see the contents of child nodes .
*
* Since we write to stdout , we can ' t display anything interactive
* we just fall back to ` console.dir ` .
2020-01-24 14:15:01 -05:00
* /
2020-04-08 13:21:04 -04:00
dirxml : (
obj : unknown ,
options? : Partial < {
showHidden : boolean ;
depth : number ;
colors : boolean ;
indentLevel : number ;
} >
) = > void ;
/** Writes the arguments to stdout */
warn : ( . . . args : unknown [ ] ) = > void ;
/** Writes the arguments to stdout */
error : ( . . . args : unknown [ ] ) = > void ;
/ * * W r i t e s a n e r r o r m e s s a g e t o s t d o u t i f t h e a s s e r t i o n i s ` f a l s e ` . I f t h e
* assertion is ` true ` , nothing happens .
*
* ref : https : //console.spec.whatwg.org/#assert
2020-01-24 14:15:01 -05:00
* /
2020-04-08 13:21:04 -04:00
assert : ( condition? : boolean , . . . args : unknown [ ] ) = > void ;
count : ( label? : string ) = > void ;
countReset : ( label? : string ) = > void ;
table : ( data : unknown , properties? : string [ ] | undefined ) = > void ;
time : ( label? : string ) = > void ;
timeLog : ( label? : string , . . . args : unknown [ ] ) = > void ;
timeEnd : ( label? : string ) = > void ;
group : ( . . . label : unknown [ ] ) = > void ;
groupCollapsed : ( . . . label : unknown [ ] ) = > void ;
groupEnd : ( ) = > void ;
clear : ( ) = > void ;
trace : ( . . . args : unknown [ ] ) = > void ;
static [ Symbol . hasInstance ] ( instance : Console ) : boolean ;
2020-01-24 14:15:01 -05:00
}
2020-05-08 08:30:53 -04:00
declare interface Crypto {
readonly subtle : null ;
getRandomValues <
T extends
| Int8Array
| Int16Array
| Int32Array
| Uint8Array
| Uint16Array
| Uint32Array
| Uint8ClampedArray
| Float32Array
| Float64Array
| DataView
| null
> (
array : T
) : T ;
}
2020-04-10 09:51:17 -04:00
type FormDataEntryValue = File | string ;
/ * * P r o v i d e s a w a y t o e a s i l y c o n s t r u c t a s e t o f k e y / v a l u e p a i r s r e p r e s e n t i n g
* form fields and their values , which can then be easily sent using the
* XMLHttpRequest . send ( ) method . It uses the same format a form would use if the
* encoding type were set to "multipart/form-data" . * /
2020-04-10 14:24:42 -04:00
interface FormData extends DomIterable < string , FormDataEntryValue > {
2020-04-10 09:51:17 -04:00
append ( name : string , value : string | Blob , fileName? : string ) : void ;
delete ( name : string ) : void ;
get ( name : string ) : FormDataEntryValue | null ;
getAll ( name : string ) : FormDataEntryValue [ ] ;
has ( name : string ) : boolean ;
set ( name : string , value : string | Blob , fileName? : string ) : void ;
}
declare const FormData : {
prototype : FormData ;
// TODO(ry) FormData constructor is non-standard.
// new(form?: HTMLFormElement): FormData;
new ( ) : FormData ;
} ;
interface Body {
/** A simple getter used to expose a `ReadableStream` of the body contents. */
readonly body : ReadableStream < Uint8Array > | null ;
/ * * S t o r e s a ` B o o l e a n ` t h a t d e c l a r e s w h e t h e r t h e b o d y h a s b e e n u s e d i n a
* response yet .
* /
readonly bodyUsed : boolean ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with an ` ArrayBuffer ` .
* /
arrayBuffer ( ) : Promise < ArrayBuffer > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with a ` Blob ` .
* /
blob ( ) : Promise < Blob > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with a ` FormData ` object .
* /
formData ( ) : Promise < FormData > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with the result of parsing the body text as JSON .
* /
json ( ) : Promise < any > ;
/ * * T a k e s a ` R e s p o n s e ` s t r e a m a n d r e a d s i t t o c o m p l e t i o n . I t r e t u r n s a p r o m i s e
* that resolves with a ` USVString ` ( text ) .
* /
text ( ) : Promise < string > ;
}
type HeadersInit = Headers | string [ ] [ ] | Record < string , string > ;
/ * * T h i s F e t c h A P I i n t e r f a c e a l l o w s y o u t o p e r f o r m v a r i o u s a c t i o n s o n H T T P
* request and response headers . These actions include retrieving , setting ,
* adding to , and removing . A Headers object has an associated header list ,
* which is initially empty and consists of zero or more name and value pairs .
* You can add to this using methods like append ( ) ( see Examples . ) In all
* methods of this interface , header names are matched by case - insensitive byte
* sequence . * /
interface Headers {
append ( name : string , value : string ) : void ;
delete ( name : string ) : void ;
get ( name : string ) : string | null ;
has ( name : string ) : boolean ;
set ( name : string , value : string ) : void ;
forEach (
callbackfn : ( value : string , key : string , parent : Headers ) = > void ,
thisArg? : any
) : void ;
2020-01-24 14:15:01 -05:00
}
2020-04-10 14:24:42 -04:00
interface Headers extends DomIterable < string , string > {
2020-04-10 09:51:17 -04:00
/ * * A p p e n d s a n e w v a l u e o n t o a n e x i s t i n g h e a d e r i n s i d e a ` H e a d e r s ` o b j e c t , o r
* adds the header if it does not already exist .
* /
append ( name : string , value : string ) : void ;
/** Deletes a header from a `Headers` object. */
delete ( name : string ) : void ;
/ * * R e t u r n s a n i t e r a t o r a l l o w i n g t o g o t h r o u g h a l l k e y / v a l u e p a i r s
* contained in this Headers object . The both the key and value of each pairs
* are ByteString objects .
* /
entries ( ) : IterableIterator < [ string , string ] > ;
/ * * R e t u r n s a ` B y t e S t r i n g ` s e q u e n c e o f a l l t h e v a l u e s o f a h e a d e r w i t h i n a
* ` Headers ` object with a given name .
* /
get ( name : string ) : string | null ;
/ * * R e t u r n s a b o o l e a n s t a t i n g w h e t h e r a ` H e a d e r s ` o b j e c t c o n t a i n s a c e r t a i n
* header .
* /
has ( name : string ) : boolean ;
/ * * R e t u r n s a n i t e r a t o r a l l o w i n g t o g o t h r o u g h a l l k e y s c o n t a i n e d i n
* this Headers object . The keys are ByteString objects .
* /
keys ( ) : IterableIterator < string > ;
/ * * S e t s a n e w v a l u e f o r a n e x i s t i n g h e a d e r i n s i d e a H e a d e r s o b j e c t , o r a d d s
* the header if it does not already exist .
* /
set ( name : string , value : string ) : void ;
/ * * R e t u r n s a n i t e r a t o r a l l o w i n g t o g o t h r o u g h a l l v a l u e s c o n t a i n e d i n
* this Headers object . The values are ByteString objects .
* /
values ( ) : IterableIterator < string > ;
forEach (
callbackfn : ( value : string , key : string , parent : this ) = > void ,
thisArg? : any
) : void ;
/ * * T h e S y m b o l . i t e r a t o r w e l l - k n o w n s y m b o l s p e c i f i e s t h e d e f a u l t
* iterator for this Headers object
* /
[ Symbol . iterator ] ( ) : IterableIterator < [ string , string ] > ;
}
declare const Headers : {
prototype : Headers ;
new ( init? : HeadersInit ) : Headers ;
} ;
type RequestInfo = Request | string ;
type RequestCache =
| "default"
| "force-cache"
| "no-cache"
| "no-store"
| "only-if-cached"
| "reload" ;
type RequestCredentials = "include" | "omit" | "same-origin" ;
type RequestMode = "cors" | "navigate" | "no-cors" | "same-origin" ;
type RequestRedirect = "error" | "follow" | "manual" ;
type ReferrerPolicy =
| ""
| "no-referrer"
| "no-referrer-when-downgrade"
| "origin"
| "origin-when-cross-origin"
| "same-origin"
| "strict-origin"
| "strict-origin-when-cross-origin"
| "unsafe-url" ;
type BodyInit =
| Blob
| BufferSource
| FormData
| URLSearchParams
| ReadableStream < Uint8Array >
| string ;
type RequestDestination =
| ""
| "audio"
| "audioworklet"
| "document"
| "embed"
| "font"
| "image"
| "manifest"
| "object"
| "paintworklet"
| "report"
| "script"
| "sharedworker"
| "style"
| "track"
| "video"
| "worker"
| "xslt" ;
interface RequestInit {
/ * *
* A BodyInit object or null to set request ' s body .
* /
body? : BodyInit | null ;
/ * *
* A string indicating how the request will interact with the browser ' s cache
* to set request ' s cache .
* /
cache? : RequestCache ;
/ * *
* A string indicating whether credentials will be sent with the request
* always , never , or only when sent to a same - origin URL . Sets request ' s
* credentials .
* /
credentials? : RequestCredentials ;
/ * *
* A Headers object , an object literal , or an array of two - item arrays to set
* request ' s headers .
* /
headers? : HeadersInit ;
/ * *
* A cryptographic hash of the resource to be fetched by request . Sets
* request ' s integrity .
* /
integrity? : string ;
/ * *
* A boolean to set request ' s keepalive .
* /
keepalive? : boolean ;
/ * *
* A string to set request ' s method .
* /
method? : string ;
/ * *
* A string to indicate whether the request will use CORS , or will be
* restricted to same - origin URLs . Sets request ' s mode .
* /
mode? : RequestMode ;
/ * *
* A string indicating whether request follows redirects , results in an error
* upon encountering a redirect , or returns the redirect ( in an opaque
* fashion ) . Sets request ' s redirect .
* /
redirect? : RequestRedirect ;
/ * *
* A string whose value is a same - origin URL , "about:client" , or the empty
* string , to set request ' s referrer .
* /
referrer? : string ;
/ * *
* A referrer policy to set request ' s referrerPolicy .
* /
referrerPolicy? : ReferrerPolicy ;
/ * *
* An AbortSignal to set request ' s signal .
* /
signal? : AbortSignal | null ;
/ * *
* Can only be null . Used to disassociate request from any Window .
* /
window ? : any ;
}
/** This Fetch API interface represents a resource request. */
interface Request extends Body {
/ * *
* Returns the cache mode associated with request , which is a string
* indicating how the request will interact with the browser ' s cache when
* fetching .
* /
readonly cache : RequestCache ;
/ * *
* Returns the credentials mode associated with request , which is a string
* indicating whether credentials will be sent with the request always , never ,
* or only when sent to a same - origin URL .
* /
readonly credentials : RequestCredentials ;
/ * *
* Returns the kind of resource requested by request , e . g . , "document" or "script" .
* /
readonly destination : RequestDestination ;
/ * *
* Returns a Headers object consisting of the headers associated with request .
* Note that headers added in the network layer by the user agent will not be
* accounted for in this object , e . g . , the "Host" header .
* /
readonly headers : Headers ;
/ * *
* Returns request ' s subresource integrity metadata , which is a cryptographic
* hash of the resource being fetched . Its value consists of multiple hashes
* separated by whitespace . [ SRI ]
* /
readonly integrity : string ;
/ * *
* Returns a boolean indicating whether or not request is for a history
2020-05-14 02:58:48 -04:00
* navigation ( a . k . a . back - forward navigation ) .
2020-04-10 09:51:17 -04:00
* /
readonly isHistoryNavigation : boolean ;
/ * *
* Returns a boolean indicating whether or not request is for a reload
* navigation .
* /
readonly isReloadNavigation : boolean ;
/ * *
* Returns a boolean indicating whether or not request can outlive the global
* in which it was created .
* /
readonly keepalive : boolean ;
/ * *
* Returns request ' s HTTP method , which is "GET" by default .
* /
readonly method : string ;
/ * *
* Returns the mode associated with request , which is a string indicating
* whether the request will use CORS , or will be restricted to same - origin
* URLs .
* /
readonly mode : RequestMode ;
/ * *
* Returns the redirect mode associated with request , which is a string
* indicating how redirects for the request will be handled during fetching . A
* request will follow redirects by default .
* /
readonly redirect : RequestRedirect ;
/ * *
* Returns the referrer of request . Its value can be a same - origin URL if
* explicitly set in init , the empty string to indicate no referrer , and
* "about:client" when defaulting to the global ' s default . This is used during
* fetching to determine the value of the ` Referer ` header of the request
* being made .
* /
readonly referrer : string ;
/ * *
* Returns the referrer policy associated with request . This is used during
* fetching to compute the value of the request ' s referrer .
* /
readonly referrerPolicy : ReferrerPolicy ;
/ * *
* Returns the signal associated with request , which is an AbortSignal object
* indicating whether or not request has been aborted , and its abort event
* handler .
* /
readonly signal : AbortSignal ;
/ * *
* Returns the URL of request as a string .
* /
readonly url : string ;
clone ( ) : Request ;
}
declare const Request : {
prototype : Request ;
new ( input : RequestInfo , init? : RequestInit ) : Request ;
} ;
2020-05-25 12:55:16 -04:00
interface ResponseInit {
headers? : HeadersInit ;
status? : number ;
statusText? : string ;
}
2020-04-10 09:51:17 -04:00
type ResponseType =
| "basic"
| "cors"
| "default"
| "error"
| "opaque"
| "opaqueredirect" ;
/** This Fetch API interface represents the response to a request. */
interface Response extends Body {
readonly headers : Headers ;
readonly ok : boolean ;
readonly redirected : boolean ;
readonly status : number ;
readonly statusText : string ;
readonly trailer : Promise < Headers > ;
readonly type : ResponseType ;
readonly url : string ;
clone ( ) : Response ;
}
declare const Response : {
prototype : Response ;
2020-05-25 12:55:16 -04:00
new ( body? : BodyInit | null , init? : ResponseInit ) : Response ;
2020-04-10 09:51:17 -04:00
error ( ) : Response ;
redirect ( url : string , status? : number ) : Response ;
} ;
2020-05-30 11:19:16 -04:00
/ * * F e t c h a r e s o u r c e f r o m t h e n e t w o r k . I t r e t u r n s a P r o m i s e t h a t r e s o l v e s t o t h e
* Response to that request , whether it is successful or not .
*
* const response = await fetch ( "http://my.json.host/data.json" ) ;
* console . log ( response . status ) ; // e.g. 200
* console . log ( response . statusText ) ; // e.g. "OK"
* const jsonData = await response . json ( ) ;
* /
2020-04-10 09:51:17 -04:00
declare function fetch (
input : Request | URL | string ,
init? : RequestInit
) : Promise < Response > ;
2020-05-30 11:19:16 -04:00
/ * * D e c o d e s a s t r i n g o f d a t a w h i c h h a s b e e n e n c o d e d u s i n g b a s e - 6 4 e n c o d i n g .
*
* console . log ( atob ( "aGVsbG8gd29ybGQ=" ) ) ; // outputs 'hello world'
* /
2020-04-07 13:27:37 -04:00
declare function atob ( s : string ) : string ;
2020-05-30 11:19:16 -04:00
/ * * C r e a t e s a b a s e - 6 4 A S C I I e n c o d e d s t r i n g f r o m t h e i n p u t s t r i n g .
*
* console . log ( btoa ( "hello world" ) ) ; // outputs "aGVsbG8gd29ybGQ="
* /
2020-04-07 13:27:37 -04:00
declare function btoa ( s : string ) : string ;
declare class TextDecoder {
/** Returns encoding's name, lowercased. */
readonly encoding : string ;
/** Returns `true` if error mode is "fatal", and `false` otherwise. */
readonly fatal : boolean ;
/** Returns `true` if ignore BOM flag is set, and `false` otherwise. */
readonly ignoreBOM = false ;
constructor (
label? : string ,
options ? : { fatal? : boolean ; ignoreBOM? : boolean }
) ;
/** Returns the result of running encoding's decoder. */
2020-04-08 13:21:04 -04:00
decode ( input? : BufferSource , options ? : { stream? : false } ) : string ;
2020-04-07 13:27:37 -04:00
readonly [ Symbol . toStringTag ] : string ;
}
declare class TextEncoder {
/** Returns "utf-8". */
readonly encoding = "utf-8" ;
/** Returns the result of running UTF-8's encoder. */
encode ( input? : string ) : Uint8Array ;
encodeInto (
input : string ,
dest : Uint8Array
) : { read : number ; written : number } ;
readonly [ Symbol . toStringTag ] : string ;
2020-01-24 14:15:01 -05:00
}
2020-04-07 17:11:38 -04:00
interface URLSearchParams {
/ * * A p p e n d s a s p e c i f i e d k e y / v a l u e p a i r a s a n e w s e a r c h p a r a m e t e r .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* let searchParams = new URLSearchParams ( ) ;
* searchParams . append ( 'name' , 'first' ) ;
* searchParams . append ( 'name' , 'second' ) ;
* ` ` `
2020-04-07 17:11:38 -04:00
* /
append ( name : string , value : string ) : void ;
2020-04-08 10:32:08 -04:00
2020-04-07 17:11:38 -04:00
/ * * D e l e t e s t h e g i v e n s e a r c h p a r a m e t e r a n d i t s a s s o c i a t e d v a l u e ,
* from the list of all search parameters .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* let searchParams = new URLSearchParams ( [ [ 'name' , 'value' ] ] ) ;
* searchParams . delete ( 'name' ) ;
* ` ` `
2020-04-07 17:11:38 -04:00
* /
delete ( name : string ) : void ;
2020-04-08 10:32:08 -04:00
2020-04-07 17:11:38 -04:00
/ * * R e t u r n s a l l t h e v a l u e s a s s o c i a t e d w i t h a g i v e n s e a r c h p a r a m e t e r
* as an array .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* searchParams . getAll ( 'name' ) ;
* ` ` `
2020-04-07 17:11:38 -04:00
* /
getAll ( name : string ) : string [ ] ;
2020-04-08 10:32:08 -04:00
2020-04-07 17:11:38 -04:00
/ * * R e t u r n s t h e f i r s t v a l u e a s s o c i a t e d t o t h e g i v e n s e a r c h p a r a m e t e r .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* searchParams . get ( 'name' ) ;
* ` ` `
2020-04-07 17:11:38 -04:00
* /
get ( name : string ) : string | null ;
2020-04-08 10:32:08 -04:00
2020-04-07 17:11:38 -04:00
/ * * R e t u r n s a B o o l e a n t h a t i n d i c a t e s w h e t h e r a p a r a m e t e r w i t h t h e
* specified name exists .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* searchParams . has ( 'name' ) ;
* ` ` `
2020-04-07 17:11:38 -04:00
* /
has ( name : string ) : boolean ;
2020-04-08 10:32:08 -04:00
2020-04-07 17:11:38 -04:00
/ * * S e t s t h e v a l u e a s s o c i a t e d w i t h a g i v e n s e a r c h p a r a m e t e r t o t h e
* given value . If there were several matching values , this method
* deletes the others . If the search parameter doesn ' t exist , this
* method creates it .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* searchParams . set ( 'name' , 'value' ) ;
* ` ` `
2020-04-07 17:11:38 -04:00
* /
set ( name : string , value : string ) : void ;
2020-04-08 10:32:08 -04:00
2020-04-07 17:11:38 -04:00
/ * * S o r t a l l k e y / v a l u e p a i r s c o n t a i n e d i n t h i s o b j e c t i n p l a c e a n d
* return undefined . The sort order is according to Unicode code
* points of the keys .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* searchParams . sort ( ) ;
* ` ` `
2020-04-07 17:11:38 -04:00
* /
sort ( ) : void ;
2020-04-08 10:32:08 -04:00
2020-04-07 17:11:38 -04:00
/ * * C a l l s a f u n c t i o n f o r e a c h e l e m e n t c o n t a i n e d i n t h i s o b j e c t i n
* place and return undefined . Optionally accepts an object to use
* as this when executing callback as second argument .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* const params = new URLSearchParams ( [ [ "a" , "b" ] , [ "c" , "d" ] ] ) ;
* params . forEach ( ( value , key , parent ) = > {
* console . log ( value , key , parent ) ;
* } ) ;
* ` ` `
2020-04-07 17:11:38 -04:00
*
* /
forEach (
callbackfn : ( value : string , key : string , parent : this ) = > void ,
thisArg? : any
) : void ;
2020-04-08 10:32:08 -04:00
2020-04-07 17:11:38 -04:00
/ * * R e t u r n s a n i t e r a t o r a l l o w i n g t o g o t h r o u g h a l l k e y s c o n t a i n e d
* in this object .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* const params = new URLSearchParams ( [ [ "a" , "b" ] , [ "c" , "d" ] ] ) ;
* for ( const key of params . keys ( ) ) {
* console . log ( key ) ;
* }
* ` ` `
2020-04-07 17:11:38 -04:00
* /
keys ( ) : IterableIterator < string > ;
2020-04-08 10:32:08 -04:00
2020-04-07 17:11:38 -04:00
/ * * R e t u r n s a n i t e r a t o r a l l o w i n g t o g o t h r o u g h a l l v a l u e s c o n t a i n e d
* in this object .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* const params = new URLSearchParams ( [ [ "a" , "b" ] , [ "c" , "d" ] ] ) ;
* for ( const value of params . values ( ) ) {
* console . log ( value ) ;
* }
* ` ` `
2020-04-07 17:11:38 -04:00
* /
values ( ) : IterableIterator < string > ;
2020-04-08 10:32:08 -04:00
2020-04-07 17:11:38 -04:00
/ * * R e t u r n s a n i t e r a t o r a l l o w i n g t o g o t h r o u g h a l l k e y / v a l u e
* pairs contained in this object .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* const params = new URLSearchParams ( [ [ "a" , "b" ] , [ "c" , "d" ] ] ) ;
* for ( const [ key , value ] of params . entries ( ) ) {
* console . log ( key , value ) ;
* }
* ` ` `
2020-04-07 17:11:38 -04:00
* /
entries ( ) : IterableIterator < [ string , string ] > ;
2020-04-08 10:32:08 -04:00
2020-04-07 17:11:38 -04:00
/ * * R e t u r n s a n i t e r a t o r a l l o w i n g t o g o t h r o u g h a l l k e y / v a l u e
* pairs contained in this object .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* const params = new URLSearchParams ( [ [ "a" , "b" ] , [ "c" , "d" ] ] ) ;
* for ( const [ key , value ] of params ) {
* console . log ( key , value ) ;
* }
* ` ` `
2020-04-07 17:11:38 -04:00
* /
[ Symbol . iterator ] ( ) : IterableIterator < [ string , string ] > ;
2020-04-08 10:32:08 -04:00
2020-04-07 17:11:38 -04:00
/ * * R e t u r n s a q u e r y s t r i n g s u i t a b l e f o r u s e i n a U R L .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* searchParams . toString ( ) ;
* ` ` `
2020-04-07 17:11:38 -04:00
* /
toString ( ) : string ;
2020-01-24 14:15:01 -05:00
}
2020-04-07 17:11:38 -04:00
declare const URLSearchParams : {
prototype : URLSearchParams ;
new (
init? : string [ ] [ ] | Record < string , string > | string | URLSearchParams
) : URLSearchParams ;
toString ( ) : string ;
} ;
/** The URL interface represents an object providing static methods used for creating object URLs. */
interface URL {
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 ;
2020-01-24 14:15:01 -05:00
}
2020-04-07 17:11:38 -04:00
declare const URL : {
prototype : URL ;
2020-05-18 08:46:56 -04:00
new ( url : string | URL , base? : string | URL ) : URL ;
2020-04-07 17:11:38 -04:00
createObjectURL ( object : any ) : string ;
revokeObjectURL ( url : string ) : void ;
} ;
2020-04-13 12:34:32 -04:00
interface MessageEventInit extends EventInit {
data? : any ;
origin? : string ;
lastEventId? : string ;
}
declare class MessageEvent extends Event {
readonly data : any ;
readonly origin : string ;
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 ) ;
}
2020-04-13 10:48:12 -04:00
interface PostMessageOptions {
transfer? : any [ ] ;
}
2020-04-13 12:34:32 -04:00
declare class Worker extends EventTarget {
onerror ? : ( e : ErrorEvent ) = > void ;
onmessage ? : ( e : MessageEvent ) = > void ;
onmessageerror ? : ( e : MessageEvent ) = > void ;
2020-04-07 15:03:14 -04:00
constructor (
specifier : string ,
options ? : {
type ? : "classic" | "module" ;
name? : string ;
2020-04-16 17:40:29 -04:00
/ * * U N S T A B L E : N e w A P I . E x p e c t m a n y c h a n g e s ; m o s t l i k e l y t h i s
* 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 :
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* // mod.ts
* const worker = new Worker ( "./deno_worker.ts" , { type : "module" , deno : true } ) ;
* worker . postMessage ( { cmd : "readFile" , fileName : "./log.txt" } ) ;
2020-04-16 17:40:29 -04:00
*
2020-05-16 15:23:48 -04:00
* // deno_worker.ts
2020-04-16 17:40:29 -04:00
*
*
2020-05-16 15:23:48 -04:00
* 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 ) ;
* }
* ` ` `
2020-04-16 17:40:29 -04:00
*
2020-05-16 15:23:48 -04:00
* // log.txt
* hello world
* hello world 2
*
* // run program
* $ deno run -- allow - read mod . ts
* hello world
* hello world2
2020-04-16 17:40:29 -04:00
*
* /
deno? : boolean ;
2020-04-07 15:03:14 -04:00
}
) ;
2020-04-13 10:48:12 -04:00
postMessage ( message : any , transfer : ArrayBuffer [ ] ) : void ;
postMessage ( message : any , options? : PostMessageOptions ) : void ;
2020-04-07 15:03:14 -04:00
terminate ( ) : void ;
2020-01-24 14:15:01 -05:00
}
2020-04-07 13:27:37 -04:00
declare namespace performance {
/ * * R e t u r n s a c u r r e n t t i m e f r o m D e n o ' s s t a r t i n m i l l i s e c o n d s .
*
2020-05-30 11:19:16 -04:00
* Use the permission flag ` --allow-hrtime ` return a precise value .
2020-04-07 13:27:37 -04:00
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* const t = performance . now ( ) ;
* console . log ( ` ${ t } ms since start! ` ) ;
* ` ` `
2020-04-07 13:27:37 -04:00
* /
export function now ( ) : number ;
2020-01-24 14:15:01 -05:00
}
2020-04-11 11:42:02 -04:00
interface EventInit {
bubbles? : boolean ;
cancelable? : boolean ;
composed? : boolean ;
}
2020-04-09 06:03:44 -04:00
/** An event which takes place in the DOM. */
2020-04-11 11:42:02 -04:00
declare class Event {
constructor ( type : string , eventInitDict? : EventInit ) ;
/ * * R e t u r n s t r u e o r f a l s e d e p e n d i n g o n h o w e v e n t w a s i n i t i a l i z e d . T r u e i f
2020-04-09 06:03:44 -04:00
* event goes through its target ' s ancestors in reverse tree order , and
2020-04-11 11:42:02 -04:00
* false otherwise . * /
2020-04-09 06:03:44 -04:00
readonly bubbles : boolean ;
cancelBubble : boolean ;
2020-04-11 11:42:02 -04:00
/ * * R e t u r n s t r u e o r f a l s e d e p e n d i n g o n h o w e v e n t w a s i n i t i a l i z e d . I t s r e t u r n
* value does not always carry meaning , but true can indicate that part of the
* operation during which event was dispatched , can be canceled by invoking
* the preventDefault ( ) method . * /
2020-04-09 06:03:44 -04:00
readonly cancelable : boolean ;
2020-04-11 11:42:02 -04:00
/ * * R e t u r n s t r u e o r f a l s e d e p e n d i n g o n h o w e v e n t w a s i n i t i a l i z e d . T r u e i f
2020-04-09 06:03:44 -04:00
* event invokes listeners past a ShadowRoot node that is the root of its
2020-04-11 11:42:02 -04:00
* target , and false otherwise . * /
2020-04-09 06:03:44 -04:00
readonly composed : boolean ;
2020-04-11 11:42:02 -04:00
/ * * R e t u r n s t h e o b j e c t w h o s e e v e n t l i s t e n e r ' s c a l l b a c k i s c u r r e n t l y b e i n g
* invoked . * /
2020-04-09 06:03:44 -04:00
readonly currentTarget : EventTarget | null ;
2020-04-11 11:42:02 -04:00
/ * * R e t u r n s t r u e i f p r e v e n t D e f a u l t ( ) w a s i n v o k e d s u c c e s s f u l l y t o i n d i c a t e
* cancellation , and false otherwise . * /
2020-04-09 06:03:44 -04:00
readonly defaultPrevented : boolean ;
2020-04-11 11:42:02 -04:00
/ * * R e t u r n s t h e e v e n t ' s p h a s e , w h i c h i s o n e o f N O N E , C A P T U R I N G _ P H A S E ,
* AT_TARGET , and BUBBLING_PHASE . * /
2020-04-09 06:03:44 -04:00
readonly eventPhase : number ;
2020-04-11 11:42:02 -04:00
/ * * R e t u r n s t r u e i f e v e n t w a s d i s p a t c h e d b y t h e u s e r a g e n t , a n d f a l s e
* otherwise . * /
2020-04-09 06:03:44 -04:00
readonly isTrusted : boolean ;
2020-04-11 11:42:02 -04:00
/** Returns the object to which event is dispatched (its target). */
2020-04-09 06:03:44 -04:00
readonly target : EventTarget | null ;
2020-04-11 11:42:02 -04:00
/ * * R e t u r n s t h e e v e n t ' s t i m e s t a m p a s t h e n u m b e r o f m i l l i s e c o n d s m e a s u r e d
* relative to the time origin . * /
2020-04-09 06:03:44 -04:00
readonly timeStamp : number ;
2020-04-11 11:42:02 -04:00
/** Returns the type of event, e.g. "click", "hashchange", or "submit". */
2020-04-09 06:03:44 -04:00
readonly type : string ;
2020-04-11 11:42:02 -04:00
/ * * R e t u r n s t h e i n v o c a t i o n t a r g e t o b j e c t s o f e v e n t ' s p a t h ( o b j e c t s o n w h i c h
2020-04-09 06:03:44 -04:00
* listeners will be invoked ) , except for any nodes in shadow trees of which
* the shadow root 's mode is "closed" that are not reachable from event' s
2020-04-11 11:42:02 -04:00
* currentTarget . * /
2020-04-09 06:03:44 -04:00
composedPath ( ) : EventTarget [ ] ;
2020-04-11 11:42:02 -04:00
/ * * I f i n v o k e d w h e n t h e c a n c e l a b l e a t t r i b u t e v a l u e i s t r u e , a n d w h i l e
2020-04-09 06:03:44 -04:00
* executing a listener for the event with passive set to false , signals to
* the operation that caused event to be dispatched that it needs to be
2020-04-11 11:42:02 -04:00
* canceled . * /
2020-04-09 06:03:44 -04:00
preventDefault ( ) : void ;
2020-04-11 11:42:02 -04:00
/ * * I n v o k i n g t h i s m e t h o d p r e v e n t s e v e n t f r o m r e a c h i n g a n y r e g i s t e r e d e v e n t
* listeners after the current one finishes running and , when dispatched in a
* tree , also prevents event from reaching any other objects . * /
2020-04-09 06:03:44 -04:00
stopImmediatePropagation ( ) : void ;
2020-04-11 11:42:02 -04:00
/ * * W h e n d i s p a t c h e d i n a t r e e , i n v o k i n g t h i s m e t h o d p r e v e n t s e v e n t f r o m
* reaching any objects other than the current object . * /
2020-04-09 06:03:44 -04:00
stopPropagation ( ) : void ;
readonly AT_TARGET : number ;
readonly BUBBLING_PHASE : number ;
readonly CAPTURING_PHASE : number ;
readonly NONE : number ;
2020-04-11 11:42:02 -04:00
static readonly AT_TARGET : number ;
static readonly BUBBLING_PHASE : number ;
static readonly CAPTURING_PHASE : number ;
static readonly NONE : number ;
2020-04-09 06:03:44 -04:00
}
/ * *
* EventTarget is a DOM interface implemented by objects that can receive events
* and may have listeners for them .
* /
2020-04-11 11:42:02 -04:00
declare class EventTarget {
/ * * A p p e n d s a n e v e n t l i s t e n e r f o r e v e n t s w h o s e t y p e a t t r i b u t e v a l u e i s t y p e .
2020-04-09 06:03:44 -04:00
* The callback argument sets the callback that will be invoked when the event
* is dispatched .
*
* The options argument sets listener - specific options . For compatibility this
* can be a boolean , in which case the method behaves exactly as if the value
* was specified as options ' s capture .
*
* When set to true , options ' s capture prevents callback from being invoked
* when the event ' s eventPhase attribute value is BUBBLING_PHASE . When false
* ( or not present ) , callback will not be invoked when event ' s eventPhase
* attribute value is CAPTURING_PHASE . Either way , callback will be invoked if
* event ' s eventPhase attribute value is AT_TARGET .
*
* When set to true , options ' s passive indicates that the callback will not
* cancel the event by invoking preventDefault ( ) . This is used to enable
* performance optimizations described in § 2.8 Observing event listeners .
*
* When set to true , options ' s once indicates that the callback will only be
* invoked once after which the event listener will be removed .
*
* The event listener is appended to target ' s event listener list and is not
2020-04-11 11:42:02 -04:00
* appended if it has the same type , callback , and capture . * /
2020-04-09 06:03:44 -04:00
addEventListener (
type : string ,
listener : EventListenerOrEventListenerObject | null ,
options? : boolean | AddEventListenerOptions
) : void ;
2020-04-11 11:42:02 -04:00
/ * * D i s p a t c h e s a s y n t h e t i c e v e n t e v e n t t o t a r g e t a n d r e t u r n s t r u e i f e i t h e r
2020-04-09 06:03:44 -04:00
* event ' s cancelable attribute value is false or its preventDefault ( ) method
2020-04-11 11:42:02 -04:00
* was not invoked , and false otherwise . * /
2020-04-09 06:03:44 -04:00
dispatchEvent ( event : Event ) : boolean ;
2020-04-11 11:42:02 -04:00
/ * * R e m o v e s t h e e v e n t l i s t e n e r i n t a r g e t ' s e v e n t l i s t e n e r l i s t w i t h t h e s a m e
* type , callback , and options . * /
2020-04-09 06:03:44 -04:00
removeEventListener (
type : string ,
callback : EventListenerOrEventListenerObject | null ,
options? : EventListenerOptions | boolean
) : void ;
2020-04-11 11:42:02 -04:00
[ Symbol . toStringTag ] : string ;
2020-04-09 06:03:44 -04:00
}
interface EventListener {
2020-04-11 11:42:02 -04:00
( evt : Event ) : void | Promise < void > ;
2020-04-09 06:03:44 -04:00
}
interface EventListenerObject {
2020-04-11 11:42:02 -04:00
handleEvent ( evt : Event ) : void | Promise < void > ;
2020-04-09 06:03:44 -04:00
}
declare type EventListenerOrEventListenerObject =
| EventListener
| EventListenerObject ;
interface AddEventListenerOptions extends EventListenerOptions {
once? : boolean ;
passive? : boolean ;
}
interface EventListenerOptions {
capture? : boolean ;
}
/ * * E v e n t s m e a s u r i n g p r o g r e s s o f a n u n d e r l y i n g p r o c e s s , l i k e a n H T T P r e q u e s t
* ( for an XMLHttpRequest , or the loading of the underlying resource of an
* < img > , < audio > , < video > , < style > or < link > ) . * /
interface ProgressEvent < T extends EventTarget = EventTarget > extends Event {
readonly lengthComputable : boolean ;
readonly loaded : number ;
readonly target : T | null ;
readonly total : number ;
}
interface CustomEventInit < T = any > extends EventInit {
detail? : T ;
}
2020-04-11 11:42:02 -04:00
declare class CustomEvent < T = any > extends Event {
constructor ( typeArg : string , eventInitDict? : CustomEventInit < T > ) ;
/ * * R e t u r n s a n y c u s t o m d a t a e v e n t w a s c r e a t e d w i t h . T y p i c a l l y u s e d f o r
* synthetic events . * /
readonly detail : T ;
}
2020-04-10 09:51:17 -04:00
2020-04-15 10:10:49 -04:00
/ * * A c o n t r o l l e r o b j e c t t h a t a l l o w s y o u t o a b o r t o n e o r m o r e D O M r e q u e s t s a s a n d
* when desired . * /
declare class AbortController {
/** Returns the AbortSignal object associated with this object. */
readonly signal : AbortSignal ;
/ * * I n v o k i n g t h i s m e t h o d w i l l s e t t h i s o b j e c t ' s A b o r t S i g n a l ' s a b o r t e d f l a g a n d
* signal to any observers that the associated activity is to be aborted . * /
abort ( ) : void ;
}
2020-04-10 09:51:17 -04:00
interface AbortSignalEventMap {
abort : Event ;
}
/ * * A s i g n a l o b j e c t t h a t a l l o w s y o u t o c o m m u n i c a t e w i t h a D O M r e q u e s t ( s u c h a s a
* Fetch ) and abort it if required via an AbortController object . * /
interface AbortSignal extends EventTarget {
2020-04-15 10:10:49 -04:00
/ * * R e t u r n s t r u e i f t h i s A b o r t S i g n a l ' s A b o r t C o n t r o l l e r h a s s i g n a l e d t o a b o r t ,
* and false otherwise . * /
2020-04-10 09:51:17 -04:00
readonly aborted : boolean ;
onabort : ( ( this : AbortSignal , ev : Event ) = > any ) | null ;
addEventListener < K extends keyof AbortSignalEventMap > (
type : K ,
listener : ( this : AbortSignal , ev : AbortSignalEventMap [ K ] ) = > any ,
options? : boolean | AddEventListenerOptions
) : void ;
addEventListener (
type : string ,
listener : EventListenerOrEventListenerObject ,
options? : boolean | AddEventListenerOptions
) : void ;
removeEventListener < K extends keyof AbortSignalEventMap > (
type : K ,
listener : ( this : AbortSignal , ev : AbortSignalEventMap [ K ] ) = > any ,
options? : boolean | EventListenerOptions
) : void ;
removeEventListener (
type : string ,
listener : EventListenerOrEventListenerObject ,
options? : boolean | EventListenerOptions
) : void ;
}
declare const AbortSignal : {
prototype : AbortSignal ;
new ( ) : AbortSignal ;
} ;
2020-05-29 08:02:36 -04:00
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.
}