@thi.ng/file-io 2.2.37 → 2.3.0

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
@@ -8,7 +8,7 @@
8
8
 
9
9
  > [!NOTE]
10
10
 
11
- > This is one of 215 standalone projects. LLM-free, human-made and
11
+ > This is one of 216 standalone projects. LLM-free, human-made and
12
12
  > cared for software, maintained as part of the
13
13
  > [@thi.ng/umbrella](https://codeberg.org/thi.ng/umbrella/) ecosystem and
14
14
  > anti-framework.
@@ -108,7 +108,7 @@ For Node.js REPL:
108
108
  const fio = await import("@thi.ng/file-io");
109
109
  ```
110
110
 
111
- Package sizes (brotli'd, pre-treeshake): ESM: 2.44 KB
111
+ Package sizes (brotli'd, pre-treeshake): ESM: 2.50 KB
112
112
 
113
113
  ## Dependencies
114
114
 
package/json.d.ts CHANGED
@@ -14,6 +14,24 @@ export declare const readJSON: <T = any>(path: string, logger?: ILogger) => T;
14
14
  * @param logger
15
15
  */
16
16
  export declare const readJSONAsync: <T = any>(path: string, logger?: ILogger) => Promise<T>;
17
+ /**
18
+ * Similar to {@link readJSON}, reads JSON file with comments.
19
+ *
20
+ * @remarks
21
+ * **IMPORTANT:** Only `//` single line comments (with optional leading
22
+ * whitespace) are supported! This is NOT a full JSONC parser.
23
+ *
24
+ * @param path
25
+ * @param logger
26
+ */
27
+ export declare const readJSONC: <T = any>(path: string, logger?: ILogger) => T;
28
+ /**
29
+ * Async version of {@link readJSONC}.
30
+ *
31
+ * @param path
32
+ * @param logger
33
+ */
34
+ export declare const readJSONCAsync: <T = any>(path: string, logger?: ILogger) => Promise<T>;
17
35
  /**
18
36
  * Serializes `obj` to JSON and writes result to UTF-8 file `path`. See
19
37
  * {@link writeText} for more details.
package/json.js CHANGED
@@ -1,6 +1,11 @@
1
1
  import { readText, readTextAsync, writeText, writeTextAsync } from "./text.js";
2
2
  const readJSON = (path, logger) => JSON.parse(readText(path, logger));
3
3
  const readJSONAsync = async (path, logger) => JSON.parse(await readTextAsync(path, logger));
4
+ const readJSONC = (path, logger) => __parseJSONC(readText(path, logger));
5
+ const readJSONCAsync = async (path, logger) => __parseJSONC(await readTextAsync(path, logger));
6
+ const __parseJSONC = (src) => JSON.parse(
7
+ src.split(/\r?\n/g).filter((x) => !/^\s*\/\//.test(x)).join("\n")
8
+ );
4
9
  const writeJSON = (path, obj, replacer, space, logger, dryRun = false) => writeText(
5
10
  path,
6
11
  JSON.stringify(obj, replacer, space) + "\n",
@@ -16,6 +21,8 @@ const writeJSONAsync = (path, obj, replacer, space, logger, dryRun = false) => w
16
21
  export {
17
22
  readJSON,
18
23
  readJSONAsync,
24
+ readJSONC,
25
+ readJSONCAsync,
19
26
  writeJSON,
20
27
  writeJSONAsync
21
28
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/file-io",
3
- "version": "2.2.37",
3
+ "version": "2.3.0",
4
4
  "description": "Assorted file I/O utils (w/ logging support) for NodeJS/Bun",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -40,11 +40,11 @@
40
40
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@thi.ng/api": "^8.12.25",
44
- "@thi.ng/checks": "^3.9.5",
45
- "@thi.ng/hex": "^2.4.17",
46
- "@thi.ng/logger": "^3.3.8",
47
- "@thi.ng/random": "^4.1.51"
43
+ "@thi.ng/api": "^8.12.26",
44
+ "@thi.ng/checks": "^3.10.0",
45
+ "@thi.ng/hex": "^2.4.18",
46
+ "@thi.ng/logger": "^3.3.9",
47
+ "@thi.ng/random": "^4.1.52"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/node": "^25.6.2",
@@ -135,5 +135,5 @@
135
135
  "status": "stable",
136
136
  "year": 2022
137
137
  },
138
- "gitHead": "65b041e97110e16c01cf968949b72a0873f14445"
138
+ "gitHead": "c47c56420bcae2e0477d252a497be44f08ca185a"
139
139
  }