You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
633 B

4 years ago
  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. };