jsonata-w 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SourceLoader = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
+ const js_yaml_1 = __importDefault(require("js-yaml"));
8
9
  class SourceLoader {
9
10
  constructor() {
10
11
  this.cache = new Map();
@@ -17,13 +18,15 @@ class SourceLoader {
17
18
  throw new Error(`File not found: ${path}`);
18
19
  }
19
20
  const content = fs_1.default.readFileSync(path, 'utf-8');
21
+ const isYaml = path.endsWith('.yml') || path.endsWith('.yaml');
20
22
  try {
21
- const json = JSON.parse(content);
22
- this.cache.set(path, json);
23
- return json;
23
+ const data = isYaml ? js_yaml_1.default.load(content) : JSON.parse(content);
24
+ this.cache.set(path, data);
25
+ return data;
24
26
  }
25
27
  catch (_e) {
26
- throw new Error(`Invalid JSON in file: ${path}`);
28
+ const format = isYaml ? 'YAML' : 'JSON';
29
+ throw new Error(`Invalid ${format} in file: ${path}`);
27
30
  }
28
31
  }
29
32
  clearCache() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsonata-w",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Tool to assist AI in transforming JSON files",
5
5
  "main": "dist/index.js",
6
6
  "bin": {