import { type Maybe, type ArrayOrValue, type IterableOrValue, type ObjectKey } from '@dereekb/util'; /** * Options for makeUrlSearchParams() */ export interface MakeUrlSearchParamsOptions { /** * Optional iterable of keys to remove from the search params. */ readonly omitKeys?: Maybe>; /** * Whether to filter out empty values from the input objects. * * Defaults to true. */ readonly filterEmptyValues?: boolean; /** * Whether to encode spaces as `%20` instead of `+` in the output string. * * `URLSearchParams.toString()` uses `application/x-www-form-urlencoded` encoding, * which represents spaces as `+`. However, `URL.search` and `decodeURIComponent()` * encode spaces as `%20`. This mismatch means that consumers like Angular's router * that use `decodeURIComponent()` will not decode `+` back to a space, corrupting * values (e.g., `"openid profile"` becomes `"openid+profile"`). * * Set to `true` when building redirect URLs or any URL that will be decoded with * `decodeURIComponent()` rather than form-data parsing. * * Defaults to false. * * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams#interaction_with_url.searchparams | MDN: Interaction with URL.searchParams} */ readonly useUrlSearchSpaceHandling?: boolean; /** * Whether to expand nested arrays and objects into bracket-notation keys instead of * letting `URLSearchParams` stringify them. * * `URLSearchParams` calls `String()` on every value, so by default an array is comma-joined * and a nested object collapses to the useless `[object Object]`. Many APIs instead expect * each leaf addressed by an indexed/keyed path: * * `{ a: [{ b: 1 }] }` becomes `a[0][b]=1` rather than `a=[object Object]`. * * Scalar values are unaffected. Nullish leaves are skipped. * * Defaults to false. */ readonly useBracketNotation?: boolean; } /** * A single URL query parameter, as a key/value tuple. */ export type UrlSearchParamsKeyValueTuple = [string, string]; /** * Expands a potentially nested object into bracket-notation query key/value tuples. * * Arrays are addressed by index and object properties by key, recursively, so every leaf * gets its own fully-qualified parameter. Nullish leaves are omitted rather than emitted * as the strings `"null"`/`"undefined"`; all other leaves are stringified. * * @param input - The object to expand. * @returns The bracket-notation key/value tuples. * * @dbxUtil * @dbxUtilCategory url * @dbxUtilTags url, query, search, params, bracket, notation, nested, expand, tuples, encode * @dbxUtilRelated make-url-search-params, make-url-search-params-string * * @example * ```typescript * toBracketNotationSearchParamTuples({ calendarsToLoad: [{ credentialId: 1, externalId: 'a@b.com' }] }); * // => [['calendarsToLoad[0][credentialId]', '1'], ['calendarsToLoad[0][externalId]', 'a@b.com']] * ``` */ export declare function toBracketNotationSearchParamTuples(input: Maybe): UrlSearchParamsKeyValueTuple[]; /** * Creates URLSearchParams from the input objects. The input objects are merged together. * * @param input - One or more objects (or nullish values) whose key-value pairs become search parameters. * @param options - Optional configuration for filtering, omitting keys, and space encoding. * @returns A URLSearchParams instance built from the merged and filtered input. * * @dbxUtil * @dbxUtilCategory url * @dbxUtilTags url, query, search, params, urlsearchparams, encode, merge, filter, omit, querystring * @dbxUtilRelated make-url-search-params-string, update-url-search-params, to-bracket-notation-search-param-tuples, merge-make-url-search-params-options */ export declare function makeUrlSearchParams(input: Maybe>>>, options?: Maybe): URLSearchParams; /** * Creates a URL query string from the input objects. * * Equivalent to `makeUrlSearchParams(...).toString()`, but respects the * {@link MakeUrlSearchParamsOptions.useUrlSearchSpaceHandling} option to produce * RFC 3986 percent-encoded output (`%20` for spaces) instead of the * `application/x-www-form-urlencoded` default (`+` for spaces). * * @param input - Objects to encode as query parameters. * @param options - Encoding options. * @returns The encoded query string (without a leading `?`) * * @dbxUtil * @dbxUtilCategory url * @dbxUtilTags url, query, search, params, string, querystring, encode, percent, space, stringify * @dbxUtilRelated make-url-search-params, update-url-search-params */ export declare function makeUrlSearchParamsString(input: Maybe>>>, options?: Maybe): string; /** * Updates or adds query parameters on an existing URL string. * * Parses the URL's existing query string, merges in the new parameters (new values * override existing keys), and returns the rebuilt URL. Respects all * {@link MakeUrlSearchParamsOptions} such as `omitKeys`, `filterEmptyValues`, and * `useUrlSearchSpaceHandling`. * * @param url - The URL string to update. * @param params - New search parameters to merge into the URL. * @param options - Optional configuration for filtering, omitting keys, and space encoding. * @returns The URL string with updated query parameters. * * @dbxUtil * @dbxUtilCategory url * @dbxUtilTags url, query, search, params, update, merge, append, override, querystring, encode * @dbxUtilRelated make-url-search-params, make-url-search-params-string, merge-slash-paths * * @example * ```typescript * // Add params to a URL with no query string * updateUrlSearchParams('https://example.com/form', { name: 'Alice', age: 30 }); * // => 'https://example.com/form?name=Alice&age=30' * * // Override an existing param * updateUrlSearchParams('https://example.com?page=1&sort=asc', { page: 2 }); * // => 'https://example.com?page=2&sort=asc' * * // Use percent-encoded spaces for redirect URLs * updateUrlSearchParams('https://example.com', { scope: 'openid profile' }, { useUrlSearchSpaceHandling: true }); * // => 'https://example.com?scope=openid%20profile' * ``` */ export declare function updateUrlSearchParams(url: string, params: Maybe>>>, options?: Maybe): string; /** * Merges an array of MakeUrlSearchParamsOptions into a single MakeUrlSearchParamsOptions value. * * @param options - One or more options objects whose omitKeys sets are combined. * @returns A single MakeUrlSearchParamsOptions with the union of all omitKeys. * * @dbxUtil * @dbxUtilCategory url * @dbxUtilTags url, query, search, params, options, merge, omit, keys, config * @dbxUtilRelated make-url-search-params */ export declare function mergeMakeUrlSearchParamsOptions(options: ArrayOrValue>): MakeUrlSearchParamsOptions;