@splitsoftware/splitio-commons
Version:
Split JavaScript SDK common components
25 lines (22 loc) • 768 B
text/typescript
import { LogLevels, isLogLevelString } from '../../../logger';
import SplitIO from '../../../../types/splitio';
/**
* Returns the LogLevel for the given debugValue or undefined if it is invalid,
* i.e., if the debugValue is not a boolean or LogLevel string.
*
* @param debugValue - debug value at config
* @returns LogLevel of the given debugValue or undefined if the provided value is invalid
*/
export function getLogLevel(debugValue: unknown): SplitIO.LogLevel | undefined {
if (typeof debugValue === 'boolean') {
if (debugValue) {
return LogLevels.DEBUG;
} else {
return LogLevels.NONE;
}
} else if (typeof debugValue === 'string' && isLogLevelString(debugValue)) {
return debugValue;
} else {
return undefined;
}
}