loaders.js 633 B

123456789101112131415161718192021222324252627282930
  1. //
  2. 'use strict';
  3. const parseJson = require('parse-json');
  4. const yaml = require('js-yaml');
  5. const importFresh = require('import-fresh');
  6. function loadJs(filepath ) {
  7. const result = importFresh(filepath);
  8. return result;
  9. }
  10. function loadJson(filepath , content ) {
  11. try {
  12. return parseJson(content);
  13. } catch (err) {
  14. err.message = `JSON Error in ${filepath}:\n${err.message}`;
  15. throw err;
  16. }
  17. }
  18. function loadYaml(filepath , content ) {
  19. return yaml.safeLoad(content, { filename: filepath });
  20. }
  21. module.exports = {
  22. loadJs,
  23. loadJson,
  24. loadYaml,
  25. };