1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/frontend/src/utils/serializeQueryParams.ts

31 lines
625 B
TypeScript
Raw Normal View History

// Custom additional serializers for query params library
// used in `useQueryParams` hook
const encodeBoolean = (
bool: boolean | null | undefined,
): string | null | undefined => {
if (bool == null) {
return bool;
}
return bool ? 'true' : 'false';
};
const decodeBoolean = (
input: string | (string | null)[] | null | undefined,
): boolean | null | undefined => {
if (input === 'true') {
return true;
}
if (input === 'false') {
return false;
}
return null;
};
export const BooleansStringParam = {
encode: encodeBoolean,
decode: decodeBoolean,
};