All files / src index.js

97.82% Statements 45/46
87.5% Branches 7/8
100% Functions 4/4
97.82% Lines 45/46

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 38 39 40 41 42 43 44 45 46 471x 1x 1x 1x 1x 1x 1x 1x 1x 1x 22x 22x 22x 22x   22x 22x 22x 22x 22x 22x 572x 22x 22x 1x 1x 35x 35x 1x 1x 100x 2x 100x 98x 98x 98x 98x 98x 100x 1x 1x 1x 1x 1x 1x 1x  
import * as locales from './locale/index.js';
import * as imports from './imports.js';
import * as constants from './constants.js';
 
/**
 *
 * @namespace pure
 */
export class Pure {
  constructor(locale) {
    this.registeredModules = new Object();
    this.possibleLocales = constants.possibleLocales;
 
    if (locale) {
      this.setLocale(locale);
    } else {
      this.registeredModules = locales.en;
    }
 
    // Dynamic import all modules
    Object.keys(imports).forEach(key => {
      this[key] = new imports[key](this);
    });
  }
 
  seed(value) {
    this.random = new imports.random(this, value);
  }
 
  setLocale(locale) {
    if (this.possibleLocales.indexOf(locale) === -1) {
      throw new Error(`The following locale is not supported: ${locale}`);
    } else {
      this.registeredModules = {
        ...locales.en,
        ...locales[locale]
      };
    }
  }
 
  getSeed() {
    return this.random.returnSeed();
  }
}
 
export default new Pure();