Code coverage report for core/src/configurable.ts

Statements: 76.92% (10 / 13)      Branches: 12.5% (1 / 8)      Functions: 60% (3 / 5)      Lines: 76.92% (10 / 13)      Ignored: none     

All files » core/src/ » configurable.ts
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                  1           58 58 58                     2 2   2                           1   2 2                
import {Key, KeyFallback, Props} from './env';
 
 
export interface Enabled {
  enabled(key: string): boolean;
 
}
 
 
export class PropEnabled implements Enabled {
  readonly acceptValues: Set<string>;
 
  readonly key: KeyFallback;
 
 
  constructor(key: Key, readonly props: Props, ...acceptValues: string[]) {
    this.acceptValues = new Set<string>(acceptValues);
    this.key = typeof key === 'string' ? { name: key } : { ...key };
  }
 
 
  enabled(key?: Key, or?: () => string): boolean {
    const val = this.props.getProp(key || this.key, or);
    return val ? this.acceptValues.has(val) : false;
  }
 
 
  extend(prefix: string, ...acceptValues: string[]): PropEnabled {
    const props = this.props.getConfig(prefix);
    const accept: string[] = [...this.acceptValues, ...acceptValues];
    // eslint-disable-next-line @typescript-eslint/no-use-before-define
    return new ChildEnabled(
      {
        ...this.key,
        name: prefix,
      },
      this,
      props,
      ...accept,
    );
  }
 
}
 
 
export class ChildEnabled extends PropEnabled {
 
  constructor(key: Key, readonly parent: PropEnabled, props: Props, ...acceptValues: string[]) {
    super(key, props, ...acceptValues);
  }
 
 
  enabled(key: string, or?: () => string): boolean {
    return super.enabled(key) || this.parent.enabled(key, or);
  }
}