sandai-react
Version:
React components and utilities for the Sandai 3D AI Characters.
57 lines • 2.01 kB
TypeScript
/**
* A utility class for constructing URLs with typed query parameters.
*
* This class allows you to dynamically build a URL with typed query parameters.
* Supports method chaining for setting multiple parameters before building the final URL.
*
* ## Example Usage
* ```typescript
* interface Params {
* userId: number;
* search: string;
* isActive: boolean;
* }
*
* const url = new UrlBuilder<Params>("https://example.com")
* .setParam("userId", 123)
* .setParam("search", "test")
* .setParam("isActive", true)
* .build();
*
* console.log(url); // "https://example.com?userId=123&search=test&isActive=true"
* ```
*
* @template T - A generic type extending `Record<string, any>`, representing the expected query parameters.
*
* @property {string} baseUrl - The base URL to which query parameters will be appended.
* @property {URLSearchParams} params - An instance of `URLSearchParams` used to store query parameters.
*/
export declare class UrlBuilder<T extends Record<string, any>> {
private baseUrl;
private params;
/**
* Creates an instance of `UrlBuilder`.
*
* @constructor
* @param {string} baseUrl - The base URL to which query parameters will be appended.
*/
constructor(baseUrl: string);
/**
* Sets a query parameter in the URL.
*
* Supports method chaining to allow setting multiple parameters fluently.
*
* @template K - A key of `T`, representing a valid query parameter name.
* @param {K} key - The key of the query parameter.
* @param {T[K]} value - The value of the query parameter.
* @returns {this} Returns the current `UrlBuilder` instance for method chaining.
*/
setParam<K extends keyof T>(key: K, value: T[K]): this;
/**
* Builds and returns the final URL with the appended query parameters.
*
* @returns {string} The fully constructed URL with query parameters.
*/
build(): string;
}
//# sourceMappingURL=urlBuilder.d.ts.map