5etools-utils 0.16.17 → 0.16.18

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/README.md CHANGED
@@ -1,13 +1,13 @@
1
- # 5etools Utils
2
-
3
- Available commands:
4
-
5
- ```
6
- npx clean-html
7
- npx test-file-names [--name-regex <regex>]
8
- npx test-file-contents --img-repo-name <repo> --url-prefix-expected <prefix>
9
- npx test-json-brew [file] [--dir <dir>]
10
- npx test-json-ua [file] [--dir <dir>]
11
- ```
12
-
13
- And more; see `bin/`.
1
+ # 5etools Utils
2
+
3
+ Available commands:
4
+
5
+ ```
6
+ npx clean-html
7
+ npx test-file-names [--name-regex <regex>]
8
+ npx test-file-contents --img-repo-name <repo> --url-prefix-expected <prefix>
9
+ npx test-json-brew [file] [--dir <dir>]
10
+ npx test-json-ua [file] [--dir <dir>]
11
+ ```
12
+
13
+ And more; see `bin/`.
package/bin/clean-html.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,7 +1,7 @@
1
1
  import * as fs from "fs";
2
2
  import * as Uf from "./UtilFs.js";
3
3
  import Um from "./UtilMisc.js";
4
- import {getCleanJson} from "./UtilClean.js";
4
+ import {getCleanFilenameString, getCleanJson} from "./UtilClean.js";
5
5
  import MiscUtil from "./UtilMisc.js";
6
6
 
7
7
  class _BrewFileCleaner {
@@ -148,6 +148,13 @@ export class BrewCleaner {
148
148
  if (!this._IS_FAIL_SLOW) break;
149
149
  }
150
150
 
151
+ const filename = file.split("/").at(-1);
152
+ const filenameClean = getCleanFilenameString(filename);
153
+ if (filenameClean !== filename) {
154
+ ALL_ERRORS.push(`${file} contained unwanted non-ASCII characters! Should be "${filenameClean}".`);
155
+ if (!this._IS_FAIL_SLOW) break;
156
+ }
157
+
151
158
  let jsonOut = _BrewFileCleaner.cleanFile({file, contents: json});
152
159
  _BrewFileTester.testFile({ALL_ERRORS, file, contents: jsonOut});
153
160
 
package/lib/UtilClean.js CHANGED
@@ -1,10 +1,13 @@
1
- const _CLEAN_JSON_REPLACEMENTS = {
2
- "—": "\\u2014",
3
- "–": "\\u2013",
4
- "‑": "\\u2011",
5
- "−": "\\u2212",
6
- " ": "\\u00A0",
7
- " ": "\\u2007", // figure space
1
+ const _CLEAN_JSON_REPLACEMENTS__FILENAME = {
2
+ "—": "-",
3
+ "–": "-",
4
+ "‑": "-",
5
+ "−": "-",
6
+ " ": " ",
7
+ " ": " ",
8
+
9
+ "“": "",
10
+ "”": "",
8
11
 
9
12
  "’": "'",
10
13
  "‘": "'",
@@ -26,21 +29,33 @@ const _CLEAN_JSON_REPLACEMENTS = {
26
29
  "Nj": "Nj",
27
30
  "nj": "nj",
28
31
  "ſt": "ft",
32
+ "\u201a": ",",
33
+ };
34
+ const _CLEAN_JSON_REPLACEMENT_REGEX__FILENAME = new RegExp(Object.keys(_CLEAN_JSON_REPLACEMENTS__FILENAME).join("|"), "g");
35
+
36
+ const _CLEAN_JSON_REPLACEMENTS = {
37
+ ..._CLEAN_JSON_REPLACEMENTS__FILENAME,
38
+
39
+ "—": "\\u2014",
40
+ "–": "\\u2013",
41
+ "‑": "\\u2011",
42
+ "−": "\\u2212",
43
+ " ": "\\u00A0",
44
+ " ": "\\u2007", // figure space
45
+
29
46
  "“": `\\"`,
30
47
  "”": `\\"`,
31
- "\u201a": ",",
32
48
  };
33
49
  const _CLEAN_JSON_REPLACEMENT_REGEX = new RegExp(Object.keys(_CLEAN_JSON_REPLACEMENTS).join("|"), "g");
34
50
 
35
- const getCleanJson = obj => {
51
+ export const getCleanJson = obj => {
36
52
  return getCleanString(`${JSON.stringify(obj, null, "\t")}\n`);
37
53
  };
38
54
 
39
- const getCleanString = str => {
40
- return str.replace(_CLEAN_JSON_REPLACEMENT_REGEX, (match) => _CLEAN_JSON_REPLACEMENTS[match]);
55
+ export const getCleanFilenameString = str => {
56
+ return str.replace(_CLEAN_JSON_REPLACEMENT_REGEX__FILENAME, (match) => _CLEAN_JSON_REPLACEMENTS__FILENAME[match]);
41
57
  };
42
58
 
43
- export {
44
- getCleanJson,
45
- getCleanString,
59
+ export const getCleanString = str => {
60
+ return str.replace(_CLEAN_JSON_REPLACEMENT_REGEX, (match) => _CLEAN_JSON_REPLACEMENTS[match]);
46
61
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "5etools-utils",
3
- "version": "0.16.17",
3
+ "version": "0.16.18",
4
4
  "description": "Shared utilities for the 5etools ecosystem.",
5
5
  "type": "module",
6
6
  "main": "lib/Api.js",