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