UNPKG

@ministryofjustice/hmpps-digital-prison-reporting-frontend

Version:

The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.

61 lines (60 loc) 2.46 kB
/** * Normalizes a querystring parameter into a consistent string array. * * Needed because Express/qs may return repeated query params as strings, arrays, * or numeric‑keyed objects depending on parser settings and arrayLimit behavior * * @param value The raw query parameter value from req.query. * @returns An array of strings representing the normalized parameter. */ export declare const normalizeQueryStringArray: (queryParamValue: string[] | string | Record<string, string> | undefined) => string[] | undefined; /** * Converts a querystring to a query object * * @param {string} qs * @param {string} prefix * @return {*} {(Record<string, string | string[]>)} */ export declare const qsToQueryObject: (qs: string, prefix?: string) => Record<string, string | string[]>; /** * Converts a query obect back to a querystring * * @param {(Record<string, string | string[]>)} query * @return {*} {string} */ export declare const queryObjectToQs: (source: Record<string, string | string[]>, exclude?: Set<string>) => string; /** * Extracts `filters.*` entries from a query object. */ export declare const extractFiltersFromQuery: (query: Record<string, unknown>) => Record<string, unknown>; /** * Extracts `filters.*` entries and normalises values for the API. */ export declare const extractApiFiltersFromQuery: (query: Record<string, unknown>) => Record<string, string>; /** * Given a form request body, will strip out the * 'filters.' prefix to return the field name/id and value * * @param {Record<string, unknown>} body * @return {*} {Record<string, unknown>} */ export declare const extractFiltersFromBody: (body: Record<string, unknown>) => Record<string, unknown>; export declare const getQueryParamAsString: (query: Record<string, unknown>, name: string) => string | null; /** * Builds a query string from a form body * * @param {Record<string, unknown>} body * @param {Set<string>} [exclude=new Set()] * @return {*} {string} */ export declare const formBodyToQs: (body: Record<string, unknown>, exclude?: Set<string>) => string; /** * Converts a form body to an API query object * - Excludes specified keys * - Drops null / empty values * - Collapses arrays to CSV (BE contract) * * @param {Record<string, unknown>} body * @return {*} {(Record<string, string | string[]>)} */ export declare const formBodyToQueryObject: (body: Record<string, unknown>, exclude?: Set<string>) => Record<string, string>;