/** * Parses the multi-value query string parameters from the given URL. * @param {string} url - The URL containing the query string parameters. * @returns {Object} - An object representing the parsed query string parameters. */ export function parseMultiValueQueryStringParameters(url: string) { // dummy placeholder url for the WHATWG URL constructor // https://github.com/nodejs/node/issues/12682 const { searchParams } = new URL(url, 'http://example') // if (Array.from(searchParams).length === 0) return {} const map = new Map() // eslint-disable-next-line no-restricted-syntax for (const [key, value] of searchParams) { const item = map.get(key) if (item) item.push(value) else map.set(key, [value]) } return Object.fromEntries(map) } /** * Parses the query string parameters from a given URL. * @param {string} url - The URL to parse the query string parameters from. * @returns {object | null} - An object containing the parsed query string parameters, or null if there are no parameters. */ export function parseQueryStringParameters(url) { // dummy placeholder url for the WHATWG URL constructor // https://github.com/nodejs/node/issues/12682 const { searchParams } = new URL(url, 'http://example') if (Array.from(searchParams).length === 0) return {} return Object.fromEntries(searchParams) }