From 8dfef5435a12e1eaa2771e834246a896d872ff41 Mon Sep 17 00:00:00 2001 From: Emile Fugulin Date: Wed, 11 Feb 2026 18:21:52 -0500 Subject: [PATCH 1/3] Clean older sdk files --- scripts/sdk.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/sdk.sh b/scripts/sdk.sh index ba6eb1b..2a931aa 100755 --- a/scripts/sdk.sh +++ b/scripts/sdk.sh @@ -6,7 +6,11 @@ cd ../sdk-js pnpm generate:doc echo "[*] Copying doc" +rm -rf ../doc-developer/src/reference/sdks/backend/* cp -r ./packages/sdk-backend/docs/* ../doc-developer/src/reference/sdks/backend/ +rm -rf ../doc-developer/src/reference/sdks/frontend/* cp -r ./packages/sdk-frontend/docs/* ../doc-developer/src/reference/sdks/frontend/ +rm -rf ../doc-developer/src/reference/sdks/workflow/* cp -r ./packages/sdk-workflow/docs/* ../doc-developer/src/reference/sdks/workflow/ +rm -rf ../doc-developer/src/reference/modules/* cp -r ./packages/quickjs-types/docs/* ../doc-developer/src/reference/modules/ From 08286ab2a954fd4b5451c923bbed9459374360c6 Mon Sep 17 00:00:00 2001 From: Emile Fugulin Date: Wed, 11 Feb 2026 18:22:17 -0500 Subject: [PATCH 2/3] Regenerate doc --- src/reference/modules/caido/crypto.md | 2047 ++++++ src/reference/modules/caido/http.md | 8 +- src/reference/modules/extra/url.md | 281 - src/reference/modules/index.md | 48 +- src/reference/modules/llrt/buffer.md | 4 +- src/reference/modules/llrt/child_process.md | 22 +- src/reference/modules/llrt/crypto.md | 780 --- src/reference/modules/llrt/dns.md | 409 ++ src/reference/modules/llrt/events.md | 476 ++ src/reference/modules/llrt/fs/index.md | 26 +- .../modules/llrt/fs/{fs => }/promises.md | 74 +- src/reference/modules/llrt/globals/index.md | 467 -- .../llrt/globals/namespaces/QuickJS.md | 52 +- src/reference/modules/llrt/https.md | 47 + src/reference/modules/llrt/net.md | 26 +- src/reference/modules/llrt/process.md | 3 - src/reference/modules/llrt/stream.md | 5658 ----------------- src/reference/modules/llrt/stream/stream.md | 56 +- .../modules/llrt/stream/web/index.md | 1231 ++++ .../modules/llrt/stream/web/stream/web.md | 1452 +++++ src/reference/modules/llrt/string_decoder.md | 64 + src/reference/modules/llrt/url/index.md | 780 +++ src/reference/modules/llrt/url/url.md | 1118 ++++ src/reference/sdks/backend/environment.md | 133 +- src/reference/sdks/backend/index.md | 3 + src/reference/sdks/backend/other.md | 73 + src/reference/sdks/frontend/index.md | 3 + src/reference/sdks/workflow/environment.md | 133 +- src/reference/sdks/workflow/index.md | 3 + src/reference/sdks/workflow/other.md | 73 + 30 files changed, 8207 insertions(+), 7343 deletions(-) create mode 100644 src/reference/modules/caido/crypto.md delete mode 100644 src/reference/modules/extra/url.md delete mode 100644 src/reference/modules/llrt/crypto.md create mode 100644 src/reference/modules/llrt/dns.md create mode 100644 src/reference/modules/llrt/events.md rename src/reference/modules/llrt/fs/{fs => }/promises.md (86%) create mode 100644 src/reference/modules/llrt/https.md delete mode 100644 src/reference/modules/llrt/process.md delete mode 100644 src/reference/modules/llrt/stream.md create mode 100644 src/reference/modules/llrt/stream/web/index.md create mode 100644 src/reference/modules/llrt/stream/web/stream/web.md create mode 100644 src/reference/modules/llrt/string_decoder.md create mode 100644 src/reference/modules/llrt/url/index.md create mode 100644 src/reference/modules/llrt/url/url.md diff --git a/src/reference/modules/caido/crypto.md b/src/reference/modules/caido/crypto.md new file mode 100644 index 0000000..b42fe84 --- /dev/null +++ b/src/reference/modules/caido/crypto.md @@ -0,0 +1,2047 @@ +[@caido/quickjs-types](../index.md) / caido/crypto + +# caido/crypto + +## Classes + +### Cipheriv + +Instances of the `Cipheriv` class are used to encrypt data. The class can be +used in one way: + +* Using the `cipher.update()` and `cipher.final()` methods to produce +the encrypted data. + +The [createCipheriv](#createcipheriv) method is +used to create `Cipheriv` instances. `Cipheriv` objects are not to be created +directly using the `new` keyword. + +#### Extended by + +- [`CipherCCM`](#cipherccm) +- [`CipherGCM`](#ciphergcm) +- [`CipherOCB`](#cipherocb) +- [`CipherChaCha20Poly1305`](#cipherchacha20poly1305) + +#### Methods + +##### final() + +> **final**(): [`Buffer`](../llrt/buffer.md#buffer) + +Once the `cipher.final()` method has been called, the `Cipheriv` object can no +longer be used to encrypt data. Attempts to call `cipher.final()` more than +once will result in an error being thrown. + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +Any remaining enciphered contents. + +##### update() + +> **update**(`data`: [`BinaryLike`](#binarylike)): [`Buffer`](../llrt/buffer.md#buffer) + +Updates the cipher with `data`. + +The `cipher.update()` method can be called multiple times with new data until `cipher.final()` is called. Calling `cipher.update()` after `cipher.final()` will result in an error being +thrown. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `data` | [`BinaryLike`](#binarylike) | + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +*** + +### Decipheriv + +Instances of the `Decipheriv` class are used to decrypt data. The class can be +used in one way: + +* Using the `decipher.update()` and `decipher.final()` methods to +produce the unencrypted data. + +The [createDecipheriv](#createdecipheriv) method is +used to create `Decipheriv` instances. `Decipheriv` objects are not to be created +directly using the `new` keyword. + +#### Extended by + +- [`DecipherCCM`](#decipherccm) +- [`DecipherGCM`](#deciphergcm) +- [`DecipherOCB`](#decipherocb) +- [`DecipherChaCha20Poly1305`](#decipherchacha20poly1305) + +#### Methods + +##### final() + +> **final**(): [`Buffer`](../llrt/buffer.md#buffer) + +Once the `decipher.final()` method has been called, the `Decipheriv` object can +no longer be used to decrypt data. Attempts to call `decipher.final()` more +than once will result in an error being thrown. + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +##### update() + +> **update**(`data`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): [`Buffer`](../llrt/buffer.md#buffer) + +Updates the decipher with `data`. + +The `decipher.update()` method can be called multiple times with new data until `decipher.final()` is called. Calling `decipher.update()` after `decipher.final()` will result in an error +being thrown. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `data` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +*** + +### Hash + +The `Hash` class is a utility for creating hash digests of data. + +Using the `hash.update()` and `hash.digest()` methods to produce the +computed hash. + +The [createHash](#createhash) method is used to create `Hash` instances. +`Hash`objects are not to be created directly using the `new` keyword. + +Example: Using the `hash.update()` and `hash.digest()` methods: + +```js +import { createHash } from 'crypto'; + +const hash = createHash('sha256'); + +hash.update('some data to hash'); +console.log(hash.digest('hex')); +// Prints: +// 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50 +``` + +#### Methods + +##### digest() + +###### Call Signature + +> **digest**(): [`Buffer`](../llrt/buffer.md#buffer) + +Calculates the digest of all of the data passed to be hashed (using the `hash.update()` method). +If `encoding` is provided a string will be returned; otherwise +a `Buffer` is returned. + +The `Hash` object can not be used again after `hash.digest()` method has been +called. Multiple calls will cause an error to be thrown. + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +###### Call Signature + +> **digest**(`encoding`: [`BinaryToTextEncoding`](#binarytotextencoding)): `string` + +Calculates the digest of all of the data passed to be hashed (using the `hash.update()` method). +If `encoding` is provided a string will be returned; otherwise +a `Buffer` is returned. + +The `Hash` object can not be used again after `hash.digest()` method has been +called. Multiple calls will cause an error to be thrown. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `encoding` | [`BinaryToTextEncoding`](#binarytotextencoding) | The `encoding` of the return value. | + +###### Returns + +`string` + +##### update() + +###### Call Signature + +> **update**(`data`: [`BinaryLike`](#binarylike)): [`Hash`](#hash) + +Updates the hash content with the given `data`, the encoding of which +is given in `inputEncoding`. +If `encoding` is not provided, and the `data` is a string, an +encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, +then `inputEncoding` is ignored. + +This can be called many times with new data as it is streamed. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `data` | [`BinaryLike`](#binarylike) | + +###### Returns + +[`Hash`](#hash) + +###### Call Signature + +> **update**(`data`: `string`, `inputEncoding`: [`Encoding`](#encoding)): [`Hash`](#hash) + +Updates the hash content with the given `data`, the encoding of which +is given in `inputEncoding`. +If `encoding` is not provided, and the `data` is a string, an +encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, +then `inputEncoding` is ignored. + +This can be called many times with new data as it is streamed. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `data` | `string` | - | +| `inputEncoding` | [`Encoding`](#encoding) | The `encoding` of the `data` string. | + +###### Returns + +[`Hash`](#hash) + +*** + +### Hmac + +The `Hmac` class is a utility for creating cryptographic HMAC digests. + +Using the `hmac.update()` and `hmac.digest()` methods to produce the +computed HMAC digest. + +The [createHmac](#createhmac) method is used to create `Hmac` instances. +`Hmac`objects are not to be created directly using the `new` keyword. + +Example: Using the `hmac.update()` and `hmac.digest()` methods: + +```js +import { createHmac } from 'crypto'; + +const hmac = createHmac('sha256', 'a secret'); + +hmac.update('some data to hash'); +console.log(hmac.digest('hex')); +// Prints: +// 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e +``` + +#### Methods + +##### digest() + +###### Call Signature + +> **digest**(): [`Buffer`](../llrt/buffer.md#buffer) + +Calculates the HMAC digest of all of the data passed using `hmac.update()`. +If `encoding` is +provided a string is returned; otherwise a `Buffer` is returned; + +The `Hmac` object can not be used again after `hmac.digest()` has been +called. Multiple calls to `hmac.digest()` will result in an error being thrown. + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +###### Call Signature + +> **digest**(`encoding`: [`BinaryToTextEncoding`](#binarytotextencoding)): `string` + +Calculates the HMAC digest of all of the data passed using `hmac.update()`. +If `encoding` is +provided a string is returned; otherwise a `Buffer` is returned; + +The `Hmac` object can not be used again after `hmac.digest()` has been +called. Multiple calls to `hmac.digest()` will result in an error being thrown. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `encoding` | [`BinaryToTextEncoding`](#binarytotextencoding) | The `encoding` of the return value. | + +###### Returns + +`string` + +##### update() + +###### Call Signature + +> **update**(`data`: [`BinaryLike`](#binarylike)): [`Hmac`](#hmac) + +Updates the `Hmac` content with the given `data`, the encoding of which +is given in `inputEncoding`. +If `encoding` is not provided, and the `data` is a string, an +encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, +then `inputEncoding` is ignored. + +This can be called many times with new data as it is streamed. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `data` | [`BinaryLike`](#binarylike) | + +###### Returns + +[`Hmac`](#hmac) + +###### Call Signature + +> **update**(`data`: `string`, `inputEncoding`: [`Encoding`](#encoding)): [`Hmac`](#hmac) + +Updates the `Hmac` content with the given `data`, the encoding of which +is given in `inputEncoding`. +If `encoding` is not provided, and the `data` is a string, an +encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, +then `inputEncoding` is ignored. + +This can be called many times with new data as it is streamed. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `data` | `string` | - | +| `inputEncoding` | [`Encoding`](#encoding) | The `encoding` of the `data` string. | + +###### Returns + +[`Hmac`](#hmac) + +## Interfaces + +### CipherCCM + +Instances of the `Cipheriv` class are used to encrypt data. The class can be +used in one way: + +* Using the `cipher.update()` and `cipher.final()` methods to produce +the encrypted data. + +The [createCipheriv](#createcipheriv) method is +used to create `Cipheriv` instances. `Cipheriv` objects are not to be created +directly using the `new` keyword. + +#### Extends + +- [`Cipheriv`](#cipheriv) + +#### Methods + +##### final() + +> **final**(): [`Buffer`](../llrt/buffer.md#buffer) + +Once the `cipher.final()` method has been called, the `Cipheriv` object can no +longer be used to encrypt data. Attempts to call `cipher.final()` more than +once will result in an error being thrown. + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +Any remaining enciphered contents. + +###### Inherited from + +[`Cipheriv`](#cipheriv).[`final`](#final) + +##### getAuthTag() + +> **getAuthTag**(): [`Buffer`](../llrt/buffer.md#buffer) + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +##### setAAD() + +> **setAAD**(`buffer`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): `this` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `buffer` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +`this` + +##### update() + +> **update**(`data`: [`BinaryLike`](#binarylike)): [`Buffer`](../llrt/buffer.md#buffer) + +Updates the cipher with `data`. + +The `cipher.update()` method can be called multiple times with new data until `cipher.final()` is called. Calling `cipher.update()` after `cipher.final()` will result in an error being +thrown. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `data` | [`BinaryLike`](#binarylike) | + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +###### Inherited from + +[`Cipheriv`](#cipheriv).[`update`](#update) + +*** + +### CipherCCMOptions + +#### Properties + +##### authTagLength + +> **authTagLength**: `number` + +*** + +### CipherChaCha20Poly1305 + +Instances of the `Cipheriv` class are used to encrypt data. The class can be +used in one way: + +* Using the `cipher.update()` and `cipher.final()` methods to produce +the encrypted data. + +The [createCipheriv](#createcipheriv) method is +used to create `Cipheriv` instances. `Cipheriv` objects are not to be created +directly using the `new` keyword. + +#### Extends + +- [`Cipheriv`](#cipheriv) + +#### Methods + +##### final() + +> **final**(): [`Buffer`](../llrt/buffer.md#buffer) + +Once the `cipher.final()` method has been called, the `Cipheriv` object can no +longer be used to encrypt data. Attempts to call `cipher.final()` more than +once will result in an error being thrown. + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +Any remaining enciphered contents. + +###### Inherited from + +[`Cipheriv`](#cipheriv).[`final`](#final) + +##### getAuthTag() + +> **getAuthTag**(): [`Buffer`](../llrt/buffer.md#buffer) + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +##### setAAD() + +> **setAAD**(`buffer`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): `this` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `buffer` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +`this` + +##### update() + +> **update**(`data`: [`BinaryLike`](#binarylike)): [`Buffer`](../llrt/buffer.md#buffer) + +Updates the cipher with `data`. + +The `cipher.update()` method can be called multiple times with new data until `cipher.final()` is called. Calling `cipher.update()` after `cipher.final()` will result in an error being +thrown. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `data` | [`BinaryLike`](#binarylike) | + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +###### Inherited from + +[`Cipheriv`](#cipheriv).[`update`](#update) + +*** + +### CipherChaCha20Poly1305Options + +#### Properties + +##### authTagLength? + +> `optional` **authTagLength**: `number` + +###### Default + +```ts +16 +``` + +*** + +### CipherGCM + +Instances of the `Cipheriv` class are used to encrypt data. The class can be +used in one way: + +* Using the `cipher.update()` and `cipher.final()` methods to produce +the encrypted data. + +The [createCipheriv](#createcipheriv) method is +used to create `Cipheriv` instances. `Cipheriv` objects are not to be created +directly using the `new` keyword. + +#### Extends + +- [`Cipheriv`](#cipheriv) + +#### Methods + +##### final() + +> **final**(): [`Buffer`](../llrt/buffer.md#buffer) + +Once the `cipher.final()` method has been called, the `Cipheriv` object can no +longer be used to encrypt data. Attempts to call `cipher.final()` more than +once will result in an error being thrown. + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +Any remaining enciphered contents. + +###### Inherited from + +[`Cipheriv`](#cipheriv).[`final`](#final) + +##### getAuthTag() + +> **getAuthTag**(): [`Buffer`](../llrt/buffer.md#buffer) + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +##### setAAD() + +> **setAAD**(`buffer`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): `this` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `buffer` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +`this` + +##### update() + +> **update**(`data`: [`BinaryLike`](#binarylike)): [`Buffer`](../llrt/buffer.md#buffer) + +Updates the cipher with `data`. + +The `cipher.update()` method can be called multiple times with new data until `cipher.final()` is called. Calling `cipher.update()` after `cipher.final()` will result in an error being +thrown. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `data` | [`BinaryLike`](#binarylike) | + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +###### Inherited from + +[`Cipheriv`](#cipheriv).[`update`](#update) + +*** + +### CipherGCMOptions + +#### Properties + +##### authTagLength? + +> `optional` **authTagLength**: `number` + +*** + +### CipherOCB + +Instances of the `Cipheriv` class are used to encrypt data. The class can be +used in one way: + +* Using the `cipher.update()` and `cipher.final()` methods to produce +the encrypted data. + +The [createCipheriv](#createcipheriv) method is +used to create `Cipheriv` instances. `Cipheriv` objects are not to be created +directly using the `new` keyword. + +#### Extends + +- [`Cipheriv`](#cipheriv) + +#### Methods + +##### final() + +> **final**(): [`Buffer`](../llrt/buffer.md#buffer) + +Once the `cipher.final()` method has been called, the `Cipheriv` object can no +longer be used to encrypt data. Attempts to call `cipher.final()` more than +once will result in an error being thrown. + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +Any remaining enciphered contents. + +###### Inherited from + +[`Cipheriv`](#cipheriv).[`final`](#final) + +##### getAuthTag() + +> **getAuthTag**(): [`Buffer`](../llrt/buffer.md#buffer) + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +##### setAAD() + +> **setAAD**(`buffer`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): `this` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `buffer` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +`this` + +##### update() + +> **update**(`data`: [`BinaryLike`](#binarylike)): [`Buffer`](../llrt/buffer.md#buffer) + +Updates the cipher with `data`. + +The `cipher.update()` method can be called multiple times with new data until `cipher.final()` is called. Calling `cipher.update()` after `cipher.final()` will result in an error being +thrown. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `data` | [`BinaryLike`](#binarylike) | + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +###### Inherited from + +[`Cipheriv`](#cipheriv).[`update`](#update) + +*** + +### CipherOCBOptions + +#### Properties + +##### authTagLength + +> **authTagLength**: `number` + +*** + +### DecipherCCM + +Instances of the `Decipheriv` class are used to decrypt data. The class can be +used in one way: + +* Using the `decipher.update()` and `decipher.final()` methods to +produce the unencrypted data. + +The [createDecipheriv](#createdecipheriv) method is +used to create `Decipheriv` instances. `Decipheriv` objects are not to be created +directly using the `new` keyword. + +#### Extends + +- [`Decipheriv`](#decipheriv) + +#### Methods + +##### final() + +> **final**(): [`Buffer`](../llrt/buffer.md#buffer) + +Once the `decipher.final()` method has been called, the `Decipheriv` object can +no longer be used to decrypt data. Attempts to call `decipher.final()` more +than once will result in an error being thrown. + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +###### Inherited from + +[`Decipheriv`](#decipheriv).[`final`](#final-2) + +##### setAAD() + +> **setAAD**(`buffer`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): `this` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `buffer` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +`this` + +##### setAuthTag() + +> **setAuthTag**(`buffer`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): `this` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `buffer` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +`this` + +##### update() + +> **update**(`data`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): [`Buffer`](../llrt/buffer.md#buffer) + +Updates the decipher with `data`. + +The `decipher.update()` method can be called multiple times with new data until `decipher.final()` is called. Calling `decipher.update()` after `decipher.final()` will result in an error +being thrown. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `data` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +###### Inherited from + +[`Decipheriv`](#decipheriv).[`update`](#update-2) + +*** + +### DecipherChaCha20Poly1305 + +Instances of the `Decipheriv` class are used to decrypt data. The class can be +used in one way: + +* Using the `decipher.update()` and `decipher.final()` methods to +produce the unencrypted data. + +The [createDecipheriv](#createdecipheriv) method is +used to create `Decipheriv` instances. `Decipheriv` objects are not to be created +directly using the `new` keyword. + +#### Extends + +- [`Decipheriv`](#decipheriv) + +#### Methods + +##### final() + +> **final**(): [`Buffer`](../llrt/buffer.md#buffer) + +Once the `decipher.final()` method has been called, the `Decipheriv` object can +no longer be used to decrypt data. Attempts to call `decipher.final()` more +than once will result in an error being thrown. + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +###### Inherited from + +[`Decipheriv`](#decipheriv).[`final`](#final-2) + +##### setAAD() + +> **setAAD**(`buffer`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): `this` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `buffer` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +`this` + +##### setAuthTag() + +> **setAuthTag**(`buffer`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): `this` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `buffer` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +`this` + +##### update() + +> **update**(`data`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): [`Buffer`](../llrt/buffer.md#buffer) + +Updates the decipher with `data`. + +The `decipher.update()` method can be called multiple times with new data until `decipher.final()` is called. Calling `decipher.update()` after `decipher.final()` will result in an error +being thrown. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `data` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +###### Inherited from + +[`Decipheriv`](#decipheriv).[`update`](#update-2) + +*** + +### DecipherGCM + +Instances of the `Decipheriv` class are used to decrypt data. The class can be +used in one way: + +* Using the `decipher.update()` and `decipher.final()` methods to +produce the unencrypted data. + +The [createDecipheriv](#createdecipheriv) method is +used to create `Decipheriv` instances. `Decipheriv` objects are not to be created +directly using the `new` keyword. + +#### Extends + +- [`Decipheriv`](#decipheriv) + +#### Methods + +##### final() + +> **final**(): [`Buffer`](../llrt/buffer.md#buffer) + +Once the `decipher.final()` method has been called, the `Decipheriv` object can +no longer be used to decrypt data. Attempts to call `decipher.final()` more +than once will result in an error being thrown. + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +###### Inherited from + +[`Decipheriv`](#decipheriv).[`final`](#final-2) + +##### setAAD() + +> **setAAD**(`buffer`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): `this` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `buffer` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +`this` + +##### setAuthTag() + +> **setAuthTag**(`buffer`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): `this` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `buffer` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +`this` + +##### update() + +> **update**(`data`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): [`Buffer`](../llrt/buffer.md#buffer) + +Updates the decipher with `data`. + +The `decipher.update()` method can be called multiple times with new data until `decipher.final()` is called. Calling `decipher.update()` after `decipher.final()` will result in an error +being thrown. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `data` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +###### Inherited from + +[`Decipheriv`](#decipheriv).[`update`](#update-2) + +*** + +### DecipherOCB + +Instances of the `Decipheriv` class are used to decrypt data. The class can be +used in one way: + +* Using the `decipher.update()` and `decipher.final()` methods to +produce the unencrypted data. + +The [createDecipheriv](#createdecipheriv) method is +used to create `Decipheriv` instances. `Decipheriv` objects are not to be created +directly using the `new` keyword. + +#### Extends + +- [`Decipheriv`](#decipheriv) + +#### Methods + +##### final() + +> **final**(): [`Buffer`](../llrt/buffer.md#buffer) + +Once the `decipher.final()` method has been called, the `Decipheriv` object can +no longer be used to decrypt data. Attempts to call `decipher.final()` more +than once will result in an error being thrown. + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +###### Inherited from + +[`Decipheriv`](#decipheriv).[`final`](#final-2) + +##### setAAD() + +> **setAAD**(`buffer`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): `this` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `buffer` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +`this` + +##### setAuthTag() + +> **setAuthTag**(`buffer`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): `this` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `buffer` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +`this` + +##### update() + +> **update**(`data`: [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview)): [`Buffer`](../llrt/buffer.md#buffer) + +Updates the decipher with `data`. + +The `decipher.update()` method can be called multiple times with new data until `decipher.final()` is called. Calling `decipher.update()` after `decipher.final()` will result in an error +being thrown. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `data` | [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +###### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +###### Inherited from + +[`Decipheriv`](#decipheriv).[`update`](#update-2) + +## Type Aliases + +### BinaryLike + +> **BinaryLike** = `string` \| [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) + +*** + +### BinaryToTextEncoding + +> **BinaryToTextEncoding** = `"base64"` \| `"hex"` + +*** + +### CharacterEncoding + +> **CharacterEncoding** = `"utf8"` \| `"utf-8"` \| `"utf16le"` \| `"utf-16le"` \| `"latin1"` + +*** + +### CipherCCMTypes + +> **CipherCCMTypes** = `"aes-128-ccm"` \| `"aes-192-ccm"` \| `"aes-256-ccm"` + +*** + +### CipherChaCha20Poly1305Types + +> **CipherChaCha20Poly1305Types** = `"chacha20-poly1305"` + +*** + +### CipherGCMTypes + +> **CipherGCMTypes** = `"aes-128-gcm"` \| `"aes-192-gcm"` \| `"aes-256-gcm"` + +*** + +### CipherKey + +> **CipherKey** = [`BinaryLike`](#binarylike) + +*** + +### CipherOCBTypes + +> **CipherOCBTypes** = `"aes-128-ocb"` \| `"aes-192-ocb"` \| `"aes-256-ocb"` + +*** + +### Encoding + +> **Encoding** = [`BinaryToTextEncoding`](#binarytotextencoding) \| [`CharacterEncoding`](#characterencoding) \| [`LegacyCharacterEncoding`](#legacycharacterencoding) + +*** + +### LegacyCharacterEncoding + +> **LegacyCharacterEncoding** = `"ascii"` + +*** + +### UUID + +> **UUID** = `` `${string}-${string}-${string}-${string}-${string}` `` + +## Functions + +### createCipheriv() + +#### Call Signature + +> **createCipheriv**(`algorithm`: [`CipherCCMTypes`](#cipherccmtypes), `key`: [`BinaryLike`](#binarylike), `iv`: [`BinaryLike`](#binarylike), `options`: [`CipherCCMOptions`](#cipherccmoptions)): [`Cipheriv`](#cipheriv) + +Creates and returns a `Cipher` object, with the given `algorithm`, `key` and +initialization vector (`iv`). + +The `options` argument controls stream behavior and is optional except when a +cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the`authTagLength` option is required and specifies the length of the +authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength`option is not required but can be used to set the length of the authentication +tag and defaults to 16 bytes. +For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes. + +The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded +strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be +a `KeyObject` of type `secret`. If the cipher does not need +an initialization vector, `iv` may be `null`. + +When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`. + +Initialization vectors should be unpredictable and unique; ideally, they will be +cryptographically random. They do not have to be secret: IVs are typically just +added to ciphertext messages unencrypted. It may sound contradictory that +something has to be unpredictable and unique, but does not have to be secret; +remember that an attacker must not be able to predict ahead of time what a +given IV will be. + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `algorithm` | [`CipherCCMTypes`](#cipherccmtypes) | +| `key` | [`BinaryLike`](#binarylike) | +| `iv` | [`BinaryLike`](#binarylike) | +| `options` | [`CipherCCMOptions`](#cipherccmoptions) | + +##### Returns + +[`Cipheriv`](#cipheriv) + +#### Call Signature + +> **createCipheriv**(`algorithm`: [`CipherOCBTypes`](#cipherocbtypes), `key`: [`BinaryLike`](#binarylike), `iv`: [`BinaryLike`](#binarylike), `options`: [`CipherOCBOptions`](#cipherocboptions)): [`CipherOCB`](#cipherocb) + +Creates and returns a `Cipher` object, with the given `algorithm`, `key` and +initialization vector (`iv`). + +The `options` argument controls stream behavior and is optional except when a +cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the`authTagLength` option is required and specifies the length of the +authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength`option is not required but can be used to set the length of the authentication +tag and defaults to 16 bytes. +For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes. + +The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded +strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be +a `KeyObject` of type `secret`. If the cipher does not need +an initialization vector, `iv` may be `null`. + +When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`. + +Initialization vectors should be unpredictable and unique; ideally, they will be +cryptographically random. They do not have to be secret: IVs are typically just +added to ciphertext messages unencrypted. It may sound contradictory that +something has to be unpredictable and unique, but does not have to be secret; +remember that an attacker must not be able to predict ahead of time what a +given IV will be. + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `algorithm` | [`CipherOCBTypes`](#cipherocbtypes) | +| `key` | [`BinaryLike`](#binarylike) | +| `iv` | [`BinaryLike`](#binarylike) | +| `options` | [`CipherOCBOptions`](#cipherocboptions) | + +##### Returns + +[`CipherOCB`](#cipherocb) + +#### Call Signature + +> **createCipheriv**(`algorithm`: [`CipherGCMTypes`](#ciphergcmtypes), `key`: [`BinaryLike`](#binarylike), `iv`: [`BinaryLike`](#binarylike), `options?`: [`CipherGCMOptions`](#ciphergcmoptions)): [`CipherGCM`](#ciphergcm) + +Creates and returns a `Cipher` object, with the given `algorithm`, `key` and +initialization vector (`iv`). + +The `options` argument controls stream behavior and is optional except when a +cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the`authTagLength` option is required and specifies the length of the +authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength`option is not required but can be used to set the length of the authentication +tag and defaults to 16 bytes. +For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes. + +The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded +strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be +a `KeyObject` of type `secret`. If the cipher does not need +an initialization vector, `iv` may be `null`. + +When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`. + +Initialization vectors should be unpredictable and unique; ideally, they will be +cryptographically random. They do not have to be secret: IVs are typically just +added to ciphertext messages unencrypted. It may sound contradictory that +something has to be unpredictable and unique, but does not have to be secret; +remember that an attacker must not be able to predict ahead of time what a +given IV will be. + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `algorithm` | [`CipherGCMTypes`](#ciphergcmtypes) | +| `key` | [`BinaryLike`](#binarylike) | +| `iv` | [`BinaryLike`](#binarylike) | +| `options?` | [`CipherGCMOptions`](#ciphergcmoptions) | + +##### Returns + +[`CipherGCM`](#ciphergcm) + +#### Call Signature + +> **createCipheriv**(`algorithm`: `"chacha20-poly1305"`, `key`: [`BinaryLike`](#binarylike), `iv`: [`BinaryLike`](#binarylike), `options?`: [`CipherChaCha20Poly1305Options`](#cipherchacha20poly1305options)): [`CipherChaCha20Poly1305`](#cipherchacha20poly1305) + +Creates and returns a `Cipher` object, with the given `algorithm`, `key` and +initialization vector (`iv`). + +The `options` argument controls stream behavior and is optional except when a +cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the`authTagLength` option is required and specifies the length of the +authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength`option is not required but can be used to set the length of the authentication +tag and defaults to 16 bytes. +For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes. + +The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded +strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be +a `KeyObject` of type `secret`. If the cipher does not need +an initialization vector, `iv` may be `null`. + +When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`. + +Initialization vectors should be unpredictable and unique; ideally, they will be +cryptographically random. They do not have to be secret: IVs are typically just +added to ciphertext messages unencrypted. It may sound contradictory that +something has to be unpredictable and unique, but does not have to be secret; +remember that an attacker must not be able to predict ahead of time what a +given IV will be. + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `algorithm` | `"chacha20-poly1305"` | +| `key` | [`BinaryLike`](#binarylike) | +| `iv` | [`BinaryLike`](#binarylike) | +| `options?` | [`CipherChaCha20Poly1305Options`](#cipherchacha20poly1305options) | + +##### Returns + +[`CipherChaCha20Poly1305`](#cipherchacha20poly1305) + +#### Call Signature + +> **createCipheriv**(`algorithm`: `string`, `key`: [`BinaryLike`](#binarylike), `iv`: [`BinaryLike`](#binarylike) \| `null`): [`Cipheriv`](#cipheriv) + +Creates and returns a `Cipher` object, with the given `algorithm`, `key` and +initialization vector (`iv`). + +The `options` argument controls stream behavior and is optional except when a +cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the`authTagLength` option is required and specifies the length of the +authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength`option is not required but can be used to set the length of the authentication +tag and defaults to 16 bytes. +For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes. + +The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded +strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be +a `KeyObject` of type `secret`. If the cipher does not need +an initialization vector, `iv` may be `null`. + +When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`. + +Initialization vectors should be unpredictable and unique; ideally, they will be +cryptographically random. They do not have to be secret: IVs are typically just +added to ciphertext messages unencrypted. It may sound contradictory that +something has to be unpredictable and unique, but does not have to be secret; +remember that an attacker must not be able to predict ahead of time what a +given IV will be. + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `algorithm` | `string` | +| `key` | [`BinaryLike`](#binarylike) | +| `iv` | [`BinaryLike`](#binarylike) \| `null` | + +##### Returns + +[`Cipheriv`](#cipheriv) + +*** + +### createDecipheriv() + +#### Call Signature + +> **createDecipheriv**(`algorithm`: [`CipherCCMTypes`](#cipherccmtypes), `key`: [`BinaryLike`](#binarylike), `iv`: [`BinaryLike`](#binarylike), `options`: [`CipherCCMOptions`](#cipherccmoptions)): [`DecipherCCM`](#decipherccm) + +Creates and returns a `Decipheriv` object that uses the given `algorithm`, `key` and initialization vector (`iv`). + +The `options` argument controls stream behavior and is optional except when a +cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the `authTagLength` option is required and specifies the length of the +authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength` option is not required but can be used to restrict accepted authentication tags +to those with the specified length. +For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes. + +The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded +strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be +a `KeyObject` of type `secret`. If the cipher does not need +an initialization vector, `iv` may be `null`. + +When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`. + +Initialization vectors should be unpredictable and unique; ideally, they will be +cryptographically random. They do not have to be secret: IVs are typically just +added to ciphertext messages unencrypted. It may sound contradictory that +something has to be unpredictable and unique, but does not have to be secret; +remember that an attacker must not be able to predict ahead of time what a given +IV will be. + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `algorithm` | [`CipherCCMTypes`](#cipherccmtypes) | +| `key` | [`BinaryLike`](#binarylike) | +| `iv` | [`BinaryLike`](#binarylike) | +| `options` | [`CipherCCMOptions`](#cipherccmoptions) | + +##### Returns + +[`DecipherCCM`](#decipherccm) + +#### Call Signature + +> **createDecipheriv**(`algorithm`: [`CipherOCBTypes`](#cipherocbtypes), `key`: [`BinaryLike`](#binarylike), `iv`: [`BinaryLike`](#binarylike), `options`: [`CipherOCBOptions`](#cipherocboptions)): [`DecipherOCB`](#decipherocb) + +Creates and returns a `Decipheriv` object that uses the given `algorithm`, `key` and initialization vector (`iv`). + +The `options` argument controls stream behavior and is optional except when a +cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the `authTagLength` option is required and specifies the length of the +authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength` option is not required but can be used to restrict accepted authentication tags +to those with the specified length. +For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes. + +The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded +strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be +a `KeyObject` of type `secret`. If the cipher does not need +an initialization vector, `iv` may be `null`. + +When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`. + +Initialization vectors should be unpredictable and unique; ideally, they will be +cryptographically random. They do not have to be secret: IVs are typically just +added to ciphertext messages unencrypted. It may sound contradictory that +something has to be unpredictable and unique, but does not have to be secret; +remember that an attacker must not be able to predict ahead of time what a given +IV will be. + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `algorithm` | [`CipherOCBTypes`](#cipherocbtypes) | +| `key` | [`BinaryLike`](#binarylike) | +| `iv` | [`BinaryLike`](#binarylike) | +| `options` | [`CipherOCBOptions`](#cipherocboptions) | + +##### Returns + +[`DecipherOCB`](#decipherocb) + +#### Call Signature + +> **createDecipheriv**(`algorithm`: [`CipherGCMTypes`](#ciphergcmtypes), `key`: [`BinaryLike`](#binarylike), `iv`: [`BinaryLike`](#binarylike), `options?`: [`CipherGCMOptions`](#ciphergcmoptions)): [`DecipherGCM`](#deciphergcm) + +Creates and returns a `Decipheriv` object that uses the given `algorithm`, `key` and initialization vector (`iv`). + +The `options` argument controls stream behavior and is optional except when a +cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the `authTagLength` option is required and specifies the length of the +authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength` option is not required but can be used to restrict accepted authentication tags +to those with the specified length. +For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes. + +The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded +strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be +a `KeyObject` of type `secret`. If the cipher does not need +an initialization vector, `iv` may be `null`. + +When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`. + +Initialization vectors should be unpredictable and unique; ideally, they will be +cryptographically random. They do not have to be secret: IVs are typically just +added to ciphertext messages unencrypted. It may sound contradictory that +something has to be unpredictable and unique, but does not have to be secret; +remember that an attacker must not be able to predict ahead of time what a given +IV will be. + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `algorithm` | [`CipherGCMTypes`](#ciphergcmtypes) | +| `key` | [`BinaryLike`](#binarylike) | +| `iv` | [`BinaryLike`](#binarylike) | +| `options?` | [`CipherGCMOptions`](#ciphergcmoptions) | + +##### Returns + +[`DecipherGCM`](#deciphergcm) + +#### Call Signature + +> **createDecipheriv**(`algorithm`: `"chacha20-poly1305"`, `key`: [`BinaryLike`](#binarylike), `iv`: [`BinaryLike`](#binarylike), `options?`: [`CipherChaCha20Poly1305Options`](#cipherchacha20poly1305options)): [`DecipherChaCha20Poly1305`](#decipherchacha20poly1305) + +Creates and returns a `Decipheriv` object that uses the given `algorithm`, `key` and initialization vector (`iv`). + +The `options` argument controls stream behavior and is optional except when a +cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the `authTagLength` option is required and specifies the length of the +authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength` option is not required but can be used to restrict accepted authentication tags +to those with the specified length. +For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes. + +The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded +strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be +a `KeyObject` of type `secret`. If the cipher does not need +an initialization vector, `iv` may be `null`. + +When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`. + +Initialization vectors should be unpredictable and unique; ideally, they will be +cryptographically random. They do not have to be secret: IVs are typically just +added to ciphertext messages unencrypted. It may sound contradictory that +something has to be unpredictable and unique, but does not have to be secret; +remember that an attacker must not be able to predict ahead of time what a given +IV will be. + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `algorithm` | `"chacha20-poly1305"` | +| `key` | [`BinaryLike`](#binarylike) | +| `iv` | [`BinaryLike`](#binarylike) | +| `options?` | [`CipherChaCha20Poly1305Options`](#cipherchacha20poly1305options) | + +##### Returns + +[`DecipherChaCha20Poly1305`](#decipherchacha20poly1305) + +#### Call Signature + +> **createDecipheriv**(`algorithm`: `string`, `key`: [`BinaryLike`](#binarylike), `iv`: [`BinaryLike`](#binarylike) \| `null`): [`Decipheriv`](#decipheriv) + +Creates and returns a `Decipheriv` object that uses the given `algorithm`, `key` and initialization vector (`iv`). + +The `options` argument controls stream behavior and is optional except when a +cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the `authTagLength` option is required and specifies the length of the +authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength` option is not required but can be used to restrict accepted authentication tags +to those with the specified length. +For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes. + +The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded +strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be +a `KeyObject` of type `secret`. If the cipher does not need +an initialization vector, `iv` may be `null`. + +When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`. + +Initialization vectors should be unpredictable and unique; ideally, they will be +cryptographically random. They do not have to be secret: IVs are typically just +added to ciphertext messages unencrypted. It may sound contradictory that +something has to be unpredictable and unique, but does not have to be secret; +remember that an attacker must not be able to predict ahead of time what a given +IV will be. + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `algorithm` | `string` | +| `key` | [`BinaryLike`](#binarylike) | +| `iv` | [`BinaryLike`](#binarylike) \| `null` | + +##### Returns + +[`Decipheriv`](#decipheriv) + +*** + +### createHash() + +> **createHash**(`algorithm`: `string`): [`Hash`](#hash) + +Creates and returns a `Hash` object that can be used to generate hash digests +using the given `algorithm`. + +The `algorithm` is supported by `'md4'`, `'md5'`, `'sha1'`, `'sha256'`,`'sha384'` and `'sha512'`. + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `algorithm` | `string` | + +#### Returns + +[`Hash`](#hash) + +*** + +### createHmac() + +> **createHmac**(`algorithm`: `string`, `key`: [`BinaryLike`](#binarylike)): [`Hmac`](#hmac) + +Creates and returns an `Hmac` object that uses the given `algorithm` and `key`. + +The `algorithm` is supported by `'md4'`, `'md5'`, `'sha1'`, `'sha256'`,`'sha384'` and `'sha512'`. + +The `key` is the HMAC key used to generate the cryptographic HMAC hash. +If it is a string, please consider `caveats when using strings as inputs to cryptographic APIs`. +If it was obtained from a cryptographically secure source of entropy, such as [randomBytes](#randombytes) +or generateKey, its length should not exceed the block size of `algorithm` +(e.g., 512 bits for SHA-256). + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `algorithm` | `string` | +| `key` | [`BinaryLike`](#binarylike) | + +#### Returns + +[`Hmac`](#hmac) + +*** + +### getRandomValues() + +> **getRandomValues**\<`T`\>(`typedArray`: `T`): `T` + +A convenient alias for webcrypto.getRandomValues. This +implementation is not compliant with the Web Crypto spec, to write +web-compatible code use webcrypto.getRandomValues instead. + +#### Type Parameters + +| Type Parameter | +| ------ | +| `T` *extends* [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `typedArray` | `T` | + +#### Returns + +`T` + +Returns `typedArray`. + +*** + +### randomBytes() + +> **randomBytes**(`size`: `number`): [`Buffer`](../llrt/buffer.md#buffer) + +Generates cryptographically strong pseudorandom data. The `size` argument +is a number indicating the number of bytes to generate. + +the random bytes are generated synchronously and returned as a `Buffer`. +An error will be thrown if there is a problem generating the bytes. + +```js +// Synchronous +import { randomBytes } from 'crypto'; + +const buf = randomBytes(256); +console.log( + `${buf.length} bytes of random data: ${buf.toString('hex')}`); +``` + +The `crypto.randomBytes()` method will not complete until there is +sufficient entropy available. +This should normally never take longer than a few milliseconds. The only time +when generating the random bytes may conceivably block for a longer period of +time is right after boot, when the whole system is still low on entropy. + +#### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `size` | `number` | The number of bytes to generate. The `size` must not be larger than `2**31 - 1`. | + +#### Returns + +[`Buffer`](../llrt/buffer.md#buffer) + +*** + +### randomFill() + +#### Call Signature + +> **randomFill**\<`T`\>(`buffer`: `T`, `callback`: (`err`: `Error` \| `null`, `buf`: `T`) => `void`): `void` + +This function is similar to [randomBytes](#randombytes) but requires the first +argument to be a `Buffer` that will be filled. It also +requires that a callback is passed in. + +If the `callback` function is not provided, an error will be thrown. + +```js +import { Buffer } from 'buffer'; +import { randomFill } from 'crypto'; + +const buf = Buffer.alloc(10); +randomFill(buf, (err, buf) => { + if (err) throw err; + console.log(buf.toString('hex')); +}); + +randomFill(buf, 5, (err, buf) => { + if (err) throw err; + console.log(buf.toString('hex')); +}); + +// The above is equivalent to the following: +randomFill(buf, 5, 5, (err, buf) => { + if (err) throw err; + console.log(buf.toString('hex')); +}); +``` + +Any `ArrayBuffer`, `TypedArray`, or `DataView` instance may be passed as `buffer`. + +While this includes instances of `Float32Array` and `Float64Array`, this +function should not be used to generate random floating-point numbers. The +result may contain `+Infinity`, `-Infinity`, and `NaN`, and even if the array +contains finite numbers only, they are not drawn from a uniform random +distribution and have no meaningful lower or upper bounds. + +```js +import { Buffer } from 'buffer'; +import { randomFill } from 'crypto'; + +const a = new Uint32Array(10); +randomFill(a, (err, buf) => { + if (err) throw err; + console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) + .toString('hex')); +}); + +const b = new DataView(new ArrayBuffer(10)); +randomFill(b, (err, buf) => { + if (err) throw err; + console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) + .toString('hex')); +}); + +const c = new ArrayBuffer(10); +randomFill(c, (err, buf) => { + if (err) throw err; + console.log(Buffer.from(buf).toString('hex')); +}); +``` + +##### Type Parameters + +| Type Parameter | +| ------ | +| `T` *extends* [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +##### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `buffer` | `T` | Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`. | +| `callback` | (`err`: `Error` \| `null`, `buf`: `T`) => `void` | `function(err, buf) {}`. | + +##### Returns + +`void` + +#### Call Signature + +> **randomFill**\<`T`\>(`buffer`: `T`, `offset`: `number`, `callback`: (`err`: `Error` \| `null`, `buf`: `T`) => `void`): `void` + +This function is similar to [randomBytes](#randombytes) but requires the first +argument to be a `Buffer` that will be filled. It also +requires that a callback is passed in. + +If the `callback` function is not provided, an error will be thrown. + +```js +import { Buffer } from 'buffer'; +import { randomFill } from 'crypto'; + +const buf = Buffer.alloc(10); +randomFill(buf, (err, buf) => { + if (err) throw err; + console.log(buf.toString('hex')); +}); + +randomFill(buf, 5, (err, buf) => { + if (err) throw err; + console.log(buf.toString('hex')); +}); + +// The above is equivalent to the following: +randomFill(buf, 5, 5, (err, buf) => { + if (err) throw err; + console.log(buf.toString('hex')); +}); +``` + +Any `ArrayBuffer`, `TypedArray`, or `DataView` instance may be passed as `buffer`. + +While this includes instances of `Float32Array` and `Float64Array`, this +function should not be used to generate random floating-point numbers. The +result may contain `+Infinity`, `-Infinity`, and `NaN`, and even if the array +contains finite numbers only, they are not drawn from a uniform random +distribution and have no meaningful lower or upper bounds. + +```js +import { Buffer } from 'buffer'; +import { randomFill } from 'crypto'; + +const a = new Uint32Array(10); +randomFill(a, (err, buf) => { + if (err) throw err; + console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) + .toString('hex')); +}); + +const b = new DataView(new ArrayBuffer(10)); +randomFill(b, (err, buf) => { + if (err) throw err; + console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) + .toString('hex')); +}); + +const c = new ArrayBuffer(10); +randomFill(c, (err, buf) => { + if (err) throw err; + console.log(Buffer.from(buf).toString('hex')); +}); +``` + +##### Type Parameters + +| Type Parameter | +| ------ | +| `T` *extends* [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +##### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `buffer` | `T` | Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`. | +| `offset` | `number` | | +| `callback` | (`err`: `Error` \| `null`, `buf`: `T`) => `void` | `function(err, buf) {}`. | + +##### Returns + +`void` + +#### Call Signature + +> **randomFill**\<`T`\>(`buffer`: `T`, `offset`: `number`, `size`: `number`, `callback`: (`err`: `Error` \| `null`, `buf`: `T`) => `void`): `void` + +This function is similar to [randomBytes](#randombytes) but requires the first +argument to be a `Buffer` that will be filled. It also +requires that a callback is passed in. + +If the `callback` function is not provided, an error will be thrown. + +```js +import { Buffer } from 'buffer'; +import { randomFill } from 'crypto'; + +const buf = Buffer.alloc(10); +randomFill(buf, (err, buf) => { + if (err) throw err; + console.log(buf.toString('hex')); +}); + +randomFill(buf, 5, (err, buf) => { + if (err) throw err; + console.log(buf.toString('hex')); +}); + +// The above is equivalent to the following: +randomFill(buf, 5, 5, (err, buf) => { + if (err) throw err; + console.log(buf.toString('hex')); +}); +``` + +Any `ArrayBuffer`, `TypedArray`, or `DataView` instance may be passed as `buffer`. + +While this includes instances of `Float32Array` and `Float64Array`, this +function should not be used to generate random floating-point numbers. The +result may contain `+Infinity`, `-Infinity`, and `NaN`, and even if the array +contains finite numbers only, they are not drawn from a uniform random +distribution and have no meaningful lower or upper bounds. + +```js +import { Buffer } from 'buffer'; +import { randomFill } from 'crypto'; + +const a = new Uint32Array(10); +randomFill(a, (err, buf) => { + if (err) throw err; + console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) + .toString('hex')); +}); + +const b = new DataView(new ArrayBuffer(10)); +randomFill(b, (err, buf) => { + if (err) throw err; + console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) + .toString('hex')); +}); + +const c = new ArrayBuffer(10); +randomFill(c, (err, buf) => { + if (err) throw err; + console.log(Buffer.from(buf).toString('hex')); +}); +``` + +##### Type Parameters + +| Type Parameter | +| ------ | +| `T` *extends* [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +##### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `buffer` | `T` | Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`. | +| `offset` | `number` | | +| `size` | `number` | | +| `callback` | (`err`: `Error` \| `null`, `buf`: `T`) => `void` | `function(err, buf) {}`. | + +##### Returns + +`void` + +*** + +### randomFillSync() + +> **randomFillSync**\<`T`\>(`buffer`: `T`, `offset?`: `number`, `size?`: `number`): `T` + +Synchronous version of [randomFill](#randomfill). + +```js +import { Buffer } from 'buffer'; +import { randomFillSync } from 'crypto'; + +const buf = Buffer.alloc(10); +console.log(randomFillSync(buf).toString('hex')); + +randomFillSync(buf, 5); +console.log(buf.toString('hex')); + +// The above is equivalent to the following: +randomFillSync(buf, 5, 5); +console.log(buf.toString('hex')); +``` + +Any `ArrayBuffer`, `TypedArray` or `DataView` instance may be passed as`buffer`. + +```js +import { Buffer } from 'buffer'; +import { randomFillSync } from 'crypto'; + +const a = new Uint32Array(10); +console.log(Buffer.from(randomFillSync(a).buffer, + a.byteOffset, a.byteLength).toString('hex')); + +const b = new DataView(new ArrayBuffer(10)); +console.log(Buffer.from(randomFillSync(b).buffer, + b.byteOffset, b.byteLength).toString('hex')); + +const c = new ArrayBuffer(10); +console.log(Buffer.from(randomFillSync(c)).toString('hex')); +``` + +#### Type Parameters + +| Type Parameter | +| ------ | +| `T` *extends* [`ArrayBufferView`](../llrt/globals/namespaces/QuickJS.md#arraybufferview) | + +#### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `buffer` | `T` | Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`. | +| `offset?` | `number` | | +| `size?` | `number` | | + +#### Returns + +`T` + +The object passed as `buffer` argument. + +*** + +### randomInt() + +#### Call Signature + +> **randomInt**(`max`: `number`): `number` + +Return a random integer `n` such that `min <= n < max`. This +implementation avoids [modulo bias](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Modulo_bias). + +The range (`max - min`) must be less than 2**48. `min` and `max` must +be [safe integers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger). + +```js +// Synchronous +import { randomInt } from 'crypto'; + +const n = randomInt(3); +console.log(`Random number chosen from (0, 1, 2): ${n}`); +``` + +```js +// With `min` argument +import { randomInt } from 'crypto'; + +const n = randomInt(1, 7); +console.log(`The dice rolled: ${n}`); +``` + +##### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `max` | `number` | End of random range (exclusive). | + +##### Returns + +`number` + +#### Call Signature + +> **randomInt**(`min`: `number`, `max`: `number`): `number` + +Return a random integer `n` such that `min <= n < max`. This +implementation avoids [modulo bias](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Modulo_bias). + +The range (`max - min`) must be less than 2**48. `min` and `max` must +be [safe integers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger). + +```js +// Synchronous +import { randomInt } from 'crypto'; + +const n = randomInt(3); +console.log(`Random number chosen from (0, 1, 2): ${n}`); +``` + +```js +// With `min` argument +import { randomInt } from 'crypto'; + +const n = randomInt(1, 7); +console.log(`The dice rolled: ${n}`); +``` + +##### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `min` | `number` | Start of random range (inclusive). | +| `max` | `number` | End of random range (exclusive). | + +##### Returns + +`number` + +*** + +### randomUUID() + +> **randomUUID**(): `` `${string}-${string}-${string}-${string}-${string}` `` + +Generates a random [RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) version 4 UUID. +The UUID is generated using a cryptographic pseudorandom number generator. + +#### Returns + +`` `${string}-${string}-${string}-${string}-${string}` `` diff --git a/src/reference/modules/caido/http.md b/src/reference/modules/caido/http.md index 6fba7dd..926c89e 100644 --- a/src/reference/modules/caido/http.md +++ b/src/reference/modules/caido/http.md @@ -16,7 +16,7 @@ A [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) encapsulates i ##### Constructor -> **new Blob**(`parts`: (`string` \| `ArrayBuffer` \| [`Blob`](#blob))[], `opts?`: [`BlobOpts`](#blobopts)): [`Blob`](#blob) +> **new Blob**(`parts`: (`string` \| [`Blob`](#blob) \| `ArrayBuffer`)[], `opts?`: [`BlobOpts`](#blobopts)): [`Blob`](#blob) Creates a new `Blob` object containing a concatenation of the given sources. @@ -29,7 +29,7 @@ String sources are also copied into the `Blob`. | Parameter | Type | | ------ | ------ | -| `parts` | (`string` \| `ArrayBuffer` \| [`Blob`](#blob))[] | +| `parts` | (`string` \| [`Blob`](#blob) \| `ArrayBuffer`)[] | | `opts?` | [`BlobOpts`](#blobopts) | ###### Returns @@ -116,7 +116,7 @@ A [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) encapsulates i ##### Constructor -> **new File**(`data`: (`string` \| `ArrayBuffer` \| [`Blob`](#blob))[], `fileName`: `string`, `opts?`: [`FileOpts`](#fileopts)): [`File`](#file) +> **new File**(`data`: (`string` \| [`Blob`](#blob) \| `ArrayBuffer`)[], `fileName`: `string`, `opts?`: [`FileOpts`](#fileopts)): [`File`](#file) Returns a newly constructed File. @@ -124,7 +124,7 @@ Returns a newly constructed File. | Parameter | Type | | ------ | ------ | -| `data` | (`string` \| `ArrayBuffer` \| [`Blob`](#blob))[] | +| `data` | (`string` \| [`Blob`](#blob) \| `ArrayBuffer`)[] | | `fileName` | `string` | | `opts?` | [`FileOpts`](#fileopts) | diff --git a/src/reference/modules/extra/url.md b/src/reference/modules/extra/url.md deleted file mode 100644 index f845d7d..0000000 --- a/src/reference/modules/extra/url.md +++ /dev/null @@ -1,281 +0,0 @@ -[@caido/quickjs-types](../index.md) / extra/url - -# extra/url - -## Classes - -### URLSearchParams - -The URLSearchParams interface defines utility methods to work with the query string of a URL. - -#### Implements - -- `Iterable`\<\[`string`, `string`\]\> - -#### Constructors - -##### new URLSearchParams() - -> **new URLSearchParams**(`init`?: `string` \| [`URLSearchParams`](url.md#urlsearchparams) \| \{\} \| `Iterable`\ \| readonly readonly \[`string`, `string`\][]): [`URLSearchParams`](url.md#urlsearchparams) - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `init`? | `string` \| [`URLSearchParams`](url.md#urlsearchparams) \| \{\} \| `Iterable`\ \| readonly readonly \[`string`, `string`\][] | - -###### Returns - -[`URLSearchParams`](url.md#urlsearchparams) - -#### Properties - -##### size - -> `readonly` **size**: `number` - -The total number of parameter entries. - -#### Methods - -##### \[iterator\]() - -> **\[iterator\]**(): `IterableIterator`\<\[`string`, `string`\]\> - -###### Returns - -`IterableIterator`\<\[`string`, `string`\]\> - -###### Implementation of - -`Iterable.[iterator]` - -##### append() - -> **append**(`name`: `string`, `value`: `string`): `void` - -Append a new name-value pair to the query string. - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `name` | `string` | -| `value` | `string` | - -###### Returns - -`void` - -##### delete() - -> **delete**(`name`: `string`, `value`?: `string`): `void` - -If `value` is provided, removes all name-value pairs -where name is `name` and value is `value`. - -If `value` is not provided, removes all name-value pairs whose name is `name`. - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `name` | `string` | -| `value`? | `string` | - -###### Returns - -`void` - -##### entries() - -> **entries**(): `IterableIterator`\<\[`string`, `string`\]\> - -Returns an ES6 `Iterator` over each of the name-value pairs in the query. -Each item of the iterator is a JavaScript `Array`. The first item of the `Array` is the `name`, the second item of the `Array` is the `value`. - -Alias for `urlSearchParams[@@iterator]()`. - -###### Returns - -`IterableIterator`\<\[`string`, `string`\]\> - -##### forEach() - -> **forEach**(`fn`: (`value`: `string`, `name`: `string`) => `void`): `void` - -Iterates over each name-value pair in the query and invokes the given function. - -```js -const myURL = new URL('https://example.org/?a=b&c=d'); -myURL.searchParams.forEach((value, name) => { - console.log(name, value); -}); -// Prints: -// a b -// c d -``` - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `fn` | (`value`: `string`, `name`: `string`) => `void` | Invoked for each name-value pair in the query | - -###### Returns - -`void` - -##### get() - -> **get**(`name`: `string`): `null` \| `string` - -Returns the value of the first name-value pair whose name is `name`. If there -are no such pairs, `null` is returned. - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `name` | `string` | - -###### Returns - -`null` \| `string` - -or `null` if there is no name-value pair with the given `name`. - -##### getAll() - -> **getAll**(`name`: `string`): `string`[] - -Returns the values of all name-value pairs whose name is `name`. If there are -no such pairs, an empty array is returned. - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `name` | `string` | - -###### Returns - -`string`[] - -##### has() - -> **has**(`name`: `string`, `value`?: `string`): `boolean` - -Checks if the `URLSearchParams` object contains key-value pair(s) based on `name` and an optional `value` argument. - -If `value` is provided, returns `true` when name-value pair with -same `name` and `value` exists. - -If `value` is not provided, returns `true` if there is at least one name-value -pair whose name is `name`. - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `name` | `string` | -| `value`? | `string` | - -###### Returns - -`boolean` - -##### keys() - -> **keys**(): `IterableIterator`\<`string`\> - -Returns an ES6 `Iterator` over the names of each name-value pair. - -```js -const params = new URLSearchParams('foo=bar&foo=baz'); -for (const name of params.keys()) { - console.log(name); -} -// Prints: -// foo -// foo -``` - -###### Returns - -`IterableIterator`\<`string`\> - -##### set() - -> **set**(`name`: `string`, `value`: `string`): `void` - -Sets the value in the `URLSearchParams` object associated with `name` to `value`. If there are any pre-existing name-value pairs whose names are `name`, -set the first such pair's value to `value` and remove all others. If not, -append the name-value pair to the query string. - -```js -const params = new URLSearchParams(); -params.append('foo', 'bar'); -params.append('foo', 'baz'); -params.append('abc', 'def'); -console.log(params.toString()); -// Prints foo=bar&foo=baz&abc=def - -params.set('foo', 'def'); -params.set('xyz', 'opq'); -console.log(params.toString()); -// Prints foo=def&abc=def&xyz=opq -``` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `name` | `string` | -| `value` | `string` | - -###### Returns - -`void` - -##### sort() - -> **sort**(): `void` - -Sort all existing name-value pairs in-place by their names. Sorting is done -with a [stable sorting algorithm](https://en.wikipedia.org/wiki/Sorting_algorithm#Stability), so relative order between name-value pairs -with the same name is preserved. - -This method can be used, in particular, to increase cache hits. - -```js -const params = new URLSearchParams('query[]=abc&type=search&query[]=123'); -params.sort(); -console.log(params.toString()); -// Prints query%5B%5D=abc&query%5B%5D=123&type=search -``` - -###### Returns - -`void` - -##### toString() - -> **toString**(): `string` - -Returns the search parameters serialized as a string, with characters -percent-encoded where necessary. - -###### Returns - -`string` - -##### values() - -> **values**(): `IterableIterator`\<`string`\> - -Returns an ES6 `Iterator` over the values of each name-value pair. - -###### Returns - -`IterableIterator`\<`string`\> diff --git a/src/reference/modules/index.md b/src/reference/modules/index.md index 09daa60..10121de 100644 --- a/src/reference/modules/index.md +++ b/src/reference/modules/index.md @@ -1,21 +1,33 @@ -# @caido/quickjs-types +# QuickJS Modules + +Here is the reference of the modules available in our engine. + +This documentation is auto-generated from the Typescript typing ([`@caido/quickjs-types`](https://www.npmjs.com/package/@caido/quickjs-types)) which is the source of truth. + +Some elements are similar to `Node.JS`, but some imports will be different and start with `caido:`. ## Modules -| Module | Description | -| ------ | ------ | -| [caido/http](caido/http.md) | - | -| [extra/console](extra/console.md) | - | -| [extra/os](extra/os.md) | - | -| [extra/sqlite](extra/sqlite.md) | - | -| [extra/timers](extra/timers.md) | - | -| [llrt/abort](llrt/abort.md) | - | -| [llrt/buffer](llrt/buffer.md) | - | -| [llrt/child\_process](llrt/child_process.md) | - | -| [llrt/dom-events](llrt/dom-events.md) | - | -| [llrt/fs](llrt/fs/index.md) | - | -| [llrt/globals](llrt/globals/index.md) | - | -| [llrt/net](llrt/net.md) | - | -| [llrt/path](llrt/path/index.md) | - | -| [llrt/process](llrt/process/index.md) | - | -| [llrt/stream](llrt/stream/index.md) | - | +| Module | Description | Import | Global | +| ---------------------------------------- | ------------------------ | ------------------ | ------ | +| [abort](llrt/abort.md) | Abort signaling | N/A | ✔︎ | +| [buffer](llrt/buffer.md) | Buffers | `buffer` | ✔︎ | +| [child_process](llrt/child_process.md) | Process spawning | `child_process` | ✘ | +| [console](extra/console.md) | Console logging | N/A | ✔︎ | +| [crypto](caido/crypto.md) | Cryptographic primitives | `crypto` | ✘ | +| [dom-events](llrt/dom-events.md) | Event Listeners | N/A | ✔︎ | +| [dns](llrt/dns.md) | DNS | `dns` | ✘ | +| [events](llrt/events.md) | Event Emitter | `events` | ✘ | +| [fs](llrt/fs/index.md) | File system | `fs`, `fs/promise` | ✘ | +| [http](caido/http.md) | Fetch implementation | `caido:http` | ✘ | +| [https](llrt/https.md) | HTTPS | `https` | ✘ | +| [globals](llrt/globals/index.md) | Global classes | N/A | ✔︎ | +| [net](llrt/net.md) | Sockets | `net` | ✘ | +| [os](extra/os.md) | OS information | `os` | ✘ | +| [path](llrt/path/index.md) | Path transformation | `path` | ✘ | +| [sqlite](extra/sqlite.md) | SQlite access | `sqlite` | ✘ | +| [stream](llrt/stream/stream.md) | Streams (basic) | `stream` | ✔︎ | +| [stream/web](llrt/web/index.md) | Streams Web | `stream/web` | ✘ | +| [string_decoder](llrt/string_decoder.md) | String Decoder | `string_decoder` | ✘ | +| [timers](extra/timers.md) | Timers | N/A | ✔︎ | +| [url](llrt/url/index.md) | URL utilities | `url` | ✔︎ | diff --git a/src/reference/modules/llrt/buffer.md b/src/reference/modules/llrt/buffer.md index 9bc5aa2..bb857d6 100644 --- a/src/reference/modules/llrt/buffer.md +++ b/src/reference/modules/llrt/buffer.md @@ -1640,7 +1640,7 @@ A `TypeError` will be thrown if `size` is not a number. ##### byteLength() -> **byteLength**(`string`: `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](#buffer), `encoding?`: [`BufferEncoding`](#bufferencoding)): `number` +> **byteLength**(`string`: `string` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer`, `encoding?`: [`BufferEncoding`](#bufferencoding)): `number` Returns the byte length of a string when encoded using `encoding`. This is not the same as [`String.prototype.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length), which does not account @@ -1665,7 +1665,7 @@ er.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuf | Parameter | Type | Description | | ------ | ------ | ------ | -| `string` | `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](#buffer) | A value to calculate the length of. | +| `string` | `string` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer` | A value to calculate the length of. | | `encoding?` | [`BufferEncoding`](#bufferencoding) | If `string` is a string, this is its encoding. | ###### Returns diff --git a/src/reference/modules/llrt/child_process.md b/src/reference/modules/llrt/child_process.md index 484262b..533961d 100644 --- a/src/reference/modules/llrt/child_process.md +++ b/src/reference/modules/llrt/child_process.md @@ -13,7 +13,7 @@ use the [spawn](#spawn) method to create instances of `ChildProcess`. #### Extends -- [`EventEmitter`](globals/index.md#eventemitter) +- [`EventEmitter`](events.md#eventemitter) #### Extended by @@ -32,7 +32,7 @@ use the [spawn](#spawn) method to create instances of `ChildProcess`. ###### Inherited from -[`EventEmitter`](globals/index.md#eventemitter).[`constructor`](globals/index.md#constructor) +[`EventEmitter`](events.md#eventemitter).[`constructor`](events.md#constructor) #### Properties @@ -143,7 +143,7 @@ events.EventEmitter ###### Overrides -[`EventEmitter`](globals/index.md#eventemitter).[`addListener`](globals/index.md#addlistener) +[`EventEmitter`](events.md#eventemitter).[`addListener`](events.md#addlistener) ###### Call Signature @@ -265,7 +265,7 @@ myEmitter.emit('event', 1, 2, 3, 4, 5); ###### Overrides -[`EventEmitter`](globals/index.md#eventemitter).[`emit`](globals/index.md#emit) +[`EventEmitter`](events.md#eventemitter).[`emit`](events.md#emit) ###### Call Signature @@ -353,7 +353,7 @@ console.log(myEE.eventNames()); ###### Inherited from -[`EventEmitter`](globals/index.md#eventemitter).[`eventNames`](globals/index.md#eventnames) +[`EventEmitter`](events.md#eventemitter).[`eventNames`](events.md#eventnames) ##### kill() @@ -451,7 +451,7 @@ Alias for `emitter.removeListener()`. ###### Inherited from -[`EventEmitter`](globals/index.md#eventemitter).[`off`](globals/index.md#off) +[`EventEmitter`](events.md#eventemitter).[`off`](events.md#off) ##### on() @@ -499,7 +499,7 @@ myEE.emit('foo'); ###### Overrides -[`EventEmitter`](globals/index.md#eventemitter).[`on`](globals/index.md#on) +[`EventEmitter`](events.md#eventemitter).[`on`](events.md#on) ###### Call Signature @@ -600,7 +600,7 @@ v0.3.0 ###### Overrides -[`EventEmitter`](globals/index.md#eventemitter).[`once`](globals/index.md#once) +[`EventEmitter`](events.md#eventemitter).[`once`](events.md#once) ###### Call Signature @@ -685,7 +685,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Overrides -[`EventEmitter`](globals/index.md#eventemitter).[`prependListener`](globals/index.md#prependlistener) +[`EventEmitter`](events.md#eventemitter).[`prependListener`](events.md#prependlistener) ###### Call Signature @@ -768,7 +768,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Overrides -[`EventEmitter`](globals/index.md#eventemitter).[`prependOnceListener`](globals/index.md#prependoncelistener) +[`EventEmitter`](events.md#eventemitter).[`prependOnceListener`](events.md#prependoncelistener) ###### Call Signature @@ -921,7 +921,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Inherited from -[`EventEmitter`](globals/index.md#eventemitter).[`removeListener`](globals/index.md#removelistener) +[`EventEmitter`](events.md#eventemitter).[`removeListener`](events.md#removelistener) ## Interfaces diff --git a/src/reference/modules/llrt/crypto.md b/src/reference/modules/llrt/crypto.md deleted file mode 100644 index 14706b8..0000000 --- a/src/reference/modules/llrt/crypto.md +++ /dev/null @@ -1,780 +0,0 @@ -[@caido/quickjs-types](../index.md) / llrt/crypto - -# llrt/crypto - -## Classes - -### Hash - -The `Hash` class is a utility for creating hash digests of data. - -Using the `hash.update()` and `hash.digest()` methods to produce the -computed hash. - -The [createHash](#createhash) method is used to create `Hash` instances. -`Hash`objects are not to be created directly using the `new` keyword. - -Example: Using the `hash.update()` and `hash.digest()` methods: - -```js -import { createHash } from 'crypto'; - -const hash = createHash('sha256'); - -hash.update('some data to hash'); -console.log(hash.digest('hex')); -// Prints: -// 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50 -``` - -#### Methods - -##### digest() - -###### Call Signature - -> **digest**(): [`Buffer`](buffer.md#buffer) - -Calculates the digest of all of the data passed to be hashed (using the `hash.update()` method). -If `encoding` is provided a string will be returned; otherwise -a `Buffer` is returned. - -The `Hash` object can not be used again after `hash.digest()` method has been -called. Multiple calls will cause an error to be thrown. - -###### Returns - -[`Buffer`](buffer.md#buffer) - -###### Call Signature - -> **digest**(`encoding`: [`BinaryToTextEncoding`](#binarytotextencoding)): `string` - -Calculates the digest of all of the data passed to be hashed (using the `hash.update()` method). -If `encoding` is provided a string will be returned; otherwise -a `Buffer` is returned. - -The `Hash` object can not be used again after `hash.digest()` method has been -called. Multiple calls will cause an error to be thrown. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `encoding` | [`BinaryToTextEncoding`](#binarytotextencoding) | The `encoding` of the return value. | - -###### Returns - -`string` - -##### update() - -###### Call Signature - -> **update**(`data`: [`BinaryLike`](#binarylike)): [`Hash`](#hash) - -Updates the hash content with the given `data`, the encoding of which -is given in `inputEncoding`. -If `encoding` is not provided, and the `data` is a string, an -encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, -then `inputEncoding` is ignored. - -This can be called many times with new data as it is streamed. - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `data` | [`BinaryLike`](#binarylike) | - -###### Returns - -[`Hash`](#hash) - -###### Call Signature - -> **update**(`data`: `string`, `inputEncoding`: [`Encoding`](#encoding)): [`Hash`](#hash) - -Updates the hash content with the given `data`, the encoding of which -is given in `inputEncoding`. -If `encoding` is not provided, and the `data` is a string, an -encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, -then `inputEncoding` is ignored. - -This can be called many times with new data as it is streamed. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `data` | `string` | - | -| `inputEncoding` | [`Encoding`](#encoding) | The `encoding` of the `data` string. | - -###### Returns - -[`Hash`](#hash) - -*** - -### Hmac - -The `Hmac` class is a utility for creating cryptographic HMAC digests. - -Using the `hmac.update()` and `hmac.digest()` methods to produce the -computed HMAC digest. - -The [createHmac](#createhmac) method is used to create `Hmac` instances. -`Hmac`objects are not to be created directly using the `new` keyword. - -Example: Using the `hmac.update()` and `hmac.digest()` methods: - -```js -import { createHmac } from 'crypto'; - -const hmac = createHmac('sha256', 'a secret'); - -hmac.update('some data to hash'); -console.log(hmac.digest('hex')); -// Prints: -// 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e -``` - -#### Methods - -##### digest() - -###### Call Signature - -> **digest**(): [`Buffer`](buffer.md#buffer) - -Calculates the HMAC digest of all of the data passed using `hmac.update()`. -If `encoding` is -provided a string is returned; otherwise a `Buffer` is returned; - -The `Hmac` object can not be used again after `hmac.digest()` has been -called. Multiple calls to `hmac.digest()` will result in an error being thrown. - -###### Returns - -[`Buffer`](buffer.md#buffer) - -###### Call Signature - -> **digest**(`encoding`: [`BinaryToTextEncoding`](#binarytotextencoding)): `string` - -Calculates the HMAC digest of all of the data passed using `hmac.update()`. -If `encoding` is -provided a string is returned; otherwise a `Buffer` is returned; - -The `Hmac` object can not be used again after `hmac.digest()` has been -called. Multiple calls to `hmac.digest()` will result in an error being thrown. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `encoding` | [`BinaryToTextEncoding`](#binarytotextencoding) | The `encoding` of the return value. | - -###### Returns - -`string` - -##### update() - -###### Call Signature - -> **update**(`data`: [`BinaryLike`](#binarylike)): [`Hmac`](#hmac) - -Updates the `Hmac` content with the given `data`, the encoding of which -is given in `inputEncoding`. -If `encoding` is not provided, and the `data` is a string, an -encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, -then `inputEncoding` is ignored. - -This can be called many times with new data as it is streamed. - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `data` | [`BinaryLike`](#binarylike) | - -###### Returns - -[`Hmac`](#hmac) - -###### Call Signature - -> **update**(`data`: `string`, `inputEncoding`: [`Encoding`](#encoding)): [`Hmac`](#hmac) - -Updates the `Hmac` content with the given `data`, the encoding of which -is given in `inputEncoding`. -If `encoding` is not provided, and the `data` is a string, an -encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, -then `inputEncoding` is ignored. - -This can be called many times with new data as it is streamed. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `data` | `string` | - | -| `inputEncoding` | [`Encoding`](#encoding) | The `encoding` of the `data` string. | - -###### Returns - -[`Hmac`](#hmac) - -## Type Aliases - -### BinaryLike - -> **BinaryLike** = `string` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) - -*** - -### BinaryToTextEncoding - -> **BinaryToTextEncoding** = `"base64"` \| `"hex"` - -*** - -### CharacterEncoding - -> **CharacterEncoding** = `"utf8"` \| `"utf-8"` \| `"utf16le"` \| `"utf-16le"` \| `"latin1"` - -*** - -### Encoding - -> **Encoding** = [`BinaryToTextEncoding`](#binarytotextencoding) \| [`CharacterEncoding`](#characterencoding) \| [`LegacyCharacterEncoding`](#legacycharacterencoding) - -*** - -### LegacyCharacterEncoding - -> **LegacyCharacterEncoding** = `"ascii"` - -*** - -### UUID - -> **UUID** = `` `${string}-${string}-${string}-${string}-${string}` `` - -## Functions - -### createHash() - -> **createHash**(`algorithm`: `string`): [`Hash`](#hash) - -Creates and returns a `Hash` object that can be used to generate hash digests -using the given `algorithm`. - -The `algorithm` is supported by `'sha1'`, `'sha256'`,`'sha384'` and `'sha512'`. - -#### Parameters - -| Parameter | Type | -| ------ | ------ | -| `algorithm` | `string` | - -#### Returns - -[`Hash`](#hash) - -*** - -### createHmac() - -> **createHmac**(`algorithm`: `string`, `key`: [`BinaryLike`](#binarylike)): [`Hmac`](#hmac) - -Creates and returns an `Hmac` object that uses the given `algorithm` and `key`. - -The `algorithm` is supported by `'sha1'`, `'sha256'`,`'sha384'` and `'sha512'`. - -The `key` is the HMAC key used to generate the cryptographic HMAC hash. -If it is a string, please consider `caveats when using strings as inputs to cryptographic APIs`. -If it was obtained from a cryptographically secure source of entropy, such as [randomBytes](#randombytes) -or generateKey, its length should not exceed the block size of `algorithm` -(e.g., 512 bits for SHA-256). - -#### Parameters - -| Parameter | Type | -| ------ | ------ | -| `algorithm` | `string` | -| `key` | [`BinaryLike`](#binarylike) | - -#### Returns - -[`Hmac`](#hmac) - -*** - -### getRandomValues() - -> **getRandomValues**\<`T`\>(`typedArray`: `T`): `T` - -A convenient alias for webcrypto.getRandomValues. This -implementation is not compliant with the Web Crypto spec, to write -web-compatible code use webcrypto.getRandomValues instead. - -#### Type Parameters - -| Type Parameter | -| ------ | -| `T` *extends* [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) | - -#### Parameters - -| Parameter | Type | -| ------ | ------ | -| `typedArray` | `T` | - -#### Returns - -`T` - -Returns `typedArray`. - -*** - -### randomBytes() - -> **randomBytes**(`size`: `number`): [`Buffer`](buffer.md#buffer) - -Generates cryptographically strong pseudorandom data. The `size` argument -is a number indicating the number of bytes to generate. - -the random bytes are generated synchronously and returned as a `Buffer`. -An error will be thrown if there is a problem generating the bytes. - -```js -// Synchronous -import { randomBytes } from 'crypto'; - -const buf = randomBytes(256); -console.log( - `${buf.length} bytes of random data: ${buf.toString('hex')}`); -``` - -The `crypto.randomBytes()` method will not complete until there is -sufficient entropy available. -This should normally never take longer than a few milliseconds. The only time -when generating the random bytes may conceivably block for a longer period of -time is right after boot, when the whole system is still low on entropy. - -#### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `size` | `number` | The number of bytes to generate. The `size` must not be larger than `2**31 - 1`. | - -#### Returns - -[`Buffer`](buffer.md#buffer) - -*** - -### randomFill() - -#### Call Signature - -> **randomFill**\<`T`\>(`buffer`: `T`, `callback`: (`err`: `Error` \| `null`, `buf`: `T`) => `void`): `void` - -This function is similar to [randomBytes](#randombytes) but requires the first -argument to be a `Buffer` that will be filled. It also -requires that a callback is passed in. - -If the `callback` function is not provided, an error will be thrown. - -```js -import { Buffer } from 'buffer'; -import { randomFill } from 'crypto'; - -const buf = Buffer.alloc(10); -randomFill(buf, (err, buf) => { - if (err) throw err; - console.log(buf.toString('hex')); -}); - -randomFill(buf, 5, (err, buf) => { - if (err) throw err; - console.log(buf.toString('hex')); -}); - -// The above is equivalent to the following: -randomFill(buf, 5, 5, (err, buf) => { - if (err) throw err; - console.log(buf.toString('hex')); -}); -``` - -Any `ArrayBuffer`, `TypedArray`, or `DataView` instance may be passed as `buffer`. - -While this includes instances of `Float32Array` and `Float64Array`, this -function should not be used to generate random floating-point numbers. The -result may contain `+Infinity`, `-Infinity`, and `NaN`, and even if the array -contains finite numbers only, they are not drawn from a uniform random -distribution and have no meaningful lower or upper bounds. - -```js -import { Buffer } from 'buffer'; -import { randomFill } from 'crypto'; - -const a = new Uint32Array(10); -randomFill(a, (err, buf) => { - if (err) throw err; - console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) - .toString('hex')); -}); - -const b = new DataView(new ArrayBuffer(10)); -randomFill(b, (err, buf) => { - if (err) throw err; - console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) - .toString('hex')); -}); - -const c = new ArrayBuffer(10); -randomFill(c, (err, buf) => { - if (err) throw err; - console.log(Buffer.from(buf).toString('hex')); -}); -``` - -##### Type Parameters - -| Type Parameter | -| ------ | -| `T` *extends* [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) | - -##### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `buffer` | `T` | Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`. | -| `callback` | (`err`: `Error` \| `null`, `buf`: `T`) => `void` | `function(err, buf) {}`. | - -##### Returns - -`void` - -#### Call Signature - -> **randomFill**\<`T`\>(`buffer`: `T`, `offset`: `number`, `callback`: (`err`: `Error` \| `null`, `buf`: `T`) => `void`): `void` - -This function is similar to [randomBytes](#randombytes) but requires the first -argument to be a `Buffer` that will be filled. It also -requires that a callback is passed in. - -If the `callback` function is not provided, an error will be thrown. - -```js -import { Buffer } from 'buffer'; -import { randomFill } from 'crypto'; - -const buf = Buffer.alloc(10); -randomFill(buf, (err, buf) => { - if (err) throw err; - console.log(buf.toString('hex')); -}); - -randomFill(buf, 5, (err, buf) => { - if (err) throw err; - console.log(buf.toString('hex')); -}); - -// The above is equivalent to the following: -randomFill(buf, 5, 5, (err, buf) => { - if (err) throw err; - console.log(buf.toString('hex')); -}); -``` - -Any `ArrayBuffer`, `TypedArray`, or `DataView` instance may be passed as `buffer`. - -While this includes instances of `Float32Array` and `Float64Array`, this -function should not be used to generate random floating-point numbers. The -result may contain `+Infinity`, `-Infinity`, and `NaN`, and even if the array -contains finite numbers only, they are not drawn from a uniform random -distribution and have no meaningful lower or upper bounds. - -```js -import { Buffer } from 'buffer'; -import { randomFill } from 'crypto'; - -const a = new Uint32Array(10); -randomFill(a, (err, buf) => { - if (err) throw err; - console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) - .toString('hex')); -}); - -const b = new DataView(new ArrayBuffer(10)); -randomFill(b, (err, buf) => { - if (err) throw err; - console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) - .toString('hex')); -}); - -const c = new ArrayBuffer(10); -randomFill(c, (err, buf) => { - if (err) throw err; - console.log(Buffer.from(buf).toString('hex')); -}); -``` - -##### Type Parameters - -| Type Parameter | -| ------ | -| `T` *extends* [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) | - -##### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `buffer` | `T` | Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`. | -| `offset` | `number` | | -| `callback` | (`err`: `Error` \| `null`, `buf`: `T`) => `void` | `function(err, buf) {}`. | - -##### Returns - -`void` - -#### Call Signature - -> **randomFill**\<`T`\>(`buffer`: `T`, `offset`: `number`, `size`: `number`, `callback`: (`err`: `Error` \| `null`, `buf`: `T`) => `void`): `void` - -This function is similar to [randomBytes](#randombytes) but requires the first -argument to be a `Buffer` that will be filled. It also -requires that a callback is passed in. - -If the `callback` function is not provided, an error will be thrown. - -```js -import { Buffer } from 'buffer'; -import { randomFill } from 'crypto'; - -const buf = Buffer.alloc(10); -randomFill(buf, (err, buf) => { - if (err) throw err; - console.log(buf.toString('hex')); -}); - -randomFill(buf, 5, (err, buf) => { - if (err) throw err; - console.log(buf.toString('hex')); -}); - -// The above is equivalent to the following: -randomFill(buf, 5, 5, (err, buf) => { - if (err) throw err; - console.log(buf.toString('hex')); -}); -``` - -Any `ArrayBuffer`, `TypedArray`, or `DataView` instance may be passed as `buffer`. - -While this includes instances of `Float32Array` and `Float64Array`, this -function should not be used to generate random floating-point numbers. The -result may contain `+Infinity`, `-Infinity`, and `NaN`, and even if the array -contains finite numbers only, they are not drawn from a uniform random -distribution and have no meaningful lower or upper bounds. - -```js -import { Buffer } from 'buffer'; -import { randomFill } from 'crypto'; - -const a = new Uint32Array(10); -randomFill(a, (err, buf) => { - if (err) throw err; - console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) - .toString('hex')); -}); - -const b = new DataView(new ArrayBuffer(10)); -randomFill(b, (err, buf) => { - if (err) throw err; - console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength) - .toString('hex')); -}); - -const c = new ArrayBuffer(10); -randomFill(c, (err, buf) => { - if (err) throw err; - console.log(Buffer.from(buf).toString('hex')); -}); -``` - -##### Type Parameters - -| Type Parameter | -| ------ | -| `T` *extends* [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) | - -##### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `buffer` | `T` | Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`. | -| `offset` | `number` | | -| `size` | `number` | | -| `callback` | (`err`: `Error` \| `null`, `buf`: `T`) => `void` | `function(err, buf) {}`. | - -##### Returns - -`void` - -*** - -### randomFillSync() - -> **randomFillSync**\<`T`\>(`buffer`: `T`, `offset?`: `number`, `size?`: `number`): `T` - -Synchronous version of [randomFill](#randomfill). - -```js -import { Buffer } from 'buffer'; -import { randomFillSync } from 'crypto'; - -const buf = Buffer.alloc(10); -console.log(randomFillSync(buf).toString('hex')); - -randomFillSync(buf, 5); -console.log(buf.toString('hex')); - -// The above is equivalent to the following: -randomFillSync(buf, 5, 5); -console.log(buf.toString('hex')); -``` - -Any `ArrayBuffer`, `TypedArray` or `DataView` instance may be passed as`buffer`. - -```js -import { Buffer } from 'buffer'; -import { randomFillSync } from 'crypto'; - -const a = new Uint32Array(10); -console.log(Buffer.from(randomFillSync(a).buffer, - a.byteOffset, a.byteLength).toString('hex')); - -const b = new DataView(new ArrayBuffer(10)); -console.log(Buffer.from(randomFillSync(b).buffer, - b.byteOffset, b.byteLength).toString('hex')); - -const c = new ArrayBuffer(10); -console.log(Buffer.from(randomFillSync(c)).toString('hex')); -``` - -#### Type Parameters - -| Type Parameter | -| ------ | -| `T` *extends* [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) | - -#### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `buffer` | `T` | Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`. | -| `offset?` | `number` | | -| `size?` | `number` | | - -#### Returns - -`T` - -The object passed as `buffer` argument. - -*** - -### randomInt() - -#### Call Signature - -> **randomInt**(`max`: `number`): `number` - -Return a random integer `n` such that `min <= n < max`. This -implementation avoids [modulo bias](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Modulo_bias). - -The range (`max - min`) must be less than 2**48. `min` and `max` must -be [safe integers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger). - -```js -// Synchronous -import { randomInt } from 'crypto'; - -const n = randomInt(3); -console.log(`Random number chosen from (0, 1, 2): ${n}`); -``` - -```js -// With `min` argument -import { randomInt } from 'crypto'; - -const n = randomInt(1, 7); -console.log(`The dice rolled: ${n}`); -``` - -##### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `max` | `number` | End of random range (exclusive). | - -##### Returns - -`number` - -#### Call Signature - -> **randomInt**(`min`: `number`, `max`: `number`): `number` - -Return a random integer `n` such that `min <= n < max`. This -implementation avoids [modulo bias](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Modulo_bias). - -The range (`max - min`) must be less than 2**48. `min` and `max` must -be [safe integers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger). - -```js -// Synchronous -import { randomInt } from 'crypto'; - -const n = randomInt(3); -console.log(`Random number chosen from (0, 1, 2): ${n}`); -``` - -```js -// With `min` argument -import { randomInt } from 'crypto'; - -const n = randomInt(1, 7); -console.log(`The dice rolled: ${n}`); -``` - -##### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `min` | `number` | Start of random range (inclusive). | -| `max` | `number` | End of random range (exclusive). | - -##### Returns - -`number` - -*** - -### randomUUID() - -> **randomUUID**(): `` `${string}-${string}-${string}-${string}-${string}` `` - -Generates a random [RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) version 4 UUID. -The UUID is generated using a cryptographic pseudorandom number generator. - -#### Returns - -`` `${string}-${string}-${string}-${string}-${string}` `` diff --git a/src/reference/modules/llrt/dns.md b/src/reference/modules/llrt/dns.md new file mode 100644 index 0000000..05f7a85 --- /dev/null +++ b/src/reference/modules/llrt/dns.md @@ -0,0 +1,409 @@ +[@caido/quickjs-types](../index.md) / llrt/dns + +# llrt/dns + +## Interfaces + +### LookupAddress + +#### Properties + +##### address + +> **address**: `string` + +A string representation of an IPv4 or IPv6 address. + +##### family + +> **family**: `number` + +`4` or `6`, denoting the family of `address`, or `0` if the address is not an IPv4 or IPv6 address. `0` is a likely indicator of a +bug in the name resolution service used by the operating system. + +*** + +### LookupAllOptions + +#### Extends + +- [`LookupOptions`](#lookupoptions) + +#### Properties + +##### all + +> **all**: `true` + +When `true`, the callback returns all resolved addresses in an array. Otherwise, returns a single address. + +###### Default + +```ts +false +``` + +###### Overrides + +[`LookupOptions`](#lookupoptions).[`all`](#all-2) + +##### family? + +> `optional` **family**: `number` \| `"IPv4"` \| `"IPv6"` + +The record family. Must be `4`, `6`, or `0`. +The value 0 indicates that either an IPv4 or IPv6 address is returned. + +###### Default + +```ts +0 +``` + +###### Inherited from + +[`LookupOptions`](#lookupoptions).[`family`](#family-3) + +##### order? + +> `optional` **order**: `"verbatim"` \| `"ipv4first"` \| `"ipv6first"` + +When `verbatim`, the resolved addresses are return unsorted. When `ipv4first`, the resolved addresses are sorted +by placing IPv4 addresses before IPv6 addresses. When `ipv6first`, the resolved addresses are sorted by placing IPv6 +addresses before IPv4 addresses. Default value is configurable using +setDefaultResultOrder or [`--dns-result-order`](https://nodejs.org/docs/latest-v20.x/api/cli.html#--dns-result-orderorder). + +###### Default + +`verbatim` (addresses are not reordered) + +###### Inherited from + +[`LookupOptions`](#lookupoptions).[`order`](#order-2) + +*** + +### LookupOneOptions + +#### Extends + +- [`LookupOptions`](#lookupoptions) + +#### Properties + +##### all? + +> `optional` **all**: `false` + +When `true`, the callback returns all resolved addresses in an array. Otherwise, returns a single address. + +###### Default + +```ts +false +``` + +###### Overrides + +[`LookupOptions`](#lookupoptions).[`all`](#all-2) + +##### family? + +> `optional` **family**: `number` \| `"IPv4"` \| `"IPv6"` + +The record family. Must be `4`, `6`, or `0`. +The value 0 indicates that either an IPv4 or IPv6 address is returned. + +###### Default + +```ts +0 +``` + +###### Inherited from + +[`LookupOptions`](#lookupoptions).[`family`](#family-3) + +##### order? + +> `optional` **order**: `"verbatim"` \| `"ipv4first"` \| `"ipv6first"` + +When `verbatim`, the resolved addresses are return unsorted. When `ipv4first`, the resolved addresses are sorted +by placing IPv4 addresses before IPv6 addresses. When `ipv6first`, the resolved addresses are sorted by placing IPv6 +addresses before IPv4 addresses. Default value is configurable using +setDefaultResultOrder or [`--dns-result-order`](https://nodejs.org/docs/latest-v20.x/api/cli.html#--dns-result-orderorder). + +###### Default + +`verbatim` (addresses are not reordered) + +###### Inherited from + +[`LookupOptions`](#lookupoptions).[`order`](#order-2) + +*** + +### LookupOptions + +#### Extended by + +- [`LookupOneOptions`](#lookuponeoptions) +- [`LookupAllOptions`](#lookupalloptions) + +#### Properties + +##### all? + +> `optional` **all**: `boolean` + +When `true`, the callback returns all resolved addresses in an array. Otherwise, returns a single address. + +###### Default + +```ts +false +``` + +##### family? + +> `optional` **family**: `number` \| `"IPv4"` \| `"IPv6"` + +The record family. Must be `4`, `6`, or `0`. +The value 0 indicates that either an IPv4 or IPv6 address is returned. + +###### Default + +```ts +0 +``` + +##### order? + +> `optional` **order**: `"verbatim"` \| `"ipv4first"` \| `"ipv6first"` + +When `verbatim`, the resolved addresses are return unsorted. When `ipv4first`, the resolved addresses are sorted +by placing IPv4 addresses before IPv6 addresses. When `ipv6first`, the resolved addresses are sorted by placing IPv6 +addresses before IPv4 addresses. Default value is configurable using +setDefaultResultOrder or [`--dns-result-order`](https://nodejs.org/docs/latest-v20.x/api/cli.html#--dns-result-orderorder). + +###### Default + +`verbatim` (addresses are not reordered) + +## Functions + +### lookup() + +#### Call Signature + +> **lookup**(`hostname`: `string`, `family`: `number`, `callback`: (`err`: `Error` \| `null`, `address`: `string`, `family`: `number`) => `void`): `void` + +Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or +AAAA (IPv6) record. All `option` properties are optional. If `options` is an +integer, then it must be `4` or `6` – if `options` is `0` or not provided, then +IPv4 and IPv6 addresses are both returned if found. + +On error, `err` is an `Error` object, where `err.code` is the error code. +Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when +the host name does not exist but also when the lookup fails in other ways +such as no available file descriptors. + +`dns.lookup()` does not necessarily have anything to do with the DNS protocol. +The implementation uses an operating system facility that can associate names +with addresses and vice versa. + +Example usage: + +```js +import dns from 'dns'; +const options = { + family: 6, +}; +dns.lookup('example.com', options, (err, address, family) => + console.log('address: %j family: IPv%s', address, family)); +// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6 + +``` + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `hostname` | `string` | +| `family` | `number` | +| `callback` | (`err`: `Error` \| `null`, `address`: `string`, `family`: `number`) => `void` | + +##### Returns + +`void` + +#### Call Signature + +> **lookup**(`hostname`: `string`, `options`: [`LookupOneOptions`](#lookuponeoptions), `callback`: (`err`: `Error` \| `null`, `address`: `string`, `family`: `number`) => `void`): `void` + +Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or +AAAA (IPv6) record. All `option` properties are optional. If `options` is an +integer, then it must be `4` or `6` – if `options` is `0` or not provided, then +IPv4 and IPv6 addresses are both returned if found. + +On error, `err` is an `Error` object, where `err.code` is the error code. +Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when +the host name does not exist but also when the lookup fails in other ways +such as no available file descriptors. + +`dns.lookup()` does not necessarily have anything to do with the DNS protocol. +The implementation uses an operating system facility that can associate names +with addresses and vice versa. + +Example usage: + +```js +import dns from 'dns'; +const options = { + family: 6, +}; +dns.lookup('example.com', options, (err, address, family) => + console.log('address: %j family: IPv%s', address, family)); +// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6 + +``` + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `hostname` | `string` | +| `options` | [`LookupOneOptions`](#lookuponeoptions) | +| `callback` | (`err`: `Error` \| `null`, `address`: `string`, `family`: `number`) => `void` | + +##### Returns + +`void` + +#### Call Signature + +> **lookup**(`hostname`: `string`, `options`: [`LookupAllOptions`](#lookupalloptions), `callback`: (`err`: `Error` \| `null`, `addresses`: [`LookupAddress`](#lookupaddress)[]) => `void`): `void` + +Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or +AAAA (IPv6) record. All `option` properties are optional. If `options` is an +integer, then it must be `4` or `6` – if `options` is `0` or not provided, then +IPv4 and IPv6 addresses are both returned if found. + +On error, `err` is an `Error` object, where `err.code` is the error code. +Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when +the host name does not exist but also when the lookup fails in other ways +such as no available file descriptors. + +`dns.lookup()` does not necessarily have anything to do with the DNS protocol. +The implementation uses an operating system facility that can associate names +with addresses and vice versa. + +Example usage: + +```js +import dns from 'dns'; +const options = { + family: 6, +}; +dns.lookup('example.com', options, (err, address, family) => + console.log('address: %j family: IPv%s', address, family)); +// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6 + +``` + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `hostname` | `string` | +| `options` | [`LookupAllOptions`](#lookupalloptions) | +| `callback` | (`err`: `Error` \| `null`, `addresses`: [`LookupAddress`](#lookupaddress)[]) => `void` | + +##### Returns + +`void` + +#### Call Signature + +> **lookup**(`hostname`: `string`, `options`: [`LookupOptions`](#lookupoptions), `callback`: (`err`: `Error` \| `null`, `address`: `string` \| [`LookupAddress`](#lookupaddress)[], `family`: `number`) => `void`): `void` + +Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or +AAAA (IPv6) record. All `option` properties are optional. If `options` is an +integer, then it must be `4` or `6` – if `options` is `0` or not provided, then +IPv4 and IPv6 addresses are both returned if found. + +On error, `err` is an `Error` object, where `err.code` is the error code. +Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when +the host name does not exist but also when the lookup fails in other ways +such as no available file descriptors. + +`dns.lookup()` does not necessarily have anything to do with the DNS protocol. +The implementation uses an operating system facility that can associate names +with addresses and vice versa. + +Example usage: + +```js +import dns from 'dns'; +const options = { + family: 6, +}; +dns.lookup('example.com', options, (err, address, family) => + console.log('address: %j family: IPv%s', address, family)); +// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6 + +``` + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `hostname` | `string` | +| `options` | [`LookupOptions`](#lookupoptions) | +| `callback` | (`err`: `Error` \| `null`, `address`: `string` \| [`LookupAddress`](#lookupaddress)[], `family`: `number`) => `void` | + +##### Returns + +`void` + +#### Call Signature + +> **lookup**(`hostname`: `string`, `callback`: (`err`: `Error` \| `null`, `address`: `string`, `family`: `number`) => `void`): `void` + +Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or +AAAA (IPv6) record. All `option` properties are optional. If `options` is an +integer, then it must be `4` or `6` – if `options` is `0` or not provided, then +IPv4 and IPv6 addresses are both returned if found. + +On error, `err` is an `Error` object, where `err.code` is the error code. +Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when +the host name does not exist but also when the lookup fails in other ways +such as no available file descriptors. + +`dns.lookup()` does not necessarily have anything to do with the DNS protocol. +The implementation uses an operating system facility that can associate names +with addresses and vice versa. + +Example usage: + +```js +import dns from 'dns'; +const options = { + family: 6, +}; +dns.lookup('example.com', options, (err, address, family) => + console.log('address: %j family: IPv%s', address, family)); +// address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6 + +``` + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `hostname` | `string` | +| `callback` | (`err`: `Error` \| `null`, `address`: `string`, `family`: `number`) => `void` | + +##### Returns + +`void` diff --git a/src/reference/modules/llrt/events.md b/src/reference/modules/llrt/events.md new file mode 100644 index 0000000..cb0ae18 --- /dev/null +++ b/src/reference/modules/llrt/events.md @@ -0,0 +1,476 @@ +[@caido/quickjs-types](../index.md) / llrt/events + +# llrt/events + +## Classes + +### EventEmitter + +#### Extended by + +- [`ChildProcess`](child_process.md#childprocess) +- [`Server`](net.md#server) +- [`ReadableStreamInner`](stream/stream.md#readablestreaminner) +- [`WritableStreamInner`](stream/stream.md#writablestreaminner) +- [`ReadableStream`](globals/namespaces/QuickJS.md#readablestream) +- [`WritableStream`](globals/namespaces/QuickJS.md#writablestream) + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `T` *extends* [`EventMap`](#eventmap)\<`T`\> | [`DefaultEventMap`](#defaulteventmap) | + +#### Constructors + +##### Constructor + +> **new EventEmitter**\<`T`\>(): [`EventEmitter`](#eventemitter)\<`T`\> + +###### Returns + +[`EventEmitter`](#eventemitter)\<`T`\> + +#### Methods + +##### addListener() + +> **addListener**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, `listener`: [`Listener`](#listener)\<`K`, `T`\>): `this` + +Alias for `emitter.on(eventName, listener)`. + +###### Type Parameters + +| Type Parameter | +| ------ | +| `K` | + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `eventName` | [`Key`](#key)\<`K`, `T`\> | +| `listener` | [`Listener`](#listener)\<`K`, `T`\> | + +###### Returns + +`this` + +##### emit() + +> **emit**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, ...`args`: [`Args`](#args)\<`K`, `T`\>): `void` + +Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments +to each. + +```js +import { EventEmitter } from 'events'; +const myEmitter = new EventEmitter(); + +// First listener +myEmitter.on('event', function firstListener() { + console.log('Helloooo! first listener'); +}); +// Second listener +myEmitter.on('event', function secondListener(arg1, arg2) { + console.log(`event with parameters ${arg1}, ${arg2} in second listener`); +}); +// Third listener +myEmitter.on('event', function thirdListener(...args) { + const parameters = args.join(', '); + console.log(`event with parameters ${parameters} in third listener`); +}); + +myEmitter.emit('event', 1, 2, 3, 4, 5); + +// Prints: +// Helloooo! first listener +// event with parameters 1, 2 in second listener +// event with parameters 1, 2, 3, 4, 5 in third listener +``` + +###### Type Parameters + +| Type Parameter | +| ------ | +| `K` | + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `eventName` | [`Key`](#key)\<`K`, `T`\> | +| ...`args` | [`Args`](#args)\<`K`, `T`\> | + +###### Returns + +`void` + +##### eventNames() + +> **eventNames**(): [`EventKey`](dom-events.md#eventkey) & [`Key2`](#key2)\<`unknown`, `T`\>[] + +Returns an array listing the events for which the emitter has registered +listeners. The values in the array are strings or `Symbol`s. + +```js +import { EventEmitter } from 'events'; + +const myEE = new EventEmitter(); +myEE.on('foo', () => {}); +myEE.on('bar', () => {}); + +const sym = Symbol('symbol'); +myEE.on(sym, () => {}); + +console.log(myEE.eventNames()); +// Prints: [ 'foo', 'bar', Symbol(symbol) ] +``` + +###### Returns + +[`EventKey`](dom-events.md#eventkey) & [`Key2`](#key2)\<`unknown`, `T`\>[] + +##### off() + +> **off**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, `listener`: [`Listener`](#listener)\<`K`, `T`\>): `this` + +Alias for `emitter.removeListener()`. + +###### Type Parameters + +| Type Parameter | +| ------ | +| `K` | + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `eventName` | [`Key`](#key)\<`K`, `T`\> | +| `listener` | [`Listener`](#listener)\<`K`, `T`\> | + +###### Returns + +`this` + +##### on() + +> **on**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, `listener`: [`Listener`](#listener)\<`K`, `T`\>): `this` + +Adds the `listener` function to the end of the listeners array for the event +named `eventName`. No checks are made to see if the `listener` has already +been added. Multiple calls passing the same combination of `eventName` and +`listener` will result in the `listener` being added, and called, multiple times. + +```js +server.on('connection', (stream) => { + console.log('someone connected!'); +}); +``` + +Returns a reference to the `EventEmitter`, so that calls can be chained. + +By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the +event listener to the beginning of the listeners array. + +```js +import { EventEmitter } from 'events'; +const myEE = new EventEmitter(); +myEE.on('foo', () => console.log('a')); +myEE.prependListener('foo', () => console.log('b')); +myEE.emit('foo'); +// Prints: +// b +// a +``` + +###### Type Parameters + +| Type Parameter | +| ------ | +| `K` | + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `eventName` | [`Key`](#key)\<`K`, `T`\> | The name of the event. | +| `listener` | [`Listener`](#listener)\<`K`, `T`\> | The callback function | + +###### Returns + +`this` + +##### once() + +> **once**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, `listener`: [`Listener`](#listener)\<`K`, `T`\>): `this` + +Adds a **one-time** `listener` function for the event named `eventName`. The +next time `eventName` is triggered, this listener is removed and then invoked. + +Returns a reference to the `EventEmitter`, so that calls can be chained. + +By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the +event listener to the beginning of the listeners array. + +```js +import { EventEmitter } from 'events'; +const myEE = new EventEmitter(); +myEE.once('foo', () => console.log('a')); +myEE.prependOnceListener('foo', () => console.log('b')); +myEE.emit('foo'); +// Prints: +// b +// a +``` + +###### Type Parameters + +| Type Parameter | +| ------ | +| `K` | + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `eventName` | [`Key`](#key)\<`K`, `T`\> | The name of the event. | +| `listener` | [`Listener`](#listener)\<`K`, `T`\> | The callback function | + +###### Returns + +`this` + +###### Since + +v0.3.0 + +##### prependListener() + +> **prependListener**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, `listener`: [`Listener`](#listener)\<`K`, `T`\>): `this` + +Adds the `listener` function to the _beginning_ of the listeners array for the +event named `eventName`. No checks are made to see if the `listener` has +already been added. Multiple calls passing the same combination of `eventName` +and `listener` will result in the `listener` being added, and called, multiple times. + +Returns a reference to the `EventEmitter`, so that calls can be chained. + +###### Type Parameters + +| Type Parameter | +| ------ | +| `K` | + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `eventName` | [`Key`](#key)\<`K`, `T`\> | The name of the event. | +| `listener` | [`Listener`](#listener)\<`K`, `T`\> | The callback function | + +###### Returns + +`this` + +##### prependOnceListener() + +> **prependOnceListener**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, `listener`: [`Listener`](#listener)\<`K`, `T`\>): `this` + +Adds a **one-time**`listener` function for the event named `eventName` to the _beginning_ of the listeners array. +The next time `eventName` is triggered, this listener is removed, and then invoked. + +Returns a reference to the `EventEmitter`, so that calls can be chained. + +###### Type Parameters + +| Type Parameter | +| ------ | +| `K` | + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `eventName` | [`Key`](#key)\<`K`, `T`\> | The name of the event. | +| `listener` | [`Listener`](#listener)\<`K`, `T`\> | The callback function | + +###### Returns + +`this` + +##### removeListener() + +> **removeListener**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, `listener`: [`Listener`](#listener)\<`K`, `T`\>): `this` + +Removes the specified `listener` from the listener array for the event named `eventName`. + +`removeListener()` will remove, at most, one instance of a listener from the +listener array. If any single listener has been added multiple times to the +listener array for the specified `eventName`, then `removeListener()` must be +called multiple times to remove each instance. + +Once an event is emitted, all listeners attached to it at the time of emitting are called in order. +This implies that any `removeListener()` calls _after_ emitting and _before_ the last listener finishes execution +will not remove them from `emit()` in progress. Subsequent events behave as expected. + +```js +import { EventEmitter } from 'events'; +class MyEmitter extends EventEmitter {} +const myEmitter = new MyEmitter(); + +const callbackA = () => { + console.log('A'); + myEmitter.removeListener('event', callbackB); +}; + +const callbackB = () => { + console.log('B'); +}; + +myEmitter.on('event', callbackA); + +myEmitter.on('event', callbackB); + +// callbackA removes listener callbackB but it will still be called. +// Internal listener array at time of emit [callbackA, callbackB] +myEmitter.emit('event'); +// Prints: +// A +// B + +// callbackB is now removed. +// Internal listener array [callbackA] +myEmitter.emit('event'); +// Prints: +// A +``` + +Because listeners are managed using an internal array, calling this will +change the position indices of any listener registered _after_ the listener +being removed. This will not impact the order in which listeners are called, +but it means that any copies of the listener array as returned by +the `emitter.listeners()` method will need to be recreated. + +When a single function has been added as a handler multiple times for a single +event (as in the example below), `removeListener()` will remove the most +recently added instance. In the example the `once('ping')` listener is removed: + +```js +import { EventEmitter } from 'events'; +const ee = new EventEmitter(); + +function pong() { + console.log('pong'); +} + +ee.on('ping', pong); +ee.once('ping', pong); +ee.removeListener('ping', pong); + +ee.emit('ping'); +ee.emit('ping'); +``` + +Returns a reference to the `EventEmitter`, so that calls can be chained. + +###### Type Parameters + +| Type Parameter | +| ------ | +| `K` | + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `eventName` | [`Key`](#key)\<`K`, `T`\> | +| `listener` | [`Listener`](#listener)\<`K`, `T`\> | + +###### Returns + +`this` + +## Type Aliases + +### AnyRest + +> **AnyRest** = \[`any`[]\] + +*** + +### Args + +> **Args**\<`K`, `T`\> = `T` *extends* [`DefaultEventMap`](#defaulteventmap) ? [`AnyRest`](#anyrest) : `K` *extends* keyof `T` ? `T`\[`K`\] : `never` + +#### Type Parameters + +| Type Parameter | +| ------ | +| `K` | +| `T` | + +*** + +### DefaultEventMap + +> **DefaultEventMap** = \[`never`\] + +*** + +### EventMap + +> **EventMap**\<`T`\> = `Record`\ \| [`DefaultEventMap`](#defaulteventmap) + +#### Type Parameters + +| Type Parameter | +| ------ | +| `T` | + +*** + +### Key + +> **Key**\<`K`, `T`\> = `T` *extends* [`DefaultEventMap`](#defaulteventmap) ? [`EventKey`](dom-events.md#eventkey) : `K` \| keyof `T` + +#### Type Parameters + +| Type Parameter | +| ------ | +| `K` | +| `T` | + +*** + +### Key2 + +> **Key2**\<`K`, `T`\> = `T` *extends* [`DefaultEventMap`](#defaulteventmap) ? [`EventKey`](dom-events.md#eventkey) : `K` & keyof `T` + +#### Type Parameters + +| Type Parameter | +| ------ | +| `K` | +| `T` | + +*** + +### Listener + +> **Listener**\<`K`, `T`, `F`\> = `T` *extends* [`DefaultEventMap`](#defaulteventmap) ? `F` : `K` *extends* keyof `T` ? `T`\[`K`\] *extends* `unknown`[] ? (...`args`: `T`\[`K`\]) => `void` : `never` : `never` + +#### Type Parameters + +| Type Parameter | +| ------ | +| `K` | +| `T` | +| `F` | + +## References + +### default + +Renames and re-exports [EventEmitter](#eventemitter) diff --git a/src/reference/modules/llrt/fs/index.md b/src/reference/modules/llrt/fs/index.md index d105a47..25a300f 100644 --- a/src/reference/modules/llrt/fs/index.md +++ b/src/reference/modules/llrt/fs/index.md @@ -2,12 +2,6 @@ # llrt/fs -## Modules - -| Module | Description | -| ------ | ------ | -| [fs/promises](fs/promises.md) | - | - ## Namespaces | Namespace | Description | @@ -21,7 +15,7 @@ A representation of a directory entry, which can be a file or a subdirectory within the directory. A directory entry is a combination of the file name and file type pairs. -Additionally, when [promises.readdir](fs/promises.md#readdir) or [readdirSync](#readdirsync) is called with +Additionally, when [promises.readdir](promises.md#readdir) or [readdirSync](#readdirsync) is called with the `withFileTypes` option set to `true`, the resulting array is filled with `fs.Dirent` objects, rather than strings. #### Constructors @@ -768,7 +762,7 @@ See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) do Returns the created directory path. For detailed information, see the documentation of the asynchronous version of -this API: [promises.mkdtemp](fs/promises.md#mkdtemp). +this API: [promises.mkdtemp](promises.md#mkdtemp). #### Parameters @@ -837,7 +831,7 @@ Synchronous readdir (2) - read a directory. Returns the contents of the `path`. For detailed information, see the documentation of the asynchronous version of -this API: [promises.readFile](fs/promises.md#readfile-3). +this API: [promises.readFile](promises.md#readfile-3). If the `encoding` option is specified then this function returns a string. Otherwise it returns a buffer. @@ -879,7 +873,7 @@ Synchronously reads the entire contents of a file. Synchronously renames a file or directory from `oldPath` to `newPath`. For detailed information, see the documentation of the asynchronous version of -this API: [promises.rename](fs/promises.md#rename). +this API: [promises.rename](promises.md#rename). #### Parameters @@ -959,22 +953,28 @@ Synchronous symlink(2) - Create a new symbolic link to an existing file. ### writeFileSync() -> **writeFileSync**(`file`: `string`, `data`: `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer), `options?`: `object`): `void` +> **writeFileSync**(`file`: `string`, `data`: `string` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer`, `options?`: `object`): `void` Returns `undefined`. For detailed information, see the documentation of the asynchronous version of -this API: [promises.writeFile](fs/promises.md#writefile-2). +this API: [promises.writeFile](promises.md#writefile-2). #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `file` | `string` | A path to a file. | -| `data` | `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer) | - | +| `data` | `string` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer` | - | | `options?` | \{ `mode?`: `number`; \} | - | | `options.mode?` | `number` | - | #### Returns `void` + +## References + +### promises + +Renames and re-exports [llrt/fs/promises](promises.md) diff --git a/src/reference/modules/llrt/fs/fs/promises.md b/src/reference/modules/llrt/fs/promises.md similarity index 86% rename from src/reference/modules/llrt/fs/fs/promises.md rename to src/reference/modules/llrt/fs/promises.md index 73b12a4..1f77228 100644 --- a/src/reference/modules/llrt/fs/fs/promises.md +++ b/src/reference/modules/llrt/fs/promises.md @@ -1,6 +1,6 @@ -[@caido/quickjs-types](../../../index.md) / [llrt/fs](../index.md) / fs/promises +[@caido/quickjs-types](../../index.md) / llrt/fs/promises -# fs/promises +# llrt/fs/promises ## Classes @@ -117,7 +117,7 @@ number of bytes read is zero. | Type Parameter | | ------ | -| `T` *extends* [`ArrayBufferView`](../../globals/namespaces/QuickJS.md#arraybufferview) | +| `T` *extends* [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) | ###### Parameters @@ -147,7 +147,7 @@ number of bytes read is zero. | Type Parameter | Default type | | ------ | ------ | -| `T` *extends* [`ArrayBufferView`](../../globals/namespaces/QuickJS.md#arraybufferview) | [`Buffer`](../../buffer.md#buffer) | +| `T` *extends* [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) | [`Buffer`](../buffer.md#buffer) | ###### Parameters @@ -175,7 +175,7 @@ number of bytes read is zero. | Type Parameter | Default type | | ------ | ------ | -| `T` *extends* [`ArrayBufferView`](../../globals/namespaces/QuickJS.md#arraybufferview) | [`Buffer`](../../buffer.md#buffer) | +| `T` *extends* [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) | [`Buffer`](../buffer.md#buffer) | ###### Parameters @@ -193,7 +193,7 @@ Fulfills upon success with an object with two properties: bytesRead and buffer ###### Call Signature -> **readFile**(`options?`: \{ `encoding?`: `null`; \} \| `null`): `Promise`\<[`Buffer`](../../buffer.md#buffer)\> +> **readFile**(`options?`: \{ `encoding?`: `null`; \} \| `null`): `Promise`\<[`Buffer`](../buffer.md#buffer)\> Asynchronously reads the entire contents of a file. @@ -213,14 +213,14 @@ of the file. ###### Returns -`Promise`\<[`Buffer`](../../buffer.md#buffer)\> +`Promise`\<[`Buffer`](../buffer.md#buffer)\> Fulfills upon a successful read with the contents of the file. If no encoding is specified (using `options.encoding`), the data is returned as a {Buffer} object. Otherwise, the data will be a string. ###### Call Signature -> **readFile**(`options`: [`BufferEncoding`](../../buffer.md#bufferencoding) \| \{ `encoding`: [`BufferEncoding`](../../buffer.md#bufferencoding); \}): `Promise`\<`string`\> +> **readFile**(`options`: [`BufferEncoding`](../buffer.md#bufferencoding) \| \{ `encoding`: [`BufferEncoding`](../buffer.md#bufferencoding); \}): `Promise`\<`string`\> Asynchronously reads the entire contents of a file. @@ -236,7 +236,7 @@ of the file. | Parameter | Type | | ------ | ------ | -| `options` | [`BufferEncoding`](../../buffer.md#bufferencoding) \| \{ `encoding`: [`BufferEncoding`](../../buffer.md#bufferencoding); \} | +| `options` | [`BufferEncoding`](../buffer.md#bufferencoding) \| \{ `encoding`: [`BufferEncoding`](../buffer.md#bufferencoding); \} | ###### Returns @@ -247,13 +247,13 @@ data will be a string. ##### stat() -> **stat**(): `Promise`\<[`Stats`](../index.md#stats)\> +> **stat**(): `Promise`\<[`Stats`](index.md#stats)\> Get {FileHandle} status. ###### Returns -`Promise`\<[`Stats`](../index.md#stats)\> +`Promise`\<[`Stats`](index.md#stats)\> Fulfills with the {fs.Stats} object. @@ -331,7 +331,7 @@ the end of the file. | Type Parameter | | ------ | -| `TBuffer` *extends* [`ArrayBufferView`](../../globals/namespaces/QuickJS.md#arraybufferview) | +| `TBuffer` *extends* [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) | ###### Parameters @@ -366,7 +366,7 @@ the end of the file. | Type Parameter | | ------ | -| `TBuffer` *extends* [`ArrayBufferView`](../../globals/namespaces/QuickJS.md#arraybufferview) | +| `TBuffer` *extends* [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) | ###### Parameters @@ -381,7 +381,7 @@ the end of the file. ###### Call Signature -> **write**(`data`: `string`, `position?`: `number` \| `null`, `encoding?`: [`BufferEncoding`](../../buffer.md#bufferencoding) \| `null`): `Promise`\<\{ `buffer`: `string`; `bytesWritten`: `number`; \}\> +> **write**(`data`: `string`, `position?`: `number` \| `null`, `encoding?`: [`BufferEncoding`](../buffer.md#bufferencoding) \| `null`): `Promise`\<\{ `buffer`: `string`; `bytesWritten`: `number`; \}\> Write `buffer` to the file. @@ -401,7 +401,7 @@ the end of the file. | ------ | ------ | ------ | | `data` | `string` | - | | `position?` | `number` \| `null` | The offset from the beginning of the file where the data from `buffer` should be written. If `position` is not a `number`, the data will be written at the current position. See the POSIX pwrite(2) documentation for more detail. | -| `encoding?` | [`BufferEncoding`](../../buffer.md#bufferencoding) \| `null` | - | +| `encoding?` | [`BufferEncoding`](../buffer.md#bufferencoding) \| `null` | - | ###### Returns @@ -409,7 +409,7 @@ the end of the file. ##### writeFile() -> **writeFile**(`data`: `string` \| [`ArrayBufferView`](../../globals/namespaces/QuickJS.md#arraybufferview), `options?`: [`BufferEncoding`](../../buffer.md#bufferencoding) \| \{ `encoding?`: BufferEncoding \| null \| undefined; \} \| `null`): `Promise`\<`void`\> +> **writeFile**(`data`: `string` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview), `options?`: [`BufferEncoding`](../buffer.md#bufferencoding) \| \{ `encoding?`: BufferEncoding \| null \| undefined; \} \| `null`): `Promise`\<`void`\> Asynchronously writes data to a file, replacing the file if it already exists. @@ -427,8 +427,8 @@ current position till the end of the file. It doesn't always write from the begi | Parameter | Type | | ------ | ------ | -| `data` | `string` \| [`ArrayBufferView`](../../globals/namespaces/QuickJS.md#arraybufferview) | -| `options?` | [`BufferEncoding`](../../buffer.md#bufferencoding) \| \{ `encoding?`: BufferEncoding \| null \| undefined; \} \| `null` | +| `data` | `string` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) | +| `options?` | [`BufferEncoding`](../buffer.md#bufferencoding) \| \{ `encoding?`: BufferEncoding \| null \| undefined; \} \| `null` | ###### Returns @@ -442,7 +442,7 @@ current position till the end of the file. It doesn't always write from the begi | Type Parameter | Default type | | ------ | ------ | -| `T` *extends* [`ArrayBufferView`](../../globals/namespaces/QuickJS.md#arraybufferview) | [`Buffer`](../../buffer.md#buffer) | +| `T` *extends* [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) | [`Buffer`](../buffer.md#buffer) | #### Properties @@ -484,7 +484,7 @@ current position till the end of the file. It doesn't always write from the begi | Type Parameter | | ------ | -| `T` *extends* [`ArrayBufferView`](../../globals/namespaces/QuickJS.md#arraybufferview) | +| `T` *extends* [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) | #### Properties @@ -506,7 +506,7 @@ current position till the end of the file. It doesn't always write from the begi ### constants -> `const` **constants**: *typeof* [`constants`](../namespaces/constants.md) +> `const` **constants**: *typeof* [`constants`](namespaces/constants.md) ## Functions @@ -580,7 +580,7 @@ Fulfills with `undefined` upon success. ### mkdir() -> **mkdir**(`path`: `string`, `options?`: [`MakeDirectoryOptions`](../index.md#makedirectoryoptions)): `Promise`\<`string`\> +> **mkdir**(`path`: `string`, `options?`: [`MakeDirectoryOptions`](index.md#makedirectoryoptions)): `Promise`\<`string`\> Asynchronously creates a directory. @@ -605,7 +605,7 @@ try { | Parameter | Type | | ------ | ------ | | `path` | `string` | -| `options?` | [`MakeDirectoryOptions`](../index.md#makedirectoryoptions) | +| `options?` | [`MakeDirectoryOptions`](index.md#makedirectoryoptions) | #### Returns @@ -722,7 +722,7 @@ Fulfills with an array of the names of the files in the directory excluding `'.' #### Call Signature -> **readdir**(`path`: `string`, `options`: `object`): `Promise`\<[`Dirent`](../index.md#dirent)[]\> +> **readdir**(`path`: `string`, `options`: `object`): `Promise`\<[`Dirent`](index.md#dirent)[]\> Asynchronous readdir(2) - read a directory. @@ -737,7 +737,7 @@ Asynchronous readdir(2) - read a directory. ##### Returns -`Promise`\<[`Dirent`](../index.md#dirent)[]\> +`Promise`\<[`Dirent`](index.md#dirent)[]\> *** @@ -745,7 +745,7 @@ Asynchronous readdir(2) - read a directory. #### Call Signature -> **readFile**(`path`: `string`, `options?`: \{ `encoding?`: `null`; \} \| `null`): `Promise`\<[`Buffer`](../../buffer.md#buffer)\> +> **readFile**(`path`: `string`, `options?`: \{ `encoding?`: `null`; \} \| `null`): `Promise`\<[`Buffer`](../buffer.md#buffer)\> Asynchronously reads the entire contents of a file. @@ -781,13 +781,13 @@ try { ##### Returns -`Promise`\<[`Buffer`](../../buffer.md#buffer)\> +`Promise`\<[`Buffer`](../buffer.md#buffer)\> Fulfills with the contents of the file. #### Call Signature -> **readFile**(`path`: `string`, `options`: [`BufferEncoding`](../../buffer.md#bufferencoding) \| \{ `encoding`: [`BufferEncoding`](../../buffer.md#bufferencoding); \}): `Promise`\<`string`\> +> **readFile**(`path`: `string`, `options`: \{ `encoding`: [`BufferEncoding`](../buffer.md#bufferencoding); \} \| [`BufferEncoding`](../buffer.md#bufferencoding)): `Promise`\<`string`\> Asynchronously reads the entire contents of a file. @@ -796,7 +796,7 @@ Asynchronously reads the entire contents of a file. | Parameter | Type | Description | | ------ | ------ | ------ | | `path` | `string` | A path to a file. If a URL is provided, it must use the `file:` protocol. If a `FileHandle` is provided, the underlying file will _not_ be closed automatically. | -| `options` | [`BufferEncoding`](../../buffer.md#bufferencoding) \| \{ `encoding`: [`BufferEncoding`](../../buffer.md#bufferencoding); \} | An object that may contain an optional flag. If a flag is not provided, it defaults to `'r'`. | +| `options` | \{ `encoding`: [`BufferEncoding`](../buffer.md#bufferencoding); \} \| [`BufferEncoding`](../buffer.md#bufferencoding) | An object that may contain an optional flag. If a flag is not provided, it defaults to `'r'`. | ##### Returns @@ -838,7 +838,7 @@ Fulfills with `undefined` upon success. ### rm() -> **rm**(`path`: `string`, `options?`: [`RmOptions`](../index.md#rmoptions)): `Promise`\<`void`\> +> **rm**(`path`: `string`, `options?`: [`RmOptions`](index.md#rmoptions)): `Promise`\<`void`\> Removes files and directories (modeled on the standard POSIX `rm` utility). @@ -847,7 +847,7 @@ Removes files and directories (modeled on the standard POSIX `rm` utility). | Parameter | Type | | ------ | ------ | | `path` | `string` | -| `options?` | [`RmOptions`](../index.md#rmoptions) | +| `options?` | [`RmOptions`](index.md#rmoptions) | #### Returns @@ -859,7 +859,7 @@ Fulfills with `undefined` upon success. ### rmdir() -> **rmdir**(`path`: `string`, `options?`: [`RmDirOptions`](../index.md#rmdiroptions)): `Promise`\<`void`\> +> **rmdir**(`path`: `string`, `options?`: [`RmDirOptions`](index.md#rmdiroptions)): `Promise`\<`void`\> Removes the directory identified by `path`. @@ -873,7 +873,7 @@ To get a behavior similar to the `rm -rf` Unix command, use `fsPromises.rm()` wi | Parameter | Type | | ------ | ------ | | `path` | `string` | -| `options?` | [`RmDirOptions`](../index.md#rmdiroptions) | +| `options?` | [`RmDirOptions`](index.md#rmdiroptions) | #### Returns @@ -885,7 +885,7 @@ Fulfills with `undefined` upon success. ### stat() -> **stat**(`path`: `string`): `Promise`\<[`Stats`](../index.md#stats)\> +> **stat**(`path`: `string`): `Promise`\<[`Stats`](index.md#stats)\> Asynchronous stat - Get file status. @@ -897,7 +897,7 @@ Asynchronous stat - Get file status. #### Returns -`Promise`\<[`Stats`](../index.md#stats)\> +`Promise`\<[`Stats`](index.md#stats)\> Fulfills with the {fs.Stats} object for the given `path`. @@ -934,7 +934,7 @@ Fulfills with `undefined` upon success. ### writeFile() -> **writeFile**(`file`: `string`, `data`: `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](../../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../../buffer.md#buffer), `options?`: `object`): `Promise`\<`void`\> +> **writeFile**(`file`: `string`, `data`: `string` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer`, `options?`: `object`): `Promise`\<`void`\> Asynchronously writes data to a file, replacing the file if it already exists. @@ -952,7 +952,7 @@ passed to it. | Parameter | Type | Description | | ------ | ------ | ------ | | `file` | `string` | filename or `FileHandle` | -| `data` | `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](../../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../../buffer.md#buffer) | - | +| `data` | `string` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer` | - | | `options?` | \{ `mode?`: `number`; \} | - | | `options.mode?` | `number` | - | diff --git a/src/reference/modules/llrt/globals/index.md b/src/reference/modules/llrt/globals/index.md index 04f7b2e..ae3f59d 100644 --- a/src/reference/modules/llrt/globals/index.md +++ b/src/reference/modules/llrt/globals/index.md @@ -8,396 +8,6 @@ | ------ | ------ | | [QuickJS](namespaces/QuickJS.md) | - | -## Classes - -### EventEmitter - -#### Extended by - -- [`ChildProcess`](../child_process.md#childprocess) -- [`Server`](../net.md#server) -- [`ReadableStreamInner`](../stream/stream.md#readablestreaminner) -- [`WritableStreamInner`](../stream/stream.md#writablestreaminner) -- [`ReadableStream`](namespaces/QuickJS.md#readablestream) -- [`WritableStream`](namespaces/QuickJS.md#writablestream) - -#### Type Parameters - -| Type Parameter | Default type | -| ------ | ------ | -| `T` *extends* [`EventMap`](#eventmap)\<`T`\> | [`DefaultEventMap`](#defaulteventmap) | - -#### Constructors - -##### Constructor - -> **new EventEmitter**\<`T`\>(): [`EventEmitter`](#eventemitter)\<`T`\> - -###### Returns - -[`EventEmitter`](#eventemitter)\<`T`\> - -#### Methods - -##### addListener() - -> **addListener**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, `listener`: [`Listener`](#listener)\<`K`, `T`\>): `this` - -Alias for `emitter.on(eventName, listener)`. - -###### Type Parameters - -| Type Parameter | -| ------ | -| `K` | - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `eventName` | [`Key`](#key)\<`K`, `T`\> | -| `listener` | [`Listener`](#listener)\<`K`, `T`\> | - -###### Returns - -`this` - -##### emit() - -> **emit**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, ...`args`: [`Args`](#args)\<`K`, `T`\>): `void` - -Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments -to each. - -```js -import { EventEmitter } from 'events'; -const myEmitter = new EventEmitter(); - -// First listener -myEmitter.on('event', function firstListener() { - console.log('Helloooo! first listener'); -}); -// Second listener -myEmitter.on('event', function secondListener(arg1, arg2) { - console.log(`event with parameters ${arg1}, ${arg2} in second listener`); -}); -// Third listener -myEmitter.on('event', function thirdListener(...args) { - const parameters = args.join(', '); - console.log(`event with parameters ${parameters} in third listener`); -}); - -myEmitter.emit('event', 1, 2, 3, 4, 5); - -// Prints: -// Helloooo! first listener -// event with parameters 1, 2 in second listener -// event with parameters 1, 2, 3, 4, 5 in third listener -``` - -###### Type Parameters - -| Type Parameter | -| ------ | -| `K` | - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `eventName` | [`Key`](#key)\<`K`, `T`\> | -| ...`args` | [`Args`](#args)\<`K`, `T`\> | - -###### Returns - -`void` - -##### eventNames() - -> **eventNames**(): [`EventKey`](../dom-events.md#eventkey) & [`Key2`](#key2)\<`unknown`, `T`\>[] - -Returns an array listing the events for which the emitter has registered -listeners. The values in the array are strings or `Symbol`s. - -```js -import { EventEmitter } from 'events'; - -const myEE = new EventEmitter(); -myEE.on('foo', () => {}); -myEE.on('bar', () => {}); - -const sym = Symbol('symbol'); -myEE.on(sym, () => {}); - -console.log(myEE.eventNames()); -// Prints: [ 'foo', 'bar', Symbol(symbol) ] -``` - -###### Returns - -[`EventKey`](../dom-events.md#eventkey) & [`Key2`](#key2)\<`unknown`, `T`\>[] - -##### off() - -> **off**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, `listener`: [`Listener`](#listener)\<`K`, `T`\>): `this` - -Alias for `emitter.removeListener()`. - -###### Type Parameters - -| Type Parameter | -| ------ | -| `K` | - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `eventName` | [`Key`](#key)\<`K`, `T`\> | -| `listener` | [`Listener`](#listener)\<`K`, `T`\> | - -###### Returns - -`this` - -##### on() - -> **on**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, `listener`: [`Listener`](#listener)\<`K`, `T`\>): `this` - -Adds the `listener` function to the end of the listeners array for the event -named `eventName`. No checks are made to see if the `listener` has already -been added. Multiple calls passing the same combination of `eventName` and -`listener` will result in the `listener` being added, and called, multiple times. - -```js -server.on('connection', (stream) => { - console.log('someone connected!'); -}); -``` - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the -event listener to the beginning of the listeners array. - -```js -import { EventEmitter } from 'events'; -const myEE = new EventEmitter(); -myEE.on('foo', () => console.log('a')); -myEE.prependListener('foo', () => console.log('b')); -myEE.emit('foo'); -// Prints: -// b -// a -``` - -###### Type Parameters - -| Type Parameter | -| ------ | -| `K` | - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `eventName` | [`Key`](#key)\<`K`, `T`\> | The name of the event. | -| `listener` | [`Listener`](#listener)\<`K`, `T`\> | The callback function | - -###### Returns - -`this` - -##### once() - -> **once**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, `listener`: [`Listener`](#listener)\<`K`, `T`\>): `this` - -Adds a **one-time** `listener` function for the event named `eventName`. The -next time `eventName` is triggered, this listener is removed and then invoked. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the -event listener to the beginning of the listeners array. - -```js -import { EventEmitter } from 'events'; -const myEE = new EventEmitter(); -myEE.once('foo', () => console.log('a')); -myEE.prependOnceListener('foo', () => console.log('b')); -myEE.emit('foo'); -// Prints: -// b -// a -``` - -###### Type Parameters - -| Type Parameter | -| ------ | -| `K` | - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `eventName` | [`Key`](#key)\<`K`, `T`\> | The name of the event. | -| `listener` | [`Listener`](#listener)\<`K`, `T`\> | The callback function | - -###### Returns - -`this` - -###### Since - -v0.3.0 - -##### prependListener() - -> **prependListener**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, `listener`: [`Listener`](#listener)\<`K`, `T`\>): `this` - -Adds the `listener` function to the _beginning_ of the listeners array for the -event named `eventName`. No checks are made to see if the `listener` has -already been added. Multiple calls passing the same combination of `eventName` -and `listener` will result in the `listener` being added, and called, multiple times. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Type Parameters - -| Type Parameter | -| ------ | -| `K` | - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `eventName` | [`Key`](#key)\<`K`, `T`\> | The name of the event. | -| `listener` | [`Listener`](#listener)\<`K`, `T`\> | The callback function | - -###### Returns - -`this` - -##### prependOnceListener() - -> **prependOnceListener**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, `listener`: [`Listener`](#listener)\<`K`, `T`\>): `this` - -Adds a **one-time**`listener` function for the event named `eventName` to the _beginning_ of the listeners array. -The next time `eventName` is triggered, this listener is removed, and then invoked. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Type Parameters - -| Type Parameter | -| ------ | -| `K` | - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `eventName` | [`Key`](#key)\<`K`, `T`\> | The name of the event. | -| `listener` | [`Listener`](#listener)\<`K`, `T`\> | The callback function | - -###### Returns - -`this` - -##### removeListener() - -> **removeListener**\<`K`\>(`eventName`: [`Key`](#key)\<`K`, `T`\>, `listener`: [`Listener`](#listener)\<`K`, `T`\>): `this` - -Removes the specified `listener` from the listener array for the event named `eventName`. - -`removeListener()` will remove, at most, one instance of a listener from the -listener array. If any single listener has been added multiple times to the -listener array for the specified `eventName`, then `removeListener()` must be -called multiple times to remove each instance. - -Once an event is emitted, all listeners attached to it at the time of emitting are called in order. -This implies that any `removeListener()` calls _after_ emitting and _before_ the last listener finishes execution -will not remove them from `emit()` in progress. Subsequent events behave as expected. - -```js -import { EventEmitter } from 'events'; -class MyEmitter extends EventEmitter {} -const myEmitter = new MyEmitter(); - -const callbackA = () => { - console.log('A'); - myEmitter.removeListener('event', callbackB); -}; - -const callbackB = () => { - console.log('B'); -}; - -myEmitter.on('event', callbackA); - -myEmitter.on('event', callbackB); - -// callbackA removes listener callbackB but it will still be called. -// Internal listener array at time of emit [callbackA, callbackB] -myEmitter.emit('event'); -// Prints: -// A -// B - -// callbackB is now removed. -// Internal listener array [callbackA] -myEmitter.emit('event'); -// Prints: -// A -``` - -Because listeners are managed using an internal array, calling this will -change the position indices of any listener registered _after_ the listener -being removed. This will not impact the order in which listeners are called, -but it means that any copies of the listener array as returned by -the `emitter.listeners()` method will need to be recreated. - -When a single function has been added as a handler multiple times for a single -event (as in the example below), `removeListener()` will remove the most -recently added instance. In the example the `once('ping')` listener is removed: - -```js -import { EventEmitter } from 'events'; -const ee = new EventEmitter(); - -function pong() { - console.log('pong'); -} - -ee.on('ping', pong); -ee.once('ping', pong); -ee.removeListener('ping', pong); - -ee.emit('ping'); -ee.emit('ping'); -``` - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Type Parameters - -| Type Parameter | -| ------ | -| `K` | - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `eventName` | [`Key`](#key)\<`K`, `T`\> | -| `listener` | [`Listener`](#listener)\<`K`, `T`\> | - -###### Returns - -`this` - ## Interfaces ### SymbolConstructor() @@ -423,80 +33,3 @@ Returns a new unique Symbol value. > `readonly` **dispose**: *typeof* [`dispose`](#dispose) A method that is used to release resources held by an object. Called by the semantics of the `using` statement. - -## Type Aliases - -### AnyRest - -> **AnyRest** = \[`any`[]\] - -*** - -### Args - -> **Args**\<`K`, `T`\> = `T` *extends* [`DefaultEventMap`](#defaulteventmap) ? [`AnyRest`](#anyrest) : `K` *extends* keyof `T` ? `T`\[`K`\] : `never` - -#### Type Parameters - -| Type Parameter | -| ------ | -| `K` | -| `T` | - -*** - -### DefaultEventMap - -> **DefaultEventMap** = \[`never`\] - -*** - -### EventMap - -> **EventMap**\<`T`\> = `Record`\ \| [`DefaultEventMap`](#defaulteventmap) - -#### Type Parameters - -| Type Parameter | -| ------ | -| `T` | - -*** - -### Key - -> **Key**\<`K`, `T`\> = `T` *extends* [`DefaultEventMap`](#defaulteventmap) ? [`EventKey`](../dom-events.md#eventkey) : `K` \| keyof `T` - -#### Type Parameters - -| Type Parameter | -| ------ | -| `K` | -| `T` | - -*** - -### Key2 - -> **Key2**\<`K`, `T`\> = `T` *extends* [`DefaultEventMap`](#defaulteventmap) ? [`EventKey`](../dom-events.md#eventkey) : `K` & keyof `T` - -#### Type Parameters - -| Type Parameter | -| ------ | -| `K` | -| `T` | - -*** - -### Listener - -> **Listener**\<`K`, `T`, `F`\> = `T` *extends* [`DefaultEventMap`](#defaulteventmap) ? `F` : `K` *extends* keyof `T` ? `T`\[`K`\] *extends* `unknown`[] ? (...`args`: `T`\[`K`\]) => `void` : `never` : `never` - -#### Type Parameters - -| Type Parameter | -| ------ | -| `K` | -| `T` | -| `F` | diff --git a/src/reference/modules/llrt/globals/namespaces/QuickJS.md b/src/reference/modules/llrt/globals/namespaces/QuickJS.md index f5a0a85..6ee46d6 100644 --- a/src/reference/modules/llrt/globals/namespaces/QuickJS.md +++ b/src/reference/modules/llrt/globals/namespaces/QuickJS.md @@ -8,7 +8,7 @@ #### Extends -- [`EventEmitter`](../index.md#eventemitter) +- [`EventEmitter`](../../events.md#eventemitter) #### Methods @@ -37,11 +37,11 @@ Alias for `emitter.on(eventName, listener)`. ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`addListener`](../index.md#addlistener) +[`EventEmitter`](../../events.md#eventemitter).[`addListener`](../../events.md#addlistener) ##### emit() -> **emit**\<`K`\>(`eventName`: [`EventKey`](../../dom-events.md#eventkey), ...`args`: [`AnyRest`](../index.md#anyrest)): `void` +> **emit**\<`K`\>(`eventName`: [`EventKey`](../../dom-events.md#eventkey), ...`args`: [`AnyRest`](../../events.md#anyrest)): `void` Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments to each. @@ -83,7 +83,7 @@ myEmitter.emit('event', 1, 2, 3, 4, 5); | Parameter | Type | | ------ | ------ | | `eventName` | [`EventKey`](../../dom-events.md#eventkey) | -| ...`args` | [`AnyRest`](../index.md#anyrest) | +| ...`args` | [`AnyRest`](../../events.md#anyrest) | ###### Returns @@ -91,7 +91,7 @@ myEmitter.emit('event', 1, 2, 3, 4, 5); ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`emit`](../index.md#emit) +[`EventEmitter`](../../events.md#eventemitter).[`emit`](../../events.md#emit) ##### eventNames() @@ -120,7 +120,7 @@ console.log(myEE.eventNames()); ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`eventNames`](../index.md#eventnames) +[`EventEmitter`](../../events.md#eventemitter).[`eventNames`](../../events.md#eventnames) ##### off() @@ -147,7 +147,7 @@ Alias for `emitter.removeListener()`. ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`off`](../index.md#off) +[`EventEmitter`](../../events.md#eventemitter).[`off`](../../events.md#off) ##### on() @@ -199,7 +199,7 @@ myEE.emit('foo'); ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`on`](../index.md#on) +[`EventEmitter`](../../events.md#eventemitter).[`on`](../../events.md#on) ##### once() @@ -247,7 +247,7 @@ v0.3.0 ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`once`](../index.md#once) +[`EventEmitter`](../../events.md#eventemitter).[`once`](../../events.md#once) ##### prependListener() @@ -279,7 +279,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`prependListener`](../index.md#prependlistener) +[`EventEmitter`](../../events.md#eventemitter).[`prependListener`](../../events.md#prependlistener) ##### prependOnceListener() @@ -309,7 +309,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`prependOnceListener`](../index.md#prependoncelistener) +[`EventEmitter`](../../events.md#eventemitter).[`prependOnceListener`](../../events.md#prependoncelistener) ##### read() @@ -419,7 +419,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`removeListener`](../index.md#removelistener) +[`EventEmitter`](../../events.md#eventemitter).[`removeListener`](../../events.md#removelistener) *** @@ -427,7 +427,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. #### Extends -- [`EventEmitter`](../index.md#eventemitter) +- [`EventEmitter`](../../events.md#eventemitter) #### Methods @@ -456,11 +456,11 @@ Alias for `emitter.on(eventName, listener)`. ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`addListener`](../index.md#addlistener) +[`EventEmitter`](../../events.md#eventemitter).[`addListener`](../../events.md#addlistener) ##### emit() -> **emit**\<`K`\>(`eventName`: [`EventKey`](../../dom-events.md#eventkey), ...`args`: [`AnyRest`](../index.md#anyrest)): `void` +> **emit**\<`K`\>(`eventName`: [`EventKey`](../../dom-events.md#eventkey), ...`args`: [`AnyRest`](../../events.md#anyrest)): `void` Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments to each. @@ -502,7 +502,7 @@ myEmitter.emit('event', 1, 2, 3, 4, 5); | Parameter | Type | | ------ | ------ | | `eventName` | [`EventKey`](../../dom-events.md#eventkey) | -| ...`args` | [`AnyRest`](../index.md#anyrest) | +| ...`args` | [`AnyRest`](../../events.md#anyrest) | ###### Returns @@ -510,7 +510,7 @@ myEmitter.emit('event', 1, 2, 3, 4, 5); ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`emit`](../index.md#emit) +[`EventEmitter`](../../events.md#eventemitter).[`emit`](../../events.md#emit) ##### end() @@ -547,7 +547,7 @@ console.log(myEE.eventNames()); ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`eventNames`](../index.md#eventnames) +[`EventEmitter`](../../events.md#eventemitter).[`eventNames`](../../events.md#eventnames) ##### off() @@ -574,7 +574,7 @@ Alias for `emitter.removeListener()`. ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`off`](../index.md#off) +[`EventEmitter`](../../events.md#eventemitter).[`off`](../../events.md#off) ##### on() @@ -626,7 +626,7 @@ myEE.emit('foo'); ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`on`](../index.md#on) +[`EventEmitter`](../../events.md#eventemitter).[`on`](../../events.md#on) ##### once() @@ -674,7 +674,7 @@ v0.3.0 ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`once`](../index.md#once) +[`EventEmitter`](../../events.md#eventemitter).[`once`](../../events.md#once) ##### prependListener() @@ -706,7 +706,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`prependListener`](../index.md#prependlistener) +[`EventEmitter`](../../events.md#eventemitter).[`prependListener`](../../events.md#prependlistener) ##### prependOnceListener() @@ -736,7 +736,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`prependOnceListener`](../index.md#prependoncelistener) +[`EventEmitter`](../../events.md#eventemitter).[`prependOnceListener`](../../events.md#prependoncelistener) ##### removeListener() @@ -832,17 +832,17 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Inherited from -[`EventEmitter`](../index.md#eventemitter).[`removeListener`](../index.md#removelistener) +[`EventEmitter`](../../events.md#eventemitter).[`removeListener`](../../events.md#removelistener) ##### write() -> **write**(`chunk`: `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](#arraybufferview) \| [`Buffer`](../../buffer.md#buffer), `callback?`: (`err?`: `Error` \| `null`) => `void`): `void` +> **write**(`chunk`: `string` \| [`ArrayBufferView`](#arraybufferview) \| [`Buffer`](../../buffer.md#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer`, `callback?`: (`err?`: `Error` \| `null`) => `void`): `void` ###### Parameters | Parameter | Type | | ------ | ------ | -| `chunk` | `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](#arraybufferview) \| [`Buffer`](../../buffer.md#buffer) | +| `chunk` | `string` \| [`ArrayBufferView`](#arraybufferview) \| [`Buffer`](../../buffer.md#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer` | | `callback?` | (`err?`: `Error` \| `null`) => `void` | ###### Returns diff --git a/src/reference/modules/llrt/https.md b/src/reference/modules/llrt/https.md new file mode 100644 index 0000000..6ad27ea --- /dev/null +++ b/src/reference/modules/llrt/https.md @@ -0,0 +1,47 @@ +[@caido/quickjs-types](../index.md) / llrt/https + +# llrt/https + +## Classes + +### Agent + +An `Agent` is responsible for managing connection persistence +and reuse for HTTP clients. Currently only a small subset of the options +are supported. + +#### Constructors + +##### Constructor + +> **new Agent**(`opts?`: [`AgentOptions`](#agentoptions)): [`Agent`](#agent) + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `opts?` | [`AgentOptions`](#agentoptions) | + +###### Returns + +[`Agent`](#agent) + +## Interfaces + +### AgentOptions + +#### Properties + +##### ca? + +> `optional` **ca**: `string` \| [`Buffer`](buffer.md#buffer) \| (`string` \| [`Buffer`](buffer.md#buffer))[] + +Optionally override the trusted CA certificates. Default is to trust +the well-known CAs curated by Mozilla. Mozilla's CAs are completely +replaced when CAs are explicitly specified using this option. + +##### rejectUnauthorized? + +> `optional` **rejectUnauthorized**: `boolean` + +Whether to reject unauthorized certificates. Default is `true`. diff --git a/src/reference/modules/llrt/net.md b/src/reference/modules/llrt/net.md index bdd279f..7e9ceed 100644 --- a/src/reference/modules/llrt/net.md +++ b/src/reference/modules/llrt/net.md @@ -10,7 +10,7 @@ This class is used to create a TCP or `IPC` server. #### Extends -- [`EventEmitter`](globals/index.md#eventemitter) +- [`EventEmitter`](events.md#eventemitter) #### Constructors @@ -30,7 +30,7 @@ This class is used to create a TCP or `IPC` server. ###### Overrides -[`EventEmitter`](globals/index.md#eventemitter).[`constructor`](globals/index.md#constructor) +[`EventEmitter`](events.md#eventemitter).[`constructor`](events.md#constructor) ##### Constructor @@ -78,7 +78,7 @@ events.EventEmitter ###### Overrides -[`EventEmitter`](globals/index.md#eventemitter).[`addListener`](globals/index.md#addlistener) +[`EventEmitter`](events.md#eventemitter).[`addListener`](events.md#addlistener) ###### Call Signature @@ -281,7 +281,7 @@ myEmitter.emit('event', 1, 2, 3, 4, 5); ###### Overrides -[`EventEmitter`](globals/index.md#eventemitter).[`emit`](globals/index.md#emit) +[`EventEmitter`](events.md#eventemitter).[`emit`](events.md#emit) ###### Call Signature @@ -384,7 +384,7 @@ console.log(myEE.eventNames()); ###### Inherited from -[`EventEmitter`](globals/index.md#eventemitter).[`eventNames`](globals/index.md#eventnames) +[`EventEmitter`](events.md#eventemitter).[`eventNames`](events.md#eventnames) ##### listen() @@ -697,7 +697,7 @@ Alias for `emitter.removeListener()`. ###### Inherited from -[`EventEmitter`](globals/index.md#eventemitter).[`off`](globals/index.md#off) +[`EventEmitter`](events.md#eventemitter).[`off`](events.md#off) ##### on() @@ -745,7 +745,7 @@ myEE.emit('foo'); ###### Overrides -[`EventEmitter`](globals/index.md#eventemitter).[`on`](globals/index.md#on) +[`EventEmitter`](events.md#eventemitter).[`on`](events.md#on) ###### Call Signature @@ -865,7 +865,7 @@ v0.3.0 ###### Overrides -[`EventEmitter`](globals/index.md#eventemitter).[`once`](globals/index.md#once) +[`EventEmitter`](events.md#eventemitter).[`once`](events.md#once) ###### Call Signature @@ -969,7 +969,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Overrides -[`EventEmitter`](globals/index.md#eventemitter).[`prependListener`](globals/index.md#prependlistener) +[`EventEmitter`](events.md#eventemitter).[`prependListener`](events.md#prependlistener) ###### Call Signature @@ -1071,7 +1071,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Overrides -[`EventEmitter`](globals/index.md#eventemitter).[`prependOnceListener`](globals/index.md#prependoncelistener) +[`EventEmitter`](events.md#eventemitter).[`prependOnceListener`](events.md#prependoncelistener) ###### Call Signature @@ -1243,7 +1243,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Inherited from -[`EventEmitter`](globals/index.md#eventemitter).[`removeListener`](globals/index.md#removelistener) +[`EventEmitter`](events.md#eventemitter).[`removeListener`](events.md#removelistener) *** @@ -2718,7 +2718,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ##### write() -> **write**(`chunk`: `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](buffer.md#buffer), `callback?`: (`error?`: `Error` \| `null`) => `void`): `void` +> **write**(`chunk`: `string` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](buffer.md#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer`, `callback?`: (`error?`: `Error` \| `null`) => `void`): `void` The `writable.write()` method writes some data to the stream, and calls the supplied `callback` once the data has been fully handled. If an error @@ -2747,7 +2747,7 @@ A `Writable` stream in object mode will always ignore the `encoding` argument. | Parameter | Type | Description | | ------ | ------ | ------ | -| `chunk` | `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](buffer.md#buffer) | Optional data to write. `chunk` must be a {string}, {Buffer}, {TypedArray} or {DataView}. | +| `chunk` | `string` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](buffer.md#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer` | Optional data to write. `chunk` must be a {string}, {Buffer}, {TypedArray} or {DataView}. | | `callback?` | (`error?`: `Error` \| `null`) => `void` | Callback for when this chunk of data is flushed. | ###### Returns diff --git a/src/reference/modules/llrt/process.md b/src/reference/modules/llrt/process.md deleted file mode 100644 index 30aecad..0000000 --- a/src/reference/modules/llrt/process.md +++ /dev/null @@ -1,3 +0,0 @@ -[@caido/quickjs-types](../index.md) / [llrt/process](process.md) / process - -# process diff --git a/src/reference/modules/llrt/stream.md b/src/reference/modules/llrt/stream.md deleted file mode 100644 index c4d2372..0000000 --- a/src/reference/modules/llrt/stream.md +++ /dev/null @@ -1,5658 +0,0 @@ -[@caido/quickjs-types](../index.md) / [llrt/stream](stream.md) / stream - -# stream - -## Classes - -### DefaultDuplexStream - -#### Extends - -- [`DefaultReadableStream`](stream.md#defaultreadablestream) - -#### Extended by - -- [`Socket`](net.md#socket) - -#### Implements - -- [`DefaultWritableStream`](stream.md#defaultwritablestream) - -#### Constructors - -##### new DefaultDuplexStream() - -> **new DefaultDuplexStream**(): [`DefaultDuplexStream`](stream.md#defaultduplexstream) - -###### Returns - -[`DefaultDuplexStream`](stream.md#defaultduplexstream) - -###### Inherited from - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`constructor`](stream.md#constructors-1) - -#### Methods - -##### \[dispose\]() - -> **\[dispose\]**(): `void` - -Calls `readable.destroy()`. - -###### Returns - -`void` - -###### Inherited from - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`[dispose]`](stream.md#dispose-1) - -##### addListener() - -###### Call Signature - -> **addListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. error -3. finish - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`addListener`](stream.md#addlistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`addListener`](stream.md#addlistener-1) - -###### Call Signature - -> **addListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. error -3. finish - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`addListener`](stream.md#addlistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`addListener`](stream.md#addlistener-1) - -###### Call Signature - -> **addListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. error -3. finish - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`addListener`](stream.md#addlistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`addListener`](stream.md#addlistener-1) - -###### Call Signature - -> **addListener**(`event`: `"finish"`, `listener`: () => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. error -3. finish - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`addListener`](stream.md#addlistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`addListener`](stream.md#addlistener-1) - -##### destroy() - -> **destroy**(`error`?: `Error`): `this` - -Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'` event. After this call, the readable -stream will release any internal resources and subsequent calls to `push()` will be ignored. - -Once `destroy()` has been called any further calls will be a no-op and no -further errors except from `_destroy()` may be emitted as `'error'`. - -Implementors should not override this method, but instead implement `readable._destroy()`. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `error`? | `Error` | Error which will be passed as payload in `'error'` event | - -###### Returns - -`this` - -###### Inherited from - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`destroy`](stream.md#destroy-1) - -##### emit() - -###### Call Signature - -> **emit**(`event`: [`EventKey`](dom-events.md#eventkey), ...`args`: `any`[]): `boolean` - -Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments -to each. - -```js -import { EventEmitter } from 'events'; -const myEmitter = new EventEmitter(); - -// First listener -myEmitter.on('event', function firstListener() { - console.log('Helloooo! first listener'); -}); -// Second listener -myEmitter.on('event', function secondListener(arg1, arg2) { - console.log(`event with parameters ${arg1}, ${arg2} in second listener`); -}); -// Third listener -myEmitter.on('event', function thirdListener(...args) { - const parameters = args.join(', '); - console.log(`event with parameters ${parameters} in third listener`); -}); - -myEmitter.emit('event', 1, 2, 3, 4, 5); - -// Prints: -// Helloooo! first listener -// event with parameters 1, 2 in second listener -// event with parameters 1, 2, 3, 4, 5 in third listener -``` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| ...`args` | `any`[] | - -###### Returns - -`boolean` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`emit`](stream.md#emit-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`emit`](stream.md#emit-1) - -###### Call Signature - -> **emit**(`event`: `"close"`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | - -###### Returns - -`boolean` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`emit`](stream.md#emit-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`emit`](stream.md#emit-1) - -###### Call Signature - -> **emit**(`event`: `"error"`, `err`: `Error`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `err` | `Error` | - -###### Returns - -`boolean` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`emit`](stream.md#emit-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`emit`](stream.md#emit-1) - -###### Call Signature - -> **emit**(`event`: `"finish"`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | - -###### Returns - -`boolean` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`emit`](stream.md#emit-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`emit`](stream.md#emit-1) - -##### end() - -> **end**(): `this` - -Calling the `writable.end()` method signals that no more data will be written -to the `Writable`. - -Calling the [write](stream.md#write) method after calling [end](stream.md#end) will raise an error. - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`end`](stream.md#end-1) - -##### eventNames() - -> **eventNames**(): [`EventKey`](dom-events.md#eventkey)[] - -Returns an array listing the events for which the emitter has registered -listeners. The values in the array are strings or `Symbol`s. - -```js -import { EventEmitter } from 'events'; - -const myEE = new EventEmitter(); -myEE.on('foo', () => {}); -myEE.on('bar', () => {}); - -const sym = Symbol('symbol'); -myEE.on(sym, () => {}); - -console.log(myEE.eventNames()); -// Prints: [ 'foo', 'bar', Symbol(symbol) ] -``` - -###### Returns - -[`EventKey`](dom-events.md#eventkey)[] - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`eventNames`](stream.md#eventnames-2) - -###### Inherited from - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`eventNames`](stream.md#eventnames-1) - -##### off() - -> **off**\<`K`\>(`eventName`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Alias for `emitter.removeListener()`. - -###### Type Parameters - -| Type Parameter | -| ------ | -| `K` | - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `eventName` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`off`](stream.md#off-2) - -###### Inherited from - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`off`](stream.md#off-1) - -##### on() - -###### Call Signature - -> **on**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds the `listener` function to the end of the listeners array for the event -named `eventName`. No checks are made to see if the `listener` has already -been added. Multiple calls passing the same combination of `eventName` and -`listener` will result in the `listener` being added, and called, multiple times. - -```js -server.on('connection', (stream) => { - console.log('someone connected!'); -}); -``` - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the -event listener to the beginning of the listeners array. - -```js -import { EventEmitter } from 'events'; -const myEE = new EventEmitter(); -myEE.on('foo', () => console.log('a')); -myEE.prependListener('foo', () => console.log('b')); -myEE.emit('foo'); -// Prints: -// b -// a -``` - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`on`](stream.md#on-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`on`](stream.md#on-1) - -###### Call Signature - -> **on**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`on`](stream.md#on-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`on`](stream.md#on-1) - -###### Call Signature - -> **on**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`on`](stream.md#on-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`on`](stream.md#on-1) - -###### Call Signature - -> **on**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`on`](stream.md#on-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`on`](stream.md#on-1) - -##### once() - -###### Call Signature - -> **once**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds a **one-time** `listener` function for the event named `eventName`. The -next time `eventName` is triggered, this listener is removed and then invoked. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the -event listener to the beginning of the listeners array. - -```js -import { EventEmitter } from 'events'; -const myEE = new EventEmitter(); -myEE.once('foo', () => console.log('a')); -myEE.prependOnceListener('foo', () => console.log('b')); -myEE.emit('foo'); -// Prints: -// b -// a -``` - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Since - -v0.3.0 - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`once`](stream.md#once-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`once`](stream.md#once-1) - -###### Call Signature - -> **once**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`once`](stream.md#once-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`once`](stream.md#once-1) - -###### Call Signature - -> **once**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`once`](stream.md#once-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`once`](stream.md#once-1) - -###### Call Signature - -> **once**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`once`](stream.md#once-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`once`](stream.md#once-1) - -##### prependListener() - -###### Call Signature - -> **prependListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds the `listener` function to the _beginning_ of the listeners array for the -event named `eventName`. No checks are made to see if the `listener` has -already been added. Multiple calls passing the same combination of `eventName` -and `listener` will result in the `listener` being added, and called, multiple times. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`prependListener`](stream.md#prependlistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`prependListener`](stream.md#prependlistener-1) - -###### Call Signature - -> **prependListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`prependListener`](stream.md#prependlistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`prependListener`](stream.md#prependlistener-1) - -###### Call Signature - -> **prependListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`prependListener`](stream.md#prependlistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`prependListener`](stream.md#prependlistener-1) - -###### Call Signature - -> **prependListener**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`prependListener`](stream.md#prependlistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`prependListener`](stream.md#prependlistener-1) - -##### prependOnceListener() - -###### Call Signature - -> **prependOnceListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds a **one-time**`listener` function for the event named `eventName` to the _beginning_ of the listeners array. -The next time `eventName` is triggered, this listener is removed, and then invoked. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`prependOnceListener`](stream.md#prependoncelistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`prependOnceListener`](stream.md#prependoncelistener-1) - -###### Call Signature - -> **prependOnceListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`prependOnceListener`](stream.md#prependoncelistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`prependOnceListener`](stream.md#prependoncelistener-1) - -###### Call Signature - -> **prependOnceListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`prependOnceListener`](stream.md#prependoncelistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`prependOnceListener`](stream.md#prependoncelistener-1) - -###### Call Signature - -> **prependOnceListener**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`prependOnceListener`](stream.md#prependoncelistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`prependOnceListener`](stream.md#prependoncelistener-1) - -##### read() - -> **read**(`size`?: `number`): `null` \| [`Buffer`](buffer.md#buffer) - -The `readable.read()` method reads data out of the internal buffer and -returns it. If no data is available to be read, `null` is returned. By default, -the data is returned as a `Buffer` object unless an encoding has been -specified using the `readable.setEncoding()` method or the stream is operating -in object mode. - -The optional `size` argument specifies a specific number of bytes to read. If -`size` bytes are not available to be read, `null` will be returned _unless_ the -stream has ended, in which case all of the data remaining in the internal buffer -will be returned. - -If the `size` argument is not specified, all of the data contained in the -internal buffer will be returned. - -The `size` argument must be less than or equal to 1 GiB. - -The `readable.read()` method should only be called on `Readable` streams -operating in paused mode. In flowing mode, `readable.read()` is called -automatically until the internal buffer is fully drained. - -```js -const readable = getReadableStreamSomehow(); - -// 'readable' may be triggered multiple times as data is buffered in -readable.on('readable', () => { - let chunk; - console.log('Stream is readable (new data received in buffer)'); - // Use a loop to make sure we read all currently available data - while (null !== (chunk = readable.read())) { - console.log(`Read ${chunk.length} bytes of data...`); - } -}); - -// 'end' will be triggered once when there is no more data available -readable.on('end', () => { - console.log('Reached end of stream.'); -}); -``` - -Each call to `readable.read()` returns a chunk of data, or `null`. The chunks -are not concatenated. A `while` loop is necessary to consume all data -currently in the buffer. When reading a large file `.read()` may return `null`, -having consumed all buffered content so far, but there is still more data to -come not yet buffered. In this case a new `'readable'` event will be emitted -when there is more data in the buffer. Finally the `'end'` event will be -emitted when there is no more data to come. - -Therefore to read a file's whole contents from a `readable`, it is necessary -to collect chunks across multiple `'readable'` events: - -```js -const chunks = []; - -readable.on('readable', () => { - let chunk; - while (null !== (chunk = readable.read())) { - chunks.push(chunk); - } -}); - -readable.on('end', () => { - const content = chunks.join(''); -}); -``` - -A `Readable` stream in object mode will always return a single item from -a call to `readable.read(size)`, regardless of the value of the `size` argument. - -If the `readable.read()` method returns a chunk of data, a `'data'` event will -also be emitted. - -Calling [read](stream.md#read-2) after the `'end'` event has -been emitted will return `null`. No runtime error will be raised. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `size`? | `number` | Optional argument to specify how much data to read. | - -###### Returns - -`null` \| [`Buffer`](buffer.md#buffer) - -###### Inherited from - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`read`](stream.md#read-1) - -##### removeListener() - -###### Call Signature - -> **removeListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Removes the specified `listener` from the listener array for the event named `eventName`. - -`removeListener()` will remove, at most, one instance of a listener from the -listener array. If any single listener has been added multiple times to the -listener array for the specified `eventName`, then `removeListener()` must be -called multiple times to remove each instance. - -Once an event is emitted, all listeners attached to it at the time of emitting are called in order. -This implies that any `removeListener()` calls _after_ emitting and _before_ the last listener finishes execution -will not remove them from `emit()` in progress. Subsequent events behave as expected. - -```js -import { EventEmitter } from 'events'; -class MyEmitter extends EventEmitter {} -const myEmitter = new MyEmitter(); - -const callbackA = () => { - console.log('A'); - myEmitter.removeListener('event', callbackB); -}; - -const callbackB = () => { - console.log('B'); -}; - -myEmitter.on('event', callbackA); - -myEmitter.on('event', callbackB); - -// callbackA removes listener callbackB but it will still be called. -// Internal listener array at time of emit [callbackA, callbackB] -myEmitter.emit('event'); -// Prints: -// A -// B - -// callbackB is now removed. -// Internal listener array [callbackA] -myEmitter.emit('event'); -// Prints: -// A -``` - -Because listeners are managed using an internal array, calling this will -change the position indices of any listener registered _after_ the listener -being removed. This will not impact the order in which listeners are called, -but it means that any copies of the listener array as returned by -the `emitter.listeners()` method will need to be recreated. - -When a single function has been added as a handler multiple times for a single -event (as in the example below), `removeListener()` will remove the most -recently added instance. In the example the `once('ping')` listener is removed: - -```js -import { EventEmitter } from 'events'; -const ee = new EventEmitter(); - -function pong() { - console.log('pong'); -} - -ee.on('ping', pong); -ee.once('ping', pong); -ee.removeListener('ping', pong); - -ee.emit('ping'); -ee.emit('ping'); -``` - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`removeListener`](stream.md#removelistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`removeListener`](stream.md#removelistener-1) - -###### Call Signature - -> **removeListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`removeListener`](stream.md#removelistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`removeListener`](stream.md#removelistener-1) - -###### Call Signature - -> **removeListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`removeListener`](stream.md#removelistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`removeListener`](stream.md#removelistener-1) - -###### Call Signature - -> **removeListener**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`removeListener`](stream.md#removelistener-2) - -###### Overrides - -[`DefaultReadableStream`](stream.md#defaultreadablestream).[`removeListener`](stream.md#removelistener-1) - -##### write() - -> **write**(`chunk`: `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](buffer.md#buffer), `callback`?: (`error`?: `null` \| `Error`) => `void`): `void` - -The `writable.write()` method writes some data to the stream, and calls the -supplied `callback` once the data has been fully handled. If an error -occurs, the `callback` will be called with the error as its -first argument. The `callback` is usually called asynchronously and before `'error'` -is emitted. - -```js -function write(data, cb) { - if (!stream.write(data)) { - stream.once('drain', cb); - } else { - process.nextTick(cb); - } -} - -// Wait for cb to be called before doing any other write. -write('hello', () => { - console.log('Write completed, do more writes now.'); -}); -``` - -A `Writable` stream in object mode will always ignore the `encoding` argument. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `chunk` | `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](buffer.md#buffer) | Optional data to write. `chunk` must be a {string}, {Buffer}, {TypedArray} or {DataView}. | -| `callback`? | (`error`?: `null` \| `Error`) => `void` | Callback for when this chunk of data is flushed. | - -###### Returns - -`void` - -`false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`. - -###### Since - -v0.9.4 - -###### Implementation of - -[`DefaultWritableStream`](stream.md#defaultwritablestream).[`write`](stream.md#write-1) - -*** - -### DefaultReadableStream - -#### Extends - -- [`ReadableStreamInner`](stream.md#readablestreaminner) - -#### Extended by - -- [`DefaultDuplexStream`](stream.md#defaultduplexstream) - -#### Constructors - -##### new DefaultReadableStream() - -> **new DefaultReadableStream**(): [`DefaultReadableStream`](stream.md#defaultreadablestream) - -###### Returns - -[`DefaultReadableStream`](stream.md#defaultreadablestream) - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`constructor`](stream.md#constructors-3) - -#### Methods - -##### \[dispose\]() - -> **\[dispose\]**(): `void` - -Calls `readable.destroy()`. - -###### Returns - -`void` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`[dispose]`](stream.md#dispose-2) - -##### addListener() - -###### Call Signature - -> **addListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. data -3. end -4. error -5. readable - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`addListener`](stream.md#addlistener-3) - -###### Call Signature - -> **addListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. data -3. end -4. error -5. readable - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`addListener`](stream.md#addlistener-3) - -###### Call Signature - -> **addListener**(`event`: `"data"`, `listener`: (`chunk`: [`Buffer`](buffer.md#buffer)) => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. data -3. end -4. error -5. readable - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"data"` | -| `listener` | (`chunk`: [`Buffer`](buffer.md#buffer)) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`addListener`](stream.md#addlistener-3) - -###### Call Signature - -> **addListener**(`event`: `"end"`, `listener`: () => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. data -3. end -4. error -5. readable - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"end"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`addListener`](stream.md#addlistener-3) - -###### Call Signature - -> **addListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. data -3. end -4. error -5. readable - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`addListener`](stream.md#addlistener-3) - -###### Call Signature - -> **addListener**(`event`: `"readable"`, `listener`: () => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. data -3. end -4. error -5. readable - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"readable"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`addListener`](stream.md#addlistener-3) - -##### destroy() - -> **destroy**(`error`?: `Error`): `this` - -Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'` event. After this call, the readable -stream will release any internal resources and subsequent calls to `push()` will be ignored. - -Once `destroy()` has been called any further calls will be a no-op and no -further errors except from `_destroy()` may be emitted as `'error'`. - -Implementors should not override this method, but instead implement `readable._destroy()`. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `error`? | `Error` | Error which will be passed as payload in `'error'` event | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`destroy`](stream.md#destroy-2) - -##### emit() - -###### Call Signature - -> **emit**(`event`: [`EventKey`](dom-events.md#eventkey), ...`args`: `any`[]): `boolean` - -Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments -to each. - -```js -import { EventEmitter } from 'events'; -const myEmitter = new EventEmitter(); - -// First listener -myEmitter.on('event', function firstListener() { - console.log('Helloooo! first listener'); -}); -// Second listener -myEmitter.on('event', function secondListener(arg1, arg2) { - console.log(`event with parameters ${arg1}, ${arg2} in second listener`); -}); -// Third listener -myEmitter.on('event', function thirdListener(...args) { - const parameters = args.join(', '); - console.log(`event with parameters ${parameters} in third listener`); -}); - -myEmitter.emit('event', 1, 2, 3, 4, 5); - -// Prints: -// Helloooo! first listener -// event with parameters 1, 2 in second listener -// event with parameters 1, 2, 3, 4, 5 in third listener -``` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| ...`args` | `any`[] | - -###### Returns - -`boolean` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`emit`](stream.md#emit-3) - -###### Call Signature - -> **emit**(`event`: `"close"`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | - -###### Returns - -`boolean` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`emit`](stream.md#emit-3) - -###### Call Signature - -> **emit**(`event`: `"data"`, `chunk`: [`Buffer`](buffer.md#buffer)): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"data"` | -| `chunk` | [`Buffer`](buffer.md#buffer) | - -###### Returns - -`boolean` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`emit`](stream.md#emit-3) - -###### Call Signature - -> **emit**(`event`: `"end"`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"end"` | - -###### Returns - -`boolean` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`emit`](stream.md#emit-3) - -###### Call Signature - -> **emit**(`event`: `"error"`, `err`: `Error`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `err` | `Error` | - -###### Returns - -`boolean` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`emit`](stream.md#emit-3) - -###### Call Signature - -> **emit**(`event`: `"readable"`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"readable"` | - -###### Returns - -`boolean` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`emit`](stream.md#emit-3) - -##### eventNames() - -> **eventNames**(): [`EventKey`](dom-events.md#eventkey)[] - -Returns an array listing the events for which the emitter has registered -listeners. The values in the array are strings or `Symbol`s. - -```js -import { EventEmitter } from 'events'; - -const myEE = new EventEmitter(); -myEE.on('foo', () => {}); -myEE.on('bar', () => {}); - -const sym = Symbol('symbol'); -myEE.on(sym, () => {}); - -console.log(myEE.eventNames()); -// Prints: [ 'foo', 'bar', Symbol(symbol) ] -``` - -###### Returns - -[`EventKey`](dom-events.md#eventkey)[] - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`eventNames`](stream.md#eventnames-3) - -##### off() - -> **off**\<`K`\>(`eventName`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Alias for `emitter.removeListener()`. - -###### Type Parameters - -| Type Parameter | -| ------ | -| `K` | - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `eventName` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`off`](stream.md#off-3) - -##### on() - -###### Call Signature - -> **on**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds the `listener` function to the end of the listeners array for the event -named `eventName`. No checks are made to see if the `listener` has already -been added. Multiple calls passing the same combination of `eventName` and -`listener` will result in the `listener` being added, and called, multiple times. - -```js -server.on('connection', (stream) => { - console.log('someone connected!'); -}); -``` - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the -event listener to the beginning of the listeners array. - -```js -import { EventEmitter } from 'events'; -const myEE = new EventEmitter(); -myEE.on('foo', () => console.log('a')); -myEE.prependListener('foo', () => console.log('b')); -myEE.emit('foo'); -// Prints: -// b -// a -``` - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`on`](stream.md#on-3) - -###### Call Signature - -> **on**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`on`](stream.md#on-3) - -###### Call Signature - -> **on**(`event`: `"data"`, `listener`: (`chunk`: [`Buffer`](buffer.md#buffer)) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"data"` | -| `listener` | (`chunk`: [`Buffer`](buffer.md#buffer)) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`on`](stream.md#on-3) - -###### Call Signature - -> **on**(`event`: `"end"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"end"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`on`](stream.md#on-3) - -###### Call Signature - -> **on**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`on`](stream.md#on-3) - -###### Call Signature - -> **on**(`event`: `"readable"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"readable"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`on`](stream.md#on-3) - -##### once() - -###### Call Signature - -> **once**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds a **one-time** `listener` function for the event named `eventName`. The -next time `eventName` is triggered, this listener is removed and then invoked. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the -event listener to the beginning of the listeners array. - -```js -import { EventEmitter } from 'events'; -const myEE = new EventEmitter(); -myEE.once('foo', () => console.log('a')); -myEE.prependOnceListener('foo', () => console.log('b')); -myEE.emit('foo'); -// Prints: -// b -// a -``` - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Since - -v0.3.0 - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`once`](stream.md#once-3) - -###### Call Signature - -> **once**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`once`](stream.md#once-3) - -###### Call Signature - -> **once**(`event`: `"data"`, `listener`: (`chunk`: [`Buffer`](buffer.md#buffer)) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"data"` | -| `listener` | (`chunk`: [`Buffer`](buffer.md#buffer)) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`once`](stream.md#once-3) - -###### Call Signature - -> **once**(`event`: `"end"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"end"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`once`](stream.md#once-3) - -###### Call Signature - -> **once**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`once`](stream.md#once-3) - -###### Call Signature - -> **once**(`event`: `"readable"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"readable"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`once`](stream.md#once-3) - -##### prependListener() - -###### Call Signature - -> **prependListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds the `listener` function to the _beginning_ of the listeners array for the -event named `eventName`. No checks are made to see if the `listener` has -already been added. Multiple calls passing the same combination of `eventName` -and `listener` will result in the `listener` being added, and called, multiple times. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`prependListener`](stream.md#prependlistener-3) - -###### Call Signature - -> **prependListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`prependListener`](stream.md#prependlistener-3) - -###### Call Signature - -> **prependListener**(`event`: `"data"`, `listener`: (`chunk`: [`Buffer`](buffer.md#buffer)) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"data"` | -| `listener` | (`chunk`: [`Buffer`](buffer.md#buffer)) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`prependListener`](stream.md#prependlistener-3) - -###### Call Signature - -> **prependListener**(`event`: `"end"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"end"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`prependListener`](stream.md#prependlistener-3) - -###### Call Signature - -> **prependListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`prependListener`](stream.md#prependlistener-3) - -###### Call Signature - -> **prependListener**(`event`: `"readable"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"readable"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`prependListener`](stream.md#prependlistener-3) - -##### prependOnceListener() - -###### Call Signature - -> **prependOnceListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds a **one-time**`listener` function for the event named `eventName` to the _beginning_ of the listeners array. -The next time `eventName` is triggered, this listener is removed, and then invoked. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`prependOnceListener`](stream.md#prependoncelistener-3) - -###### Call Signature - -> **prependOnceListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`prependOnceListener`](stream.md#prependoncelistener-3) - -###### Call Signature - -> **prependOnceListener**(`event`: `"data"`, `listener`: (`chunk`: [`Buffer`](buffer.md#buffer)) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"data"` | -| `listener` | (`chunk`: [`Buffer`](buffer.md#buffer)) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`prependOnceListener`](stream.md#prependoncelistener-3) - -###### Call Signature - -> **prependOnceListener**(`event`: `"end"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"end"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`prependOnceListener`](stream.md#prependoncelistener-3) - -###### Call Signature - -> **prependOnceListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`prependOnceListener`](stream.md#prependoncelistener-3) - -###### Call Signature - -> **prependOnceListener**(`event`: `"readable"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"readable"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`prependOnceListener`](stream.md#prependoncelistener-3) - -##### read() - -> **read**(`size`?: `number`): `null` \| [`Buffer`](buffer.md#buffer) - -The `readable.read()` method reads data out of the internal buffer and -returns it. If no data is available to be read, `null` is returned. By default, -the data is returned as a `Buffer` object unless an encoding has been -specified using the `readable.setEncoding()` method or the stream is operating -in object mode. - -The optional `size` argument specifies a specific number of bytes to read. If -`size` bytes are not available to be read, `null` will be returned _unless_ the -stream has ended, in which case all of the data remaining in the internal buffer -will be returned. - -If the `size` argument is not specified, all of the data contained in the -internal buffer will be returned. - -The `size` argument must be less than or equal to 1 GiB. - -The `readable.read()` method should only be called on `Readable` streams -operating in paused mode. In flowing mode, `readable.read()` is called -automatically until the internal buffer is fully drained. - -```js -const readable = getReadableStreamSomehow(); - -// 'readable' may be triggered multiple times as data is buffered in -readable.on('readable', () => { - let chunk; - console.log('Stream is readable (new data received in buffer)'); - // Use a loop to make sure we read all currently available data - while (null !== (chunk = readable.read())) { - console.log(`Read ${chunk.length} bytes of data...`); - } -}); - -// 'end' will be triggered once when there is no more data available -readable.on('end', () => { - console.log('Reached end of stream.'); -}); -``` - -Each call to `readable.read()` returns a chunk of data, or `null`. The chunks -are not concatenated. A `while` loop is necessary to consume all data -currently in the buffer. When reading a large file `.read()` may return `null`, -having consumed all buffered content so far, but there is still more data to -come not yet buffered. In this case a new `'readable'` event will be emitted -when there is more data in the buffer. Finally the `'end'` event will be -emitted when there is no more data to come. - -Therefore to read a file's whole contents from a `readable`, it is necessary -to collect chunks across multiple `'readable'` events: - -```js -const chunks = []; - -readable.on('readable', () => { - let chunk; - while (null !== (chunk = readable.read())) { - chunks.push(chunk); - } -}); - -readable.on('end', () => { - const content = chunks.join(''); -}); -``` - -A `Readable` stream in object mode will always return a single item from -a call to `readable.read(size)`, regardless of the value of the `size` argument. - -If the `readable.read()` method returns a chunk of data, a `'data'` event will -also be emitted. - -Calling [read](stream.md#read-2) after the `'end'` event has -been emitted will return `null`. No runtime error will be raised. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `size`? | `number` | Optional argument to specify how much data to read. | - -###### Returns - -`null` \| [`Buffer`](buffer.md#buffer) - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`read`](stream.md#read-2) - -##### removeListener() - -###### Call Signature - -> **removeListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Removes the specified `listener` from the listener array for the event named `eventName`. - -`removeListener()` will remove, at most, one instance of a listener from the -listener array. If any single listener has been added multiple times to the -listener array for the specified `eventName`, then `removeListener()` must be -called multiple times to remove each instance. - -Once an event is emitted, all listeners attached to it at the time of emitting are called in order. -This implies that any `removeListener()` calls _after_ emitting and _before_ the last listener finishes execution -will not remove them from `emit()` in progress. Subsequent events behave as expected. - -```js -import { EventEmitter } from 'events'; -class MyEmitter extends EventEmitter {} -const myEmitter = new MyEmitter(); - -const callbackA = () => { - console.log('A'); - myEmitter.removeListener('event', callbackB); -}; - -const callbackB = () => { - console.log('B'); -}; - -myEmitter.on('event', callbackA); - -myEmitter.on('event', callbackB); - -// callbackA removes listener callbackB but it will still be called. -// Internal listener array at time of emit [callbackA, callbackB] -myEmitter.emit('event'); -// Prints: -// A -// B - -// callbackB is now removed. -// Internal listener array [callbackA] -myEmitter.emit('event'); -// Prints: -// A -``` - -Because listeners are managed using an internal array, calling this will -change the position indices of any listener registered _after_ the listener -being removed. This will not impact the order in which listeners are called, -but it means that any copies of the listener array as returned by -the `emitter.listeners()` method will need to be recreated. - -When a single function has been added as a handler multiple times for a single -event (as in the example below), `removeListener()` will remove the most -recently added instance. In the example the `once('ping')` listener is removed: - -```js -import { EventEmitter } from 'events'; -const ee = new EventEmitter(); - -function pong() { - console.log('pong'); -} - -ee.on('ping', pong); -ee.once('ping', pong); -ee.removeListener('ping', pong); - -ee.emit('ping'); -ee.emit('ping'); -``` - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`removeListener`](stream.md#removelistener-3) - -###### Call Signature - -> **removeListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`removeListener`](stream.md#removelistener-3) - -###### Call Signature - -> **removeListener**(`event`: `"data"`, `listener`: (`chunk`: [`Buffer`](buffer.md#buffer)) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"data"` | -| `listener` | (`chunk`: [`Buffer`](buffer.md#buffer)) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`removeListener`](stream.md#removelistener-3) - -###### Call Signature - -> **removeListener**(`event`: `"end"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"end"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`removeListener`](stream.md#removelistener-3) - -###### Call Signature - -> **removeListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`removeListener`](stream.md#removelistener-3) - -###### Call Signature - -> **removeListener**(`event`: `"readable"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"readable"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`ReadableStreamInner`](stream.md#readablestreaminner).[`removeListener`](stream.md#removelistener-3) - -*** - -### DefaultWritableStream - -#### Extends - -- [`WritableStreamInner`](stream.md#writablestreaminner) - -#### Constructors - -##### new DefaultWritableStream() - -> **new DefaultWritableStream**(): [`DefaultWritableStream`](stream.md#defaultwritablestream) - -###### Returns - -[`DefaultWritableStream`](stream.md#defaultwritablestream) - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`constructor`](stream.md#constructors-4) - -#### Methods - -##### addListener() - -###### Call Signature - -> **addListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. error -3. finish - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`addListener`](stream.md#addlistener-4) - -###### Call Signature - -> **addListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. error -3. finish - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`addListener`](stream.md#addlistener-4) - -###### Call Signature - -> **addListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. error -3. finish - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`addListener`](stream.md#addlistener-4) - -###### Call Signature - -> **addListener**(`event`: `"finish"`, `listener`: () => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. error -3. finish - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`addListener`](stream.md#addlistener-4) - -##### emit() - -###### Call Signature - -> **emit**(`event`: [`EventKey`](dom-events.md#eventkey), ...`args`: `any`[]): `boolean` - -Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments -to each. - -```js -import { EventEmitter } from 'events'; -const myEmitter = new EventEmitter(); - -// First listener -myEmitter.on('event', function firstListener() { - console.log('Helloooo! first listener'); -}); -// Second listener -myEmitter.on('event', function secondListener(arg1, arg2) { - console.log(`event with parameters ${arg1}, ${arg2} in second listener`); -}); -// Third listener -myEmitter.on('event', function thirdListener(...args) { - const parameters = args.join(', '); - console.log(`event with parameters ${parameters} in third listener`); -}); - -myEmitter.emit('event', 1, 2, 3, 4, 5); - -// Prints: -// Helloooo! first listener -// event with parameters 1, 2 in second listener -// event with parameters 1, 2, 3, 4, 5 in third listener -``` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| ...`args` | `any`[] | - -###### Returns - -`boolean` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`emit`](stream.md#emit-4) - -###### Call Signature - -> **emit**(`event`: `"close"`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | - -###### Returns - -`boolean` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`emit`](stream.md#emit-4) - -###### Call Signature - -> **emit**(`event`: `"error"`, `err`: `Error`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `err` | `Error` | - -###### Returns - -`boolean` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`emit`](stream.md#emit-4) - -###### Call Signature - -> **emit**(`event`: `"finish"`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | - -###### Returns - -`boolean` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`emit`](stream.md#emit-4) - -##### end() - -> **end**(): `this` - -Calling the `writable.end()` method signals that no more data will be written -to the `Writable`. - -Calling the [write](stream.md#write-2) method after calling [end](stream.md#end-2) will raise an error. - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`end`](stream.md#end-2) - -##### eventNames() - -> **eventNames**(): [`EventKey`](dom-events.md#eventkey)[] - -Returns an array listing the events for which the emitter has registered -listeners. The values in the array are strings or `Symbol`s. - -```js -import { EventEmitter } from 'events'; - -const myEE = new EventEmitter(); -myEE.on('foo', () => {}); -myEE.on('bar', () => {}); - -const sym = Symbol('symbol'); -myEE.on(sym, () => {}); - -console.log(myEE.eventNames()); -// Prints: [ 'foo', 'bar', Symbol(symbol) ] -``` - -###### Returns - -[`EventKey`](dom-events.md#eventkey)[] - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`eventNames`](stream.md#eventnames-4) - -##### off() - -> **off**\<`K`\>(`eventName`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Alias for `emitter.removeListener()`. - -###### Type Parameters - -| Type Parameter | -| ------ | -| `K` | - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `eventName` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`off`](stream.md#off-4) - -##### on() - -###### Call Signature - -> **on**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds the `listener` function to the end of the listeners array for the event -named `eventName`. No checks are made to see if the `listener` has already -been added. Multiple calls passing the same combination of `eventName` and -`listener` will result in the `listener` being added, and called, multiple times. - -```js -server.on('connection', (stream) => { - console.log('someone connected!'); -}); -``` - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the -event listener to the beginning of the listeners array. - -```js -import { EventEmitter } from 'events'; -const myEE = new EventEmitter(); -myEE.on('foo', () => console.log('a')); -myEE.prependListener('foo', () => console.log('b')); -myEE.emit('foo'); -// Prints: -// b -// a -``` - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`on`](stream.md#on-4) - -###### Call Signature - -> **on**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`on`](stream.md#on-4) - -###### Call Signature - -> **on**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`on`](stream.md#on-4) - -###### Call Signature - -> **on**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`on`](stream.md#on-4) - -##### once() - -###### Call Signature - -> **once**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds a **one-time** `listener` function for the event named `eventName`. The -next time `eventName` is triggered, this listener is removed and then invoked. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the -event listener to the beginning of the listeners array. - -```js -import { EventEmitter } from 'events'; -const myEE = new EventEmitter(); -myEE.once('foo', () => console.log('a')); -myEE.prependOnceListener('foo', () => console.log('b')); -myEE.emit('foo'); -// Prints: -// b -// a -``` - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Since - -v0.3.0 - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`once`](stream.md#once-4) - -###### Call Signature - -> **once**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`once`](stream.md#once-4) - -###### Call Signature - -> **once**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`once`](stream.md#once-4) - -###### Call Signature - -> **once**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`once`](stream.md#once-4) - -##### prependListener() - -###### Call Signature - -> **prependListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds the `listener` function to the _beginning_ of the listeners array for the -event named `eventName`. No checks are made to see if the `listener` has -already been added. Multiple calls passing the same combination of `eventName` -and `listener` will result in the `listener` being added, and called, multiple times. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`prependListener`](stream.md#prependlistener-4) - -###### Call Signature - -> **prependListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`prependListener`](stream.md#prependlistener-4) - -###### Call Signature - -> **prependListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`prependListener`](stream.md#prependlistener-4) - -###### Call Signature - -> **prependListener**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`prependListener`](stream.md#prependlistener-4) - -##### prependOnceListener() - -###### Call Signature - -> **prependOnceListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds a **one-time**`listener` function for the event named `eventName` to the _beginning_ of the listeners array. -The next time `eventName` is triggered, this listener is removed, and then invoked. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`prependOnceListener`](stream.md#prependoncelistener-4) - -###### Call Signature - -> **prependOnceListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`prependOnceListener`](stream.md#prependoncelistener-4) - -###### Call Signature - -> **prependOnceListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`prependOnceListener`](stream.md#prependoncelistener-4) - -###### Call Signature - -> **prependOnceListener**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`prependOnceListener`](stream.md#prependoncelistener-4) - -##### removeListener() - -###### Call Signature - -> **removeListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Removes the specified `listener` from the listener array for the event named `eventName`. - -`removeListener()` will remove, at most, one instance of a listener from the -listener array. If any single listener has been added multiple times to the -listener array for the specified `eventName`, then `removeListener()` must be -called multiple times to remove each instance. - -Once an event is emitted, all listeners attached to it at the time of emitting are called in order. -This implies that any `removeListener()` calls _after_ emitting and _before_ the last listener finishes execution -will not remove them from `emit()` in progress. Subsequent events behave as expected. - -```js -import { EventEmitter } from 'events'; -class MyEmitter extends EventEmitter {} -const myEmitter = new MyEmitter(); - -const callbackA = () => { - console.log('A'); - myEmitter.removeListener('event', callbackB); -}; - -const callbackB = () => { - console.log('B'); -}; - -myEmitter.on('event', callbackA); - -myEmitter.on('event', callbackB); - -// callbackA removes listener callbackB but it will still be called. -// Internal listener array at time of emit [callbackA, callbackB] -myEmitter.emit('event'); -// Prints: -// A -// B - -// callbackB is now removed. -// Internal listener array [callbackA] -myEmitter.emit('event'); -// Prints: -// A -``` - -Because listeners are managed using an internal array, calling this will -change the position indices of any listener registered _after_ the listener -being removed. This will not impact the order in which listeners are called, -but it means that any copies of the listener array as returned by -the `emitter.listeners()` method will need to be recreated. - -When a single function has been added as a handler multiple times for a single -event (as in the example below), `removeListener()` will remove the most -recently added instance. In the example the `once('ping')` listener is removed: - -```js -import { EventEmitter } from 'events'; -const ee = new EventEmitter(); - -function pong() { - console.log('pong'); -} - -ee.on('ping', pong); -ee.once('ping', pong); -ee.removeListener('ping', pong); - -ee.emit('ping'); -ee.emit('ping'); -``` - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`removeListener`](stream.md#removelistener-4) - -###### Call Signature - -> **removeListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`removeListener`](stream.md#removelistener-4) - -###### Call Signature - -> **removeListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`removeListener`](stream.md#removelistener-4) - -###### Call Signature - -> **removeListener**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`removeListener`](stream.md#removelistener-4) - -##### write() - -> **write**(`chunk`: `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](buffer.md#buffer), `callback`?: (`error`?: `null` \| `Error`) => `void`): `void` - -The `writable.write()` method writes some data to the stream, and calls the -supplied `callback` once the data has been fully handled. If an error -occurs, the `callback` will be called with the error as its -first argument. The `callback` is usually called asynchronously and before `'error'` -is emitted. - -```js -function write(data, cb) { - if (!stream.write(data)) { - stream.once('drain', cb); - } else { - process.nextTick(cb); - } -} - -// Wait for cb to be called before doing any other write. -write('hello', () => { - console.log('Write completed, do more writes now.'); -}); -``` - -A `Writable` stream in object mode will always ignore the `encoding` argument. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `chunk` | `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](buffer.md#buffer) | Optional data to write. `chunk` must be a {string}, {Buffer}, {TypedArray} or {DataView}. | -| `callback`? | (`error`?: `null` \| `Error`) => `void` | Callback for when this chunk of data is flushed. | - -###### Returns - -`void` - -`false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`. - -###### Since - -v0.9.4 - -###### Inherited from - -[`WritableStreamInner`](stream.md#writablestreaminner).[`write`](stream.md#write-2) - -*** - -### ReadableStreamInner - -#### Extends - -- [`EventEmitter`](globals/index.md#eventemittert) - -#### Extended by - -- [`DefaultReadableStream`](stream.md#defaultreadablestream) - -#### Implements - -- [`ReadableStream`](globals/namespaces/QuickJS.md#readablestream) - -#### Constructors - -##### new ReadableStreamInner() - -> **new ReadableStreamInner**(): [`ReadableStreamInner`](stream.md#readablestreaminner) - -###### Returns - -[`ReadableStreamInner`](stream.md#readablestreaminner) - -###### Inherited from - -[`EventEmitter`](globals/index.md#eventemittert).[`constructor`](globals/index.md#constructors) - -#### Methods - -##### \[dispose\]() - -> **\[dispose\]**(): `void` - -Calls `readable.destroy()`. - -###### Returns - -`void` - -##### addListener() - -###### Call Signature - -> **addListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. data -3. end -4. error -5. readable - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`ReadableStream`](globals/namespaces/QuickJS.md#readablestream).[`addListener`](globals/namespaces/QuickJS.md#addlistener) - -###### Overrides - -[`EventEmitter`](globals/index.md#eventemittert).[`addListener`](globals/index.md#addlistener) - -###### Call Signature - -> **addListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. data -3. end -4. error -5. readable - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.addListener` - -###### Overrides - -`EventEmitter.addListener` - -###### Call Signature - -> **addListener**(`event`: `"data"`, `listener`: (`chunk`: [`Buffer`](buffer.md#buffer)) => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. data -3. end -4. error -5. readable - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"data"` | -| `listener` | (`chunk`: [`Buffer`](buffer.md#buffer)) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.addListener` - -###### Overrides - -`EventEmitter.addListener` - -###### Call Signature - -> **addListener**(`event`: `"end"`, `listener`: () => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. data -3. end -4. error -5. readable - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"end"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.addListener` - -###### Overrides - -`EventEmitter.addListener` - -###### Call Signature - -> **addListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. data -3. end -4. error -5. readable - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.addListener` - -###### Overrides - -`EventEmitter.addListener` - -###### Call Signature - -> **addListener**(`event`: `"readable"`, `listener`: () => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. data -3. end -4. error -5. readable - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"readable"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.addListener` - -###### Overrides - -`EventEmitter.addListener` - -##### destroy() - -> **destroy**(`error`?: `Error`): `this` - -Destroy the stream. Optionally emit an `'error'` event, and emit a `'close'` event. After this call, the readable -stream will release any internal resources and subsequent calls to `push()` will be ignored. - -Once `destroy()` has been called any further calls will be a no-op and no -further errors except from `_destroy()` may be emitted as `'error'`. - -Implementors should not override this method, but instead implement `readable._destroy()`. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `error`? | `Error` | Error which will be passed as payload in `'error'` event | - -###### Returns - -`this` - -##### emit() - -###### Call Signature - -> **emit**(`event`: [`EventKey`](dom-events.md#eventkey), ...`args`: `any`[]): `boolean` - -Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments -to each. - -```js -import { EventEmitter } from 'events'; -const myEmitter = new EventEmitter(); - -// First listener -myEmitter.on('event', function firstListener() { - console.log('Helloooo! first listener'); -}); -// Second listener -myEmitter.on('event', function secondListener(arg1, arg2) { - console.log(`event with parameters ${arg1}, ${arg2} in second listener`); -}); -// Third listener -myEmitter.on('event', function thirdListener(...args) { - const parameters = args.join(', '); - console.log(`event with parameters ${parameters} in third listener`); -}); - -myEmitter.emit('event', 1, 2, 3, 4, 5); - -// Prints: -// Helloooo! first listener -// event with parameters 1, 2 in second listener -// event with parameters 1, 2, 3, 4, 5 in third listener -``` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| ...`args` | `any`[] | - -###### Returns - -`boolean` - -###### Implementation of - -[`ReadableStream`](globals/namespaces/QuickJS.md#readablestream).[`emit`](globals/namespaces/QuickJS.md#emit) - -###### Overrides - -[`EventEmitter`](globals/index.md#eventemittert).[`emit`](globals/index.md#emit) - -###### Call Signature - -> **emit**(`event`: `"close"`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | - -###### Returns - -`boolean` - -###### Implementation of - -`QuickJS.ReadableStream.emit` - -###### Overrides - -`EventEmitter.emit` - -###### Call Signature - -> **emit**(`event`: `"data"`, `chunk`: [`Buffer`](buffer.md#buffer)): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"data"` | -| `chunk` | [`Buffer`](buffer.md#buffer) | - -###### Returns - -`boolean` - -###### Implementation of - -`QuickJS.ReadableStream.emit` - -###### Overrides - -`EventEmitter.emit` - -###### Call Signature - -> **emit**(`event`: `"end"`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"end"` | - -###### Returns - -`boolean` - -###### Implementation of - -`QuickJS.ReadableStream.emit` - -###### Overrides - -`EventEmitter.emit` - -###### Call Signature - -> **emit**(`event`: `"error"`, `err`: `Error`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `err` | `Error` | - -###### Returns - -`boolean` - -###### Implementation of - -`QuickJS.ReadableStream.emit` - -###### Overrides - -`EventEmitter.emit` - -###### Call Signature - -> **emit**(`event`: `"readable"`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"readable"` | - -###### Returns - -`boolean` - -###### Implementation of - -`QuickJS.ReadableStream.emit` - -###### Overrides - -`EventEmitter.emit` - -##### eventNames() - -> **eventNames**(): [`EventKey`](dom-events.md#eventkey)[] - -Returns an array listing the events for which the emitter has registered -listeners. The values in the array are strings or `Symbol`s. - -```js -import { EventEmitter } from 'events'; - -const myEE = new EventEmitter(); -myEE.on('foo', () => {}); -myEE.on('bar', () => {}); - -const sym = Symbol('symbol'); -myEE.on(sym, () => {}); - -console.log(myEE.eventNames()); -// Prints: [ 'foo', 'bar', Symbol(symbol) ] -``` - -###### Returns - -[`EventKey`](dom-events.md#eventkey)[] - -###### Implementation of - -[`ReadableStream`](globals/namespaces/QuickJS.md#readablestream).[`eventNames`](globals/namespaces/QuickJS.md#eventnames) - -###### Inherited from - -[`EventEmitter`](globals/index.md#eventemittert).[`eventNames`](globals/index.md#eventnames) - -##### off() - -> **off**\<`K`\>(`eventName`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Alias for `emitter.removeListener()`. - -###### Type Parameters - -| Type Parameter | -| ------ | -| `K` | - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `eventName` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`ReadableStream`](globals/namespaces/QuickJS.md#readablestream).[`off`](globals/namespaces/QuickJS.md#off) - -###### Inherited from - -[`EventEmitter`](globals/index.md#eventemittert).[`off`](globals/index.md#off) - -##### on() - -###### Call Signature - -> **on**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds the `listener` function to the end of the listeners array for the event -named `eventName`. No checks are made to see if the `listener` has already -been added. Multiple calls passing the same combination of `eventName` and -`listener` will result in the `listener` being added, and called, multiple times. - -```js -server.on('connection', (stream) => { - console.log('someone connected!'); -}); -``` - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the -event listener to the beginning of the listeners array. - -```js -import { EventEmitter } from 'events'; -const myEE = new EventEmitter(); -myEE.on('foo', () => console.log('a')); -myEE.prependListener('foo', () => console.log('b')); -myEE.emit('foo'); -// Prints: -// b -// a -``` - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Implementation of - -[`ReadableStream`](globals/namespaces/QuickJS.md#readablestream).[`on`](globals/namespaces/QuickJS.md#on) - -###### Overrides - -[`EventEmitter`](globals/index.md#eventemittert).[`on`](globals/index.md#on) - -###### Call Signature - -> **on**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.on` - -###### Overrides - -`EventEmitter.on` - -###### Call Signature - -> **on**(`event`: `"data"`, `listener`: (`chunk`: [`Buffer`](buffer.md#buffer)) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"data"` | -| `listener` | (`chunk`: [`Buffer`](buffer.md#buffer)) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.on` - -###### Overrides - -`EventEmitter.on` - -###### Call Signature - -> **on**(`event`: `"end"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"end"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.on` - -###### Overrides - -`EventEmitter.on` - -###### Call Signature - -> **on**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.on` - -###### Overrides - -`EventEmitter.on` - -###### Call Signature - -> **on**(`event`: `"readable"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"readable"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.on` - -###### Overrides - -`EventEmitter.on` - -##### once() - -###### Call Signature - -> **once**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds a **one-time** `listener` function for the event named `eventName`. The -next time `eventName` is triggered, this listener is removed and then invoked. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the -event listener to the beginning of the listeners array. - -```js -import { EventEmitter } from 'events'; -const myEE = new EventEmitter(); -myEE.once('foo', () => console.log('a')); -myEE.prependOnceListener('foo', () => console.log('b')); -myEE.emit('foo'); -// Prints: -// b -// a -``` - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Since - -v0.3.0 - -###### Implementation of - -[`ReadableStream`](globals/namespaces/QuickJS.md#readablestream).[`once`](globals/namespaces/QuickJS.md#once) - -###### Overrides - -[`EventEmitter`](globals/index.md#eventemittert).[`once`](globals/index.md#once) - -###### Call Signature - -> **once**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.once` - -###### Overrides - -`EventEmitter.once` - -###### Call Signature - -> **once**(`event`: `"data"`, `listener`: (`chunk`: [`Buffer`](buffer.md#buffer)) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"data"` | -| `listener` | (`chunk`: [`Buffer`](buffer.md#buffer)) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.once` - -###### Overrides - -`EventEmitter.once` - -###### Call Signature - -> **once**(`event`: `"end"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"end"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.once` - -###### Overrides - -`EventEmitter.once` - -###### Call Signature - -> **once**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.once` - -###### Overrides - -`EventEmitter.once` - -###### Call Signature - -> **once**(`event`: `"readable"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"readable"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.once` - -###### Overrides - -`EventEmitter.once` - -##### prependListener() - -###### Call Signature - -> **prependListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds the `listener` function to the _beginning_ of the listeners array for the -event named `eventName`. No checks are made to see if the `listener` has -already been added. Multiple calls passing the same combination of `eventName` -and `listener` will result in the `listener` being added, and called, multiple times. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Implementation of - -[`ReadableStream`](globals/namespaces/QuickJS.md#readablestream).[`prependListener`](globals/namespaces/QuickJS.md#prependlistener) - -###### Overrides - -[`EventEmitter`](globals/index.md#eventemittert).[`prependListener`](globals/index.md#prependlistener) - -###### Call Signature - -> **prependListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.prependListener` - -###### Overrides - -`EventEmitter.prependListener` - -###### Call Signature - -> **prependListener**(`event`: `"data"`, `listener`: (`chunk`: [`Buffer`](buffer.md#buffer)) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"data"` | -| `listener` | (`chunk`: [`Buffer`](buffer.md#buffer)) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.prependListener` - -###### Overrides - -`EventEmitter.prependListener` - -###### Call Signature - -> **prependListener**(`event`: `"end"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"end"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.prependListener` - -###### Overrides - -`EventEmitter.prependListener` - -###### Call Signature - -> **prependListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.prependListener` - -###### Overrides - -`EventEmitter.prependListener` - -###### Call Signature - -> **prependListener**(`event`: `"readable"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"readable"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.prependListener` - -###### Overrides - -`EventEmitter.prependListener` - -##### prependOnceListener() - -###### Call Signature - -> **prependOnceListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds a **one-time**`listener` function for the event named `eventName` to the _beginning_ of the listeners array. -The next time `eventName` is triggered, this listener is removed, and then invoked. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Implementation of - -[`ReadableStream`](globals/namespaces/QuickJS.md#readablestream).[`prependOnceListener`](globals/namespaces/QuickJS.md#prependoncelistener) - -###### Overrides - -[`EventEmitter`](globals/index.md#eventemittert).[`prependOnceListener`](globals/index.md#prependoncelistener) - -###### Call Signature - -> **prependOnceListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.prependOnceListener` - -###### Overrides - -`EventEmitter.prependOnceListener` - -###### Call Signature - -> **prependOnceListener**(`event`: `"data"`, `listener`: (`chunk`: [`Buffer`](buffer.md#buffer)) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"data"` | -| `listener` | (`chunk`: [`Buffer`](buffer.md#buffer)) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.prependOnceListener` - -###### Overrides - -`EventEmitter.prependOnceListener` - -###### Call Signature - -> **prependOnceListener**(`event`: `"end"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"end"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.prependOnceListener` - -###### Overrides - -`EventEmitter.prependOnceListener` - -###### Call Signature - -> **prependOnceListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.prependOnceListener` - -###### Overrides - -`EventEmitter.prependOnceListener` - -###### Call Signature - -> **prependOnceListener**(`event`: `"readable"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"readable"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.prependOnceListener` - -###### Overrides - -`EventEmitter.prependOnceListener` - -##### read() - -> **read**(`size`?: `number`): `null` \| [`Buffer`](buffer.md#buffer) - -The `readable.read()` method reads data out of the internal buffer and -returns it. If no data is available to be read, `null` is returned. By default, -the data is returned as a `Buffer` object unless an encoding has been -specified using the `readable.setEncoding()` method or the stream is operating -in object mode. - -The optional `size` argument specifies a specific number of bytes to read. If -`size` bytes are not available to be read, `null` will be returned _unless_ the -stream has ended, in which case all of the data remaining in the internal buffer -will be returned. - -If the `size` argument is not specified, all of the data contained in the -internal buffer will be returned. - -The `size` argument must be less than or equal to 1 GiB. - -The `readable.read()` method should only be called on `Readable` streams -operating in paused mode. In flowing mode, `readable.read()` is called -automatically until the internal buffer is fully drained. - -```js -const readable = getReadableStreamSomehow(); - -// 'readable' may be triggered multiple times as data is buffered in -readable.on('readable', () => { - let chunk; - console.log('Stream is readable (new data received in buffer)'); - // Use a loop to make sure we read all currently available data - while (null !== (chunk = readable.read())) { - console.log(`Read ${chunk.length} bytes of data...`); - } -}); - -// 'end' will be triggered once when there is no more data available -readable.on('end', () => { - console.log('Reached end of stream.'); -}); -``` - -Each call to `readable.read()` returns a chunk of data, or `null`. The chunks -are not concatenated. A `while` loop is necessary to consume all data -currently in the buffer. When reading a large file `.read()` may return `null`, -having consumed all buffered content so far, but there is still more data to -come not yet buffered. In this case a new `'readable'` event will be emitted -when there is more data in the buffer. Finally the `'end'` event will be -emitted when there is no more data to come. - -Therefore to read a file's whole contents from a `readable`, it is necessary -to collect chunks across multiple `'readable'` events: - -```js -const chunks = []; - -readable.on('readable', () => { - let chunk; - while (null !== (chunk = readable.read())) { - chunks.push(chunk); - } -}); - -readable.on('end', () => { - const content = chunks.join(''); -}); -``` - -A `Readable` stream in object mode will always return a single item from -a call to `readable.read(size)`, regardless of the value of the `size` argument. - -If the `readable.read()` method returns a chunk of data, a `'data'` event will -also be emitted. - -Calling [read](stream.md#read-2) after the `'end'` event has -been emitted will return `null`. No runtime error will be raised. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `size`? | `number` | Optional argument to specify how much data to read. | - -###### Returns - -`null` \| [`Buffer`](buffer.md#buffer) - -###### Implementation of - -[`ReadableStream`](globals/namespaces/QuickJS.md#readablestream).[`read`](globals/namespaces/QuickJS.md#read) - -##### removeListener() - -###### Call Signature - -> **removeListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Removes the specified `listener` from the listener array for the event named `eventName`. - -`removeListener()` will remove, at most, one instance of a listener from the -listener array. If any single listener has been added multiple times to the -listener array for the specified `eventName`, then `removeListener()` must be -called multiple times to remove each instance. - -Once an event is emitted, all listeners attached to it at the time of emitting are called in order. -This implies that any `removeListener()` calls _after_ emitting and _before_ the last listener finishes execution -will not remove them from `emit()` in progress. Subsequent events behave as expected. - -```js -import { EventEmitter } from 'events'; -class MyEmitter extends EventEmitter {} -const myEmitter = new MyEmitter(); - -const callbackA = () => { - console.log('A'); - myEmitter.removeListener('event', callbackB); -}; - -const callbackB = () => { - console.log('B'); -}; - -myEmitter.on('event', callbackA); - -myEmitter.on('event', callbackB); - -// callbackA removes listener callbackB but it will still be called. -// Internal listener array at time of emit [callbackA, callbackB] -myEmitter.emit('event'); -// Prints: -// A -// B - -// callbackB is now removed. -// Internal listener array [callbackA] -myEmitter.emit('event'); -// Prints: -// A -``` - -Because listeners are managed using an internal array, calling this will -change the position indices of any listener registered _after_ the listener -being removed. This will not impact the order in which listeners are called, -but it means that any copies of the listener array as returned by -the `emitter.listeners()` method will need to be recreated. - -When a single function has been added as a handler multiple times for a single -event (as in the example below), `removeListener()` will remove the most -recently added instance. In the example the `once('ping')` listener is removed: - -```js -import { EventEmitter } from 'events'; -const ee = new EventEmitter(); - -function pong() { - console.log('pong'); -} - -ee.on('ping', pong); -ee.once('ping', pong); -ee.removeListener('ping', pong); - -ee.emit('ping'); -ee.emit('ping'); -``` - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`ReadableStream`](globals/namespaces/QuickJS.md#readablestream).[`removeListener`](globals/namespaces/QuickJS.md#removelistener) - -###### Overrides - -[`EventEmitter`](globals/index.md#eventemittert).[`removeListener`](globals/index.md#removelistener) - -###### Call Signature - -> **removeListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.removeListener` - -###### Overrides - -`EventEmitter.removeListener` - -###### Call Signature - -> **removeListener**(`event`: `"data"`, `listener`: (`chunk`: [`Buffer`](buffer.md#buffer)) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"data"` | -| `listener` | (`chunk`: [`Buffer`](buffer.md#buffer)) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.removeListener` - -###### Overrides - -`EventEmitter.removeListener` - -###### Call Signature - -> **removeListener**(`event`: `"end"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"end"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.removeListener` - -###### Overrides - -`EventEmitter.removeListener` - -###### Call Signature - -> **removeListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.removeListener` - -###### Overrides - -`EventEmitter.removeListener` - -###### Call Signature - -> **removeListener**(`event`: `"readable"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"readable"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.ReadableStream.removeListener` - -###### Overrides - -`EventEmitter.removeListener` - -*** - -### WritableStreamInner - -#### Extends - -- [`EventEmitter`](globals/index.md#eventemittert) - -#### Extended by - -- [`DefaultWritableStream`](stream.md#defaultwritablestream) - -#### Implements - -- [`WritableStream`](globals/namespaces/QuickJS.md#writablestream) - -#### Constructors - -##### new WritableStreamInner() - -> **new WritableStreamInner**(): [`WritableStreamInner`](stream.md#writablestreaminner) - -###### Returns - -[`WritableStreamInner`](stream.md#writablestreaminner) - -###### Inherited from - -[`EventEmitter`](globals/index.md#eventemittert).[`constructor`](globals/index.md#constructors) - -#### Methods - -##### addListener() - -###### Call Signature - -> **addListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. error -3. finish - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`WritableStream`](globals/namespaces/QuickJS.md#writablestream).[`addListener`](globals/namespaces/QuickJS.md#addlistener-1) - -###### Overrides - -[`EventEmitter`](globals/index.md#eventemittert).[`addListener`](globals/index.md#addlistener) - -###### Call Signature - -> **addListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. error -3. finish - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.addListener` - -###### Overrides - -`EventEmitter.addListener` - -###### Call Signature - -> **addListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. error -3. finish - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.addListener` - -###### Overrides - -`EventEmitter.addListener` - -###### Call Signature - -> **addListener**(`event`: `"finish"`, `listener`: () => `void`): `this` - -Event emitter -The defined events on documents including: -1. close -2. error -3. finish - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.addListener` - -###### Overrides - -`EventEmitter.addListener` - -##### emit() - -###### Call Signature - -> **emit**(`event`: [`EventKey`](dom-events.md#eventkey), ...`args`: `any`[]): `boolean` - -Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments -to each. - -```js -import { EventEmitter } from 'events'; -const myEmitter = new EventEmitter(); - -// First listener -myEmitter.on('event', function firstListener() { - console.log('Helloooo! first listener'); -}); -// Second listener -myEmitter.on('event', function secondListener(arg1, arg2) { - console.log(`event with parameters ${arg1}, ${arg2} in second listener`); -}); -// Third listener -myEmitter.on('event', function thirdListener(...args) { - const parameters = args.join(', '); - console.log(`event with parameters ${parameters} in third listener`); -}); - -myEmitter.emit('event', 1, 2, 3, 4, 5); - -// Prints: -// Helloooo! first listener -// event with parameters 1, 2 in second listener -// event with parameters 1, 2, 3, 4, 5 in third listener -``` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| ...`args` | `any`[] | - -###### Returns - -`boolean` - -###### Implementation of - -[`WritableStream`](globals/namespaces/QuickJS.md#writablestream).[`emit`](globals/namespaces/QuickJS.md#emit-1) - -###### Overrides - -[`EventEmitter`](globals/index.md#eventemittert).[`emit`](globals/index.md#emit) - -###### Call Signature - -> **emit**(`event`: `"close"`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | - -###### Returns - -`boolean` - -###### Implementation of - -`QuickJS.WritableStream.emit` - -###### Overrides - -`EventEmitter.emit` - -###### Call Signature - -> **emit**(`event`: `"error"`, `err`: `Error`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `err` | `Error` | - -###### Returns - -`boolean` - -###### Implementation of - -`QuickJS.WritableStream.emit` - -###### Overrides - -`EventEmitter.emit` - -###### Call Signature - -> **emit**(`event`: `"finish"`): `boolean` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | - -###### Returns - -`boolean` - -###### Implementation of - -`QuickJS.WritableStream.emit` - -###### Overrides - -`EventEmitter.emit` - -##### end() - -> **end**(): `this` - -Calling the `writable.end()` method signals that no more data will be written -to the `Writable`. - -Calling the [write](stream.md#write-2) method after calling [end](stream.md#end-2) will raise an error. - -###### Returns - -`this` - -###### Implementation of - -[`WritableStream`](globals/namespaces/QuickJS.md#writablestream).[`end`](globals/namespaces/QuickJS.md#end) - -##### eventNames() - -> **eventNames**(): [`EventKey`](dom-events.md#eventkey)[] - -Returns an array listing the events for which the emitter has registered -listeners. The values in the array are strings or `Symbol`s. - -```js -import { EventEmitter } from 'events'; - -const myEE = new EventEmitter(); -myEE.on('foo', () => {}); -myEE.on('bar', () => {}); - -const sym = Symbol('symbol'); -myEE.on(sym, () => {}); - -console.log(myEE.eventNames()); -// Prints: [ 'foo', 'bar', Symbol(symbol) ] -``` - -###### Returns - -[`EventKey`](dom-events.md#eventkey)[] - -###### Implementation of - -[`WritableStream`](globals/namespaces/QuickJS.md#writablestream).[`eventNames`](globals/namespaces/QuickJS.md#eventnames-1) - -###### Inherited from - -[`EventEmitter`](globals/index.md#eventemittert).[`eventNames`](globals/index.md#eventnames) - -##### off() - -> **off**\<`K`\>(`eventName`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Alias for `emitter.removeListener()`. - -###### Type Parameters - -| Type Parameter | -| ------ | -| `K` | - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `eventName` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`WritableStream`](globals/namespaces/QuickJS.md#writablestream).[`off`](globals/namespaces/QuickJS.md#off-1) - -###### Inherited from - -[`EventEmitter`](globals/index.md#eventemittert).[`off`](globals/index.md#off) - -##### on() - -###### Call Signature - -> **on**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds the `listener` function to the end of the listeners array for the event -named `eventName`. No checks are made to see if the `listener` has already -been added. Multiple calls passing the same combination of `eventName` and -`listener` will result in the `listener` being added, and called, multiple times. - -```js -server.on('connection', (stream) => { - console.log('someone connected!'); -}); -``` - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the -event listener to the beginning of the listeners array. - -```js -import { EventEmitter } from 'events'; -const myEE = new EventEmitter(); -myEE.on('foo', () => console.log('a')); -myEE.prependListener('foo', () => console.log('b')); -myEE.emit('foo'); -// Prints: -// b -// a -``` - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Implementation of - -[`WritableStream`](globals/namespaces/QuickJS.md#writablestream).[`on`](globals/namespaces/QuickJS.md#on-1) - -###### Overrides - -[`EventEmitter`](globals/index.md#eventemittert).[`on`](globals/index.md#on) - -###### Call Signature - -> **on**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.on` - -###### Overrides - -`EventEmitter.on` - -###### Call Signature - -> **on**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.on` - -###### Overrides - -`EventEmitter.on` - -###### Call Signature - -> **on**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.on` - -###### Overrides - -`EventEmitter.on` - -##### once() - -###### Call Signature - -> **once**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds a **one-time** `listener` function for the event named `eventName`. The -next time `eventName` is triggered, this listener is removed and then invoked. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the -event listener to the beginning of the listeners array. - -```js -import { EventEmitter } from 'events'; -const myEE = new EventEmitter(); -myEE.once('foo', () => console.log('a')); -myEE.prependOnceListener('foo', () => console.log('b')); -myEE.emit('foo'); -// Prints: -// b -// a -``` - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Since - -v0.3.0 - -###### Implementation of - -[`WritableStream`](globals/namespaces/QuickJS.md#writablestream).[`once`](globals/namespaces/QuickJS.md#once-1) - -###### Overrides - -[`EventEmitter`](globals/index.md#eventemittert).[`once`](globals/index.md#once) - -###### Call Signature - -> **once**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.once` - -###### Overrides - -`EventEmitter.once` - -###### Call Signature - -> **once**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.once` - -###### Overrides - -`EventEmitter.once` - -###### Call Signature - -> **once**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.once` - -###### Overrides - -`EventEmitter.once` - -##### prependListener() - -###### Call Signature - -> **prependListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds the `listener` function to the _beginning_ of the listeners array for the -event named `eventName`. No checks are made to see if the `listener` has -already been added. Multiple calls passing the same combination of `eventName` -and `listener` will result in the `listener` being added, and called, multiple times. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Implementation of - -[`WritableStream`](globals/namespaces/QuickJS.md#writablestream).[`prependListener`](globals/namespaces/QuickJS.md#prependlistener-1) - -###### Overrides - -[`EventEmitter`](globals/index.md#eventemittert).[`prependListener`](globals/index.md#prependlistener) - -###### Call Signature - -> **prependListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.prependListener` - -###### Overrides - -`EventEmitter.prependListener` - -###### Call Signature - -> **prependListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.prependListener` - -###### Overrides - -`EventEmitter.prependListener` - -###### Call Signature - -> **prependListener**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.prependListener` - -###### Overrides - -`EventEmitter.prependListener` - -##### prependOnceListener() - -###### Call Signature - -> **prependOnceListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Adds a **one-time**`listener` function for the event named `eventName` to the _beginning_ of the listeners array. -The next time `eventName` is triggered, this listener is removed, and then invoked. - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | - | -| `listener` | (...`args`: `any`[]) => `void` | The callback function | - -###### Returns - -`this` - -###### Implementation of - -[`WritableStream`](globals/namespaces/QuickJS.md#writablestream).[`prependOnceListener`](globals/namespaces/QuickJS.md#prependoncelistener-1) - -###### Overrides - -[`EventEmitter`](globals/index.md#eventemittert).[`prependOnceListener`](globals/index.md#prependoncelistener) - -###### Call Signature - -> **prependOnceListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.prependOnceListener` - -###### Overrides - -`EventEmitter.prependOnceListener` - -###### Call Signature - -> **prependOnceListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.prependOnceListener` - -###### Overrides - -`EventEmitter.prependOnceListener` - -###### Call Signature - -> **prependOnceListener**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.prependOnceListener` - -###### Overrides - -`EventEmitter.prependOnceListener` - -##### removeListener() - -###### Call Signature - -> **removeListener**(`event`: [`EventKey`](dom-events.md#eventkey), `listener`: (...`args`: `any`[]) => `void`): `this` - -Removes the specified `listener` from the listener array for the event named `eventName`. - -`removeListener()` will remove, at most, one instance of a listener from the -listener array. If any single listener has been added multiple times to the -listener array for the specified `eventName`, then `removeListener()` must be -called multiple times to remove each instance. - -Once an event is emitted, all listeners attached to it at the time of emitting are called in order. -This implies that any `removeListener()` calls _after_ emitting and _before_ the last listener finishes execution -will not remove them from `emit()` in progress. Subsequent events behave as expected. - -```js -import { EventEmitter } from 'events'; -class MyEmitter extends EventEmitter {} -const myEmitter = new MyEmitter(); - -const callbackA = () => { - console.log('A'); - myEmitter.removeListener('event', callbackB); -}; - -const callbackB = () => { - console.log('B'); -}; - -myEmitter.on('event', callbackA); - -myEmitter.on('event', callbackB); - -// callbackA removes listener callbackB but it will still be called. -// Internal listener array at time of emit [callbackA, callbackB] -myEmitter.emit('event'); -// Prints: -// A -// B - -// callbackB is now removed. -// Internal listener array [callbackA] -myEmitter.emit('event'); -// Prints: -// A -``` - -Because listeners are managed using an internal array, calling this will -change the position indices of any listener registered _after_ the listener -being removed. This will not impact the order in which listeners are called, -but it means that any copies of the listener array as returned by -the `emitter.listeners()` method will need to be recreated. - -When a single function has been added as a handler multiple times for a single -event (as in the example below), `removeListener()` will remove the most -recently added instance. In the example the `once('ping')` listener is removed: - -```js -import { EventEmitter } from 'events'; -const ee = new EventEmitter(); - -function pong() { - console.log('pong'); -} - -ee.on('ping', pong); -ee.once('ping', pong); -ee.removeListener('ping', pong); - -ee.emit('ping'); -ee.emit('ping'); -``` - -Returns a reference to the `EventEmitter`, so that calls can be chained. - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | [`EventKey`](dom-events.md#eventkey) | -| `listener` | (...`args`: `any`[]) => `void` | - -###### Returns - -`this` - -###### Implementation of - -[`WritableStream`](globals/namespaces/QuickJS.md#writablestream).[`removeListener`](globals/namespaces/QuickJS.md#removelistener-1) - -###### Overrides - -[`EventEmitter`](globals/index.md#eventemittert).[`removeListener`](globals/index.md#removelistener) - -###### Call Signature - -> **removeListener**(`event`: `"close"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"close"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.removeListener` - -###### Overrides - -`EventEmitter.removeListener` - -###### Call Signature - -> **removeListener**(`event`: `"error"`, `listener`: (`err`: `Error`) => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"error"` | -| `listener` | (`err`: `Error`) => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.removeListener` - -###### Overrides - -`EventEmitter.removeListener` - -###### Call Signature - -> **removeListener**(`event`: `"finish"`, `listener`: () => `void`): `this` - -###### Parameters - -| Parameter | Type | -| ------ | ------ | -| `event` | `"finish"` | -| `listener` | () => `void` | - -###### Returns - -`this` - -###### Implementation of - -`QuickJS.WritableStream.removeListener` - -###### Overrides - -`EventEmitter.removeListener` - -##### write() - -> **write**(`chunk`: `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](buffer.md#buffer), `callback`?: (`error`?: `null` \| `Error`) => `void`): `void` - -The `writable.write()` method writes some data to the stream, and calls the -supplied `callback` once the data has been fully handled. If an error -occurs, the `callback` will be called with the error as its -first argument. The `callback` is usually called asynchronously and before `'error'` -is emitted. - -```js -function write(data, cb) { - if (!stream.write(data)) { - stream.once('drain', cb); - } else { - process.nextTick(cb); - } -} - -// Wait for cb to be called before doing any other write. -write('hello', () => { - console.log('Write completed, do more writes now.'); -}); -``` - -A `Writable` stream in object mode will always ignore the `encoding` argument. - -###### Parameters - -| Parameter | Type | Description | -| ------ | ------ | ------ | -| `chunk` | `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](buffer.md#buffer) | Optional data to write. `chunk` must be a {string}, {Buffer}, {TypedArray} or {DataView}. | -| `callback`? | (`error`?: `null` \| `Error`) => `void` | Callback for when this chunk of data is flushed. | - -###### Returns - -`void` - -`false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`. - -###### Since - -v0.9.4 - -###### Implementation of - -[`WritableStream`](globals/namespaces/QuickJS.md#writablestream).[`write`](globals/namespaces/QuickJS.md#write) diff --git a/src/reference/modules/llrt/stream/stream.md b/src/reference/modules/llrt/stream/stream.md index 8446777..5ec201b 100644 --- a/src/reference/modules/llrt/stream/stream.md +++ b/src/reference/modules/llrt/stream/stream.md @@ -1091,7 +1091,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ##### write() -> **write**(`chunk`: `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer), `callback?`: (`error?`: `Error` \| `null`) => `void`): `void` +> **write**(`chunk`: `string` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer`, `callback?`: (`error?`: `Error` \| `null`) => `void`): `void` The `writable.write()` method writes some data to the stream, and calls the supplied `callback` once the data has been fully handled. If an error @@ -1120,7 +1120,7 @@ A `Writable` stream in object mode will always ignore the `encoding` argument. | Parameter | Type | Description | | ------ | ------ | ------ | -| `chunk` | `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer) | Optional data to write. `chunk` must be a {string}, {Buffer}, {TypedArray} or {DataView}. | +| `chunk` | `string` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer` | Optional data to write. `chunk` must be a {string}, {Buffer}, {TypedArray} or {DataView}. | | `callback?` | (`error?`: `Error` \| `null`) => `void` | Callback for when this chunk of data is flushed. | ###### Returns @@ -3201,7 +3201,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ##### write() -> **write**(`chunk`: `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer), `callback?`: (`error?`: `Error` \| `null`) => `void`): `void` +> **write**(`chunk`: `string` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer`, `callback?`: (`error?`: `Error` \| `null`) => `void`): `void` The `writable.write()` method writes some data to the stream, and calls the supplied `callback` once the data has been fully handled. If an error @@ -3230,7 +3230,7 @@ A `Writable` stream in object mode will always ignore the `encoding` argument. | Parameter | Type | Description | | ------ | ------ | ------ | -| `chunk` | `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer) | Optional data to write. `chunk` must be a {string}, {Buffer}, {TypedArray} or {DataView}. | +| `chunk` | `string` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer` | Optional data to write. `chunk` must be a {string}, {Buffer}, {TypedArray} or {DataView}. | | `callback?` | (`error?`: `Error` \| `null`) => `void` | Callback for when this chunk of data is flushed. | ###### Returns @@ -3253,7 +3253,7 @@ v0.9.4 #### Extends -- [`EventEmitter`](../globals/index.md#eventemitter) +- [`EventEmitter`](../events.md#eventemitter) #### Extended by @@ -3275,7 +3275,7 @@ v0.9.4 ###### Inherited from -[`EventEmitter`](../globals/index.md#eventemitter).[`constructor`](../globals/index.md#constructor) +[`EventEmitter`](../events.md#eventemitter).[`constructor`](../events.md#constructor) #### Methods @@ -3320,7 +3320,7 @@ The defined events on documents including: ###### Overrides -[`EventEmitter`](../globals/index.md#eventemitter).[`addListener`](../globals/index.md#addlistener) +[`EventEmitter`](../events.md#eventemitter).[`addListener`](../events.md#addlistener) ###### Call Signature @@ -3551,7 +3551,7 @@ myEmitter.emit('event', 1, 2, 3, 4, 5); ###### Overrides -[`EventEmitter`](../globals/index.md#eventemitter).[`emit`](../globals/index.md#emit) +[`EventEmitter`](../events.md#eventemitter).[`emit`](../events.md#emit) ###### Call Signature @@ -3696,7 +3696,7 @@ console.log(myEE.eventNames()); ###### Inherited from -[`EventEmitter`](../globals/index.md#eventemitter).[`eventNames`](../globals/index.md#eventnames) +[`EventEmitter`](../events.md#eventemitter).[`eventNames`](../events.md#eventnames) ##### off() @@ -3727,7 +3727,7 @@ Alias for `emitter.removeListener()`. ###### Inherited from -[`EventEmitter`](../globals/index.md#eventemitter).[`off`](../globals/index.md#off) +[`EventEmitter`](../events.md#eventemitter).[`off`](../events.md#off) ##### on() @@ -3779,7 +3779,7 @@ myEE.emit('foo'); ###### Overrides -[`EventEmitter`](../globals/index.md#eventemitter).[`on`](../globals/index.md#on) +[`EventEmitter`](../events.md#eventemitter).[`on`](../events.md#on) ###### Call Signature @@ -3942,7 +3942,7 @@ v0.3.0 ###### Overrides -[`EventEmitter`](../globals/index.md#eventemitter).[`once`](../globals/index.md#once) +[`EventEmitter`](../events.md#eventemitter).[`once`](../events.md#once) ###### Call Signature @@ -4089,7 +4089,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Overrides -[`EventEmitter`](../globals/index.md#eventemitter).[`prependListener`](../globals/index.md#prependlistener) +[`EventEmitter`](../events.md#eventemitter).[`prependListener`](../events.md#prependlistener) ###### Call Signature @@ -4234,7 +4234,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Overrides -[`EventEmitter`](../globals/index.md#eventemitter).[`prependOnceListener`](../globals/index.md#prependoncelistener) +[`EventEmitter`](../events.md#eventemitter).[`prependOnceListener`](../events.md#prependoncelistener) ###### Call Signature @@ -4537,7 +4537,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Overrides -[`EventEmitter`](../globals/index.md#eventemitter).[`removeListener`](../globals/index.md#removelistener) +[`EventEmitter`](../events.md#eventemitter).[`removeListener`](../events.md#removelistener) ###### Call Signature @@ -4660,7 +4660,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. #### Extends -- [`EventEmitter`](../globals/index.md#eventemitter) +- [`EventEmitter`](../events.md#eventemitter) #### Extended by @@ -4682,7 +4682,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Inherited from -[`EventEmitter`](../globals/index.md#eventemitter).[`constructor`](../globals/index.md#constructor) +[`EventEmitter`](../events.md#eventemitter).[`constructor`](../events.md#constructor) #### Methods @@ -4715,7 +4715,7 @@ The defined events on documents including: ###### Overrides -[`EventEmitter`](../globals/index.md#eventemitter).[`addListener`](../globals/index.md#addlistener) +[`EventEmitter`](../events.md#eventemitter).[`addListener`](../events.md#addlistener) ###### Call Signature @@ -4856,7 +4856,7 @@ myEmitter.emit('event', 1, 2, 3, 4, 5); ###### Overrides -[`EventEmitter`](../globals/index.md#eventemitter).[`emit`](../globals/index.md#emit) +[`EventEmitter`](../events.md#eventemitter).[`emit`](../events.md#emit) ###### Call Signature @@ -4973,7 +4973,7 @@ console.log(myEE.eventNames()); ###### Inherited from -[`EventEmitter`](../globals/index.md#eventemitter).[`eventNames`](../globals/index.md#eventnames) +[`EventEmitter`](../events.md#eventemitter).[`eventNames`](../events.md#eventnames) ##### off() @@ -5004,7 +5004,7 @@ Alias for `emitter.removeListener()`. ###### Inherited from -[`EventEmitter`](../globals/index.md#eventemitter).[`off`](../globals/index.md#off) +[`EventEmitter`](../events.md#eventemitter).[`off`](../events.md#off) ##### on() @@ -5056,7 +5056,7 @@ myEE.emit('foo'); ###### Overrides -[`EventEmitter`](../globals/index.md#eventemitter).[`on`](../globals/index.md#on) +[`EventEmitter`](../events.md#eventemitter).[`on`](../events.md#on) ###### Call Signature @@ -5173,7 +5173,7 @@ v0.3.0 ###### Overrides -[`EventEmitter`](../globals/index.md#eventemitter).[`once`](../globals/index.md#once) +[`EventEmitter`](../events.md#eventemitter).[`once`](../events.md#once) ###### Call Signature @@ -5274,7 +5274,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Overrides -[`EventEmitter`](../globals/index.md#eventemitter).[`prependListener`](../globals/index.md#prependlistener) +[`EventEmitter`](../events.md#eventemitter).[`prependListener`](../events.md#prependlistener) ###### Call Signature @@ -5373,7 +5373,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Overrides -[`EventEmitter`](../globals/index.md#eventemitter).[`prependOnceListener`](../globals/index.md#prependoncelistener) +[`EventEmitter`](../events.md#eventemitter).[`prependOnceListener`](../events.md#prependoncelistener) ###### Call Signature @@ -5538,7 +5538,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ###### Overrides -[`EventEmitter`](../globals/index.md#eventemitter).[`removeListener`](../globals/index.md#removelistener) +[`EventEmitter`](../events.md#eventemitter).[`removeListener`](../events.md#removelistener) ###### Call Signature @@ -5611,7 +5611,7 @@ Returns a reference to the `EventEmitter`, so that calls can be chained. ##### write() -> **write**(`chunk`: `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer), `callback?`: (`error?`: `Error` \| `null`) => `void`): `void` +> **write**(`chunk`: `string` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer`, `callback?`: (`error?`: `Error` \| `null`) => `void`): `void` The `writable.write()` method writes some data to the stream, and calls the supplied `callback` once the data has been fully handled. If an error @@ -5640,7 +5640,7 @@ A `Writable` stream in object mode will always ignore the `encoding` argument. | Parameter | Type | Description | | ------ | ------ | ------ | -| `chunk` | `string` \| `ArrayBuffer` \| `SharedArrayBuffer` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer) | Optional data to write. `chunk` must be a {string}, {Buffer}, {TypedArray} or {DataView}. | +| `chunk` | `string` \| [`ArrayBufferView`](../globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](../buffer.md#buffer) \| `ArrayBuffer` \| `SharedArrayBuffer` | Optional data to write. `chunk` must be a {string}, {Buffer}, {TypedArray} or {DataView}. | | `callback?` | (`error?`: `Error` \| `null`) => `void` | Callback for when this chunk of data is flushed. | ###### Returns diff --git a/src/reference/modules/llrt/stream/web/index.md b/src/reference/modules/llrt/stream/web/index.md new file mode 100644 index 0000000..2d2039c --- /dev/null +++ b/src/reference/modules/llrt/stream/web/index.md @@ -0,0 +1,1231 @@ +[@caido/quickjs-types](../../../index.md) / llrt/stream/web + +# llrt/stream/web + +## Modules + +| Module | Description | +| ------ | ------ | +| [stream/web](stream/web.md) | - | + +## Interfaces + +### ByteLengthQueuingStrategy + +#### Extends + +- [`_ByteLengthQueuingStrategy`](#_bytelengthqueuingstrategy) + +#### Properties + +##### highWaterMark + +> `readonly` **highWaterMark**: `number` + +###### Inherited from + +`_ByteLengthQueuingStrategy.highWaterMark` + +##### size + +> `readonly` **size**: [`QueuingStrategySize`](stream/web.md#queuingstrategysize-1)\<`ArrayBufferView`\> + +###### Inherited from + +`_ByteLengthQueuingStrategy.size` + +*** + +### CountQueuingStrategy + +#### Extends + +- [`_CountQueuingStrategy`](#_countqueuingstrategy) + +#### Properties + +##### highWaterMark + +> `readonly` **highWaterMark**: `number` + +###### Inherited from + +`_CountQueuingStrategy.highWaterMark` + +##### size + +> `readonly` **size**: [`QueuingStrategySize`](stream/web.md#queuingstrategysize-1) + +###### Inherited from + +`_CountQueuingStrategy.size` + +*** + +### ReadableByteStreamController + +#### Extends + +- [`_ReadableByteStreamController`](#_readablebytestreamcontroller) + +#### Properties + +##### byobRequest + +> `readonly` **byobRequest**: `undefined` + +###### Inherited from + +`_ReadableByteStreamController.byobRequest` + +##### desiredSize + +> `readonly` **desiredSize**: `number` \| `null` + +###### Inherited from + +`_ReadableByteStreamController.desiredSize` + +#### Methods + +##### close() + +> **close**(): `void` + +###### Returns + +`void` + +###### Inherited from + +`_ReadableByteStreamController.close` + +##### enqueue() + +> **enqueue**(`chunk`: `ArrayBufferView`): `void` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `chunk` | `ArrayBufferView` | + +###### Returns + +`void` + +###### Inherited from + +`_ReadableByteStreamController.enqueue` + +##### error() + +> **error**(`error?`: `any`): `void` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `error?` | `any` | + +###### Returns + +`void` + +###### Inherited from + +`_ReadableByteStreamController.error` + +*** + +### ReadableStream + +#### Extends + +- [`_ReadableStream`](#_readablestream)\<`R`\> + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `R` | `any` | + +#### Properties + +##### locked + +> `readonly` **locked**: `boolean` + +###### Inherited from + +`_ReadableStream.locked` + +#### Methods + +##### \[asyncIterator\]() + +> **\[asyncIterator\]**(): [`ReadableStreamAsyncIterator`](stream/web.md#readablestreamasynciterator-2)\<`R`\> + +###### Returns + +[`ReadableStreamAsyncIterator`](stream/web.md#readablestreamasynciterator-2)\<`R`\> + +###### Inherited from + +`_ReadableStream.[asyncIterator]` + +##### cancel() + +> **cancel**(`reason?`: `any`): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `reason?` | `any` | + +###### Returns + +`Promise`\<`void`\> + +###### Inherited from + +`_ReadableStream.cancel` + +##### getReader() + +###### Call Signature + +> **getReader**(`options`: `object`): [`ReadableStreamBYOBReader`](stream/web.md#readablestreambyobreader) + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `options` | \{ `mode`: `"byob"`; \} | +| `options.mode` | `"byob"` | + +###### Returns + +[`ReadableStreamBYOBReader`](stream/web.md#readablestreambyobreader) + +###### Inherited from + +`_ReadableStream.getReader` + +###### Call Signature + +> **getReader**(): [`ReadableStreamDefaultReader`](stream/web.md#readablestreamdefaultreader)\<`R`\> + +###### Returns + +[`ReadableStreamDefaultReader`](stream/web.md#readablestreamdefaultreader)\<`R`\> + +###### Inherited from + +`_ReadableStream.getReader` + +###### Call Signature + +> **getReader**(`options?`: [`ReadableStreamGetReaderOptions`](stream/web.md#readablestreamgetreaderoptions)): [`ReadableStreamReader`](stream/web.md#readablestreamreader)\<`R`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `options?` | [`ReadableStreamGetReaderOptions`](stream/web.md#readablestreamgetreaderoptions) | + +###### Returns + +[`ReadableStreamReader`](stream/web.md#readablestreamreader)\<`R`\> + +###### Inherited from + +`_ReadableStream.getReader` + +##### pipeThrough() + +> **pipeThrough**\<`T`\>(`transform`: [`ReadableWritablePair`](stream/web.md#readablewritablepair)\<`T`, `R`\>, `options?`: [`StreamPipeOptions`](stream/web.md#streampipeoptions)): [`ReadableStream`](stream/web.md#readablestream)\<`T`\> + +###### Type Parameters + +| Type Parameter | +| ------ | +| `T` | + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `transform` | [`ReadableWritablePair`](stream/web.md#readablewritablepair)\<`T`, `R`\> | +| `options?` | [`StreamPipeOptions`](stream/web.md#streampipeoptions) | + +###### Returns + +[`ReadableStream`](stream/web.md#readablestream)\<`T`\> + +###### Inherited from + +`_ReadableStream.pipeThrough` + +##### pipeTo() + +> **pipeTo**(`destination`: [`WritableStream`](stream/web.md#writablestream)\<`R`\>, `options?`: [`StreamPipeOptions`](stream/web.md#streampipeoptions)): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `destination` | [`WritableStream`](stream/web.md#writablestream)\<`R`\> | +| `options?` | [`StreamPipeOptions`](stream/web.md#streampipeoptions) | + +###### Returns + +`Promise`\<`void`\> + +###### Inherited from + +`_ReadableStream.pipeTo` + +##### tee() + +> **tee**(): \[[`ReadableStream`](stream/web.md#readablestream)\<`R`\>, [`ReadableStream`](stream/web.md#readablestream)\<`R`\>\] + +###### Returns + +\[[`ReadableStream`](stream/web.md#readablestream)\<`R`\>, [`ReadableStream`](stream/web.md#readablestream)\<`R`\>\] + +###### Inherited from + +`_ReadableStream.tee` + +##### values() + +> **values**(`options?`: `object`): [`ReadableStreamAsyncIterator`](stream/web.md#readablestreamasynciterator-2)\<`R`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `options?` | \{ `preventCancel?`: `boolean`; \} | +| `options.preventCancel?` | `boolean` | + +###### Returns + +[`ReadableStreamAsyncIterator`](stream/web.md#readablestreamasynciterator-2)\<`R`\> + +###### Inherited from + +`_ReadableStream.values` + +*** + +### ReadableStreamBYOBReader + +#### Extends + +- [`_ReadableStreamBYOBReader`](#_readablestreambyobreader) + +#### Properties + +##### closed + +> `readonly` **closed**: `Promise`\<`undefined`\> + +###### Inherited from + +`_ReadableStreamBYOBReader.closed` + +#### Methods + +##### cancel() + +> **cancel**(`reason?`: `any`): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `reason?` | `any` | + +###### Returns + +`Promise`\<`void`\> + +###### Inherited from + +`_ReadableStreamBYOBReader.cancel` + +##### read() + +> **read**\<`T`\>(`view`: `T`): `Promise`\<[`ReadableStreamReadResult`](stream/web.md#readablestreamreadresult)\<`T`\>\> + +[MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/read) + +###### Type Parameters + +| Type Parameter | +| ------ | +| `T` *extends* `ArrayBufferView` | + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `view` | `T` | + +###### Returns + +`Promise`\<[`ReadableStreamReadResult`](stream/web.md#readablestreamreadresult)\<`T`\>\> + +###### Inherited from + +`_ReadableStreamBYOBReader.read` + +##### releaseLock() + +> **releaseLock**(): `void` + +[MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/releaseLock) + +###### Returns + +`void` + +###### Inherited from + +`_ReadableStreamBYOBReader.releaseLock` + +*** + +### ReadableStreamBYOBRequest + +#### Extends + +- [`_ReadableStreamBYOBRequest`](#_readablestreambyobrequest) + +#### Properties + +##### view + +> `readonly` **view**: `ArrayBufferView` \| `null` + +[MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest/view) + +###### Inherited from + +`_ReadableStreamBYOBRequest.view` + +#### Methods + +##### respond() + +> **respond**(`bytesWritten`: `number`): `void` + +[MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest/respond) + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `bytesWritten` | `number` | + +###### Returns + +`void` + +###### Inherited from + +`_ReadableStreamBYOBRequest.respond` + +##### respondWithNewView() + +> **respondWithNewView**(`view`: `ArrayBufferView`): `void` + +[MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest/respondWithNewView) + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `view` | `ArrayBufferView` | + +###### Returns + +`void` + +###### Inherited from + +`_ReadableStreamBYOBRequest.respondWithNewView` + +*** + +### ReadableStreamDefaultController + +#### Extends + +- [`_ReadableStreamDefaultController`](#_readablestreamdefaultcontroller)\<`R`\> + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `R` | `any` | + +#### Properties + +##### desiredSize + +> `readonly` **desiredSize**: `number` \| `null` + +###### Inherited from + +`_ReadableStreamDefaultController.desiredSize` + +#### Methods + +##### close() + +> **close**(): `void` + +###### Returns + +`void` + +###### Inherited from + +`_ReadableStreamDefaultController.close` + +##### enqueue() + +> **enqueue**(`chunk?`: `R`): `void` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `chunk?` | `R` | + +###### Returns + +`void` + +###### Inherited from + +`_ReadableStreamDefaultController.enqueue` + +##### error() + +> **error**(`e?`: `any`): `void` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `e?` | `any` | + +###### Returns + +`void` + +###### Inherited from + +`_ReadableStreamDefaultController.error` + +*** + +### ReadableStreamDefaultReader + +#### Extends + +- [`_ReadableStreamDefaultReader`](#_readablestreamdefaultreader)\<`R`\> + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `R` | `any` | + +#### Properties + +##### closed + +> `readonly` **closed**: `Promise`\<`undefined`\> + +###### Inherited from + +`_ReadableStreamDefaultReader.closed` + +#### Methods + +##### cancel() + +> **cancel**(`reason?`: `any`): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `reason?` | `any` | + +###### Returns + +`Promise`\<`void`\> + +###### Inherited from + +`_ReadableStreamDefaultReader.cancel` + +##### read() + +> **read**(): `Promise`\<[`ReadableStreamReadResult`](stream/web.md#readablestreamreadresult)\<`R`\>\> + +###### Returns + +`Promise`\<[`ReadableStreamReadResult`](stream/web.md#readablestreamreadresult)\<`R`\>\> + +###### Inherited from + +`_ReadableStreamDefaultReader.read` + +##### releaseLock() + +> **releaseLock**(): `void` + +###### Returns + +`void` + +###### Inherited from + +`_ReadableStreamDefaultReader.releaseLock` + +*** + +### WritableStream + +#### Extends + +- [`_WritableStream`](#_writablestream)\<`W`\> + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `W` | `any` | + +#### Properties + +##### locked + +> `readonly` **locked**: `boolean` + +###### Inherited from + +`_WritableStream.locked` + +#### Methods + +##### abort() + +> **abort**(`reason?`: `any`): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `reason?` | `any` | + +###### Returns + +`Promise`\<`void`\> + +###### Inherited from + +`_WritableStream.abort` + +##### close() + +> **close**(): `Promise`\<`void`\> + +###### Returns + +`Promise`\<`void`\> + +###### Inherited from + +`_WritableStream.close` + +##### getWriter() + +> **getWriter**(): [`WritableStreamDefaultWriter`](stream/web.md#writablestreamdefaultwriter)\<`W`\> + +###### Returns + +[`WritableStreamDefaultWriter`](stream/web.md#writablestreamdefaultwriter)\<`W`\> + +###### Inherited from + +`_WritableStream.getWriter` + +*** + +### WritableStreamDefaultController + +#### Extends + +- [`_WritableStreamDefaultController`](#_writablestreamdefaultcontroller) + +#### Methods + +##### error() + +> **error**(`e?`: `any`): `void` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `e?` | `any` | + +###### Returns + +`void` + +###### Inherited from + +`_WritableStreamDefaultController.error` + +*** + +### WritableStreamDefaultWriter + +#### Extends + +- [`_WritableStreamDefaultWriter`](#_writablestreamdefaultwriter)\<`W`\> + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `W` | `any` | + +#### Properties + +##### closed + +> `readonly` **closed**: `Promise`\<`undefined`\> + +###### Inherited from + +`_WritableStreamDefaultWriter.closed` + +##### desiredSize + +> `readonly` **desiredSize**: `number` \| `null` + +###### Inherited from + +`_WritableStreamDefaultWriter.desiredSize` + +##### ready + +> `readonly` **ready**: `Promise`\<`undefined`\> + +###### Inherited from + +`_WritableStreamDefaultWriter.ready` + +#### Methods + +##### abort() + +> **abort**(`reason?`: `any`): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `reason?` | `any` | + +###### Returns + +`Promise`\<`void`\> + +###### Inherited from + +`_WritableStreamDefaultWriter.abort` + +##### close() + +> **close**(): `Promise`\<`void`\> + +###### Returns + +`Promise`\<`void`\> + +###### Inherited from + +`_WritableStreamDefaultWriter.close` + +##### releaseLock() + +> **releaseLock**(): `void` + +###### Returns + +`void` + +###### Inherited from + +`_WritableStreamDefaultWriter.releaseLock` + +##### write() + +> **write**(`chunk?`: `W`): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `chunk?` | `W` | + +###### Returns + +`Promise`\<`void`\> + +###### Inherited from + +`_WritableStreamDefaultWriter.write` + +## Type Aliases + +### \_ByteLengthQueuingStrategy + +> **\_ByteLengthQueuingStrategy** = *typeof* `globalThis` *extends* `object` ? `object` : [`ByteLengthQueuingStrategy`](stream/web.md#bytelengthqueuingstrategy) + +*** + +### \_CountQueuingStrategy + +> **\_CountQueuingStrategy** = *typeof* `globalThis` *extends* `object` ? `object` : [`CountQueuingStrategy`](stream/web.md#countqueuingstrategy) + +*** + +### \_ReadableByteStreamController + +> **\_ReadableByteStreamController** = *typeof* `globalThis` *extends* `object` ? `object` : [`ReadableByteStreamController`](stream/web.md#readablebytestreamcontroller) + +*** + +### \_ReadableStream + +> **\_ReadableStream**\<`R`\> = *typeof* `globalThis` *extends* `object` ? `object` : [`ReadableStream`](stream/web.md#readablestream) + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `R` | `any` | + +*** + +### \_ReadableStreamBYOBReader + +> **\_ReadableStreamBYOBReader** = *typeof* `globalThis` *extends* `object` ? `object` : [`ReadableStreamBYOBReader`](stream/web.md#readablestreambyobreader) + +*** + +### \_ReadableStreamBYOBRequest + +> **\_ReadableStreamBYOBRequest** = *typeof* `globalThis` *extends* `object` ? `object` : [`ReadableStreamBYOBRequest`](stream/web.md#readablestreambyobrequest) + +*** + +### \_ReadableStreamDefaultController + +> **\_ReadableStreamDefaultController**\<`R`\> = *typeof* `globalThis` *extends* `object` ? `object` : [`ReadableStreamDefaultController`](stream/web.md#readablestreamdefaultcontroller) + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `R` | `any` | + +*** + +### \_ReadableStreamDefaultReader + +> **\_ReadableStreamDefaultReader**\<`R`\> = *typeof* `globalThis` *extends* `object` ? `object` : [`ReadableStreamDefaultReader`](stream/web.md#readablestreamdefaultreader) + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `R` | `any` | + +*** + +### \_WritableStream + +> **\_WritableStream**\<`W`\> = *typeof* `globalThis` *extends* `object` ? `object` : [`WritableStream`](stream/web.md#writablestream) + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `W` | `any` | + +*** + +### \_WritableStreamDefaultController + +> **\_WritableStreamDefaultController** = *typeof* `globalThis` *extends* `object` ? `object` : [`WritableStreamDefaultController`](stream/web.md#writablestreamdefaultcontroller) + +*** + +### \_WritableStreamDefaultWriter + +> **\_WritableStreamDefaultWriter**\<`W`\> = *typeof* `globalThis` *extends* `object` ? `object` : [`WritableStreamDefaultWriter`](stream/web.md#writablestreamdefaultwriter) + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `W` | `any` | + +## Variables + +### ByteLengthQueuingStrategy + +> **ByteLengthQueuingStrategy**: \{(`init`: [`QueuingStrategyInit`](stream/web.md#queuingstrategyinit)): [`ByteLengthQueuingStrategy`](stream/web.md#bytelengthqueuingstrategy); `prototype`: [`ByteLengthQueuingStrategy`](stream/web.md#bytelengthqueuingstrategy); \} + +`ByteLengthQueuingStrategy` class is a global reference for `import { ByteLengthQueuingStrategy } from 'stream/web'`. +https://nodejs.org/api/globals.html#class-bytelengthqueuingstrategy + +#### Type Declaration + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `init` | [`QueuingStrategyInit`](stream/web.md#queuingstrategyinit) | + +#### Returns + +[`ByteLengthQueuingStrategy`](stream/web.md#bytelengthqueuingstrategy) + +##### prototype + +> **prototype**: [`ByteLengthQueuingStrategy`](stream/web.md#bytelengthqueuingstrategy) + +#### Since + +v18.0.0 + +*** + +### CountQueuingStrategy + +> **CountQueuingStrategy**: \{(`init`: [`QueuingStrategyInit`](stream/web.md#queuingstrategyinit)): [`CountQueuingStrategy`](stream/web.md#countqueuingstrategy); `prototype`: [`CountQueuingStrategy`](stream/web.md#countqueuingstrategy); \} + +`CountQueuingStrategy` class is a global reference for `import { CountQueuingStrategy } from 'stream/web'`. +https://nodejs.org/api/globals.html#class-countqueuingstrategy + +#### Type Declaration + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `init` | [`QueuingStrategyInit`](stream/web.md#queuingstrategyinit) | + +#### Returns + +[`CountQueuingStrategy`](stream/web.md#countqueuingstrategy) + +##### prototype + +> **prototype**: [`CountQueuingStrategy`](stream/web.md#countqueuingstrategy) + +#### Since + +v18.0.0 + +*** + +### ReadableByteStreamController + +> **ReadableByteStreamController**: \{(): [`ReadableByteStreamController`](stream/web.md#readablebytestreamcontroller); `prototype`: [`ReadableByteStreamController`](stream/web.md#readablebytestreamcontroller); \} + +`ReadableByteStreamController` class is a global reference for `import { ReadableByteStreamController } from 'stream/web'`. +https://nodejs.org/api/globals.html#class-readablebytestreamcontroller + +#### Type Declaration + +#### Returns + +[`ReadableByteStreamController`](stream/web.md#readablebytestreamcontroller) + +##### prototype + +> **prototype**: [`ReadableByteStreamController`](stream/web.md#readablebytestreamcontroller) + +#### Since + +v18.0.0 + +*** + +### ReadableStream + +> **ReadableStream**: \{(`underlyingSource`: [`UnderlyingByteSource`](stream/web.md#underlyingbytesource), `strategy?`: [`QueuingStrategy`](stream/web.md#queuingstrategy)\<`Uint8Array`\>): [`ReadableStream`](stream/web.md#readablestream)\<`Uint8Array`\>; \<`R`\>(`underlyingSource?`: [`UnderlyingSource`](stream/web.md#underlyingsource)\<`R`\>, `strategy?`: [`QueuingStrategy`](stream/web.md#queuingstrategy)\<`R`\>): [`ReadableStream`](stream/web.md#readablestream)\<`R`\>; `prototype`: [`ReadableStream`](stream/web.md#readablestream); `from`: [`ReadableStream`](stream/web.md#readablestream)\<`T`\>; \} + +`ReadableStream` class is a global reference for `import { ReadableStream } from 'stream/web'`. +https://nodejs.org/api/globals.html#class-readablestream + +#### Type Declaration + +#### Call Signature + +> **new ReadableStream**(`underlyingSource`: [`UnderlyingByteSource`](stream/web.md#underlyingbytesource), `strategy?`: [`QueuingStrategy`](stream/web.md#queuingstrategy)\<`Uint8Array`\>): [`ReadableStream`](stream/web.md#readablestream)\<`Uint8Array`\> + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `underlyingSource` | [`UnderlyingByteSource`](stream/web.md#underlyingbytesource) | +| `strategy?` | [`QueuingStrategy`](stream/web.md#queuingstrategy)\<`Uint8Array`\> | + +##### Returns + +[`ReadableStream`](stream/web.md#readablestream)\<`Uint8Array`\> + +#### Call Signature + +> **new ReadableStream**\<`R`\>(`underlyingSource?`: [`UnderlyingSource`](stream/web.md#underlyingsource)\<`R`\>, `strategy?`: [`QueuingStrategy`](stream/web.md#queuingstrategy)\<`R`\>): [`ReadableStream`](stream/web.md#readablestream)\<`R`\> + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `underlyingSource?` | [`UnderlyingSource`](stream/web.md#underlyingsource)\<`R`\> | +| `strategy?` | [`QueuingStrategy`](stream/web.md#queuingstrategy)\<`R`\> | + +##### Returns + +[`ReadableStream`](stream/web.md#readablestream)\<`R`\> + +##### prototype + +> **prototype**: [`ReadableStream`](stream/web.md#readablestream) + +##### from() + +> **from**\<`T`\>(`iterable`: `Iterable`\<`T`, `any`, `any`\> \| `AsyncIterable`\<`T`, `any`, `any`\>): [`ReadableStream`](stream/web.md#readablestream)\<`T`\> + +###### Type Parameters + +| Type Parameter | +| ------ | +| `T` | + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `iterable` | `Iterable`\<`T`, `any`, `any`\> \| `AsyncIterable`\<`T`, `any`, `any`\> | + +###### Returns + +[`ReadableStream`](stream/web.md#readablestream)\<`T`\> + +#### Since + +v18.0.0 + +*** + +### ReadableStreamBYOBReader + +> **ReadableStreamBYOBReader**: \{(`stream`: [`ReadableStream`](stream/web.md#readablestream)): [`ReadableStreamBYOBReader`](stream/web.md#readablestreambyobreader); `prototype`: [`ReadableStreamBYOBReader`](stream/web.md#readablestreambyobreader); \} + +`ReadableStreamBYOBReader` class is a global reference for `import { ReadableStreamBYOBReader } from 'stream/web'`. +https://nodejs.org/api/globals.html#class-readablestreambyobreader + +#### Type Declaration + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `stream` | [`ReadableStream`](stream/web.md#readablestream) | + +#### Returns + +[`ReadableStreamBYOBReader`](stream/web.md#readablestreambyobreader) + +##### prototype + +> **prototype**: [`ReadableStreamBYOBReader`](stream/web.md#readablestreambyobreader) + +#### Since + +v18.0.0 + +*** + +### ReadableStreamBYOBRequest + +> **ReadableStreamBYOBRequest**: \{(): [`ReadableStreamBYOBRequest`](stream/web.md#readablestreambyobrequest); `prototype`: [`ReadableStreamBYOBRequest`](stream/web.md#readablestreambyobrequest); \} + +`ReadableStreamBYOBRequest` class is a global reference for `import { ReadableStreamBYOBRequest } from 'stream/web'`. +https://nodejs.org/api/globals.html#class-readablestreambyobrequest + +#### Type Declaration + +#### Returns + +[`ReadableStreamBYOBRequest`](stream/web.md#readablestreambyobrequest) + +##### prototype + +> **prototype**: [`ReadableStreamBYOBRequest`](stream/web.md#readablestreambyobrequest) + +#### Since + +v18.0.0 + +*** + +### ReadableStreamDefaultController + +> **ReadableStreamDefaultController**: \{(): [`ReadableStreamDefaultController`](stream/web.md#readablestreamdefaultcontroller); `prototype`: [`ReadableStreamDefaultController`](stream/web.md#readablestreamdefaultcontroller); \} + +`ReadableStreamDefaultController` class is a global reference for `import { ReadableStreamDefaultController } from 'stream/web'`. +https://nodejs.org/api/globals.html#class-readablestreamdefaultcontroller + +#### Type Declaration + +#### Returns + +[`ReadableStreamDefaultController`](stream/web.md#readablestreamdefaultcontroller) + +##### prototype + +> **prototype**: [`ReadableStreamDefaultController`](stream/web.md#readablestreamdefaultcontroller) + +#### Since + +v18.0.0 + +*** + +### ReadableStreamDefaultReader + +> **ReadableStreamDefaultReader**: \{\<`R`\>(`stream`: [`ReadableStream`](stream/web.md#readablestream)\<`R`\>): [`ReadableStreamDefaultReader`](stream/web.md#readablestreamdefaultreader)\<`R`\>; `prototype`: [`ReadableStreamDefaultReader`](stream/web.md#readablestreamdefaultreader); \} + +`ReadableStreamDefaultReader` class is a global reference for `import { ReadableStreamDefaultReader } from 'stream/web'`. +https://nodejs.org/api/globals.html#class-readablestreamdefaultreader + +#### Type Declaration + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `stream` | [`ReadableStream`](stream/web.md#readablestream)\<`R`\> | + +#### Returns + +[`ReadableStreamDefaultReader`](stream/web.md#readablestreamdefaultreader)\<`R`\> + +##### prototype + +> **prototype**: [`ReadableStreamDefaultReader`](stream/web.md#readablestreamdefaultreader) + +#### Since + +v18.0.0 + +*** + +### WritableStream + +> **WritableStream**: \{\<`W`\>(`underlyingSink?`: [`UnderlyingSink`](stream/web.md#underlyingsink)\<`W`\>, `strategy?`: [`QueuingStrategy`](stream/web.md#queuingstrategy)\<`W`\>): [`WritableStream`](stream/web.md#writablestream)\<`W`\>; `prototype`: [`WritableStream`](stream/web.md#writablestream); \} + +`WritableStream` class is a global reference for `import { WritableStream } from 'stream/web'`. +https://nodejs.org/api/globals.html#class-writablestream + +#### Type Declaration + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `underlyingSink?` | [`UnderlyingSink`](stream/web.md#underlyingsink)\<`W`\> | +| `strategy?` | [`QueuingStrategy`](stream/web.md#queuingstrategy)\<`W`\> | + +#### Returns + +[`WritableStream`](stream/web.md#writablestream)\<`W`\> + +##### prototype + +> **prototype**: [`WritableStream`](stream/web.md#writablestream) + +#### Since + +v18.0.0 + +*** + +### WritableStreamDefaultController + +> **WritableStreamDefaultController**: \{(): [`WritableStreamDefaultController`](stream/web.md#writablestreamdefaultcontroller); `prototype`: [`WritableStreamDefaultController`](stream/web.md#writablestreamdefaultcontroller); \} + +`WritableStreamDefaultController` class is a global reference for `import { WritableStreamDefaultController } from 'stream/web'`. +https://nodejs.org/api/globals.html#class-writablestreamdefaultcontroller + +#### Type Declaration + +#### Returns + +[`WritableStreamDefaultController`](stream/web.md#writablestreamdefaultcontroller) + +##### prototype + +> **prototype**: [`WritableStreamDefaultController`](stream/web.md#writablestreamdefaultcontroller) + +#### Since + +v18.0.0 + +*** + +### WritableStreamDefaultWriter + +> **WritableStreamDefaultWriter**: \{\<`W`\>(`stream`: [`WritableStream`](stream/web.md#writablestream)\<`W`\>): [`WritableStreamDefaultWriter`](stream/web.md#writablestreamdefaultwriter)\<`W`\>; `prototype`: [`WritableStreamDefaultWriter`](stream/web.md#writablestreamdefaultwriter); \} + +`WritableStreamDefaultWriter` class is a global reference for `import { WritableStreamDefaultWriter } from 'stream/web'`. +https://nodejs.org/api/globals.html#class-writablestreamdefaultwriter + +#### Type Declaration + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `stream` | [`WritableStream`](stream/web.md#writablestream)\<`W`\> | + +#### Returns + +[`WritableStreamDefaultWriter`](stream/web.md#writablestreamdefaultwriter)\<`W`\> + +##### prototype + +> **prototype**: [`WritableStreamDefaultWriter`](stream/web.md#writablestreamdefaultwriter) + +#### Since + +v18.0.0 diff --git a/src/reference/modules/llrt/stream/web/stream/web.md b/src/reference/modules/llrt/stream/web/stream/web.md new file mode 100644 index 0000000..4d5b44b --- /dev/null +++ b/src/reference/modules/llrt/stream/web/stream/web.md @@ -0,0 +1,1452 @@ +[@caido/quickjs-types](../../../../index.md) / [llrt/stream/web](../index.md) / stream/web + +# stream/web + +## Interfaces + +### ByteLengthQueuingStrategy + +This Streams API interface provides a built-in byte length queuing +strategy that can be used when constructing streams. + +#### Extends + +- [`QueuingStrategy`](#queuingstrategy)\<`ArrayBufferView`\> + +#### Properties + +##### highWaterMark + +> `readonly` **highWaterMark**: `number` + +###### Overrides + +[`QueuingStrategy`](#queuingstrategy).[`highWaterMark`](#highwatermark-2) + +##### size + +> `readonly` **size**: [`QueuingStrategySize`](#queuingstrategysize-1)\<`ArrayBufferView`\> + +###### Overrides + +[`QueuingStrategy`](#queuingstrategy).[`size`](#size-2) + +*** + +### CountQueuingStrategy + +This Streams API interface provides a built-in byte length queuing +strategy that can be used when constructing streams. + +#### Extends + +- [`QueuingStrategy`](#queuingstrategy) + +#### Properties + +##### highWaterMark + +> `readonly` **highWaterMark**: `number` + +###### Overrides + +[`QueuingStrategy`](#queuingstrategy).[`highWaterMark`](#highwatermark-2) + +##### size + +> `readonly` **size**: [`QueuingStrategySize`](#queuingstrategysize-1) + +###### Overrides + +[`QueuingStrategy`](#queuingstrategy).[`size`](#size-2) + +*** + +### QueuingStrategy + +#### Extended by + +- [`ByteLengthQueuingStrategy`](#bytelengthqueuingstrategy) +- [`CountQueuingStrategy`](#countqueuingstrategy) + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `T` | `any` | + +#### Properties + +##### highWaterMark? + +> `optional` **highWaterMark**: `number` + +##### size? + +> `optional` **size**: [`QueuingStrategySize`](#queuingstrategysize-1)\<`T`\> + +*** + +### QueuingStrategyInit + +#### Properties + +##### highWaterMark + +> **highWaterMark**: `number` + +Creates a new ByteLengthQueuingStrategy with the provided high water +mark. + +Note that the provided high water mark will not be validated ahead of +time. Instead, if it is negative, NaN, or not a number, the resulting +ByteLengthQueuingStrategy will cause the corresponding stream +constructor to throw. + +*** + +### QueuingStrategySize() + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `T` | `any` | + +> **QueuingStrategySize**(`chunk?`: `T`): `number` + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `chunk?` | `T` | + +#### Returns + +`number` + +*** + +### ReadableByteStreamController + +#### Properties + +##### byobRequest + +> `readonly` **byobRequest**: `undefined` + +##### desiredSize + +> `readonly` **desiredSize**: `number` \| `null` + +#### Methods + +##### close() + +> **close**(): `void` + +###### Returns + +`void` + +##### enqueue() + +> **enqueue**(`chunk`: `ArrayBufferView`): `void` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `chunk` | `ArrayBufferView` | + +###### Returns + +`void` + +##### error() + +> **error**(`error?`: `any`): `void` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `error?` | `any` | + +###### Returns + +`void` + +*** + +### ReadableByteStreamControllerCallback() + +> **ReadableByteStreamControllerCallback**(`controller`: [`ReadableByteStreamController`](#readablebytestreamcontroller)): `void` \| `PromiseLike`\<`void`\> + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `controller` | [`ReadableByteStreamController`](#readablebytestreamcontroller) | + +#### Returns + +`void` \| `PromiseLike`\<`void`\> + +*** + +### ReadableStream + +This Streams API interface represents a readable stream of byte data. + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `R` | `any` | + +#### Properties + +##### locked + +> `readonly` **locked**: `boolean` + +#### Methods + +##### \[asyncIterator\]() + +> **\[asyncIterator\]**(): [`ReadableStreamAsyncIterator`](#readablestreamasynciterator-2)\<`R`\> + +###### Returns + +[`ReadableStreamAsyncIterator`](#readablestreamasynciterator-2)\<`R`\> + +##### cancel() + +> **cancel**(`reason?`: `any`): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `reason?` | `any` | + +###### Returns + +`Promise`\<`void`\> + +##### getReader() + +###### Call Signature + +> **getReader**(`options`: `object`): [`ReadableStreamBYOBReader`](#readablestreambyobreader) + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `options` | \{ `mode`: `"byob"`; \} | +| `options.mode` | `"byob"` | + +###### Returns + +[`ReadableStreamBYOBReader`](#readablestreambyobreader) + +###### Call Signature + +> **getReader**(): [`ReadableStreamDefaultReader`](#readablestreamdefaultreader)\<`R`\> + +###### Returns + +[`ReadableStreamDefaultReader`](#readablestreamdefaultreader)\<`R`\> + +###### Call Signature + +> **getReader**(`options?`: [`ReadableStreamGetReaderOptions`](#readablestreamgetreaderoptions)): [`ReadableStreamReader`](#readablestreamreader)\<`R`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `options?` | [`ReadableStreamGetReaderOptions`](#readablestreamgetreaderoptions) | + +###### Returns + +[`ReadableStreamReader`](#readablestreamreader)\<`R`\> + +##### pipeThrough() + +> **pipeThrough**\<`T`\>(`transform`: [`ReadableWritablePair`](#readablewritablepair)\<`T`, `R`\>, `options?`: [`StreamPipeOptions`](#streampipeoptions)): [`ReadableStream`](#readablestream)\<`T`\> + +###### Type Parameters + +| Type Parameter | +| ------ | +| `T` | + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `transform` | [`ReadableWritablePair`](#readablewritablepair)\<`T`, `R`\> | +| `options?` | [`StreamPipeOptions`](#streampipeoptions) | + +###### Returns + +[`ReadableStream`](#readablestream)\<`T`\> + +##### pipeTo() + +> **pipeTo**(`destination`: [`WritableStream`](#writablestream)\<`R`\>, `options?`: [`StreamPipeOptions`](#streampipeoptions)): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `destination` | [`WritableStream`](#writablestream)\<`R`\> | +| `options?` | [`StreamPipeOptions`](#streampipeoptions) | + +###### Returns + +`Promise`\<`void`\> + +##### tee() + +> **tee**(): \[[`ReadableStream`](#readablestream)\<`R`\>, [`ReadableStream`](#readablestream)\<`R`\>\] + +###### Returns + +\[[`ReadableStream`](#readablestream)\<`R`\>, [`ReadableStream`](#readablestream)\<`R`\>\] + +##### values() + +> **values**(`options?`: `object`): [`ReadableStreamAsyncIterator`](#readablestreamasynciterator-2)\<`R`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `options?` | \{ `preventCancel?`: `boolean`; \} | +| `options.preventCancel?` | `boolean` | + +###### Returns + +[`ReadableStreamAsyncIterator`](#readablestreamasynciterator-2)\<`R`\> + +*** + +### ReadableStreamAsyncIterator + +#### Extends + +- `AsyncIterableIterator`\<`T`\> + +#### Type Parameters + +| Type Parameter | +| ------ | +| `T` | + +#### Methods + +##### \[asyncIterator\]() + +> **\[asyncIterator\]**(): [`ReadableStreamAsyncIterator`](#readablestreamasynciterator-2)\<`T`\> + +###### Returns + +[`ReadableStreamAsyncIterator`](#readablestreamasynciterator-2)\<`T`\> + +###### Overrides + +`AsyncIterableIterator.[asyncIterator]` + +*** + +### ReadableStreamBYOBReader + +[MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader) + +#### Extends + +- [`ReadableStreamGenericReader`](#readablestreamgenericreader) + +#### Properties + +##### closed + +> `readonly` **closed**: `Promise`\<`undefined`\> + +###### Inherited from + +[`ReadableStreamGenericReader`](#readablestreamgenericreader).[`closed`](#closed-2) + +#### Methods + +##### cancel() + +> **cancel**(`reason?`: `any`): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `reason?` | `any` | + +###### Returns + +`Promise`\<`void`\> + +###### Inherited from + +[`ReadableStreamGenericReader`](#readablestreamgenericreader).[`cancel`](#cancel-6) + +##### read() + +> **read**\<`T`\>(`view`: `T`): `Promise`\<[`ReadableStreamReadResult`](#readablestreamreadresult)\<`T`\>\> + +[MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/read) + +###### Type Parameters + +| Type Parameter | +| ------ | +| `T` *extends* `ArrayBufferView` | + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `view` | `T` | + +###### Returns + +`Promise`\<[`ReadableStreamReadResult`](#readablestreamreadresult)\<`T`\>\> + +##### releaseLock() + +> **releaseLock**(): `void` + +[MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/releaseLock) + +###### Returns + +`void` + +*** + +### ReadableStreamBYOBRequest + +[MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest) + +#### Properties + +##### view + +> `readonly` **view**: `ArrayBufferView` \| `null` + +[MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest/view) + +#### Methods + +##### respond() + +> **respond**(`bytesWritten`: `number`): `void` + +[MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest/respond) + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `bytesWritten` | `number` | + +###### Returns + +`void` + +##### respondWithNewView() + +> **respondWithNewView**(`view`: `ArrayBufferView`): `void` + +[MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest/respondWithNewView) + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `view` | `ArrayBufferView` | + +###### Returns + +`void` + +*** + +### ReadableStreamDefaultController + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `R` | `any` | + +#### Properties + +##### desiredSize + +> `readonly` **desiredSize**: `number` \| `null` + +#### Methods + +##### close() + +> **close**(): `void` + +###### Returns + +`void` + +##### enqueue() + +> **enqueue**(`chunk?`: `R`): `void` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `chunk?` | `R` | + +###### Returns + +`void` + +##### error() + +> **error**(`e?`: `any`): `void` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `e?` | `any` | + +###### Returns + +`void` + +*** + +### ReadableStreamDefaultReader + +#### Extends + +- [`ReadableStreamGenericReader`](#readablestreamgenericreader) + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `R` | `any` | + +#### Properties + +##### closed + +> `readonly` **closed**: `Promise`\<`undefined`\> + +###### Inherited from + +[`ReadableStreamGenericReader`](#readablestreamgenericreader).[`closed`](#closed-2) + +#### Methods + +##### cancel() + +> **cancel**(`reason?`: `any`): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `reason?` | `any` | + +###### Returns + +`Promise`\<`void`\> + +###### Inherited from + +[`ReadableStreamGenericReader`](#readablestreamgenericreader).[`cancel`](#cancel-6) + +##### read() + +> **read**(): `Promise`\<[`ReadableStreamReadResult`](#readablestreamreadresult)\<`R`\>\> + +###### Returns + +`Promise`\<[`ReadableStreamReadResult`](#readablestreamreadresult)\<`R`\>\> + +##### releaseLock() + +> **releaseLock**(): `void` + +###### Returns + +`void` + +*** + +### ReadableStreamErrorCallback() + +> **ReadableStreamErrorCallback**(`reason`: `any`): `void` \| `PromiseLike`\<`void`\> + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `reason` | `any` | + +#### Returns + +`void` \| `PromiseLike`\<`void`\> + +*** + +### ReadableStreamGenericReader + +#### Extended by + +- [`ReadableStreamDefaultReader`](#readablestreamdefaultreader) +- [`ReadableStreamBYOBReader`](#readablestreambyobreader) + +#### Properties + +##### closed + +> `readonly` **closed**: `Promise`\<`undefined`\> + +#### Methods + +##### cancel() + +> **cancel**(`reason?`: `any`): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `reason?` | `any` | + +###### Returns + +`Promise`\<`void`\> + +*** + +### ReadableStreamGetReaderOptions + +#### Properties + +##### mode? + +> `optional` **mode**: `"byob"` + +Creates a ReadableStreamBYOBReader and locks the stream to the new reader. + +This call behaves the same way as the no-argument variant, except that it only works on readable byte streams, i.e. streams which were constructed specifically with the ability to handle "bring your own buffer" reading. The returned BYOB reader provides the ability to directly read individual chunks from the stream via its read() method, into developer-supplied buffers, allowing more precise control over allocation. + +*** + +### ReadableStreamReadDoneResult + +#### Type Parameters + +| Type Parameter | +| ------ | +| `T` | + +#### Properties + +##### done + +> **done**: `true` + +##### value? + +> `optional` **value**: `T` + +*** + +### ReadableStreamReadValueResult + +#### Type Parameters + +| Type Parameter | +| ------ | +| `T` | + +#### Properties + +##### done + +> **done**: `false` + +##### value + +> **value**: `T` + +*** + +### ReadableWritablePair + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `R` | `any` | +| `W` | `any` | + +#### Properties + +##### readable + +> **readable**: [`ReadableStream`](#readablestream)\<`R`\> + +##### writable + +> **writable**: [`WritableStream`](#writablestream)\<`W`\> + +Provides a convenient, chainable way of piping this readable stream +through a transform stream (or any other { writable, readable } +pair). It simply pipes the stream into the writable side of the +supplied pair, and returns the readable side for further use. + +Piping a stream will lock it for the duration of the pipe, preventing +any other consumer from acquiring a reader. + +*** + +### StreamPipeOptions + +#### Properties + +##### preventAbort? + +> `optional` **preventAbort**: `boolean` + +##### preventCancel? + +> `optional` **preventCancel**: `boolean` + +##### preventClose? + +> `optional` **preventClose**: `boolean` + +Pipes this readable stream to a given writable stream destination. +The way in which the piping process behaves under various error +conditions can be customized with a number of passed options. It +returns a promise that fulfills when the piping process completes +successfully, or rejects if any errors were encountered. + +Piping a stream will lock it for the duration of the pipe, preventing +any other consumer from acquiring a reader. + +Errors and closures of the source and destination streams propagate +as follows: + +An error in this source readable stream will abort destination, +unless preventAbort is truthy. The returned promise will be rejected +with the source's error, or with any error that occurs during +aborting the destination. + +An error in destination will cancel this source readable stream, +unless preventCancel is truthy. The returned promise will be rejected +with the destination's error, or with any error that occurs during +canceling the source. + +When this source readable stream closes, destination will be closed, +unless preventClose is truthy. The returned promise will be fulfilled +once this process completes, unless an error is encountered while +closing the destination, in which case it will be rejected with that +error. + +If destination starts out closed or closing, this source readable +stream will be canceled, unless preventCancel is true. The returned +promise will be rejected with an error indicating piping to a closed +stream failed, or with any error that occurs during canceling the +source. + +The signal option can be set to an AbortSignal to allow aborting an +ongoing pipe operation via the corresponding AbortController. In this +case, this source readable stream will be canceled, and destination +aborted, unless the respective options preventCancel or preventAbort +are set. + +##### signal? + +> `optional` **signal**: [`AbortSignal`](../../../abort.md#abortsignal) + +*** + +### UnderlyingByteSource + +#### Properties + +##### autoAllocateChunkSize? + +> `optional` **autoAllocateChunkSize**: `number` + +##### cancel? + +> `optional` **cancel**: [`ReadableStreamErrorCallback`](#readablestreamerrorcallback) + +##### pull? + +> `optional` **pull**: [`ReadableByteStreamControllerCallback`](#readablebytestreamcontrollercallback) + +##### start? + +> `optional` **start**: [`ReadableByteStreamControllerCallback`](#readablebytestreamcontrollercallback) + +##### type + +> **type**: `"bytes"` + +*** + +### UnderlyingSink + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `W` | `any` | + +#### Properties + +##### abort? + +> `optional` **abort**: [`UnderlyingSinkAbortCallback`](#underlyingsinkabortcallback) + +##### close? + +> `optional` **close**: [`UnderlyingSinkCloseCallback`](#underlyingsinkclosecallback) + +##### start? + +> `optional` **start**: [`UnderlyingSinkStartCallback`](#underlyingsinkstartcallback) + +##### type? + +> `optional` **type**: `undefined` + +##### write? + +> `optional` **write**: [`UnderlyingSinkWriteCallback`](#underlyingsinkwritecallback)\<`W`\> + +*** + +### UnderlyingSinkAbortCallback() + +> **UnderlyingSinkAbortCallback**(`reason?`: `any`): `void` \| `PromiseLike`\<`void`\> + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `reason?` | `any` | + +#### Returns + +`void` \| `PromiseLike`\<`void`\> + +*** + +### UnderlyingSinkCloseCallback() + +> **UnderlyingSinkCloseCallback**(): `void` \| `PromiseLike`\<`void`\> + +#### Returns + +`void` \| `PromiseLike`\<`void`\> + +*** + +### UnderlyingSinkStartCallback() + +> **UnderlyingSinkStartCallback**(`controller`: [`WritableStreamDefaultController`](#writablestreamdefaultcontroller)): `any` + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `controller` | [`WritableStreamDefaultController`](#writablestreamdefaultcontroller) | + +#### Returns + +`any` + +*** + +### UnderlyingSinkWriteCallback() + +#### Type Parameters + +| Type Parameter | +| ------ | +| `W` | + +> **UnderlyingSinkWriteCallback**(`chunk`: `W`, `controller`: [`WritableStreamDefaultController`](#writablestreamdefaultcontroller)): `void` \| `PromiseLike`\<`void`\> + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `chunk` | `W` | +| `controller` | [`WritableStreamDefaultController`](#writablestreamdefaultcontroller) | + +#### Returns + +`void` \| `PromiseLike`\<`void`\> + +*** + +### UnderlyingSource + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `R` | `any` | + +#### Properties + +##### cancel? + +> `optional` **cancel**: [`UnderlyingSourceCancelCallback`](#underlyingsourcecancelcallback) + +##### pull? + +> `optional` **pull**: [`UnderlyingSourcePullCallback`](#underlyingsourcepullcallback)\<`R`\> + +##### start? + +> `optional` **start**: [`UnderlyingSourceStartCallback`](#underlyingsourcestartcallback)\<`R`\> + +##### type? + +> `optional` **type**: `undefined` + +*** + +### UnderlyingSourceCancelCallback() + +> **UnderlyingSourceCancelCallback**(`reason?`: `any`): `void` \| `PromiseLike`\<`void`\> + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `reason?` | `any` | + +#### Returns + +`void` \| `PromiseLike`\<`void`\> + +*** + +### UnderlyingSourcePullCallback() + +#### Type Parameters + +| Type Parameter | +| ------ | +| `R` | + +> **UnderlyingSourcePullCallback**(`controller`: [`ReadableStreamController`](#readablestreamcontroller)\<`R`\>): `void` \| `PromiseLike`\<`void`\> + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `controller` | [`ReadableStreamController`](#readablestreamcontroller)\<`R`\> | + +#### Returns + +`void` \| `PromiseLike`\<`void`\> + +*** + +### UnderlyingSourceStartCallback() + +#### Type Parameters + +| Type Parameter | +| ------ | +| `R` | + +> **UnderlyingSourceStartCallback**(`controller`: [`ReadableStreamController`](#readablestreamcontroller)\<`R`\>): `any` + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `controller` | [`ReadableStreamController`](#readablestreamcontroller)\<`R`\> | + +#### Returns + +`any` + +*** + +### WritableStream + +This Streams API interface provides a standard abstraction for writing +streaming data to a destination, known as a sink. This object comes with +built-in back pressure and queuing. + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `W` | `any` | + +#### Properties + +##### locked + +> `readonly` **locked**: `boolean` + +#### Methods + +##### abort() + +> **abort**(`reason?`: `any`): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `reason?` | `any` | + +###### Returns + +`Promise`\<`void`\> + +##### close() + +> **close**(): `Promise`\<`void`\> + +###### Returns + +`Promise`\<`void`\> + +##### getWriter() + +> **getWriter**(): [`WritableStreamDefaultWriter`](#writablestreamdefaultwriter)\<`W`\> + +###### Returns + +[`WritableStreamDefaultWriter`](#writablestreamdefaultwriter)\<`W`\> + +*** + +### WritableStreamDefaultController + +This Streams API interface represents a controller allowing control of a +WritableStream's state. When constructing a WritableStream, the +underlying sink is given a corresponding WritableStreamDefaultController +instance to manipulate. + +#### Methods + +##### error() + +> **error**(`e?`: `any`): `void` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `e?` | `any` | + +###### Returns + +`void` + +*** + +### WritableStreamDefaultWriter + +This Streams API interface is the object returned by +WritableStream.getWriter() and once created locks the < writer to the +WritableStream ensuring that no other streams can write to the underlying +sink. + +#### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `W` | `any` | + +#### Properties + +##### closed + +> `readonly` **closed**: `Promise`\<`undefined`\> + +##### desiredSize + +> `readonly` **desiredSize**: `number` \| `null` + +##### ready + +> `readonly` **ready**: `Promise`\<`undefined`\> + +#### Methods + +##### abort() + +> **abort**(`reason?`: `any`): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `reason?` | `any` | + +###### Returns + +`Promise`\<`void`\> + +##### close() + +> **close**(): `Promise`\<`void`\> + +###### Returns + +`Promise`\<`void`\> + +##### releaseLock() + +> **releaseLock**(): `void` + +###### Returns + +`void` + +##### write() + +> **write**(`chunk?`: `W`): `Promise`\<`void`\> + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `chunk?` | `W` | + +###### Returns + +`Promise`\<`void`\> + +## Type Aliases + +### ReadableStreamController + +> **ReadableStreamController**\<`T`\> = [`ReadableStreamDefaultController`](#readablestreamdefaultcontroller)\<`T`\> + +#### Type Parameters + +| Type Parameter | +| ------ | +| `T` | + +*** + +### ReadableStreamReader + +> **ReadableStreamReader**\<`T`\> = [`ReadableStreamDefaultReader`](#readablestreamdefaultreader)\<`T`\> \| [`ReadableStreamBYOBReader`](#readablestreambyobreader) + +#### Type Parameters + +| Type Parameter | +| ------ | +| `T` | + +*** + +### ReadableStreamReaderMode + +> **ReadableStreamReaderMode** = `"byob"` + +*** + +### ReadableStreamReadResult + +> **ReadableStreamReadResult**\<`T`\> = [`ReadableStreamReadValueResult`](#readablestreamreadvalueresult)\<`T`\> \| [`ReadableStreamReadDoneResult`](#readablestreamreaddoneresult)\<`T`\> + +#### Type Parameters + +| Type Parameter | +| ------ | +| `T` | + +## Variables + +### ByteLengthQueuingStrategy + +> **ByteLengthQueuingStrategy**: \{(`init`: [`QueuingStrategyInit`](#queuingstrategyinit)): [`ByteLengthQueuingStrategy`](#bytelengthqueuingstrategy); `prototype`: [`ByteLengthQueuingStrategy`](#bytelengthqueuingstrategy); \} + +#### Type Declaration + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `init` | [`QueuingStrategyInit`](#queuingstrategyinit) | + +#### Returns + +[`ByteLengthQueuingStrategy`](#bytelengthqueuingstrategy) + +##### prototype + +> **prototype**: [`ByteLengthQueuingStrategy`](#bytelengthqueuingstrategy) + +*** + +### CountQueuingStrategy + +> **CountQueuingStrategy**: \{(`init`: [`QueuingStrategyInit`](#queuingstrategyinit)): [`CountQueuingStrategy`](#countqueuingstrategy); `prototype`: [`CountQueuingStrategy`](#countqueuingstrategy); \} + +#### Type Declaration + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `init` | [`QueuingStrategyInit`](#queuingstrategyinit) | + +#### Returns + +[`CountQueuingStrategy`](#countqueuingstrategy) + +##### prototype + +> **prototype**: [`CountQueuingStrategy`](#countqueuingstrategy) + +*** + +### ReadableByteStreamController + +> **ReadableByteStreamController**: \{(): [`ReadableByteStreamController`](#readablebytestreamcontroller); `prototype`: [`ReadableByteStreamController`](#readablebytestreamcontroller); \} + +#### Type Declaration + +#### Returns + +[`ReadableByteStreamController`](#readablebytestreamcontroller) + +##### prototype + +> **prototype**: [`ReadableByteStreamController`](#readablebytestreamcontroller) + +*** + +### ReadableStream + +> **ReadableStream**: \{(`underlyingSource`: [`UnderlyingByteSource`](#underlyingbytesource), `strategy?`: [`QueuingStrategy`](#queuingstrategy)\<`Uint8Array`\>): [`ReadableStream`](#readablestream)\<`Uint8Array`\>; \<`R`\>(`underlyingSource?`: [`UnderlyingSource`](#underlyingsource)\<`R`\>, `strategy?`: [`QueuingStrategy`](#queuingstrategy)\<`R`\>): [`ReadableStream`](#readablestream)\<`R`\>; `prototype`: [`ReadableStream`](#readablestream); `from`: [`ReadableStream`](#readablestream)\<`T`\>; \} + +#### Type Declaration + +#### Call Signature + +> **new ReadableStream**(`underlyingSource`: [`UnderlyingByteSource`](#underlyingbytesource), `strategy?`: [`QueuingStrategy`](#queuingstrategy)\<`Uint8Array`\>): [`ReadableStream`](#readablestream)\<`Uint8Array`\> + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `underlyingSource` | [`UnderlyingByteSource`](#underlyingbytesource) | +| `strategy?` | [`QueuingStrategy`](#queuingstrategy)\<`Uint8Array`\> | + +##### Returns + +[`ReadableStream`](#readablestream)\<`Uint8Array`\> + +#### Call Signature + +> **new ReadableStream**\<`R`\>(`underlyingSource?`: [`UnderlyingSource`](#underlyingsource)\<`R`\>, `strategy?`: [`QueuingStrategy`](#queuingstrategy)\<`R`\>): [`ReadableStream`](#readablestream)\<`R`\> + +##### Parameters + +| Parameter | Type | +| ------ | ------ | +| `underlyingSource?` | [`UnderlyingSource`](#underlyingsource)\<`R`\> | +| `strategy?` | [`QueuingStrategy`](#queuingstrategy)\<`R`\> | + +##### Returns + +[`ReadableStream`](#readablestream)\<`R`\> + +##### prototype + +> **prototype**: [`ReadableStream`](#readablestream) + +##### from() + +> **from**\<`T`\>(`iterable`: `Iterable`\<`T`, `any`, `any`\> \| `AsyncIterable`\<`T`, `any`, `any`\>): [`ReadableStream`](#readablestream)\<`T`\> + +###### Type Parameters + +| Type Parameter | +| ------ | +| `T` | + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `iterable` | `Iterable`\<`T`, `any`, `any`\> \| `AsyncIterable`\<`T`, `any`, `any`\> | + +###### Returns + +[`ReadableStream`](#readablestream)\<`T`\> + +*** + +### ReadableStreamBYOBReader + +> **ReadableStreamBYOBReader**: \{(`stream`: [`ReadableStream`](#readablestream)): [`ReadableStreamBYOBReader`](#readablestreambyobreader); `prototype`: [`ReadableStreamBYOBReader`](#readablestreambyobreader); \} + +#### Type Declaration + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `stream` | [`ReadableStream`](#readablestream) | + +#### Returns + +[`ReadableStreamBYOBReader`](#readablestreambyobreader) + +##### prototype + +> **prototype**: [`ReadableStreamBYOBReader`](#readablestreambyobreader) + +*** + +### ReadableStreamBYOBRequest + +> **ReadableStreamBYOBRequest**: \{(): [`ReadableStreamBYOBRequest`](#readablestreambyobrequest); `prototype`: [`ReadableStreamBYOBRequest`](#readablestreambyobrequest); \} + +#### Type Declaration + +#### Returns + +[`ReadableStreamBYOBRequest`](#readablestreambyobrequest) + +##### prototype + +> **prototype**: [`ReadableStreamBYOBRequest`](#readablestreambyobrequest) + +*** + +### ReadableStreamDefaultController + +> **ReadableStreamDefaultController**: \{(): [`ReadableStreamDefaultController`](#readablestreamdefaultcontroller); `prototype`: [`ReadableStreamDefaultController`](#readablestreamdefaultcontroller); \} + +#### Type Declaration + +#### Returns + +[`ReadableStreamDefaultController`](#readablestreamdefaultcontroller) + +##### prototype + +> **prototype**: [`ReadableStreamDefaultController`](#readablestreamdefaultcontroller) + +*** + +### ReadableStreamDefaultReader + +> **ReadableStreamDefaultReader**: \{\<`R`\>(`stream`: [`ReadableStream`](#readablestream)\<`R`\>): [`ReadableStreamDefaultReader`](#readablestreamdefaultreader)\<`R`\>; `prototype`: [`ReadableStreamDefaultReader`](#readablestreamdefaultreader); \} + +#### Type Declaration + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `stream` | [`ReadableStream`](#readablestream)\<`R`\> | + +#### Returns + +[`ReadableStreamDefaultReader`](#readablestreamdefaultreader)\<`R`\> + +##### prototype + +> **prototype**: [`ReadableStreamDefaultReader`](#readablestreamdefaultreader) + +*** + +### WritableStream + +> **WritableStream**: \{\<`W`\>(`underlyingSink?`: [`UnderlyingSink`](#underlyingsink)\<`W`\>, `strategy?`: [`QueuingStrategy`](#queuingstrategy)\<`W`\>): [`WritableStream`](#writablestream)\<`W`\>; `prototype`: [`WritableStream`](#writablestream); \} + +#### Type Declaration + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `underlyingSink?` | [`UnderlyingSink`](#underlyingsink)\<`W`\> | +| `strategy?` | [`QueuingStrategy`](#queuingstrategy)\<`W`\> | + +#### Returns + +[`WritableStream`](#writablestream)\<`W`\> + +##### prototype + +> **prototype**: [`WritableStream`](#writablestream) + +*** + +### WritableStreamDefaultController + +> **WritableStreamDefaultController**: \{(): [`WritableStreamDefaultController`](#writablestreamdefaultcontroller); `prototype`: [`WritableStreamDefaultController`](#writablestreamdefaultcontroller); \} + +#### Type Declaration + +#### Returns + +[`WritableStreamDefaultController`](#writablestreamdefaultcontroller) + +##### prototype + +> **prototype**: [`WritableStreamDefaultController`](#writablestreamdefaultcontroller) + +*** + +### WritableStreamDefaultWriter + +> **WritableStreamDefaultWriter**: \{\<`W`\>(`stream`: [`WritableStream`](#writablestream)\<`W`\>): [`WritableStreamDefaultWriter`](#writablestreamdefaultwriter)\<`W`\>; `prototype`: [`WritableStreamDefaultWriter`](#writablestreamdefaultwriter); \} + +#### Type Declaration + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `stream` | [`WritableStream`](#writablestream)\<`W`\> | + +#### Returns + +[`WritableStreamDefaultWriter`](#writablestreamdefaultwriter)\<`W`\> + +##### prototype + +> **prototype**: [`WritableStreamDefaultWriter`](#writablestreamdefaultwriter) diff --git a/src/reference/modules/llrt/string_decoder.md b/src/reference/modules/llrt/string_decoder.md new file mode 100644 index 0000000..b41351f --- /dev/null +++ b/src/reference/modules/llrt/string_decoder.md @@ -0,0 +1,64 @@ +[@caido/quickjs-types](../index.md) / llrt/string\_decoder + +# llrt/string\_decoder + +## Classes + +### StringDecoder + +#### Constructors + +##### Constructor + +> **new StringDecoder**(`encoding?`: [`BufferEncoding`](buffer.md#bufferencoding)): [`StringDecoder`](#stringdecoder) + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `encoding?` | [`BufferEncoding`](buffer.md#bufferencoding) | + +###### Returns + +[`StringDecoder`](#stringdecoder) + +#### Methods + +##### end() + +> **end**(`buffer?`: `string` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](buffer.md#buffer)): `string` + +Returns any remaining input stored in the internal buffer as a string. Bytes +representing incomplete UTF-8 and UTF-16 characters will be replaced with +substitution characters appropriate for the character encoding. + +If the `buffer` argument is provided, one final call to `stringDecoder.write()` is performed before returning the remaining input. +After `end()` is called, the `stringDecoder` object can be reused for new input. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `buffer?` | `string` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](buffer.md#buffer) | The bytes to decode. | + +###### Returns + +`string` + +##### write() + +> **write**(`buffer`: `string` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](buffer.md#buffer)): `string` + +Returns a decoded string, ensuring that any incomplete multibyte characters at +the end of the `Buffer`, or `TypedArray`, or `DataView` are omitted from the +returned string and stored in an internal buffer for the next call to `stringDecoder.write()` or `stringDecoder.end()`. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `buffer` | `string` \| [`ArrayBufferView`](globals/namespaces/QuickJS.md#arraybufferview) \| [`Buffer`](buffer.md#buffer) | The bytes to decode. | + +###### Returns + +`string` diff --git a/src/reference/modules/llrt/url/index.md b/src/reference/modules/llrt/url/index.md new file mode 100644 index 0000000..a23487b --- /dev/null +++ b/src/reference/modules/llrt/url/index.md @@ -0,0 +1,780 @@ +[@caido/quickjs-types](../../index.md) / llrt/url + +# llrt/url + +## Modules + +| Module | Description | +| ------ | ------ | +| [url](url.md) | - | + +## Interfaces + +### Global + +#### Properties + +##### URL + +> **URL**: *typeof* [`URL`](url.md#url) + +##### URLSearchParams + +> **URLSearchParams**: *typeof* [`URLSearchParams`](url.md#urlsearchparams-1) + +*** + +### URL + +Browser-compatible `URL` class, implemented by following the WHATWG URL +Standard. [Examples of parsed URLs](https://url.spec.whatwg.org/#example-url-parsing) may be found in the Standard itself. +The `URL` class is also available on the global object. + +In accordance with browser conventions, all properties of `URL` objects +are implemented as getters and setters on the class prototype, rather than as +data properties on the object itself. Thus, unlike `legacy urlObject`s, +using the `delete` keyword on any properties of `URL` objects (e.g. `delete myURL.protocol`, `delete myURL.pathname`, etc) has no effect but will still +return `true`. + +#### Extends + +- [`URL`](url.md#url) + +#### Properties + +##### hash + +> **hash**: `string` + +Gets and sets the fragment portion of the URL. + +```js +const myURL = new URL('https://example.org/foo#bar'); +console.log(myURL.hash); +// Prints #bar + +myURL.hash = 'baz'; +console.log(myURL.href); +// Prints https://example.org/foo#baz +``` + +Invalid URL characters included in the value assigned to the `hash` property +are `percent-encoded`. The selection of which characters to +percent-encode may vary somewhat from what the [parse](url.md#parse-2) and [format](url.md#format) methods would produce. + +###### Inherited from + +[`URL`](url.md#url).[`hash`](url.md#hash) + +##### host + +> **host**: `string` + +Gets and sets the host portion of the URL. + +```js +const myURL = new URL('https://example.org:81/foo'); +console.log(myURL.host); +// Prints example.org:81 + +myURL.host = 'example.com:82'; +console.log(myURL.href); +// Prints https://example.com:82/foo +``` + +Invalid host values assigned to the `host` property are ignored. + +###### Inherited from + +[`URL`](url.md#url).[`host`](url.md#host) + +##### hostname + +> **hostname**: `string` + +Gets and sets the host name portion of the URL. The key difference between`url.host` and `url.hostname` is that `url.hostname` does _not_ include the +port. + +```js +const myURL = new URL('https://example.org:81/foo'); +console.log(myURL.hostname); +// Prints example.org + +// Setting the hostname does not change the port +myURL.hostname = 'example.com'; +console.log(myURL.href); +// Prints https://example.com:81/foo + +// Use myURL.host to change the hostname and port +myURL.host = 'example.org:82'; +console.log(myURL.href); +// Prints https://example.org:82/foo +``` + +Invalid host name values assigned to the `hostname` property are ignored. + +###### Inherited from + +[`URL`](url.md#url).[`hostname`](url.md#hostname) + +##### href + +> **href**: `string` + +Gets and sets the serialized URL. + +```js +const myURL = new URL('https://example.org/foo'); +console.log(myURL.href); +// Prints https://example.org/foo + +myURL.href = 'https://example.com/bar'; +console.log(myURL.href); +// Prints https://example.com/bar +``` + +Getting the value of the `href` property is equivalent to calling [toString](url.md#tostring). + +Setting the value of this property to a new value is equivalent to creating a +new `URL` object using `new URL(value)`. Each of the `URL` object's properties will be modified. + +If the value assigned to the `href` property is not a valid URL, a `TypeError` will be thrown. + +###### Inherited from + +[`URL`](url.md#url).[`href`](url.md#href) + +##### origin + +> `readonly` **origin**: `string` + +Gets the read-only serialization of the URL's origin. + +```js +const myURL = new URL('https://example.org/foo/bar?baz'); +console.log(myURL.origin); +// Prints https://example.org +``` + +```js +const idnURL = new URL('https://測試'); +console.log(idnURL.origin); +// Prints https://xn--g6w251d + +console.log(idnURL.hostname); +// Prints xn--g6w251d +``` + +###### Inherited from + +[`URL`](url.md#url).[`origin`](url.md#origin) + +##### password + +> **password**: `string` + +Gets and sets the password portion of the URL. + +```js +const myURL = new URL('https://abc:xyz@example.com'); +console.log(myURL.password); +// Prints xyz + +myURL.password = '123'; +console.log(myURL.href); +// Prints https://abc:123@example.com/ +``` + +Invalid URL characters included in the value assigned to the `password` property +are `percent-encoded`. The selection of which characters to +percent-encode may vary somewhat from what the [parse](url.md#parse-2) and [format](url.md#format) methods would produce. + +###### Inherited from + +[`URL`](url.md#url).[`password`](url.md#password) + +##### pathname + +> **pathname**: `string` + +Gets and sets the path portion of the URL. + +```js +const myURL = new URL('https://example.org/abc/xyz?123'); +console.log(myURL.pathname); +// Prints /abc/xyz + +myURL.pathname = '/abcdef'; +console.log(myURL.href); +// Prints https://example.org/abcdef?123 +``` + +Invalid URL characters included in the value assigned to the `pathname` property are `percent-encoded`. The selection of which characters +to percent-encode may vary somewhat from what the [parse](url.md#parse-2) and [format](url.md#format) methods would produce. + +###### Inherited from + +[`URL`](url.md#url).[`pathname`](url.md#pathname) + +##### port + +> **port**: `string` + +Gets and sets the port portion of the URL. + +The port value may be a number or a string containing a number in the range `0` to `65535` (inclusive). Setting the value to the default port of the `URL` objects given `protocol` will +result in the `port` value becoming +the empty string (`''`). + +The port value can be an empty string in which case the port depends on +the protocol/scheme. + +Upon assigning a value to the port, the value will first be converted to a +string using `.toString()`. + +If that string is invalid but it begins with a number, the leading number is +assigned to `port`. +If the number lies outside the range denoted above, it is ignored. + +```js +const myURL = new URL('https://example.org:8888'); +console.log(myURL.port); +// Prints 8888 + +// Default ports are automatically transformed to the empty string +// (HTTPS protocol's default port is 443) +myURL.port = '443'; +console.log(myURL.port); +// Prints the empty string +console.log(myURL.href); +// Prints https://example.org/ + +myURL.port = 1234; +console.log(myURL.port); +// Prints 1234 +console.log(myURL.href); +// Prints https://example.org:1234/ + +// Completely invalid port strings are ignored +myURL.port = 'abcd'; +console.log(myURL.port); +// Prints 1234 + +// Leading numbers are treated as a port number +myURL.port = '5678abcd'; +console.log(myURL.port); +// Prints 5678 + +// Non-integers are truncated +myURL.port = 1234.5678; +console.log(myURL.port); +// Prints 1234 + +// Out-of-range numbers which are not represented in scientific notation +// will be ignored. +myURL.port = 1e10; // 10000000000, will be range-checked as described below +console.log(myURL.port); +// Prints 1234 +``` + +Numbers which contain a decimal point, +such as floating-point numbers or numbers in scientific notation, +are not an exception to this rule. +Leading numbers up to the decimal point will be set as the URL's port, +assuming they are valid: + +```js +myURL.port = 4.567e21; +console.log(myURL.port); +// Prints 4 (because it is the leading number in the string '4.567e21') +``` + +###### Inherited from + +[`URL`](url.md#url).[`port`](url.md#port) + +##### protocol + +> **protocol**: `string` + +Gets and sets the protocol portion of the URL. + +```js +const myURL = new URL('https://example.org'); +console.log(myURL.protocol); +// Prints https: + +myURL.protocol = 'ftp'; +console.log(myURL.href); +// Prints ftp://example.org/ +``` + +Invalid URL protocol values assigned to the `protocol` property are ignored. + +###### Inherited from + +[`URL`](url.md#url).[`protocol`](url.md#protocol) + +##### search + +> **search**: `string` + +Gets and sets the serialized query portion of the URL. + +```js +const myURL = new URL('https://example.org/abc?123'); +console.log(myURL.search); +// Prints ?123 + +myURL.search = 'abc=xyz'; +console.log(myURL.href); +// Prints https://example.org/abc?abc=xyz +``` + +Any invalid URL characters appearing in the value assigned the `search` property will be `percent-encoded`. The selection of which +characters to percent-encode may vary somewhat from what the [parse](url.md#parse-2) and [format](url.md#format) methods would produce. + +###### Inherited from + +[`URL`](url.md#url).[`search`](url.md#search) + +##### searchParams + +> `readonly` **searchParams**: [`URLSearchParams`](url.md#urlsearchparams-1) + +Gets the `URLSearchParams` object representing the query parameters of the +URL. This property is read-only but the `URLSearchParams` object it provides +can be used to mutate the URL instance; to replace the entirety of query +parameters of the URL, use the [search](url.md#search) setter. See `URLSearchParams` documentation for details. + +Use care when using `.searchParams` to modify the `URL` because, +per the WHATWG specification, the `URLSearchParams` object uses +different rules to determine which characters to percent-encode. For +instance, the `URL` object will not percent encode the ASCII tilde (`~`) +character, while `URLSearchParams` will always encode it: + +```js +const myURL = new URL('https://example.org/abc?foo=~bar'); + +console.log(myURL.search); // prints ?foo=~bar + +// Modify the URL via searchParams... +myURL.searchParams.sort(); + +console.log(myURL.search); // prints ?foo=%7Ebar +``` + +###### Inherited from + +[`URL`](url.md#url).[`searchParams`](url.md#searchparams) + +##### username + +> **username**: `string` + +Gets and sets the username portion of the URL. + +```js +const myURL = new URL('https://abc:xyz@example.com'); +console.log(myURL.username); +// Prints abc + +myURL.username = '123'; +console.log(myURL.href); +// Prints https://123:xyz@example.com/ +``` + +Any invalid URL characters appearing in the value assigned the `username` property will be `percent-encoded`. The selection of which +characters to percent-encode may vary somewhat from what the [parse](url.md#parse-2) and [format](url.md#format) methods would produce. + +###### Inherited from + +[`URL`](url.md#url).[`username`](url.md#username) + +#### Methods + +##### toJSON() + +> **toJSON**(): `string` + +The `toJSON()` method on the `URL` object returns the serialized URL. The +value returned is equivalent to that of [href](url.md#href) and [toString](url.md#tostring). + +This method is automatically called when an `URL` object is serialized +with [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). + +```js +const myURLs = [ + new URL('https://www.example.com'), + new URL('https://test.example.org'), +]; +console.log(JSON.stringify(myURLs)); +// Prints ["https://www.example.com/","https://test.example.org/"] +``` + +###### Returns + +`string` + +###### Inherited from + +[`URL`](url.md#url).[`toJSON`](url.md#tojson) + +##### toString() + +> **toString**(): `string` + +The `toString()` method on the `URL` object returns the serialized URL. The +value returned is equivalent to that of [href](url.md#href) and [toJSON](url.md#tojson). + +###### Returns + +`string` + +###### Inherited from + +[`URL`](url.md#url).[`toString`](url.md#tostring) + +*** + +### URLSearchParams + +The `URLSearchParams` API provides read and write access to the query of a `URL`. The `URLSearchParams` class can also be used standalone with one of the +four following constructors. +The `URLSearchParams` class is also available on the global object. + +The WHATWG `URLSearchParams` interface and the `querystring` module have +similar purpose, but the purpose of the `querystring` module is more +general, as it allows the customization of delimiter characters (`&` and `=`). +On the other hand, this API is designed purely for URL query strings. + +```js +const myURL = new URL('https://example.org/?abc=123'); +console.log(myURL.searchParams.get('abc')); +// Prints 123 + +myURL.searchParams.append('abc', 'xyz'); +console.log(myURL.href); +// Prints https://example.org/?abc=123&abc=xyz + +myURL.searchParams.delete('abc'); +myURL.searchParams.set('a', 'b'); +console.log(myURL.href); +// Prints https://example.org/?a=b + +const newSearchParams = new URLSearchParams(myURL.searchParams); +// The above is equivalent to +// const newSearchParams = new URLSearchParams(myURL.search); + +newSearchParams.append('a', 'c'); +console.log(myURL.href); +// Prints https://example.org/?a=b +console.log(newSearchParams.toString()); +// Prints a=b&a=c + +// newSearchParams.toString() is implicitly called +myURL.search = newSearchParams; +console.log(myURL.href); +// Prints https://example.org/?a=b&a=c +newSearchParams.delete('a'); +console.log(myURL.href); +// Prints https://example.org/?a=b&a=c +``` + +#### Extends + +- [`URLSearchParams`](url.md#urlsearchparams-1) + +#### Methods + +##### \[iterator\]() + +> **\[iterator\]**(): `IterableIterator`\<\[`string`, `string`\]\> + +###### Returns + +`IterableIterator`\<\[`string`, `string`\]\> + +###### Inherited from + +[`URLSearchParams`](url.md#urlsearchparams-1).[`[iterator]`](url.md#iterator) + +##### append() + +> **append**(`name`: `string`, `value`: `string`): `void` + +Append a new name-value pair to the query string. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `name` | `string` | +| `value` | `string` | + +###### Returns + +`void` + +###### Inherited from + +[`URLSearchParams`](url.md#urlsearchparams-1).[`append`](url.md#append) + +##### delete() + +> **delete**(`name`: `string`, `value?`: `string`): `void` + +If `value` is provided, removes all name-value pairs +where name is `name` and value is `value`. + +If `value` is not provided, removes all name-value pairs whose name is `name`. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `name` | `string` | +| `value?` | `string` | + +###### Returns + +`void` + +###### Inherited from + +[`URLSearchParams`](url.md#urlsearchparams-1).[`delete`](url.md#delete) + +##### entries() + +> **entries**(): `IterableIterator`\<\[`string`, `string`\]\> + +Returns an ES6 `Iterator` over each of the name-value pairs in the query. +Each item of the iterator is a JavaScript `Array`. The first item of the `Array` is the `name`, the second item of the `Array` is the `value`. + +Alias for `urlSearchParams[@@iterator]()`. + +###### Returns + +`IterableIterator`\<\[`string`, `string`\]\> + +###### Inherited from + +[`URLSearchParams`](url.md#urlsearchparams-1).[`entries`](url.md#entries) + +##### forEach() + +> **forEach**\<`TThis`\>(`fn`: (`this`: `TThis`, `value`: `string`, `name`: `string`, `searchParams`: [`URLSearchParams`](url.md#urlsearchparams-1)) => `void`, `thisArg?`: `TThis`): `void` + +Iterates over each name-value pair in the query and invokes the given function. + +```js +const myURL = new URL('https://example.org/?a=b&c=d'); +myURL.searchParams.forEach((value, name, searchParams) => { + console.log(name, value, myURL.searchParams === searchParams); +}); +// Prints: +// a b true +// c d true +``` + +###### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `TThis` | [`URLSearchParams`](#urlsearchparams-2) | + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `fn` | (`this`: `TThis`, `value`: `string`, `name`: `string`, `searchParams`: [`URLSearchParams`](url.md#urlsearchparams-1)) => `void` | Invoked for each name-value pair in the query | +| `thisArg?` | `TThis` | To be used as `this` value for when `fn` is called | + +###### Returns + +`void` + +###### Inherited from + +[`URLSearchParams`](url.md#urlsearchparams-1).[`forEach`](url.md#foreach) + +##### get() + +> **get**(`name`: `string`): `string` \| `null` + +Returns the value of the first name-value pair whose name is `name`. If there +are no such pairs, `null` is returned. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `name` | `string` | + +###### Returns + +`string` \| `null` + +or `null` if there is no name-value pair with the given `name`. + +###### Inherited from + +[`URLSearchParams`](url.md#urlsearchparams-1).[`get`](url.md#get) + +##### has() + +> **has**(`name`: `string`, `value?`: `string`): `boolean` + +Checks if the `URLSearchParams` object contains key-value pair(s) based on `name` and an optional `value` argument. + +If `value` is provided, returns `true` when name-value pair with +same `name` and `value` exists. + +If `value` is not provided, returns `true` if there is at least one name-value +pair whose name is `name`. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `name` | `string` | +| `value?` | `string` | + +###### Returns + +`boolean` + +###### Inherited from + +[`URLSearchParams`](url.md#urlsearchparams-1).[`has`](url.md#has) + +##### keys() + +> **keys**(): `IterableIterator`\<`string`\> + +Returns an ES6 `Iterator` over the names of each name-value pair. + +```js +const params = new URLSearchParams('foo=bar&foo=baz'); +for (const name of params.keys()) { + console.log(name); +} +// Prints: +// foo +// foo +``` + +###### Returns + +`IterableIterator`\<`string`\> + +###### Inherited from + +[`URLSearchParams`](url.md#urlsearchparams-1).[`keys`](url.md#keys) + +##### set() + +> **set**(`name`: `string`, `value`: `string`): `void` + +Sets the value in the `URLSearchParams` object associated with `name` to `value`. If there are any pre-existing name-value pairs whose names are `name`, +set the first such pair's value to `value` and remove all others. If not, +append the name-value pair to the query string. + +```js +const params = new URLSearchParams(); +params.append('foo', 'bar'); +params.append('foo', 'baz'); +params.append('abc', 'def'); +console.log(params.toString()); +// Prints foo=bar&foo=baz&abc=def + +params.set('foo', 'def'); +params.set('xyz', 'opq'); +console.log(params.toString()); +// Prints foo=def&abc=def&xyz=opq +``` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `name` | `string` | +| `value` | `string` | + +###### Returns + +`void` + +###### Inherited from + +[`URLSearchParams`](url.md#urlsearchparams-1).[`set`](url.md#set) + +##### sort() + +> **sort**(): `void` + +Sort all existing name-value pairs in-place by their names. Sorting is done +with a [stable sorting algorithm](https://en.wikipedia.org/wiki/Sorting_algorithm#Stability), so relative order between name-value pairs +with the same name is preserved. + +This method can be used, in particular, to increase cache hits. + +```js +const params = new URLSearchParams('query[]=abc&type=search&query[]=123'); +params.sort(); +console.log(params.toString()); +// Prints query%5B%5D=abc&query%5B%5D=123&type=search +``` + +###### Returns + +`void` + +###### Inherited from + +[`URLSearchParams`](url.md#urlsearchparams-1).[`sort`](url.md#sort) + +##### toString() + +> **toString**(): `string` + +Returns the search parameters serialized as a string, with characters +percent-encoded where necessary. + +###### Returns + +`string` + +###### Inherited from + +[`URLSearchParams`](url.md#urlsearchparams-1).[`toString`](url.md#tostring-2) + +##### values() + +> **values**(): `IterableIterator`\<`string`\> + +Returns an ES6 `Iterator` over the values of each name-value pair. + +###### Returns + +`IterableIterator`\<`string`\> + +###### Inherited from + +[`URLSearchParams`](url.md#urlsearchparams-1).[`values`](url.md#values) + +## Variables + +### URL + +> **URL**: *typeof* [`URL`](url.md#url) + +`URL` class is a global reference for `require('url').URL` + +*** + +### URLSearchParams + +> **URLSearchParams**: *typeof* [`URLSearchParams`](url.md#urlsearchparams-1) + +`URLSearchParams` class is a global reference for `require('url').URLSearchParams` diff --git a/src/reference/modules/llrt/url/url.md b/src/reference/modules/llrt/url/url.md new file mode 100644 index 0000000..c00ae20 --- /dev/null +++ b/src/reference/modules/llrt/url/url.md @@ -0,0 +1,1118 @@ +[@caido/quickjs-types](../../index.md) / [llrt/url](index.md) / url + +# url + +## Classes + +### URL + +Browser-compatible `URL` class, implemented by following the WHATWG URL +Standard. [Examples of parsed URLs](https://url.spec.whatwg.org/#example-url-parsing) may be found in the Standard itself. +The `URL` class is also available on the global object. + +In accordance with browser conventions, all properties of `URL` objects +are implemented as getters and setters on the class prototype, rather than as +data properties on the object itself. Thus, unlike `legacy urlObject`s, +using the `delete` keyword on any properties of `URL` objects (e.g. `delete myURL.protocol`, `delete myURL.pathname`, etc) has no effect but will still +return `true`. + +#### Extended by + +- [`URL`](index.md#url-1) + +#### Constructors + +##### Constructor + +> **new URL**(`input`: `string` \| \{ `toString`: () => `string`; \}, `base?`: `string` \| [`URL`](#url)): [`URL`](#url) + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `input` | `string` \| \{ `toString`: () => `string`; \} | +| `base?` | `string` \| [`URL`](#url) | + +###### Returns + +[`URL`](#url) + +#### Properties + +##### hash + +> **hash**: `string` + +Gets and sets the fragment portion of the URL. + +```js +const myURL = new URL('https://example.org/foo#bar'); +console.log(myURL.hash); +// Prints #bar + +myURL.hash = 'baz'; +console.log(myURL.href); +// Prints https://example.org/foo#baz +``` + +Invalid URL characters included in the value assigned to the `hash` property +are `percent-encoded`. The selection of which characters to +percent-encode may vary somewhat from what the [parse](#parse-2) and [format](#format) methods would produce. + +##### host + +> **host**: `string` + +Gets and sets the host portion of the URL. + +```js +const myURL = new URL('https://example.org:81/foo'); +console.log(myURL.host); +// Prints example.org:81 + +myURL.host = 'example.com:82'; +console.log(myURL.href); +// Prints https://example.com:82/foo +``` + +Invalid host values assigned to the `host` property are ignored. + +##### hostname + +> **hostname**: `string` + +Gets and sets the host name portion of the URL. The key difference between`url.host` and `url.hostname` is that `url.hostname` does _not_ include the +port. + +```js +const myURL = new URL('https://example.org:81/foo'); +console.log(myURL.hostname); +// Prints example.org + +// Setting the hostname does not change the port +myURL.hostname = 'example.com'; +console.log(myURL.href); +// Prints https://example.com:81/foo + +// Use myURL.host to change the hostname and port +myURL.host = 'example.org:82'; +console.log(myURL.href); +// Prints https://example.org:82/foo +``` + +Invalid host name values assigned to the `hostname` property are ignored. + +##### href + +> **href**: `string` + +Gets and sets the serialized URL. + +```js +const myURL = new URL('https://example.org/foo'); +console.log(myURL.href); +// Prints https://example.org/foo + +myURL.href = 'https://example.com/bar'; +console.log(myURL.href); +// Prints https://example.com/bar +``` + +Getting the value of the `href` property is equivalent to calling [toString](#tostring). + +Setting the value of this property to a new value is equivalent to creating a +new `URL` object using `new URL(value)`. Each of the `URL` object's properties will be modified. + +If the value assigned to the `href` property is not a valid URL, a `TypeError` will be thrown. + +##### origin + +> `readonly` **origin**: `string` + +Gets the read-only serialization of the URL's origin. + +```js +const myURL = new URL('https://example.org/foo/bar?baz'); +console.log(myURL.origin); +// Prints https://example.org +``` + +```js +const idnURL = new URL('https://測試'); +console.log(idnURL.origin); +// Prints https://xn--g6w251d + +console.log(idnURL.hostname); +// Prints xn--g6w251d +``` + +##### password + +> **password**: `string` + +Gets and sets the password portion of the URL. + +```js +const myURL = new URL('https://abc:xyz@example.com'); +console.log(myURL.password); +// Prints xyz + +myURL.password = '123'; +console.log(myURL.href); +// Prints https://abc:123@example.com/ +``` + +Invalid URL characters included in the value assigned to the `password` property +are `percent-encoded`. The selection of which characters to +percent-encode may vary somewhat from what the [parse](#parse-2) and [format](#format) methods would produce. + +##### pathname + +> **pathname**: `string` + +Gets and sets the path portion of the URL. + +```js +const myURL = new URL('https://example.org/abc/xyz?123'); +console.log(myURL.pathname); +// Prints /abc/xyz + +myURL.pathname = '/abcdef'; +console.log(myURL.href); +// Prints https://example.org/abcdef?123 +``` + +Invalid URL characters included in the value assigned to the `pathname` property are `percent-encoded`. The selection of which characters +to percent-encode may vary somewhat from what the [parse](#parse-2) and [format](#format) methods would produce. + +##### port + +> **port**: `string` + +Gets and sets the port portion of the URL. + +The port value may be a number or a string containing a number in the range `0` to `65535` (inclusive). Setting the value to the default port of the `URL` objects given `protocol` will +result in the `port` value becoming +the empty string (`''`). + +The port value can be an empty string in which case the port depends on +the protocol/scheme. + +Upon assigning a value to the port, the value will first be converted to a +string using `.toString()`. + +If that string is invalid but it begins with a number, the leading number is +assigned to `port`. +If the number lies outside the range denoted above, it is ignored. + +```js +const myURL = new URL('https://example.org:8888'); +console.log(myURL.port); +// Prints 8888 + +// Default ports are automatically transformed to the empty string +// (HTTPS protocol's default port is 443) +myURL.port = '443'; +console.log(myURL.port); +// Prints the empty string +console.log(myURL.href); +// Prints https://example.org/ + +myURL.port = 1234; +console.log(myURL.port); +// Prints 1234 +console.log(myURL.href); +// Prints https://example.org:1234/ + +// Completely invalid port strings are ignored +myURL.port = 'abcd'; +console.log(myURL.port); +// Prints 1234 + +// Leading numbers are treated as a port number +myURL.port = '5678abcd'; +console.log(myURL.port); +// Prints 5678 + +// Non-integers are truncated +myURL.port = 1234.5678; +console.log(myURL.port); +// Prints 1234 + +// Out-of-range numbers which are not represented in scientific notation +// will be ignored. +myURL.port = 1e10; // 10000000000, will be range-checked as described below +console.log(myURL.port); +// Prints 1234 +``` + +Numbers which contain a decimal point, +such as floating-point numbers or numbers in scientific notation, +are not an exception to this rule. +Leading numbers up to the decimal point will be set as the URL's port, +assuming they are valid: + +```js +myURL.port = 4.567e21; +console.log(myURL.port); +// Prints 4 (because it is the leading number in the string '4.567e21') +``` + +##### protocol + +> **protocol**: `string` + +Gets and sets the protocol portion of the URL. + +```js +const myURL = new URL('https://example.org'); +console.log(myURL.protocol); +// Prints https: + +myURL.protocol = 'ftp'; +console.log(myURL.href); +// Prints ftp://example.org/ +``` + +Invalid URL protocol values assigned to the `protocol` property are ignored. + +##### search + +> **search**: `string` + +Gets and sets the serialized query portion of the URL. + +```js +const myURL = new URL('https://example.org/abc?123'); +console.log(myURL.search); +// Prints ?123 + +myURL.search = 'abc=xyz'; +console.log(myURL.href); +// Prints https://example.org/abc?abc=xyz +``` + +Any invalid URL characters appearing in the value assigned the `search` property will be `percent-encoded`. The selection of which +characters to percent-encode may vary somewhat from what the [parse](#parse-2) and [format](#format) methods would produce. + +##### searchParams + +> `readonly` **searchParams**: [`URLSearchParams`](#urlsearchparams-1) + +Gets the `URLSearchParams` object representing the query parameters of the +URL. This property is read-only but the `URLSearchParams` object it provides +can be used to mutate the URL instance; to replace the entirety of query +parameters of the URL, use the [search](#search) setter. See `URLSearchParams` documentation for details. + +Use care when using `.searchParams` to modify the `URL` because, +per the WHATWG specification, the `URLSearchParams` object uses +different rules to determine which characters to percent-encode. For +instance, the `URL` object will not percent encode the ASCII tilde (`~`) +character, while `URLSearchParams` will always encode it: + +```js +const myURL = new URL('https://example.org/abc?foo=~bar'); + +console.log(myURL.search); // prints ?foo=~bar + +// Modify the URL via searchParams... +myURL.searchParams.sort(); + +console.log(myURL.search); // prints ?foo=%7Ebar +``` + +##### username + +> **username**: `string` + +Gets and sets the username portion of the URL. + +```js +const myURL = new URL('https://abc:xyz@example.com'); +console.log(myURL.username); +// Prints abc + +myURL.username = '123'; +console.log(myURL.href); +// Prints https://123:xyz@example.com/ +``` + +Any invalid URL characters appearing in the value assigned the `username` property will be `percent-encoded`. The selection of which +characters to percent-encode may vary somewhat from what the [parse](#parse-2) and [format](#format) methods would produce. + +#### Methods + +##### toJSON() + +> **toJSON**(): `string` + +The `toJSON()` method on the `URL` object returns the serialized URL. The +value returned is equivalent to that of [href](#href) and [toString](#tostring). + +This method is automatically called when an `URL` object is serialized +with [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). + +```js +const myURLs = [ + new URL('https://www.example.com'), + new URL('https://test.example.org'), +]; +console.log(JSON.stringify(myURLs)); +// Prints ["https://www.example.com/","https://test.example.org/"] +``` + +###### Returns + +`string` + +##### toString() + +> **toString**(): `string` + +The `toString()` method on the `URL` object returns the serialized URL. The +value returned is equivalent to that of [href](#href) and [toJSON](#tojson). + +###### Returns + +`string` + +##### canParse() + +> `static` **canParse**(`input`: `string`, `base?`: `string`): `boolean` + +Checks if an `input` relative to the `base` can be parsed to a `URL`. + +```js +const isValid = URL.canParse('/foo', 'https://example.org/'); // true + +const isNotValid = URL.canParse('/foo'); // false +``` + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `input` | `string` | The absolute or relative input URL to parse. If `input` is relative, then `base` is required. If `input` is absolute, the `base` is ignored. If `input` is not a string, it is `converted to a string` first. | +| `base?` | `string` | The base URL to resolve against if the `input` is not absolute. If `base` is not a string, it is `converted to a string` first. | + +###### Returns + +`boolean` + +##### parse() + +> `static` **parse**(`input`: `string`, `base?`: `string`): [`URL`](#url) \| `null` + +Parses a string as a URL. If `base` is provided, it will be used as the base URL for the purpose of resolving non-absolute `input` URLs. +Returns `null` if `input` is not a valid. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `input` | `string` | The absolute or relative input URL to parse. If `input` is relative, then `base` is required. If `input` is absolute, the `base` is ignored. If `input` is not a string, it is `converted to a string` first. | +| `base?` | `string` | The base URL to resolve against if the `input` is not absolute. If `base` is not a string, it is `converted to a string` first. | + +###### Returns + +[`URL`](#url) \| `null` + +*** + +### URLSearchParams + +The `URLSearchParams` API provides read and write access to the query of a `URL`. The `URLSearchParams` class can also be used standalone with one of the +four following constructors. +The `URLSearchParams` class is also available on the global object. + +The WHATWG `URLSearchParams` interface and the `querystring` module have +similar purpose, but the purpose of the `querystring` module is more +general, as it allows the customization of delimiter characters (`&` and `=`). +On the other hand, this API is designed purely for URL query strings. + +```js +const myURL = new URL('https://example.org/?abc=123'); +console.log(myURL.searchParams.get('abc')); +// Prints 123 + +myURL.searchParams.append('abc', 'xyz'); +console.log(myURL.href); +// Prints https://example.org/?abc=123&abc=xyz + +myURL.searchParams.delete('abc'); +myURL.searchParams.set('a', 'b'); +console.log(myURL.href); +// Prints https://example.org/?a=b + +const newSearchParams = new URLSearchParams(myURL.searchParams); +// The above is equivalent to +// const newSearchParams = new URLSearchParams(myURL.search); + +newSearchParams.append('a', 'c'); +console.log(myURL.href); +// Prints https://example.org/?a=b +console.log(newSearchParams.toString()); +// Prints a=b&a=c + +// newSearchParams.toString() is implicitly called +myURL.search = newSearchParams; +console.log(myURL.href); +// Prints https://example.org/?a=b&a=c +newSearchParams.delete('a'); +console.log(myURL.href); +// Prints https://example.org/?a=b&a=c +``` + +#### Extended by + +- [`URLSearchParams`](index.md#urlsearchparams-2) + +#### Implements + +- `Iterable`\<\[`string`, `string`\]\> + +#### Constructors + +##### Constructor + +> **new URLSearchParams**(`init?`: `string` \| `Iterable`\<\[`string`, `string`\], `any`, `any`\> \| [`URLSearchParams`](#urlsearchparams-1) \| `Record`\<`string`, `string` \| readonly `string`[]\> \| readonly \[`string`, `string`\][]): [`URLSearchParams`](#urlsearchparams-1) + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `init?` | `string` \| `Iterable`\<\[`string`, `string`\], `any`, `any`\> \| [`URLSearchParams`](#urlsearchparams-1) \| `Record`\<`string`, `string` \| readonly `string`[]\> \| readonly \[`string`, `string`\][] | + +###### Returns + +[`URLSearchParams`](#urlsearchparams-1) + +#### Methods + +##### \[iterator\]() + +> **\[iterator\]**(): `IterableIterator`\<\[`string`, `string`\]\> + +###### Returns + +`IterableIterator`\<\[`string`, `string`\]\> + +###### Implementation of + +`Iterable.[iterator]` + +##### append() + +> **append**(`name`: `string`, `value`: `string`): `void` + +Append a new name-value pair to the query string. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `name` | `string` | +| `value` | `string` | + +###### Returns + +`void` + +##### delete() + +> **delete**(`name`: `string`, `value?`: `string`): `void` + +If `value` is provided, removes all name-value pairs +where name is `name` and value is `value`. + +If `value` is not provided, removes all name-value pairs whose name is `name`. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `name` | `string` | +| `value?` | `string` | + +###### Returns + +`void` + +##### entries() + +> **entries**(): `IterableIterator`\<\[`string`, `string`\]\> + +Returns an ES6 `Iterator` over each of the name-value pairs in the query. +Each item of the iterator is a JavaScript `Array`. The first item of the `Array` is the `name`, the second item of the `Array` is the `value`. + +Alias for `urlSearchParams[@@iterator]()`. + +###### Returns + +`IterableIterator`\<\[`string`, `string`\]\> + +##### forEach() + +> **forEach**\<`TThis`\>(`fn`: (`this`: `TThis`, `value`: `string`, `name`: `string`, `searchParams`: [`URLSearchParams`](#urlsearchparams-1)) => `void`, `thisArg?`: `TThis`): `void` + +Iterates over each name-value pair in the query and invokes the given function. + +```js +const myURL = new URL('https://example.org/?a=b&c=d'); +myURL.searchParams.forEach((value, name, searchParams) => { + console.log(name, value, myURL.searchParams === searchParams); +}); +// Prints: +// a b true +// c d true +``` + +###### Type Parameters + +| Type Parameter | Default type | +| ------ | ------ | +| `TThis` | [`URLSearchParams`](#urlsearchparams-1) | + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `fn` | (`this`: `TThis`, `value`: `string`, `name`: `string`, `searchParams`: [`URLSearchParams`](#urlsearchparams-1)) => `void` | Invoked for each name-value pair in the query | +| `thisArg?` | `TThis` | To be used as `this` value for when `fn` is called | + +###### Returns + +`void` + +##### get() + +> **get**(`name`: `string`): `string` \| `null` + +Returns the value of the first name-value pair whose name is `name`. If there +are no such pairs, `null` is returned. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `name` | `string` | + +###### Returns + +`string` \| `null` + +or `null` if there is no name-value pair with the given `name`. + +##### has() + +> **has**(`name`: `string`, `value?`: `string`): `boolean` + +Checks if the `URLSearchParams` object contains key-value pair(s) based on `name` and an optional `value` argument. + +If `value` is provided, returns `true` when name-value pair with +same `name` and `value` exists. + +If `value` is not provided, returns `true` if there is at least one name-value +pair whose name is `name`. + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `name` | `string` | +| `value?` | `string` | + +###### Returns + +`boolean` + +##### keys() + +> **keys**(): `IterableIterator`\<`string`\> + +Returns an ES6 `Iterator` over the names of each name-value pair. + +```js +const params = new URLSearchParams('foo=bar&foo=baz'); +for (const name of params.keys()) { + console.log(name); +} +// Prints: +// foo +// foo +``` + +###### Returns + +`IterableIterator`\<`string`\> + +##### set() + +> **set**(`name`: `string`, `value`: `string`): `void` + +Sets the value in the `URLSearchParams` object associated with `name` to `value`. If there are any pre-existing name-value pairs whose names are `name`, +set the first such pair's value to `value` and remove all others. If not, +append the name-value pair to the query string. + +```js +const params = new URLSearchParams(); +params.append('foo', 'bar'); +params.append('foo', 'baz'); +params.append('abc', 'def'); +console.log(params.toString()); +// Prints foo=bar&foo=baz&abc=def + +params.set('foo', 'def'); +params.set('xyz', 'opq'); +console.log(params.toString()); +// Prints foo=def&abc=def&xyz=opq +``` + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `name` | `string` | +| `value` | `string` | + +###### Returns + +`void` + +##### sort() + +> **sort**(): `void` + +Sort all existing name-value pairs in-place by their names. Sorting is done +with a [stable sorting algorithm](https://en.wikipedia.org/wiki/Sorting_algorithm#Stability), so relative order between name-value pairs +with the same name is preserved. + +This method can be used, in particular, to increase cache hits. + +```js +const params = new URLSearchParams('query[]=abc&type=search&query[]=123'); +params.sort(); +console.log(params.toString()); +// Prints query%5B%5D=abc&query%5B%5D=123&type=search +``` + +###### Returns + +`void` + +##### toString() + +> **toString**(): `string` + +Returns the search parameters serialized as a string, with characters +percent-encoded where necessary. + +###### Returns + +`string` + +##### values() + +> **values**(): `IterableIterator`\<`string`\> + +Returns an ES6 `Iterator` over the values of each name-value pair. + +###### Returns + +`IterableIterator`\<`string`\> + +## Interfaces + +### Url + +#### Properties + +##### auth + +> **auth**: `string` \| `null` + +##### hash + +> **hash**: `string` \| `null` + +##### host + +> **host**: `string` \| `null` + +##### hostname + +> **hostname**: `string` \| `null` + +##### href + +> **href**: `string` + +##### path + +> **path**: `string` \| `null` + +##### pathname + +> **pathname**: `string` \| `null` + +##### port + +> **port**: `string` \| `null` + +##### protocol + +> **protocol**: `string` \| `null` + +##### query + +> **query**: `string` \| `null` + +##### search + +> **search**: `string` \| `null` + +##### slashes + +> **slashes**: `boolean` \| `null` + +*** + +### URLFormatOptions + +#### Properties + +##### auth? + +> `optional` **auth**: `boolean` + +`true` if the serialized URL string should include the username and password, `false` otherwise. + +###### Default + +```ts +true +``` + +##### fragment? + +> `optional` **fragment**: `boolean` + +`true` if the serialized URL string should include the fragment, `false` otherwise. + +###### Default + +```ts +true +``` + +##### search? + +> `optional` **search**: `boolean` + +`true` if the serialized URL string should include the search query, `false` otherwise. + +###### Default + +```ts +true +``` + +##### unicode? + +> `optional` **unicode**: `boolean` + +`true` if Unicode characters appearing in the host component of the URL string should be encoded directly as opposed to +being Punycode encoded. + +###### Default + +```ts +false +``` + +## Functions + +### domainToASCII() + +> **domainToASCII**(`domain`: `string`): `string` + +Returns the [Punycode](https://tools.ietf.org/html/rfc5891#section-4.4) ASCII serialization of the `domain`. If `domain` is an +invalid domain, the empty string is returned. + +It performs the inverse operation to [domainToUnicode](#domaintounicode). + +```js +import url from 'url'; + +console.log(url.domainToASCII('español.com')); +// Prints xn--espaol-zwa.com +console.log(url.domainToASCII('中文.com')); +// Prints xn--fiq228c.com +console.log(url.domainToASCII('xn--iñvalid.com')); +// Prints an empty string +``` + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `domain` | `string` | + +#### Returns + +`string` + +*** + +### domainToUnicode() + +> **domainToUnicode**(`domain`: `string`): `string` + +Returns the Unicode serialization of the `domain`. If `domain` is an invalid +domain, the empty string is returned. + +It performs the inverse operation to [domainToASCII](#domaintoascii). + +```js +import url from 'url'; + +console.log(url.domainToUnicode('xn--espaol-zwa.com')); +// Prints español.com +console.log(url.domainToUnicode('xn--fiq228c.com')); +// Prints 中文.com +console.log(url.domainToUnicode('xn--iñvalid.com')); +// Prints an empty string +``` + +#### Parameters + +| Parameter | Type | +| ------ | ------ | +| `domain` | `string` | + +#### Returns + +`string` + +*** + +### fileURLToPath() + +> **fileURLToPath**(`url`: `string` \| [`URL`](#url)): `string` + +This function ensures the correct decodings of percent-encoded characters as +well as ensuring a cross-platform valid absolute path string. + +```js +import { fileURLToPath } from 'url'; + +const __filename = fileURLToPath(import.meta.url); + +new URL('file:///C:/path/').pathname; // Incorrect: /C:/path/ +fileURLToPath('file:///C:/path/'); // Correct: C:\path\ (Windows) + +new URL('file://nas/foo.txt').pathname; // Incorrect: /foo.txt +fileURLToPath('file://nas/foo.txt'); // Correct: \\nas\foo.txt (Windows) + +new URL('file:///你好.txt').pathname; // Incorrect: /%E4%BD%A0%E5%A5%BD.txt +fileURLToPath('file:///你好.txt'); // Correct: /你好.txt (POSIX) + +new URL('file:///hello world').pathname; // Incorrect: /hello%20world +fileURLToPath('file:///hello world'); // Correct: /hello world (POSIX) +``` + +#### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `url` | `string` \| [`URL`](#url) | The file URL string or URL object to convert to a path. | + +#### Returns + +`string` + +The fully-resolved platform-specific Node.js file path. + +*** + +### format() + +> **format**(`urlObject`: [`URL`](#url), `options?`: [`URLFormatOptions`](#urlformatoptions)): `string` + +The `url.format()` method returns a formatted URL string derived from `urlObject`. + +```js +const url = require('url'); +url.format({ + protocol: 'https', + hostname: 'example.com', + pathname: '/some/path', + query: { + page: 1, + format: 'json', + }, +}); + +// => 'https://example.com/some/path?page=1&format=json' +``` + +If `urlObject` is not an object or a string, `url.format()` will throw a `TypeError`. + +The formatting process operates as follows: + +* A new empty string `result` is created. +* If `urlObject.protocol` is a string, it is appended as-is to `result`. +* Otherwise, if `urlObject.protocol` is not `undefined` and is not a string, an `Error` is thrown. +* For all string values of `urlObject.protocol` that _do not end_ with an ASCII +colon (`:`) character, the literal string `:` will be appended to `result`. +* If either of the following conditions is true, then the literal string `//` will be appended to `result`: + * `urlObject.slashes` property is true; + * `urlObject.protocol` begins with `http`, `https`, `ftp`, `gopher`, or `file`; +* If the value of the `urlObject.auth` property is truthy, and either `urlObject.host` or `urlObject.hostname` are not `undefined`, the value of `urlObject.auth` will be coerced into a string +and appended to `result` followed by the literal string `@`. +* If the `urlObject.host` property is `undefined` then: + * If the `urlObject.hostname` is a string, it is appended to `result`. + * Otherwise, if `urlObject.hostname` is not `undefined` and is not a string, + an `Error` is thrown. + * If the `urlObject.port` property value is truthy, and `urlObject.hostname` is not `undefined`: + * The literal string `:` is appended to `result`, and + * The value of `urlObject.port` is coerced to a string and appended to `result`. +* Otherwise, if the `urlObject.host` property value is truthy, the value of `urlObject.host` is coerced to a string and appended to `result`. +* If the `urlObject.pathname` property is a string that is not an empty string: + * If the `urlObject.pathname` _does not start_ with an ASCII forward slash + (`/`), then the literal string `'/'` is appended to `result`. + * The value of `urlObject.pathname` is appended to `result`. +* Otherwise, if `urlObject.pathname` is not `undefined` and is not a string, an `Error` is thrown. +* If the `urlObject.search` property is `undefined` and if the `urlObject.query`property is an `Object`, the literal string `?` is appended to `result` followed by the output of calling the +`querystring` module's `stringify()` method passing the value of `urlObject.query`. +* Otherwise, if `urlObject.search` is a string: + * If the value of `urlObject.search` _does not start_ with the ASCII question + mark (`?`) character, the literal string `?` is appended to `result`. + * The value of `urlObject.search` is appended to `result`. +* Otherwise, if `urlObject.search` is not `undefined` and is not a string, an `Error` is thrown. +* If the `urlObject.hash` property is a string: + * If the value of `urlObject.hash` _does not start_ with the ASCII hash (`#`) + character, the literal string `#` is appended to `result`. + * The value of `urlObject.hash` is appended to `result`. +* Otherwise, if the `urlObject.hash` property is not `undefined` and is not a +string, an `Error` is thrown. +* `result` is returned. + +#### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `urlObject` | [`URL`](#url) | A URL object (as returned by `url.parse()` or constructed otherwise). If a string, it is converted to an object by passing it to `url.parse()`. | +| `options?` | [`URLFormatOptions`](#urlformatoptions) | - | + +#### Returns + +`string` + +#### Legacy + +Use the WHATWG URL API instead. + +*** + +### ~~parse()~~ + +> **parse**(`urlString`: `string`, `parseQueryString?`: `boolean`, `slashesDenoteHost?`: `boolean`): [`Url`](#url-1) + +The `url.parse()` method takes a URL string, parses it, and returns a URL +object. + +A `TypeError` is thrown if `urlString` is not a string. + +A `URIError` is thrown if the `auth` property is present but cannot be decoded. + +`url.parse()` uses a lenient, non-standard algorithm for parsing URL +strings. It is prone to security issues such as [host name spoofing](https://hackerone.com/reports/678487) and incorrect handling of usernames and passwords. Do not use with untrusted +input. CVEs are not issued for `url.parse()` vulnerabilities. Use the `WHATWG URL` API instead. + +#### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `urlString` | `string` | The URL string to parse. | +| `parseQueryString?` | `boolean` | If `true`, the `query` property will always be set to an object returned by the querystring module's `parse()` method. If `false`, the `query` property on the returned URL object will be an unparsed, undecoded string. | +| `slashesDenoteHost?` | `boolean` | If `true`, the first token after the literal string `//` and preceding the next `/` will be interpreted as the `host`. For instance, given `//foo/bar`, the result would be `{host: 'foo', pathname: '/bar'}` rather than `{pathname: '//foo/bar'}`. | + +#### Returns + +[`Url`](#url-1) + +#### Deprecated + +Use the WHATWG URL API instead. + +*** + +### pathToFileURL() + +> **pathToFileURL**(`path`: `string`): [`URL`](#url) + +This function ensures that `path` is resolved absolutely, and that the URL +control characters are correctly encoded when converting into a File URL. + +```js +import { pathToFileURL } from 'url'; + +new URL('/foo#1', 'file:'); // Incorrect: file:///foo#1 +pathToFileURL('/foo#1'); // Correct: file:///foo%231 (POSIX) + +new URL('/some/path%.c', 'file:'); // Incorrect: file:///some/path%.c +pathToFileURL('/some/path%.c'); // Correct: file:///some/path%25.c (POSIX) +``` + +#### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `path` | `string` | The path to convert to a File URL. | + +#### Returns + +[`URL`](#url) + +The file URL object. + +*** + +### urlToHttpOptions() + +> **urlToHttpOptions**(`url`: [`URL`](#url)): `Object` + +This utility function converts a URL object into an ordinary options object as +expected by the `http.request()` and `https.request()` APIs. + +```js +import { urlToHttpOptions } from 'url'; +const myURL = new URL('https://a:b@測試?abc#foo'); + +console.log(urlToHttpOptions(myURL)); +/* +{ + protocol: 'https:', + hostname: 'xn--g6w251d', + hash: '#foo', + search: '?abc', + pathname: '/', + path: '/?abc', + href: 'https://a:b@xn--g6w251d/?abc#foo', + auth: 'a:b' +} + +``` + +#### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `url` | [`URL`](#url) | The `WHATWG URL` object to convert to an options object. | + +#### Returns + +`Object` + +Options object diff --git a/src/reference/sdks/backend/environment.md b/src/reference/sdks/backend/environment.md index e9a110f..4947f50 100644 --- a/src/reference/sdks/backend/environment.md +++ b/src/reference/sdks/backend/environment.md @@ -1,5 +1,39 @@ # Environment +### Environment + +> **Environment** = `object` + +A saved immutable Environment. + +#### Properties + +##### id + +> `readonly` **id**: [`ID`](shared.md#id) + +The ID of the environment. + +##### name + +> `readonly` **name**: `string` + +The name of the environment. + +##### variables + +> `readonly` **variables**: [`EnvironmentVariable`](#environmentvariable)[] + +The variables of the environment. + +##### version + +> `readonly` **version**: `number` + +The version of the environment. + +*** + ### EnvironmentSDK > **EnvironmentSDK** = `object` @@ -8,6 +42,70 @@ The SDK for the Environment service. #### Methods +##### createEnvironment() + +> **createEnvironment**(`input`: [`CreateEnvironmentInput`](other.md#createenvironmentinput)): `Promise`\<[`Environment`](#environment)\> + +Create a new environment. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `input` | [`CreateEnvironmentInput`](other.md#createenvironmentinput) | The input for the creation. | + +###### Returns + +`Promise`\<[`Environment`](#environment)\> + +The created environment. + +##### deleteEnvironment() + +> **deleteEnvironment**(`id`: [`ID`](shared.md#id)): `Promise`\<`void`\> + +Delete an environment by its ID. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `id` | [`ID`](shared.md#id) | The ID of the environment. | + +###### Returns + +`Promise`\<`void`\> + +##### getEnvironment() + +> **getEnvironment**(`id`: [`ID`](shared.md#id)): `Promise`\<[`Environment`](#environment) \| `undefined`\> + +Get an environment by its ID. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `id` | [`ID`](shared.md#id) | The ID of the environment. | + +###### Returns + +`Promise`\<[`Environment`](#environment) \| `undefined`\> + +The environment or undefined if not found. + +##### getEnvironments() + +> **getEnvironments**(): `Promise`\<[`Environment`](#environment)[]\> + +Get all the environments. + +###### Returns + +`Promise`\<[`Environment`](#environment)[]\> + +An array of [Environment](#environment) + ##### getVar() > **getVar**(`name`: `string`): `string` \| `undefined` @@ -78,6 +176,40 @@ await sdk.env.setVar({ }); ``` +##### updateEnvironment() + +> **updateEnvironment**(`id`: [`ID`](shared.md#id), `input`: [`UpdateEnvironmentInput`](other.md#updateenvironmentinput)): `Promise`\<[`Environment`](#environment)\> + +Update an environment. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `id` | [`ID`](shared.md#id) | The ID of the environment. | +| `input` | [`UpdateEnvironmentInput`](other.md#updateenvironmentinput) | The input for the update. | + +###### Returns + +`Promise`\<[`Environment`](#environment)\> + +The updated environment. + +###### Throws + +If the version passed in is not equal to the current version of the environment. + +###### Example + +```js +const environment = await sdk.env.getEnvironment(id); +await sdk.env.updateEnvironment(id, { + version: environment.version, + name: "new name", + variables: [{ name: "USER_SECRET", value: "new secret value", secret: true }], +}); +``` + *** ### EnvironmentVariable @@ -148,7 +280,6 @@ Name of the environment variable > **secret**: `boolean` If the environment variable should be treated as secret. -Secrets are encrypted on the disk. ###### Default diff --git a/src/reference/sdks/backend/index.md b/src/reference/sdks/backend/index.md index 4387152..aa58f0c 100644 --- a/src/reference/sdks/backend/index.md +++ b/src/reference/sdks/backend/index.md @@ -1,5 +1,8 @@ # @caido/sdk-backend +This is the reference for the backend SDK used by backend plugins. +[SDK](#events) is the main interface that provides access to various services and functionalities. + ## SDK ### SDK diff --git a/src/reference/sdks/backend/other.md b/src/reference/sdks/backend/other.md index 080841a..a0e47b6 100644 --- a/src/reference/sdks/backend/other.md +++ b/src/reference/sdks/backend/other.md @@ -230,6 +230,52 @@ Usually used for unexpected behaviors. *** +### CreateEnvironmentInput + +> **CreateEnvironmentInput** = `object` + +#### Properties + +##### name + +> **name**: `string` + +The name of the environment. + +##### variables + +> **variables**: [`EnvironmentVariable`](environment.md#environmentvariable)[] + +The variables of the environment. + +*** + +### EnvironmentVariableInput + +> **EnvironmentVariableInput** = `object` + +#### Properties + +##### name + +> **name**: `string` + +The name of the environment variable. + +##### secret + +> **secret**: `boolean` + +If the environment variable should be treated as secret. + +##### value + +> **value**: `string` + +The value of the environment variable. + +*** + ### PageInfo > **PageInfo** = `object` @@ -275,3 +321,30 @@ Information on the current page of paginated data. ##### lastInsertRowid > **lastInsertRowid**: `number` + +*** + +### UpdateEnvironmentInput + +> **UpdateEnvironmentInput** = `object` + +#### Properties + +##### name? + +> `optional` **name**: `string` + +The name of the environment. + +##### variables? + +> `optional` **variables**: [`EnvironmentVariableInput`](#environmentvariableinput)[] + +The variables of the environment. + +##### version + +> **version**: `number` + +The version of the environment to update. +If not equal to the current version, the update will fail. diff --git a/src/reference/sdks/frontend/index.md b/src/reference/sdks/frontend/index.md index 5273a19..643d174 100644 --- a/src/reference/sdks/frontend/index.md +++ b/src/reference/sdks/frontend/index.md @@ -1,5 +1,8 @@ # @caido/sdk-frontend +This is the reference for the frontend SDK used by frontend plugins. +[Caido](#caido-t-e) is the main interface that provides access to various services and functionalities. + ## SDK ### Caido diff --git a/src/reference/sdks/workflow/environment.md b/src/reference/sdks/workflow/environment.md index e9a110f..4947f50 100644 --- a/src/reference/sdks/workflow/environment.md +++ b/src/reference/sdks/workflow/environment.md @@ -1,5 +1,39 @@ # Environment +### Environment + +> **Environment** = `object` + +A saved immutable Environment. + +#### Properties + +##### id + +> `readonly` **id**: [`ID`](shared.md#id) + +The ID of the environment. + +##### name + +> `readonly` **name**: `string` + +The name of the environment. + +##### variables + +> `readonly` **variables**: [`EnvironmentVariable`](#environmentvariable)[] + +The variables of the environment. + +##### version + +> `readonly` **version**: `number` + +The version of the environment. + +*** + ### EnvironmentSDK > **EnvironmentSDK** = `object` @@ -8,6 +42,70 @@ The SDK for the Environment service. #### Methods +##### createEnvironment() + +> **createEnvironment**(`input`: [`CreateEnvironmentInput`](other.md#createenvironmentinput)): `Promise`\<[`Environment`](#environment)\> + +Create a new environment. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `input` | [`CreateEnvironmentInput`](other.md#createenvironmentinput) | The input for the creation. | + +###### Returns + +`Promise`\<[`Environment`](#environment)\> + +The created environment. + +##### deleteEnvironment() + +> **deleteEnvironment**(`id`: [`ID`](shared.md#id)): `Promise`\<`void`\> + +Delete an environment by its ID. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `id` | [`ID`](shared.md#id) | The ID of the environment. | + +###### Returns + +`Promise`\<`void`\> + +##### getEnvironment() + +> **getEnvironment**(`id`: [`ID`](shared.md#id)): `Promise`\<[`Environment`](#environment) \| `undefined`\> + +Get an environment by its ID. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `id` | [`ID`](shared.md#id) | The ID of the environment. | + +###### Returns + +`Promise`\<[`Environment`](#environment) \| `undefined`\> + +The environment or undefined if not found. + +##### getEnvironments() + +> **getEnvironments**(): `Promise`\<[`Environment`](#environment)[]\> + +Get all the environments. + +###### Returns + +`Promise`\<[`Environment`](#environment)[]\> + +An array of [Environment](#environment) + ##### getVar() > **getVar**(`name`: `string`): `string` \| `undefined` @@ -78,6 +176,40 @@ await sdk.env.setVar({ }); ``` +##### updateEnvironment() + +> **updateEnvironment**(`id`: [`ID`](shared.md#id), `input`: [`UpdateEnvironmentInput`](other.md#updateenvironmentinput)): `Promise`\<[`Environment`](#environment)\> + +Update an environment. + +###### Parameters + +| Parameter | Type | Description | +| ------ | ------ | ------ | +| `id` | [`ID`](shared.md#id) | The ID of the environment. | +| `input` | [`UpdateEnvironmentInput`](other.md#updateenvironmentinput) | The input for the update. | + +###### Returns + +`Promise`\<[`Environment`](#environment)\> + +The updated environment. + +###### Throws + +If the version passed in is not equal to the current version of the environment. + +###### Example + +```js +const environment = await sdk.env.getEnvironment(id); +await sdk.env.updateEnvironment(id, { + version: environment.version, + name: "new name", + variables: [{ name: "USER_SECRET", value: "new secret value", secret: true }], +}); +``` + *** ### EnvironmentVariable @@ -148,7 +280,6 @@ Name of the environment variable > **secret**: `boolean` If the environment variable should be treated as secret. -Secrets are encrypted on the disk. ###### Default diff --git a/src/reference/sdks/workflow/index.md b/src/reference/sdks/workflow/index.md index 54afd0e..144eb77 100644 --- a/src/reference/sdks/workflow/index.md +++ b/src/reference/sdks/workflow/index.md @@ -1,5 +1,8 @@ # @caido/sdk-workflow +This is the reference for the workflow SDK used by JS Nodes. +[SDK](#sdk) is the main interface that provides access to various services and functionalities. + ## SDK ### SDK diff --git a/src/reference/sdks/workflow/other.md b/src/reference/sdks/workflow/other.md index 00c9e27..14956ba 100644 --- a/src/reference/sdks/workflow/other.md +++ b/src/reference/sdks/workflow/other.md @@ -85,6 +85,52 @@ Usually used for unexpected behaviors. *** +### CreateEnvironmentInput + +> **CreateEnvironmentInput** = `object` + +#### Properties + +##### name + +> **name**: `string` + +The name of the environment. + +##### variables + +> **variables**: [`EnvironmentVariable`](environment.md#environmentvariable)[] + +The variables of the environment. + +*** + +### EnvironmentVariableInput + +> **EnvironmentVariableInput** = `object` + +#### Properties + +##### name + +> **name**: `string` + +The name of the environment variable. + +##### secret + +> **secret**: `boolean` + +If the environment variable should be treated as secret. + +##### value + +> **value**: `string` + +The value of the environment variable. + +*** + ### PageInfo > **PageInfo** = `object` @@ -108,3 +154,30 @@ Information on the current page of paginated data. ##### startCursor > **startCursor**: [`Cursor`](shared.md#cursor) + +*** + +### UpdateEnvironmentInput + +> **UpdateEnvironmentInput** = `object` + +#### Properties + +##### name? + +> `optional` **name**: `string` + +The name of the environment. + +##### variables? + +> `optional` **variables**: [`EnvironmentVariableInput`](#environmentvariableinput)[] + +The variables of the environment. + +##### version + +> **version**: `number` + +The version of the environment to update. +If not equal to the current version, the update will fail. From bfdcc5e6c9dd3905b7366eb526452b8853362679 Mon Sep 17 00:00:00 2001 From: Emile Fugulin Date: Wed, 11 Feb 2026 18:27:38 -0500 Subject: [PATCH 3/3] Fix bugs --- eslint.config.mjs | 24 +++++++++++++++--------- src/reference/modules/index.md | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 03d9648..5799d11 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,19 +1,25 @@ -import { defaultConfig } from '@caido/eslint-config'; -import markdownPlugin from '@eslint/markdown'; +import { defaultConfig } from "@caido/eslint-config"; +import markdownPlugin from "@eslint/markdown"; /** @type {import('eslint').Linter.Config } */ export default [ { - ignores: [".vitepress/cache", ".vitepress/dist", "./src/reference/sdks", "./src/reference/modules"], + ignores: [ + ".vitepress/cache", + ".vitepress/dist", + "./src/reference/sdks", + "./src/reference/modules", + "src/reference/api.md", + ], }, - ...(markdownPlugin.configs.recommended.map(config => ({ + ...markdownPlugin.configs.recommended.map((config) => ({ ...config, languageOptions: { - frontmatter: "yaml" - } - }))), - ...(defaultConfig().map(config => ({ + frontmatter: "yaml", + }, + })), + ...defaultConfig().map((config) => ({ ...config, files: ["**/*.ts", "**/*.vue"], - }))), + })), ]; diff --git a/src/reference/modules/index.md b/src/reference/modules/index.md index 10121de..c29dd44 100644 --- a/src/reference/modules/index.md +++ b/src/reference/modules/index.md @@ -27,7 +27,7 @@ Some elements are similar to `Node.JS`, but some imports will be different and s | [path](llrt/path/index.md) | Path transformation | `path` | ✘ | | [sqlite](extra/sqlite.md) | SQlite access | `sqlite` | ✘ | | [stream](llrt/stream/stream.md) | Streams (basic) | `stream` | ✔︎ | -| [stream/web](llrt/web/index.md) | Streams Web | `stream/web` | ✘ | +| [stream/web](llrt/stream/web/index.md) | Streams Web | `stream/web` | ✘ | | [string_decoder](llrt/string_decoder.md) | String Decoder | `string_decoder` | ✘ | | [timers](extra/timers.md) | Timers | N/A | ✔︎ | | [url](llrt/url/index.md) | URL utilities | `url` | ✔︎ |