UNPKG

@domonda/query-params

Version:

Useful but simple query params manipulator for React.

24 lines (23 loc) 963 B
/** * * queryParams * */ export declare function strictUriEncode(str: string): string; /** Stringify function which omits `undefined` values and persists empty arrays. */ export declare function stringify(value: { [key: string]: any; }, props?: { prependQuestionMark?: boolean; }): string; export declare type QueryModel<V> = { [K in keyof V]: { type: V[K] extends string ? 'string' : V[K] extends number ? 'number' : V[K] extends boolean ? 'boolean' : V[K] extends Date ? 'date' : V[K] extends any[] ? 'array' : string; defaultValue: (() => V[K]) | V[K]; validate?: (value: V[K]) => boolean; }; }; /** Parses the URL query string following the `QueryModel` definitions. */ export declare function parseQueryParams<V>(queryString: string, model: QueryModel<V>): V; /** Following the model, gives the query params populated with default values. */ export declare function defaultQueryParams<V>(model: QueryModel<V>): V;