@thi.ng/file-io 2.1.1 → 2.1.2

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-04-25T19:44:55Z
3
+ - **Last updated**: 2024-05-08T18:24:31Z
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.
package/delete.js CHANGED
@@ -1,14 +1,12 @@
1
1
  import { rmSync, unlinkSync } from "node:fs";
2
2
  const deleteFile = (path, logger, dryRun = false) => {
3
3
  logger && logger.info(`${dryRun ? "[dryrun] " : ""}deleting file: ${path}`);
4
- if (dryRun)
5
- return;
4
+ if (dryRun) return;
6
5
  unlinkSync(path);
7
6
  };
8
7
  const deleteDir = (path, logger, dryRun = false) => {
9
8
  logger && logger.info(`${dryRun ? "[dryrun] " : ""}deleting file: ${path}`);
10
- if (dryRun)
11
- return;
9
+ if (dryRun) return;
12
10
  rmSync(path, { recursive: true, force: true });
13
11
  };
14
12
  export {
package/file-chunks.js CHANGED
@@ -17,11 +17,9 @@ async function* fileChunks(path, opts = {}) {
17
17
  length: size,
18
18
  position: start
19
19
  });
20
- if (bytesRead === 0)
21
- break;
20
+ if (bytesRead === 0) break;
22
21
  yield buffer;
23
- if (bytesRead < size)
24
- break;
22
+ if (bytesRead < size) break;
25
23
  start += bytesRead;
26
24
  }
27
25
  } finally {
package/files.js CHANGED
@@ -4,8 +4,7 @@ import { isDirectory } from "./dir.js";
4
4
  import { __ensurePred } from "./internal/ensure.js";
5
5
  const files = (dir, match = "", maxDepth = Infinity, logger) => __files(dir, match, logger, maxDepth, 0);
6
6
  function* __files(dir, match = "", logger, maxDepth = Infinity, depth = 0) {
7
- if (depth >= maxDepth)
8
- return;
7
+ if (depth >= maxDepth) return;
9
8
  const pred = __ensurePred(match);
10
9
  for (let f of readdirSync(dir).sort()) {
11
10
  const curr = dir + sep + f;
@@ -22,15 +21,13 @@ function* __files(dir, match = "", logger, maxDepth = Infinity, depth = 0) {
22
21
  }
23
22
  const dirs = (dir, match = "", maxDepth = Infinity, logger) => __dirs(dir, match, logger, maxDepth, 0);
24
23
  function* __dirs(dir, match = "", logger, maxDepth = Infinity, depth = 0) {
25
- if (depth >= maxDepth)
26
- return;
24
+ if (depth >= maxDepth) return;
27
25
  const pred = __ensurePred(match);
28
26
  for (let f of readdirSync(dir).sort()) {
29
27
  const curr = dir + sep + f;
30
28
  try {
31
29
  if (statSync(curr).isDirectory()) {
32
- if (pred(curr))
33
- yield curr;
30
+ if (pred(curr)) yield curr;
34
31
  yield* __dirs(curr, match, logger, maxDepth, depth + 1);
35
32
  }
36
33
  } catch (e) {
package/hash.js CHANGED
@@ -6,8 +6,7 @@ const fileHash = async (path, logger, algo = "sha256") => {
6
6
  };
7
7
  const streamHash = async (src, logger, algo = "sha256") => {
8
8
  const sum = createHash(algo);
9
- for await (let chunk of src)
10
- sum.update(chunk);
9
+ for await (let chunk of src) sum.update(chunk);
11
10
  const hash = sum.digest("hex");
12
11
  logger && logger.info(`${algo} hash: ${hash}`);
13
12
  return hash;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/file-io",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "Assorted file I/O utils (with logging support) for NodeJS/Bun",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -36,17 +36,17 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.11.1",
40
- "@thi.ng/checks": "^3.6.3",
41
- "@thi.ng/hex": "^2.3.45",
42
- "@thi.ng/logger": "^3.0.11",
43
- "@thi.ng/random": "^3.7.5"
39
+ "@thi.ng/api": "^8.11.2",
40
+ "@thi.ng/checks": "^3.6.4",
41
+ "@thi.ng/hex": "^2.3.46",
42
+ "@thi.ng/logger": "^3.0.12",
43
+ "@thi.ng/random": "^3.8.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@microsoft/api-extractor": "^7.43.0",
47
- "esbuild": "^0.20.2",
48
- "typedoc": "^0.25.12",
49
- "typescript": "^5.4.3"
46
+ "@microsoft/api-extractor": "^7.43.2",
47
+ "esbuild": "^0.21.1",
48
+ "typedoc": "^0.25.13",
49
+ "typescript": "^5.4.5"
50
50
  },
51
51
  "keywords": [
52
52
  "async",
@@ -123,5 +123,5 @@
123
123
  "status": "stable",
124
124
  "year": 2022
125
125
  },
126
- "gitHead": "aed3421c21044c005fbcb7cc37965ccf85a870d2\n"
126
+ "gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
127
127
  }
package/watch.js CHANGED
@@ -5,8 +5,7 @@ var __decorateClass = (decorators, target, key, kind) => {
5
5
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
6
  if (decorator = decorators[i])
7
7
  result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
- if (kind && result)
9
- __defProp(target, key, result);
8
+ if (kind && result) __defProp(target, key, result);
10
9
  return result;
11
10
  };
12
11
  import {
@@ -38,8 +37,7 @@ let Watcher = class {
38
37
  }
39
38
  }
40
39
  add(path, opts) {
41
- if (this.watchers[path])
42
- return false;
40
+ if (this.watchers[path]) return false;
43
41
  const isDir = isDirectory(path);
44
42
  const pred = __ensurePred(opts?.ext || "");
45
43
  this.opts.logger.debug(`adding watcher for: ${path}`);
@@ -47,11 +45,9 @@ let Watcher = class {
47
45
  path,
48
46
  { recursive: opts?.recursive !== false },
49
47
  (event, currPath) => {
50
- if (!currPath)
51
- return;
48
+ if (!currPath) return;
52
49
  currPath = isDir ? join(path, currPath) : path;
53
- if (!pred(currPath))
54
- return;
50
+ if (!pred(currPath)) return;
55
51
  setTimeout(() => {
56
52
  if (event === "change") {
57
53
  this.opts.logger.info(`file changed: ${currPath}`);
@@ -75,8 +71,7 @@ let Watcher = class {
75
71
  }
76
72
  remove(path) {
77
73
  const watcher = this.watchers[path];
78
- if (!watcher)
79
- return false;
74
+ if (!watcher) return false;
80
75
  this.opts.logger.debug(`removing watcher for: ${path}`);
81
76
  watcher.close();
82
77
  delete this.watchers[path];
package/write.js CHANGED
@@ -3,8 +3,7 @@ import { writeFileSync } from "node:fs";
3
3
  import { ensureDirForFile } from "./dir.js";
4
4
  const writeFile = (path, body, opts, logger, dryRun = false) => {
5
5
  logger && logger.info(`${dryRun ? "[dryrun] " : ""}writing file: ${path}`);
6
- if (dryRun)
7
- return;
6
+ if (dryRun) return;
8
7
  ensureDirForFile(path);
9
8
  writeFileSync(path, body, !opts && isString(body) ? "utf-8" : opts);
10
9
  };