lofig.js 752 B

1234567891011121314151617181920212223242526272829303132333435
  1. window.lofig = {
  2. folder: '/config/default.json',
  3. get: (query, cb) => {
  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. if (cb) return cb(json);
  13. else return json;
  14. }).catch(err => {
  15. console.log('parsing failed', err);
  16. });
  17. },
  18. has: (query, cb) => {
  19. return fetch(lofig.folder)
  20. .then(response => {
  21. return response.json();
  22. }).then(json => {
  23. query.split('.')
  24. .forEach(property => {
  25. json = json[property];
  26. });
  27. if (cb) return cb(json);
  28. return json;
  29. }).catch(err => {
  30. console.log('parsing failed', err);
  31. });
  32. }
  33. };