Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 1x 1x 1x 65x 1x 13x 47x | import { GlobalConfig } from './interface';
const DEFAULT_TRY_TIMES = 3;
const NOOP = function (): void { /* Noop */ };
let globalConfig: GlobalConfig = {
logTryTimes: DEFAULT_TRY_TIMES,
errorHandler: NOOP
};
function validOrBackup (
param: any,
type: 'string' | 'number' | 'function',
backup: string | number | Function | undefined
): string | number | Function | undefined {
return typeof param === type ? param : backup;
}
export default {
set: (configOb: GlobalConfig): void => {
globalConfig = {
publicKey: validOrBackup(configOb.publicKey, 'string', undefined) as string,
logTryTimes: validOrBackup(
configOb.logTryTimes,
'number',
DEFAULT_TRY_TIMES
) as number,
reportUrl: validOrBackup(configOb.reportUrl, 'string', undefined) as string,
dbName: validOrBackup(configOb.dbName, 'string', undefined) as string,
errorHandler: validOrBackup(
configOb.errorHandler,
'function',
NOOP
) as Function
};
},
get: (propertyKey: keyof GlobalConfig): string | number | Function | undefined => {
return globalConfig[propertyKey];
}
};
|