All files mode.ts

100% Statements 22/22
100% Branches 5/5
100% Functions 3/3
100% Lines 22/22

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  1x   1x 1x       1x   1x 1x 1x   1x 123x 1x 1x 1x 1x 1x 122x 122x   1x 10x 10x   1x 213x 213x  
import { devMessages } from './dev';
import { FlowfulError } from './error';
 
export const MODE_DEV = 'development';
export const MODE_PROD = 'production';
 
export type MODE = typeof MODE_DEV | typeof MODE_PROD;
 
let mode: MODE = MODE_PROD;
 
if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV && process.env.NODE_ENV !== 'production') {
  mode = MODE_DEV;
}
 
export function checkMode(mode: MODE, functionName: string) {
  if (mode !== MODE_PROD && mode !== MODE_DEV) {
    throw new FlowfulError(
      `[Flowful][${functionName}] Invalid mode: "${mode}". The mode must be either "${MODE_PROD}" or "${MODE_DEV}".`,
      { mode }
    );
  }
  return mode;
}
 
export function setGlobalMode(newMode: MODE) {
  mode = checkMode(newMode, 'setGlobalMode');
}
 
export function getGlobalMode() {
  return mode;
}