@thi.ng/file-io 0.3.25 → 0.4.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/CHANGELOG.md +8 -1
- package/README.md +2 -2
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +10 -7
- package/read.d.ts +9 -0
- package/read.js +12 -0
- package/text.d.ts +10 -1
- package/text.js +10 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**:
|
|
3
|
+
- **Last updated**: 2023-01-10T15:20:18Z
|
|
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,13 @@ 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
|
+
## [0.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/file-io@0.4.0) (2023-01-10)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add readText() encoding opts ([22366c0](https://github.com/thi-ng/umbrella/commit/22366c0))
|
|
17
|
+
- add readBinary(), update pkg exports ([2c647ed](https://github.com/thi-ng/umbrella/commit/2c647ed))
|
|
18
|
+
|
|
12
19
|
### [0.3.25](https://github.com/thi-ng/umbrella/tree/@thi.ng/file-io@0.3.25) (2022-12-29)
|
|
13
20
|
|
|
14
21
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ For Node.js REPL:
|
|
|
43
43
|
const fileIo = await import("@thi.ng/file-io");
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
46
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 1.03 KB
|
|
47
47
|
|
|
48
48
|
## Dependencies
|
|
49
49
|
|
|
@@ -75,4 +75,4 @@ If this project contributes to an academic publication, please cite it as:
|
|
|
75
75
|
|
|
76
76
|
## License
|
|
77
77
|
|
|
78
|
-
© 2022 Karsten Schmidt // Apache License 2.0
|
|
78
|
+
© 2022 - 2023 Karsten Schmidt // Apache License 2.0
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/file-io",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Assorted file I/O utils (with logging support) for NodeJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.6.
|
|
38
|
-
"@thi.ng/checks": "^3.3.
|
|
39
|
-
"@thi.ng/logger": "^1.4.
|
|
40
|
-
"@thi.ng/random": "^3.3.
|
|
37
|
+
"@thi.ng/api": "^8.6.3",
|
|
38
|
+
"@thi.ng/checks": "^3.3.7",
|
|
39
|
+
"@thi.ng/logger": "^1.4.7",
|
|
40
|
+
"@thi.ng/random": "^3.3.21"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@microsoft/api-extractor": "^7.33.7",
|
|
44
|
-
"@thi.ng/testament": "^0.3.
|
|
44
|
+
"@thi.ng/testament": "^0.3.9",
|
|
45
45
|
"rimraf": "^3.0.2",
|
|
46
46
|
"tools": "^0.0.1",
|
|
47
47
|
"typedoc": "^0.23.22",
|
|
@@ -95,6 +95,9 @@
|
|
|
95
95
|
"./mask": {
|
|
96
96
|
"default": "./mask.js"
|
|
97
97
|
},
|
|
98
|
+
"./read": {
|
|
99
|
+
"default": "./read.js"
|
|
100
|
+
},
|
|
98
101
|
"./temp": {
|
|
99
102
|
"default": "./temp.js"
|
|
100
103
|
},
|
|
@@ -109,5 +112,5 @@
|
|
|
109
112
|
"status": "stable",
|
|
110
113
|
"year": 2022
|
|
111
114
|
},
|
|
112
|
-
"gitHead": "
|
|
115
|
+
"gitHead": "3f0b3e2a7c82aefc7e46fb4338369836b5e1b8cf\n"
|
|
113
116
|
}
|
package/read.d.ts
ADDED
package/read.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
/**
|
|
3
|
+
* Reads given file `path` into a byte array.
|
|
4
|
+
*
|
|
5
|
+
* @param path
|
|
6
|
+
* @param logger
|
|
7
|
+
*/
|
|
8
|
+
export const readBinary = (path, logger) => {
|
|
9
|
+
logger && logger.debug("reading file:", path);
|
|
10
|
+
const buf = readFileSync(path);
|
|
11
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
12
|
+
};
|
package/text.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { ILogger } from "@thi.ng/logger";
|
|
2
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Reads text from given file `path`, optionally with custom encoding (default:
|
|
5
|
+
* UTF-8).
|
|
6
|
+
*
|
|
7
|
+
* @param path
|
|
8
|
+
* @param logger
|
|
9
|
+
* @param encoding
|
|
10
|
+
*/
|
|
11
|
+
export declare const readText: (path: string, logger?: ILogger, encoding?: Extract<BufferEncoding, "ascii" | "latin1" | "utf-8" | "utf-16le" | "ucs-2">) => string;
|
|
3
12
|
/**
|
|
4
13
|
* Writes `body` as UTF-8 file to given `path`. If `dryRun` is true (default:
|
|
5
14
|
* false), the file WON'T be written, however if a `logger` is provided then at
|
package/text.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { isArray } from "@thi.ng/checks/is-array";
|
|
2
2
|
import { readFileSync } from "fs";
|
|
3
3
|
import { writeFile } from "./write.js";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Reads text from given file `path`, optionally with custom encoding (default:
|
|
6
|
+
* UTF-8).
|
|
7
|
+
*
|
|
8
|
+
* @param path
|
|
9
|
+
* @param logger
|
|
10
|
+
* @param encoding
|
|
11
|
+
*/
|
|
12
|
+
export const readText = (path, logger, encoding = "utf-8") => {
|
|
5
13
|
logger && logger.debug("reading file:", path);
|
|
6
|
-
return readFileSync(path,
|
|
14
|
+
return readFileSync(path, encoding);
|
|
7
15
|
};
|
|
8
16
|
/**
|
|
9
17
|
* Writes `body` as UTF-8 file to given `path`. If `dryRun` is true (default:
|