Reqor Namespace
Types and classes exposed under the Reqor namespace.
Classes
Reqor.Error
Error instance used by Reqor.
Constructor
ts
new Reqor.Error(message: string, sub?: string)Creates a new Reqor error with an optional sub-message.
Reqor.Headers
Headers returned in a Reqor Response.
Constructor
ts
new Reqor.Headers(original: globalThis.Headers)Creates a new Headers instance wrapping the original globalThis.Headers.
Reqor.Status
Represents the status of a response.
Constructor
ts
new Reqor.Status(status: number, statusText: string)Creates a new Status instance.
Properties
| Property | Type | Description |
|---|---|---|
status | number | The HTTP status code. |
text | string | The status text. |
ok | boolean | Whether the status is in the 200-299 range. |
redirected | boolean | Whether the response was redirected. |
clientError | boolean | Whether the status is in the 400-499 range. |
serverError | boolean | Whether the status is in the 500-599 range. |
Methods
.set(status: number, statusText?: string): void
| Argument | Type | Description |
|---|---|---|
status | number | The new status code. |
statusText | string | Optional new status text. |
Sets the status and status text.
.toString(): string
Returns the status as a string.
.valueOf(): number
Returns the status code as a number.
[Symbol.toPrimitive](hint: string): string | number
Returns the status code or string representation based on hint.
Reqor.Type
Represents the type of response.
Constructor
ts
new Reqor.Type(type: string)Creates a new Type instance.
Properties
| Property | Type | Description |
|---|---|---|
value | string | The response type value. |
Methods
.isBasic(): boolean
Returns true if the type is "basic".
.isCors(): boolean
Returns true if the type is "cors".
.isError(): boolean
Returns true if the type is "error".
.isOpaque(): boolean
Returns true if the type is "opaque".
.isOpaqueRedirect(): boolean
Returns true if the type is "opaqueredirect".
.toString(): string
Returns the type value as string.
.valueOf(): string
Returns the type value.
[Symbol.toPrimitive](_hint: string): string
Returns the type value.
Reqor.Body
Represents the body of a response.
Constructor
ts
new Reqor.Body(response: globalThis.Response)Creates a new Body instance.
Properties
| Property | Type | Description |
|---|---|---|
stream | ReadableStream<Uint8Array> | null | The readable stream of the body. |
used | boolean | Whether the body has been consumed. |
Methods
.pump(onChunk: (chunk: Uint8Array) => void): Promise<void>
| Argument | Type | Description |
|---|---|---|
onChunk | (chunk: Uint8Array) => void | Callback for each chunk. |
Pumps the body stream through the callback.
.pipeTo(dest: WritableStream<Uint8Array>): Promise<void> | undefined
| Argument | Type | Description |
|---|---|---|
dest | WritableStream<Uint8Array> | Destination writable stream. |
Pipes the body to the destination.
.pipeThrough<T>(transform: TransformStream<Uint8Array, T>): ReadableStream<T> | undefined
| Argument | Type | Description |
|---|---|---|
transform | TransformStream<Uint8Array, T> | Transform stream. |
Pipes through a transform stream.
.json<T = any>(): Promise<T>
Parses the body as JSON.
.text(): Promise<string>
Reads the body as text.
.arrayBuffer(): Promise<ArrayBuffer>
Reads the body as ArrayBuffer.
.blob(): Promise<Blob>
Reads the body as Blob.
.formData(): Promise<FormData>
Reads the body as FormData.
Interfaces
Reqor.ResponseLater
Interface for delayed responses.
Properties
activated:boolean- Whether the response activated or not.canceled:boolean- Whether the delayed request has been canceled.cancel:() => boolean- Cancels the delayed request before or during activation. Returns true when cancellation was applied.done:Promise<void>- Resolves when delayed request scheduling completes.
Reqor.Response
Response returned by reqor.
Properties
| Property | Type | Description |
|---|---|---|
raw | globalThis.Response | Raw Response returned by fetch(). |
headers | Reqor.Headers | A easier way to use Response.headers. |
ok | boolean | Whether the response was successful (status in the range 200-299). |
redirected | boolean | Whether the response is the result of a request which was redirected. |
status | Reqor.Status | Status of the response. |
statusText | string | The status message corresponding to the HTTP status code. |
type | Reqor.Type | Type of response. |
url | string | The URL of the response. |
Functions
Reqor.createStatus(status: number, statusText: string): Status
| Argument | Type | Description |
|---|---|---|
status | number | The status code. |
statusText | string | The status text. |
Creates a new Status instance.
Reqor.createType(type: string): Type
| Argument | Type | Description |
|---|---|---|
type | string | The response type. |
Creates a new Type instance.
Namespaces
Reqor.Headers.Map
Interface for header maps.
Types
Reqor.Headers.Map
ts
interface Reqor.Headers.Map {
[key: string]: any;
[key: symbol]: any;
new?: (name: string, value?: any) => void \| ((value: any) => void);
}Creates a new Key-Value in the header.
Functions
Reqor.Headers.value(headers: globalThis.Headers, k: string, v?: any): (value?: any) => any | undefined
| Argument | Type | Description |
|---|---|---|
headers | globalThis.Headers | The headers object. |
k | string | The key. |
v | any | Optional value. |
Returns a function to get or set header value.
Reqor.Headers.HTTPHeaders
Namespace for HTTP header utilities.
Types
ValidityCheck
ts
type ValidityCheck = string[] \| ((value?: string) => boolean)Type for validity checks.
HeaderPrimitive
ts
type HeaderPrimitive = string \| number \| booleanPrimitive types for headers.
HeaderMode
ts
type HeaderMode = "mime" \| "mime-array" \| "valid-string" \| "valid-string-array" \| "any-string" \| "any-string-array" \| "number" \| "number-array" \| "string-bool" \| "string-bool-array"Modes for header controllers.
HeaderController
ts
type HeaderController = MIME \| MIME_ARRAY \| VALID_STRING \| VALID_STRING_ARRAY \| ANY_STRING \| ANY_STRING_ARRAY \| NUMBER_STRING \| NUMBER_ARRAY \| STRING_BOOL \| STRING_BOOL_ARRAYUnion of header controller types.
Constants
contentTypeValidBases
ts
readonly ["application", "audio", "font", "example", "image", "message", "model", "multipart", "text", "video", "*"]Valid content type bases.
Classes
MIME
Represents a MIME type header.
Constructor
ts
new MIME(h: globalThis.Headers, key: string, defaultVal?: string)Creates a new MIME instance.
Properties
| Property | Type | Description |
|---|---|---|
_value | string | The MIME value. |
_h | globalThis.Headers | The headers object. |
_key | string | The header key. |
Methods
.set(val: string): void
| Argument | Type | Description |
|---|---|---|
val | string | The MIME value. |
Sets the MIME value.
.base(base: string): this
| Argument | Type | Description |
|---|---|---|
base | string | The base type. |
Sets the base of the MIME type.
.subtype(sub: string): this
| Argument | Type | Description |
|---|---|---|
sub | string | The subtype. |
Sets the subtype of the MIME type.
.toString(): string
Returns the MIME value as string.
.valueOf(): string
Returns the MIME value.
[Symbol.toPrimitive](hint: string): string | number
Returns the MIME value.
MIME_ARRAY
Represents an array of MIME types.
Constructor
ts
new MIME_ARRAY(h: globalThis.Headers, key: string, defaultVal?: string)Creates a new MIME_ARRAY instance.
Properties
| Property | Type | Description |
|---|---|---|
length | number | The length of the array. |
array | MIME[] | The array of MIME instances. |
Methods
.set(val: string | string[] | MIME[]): void
| Argument | Type | Description |
|---|---|---|
val | string | string[] | MIME[] | The values to set. |
Sets the MIME array.
.at(index: number): MIME
| Argument | Type | Description |
|---|---|---|
index | number | The index. |
Gets the MIME at index.
.toString(): string
Returns the array as string.
.valueOf(): string
Returns the array value.
[Symbol.toPrimitive](hint: string): string | number
Returns the array value.
VALID_STRING
Represents a validated string header.
Constructor
ts
new VALID_STRING(h: globalThis.Headers, key: string, defaultVal: string \| undefined, validStrings: ValidityCheck)Creates a new VALID_STRING instance.
Properties
| Property | Type | Description |
|---|---|---|
value | string | The current value. |
validityArrayOrFunction | ValidityCheck | The validity check. |
key | string | The header key. |
Methods
.isValid(string: string): boolean
| Argument | Type | Description |
|---|---|---|
string | string | The string to check. |
Checks if the string is valid.
.set(string: string): void
| Argument | Type | Description |
|---|---|---|
string | string | The value to set. |
Sets the value if valid.
.toString(): string
Returns the value as string.
.valueOf(): string
Returns the value.
[Symbol.toPrimitive](hint: string): string | number
Returns the value.
ANY_STRING
Extends VALID_STRING with no validation.
Constructor
ts
new ANY_STRING(h: globalThis.Headers, key: string, defaultVal?: string)Creates a new ANY_STRING instance.
NUMBER_STRING
Extends VALID_STRING for numbers.
Constructor
ts
new NUMBER_STRING(h: globalThis.Headers, key: string, defaultVal?: string)Creates a new NUMBER_STRING instance.
Properties
| Property | Type | Description |
|---|---|---|
number | number | The numeric value. |
NUMBER_ARRAY
Represents an array of numbers.
Constructor
ts
new NUMBER_ARRAY(h: globalThis.Headers, key: string, defaultVals?: number[])Creates a new NUMBER_ARRAY instance.
Properties
| Property | Type | Description |
|---|---|---|
length | number | The length of the array. |
array | number[] | The array of numbers. |
Methods
.add(value: number): void
| Argument | Type | Description |
|---|---|---|
value | number | The value to add. |
Adds a number to the array.
.remove(value: number): void
| Argument | Type | Description |
|---|---|---|
value | number | The value to remove. |
Removes a number from the array.
.set(vals: number[]): void
| Argument | Type | Description |
|---|---|---|
vals | number[] | The values to set. |
Sets the array.
.at(index: number): number
| Argument | Type | Description |
|---|---|---|
index | number | The index. |
Gets the number at index.
.toString(): string
Returns the array as string.
.valueOf(): string
Returns the array value.
[Symbol.toPrimitive](hint: string): string | number
Returns the array value.
ANY_STRING_ARRAY
Represents an array of strings.
Constructor
ts
new ANY_STRING_ARRAY(h: globalThis.Headers, key: string, defaultVals?: string[])Creates a new ANY_STRING_ARRAY instance.
Properties
| Property | Type | Description |
|---|---|---|
length | number | The length of the array. |
array | string[] | The array of strings. |
Methods
.add(str: string): void
| Argument | Type | Description |
|---|---|---|
str | string | The string to add. |
Adds a string to the array.
.remove(str: string): void
| Argument | Type | Description |
|---|---|---|
str | string | The string to remove. |
Removes a string from the array.
.set(vals: string[]): void
| Argument | Type | Description |
|---|---|---|
vals | string[] | The values to set. |
Sets the array.
.at(index: number): string
| Argument | Type | Description |
|---|---|---|
index | number | The index. |
Gets the string at index.
.toString(): string
Returns the array as string.
.valueOf(): string
Returns the array value.
[Symbol.toPrimitive](hint: string): string | number
Returns the array value.
STRING_BOOL
Extends VALID_STRING for boolean strings.
Constructor
ts
new STRING_BOOL(h: globalThis.Headers, key: string, defaultVal?: string)Creates a new STRING_BOOL instance.
VALID_STRING_ARRAY
Represents an array of validated strings.
Constructor
ts
new VALID_STRING_ARRAY(h: globalThis.Headers, key: string, defaultVals: string[] \| undefined, validStrings: ValidityCheck)Creates a new VALID_STRING_ARRAY instance.
Properties
| Property | Type | Description |
|---|---|---|
length | number | The length of the array. |
array | string[] | The array of strings. |
Methods
.add(str: string): void
| Argument | Type | Description |
|---|---|---|
str | string | The string to add. |
Adds a string to the array if valid.
.remove(str: string): void
| Argument | Type | Description |
|---|---|---|
str | string | The string to remove. |
Removes a string from the array.
.set(vals: string[]): void
| Argument | Type | Description |
|---|---|---|
vals | string[] | The values to set. |
Sets the array if all valid.
.at(index: number): string
| Argument | Type | Description |
|---|---|---|
index | number | The index. |
Gets the string at index.
.toString(): string
Returns the array as string.
.valueOf(): string
Returns the array value.
[Symbol.toPrimitive](hint: string): string | number
Returns the array value.
STRING_BOOL_ARRAY
Extends VALID_STRING_ARRAY for boolean strings.
Constructor
ts
new STRING_BOOL_ARRAY(h: globalThis.Headers, key: string, defaultVals?: string[])Creates a new STRING_BOOL_ARRAY instance.
Functions
Reqor.Headers.HTTPHeaders.create(h: globalThis.Headers): Record<string, unknown>
| Argument | Type | Description |
|---|---|---|
h | globalThis.Headers | The headers object. |
Creates a record of header controllers.
Reqor.Headers.HTTPHeaders.header(h: globalThis.Headers, name: string): HeaderController & ((v?: any) => HeaderController)
| Argument | Type | Description |
|---|---|---|
h | globalThis.Headers | The headers object. |
name | string | The header name. |
Creates a header controller for the given name.
Reqor.Headers.HTTPHeaders.typed(h: globalThis.Headers, name: string, mode: HeaderMode, defaultValue: HeaderPrimitive | HeaderPrimitive[], validStrings?: ValidityCheck): HeaderController & ((v?: any) => HeaderController)
| Argument | Type | Description |
|---|---|---|
h | globalThis.Headers | The headers object. |
name | string | The header name. |
mode | HeaderMode | The header mode. |
defaultValue | HeaderPrimitive | HeaderPrimitive[] | The default value. |
validStrings | ValidityCheck | Optional validity check. |
Creates a typed header controller.
Reqor.Headers.HTTPHeaders.contentType(h: globalThis.Headers): HeaderController & ((v?: any) => HeaderController)
| Argument | Type | Description |
|---|---|---|
h | globalThis.Headers | The headers object. |
Creates a content-type header controller.
Reqor.Headers.HTTPHeaders.accept(h: globalThis.Headers): HeaderController & ((v?: any) => HeaderController)
| Argument | Type | Description |
|---|---|---|
h | globalThis.Headers | The headers object. |
Creates an accept header controller.
Reqor.Headers.HTTPHeaders.acceptEncoding(h: globalThis.Headers): HeaderController & ((v?: any) => HeaderController)
| Argument | Type | Description |
|---|---|---|
h | globalThis.Headers | The headers object. |
Creates an accept-encoding header controller.
Reqor.Headers.HTTPHeaders.acceptLanguage(h: globalThis.Headers): HeaderController & ((v?: any) => HeaderController)
| Argument | Type | Description |
|---|---|---|
h | globalThis.Headers | The headers object. |
Creates an accept-language header controller.
Reqor.Headers.HTTPHeaders.acceptPatch(h: globalThis.Headers): HeaderController & ((v?: any) => HeaderController)
| Argument | Type | Description |
|---|---|---|
h | globalThis.Headers | The headers object. |
Creates an accept-patch header controller.
Reqor.Headers.HTTPHeaders.acceptPost(h: globalThis.Headers): HeaderController & ((v?: any) => HeaderController)
| Argument | Type | Description |
|---|---|---|
h | globalThis.Headers | The headers object. |
Creates an accept-post header controller.
Reqor.Headers.HTTPHeaders.ContentType
Sub-namespace for content type utilities.
Constants
validBases
ts
readonly ["application", "audio", "font", "example", "image", "message", "model", "multipart", "text", "video", "*"]Valid content type bases.
Types
validBases
ts
type validBases = (typeof validBases)[number]Union of valid bases.
