@sigiljs/sigil
Version:
TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating
82 lines (81 loc) • 2.82 kB
TypeScript
type KeyOf<S, Q> = keyof (S & Q);
/**
* Container for URL query parameters with typed accessors.
* Supports initialization from multiple formats (string, array, object, URLSearchParams).
*
* @template QuerySchema Known query parameter keys and their expected value types.
*/
export default class IncomingSearchParams<QuerySchema extends Record<string, string> = Record<string, string>> {
#private;
/**
* Read any known query parameter as a string or null.
*/
getAny: <T extends KeyOf<QuerySchema, any>>(key: T) => string | null;
/**
* Constructs a new IncomingSearchParams instance.
*
* @param init initial parameters
*/
constructor(init?: string | string[][] | Record<string, string> | URLSearchParams);
/**
* Returns a JSON-like object of parameters, taking the first value for each key.
* @returns object mapping each key to its first value.
*/
json(): QuerySchema;
/**
* Retrieves the first value for a known parameter or null if missing.
*
* @param key parameter key to retrieve.
* @returns first parameter value or null.
*/
getKnown<T extends keyof QuerySchema>(key: T): QuerySchema[T] | null;
/**
* Retrieves all values for a known parameter key.
*
* @param key parameter key to retrieve.
* @returns array of all values for the key.
*/
getAll<T extends keyof QuerySchema>(key: T): string[];
/**
* Checks if a known parameter key is present.
*
* @param key parameter key to check.
* @returns true if the key exists.
*/
has<T extends keyof QuerySchema>(key: T): boolean;
/**
* Sets a parameter to a single value, replacing existing values.
*
* @param key parameter key to set.
* @param value value to assign.
* @returns instance for chaining.
*/
set<T extends keyof QuerySchema>(key: T, value: any): this;
/**
* Appends a value to a parameter key, preserving existing values.
*
* @param key parameter key to append to.
* @param value value to append.
* @returns instance for chaining.
*/
append<T extends keyof QuerySchema>(key: T, value: any): this;
/**
* Deletes all values for a parameter key.
*
* @param key parameter key to delete.
* @returns instance for chaining.
*/
delete<T extends keyof QuerySchema>(key: T): this;
/**
* Returns a simple object of parameters taking the first value for each key.
*
* @returns plain object of key->firstValue.
*/
getObject(): Record<string, string>;
/**
* Iterator over [key, value] pairs for each parameter value.
* Works like URLSearchParams[Symbol.iterator].
*/
[Symbol.iterator](): IterableIterator<[string, string]>;
}
export {};