@sigiljs/sigil
Version:
TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating
86 lines (85 loc) • 3.42 kB
TypeScript
import { IncomingHttpHeaders } from 'node:http';
type RawHeaders = readonly string[];
type Dict = NodeJS.Dict<string | string[]>;
type KeyOf<H, S> = keyof (H & S);
export default class IncomingHeaders<Schema extends Record<string, string | string[]> = Record<string, string | string[]>, H extends Dict = IncomingHttpHeaders> {
#private;
constructor(raw?: RawHeaders | Dict);
/**
* Gets the link associated with the current map instance.
*
* @return link to the internal map.
*/
get link(): Record<string, string[]>;
/**
* Retrieves all stored cookies as key-value pairs.
*
* @return {Record<string, string>} an object containing cookie names as keys and their corresponding values.
*/
get cookies(): Record<string, string>;
/**
* Retrieves the value of a cookie by its name.
*
* @param {string} name name of the cookie to retrieve.
* @return {string | undefined} value of the cookie if found, or undefined if the cookie does not exist.
*/
getCookie(name: string): string | undefined;
/**
* Returns an iterator for traversing the key-value pair entries stored in the internal map.
* Each key-value pair is returned as a two-element array.
*
* @return {IterableIterator<[string, string]>} an iterator that yields key-value pairs as arrays.
*/
entries(): IterableIterator<[string, string]>;
/**
* Returns a JSON-like object of parameters, taking the first value for each key.
* @returns object mapping each key to its first value.
*/
json(): Schema;
/**
* Checks if a given key exists in the internal map.
*
* @param name key to check for existence. It can either be a specific type parameter of `Schema` or any string.
* @return {boolean} true if the key exists in the map, otherwise false.
*/
has<T extends KeyOf<Schema, H>>(name: T | string): boolean;
/**
* Retrieves the first value associated with a given key.
*
* @param name key whose associated value needs to be retrieved.
* @return {string | null} first value associated with the specified key if it exists, otherwise returns null.
*/
get<T extends KeyOf<Schema, H>>(name: T): string | null;
/**
* Retrieves all values associated with the specified key from the internal map.
*
* @param name key whose associated values are to be retrieved.
* @return {string[]} array of strings containing the values associated with the specified key.
* Returns an empty array if no values are found.
*/
getAll<T extends KeyOf<Schema, H>>(name: T): string[];
/**
* Sets or replaces the header with the given name and value.
*
* @param name header name (typed if using a Schema).
* @param value header value.
* @returns instance for chaining.
*/
set<T extends KeyOf<Schema, H>>(name: T, value: string): this;
/**
* Appends a value to an existing header or creates it if absent.
*
* @param name header name.
* @param value value to append.
* @returns instance for chaining.
*/
append<T extends KeyOf<Schema, H>>(name: T, value: string): this;
/**
* Deletes a header by name.
*
* @param name header name to delete.
* @returns instance for chaining.
*/
delete<T extends KeyOf<Schema, H>>(name: T): this;
}
export {};