Created
March 26, 2024 05:16
-
-
Save TheLucifurry/364529aefa9b9b79d60eca89cade1a47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import type { LocationQueryValue } from 'vue-router' | |
| type TQueryParams = Record<string, LocationQueryValue | LocationQueryValue[]> | |
| type TQueryParamsValues = string | Record<string, unknown> | Array<unknown> | |
| export function getEncodedQueryParams(params: Record<string, TQueryParamsValues>): TQueryParams { | |
| return Object.entries(params) | |
| .reduce((acc, [key, value]) => { | |
| if (typeof value === 'string') { | |
| acc[key] = encodeURIComponent(decodeURIComponent(value)) | |
| } else { | |
| try { | |
| acc[key] = encodeURIComponent(JSON.stringify(value)) | |
| } catch (error) {} | |
| } | |
| return acc | |
| }, {} as TQueryParams) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment