plane/space/helpers/query-param-generator.ts
guru_sainath bab52a2672
[WEB-1319] chore: New authentication workflow (#4481)
* chore: New authentication workflow

* chore: resolved build erros and updated imports in auth

* chore: code optimisation for query param util

* chore: added client for auth forms
2024-05-16 17:17:04 +05:30

25 lines
921 B
TypeScript

type TQueryParamValue = string | string[] | boolean | number | bigint | undefined | null;
export const queryParamGenerator = (queryObject: Record<string, TQueryParamValue>) => {
const queryParamObject: Record<string, TQueryParamValue> = {};
const queryParam = new URLSearchParams();
Object.entries(queryObject).forEach(([key, value]) => {
if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") {
queryParamObject[key] = value;
queryParam.append(key, value.toString());
} else if (typeof value === "string" && value.length > 0) {
queryParamObject[key] = value.split(",");
queryParam.append(key, value);
} else if (Array.isArray(value) && value.length > 0) {
queryParamObject[key] = value;
queryParam.append(key, value.toString());
}
});
return {
query: queryParamObject,
queryParam: queryParam.toString(),
};
};