5etools-utils 0.1.5 → 0.1.6

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.
package/lib/TestJson.js CHANGED
@@ -9,16 +9,20 @@ import * as um from "./UtilMisc.js";
9
9
  const _IS_SORT_RESULTS = !process.env.VET_TEST_JSON_RESULTS_UNSORTED;
10
10
  const _IS_TRIM_RESULTS = !process.env.VET_TEST_JSON_RESULTS_UNTRIMMED;
11
11
 
12
+ const LOG_TAG = "JSON";
13
+
12
14
  class JsonTester {
13
15
  static _RE_DATE = /^\d\d\d\d-\d\d-\d\d$/;
14
16
 
15
17
  constructor (
16
18
  {
17
19
  dirSchema,
18
- tagLog = "JSON",
20
+ dir = ".",
21
+ tagLog = LOG_TAG,
19
22
  },
20
23
  ) {
21
24
  this._dirSchema = dirSchema;
25
+ this._dir = dir;
22
26
  this._tagLog = tagLog;
23
27
 
24
28
  // region Set up validator
@@ -103,19 +107,22 @@ class JsonTester {
103
107
  const errors = [];
104
108
  const errorsFull = [];
105
109
 
106
- uf.runOnDirs((dir) => {
107
- uf.listJsonFiles(dir)
108
- .forEach(filePath => {
109
- const data = uf.readJSON(filePath);
110
- this._addImplicits(data);
111
- const valid = this._ajv.validate("homebrew.json", data);
110
+ uf.runOnDirs(
111
+ (dir) => {
112
+ uf.listJsonFiles(dir)
113
+ .forEach(filePath => {
114
+ const data = uf.readJSON(filePath);
115
+ this._addImplicits(data);
116
+ const valid = this._ajv.validate("homebrew.json", data);
112
117
 
113
- if (!valid) this._handleError({filePath, errors, errorsFull, data});
114
- });
115
- });
118
+ if (!valid) this._handleError({filePath, errors, errorsFull, data});
119
+ });
120
+ },
121
+ this._dir,
122
+ );
116
123
 
117
124
  return {errors, errorsFull};
118
125
  }
119
126
  }
120
127
 
121
- export {JsonTester};
128
+ export {JsonTester, LOG_TAG};
package/lib/UtilFs.js CHANGED
@@ -38,8 +38,8 @@ function listJsonFiles (dir) {
38
38
  }, []);
39
39
  }
40
40
 
41
- function runOnDirs (fn) {
42
- fs.readdirSync(".", "utf8")
41
+ function runOnDirs (fn, root = ".") {
42
+ fs.readdirSync(root, "utf8")
43
43
  .filter(dir => isDirectory(dir) && !dir.startsWith(".") && !dir.startsWith("_") && dir !== "node_modules")
44
44
  .forEach(dir => fn(dir));
45
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "5etools-utils",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Shared utilities for the 5etools ecosystem.",
5
5
  "type": "module",
6
6
  "main": "lib/Api.js",