lofig.js 862 B

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