mirror of
https://github.com/denoland/deno.git
synced 2025-01-22 06:09:25 -05:00
docs: code example to structuredClone
, CompressionStream
, DecompressionStream
(#13719)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
877c0b724e
commit
6613a312b1
4 changed files with 85 additions and 13 deletions
2
cli/dts/lib.deno.ns.d.ts
vendored
2
cli/dts/lib.deno.ns.d.ts
vendored
|
@ -2910,11 +2910,13 @@ declare namespace Deno {
|
||||||
* If `pid` is negative, the signal will be sent to the process group
|
* If `pid` is negative, the signal will be sent to the process group
|
||||||
* identified by `pid`.
|
* identified by `pid`.
|
||||||
*
|
*
|
||||||
|
* ```ts
|
||||||
* const p = Deno.run({
|
* const p = Deno.run({
|
||||||
* cmd: ["sleep", "10000"]
|
* cmd: ["sleep", "10000"]
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* Deno.kill(p.pid, "SIGINT");
|
* Deno.kill(p.pid, "SIGINT");
|
||||||
|
* ```
|
||||||
*
|
*
|
||||||
* Requires `allow-run` permission. */
|
* Requires `allow-run` permission. */
|
||||||
export function kill(pid: number, signo: Signal): void;
|
export function kill(pid: number, signo: Signal): void;
|
||||||
|
|
10
cli/dts/lib.deno.window.d.ts
vendored
10
cli/dts/lib.deno.window.d.ts
vendored
|
@ -71,9 +71,11 @@ declare function prompt(message?: string, defaultValue?: string): string | null;
|
||||||
/** Registers an event listener in the global scope, which will be called
|
/** Registers an event listener in the global scope, which will be called
|
||||||
* synchronously whenever the event `type` is dispatched.
|
* synchronously whenever the event `type` is dispatched.
|
||||||
*
|
*
|
||||||
|
* ```ts
|
||||||
* addEventListener('unload', () => { console.log('All finished!'); });
|
* addEventListener('unload', () => { console.log('All finished!'); });
|
||||||
* ...
|
* ...
|
||||||
* dispatchEvent(new Event('unload'));
|
* dispatchEvent(new Event('unload'));
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
declare function addEventListener(
|
declare function addEventListener(
|
||||||
type: string,
|
type: string,
|
||||||
|
@ -83,9 +85,11 @@ declare function addEventListener(
|
||||||
|
|
||||||
/** Remove a previously registered event listener from the global scope
|
/** Remove a previously registered event listener from the global scope
|
||||||
*
|
*
|
||||||
* const lstnr = () => { console.log('hello'); };
|
* ```ts
|
||||||
* addEventListener('load', lstnr);
|
* const listener = () => { console.log('hello'); };
|
||||||
* removeEventListener('load', lstnr);
|
* addEventListener('load', listener);
|
||||||
|
* removeEventListener('load', listener);
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
declare function removeEventListener(
|
declare function removeEventListener(
|
||||||
type: string,
|
type: string,
|
||||||
|
|
66
ext/web/lib.deno_web.d.ts
vendored
66
ext/web/lib.deno_web.d.ts
vendored
|
@ -167,13 +167,17 @@ declare class ProgressEvent<T extends EventTarget = EventTarget> extends Event {
|
||||||
|
|
||||||
/** Decodes a string of data which has been encoded using base-64 encoding.
|
/** Decodes a string of data which has been encoded using base-64 encoding.
|
||||||
*
|
*
|
||||||
|
* ```
|
||||||
* console.log(atob("aGVsbG8gd29ybGQ=")); // outputs 'hello world'
|
* console.log(atob("aGVsbG8gd29ybGQ=")); // outputs 'hello world'
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
declare function atob(s: string): string;
|
declare function atob(s: string): string;
|
||||||
|
|
||||||
/** Creates a base-64 ASCII encoded string from the input string.
|
/** Creates a base-64 ASCII encoded string from the input string.
|
||||||
*
|
*
|
||||||
|
* ```
|
||||||
* console.log(btoa("hello world")); // outputs "aGVsbG8gd29ybGQ="
|
* console.log(btoa("hello world")); // outputs "aGVsbG8gd29ybGQ="
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
declare function btoa(s: string): string;
|
declare function btoa(s: string): string;
|
||||||
|
|
||||||
|
@ -805,19 +809,81 @@ declare class MessagePort extends EventTarget {
|
||||||
): void;
|
): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates 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](https://developer.mozilla.org/en-US/docs/Glossary/Deep_copy).
|
||||||
|
*
|
||||||
|
* Throws a `DataCloneError` if any part of the input value is not
|
||||||
|
* serializable.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```ts
|
||||||
|
* 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
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
declare function structuredClone(
|
declare function structuredClone(
|
||||||
value: any,
|
value: any,
|
||||||
options?: StructuredSerializeOptions,
|
options?: StructuredSerializeOptions,
|
||||||
): any;
|
): any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An API for compressing a stream of data.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```ts
|
||||||
|
* await Deno.stdin.readable
|
||||||
|
* .pipeThrough(new CompressionStream("gzip"))
|
||||||
|
* .pipeTo(Deno.stdout.writable);
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
declare class CompressionStream {
|
declare class CompressionStream {
|
||||||
|
/**
|
||||||
|
* Creates a new `CompressionStream` object which compresses a stream of
|
||||||
|
* data.
|
||||||
|
*
|
||||||
|
* Throws a `TypeError` if the format passed to the constructor is not
|
||||||
|
* supported.
|
||||||
|
*/
|
||||||
constructor(format: string);
|
constructor(format: string);
|
||||||
|
|
||||||
readonly readable: ReadableStream<Uint8Array>;
|
readonly readable: ReadableStream<Uint8Array>;
|
||||||
readonly writable: WritableStream<Uint8Array>;
|
readonly writable: WritableStream<Uint8Array>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An API for decompressing a stream of data.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```ts
|
||||||
|
* const input = await Deno.open("./file.txt.gz");
|
||||||
|
* const output = await Deno.create("./file.txt");
|
||||||
|
*
|
||||||
|
* await input.readable
|
||||||
|
* .pipeThrough(new DecompressionStream("gzip"))
|
||||||
|
* .pipeTo(output.writable);
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
declare class DecompressionStream {
|
declare class DecompressionStream {
|
||||||
|
/**
|
||||||
|
* Creates a new `DecompressionStream` object which decompresses a stream of
|
||||||
|
* data.
|
||||||
|
*
|
||||||
|
* Throws a `TypeError` if the format passed to the constructor is not
|
||||||
|
* supported.
|
||||||
|
*/
|
||||||
constructor(format: string);
|
constructor(format: string);
|
||||||
|
|
||||||
readonly readable: ReadableStream<Uint8Array>;
|
readonly readable: ReadableStream<Uint8Array>;
|
||||||
|
|
2
ext/websocket/lib.deno_websocket.d.ts
vendored
2
ext/websocket/lib.deno_websocket.d.ts
vendored
|
@ -37,7 +37,7 @@ interface WebSocketEventMap {
|
||||||
/**
|
/**
|
||||||
* Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.
|
* Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.
|
||||||
*
|
*
|
||||||
* If you are looking to create a WebSocket server, please take a look at Deno.upgradeWebSocket().
|
* If you are looking to create a WebSocket server, please take a look at `Deno.upgradeWebSocket()`.
|
||||||
*/
|
*/
|
||||||
declare class WebSocket extends EventTarget {
|
declare class WebSocket extends EventTarget {
|
||||||
constructor(url: string, protocols?: string | string[]);
|
constructor(url: string, protocols?: string | string[]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue