Code coverage report for src\index.js

Statements: 100% (18 / 18)      Branches: 100% (6 / 6)      Functions: 100% (6 / 6)      Lines: 100% (18 / 18)      Ignored: none     

All files » src/ » index.js
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 421   1         1   1 3 1     2 2   2 2   2 1     1           1 1 1   1     1        
import {Parser} from './parser';
 
let defaultOptions = {
  path: './',
  file: 'aurelia.env'
};
 
let _options = Object.create(null);
 
export function load(options) {
  if (typeof fetch === 'undefined') {
    throw new Error('aurelia-environment plugin requires a Fetch API implementation.');
  }
 
  window.env = Object.create(null);
  _options = Object.assign(Object.create(null), defaultOptions, options);
 
  return new Promise((resolve, reject) => {
    fetch(new Request(_options.path + _options.file))
      .then(response => {
        if (response.status >= 200 && response.status < 300) {
          return response.text();
        }
 
        return Promise.reject({
          status: response.status,
          statusText: response.statusText
        });
      })
      .then(text => {
        let parsedObject = Parser.parse(text);
        Object.keys(parsedObject).forEach(key => {
          window.env[key] = parsedObject[key];
        });
        resolve();
      })
      .catch(error => {
        reject(error);
      });
  });
}