Platform
Functions
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.
Interfaces
A controller object that allows you to abort one or more DOM requests as and when desired.
A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object.
- ABORT_ERR
- DATA_CLONE_ERR
- DOMSTRING_SIZE_ERR
- HIERARCHY_REQUEST_ERR
- INDEX_SIZE_ERR
- INUSE_ATTRIBUTE_ERR
- INVALID_ACCESS_ERR
- INVALID_CHARACTER_ERR
- INVALID_MODIFICATION_ERR
- INVALID_NODE_TYPE_ERR
- INVALID_STATE_ERR
- NAMESPACE_ERR
- NETWORK_ERR
- NOT_FOUND_ERR
- NOT_SUPPORTED_ERR
- NO_DATA_ALLOWED_ERR
- NO_MODIFICATION_ALLOWED_ERR
- QUOTA_EXCEEDED_ERR
- SECURITY_ERR
- SYNTAX_ERR
- TIMEOUT_ERR
- TYPE_MISMATCH_ERR
- URL_MISMATCH_ERR
- VALIDATION_ERR
- WRONG_DOCUMENT_ERR
- code
- message
- name
- prototype
Options that control structured serialization operations such as
structuredClone(value, options) and MessagePort.postMessage(message, options).
Represents the global window object in the Deno runtime environment.
Defines the mapping between event names and their corresponding event types
for the Window interface in Deno.
Type Aliases
function alert
#alert(message?: string): voidShows the given message and waits for the enter key pressed.
If the stdin is not interactive, it does nothing.
Examples #
// Displays the message "Acknowledge me! [Enter]" and waits for the enter key to be pressed before continuing.
alert("Acknowledge me!");
Parameters #
#message: string Return Type #
void See #
function close
#close(): voidExits the current Deno process.
This function terminates the process by signaling the runtime to exit.
Similar to exit(0) in posix. Its behavior is similar to the window.close()
method in the browser, but specific to the Deno runtime.
Note: Use this function cautiously, as it will stop the execution of the entire Deno program immediately.
Examples #
console.log("About to close the Deno process.");
close(); // The process will terminate here.
console.log("This will not be logged."); // This line will never execute.
Return Type #
void See #
function confirm
#confirm(message?: string): booleanShows the given message and waits for the answer. Returns the user's answer as boolean.
Only y and Y are considered as true.
If the stdin is not interactive, it returns false.
Examples #
const shouldProceed = confirm("Do you want to proceed?");
// If the user presses 'y' or 'Y', the result will be true
// If the user presses 'n' or 'N', the result will be false
console.log("Should proceed?", shouldProceed);
Parameters #
#message: string Return Type #
boolean See #
function prompt
#prompt(message?: string,defaultValue?: string,): string | nullShows the given message and waits for the user's input. Returns the user's input as string.
If the default value is given and the user inputs the empty string, then it returns the given default value.
If the default value is not given and the user inputs the empty string, it returns the empty string.
If the stdin is not interactive, it returns null.
Examples #
const pet = prompt("Cats or dogs?", "It's fine to love both!");
// Displays the user's input or the default value of "It's fine to love both!"
console.log("Best pet:", pet);
Parameters #
Return Type #
string | null See #
function queueMicrotask
#queueMicrotask(func: VoidFunction): voidA 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'); });
Parameters #
#func: VoidFunction Return Type #
void function reportError
#reportError(error: any): voidDispatch an uncaught exception. Similar to a synchronous version of:
setTimeout(() => { throw error; }, 0);
The error can not be caught with a try/catch block. An error event will
be dispatched to the global scope. You can prevent the error from being
reported to the console with Event.prototype.preventDefault():
addEventListener("error", (event) => {
event.preventDefault();
});
reportError(new Error("foo")); // Will not be reported.
In Deno, this error will terminate the process if not intercepted like above.
Parameters #
#error: any Return Type #
void function structuredClone
#structuredClone<T = any>(value: T,options?: StructuredSerializeOptions,): TCreates a deep copy of a given value using the structured clone algorithm.
Unlike a shallow copy, a deep copy does not hold the same references as the source object, meaning its properties can be changed without affecting the source. For more details, see MDN.
Throws a DataCloneError if any part of the input value is not
serializable.
Examples #
const object = { x: 0, y: 1 };
const deepCopy = structuredClone(object);
deepCopy.x = 1;
console.log(deepCopy.x, object.x); // 1 0
const shallowCopy = object;
shallowCopy.x = 1;
// shallowCopy.x is pointing to the same location in memory as object.x
console.log(shallowCopy.x, object.x); // 1 1
Type Parameters #
#T = any Parameters #
#options: StructuredSerializeOptions Return Type #
interface AbortController
A controller object that allows you to abort one or more DOM requests as and when desired.
Properties #
#signal: AbortSignal Returns the AbortSignal object associated with this object.
Methods #
variable AbortController
A controller object that allows you to abort one or more DOM requests as and when desired.
Properties #
#prototype: AbortController interface AbortSignal
A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object.
Properties #
Methods #
#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(): void #throwIfAborted(): void Throws this AbortSignal's abort reason, if its AbortController has signaled to abort; otherwise, does nothing.
variable AbortSignal
The constructor object for AbortSignal.
AbortSignal instances are obtained from an AbortController or via the
static abort, timeout, and any factory methods rather than constructed
directly, so calling the constructor throws.
Properties #
#prototype: AbortSignal Methods #
#abort(reason?: any): AbortSignal #any(signals: AbortSignal[]): AbortSignal #timeout(milliseconds: number): AbortSignal interface AbortSignalEventMap
interface DOMException
Properties #
#INDEX_SIZE_ERR: 1 #DOMSTRING_SIZE_ERR: 2 #HIERARCHY_REQUEST_ERR: 3 #WRONG_DOCUMENT_ERR: 4 #INVALID_CHARACTER_ERR: 5 #NO_DATA_ALLOWED_ERR: 6 #NO_MODIFICATION_ALLOWED_ERR: 7 #NOT_FOUND_ERR: 8 #NOT_SUPPORTED_ERR: 9 #INUSE_ATTRIBUTE_ERR: 10 #INVALID_STATE_ERR: 11 #SYNTAX_ERR: 12 #INVALID_MODIFICATION_ERR: 13 #NAMESPACE_ERR: 14 #INVALID_ACCESS_ERR: 15 #VALIDATION_ERR: 16 #TYPE_MISMATCH_ERR: 17 #SECURITY_ERR: 18 #NETWORK_ERR: 19 #URL_MISMATCH_ERR: 21 #QUOTA_EXCEEDED_ERR: 22 #TIMEOUT_ERR: 23 #INVALID_NODE_TYPE_ERR: 24 #DATA_CLONE_ERR: 25 variable DOMException
The constructor object for DOMException, used to construct an
exception describing an abnormal event raised by a web API. It also exposes
the legacy numeric error code constants (e.g. ABORT_ERR).
Properties #
#prototype: DOMException #INDEX_SIZE_ERR: 1 #DOMSTRING_SIZE_ERR: 2 #HIERARCHY_REQUEST_ERR: 3 #WRONG_DOCUMENT_ERR: 4 #INVALID_CHARACTER_ERR: 5 #NO_DATA_ALLOWED_ERR: 6 #NO_MODIFICATION_ALLOWED_ERR: 7 #NOT_FOUND_ERR: 8 #NOT_SUPPORTED_ERR: 9 #INUSE_ATTRIBUTE_ERR: 10 #INVALID_STATE_ERR: 11 #SYNTAX_ERR: 12 #INVALID_MODIFICATION_ERR: 13 #NAMESPACE_ERR: 14 #INVALID_ACCESS_ERR: 15 #VALIDATION_ERR: 16 #TYPE_MISMATCH_ERR: 17 #SECURITY_ERR: 18 #NETWORK_ERR: 19 #URL_MISMATCH_ERR: 21 #QUOTA_EXCEEDED_ERR: 22 #TIMEOUT_ERR: 23 #INVALID_NODE_TYPE_ERR: 24 #DATA_CLONE_ERR: 25 interface DOMStringList
interface ErrorConstructor
Properties #
#stackTraceLimit: number Methods #
#captureStackTrace(error: Object,constructor?: Function,): void interface ImageData
Properties #
#data: ImageDataArray #pixelFormat: ImageDataPixelFormat #colorSpace: PredefinedColorSpace interface ImageDataSettings
Properties #
#colorSpace: PredefinedColorSpace #pixelFormat: ImageDataPixelFormat interface ImportMeta
Deno provides extra properties on import.meta. These are included here
to ensure that these are still available when using the Deno namespace in
conjunction with other type libs, like dom.
Properties #
A string representation of the fully qualified module URL. When the
module is loaded locally, the value will be a file URL (e.g.
file:///path/module.ts).
You can also parse the string as a URL to determine more information about how the current module was loaded. For example to determine if a module was local or not:
const url = new URL(import.meta.url);
if (url.protocol === "file:") {
console.log("this module was loaded locally");
}
The absolute path of the current module.
This property is only provided for local modules (ie. using file:// URLs).
Example:
// Unix
console.log(import.meta.filename); // /home/alice/my_module.ts
// Windows
console.log(import.meta.filename); // C:\alice\my_module.ts
The absolute path of the directory containing the current module.
This property is only provided for local modules (ie. using file:// URLs).
- Example:
// Unix
console.log(import.meta.dirname); // /home/alice
// Windows
console.log(import.meta.dirname); // C:\alice
Methods #
interface Location
The location (URL) of the object it is linked to. Changes done on it are
reflected on the object it relates to. Accessible via
globalThis.location.
Properties #
#ancestorOrigins: DOMStringList Returns a DOMStringList object listing the origins of the ancestor browsing contexts, from the parent browsing context to the top-level browsing context.
Always empty in Deno.
Returns the Location object's URL's fragment (includes leading "#" if non-empty).
Cannot be set in Deno.
Returns the Location object's URL's host and port (if different from the default port for the scheme).
Cannot be set in Deno.
Methods #
interface Math
Methods #
#sumPrecise(values: Iterable<number>): number Returns the sum of the given values using a more precise algorithm than a
naive +-based reduction, avoiding the floating-point rounding errors
that accumulate when summing many numbers.
interface Navigator
Provides information about the Deno runtime environment and the system
on which it's running. Similar to the browser Navigator object but
adapted for the Deno context.
variable Navigator
Constructor for Navigator objects.
Note: This constructor cannot be used to create new Navigator instances in Deno.
The global navigator object is pre-defined in the runtime environment.
interface QuotaExceededError
variable QuotaExceededError
The constructor object for QuotaExceededError, used to construct
an error thrown when an operation would exceed an enforced quota.
Properties #
#prototype: QuotaExceededError interface RegExpConstructor
interface StructuredSerializeOptions
Options that control structured serialization operations such as
structuredClone(value, options) and MessagePort.postMessage(message, options).
The optional transfer array lists Transferable objects whose
underlying resources should be moved (transferred) to the receiving side
instead of being cloned. After a successful transfer:
- For an
ArrayBuffer, the original buffer becomes neutered (itsbyteLengthis set to0). - For a
MessagePort, the port becomes unusable on the sending side and future events will arrive only on the transferred port at the receiver.
Validation rules:
- Each transferable may appear only once in the
transferlist. - A
MessagePortcannot be listed together with its counterpart port from the sameMessageChannelin the same transfer operation. - Duplicate or otherwise invalid entries will cause a
DataCloneErrorDOMExceptionto be thrown.
Transferring improves performance for large binary data and allows moving communication endpoints without copying.
Examples #
// Transferring an ArrayBuffer (zero-copy for large data)
const buffer = new ArrayBuffer(16);
const cloned = structuredClone(buffer, { transfer: [buffer] });
// After transfer, the original buffer is neutered
console.log(buffer.byteLength); // 0
console.log(cloned.byteLength); // 16
Properties #
#transfer: Transferable[] List of transferable objects whose ownership is moved instead of cloned.
interface Uint8Array
Methods #
Converts this Uint8Array object to a base64 string.
#setFromBase64(string: string,options?: { alphabet?: "base64" | "base64url"; lastChunkHandling?: "loose"
| "strict"
| "stop-before-partial"; },): { read: number; written: number; } Populates this Uint8Array object with data from a base64 string.
#setFromHex(string: string): { read: number; written: number; } Populates this Uint8Array object with data from a hex string.
interface Uint8ArrayConstructor
Methods #
#fromBase64(string: string,options?: { alphabet?: "base64" | "base64url"; lastChunkHandling?: "loose"
| "strict"
| "stop-before-partial"; },): Uint8Array<ArrayBuffer> Creates a new Uint8Array object from a base64 string.
#fromHex(string: string): Uint8Array<ArrayBuffer> Creates a new Uint8Array object from a hex string.
interface VoidFunction
Call Signatures #
(): void interface WebTransport
Properties #
Methods #
#close(closeInfo?: WebTransportCloseInfo): void #createBidirectionalStream(options?: WebTransportSendStreamOptions): Promise<WebTransportBidirectionalStream> #createUnidirectionalStream(options?: WebTransportSendStreamOptions): Promise<WebTransportSendStream> variable WebTransport
The constructor object for WebTransport, used to open a new
WebTransport session to the server at the given url.
Properties #
interface WebTransportBidirectionalStream
Properties #
#writable: WebTransportSendStream variable WebTransportBidirectionalStream
The constructor object for WebTransportBidirectionalStream.
Instances are obtained from a WebTransport session rather than
constructed directly.
Properties #
interface WebTransportDatagramDuplexStream
Properties #
#incomingHighWaterMark: number #incomingMaxAge: number | null #maxDatagramSize: number #outgoingHighWaterMark: number #outgoingMaxAge: number | null #writable: WebTransportSendStream variable WebTransportDatagramDuplexStream
The constructor object for WebTransportDatagramDuplexStream.
The datagram duplex stream is obtained from
WebTransport.datagrams rather than constructed directly.
Properties #
interface WebTransportError
Properties #
#source: WebTransportErrorSource #streamErrorCode: number | null variable WebTransportError
The constructor object for WebTransportError, used to construct
an error describing a failure of a WebTransport session or one of
its streams.
Properties #
interface WebTransportErrorOptions
Properties #
#source: WebTransportErrorSource #streamErrorCode: number | null interface WebTransportHash
interface WebTransportOptions
Properties #
#allowPooling: boolean #requireUnreliable: boolean #serverCertificateHashes: WebTransportHash[] interface WebTransportReceiveStream
Methods #
#getStats(): Promise<WebTransportReceiveStreamStats> variable WebTransportReceiveStream
The constructor object for WebTransportReceiveStream.
Instances are obtained from a WebTransport session rather than
constructed directly.
Properties #
interface WebTransportReceiveStreamStats
Properties #
#bytesReceived: number interface WebTransportSendGroup
Methods #
#getStats(): Promise<WebTransportSendStreamStats> variable WebTransportSendGroup
The constructor object for WebTransportSendGroup.
Instances are obtained from a WebTransport session rather than
constructed directly.
Properties #
interface WebTransportSendStream
Properties #
#sendGroup: WebTransportSendGroup Methods #
variable WebTransportSendStream
The constructor object for WebTransportSendStream.
Instances are obtained from a WebTransport session rather than
constructed directly.
Properties #
interface WebTransportSendStreamOptions
Properties #
#sendGroup: WebTransportSendGroup #waitUntilAvailable: boolean interface WebTransportSendStreamStats
Properties #
interface WebTransportWriter
Methods #
#atomicWrite(chunk: any): Promise<undefined> variable WebTransportWriter
The constructor object for WebTransportWriter.
Instances are obtained from a WebTransportSendStream rather than
constructed directly.
Properties #
interface Window
Represents the global window object in the Deno runtime environment.
While Deno doesn't have a browser window, this interface mimics browser window functionality for compatibility with web APIs. It provides access to global properties and methods such as timers, storage, and event handling.
Examples #
// Accessing global objects
const localStorage = window.localStorage;
// Event handling
window.addEventListener("unhandledrejection", (event) => {
console.log("Unhandled promise rejection:", event.reason);d
});
Properties #
#onerror: ((this: Window,ev: ErrorEvent,) => any) | null #onbeforeunload: (() => any) | null #onunhandledrejection: ((this: Window,) => any) | null #onrejectionhandled: ((this: Window,) => any) | null Methods #
#addEventListener<K extends keyof WindowEventMap>(type: K,listener: (this: Window,ev: WindowEventMap[K],) => any,options?: boolean | AddEventListenerOptions,): void #addEventListener(type: string,listener: EventListenerOrEventListenerObject,options?: boolean | AddEventListenerOptions,): void #removeEventListener<K extends keyof WindowEventMap>(type: K,listener: (this: Window,ev: WindowEventMap[K],) => any,options?: boolean | EventListenerOptions,): void #removeEventListener(): void interface WindowEventMap
Defines the mapping between event names and their corresponding event types
for the Window interface in Deno.
This interface provides type safety for event handlers by associating event names with their proper event types.
Properties #
type alias AllowSharedBufferSource
type alias BufferSource
Definition #
ArrayBufferView<ArrayBuffer> | ArrayBuffer type alias ImageDataArray
Definition #
Uint8ClampedArray<ArrayBuffer> | Float16Array<ArrayBuffer> type alias ImageDataPixelFormat
Definition #
"rgba-unorm8" | "rgba-float16" type alias PredefinedColorSpace
Definition #
"srgb" | "display-p3" type alias WebTransportCongestionControl
Definition #
"default"
| "low-latency"
| "throughput" type alias WebTransportErrorSource
Definition #
"session" | "stream" variable navigator
Provides access to the Deno runtime's Navigator interface, which contains
information about the environment in which the script is running.