lofig.js 755 B

1234567891011121314151617181920212223242526272829303132333435
  1. window.lofig = {
  2. folder: 'config/default.json',
  3. get: query => {
  4. return fetch(lofig.folder)
  5. .then(response => {
  6. return response.json();
  7. }).then(json => {
  8. query.split('.')
  9. .forEach(property => {
  10. json = json[property];
  11. });
  12. return json;
  13. }).catch(err => {
  14. console.log('parsing failed', err);
  15. });
  16. },
  17. has: query => {
  18. return fetch(lofig.folder)
  19. .then(response => {
  20. return response.json();
  21. }).then(json => {
  22. query = query.split('.');
  23. return Promise.each(query, property => {
  24. json = json[property];
  25. }).then(() => {
  26. if (json) return true;
  27. else return false;
  28. });
  29. }).catch(err => {
  30. console.log('parsing failed', err);
  31. });
  32. }
  33. };