@thi.ng/file-io 2.1.19 → 2.1.21

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-12-27T14:11:37Z
3
+ - **Last updated**: 2025-01-14T12:23:33Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [2.1.21](https://github.com/thi-ng/umbrella/tree/@thi.ng/file-io@2.1.21) (2025-01-14)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - use optional chaining & nullish coalescing ([c5a0a13](https://github.com/thi-ng/umbrella/commit/c5a0a13))
17
+
12
18
  ## [2.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/file-io@2.1.0) (2024-04-23)
13
19
 
14
20
  #### 🚀 Features
package/README.md CHANGED
@@ -100,4 +100,4 @@ If this project contributes to an academic publication, please cite it as:
100
100
 
101
101
  ## License
102
102
 
103
- © 2022 - 2024 Karsten Schmidt // Apache License 2.0
103
+ © 2022 - 2025 Karsten Schmidt // Apache License 2.0
package/delete.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { rmSync, unlinkSync } from "node:fs";
2
2
  const deleteFile = (path, logger, dryRun = false) => {
3
- logger && logger.info(`${dryRun ? "[dryrun] " : ""}deleting file: ${path}`);
3
+ logger?.info(`${dryRun ? "[dryrun] " : ""}deleting file: ${path}`);
4
4
  if (dryRun) return;
5
5
  unlinkSync(path);
6
6
  };
7
7
  const deleteDir = (path, logger, dryRun = false) => {
8
- logger && logger.info(`${dryRun ? "[dryrun] " : ""}deleting file: ${path}`);
8
+ logger?.info(`${dryRun ? "[dryrun] " : ""}deleting file: ${path}`);
9
9
  if (dryRun) return;
10
10
  rmSync(path, { recursive: true, force: true });
11
11
  };
package/hash.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { createReadStream } from "node:fs";
3
3
  const fileHash = async (path, logger, algo = "sha256") => {
4
- logger && logger.info("reading file:", path);
4
+ logger?.info("reading file:", path);
5
5
  return await streamHash(createReadStream(path), logger, algo);
6
6
  };
7
7
  const streamHash = async (src, logger, algo = "sha256") => {
8
8
  const sum = createHash(algo);
9
9
  for await (let chunk of src) sum.update(chunk);
10
10
  const hash = sum.digest("hex");
11
- logger && logger.info(`${algo} hash: ${hash}`);
11
+ logger?.info(`${algo} hash: ${hash}`);
12
12
  return hash;
13
13
  };
14
14
  const bufferHash = (src, logger, algo = "sha256") => {
15
15
  const hash = createHash(algo).update(src).digest("hex");
16
- logger && logger.info(`${algo} hash: ${hash}`);
16
+ logger?.info(`${algo} hash: ${hash}`);
17
17
  return hash;
18
18
  };
19
19
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/file-io",
3
- "version": "2.1.19",
3
+ "version": "2.1.21",
4
4
  "description": "Assorted file I/O utils (with 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.11.15",
44
- "@thi.ng/checks": "^3.6.17",
45
- "@thi.ng/hex": "^2.3.59",
46
- "@thi.ng/logger": "^3.0.25",
47
- "@thi.ng/random": "^4.1.6"
43
+ "@thi.ng/api": "^8.11.16",
44
+ "@thi.ng/checks": "^3.6.19",
45
+ "@thi.ng/hex": "^2.3.60",
46
+ "@thi.ng/logger": "^3.0.27",
47
+ "@thi.ng/random": "^4.1.7"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@microsoft/api-extractor": "^7.48.1",
@@ -127,5 +127,5 @@
127
127
  "status": "stable",
128
128
  "year": 2022
129
129
  },
130
- "gitHead": "48bf4c22bf23f88ac99f435106af2214f79a0be1\n"
130
+ "gitHead": "6542b842120bef47cc18d45a1b1db68307a7f04b\n"
131
131
  }
package/read.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  const readBinary = (path, logger) => {
3
- logger && logger.debug("reading file:", path);
3
+ logger?.debug("reading file:", path);
4
4
  const buf = readFileSync(path);
5
5
  return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
6
6
  };
package/temp.js CHANGED
@@ -6,7 +6,7 @@ import { sep } from "node:path";
6
6
  import { ensureDirForFile } from "./dir.js";
7
7
  const createTempFile = (body, logger, name, ext) => {
8
8
  const path = tempFilePath(name, ext);
9
- logger && logger.debug("creating temp file:", path);
9
+ logger?.debug("creating temp file:", path);
10
10
  ensureDirForFile(path);
11
11
  writeFileSync(path, body, isString(body) ? "utf-8" : void 0);
12
12
  return path;
package/text.js CHANGED
@@ -2,7 +2,7 @@ import { isArray } from "@thi.ng/checks/is-array";
2
2
  import { readFileSync } from "node:fs";
3
3
  import { writeFile } from "./write.js";
4
4
  const readText = (path, logger, encoding = "utf-8") => {
5
- logger && logger.debug("reading file:", path);
5
+ logger?.debug("reading file:", path);
6
6
  return readFileSync(path, encoding);
7
7
  };
8
8
  const writeText = (path, body, logger, dryRun = false) => writeFile(
package/write.js CHANGED
@@ -2,7 +2,7 @@ import { isString } from "@thi.ng/checks/is-string";
2
2
  import { writeFileSync } from "node:fs";
3
3
  import { ensureDirForFile } from "./dir.js";
4
4
  const writeFile = (path, body, opts, logger, dryRun = false) => {
5
- logger && logger.info(`${dryRun ? "[dryrun] " : ""}writing file: ${path}`);
5
+ logger?.info(`${dryRun ? "[dryrun] " : ""}writing file: ${path}`);
6
6
  if (dryRun) return;
7
7
  ensureDirForFile(path);
8
8
  writeFileSync(path, body, !opts && isString(body) ? "utf-8" : opts);