Created helper function to evolve a query string based on an object

This commit is contained in:
Alejandro Celaya
2021-11-07 11:22:29 +01:00
parent 109baef828
commit a2421ee2d3
2 changed files with 15 additions and 1 deletions

View File

@@ -3,3 +3,6 @@ import qs from 'qs';
export const parseQuery = <T>(search: string) => qs.parse(search, { ignoreQueryPrefix: true }) as unknown as T;
export const stringifyQuery = (query: any): string => qs.stringify(query, { arrayFormat: 'brackets' });
export const evolveStringifiedQuery = (currentQuery: string, extra: any): string =>
stringifyQuery({ ...parseQuery(currentQuery), ...extra });