mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-06 00:07:44 +01:00
31 lines
625 B
TypeScript
31 lines
625 B
TypeScript
|
// 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,
|
||
|
};
|