Spaces:
Runtime error
Runtime error
File size: 952 Bytes
2485dd8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import type {URLParamNames} from './types/URLParamsTypes';
export function getBooleanParamFlag(
flag: URLParamNames,
defaultValue?: boolean,
): boolean {
const paramFlagValue = getBooleanParamFlagWithoutDefault(flag);
if (paramFlagValue == null) {
// The default value for paramFlags is false, unless they explicitly provide a
// defaultValue via the config
return defaultValue ?? false;
}
return paramFlagValue;
}
export function getBooleanParamFlagWithoutDefault(
flag: URLParamNames,
): boolean | null {
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get(flag) == null) {
return null;
}
return urlParams.get(flag) !== '0';
}
export function getStringParamFlag(
flag: URLParamNames,
defaultValue?: string,
): string | null {
const urlParams = new URLSearchParams(window.location.search);
const param = urlParams.get(flag);
return param ?? defaultValue ?? null;
}
|