@visulima/fs 4.0.4 → 4.0.6
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 +30 -0
- package/LICENSE.md +3 -0
- package/dist/constants.d.ts +42 -0
- package/dist/ensure/ensure-dir-sync.d.ts +14 -0
- package/dist/ensure/ensure-dir.d.ts +14 -0
- package/dist/ensure/ensure-file-sync.d.ts +15 -0
- package/dist/ensure/ensure-file.d.ts +27 -0
- package/dist/ensure/ensure-link-sync.d.ts +16 -0
- package/dist/ensure/ensure-link.d.ts +16 -0
- package/dist/ensure/ensure-symlink-sync.d.ts +23 -0
- package/dist/ensure/ensure-symlink.d.ts +23 -0
- package/dist/ensure/utils/get-file-info-type.d.ts +7 -0
- package/dist/ensure/utils/is-stats-identical.d.ts +3 -0
- package/dist/ensure/utils/resolve-symlink-target.d.ts +2 -0
- package/dist/eol.d.ts +35 -7
- package/dist/error/already-exists-error.d.ts +39 -0
- package/dist/error/directory-error.d.ts +47 -0
- package/dist/error/json-error.d.ts +52 -0
- package/dist/error/not-empty-error.d.ts +51 -0
- package/dist/error/not-found-error.d.ts +44 -0
- package/dist/error/permission-error.d.ts +45 -0
- package/dist/error/walk-error.d.ts +51 -0
- package/dist/error.d.ts +7 -50
- package/dist/find/collect-sync.d.ts +31 -0
- package/dist/find/collect.d.ts +35 -0
- package/dist/find/find-up-sync.d.ts +42 -0
- package/dist/find/find-up.d.ts +46 -0
- package/dist/find/utils/glob-to-regex.d.ts +2 -0
- package/dist/find/utils/walk-include.d.ts +2 -0
- package/dist/find/walk-sync.d.ts +26 -0
- package/dist/find/walk.d.ts +29 -0
- package/dist/index.d.ts +34 -136
- package/dist/index.js +14 -14
- package/dist/is-accessible-sync.d.ts +3 -0
- package/dist/is-accessible.d.ts +29 -0
- package/dist/move/index.d.ts +70 -0
- package/dist/move/types.d.ts +38 -0
- package/dist/move/utils/internal-move-file-sync.d.ts +3 -0
- package/dist/move/utils/internal-move-file.d.ts +3 -0
- package/dist/move/utils/validate-same-directory.d.ts +2 -0
- package/dist/packem_shared/{F_OK-MldBaGxb.js → F_OK-BalxCn9n.js} +1 -1
- package/dist/packem_shared/{findUp-BSnyGqer.js → findUp-Lv9mZCIQ.js} +1 -1
- package/dist/packem_shared/{findUpSync-jRHbSCMV.js → findUpSync-BsK4Nrrq.js} +1 -1
- package/dist/packem_shared/{isAccessible-DuVrTNFV.js → isAccessible-iOp0Bou6.js} +1 -1
- package/dist/packem_shared/{isAccessibleSync-DI8mM0fA.js → isAccessibleSync-38BmiIcx.js} +1 -1
- package/dist/packem_shared/{move-DbpW5_vA.js → move-BD6JbYSu.js} +2 -2
- package/dist/packem_shared/{readFile-iHOVXeH-.js → readFile-XVOjAw8r.js} +11 -14
- package/dist/packem_shared/{readFileSync-BkEj9BQY.js → readFileSync-B9Zg5PSF.js} +2 -2
- package/dist/packem_shared/{readJson-pdfQBWDR.js → readJson-Dra2m6s-.js} +1 -1
- package/dist/packem_shared/{readJsonSync-BZqGcA5d.js → readJsonSync-B6Dl1I_6.js} +1 -1
- package/dist/packem_shared/{readYaml-BQXTlR2p.js → readYaml-Bu1nsexB.js} +1 -1
- package/dist/packem_shared/{readYamlSync-BBBQ5ujx.js → readYamlSync-Di88aMME.js} +1 -1
- package/dist/packem_shared/{stripJsonComments-vo4k0mpF.js → stripJsonComments-21XWVDwP.js} +1 -1
- package/dist/packem_shared/{writeFile-DSHERs0Z.js → writeFile-NT1fLEEe.js} +2 -2
- package/dist/packem_shared/{writeFileSync-CJp1kXQR.js → writeFileSync-Bj5UDSf0.js} +2 -2
- package/dist/packem_shared/{writeJson-C0OfLDbe.js → writeJson-DQLdAi0d.js} +3 -3
- package/dist/packem_shared/{writeJsonSync-Cs21FE7v.js → writeJsonSync-DvTCjVUi.js} +3 -3
- package/dist/packem_shared/{writeYaml-n4xzYN9a.js → writeYaml-BMY0kOPf.js} +1 -1
- package/dist/packem_shared/{writeYamlSync-DnOEnP10.js → writeYamlSync-DqPu8cCd.js} +1 -1
- package/dist/read/read-file-sync.d.ts +37 -0
- package/dist/read/read-file.d.ts +41 -0
- package/dist/read/read-json-sync.d.ts +5 -0
- package/dist/read/read-json.d.ts +5 -0
- package/dist/read/read-yaml-sync.d.ts +4 -0
- package/dist/read/read-yaml.d.ts +4 -0
- package/dist/remove/empty-dir-sync.d.ts +24 -0
- package/dist/remove/empty-dir.d.ts +28 -0
- package/dist/remove/remove-sync.d.ts +28 -0
- package/dist/remove/remove.d.ts +32 -0
- package/dist/size.d.ts +245 -12
- package/dist/types.d.ts +299 -0
- package/dist/utils/assert-valid-file-contents.d.ts +27 -0
- package/dist/utils/assert-valid-file-or-directory-path.d.ts +26 -0
- package/dist/utils/parse-json.d.ts +5 -0
- package/dist/utils/strip-json-comments.d.ts +44 -0
- package/dist/utils.d.ts +6 -19
- package/dist/utils.js +1 -1
- package/dist/write/utils/to-uint-8-array.d.ts +2 -0
- package/dist/write/write-file-sync.d.ts +30 -0
- package/dist/write/write-file.d.ts +30 -0
- package/dist/write/write-json-sync.d.ts +30 -0
- package/dist/write/write-json.d.ts +30 -0
- package/dist/write/write-yaml-sync.d.ts +4 -0
- package/dist/write/write-yaml.d.ts +4 -0
- package/dist/yaml.d.ts +5 -17
- package/dist/yaml.js +4 -4
- package/package.json +2 -3
- package/dist/packem_shared/json-error-ZPgZIXcg.d.ts +0 -11
- package/dist/packem_shared/types-T308NKwz.d.ts +0 -90
|
@@ -2,7 +2,7 @@ const F_OK = 0;
|
|
|
2
2
|
const R_OK = 4;
|
|
3
3
|
const W_OK = 2;
|
|
4
4
|
const X_OK = 1;
|
|
5
|
-
const FIND_UP_STOP =
|
|
5
|
+
const FIND_UP_STOP = Symbol("findUpStop");
|
|
6
6
|
const INTERNAL_STRIP_JSON_REGEX = /"(?:[^"\\]|\\.)*"|\/\/[^\r\n]*|\/\*[\s\S]*?\*\//g;
|
|
7
7
|
|
|
8
8
|
export { FIND_UP_STOP, F_OK, INTERNAL_STRIP_JSON_REGEX, R_OK, W_OK, X_OK };
|
|
@@ -26,7 +26,7 @@ const {
|
|
|
26
26
|
} = __cjs_getBuiltinModule("node:url");
|
|
27
27
|
import { resolve, parse, isAbsolute, dirname } from '@visulima/path';
|
|
28
28
|
import { toPath } from '@visulima/path/utils';
|
|
29
|
-
import { FIND_UP_STOP } from './F_OK-
|
|
29
|
+
import { FIND_UP_STOP } from './F_OK-BalxCn9n.js';
|
|
30
30
|
|
|
31
31
|
const findUp = async (name, options = {}) => {
|
|
32
32
|
if (typeof name !== "string" && !Array.isArray(name) && typeof name !== "function") {
|
|
@@ -26,7 +26,7 @@ const {
|
|
|
26
26
|
} = __cjs_getBuiltinModule("node:url");
|
|
27
27
|
import { resolve, parse, isAbsolute, dirname } from '@visulima/path';
|
|
28
28
|
import { toPath } from '@visulima/path/utils';
|
|
29
|
-
import { FIND_UP_STOP } from './F_OK-
|
|
29
|
+
import { FIND_UP_STOP } from './F_OK-BalxCn9n.js';
|
|
30
30
|
|
|
31
31
|
const findUpSync = (name, options = {}) => {
|
|
32
32
|
if (typeof name !== "string" && !Array.isArray(name) && typeof name !== "function") {
|
|
@@ -21,7 +21,7 @@ const {
|
|
|
21
21
|
access
|
|
22
22
|
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
23
23
|
import { toPath } from '@visulima/path/utils';
|
|
24
|
-
import { F_OK } from './F_OK-
|
|
24
|
+
import { F_OK } from './F_OK-BalxCn9n.js';
|
|
25
25
|
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
26
26
|
|
|
27
27
|
async function isAccessible(path, mode = F_OK) {
|
|
@@ -21,7 +21,7 @@ const {
|
|
|
21
21
|
accessSync
|
|
22
22
|
} = __cjs_getBuiltinModule("node:fs");
|
|
23
23
|
import { toPath } from '@visulima/path/utils';
|
|
24
|
-
import { F_OK } from './F_OK-
|
|
24
|
+
import { F_OK } from './F_OK-BalxCn9n.js';
|
|
25
25
|
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
26
26
|
|
|
27
27
|
function isAccessibleSync(path, mode = F_OK) {
|
|
@@ -28,14 +28,14 @@ const {
|
|
|
28
28
|
unlink
|
|
29
29
|
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
30
30
|
import { dirname, resolve } from '@visulima/path';
|
|
31
|
-
import isAccessible from './isAccessible-
|
|
31
|
+
import isAccessible from './isAccessible-iOp0Bou6.js';
|
|
32
32
|
const {
|
|
33
33
|
mkdirSync,
|
|
34
34
|
renameSync: renameSync$1,
|
|
35
35
|
copyFileSync,
|
|
36
36
|
unlinkSync
|
|
37
37
|
} = __cjs_getBuiltinModule("node:fs");
|
|
38
|
-
import isAccessibleSync from './isAccessibleSync-
|
|
38
|
+
import isAccessibleSync from './isAccessibleSync-38BmiIcx.js';
|
|
39
39
|
|
|
40
40
|
class SameDirectoryError extends Error {
|
|
41
41
|
constructor(source, destination) {
|
|
@@ -25,9 +25,9 @@ const {
|
|
|
25
25
|
brotliDecompress
|
|
26
26
|
} = __cjs_getBuiltinModule("node:zlib");
|
|
27
27
|
import { toPath } from '@visulima/path/utils';
|
|
28
|
-
import { R_OK } from './F_OK-
|
|
28
|
+
import { R_OK } from './F_OK-BalxCn9n.js';
|
|
29
29
|
import PermissionError from './PermissionError-1qs0skfo.js';
|
|
30
|
-
import isAccessible from './isAccessible-
|
|
30
|
+
import isAccessible from './isAccessible-iOp0Bou6.js';
|
|
31
31
|
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
32
32
|
|
|
33
33
|
const decompressionMethods = {
|
|
@@ -48,18 +48,15 @@ const readFile = async (path, options) => {
|
|
|
48
48
|
}
|
|
49
49
|
const { buffer, compression, encoding, flag } = options ?? {};
|
|
50
50
|
return await readFile$1(path, flag ? { encoding, flag } : { encoding }).then(
|
|
51
|
-
async (content) => (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
})
|
|
62
|
-
)
|
|
51
|
+
async (content) => await new Promise((resolve, reject) => {
|
|
52
|
+
decompressionMethods[compression ?? "none"](content, (error, result) => {
|
|
53
|
+
if (error) {
|
|
54
|
+
reject(error);
|
|
55
|
+
} else {
|
|
56
|
+
resolve(buffer ? result : result.toString());
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
})
|
|
63
60
|
).catch((error) => {
|
|
64
61
|
throw error;
|
|
65
62
|
});
|
|
@@ -25,9 +25,9 @@ const {
|
|
|
25
25
|
brotliDecompressSync
|
|
26
26
|
} = __cjs_getBuiltinModule("node:zlib");
|
|
27
27
|
import { toPath } from '@visulima/path/utils';
|
|
28
|
-
import { R_OK } from './F_OK-
|
|
28
|
+
import { R_OK } from './F_OK-BalxCn9n.js';
|
|
29
29
|
import PermissionError from './PermissionError-1qs0skfo.js';
|
|
30
|
-
import isAccessibleSync from './isAccessibleSync-
|
|
30
|
+
import isAccessibleSync from './isAccessibleSync-38BmiIcx.js';
|
|
31
31
|
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
32
32
|
|
|
33
33
|
const decompressionMethods = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toPath } from '@visulima/path/utils';
|
|
2
2
|
import parseJson from './parseJson-CqUuRguZ.js';
|
|
3
|
-
import readFile from './readFile-
|
|
3
|
+
import readFile from './readFile-XVOjAw8r.js';
|
|
4
4
|
|
|
5
5
|
async function readJson(path, reviver, options) {
|
|
6
6
|
if (typeof reviver === "object") {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toPath } from '@visulima/path/utils';
|
|
2
2
|
import parseJson from './parseJson-CqUuRguZ.js';
|
|
3
|
-
import readFileSync from './readFileSync-
|
|
3
|
+
import readFileSync from './readFileSync-B9Zg5PSF.js';
|
|
4
4
|
|
|
5
5
|
function readJsonSync(path, reviver, options) {
|
|
6
6
|
if (typeof reviver === "object") {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parse } from 'yaml';
|
|
2
|
-
import readFile from './readFile-
|
|
2
|
+
import readFile from './readFile-XVOjAw8r.js';
|
|
3
3
|
|
|
4
4
|
async function readYaml(path, reviver, options) {
|
|
5
5
|
const { buffer, compression, encoding = "utf8", flag, ...parseOptions } = options ?? {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parse } from 'yaml';
|
|
2
|
-
import readFileSync from './readFileSync-
|
|
2
|
+
import readFileSync from './readFileSync-B9Zg5PSF.js';
|
|
3
3
|
|
|
4
4
|
function readYamlSync(path, reviver, options) {
|
|
5
5
|
const { buffer, compression, encoding = "utf8", flag, ...parseOptions } = options ?? {};
|
|
@@ -28,8 +28,8 @@ const {
|
|
|
28
28
|
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
29
29
|
import { dirname } from '@visulima/path';
|
|
30
30
|
import { toPath } from '@visulima/path/utils';
|
|
31
|
-
import { F_OK } from './F_OK-
|
|
32
|
-
import isAccessible from './isAccessible-
|
|
31
|
+
import { F_OK } from './F_OK-BalxCn9n.js';
|
|
32
|
+
import isAccessible from './isAccessible-iOp0Bou6.js';
|
|
33
33
|
import assertValidFileContents from './assertValidFileContents-BmcLtsGd.js';
|
|
34
34
|
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
35
35
|
import { t as toUint8Array } from './to-uint-8-array-Dz2nF1y1.js';
|
|
@@ -28,8 +28,8 @@ const {
|
|
|
28
28
|
} = __cjs_getBuiltinModule("node:fs");
|
|
29
29
|
import { dirname } from '@visulima/path';
|
|
30
30
|
import { toPath } from '@visulima/path/utils';
|
|
31
|
-
import { F_OK } from './F_OK-
|
|
32
|
-
import isAccessibleSync from './isAccessibleSync-
|
|
31
|
+
import { F_OK } from './F_OK-BalxCn9n.js';
|
|
32
|
+
import isAccessibleSync from './isAccessibleSync-38BmiIcx.js';
|
|
33
33
|
import assertValidFileContents from './assertValidFileContents-BmcLtsGd.js';
|
|
34
34
|
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-8HANmVjk.js';
|
|
35
35
|
import { t as toUint8Array } from './to-uint-8-array-Dz2nF1y1.js';
|
|
@@ -21,9 +21,9 @@ const {
|
|
|
21
21
|
readFile
|
|
22
22
|
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
23
23
|
import { d as detectIndent } from './index-CHM-in-V.js';
|
|
24
|
-
import { R_OK } from './F_OK-
|
|
25
|
-
import isAccessible from './isAccessible-
|
|
26
|
-
import writeFile from './writeFile-
|
|
24
|
+
import { R_OK } from './F_OK-BalxCn9n.js';
|
|
25
|
+
import isAccessible from './isAccessible-iOp0Bou6.js';
|
|
26
|
+
import writeFile from './writeFile-NT1fLEEe.js';
|
|
27
27
|
|
|
28
28
|
const writeJson = async (path, data, options = {}) => {
|
|
29
29
|
const { detectIndent: detectIndent$1, indent: indentOption, replacer, stringify = JSON.stringify, ...writeOptions } = { indent: " ", ...options };
|
|
@@ -21,9 +21,9 @@ const {
|
|
|
21
21
|
readFileSync
|
|
22
22
|
} = __cjs_getBuiltinModule("node:fs");
|
|
23
23
|
import { d as detectIndent } from './index-CHM-in-V.js';
|
|
24
|
-
import { R_OK } from './F_OK-
|
|
25
|
-
import isAccessibleSync from './isAccessibleSync-
|
|
26
|
-
import writeFileSync from './writeFileSync-
|
|
24
|
+
import { R_OK } from './F_OK-BalxCn9n.js';
|
|
25
|
+
import isAccessibleSync from './isAccessibleSync-38BmiIcx.js';
|
|
26
|
+
import writeFileSync from './writeFileSync-Bj5UDSf0.js';
|
|
27
27
|
|
|
28
28
|
const writeJsonSync = (path, data, options = {}) => {
|
|
29
29
|
const { detectIndent: detectIndent$1, indent: indentOption, replacer, stringify = JSON.stringify, ...writeOptions } = { indent: " ", ...options };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ContentType, ReadFileOptions } from "../types.d.ts";
|
|
2
|
+
type DecompressionMethod = (buffer: Buffer, callback: (error: Error | null, result: Buffer) => void) => void;
|
|
3
|
+
declare const decompressionMethods: Record<string, DecompressionMethod>;
|
|
4
|
+
/**
|
|
5
|
+
* Synchronously reads the entire contents of a file.
|
|
6
|
+
* It can also decompress the file content if a `compression` option is provided.
|
|
7
|
+
* @template O - The type of the options object, extending {@link ReadFileOptions}.
|
|
8
|
+
* @param path The path to the file to read. Can be a file URL or a string path.
|
|
9
|
+
* @param options Optional configuration for reading the file. See {@link ReadFileOptions}.
|
|
10
|
+
* Available `compression` methods: "brotli", "gzip", "none" (default).
|
|
11
|
+
* @returns The file content. The type of the content (string or Buffer)
|
|
12
|
+
* depends on the `buffer` option (defaults to string if `buffer` is false or not set).
|
|
13
|
+
* @example
|
|
14
|
+
* ```javascript
|
|
15
|
+
* import { readFileSync } from "@visulima/fs";
|
|
16
|
+
* import { join } from "node:path";
|
|
17
|
+
*
|
|
18
|
+
* try {
|
|
19
|
+
* // Read a regular text file
|
|
20
|
+
* const content = readFileSync(join("path", "to", "my-file.txt"));
|
|
21
|
+
* console.log("File content:", content);
|
|
22
|
+
*
|
|
23
|
+
* // Read a file as a Buffer
|
|
24
|
+
* const bufferContent = readFileSync(join("path", "to", "another-file.bin"), { buffer: true });
|
|
25
|
+
* console.log("Buffer length:", bufferContent.length);
|
|
26
|
+
*
|
|
27
|
+
* // Read and decompress a gzipped file
|
|
28
|
+
* // Assume my-archive.txt.gz exists
|
|
29
|
+
* // const decompressedContent = readFileSync(join("path", "to", "my-archive.txt.gz"), { compression: "gzip", encoding: "utf8" });
|
|
30
|
+
* // console.log("Decompressed content:", decompressedContent);
|
|
31
|
+
* } catch (error) {
|
|
32
|
+
* console.error("Failed to read file:", error);
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare const readFileSync: <O extends ReadFileOptions<keyof typeof decompressionMethods> | undefined = undefined>(path: URL | string, options?: O) => ContentType<O>;
|
|
37
|
+
export default readFileSync;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ContentType, ReadFileOptions } from "../types.d.ts";
|
|
2
|
+
type DecompressionMethod = (buffer: Buffer, callback: (error: Error | null, result: Buffer) => void) => void;
|
|
3
|
+
declare const decompressionMethods: Record<string, DecompressionMethod>;
|
|
4
|
+
/**
|
|
5
|
+
* Asynchronously reads the entire contents of a file.
|
|
6
|
+
* It can also decompress the file content if a `compression` option is provided.
|
|
7
|
+
* @template O - The type of the options object, extending {@link ReadFileOptions}.
|
|
8
|
+
* @param path The path to the file to read. Can be a file URL or a string path.
|
|
9
|
+
* @param options Optional configuration for reading the file. See {@link ReadFileOptions}.
|
|
10
|
+
* Available `compression` methods: "brotli", "gzip", "none" (default).
|
|
11
|
+
* @returns A promise that resolves with the file content. The type of the content (string or Buffer)
|
|
12
|
+
* depends on the `buffer` option (defaults to string if `buffer` is false or not set).
|
|
13
|
+
* @example
|
|
14
|
+
* ```javascript
|
|
15
|
+
* import { readFile } from "@visulima/fs";
|
|
16
|
+
* import { join } from "node:path";
|
|
17
|
+
*
|
|
18
|
+
* const readMyFile = async () => {
|
|
19
|
+
* try {
|
|
20
|
+
* // Read a regular text file
|
|
21
|
+
* const content = await readFile(join("path", "to", "my-file.txt"));
|
|
22
|
+
* console.log("File content:", content);
|
|
23
|
+
*
|
|
24
|
+
* // Read a file as a Buffer
|
|
25
|
+
* const bufferContent = await readFile(join("path", "to", "another-file.bin"), { buffer: true });
|
|
26
|
+
* console.log("Buffer length:", bufferContent.length);
|
|
27
|
+
*
|
|
28
|
+
* // Read and decompress a gzipped file
|
|
29
|
+
* // Assume my-archive.txt.gz exists
|
|
30
|
+
* // const decompressedContent = await readFile(join("path", "to", "my-archive.txt.gz"), { compression: "gzip", encoding: "utf8" });
|
|
31
|
+
* // console.log("Decompressed content:", decompressedContent);
|
|
32
|
+
* } catch (error) {
|
|
33
|
+
* console.error("Failed to read file:", error);
|
|
34
|
+
* }
|
|
35
|
+
* };
|
|
36
|
+
*
|
|
37
|
+
* readMyFile();
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare const readFile: <O extends ReadFileOptions<keyof typeof decompressionMethods> | undefined = undefined>(path: URL | string, options?: O) => Promise<ContentType<O>>;
|
|
41
|
+
export default readFile;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { JsonValue } from "type-fest";
|
|
2
|
+
import type { JsonReviver, ReadJsonOptions } from "../types.d.ts";
|
|
3
|
+
declare function readJsonSync<T extends JsonValue>(path: URL | string, options?: ReadJsonOptions): T;
|
|
4
|
+
declare function readJsonSync<T extends JsonValue>(path: URL | string, reviver: JsonReviver, options?: ReadJsonOptions): T;
|
|
5
|
+
export default readJsonSync;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { JsonValue } from "type-fest";
|
|
2
|
+
import type { JsonReviver, ReadJsonOptions } from "../types.d.ts";
|
|
3
|
+
declare function readJson<T extends JsonValue>(path: URL | string, options?: ReadJsonOptions): Promise<T>;
|
|
4
|
+
declare function readJson<T extends JsonValue>(path: URL | string, reviver: JsonReviver, options?: ReadJsonOptions): Promise<T>;
|
|
5
|
+
export default readJson;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ReadYamlOptions, YamlReviver } from "../types.d.ts";
|
|
2
|
+
declare function readYamlSync<R = Record<string, unknown>>(path: URL | string, options?: ReadYamlOptions<"brotli" | "gzip" | "none">): R;
|
|
3
|
+
declare function readYamlSync<R = Record<string, unknown>>(path: URL | string, reviver?: YamlReviver, options?: ReadYamlOptions<"brotli" | "gzip" | "none">): R;
|
|
4
|
+
export default readYamlSync;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ReadYamlOptions, YamlReviver } from "../types.d.ts";
|
|
2
|
+
declare function readYaml<R = Record<string, unknown>>(path: URL | string, options?: ReadYamlOptions<"brotli" | "gzip" | "none">): Promise<R>;
|
|
3
|
+
declare function readYaml<R = Record<string, unknown>>(path: URL | string, reviver?: YamlReviver, options?: ReadYamlOptions<"brotli" | "gzip" | "none">): Promise<R>;
|
|
4
|
+
export default readYaml;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { RetryOptions } from "../types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Ensures that a directory is empty.
|
|
4
|
+
* Deletes directory contents if the directory is not empty.
|
|
5
|
+
* If the directory does not exist, it is created.
|
|
6
|
+
* The directory itself is not deleted.
|
|
7
|
+
* @param dir The path to the directory to empty.
|
|
8
|
+
* @param options Optional configuration for the operation. See {@link RetryOptions}.
|
|
9
|
+
* @returns void
|
|
10
|
+
* @example
|
|
11
|
+
* ```javascript
|
|
12
|
+
* import { emptyDirSync } from "@visulima/fs";
|
|
13
|
+
* import { join } from "node:path";
|
|
14
|
+
*
|
|
15
|
+
* try {
|
|
16
|
+
* emptyDirSync(join("/tmp", "my-app-temp"));
|
|
17
|
+
* console.log("Temporary directory emptied or created.");
|
|
18
|
+
* } catch (error) {
|
|
19
|
+
* console.error("Failed to empty directory:", error);
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare const emptyDirSync: (dir: URL | string, options?: RetryOptions) => void;
|
|
24
|
+
export default emptyDirSync;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RetryOptions } from "../types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Ensures that a directory is empty.
|
|
4
|
+
* Deletes directory contents if the directory is not empty.
|
|
5
|
+
* If the directory does not exist, it is created.
|
|
6
|
+
* The directory itself is not deleted.
|
|
7
|
+
* @param dir The path to the directory to empty.
|
|
8
|
+
* @param options Optional configuration for the operation. See {@link RetryOptions}.
|
|
9
|
+
* @returns A promise that resolves when the directory is empty.
|
|
10
|
+
* @example
|
|
11
|
+
* ```javascript
|
|
12
|
+
* import { emptyDir } from "@visulima/fs";
|
|
13
|
+
* import { join } from "node:path";
|
|
14
|
+
*
|
|
15
|
+
* const clearTempDir = async () => {
|
|
16
|
+
* try {
|
|
17
|
+
* await emptyDir(join("/tmp", "my-app-temp"));
|
|
18
|
+
* console.log("Temporary directory emptied or created.");
|
|
19
|
+
* } catch (error) {
|
|
20
|
+
* console.error("Failed to empty directory:", error);
|
|
21
|
+
* }
|
|
22
|
+
* };
|
|
23
|
+
*
|
|
24
|
+
* clearTempDir();
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare const emptyDir: (dir: URL | string, options?: RetryOptions) => Promise<void>;
|
|
28
|
+
export default emptyDir;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RetryOptions } from "../types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Synchronously removes a file or directory (recursively).
|
|
4
|
+
* If the path does not exist, it does nothing.
|
|
5
|
+
* @param path The path to the file or directory to remove.
|
|
6
|
+
* @param options Optional configuration for the operation. See {@link RetryOptions}.
|
|
7
|
+
* @returns void
|
|
8
|
+
* @example
|
|
9
|
+
* ```javascript
|
|
10
|
+
* import { removeSync } from "@visulima/fs";
|
|
11
|
+
* import { join } from "node:path";
|
|
12
|
+
*
|
|
13
|
+
* try {
|
|
14
|
+
* removeSync(join("/tmp", "my-file.txt"));
|
|
15
|
+
* console.log("File /tmp/my-file.txt removed.");
|
|
16
|
+
*
|
|
17
|
+
* removeSync(join("/tmp", "my-empty-dir"));
|
|
18
|
+
* console.log("Directory /tmp/my-empty-dir removed.");
|
|
19
|
+
*
|
|
20
|
+
* removeSync(join("/tmp", "my-dir-with-contents"));
|
|
21
|
+
* console.log("Directory /tmp/my-dir-with-contents and its contents removed.");
|
|
22
|
+
* } catch (error) {
|
|
23
|
+
* console.error("Failed to remove path:", error);
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare const removeSync: (path: URL | string, options?: RetryOptions) => void;
|
|
28
|
+
export default removeSync;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RetryOptions } from "../types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Asynchronously removes a file or directory (recursively).
|
|
4
|
+
* If the path does not exist, it does nothing.
|
|
5
|
+
* @param path The path to the file or directory to remove.
|
|
6
|
+
* @param options Optional configuration for the operation. See {@link RetryOptions}.
|
|
7
|
+
* @returns A promise that resolves when the path has been removed.
|
|
8
|
+
* @example
|
|
9
|
+
* ```javascript
|
|
10
|
+
* import { remove } from "@visulima/fs";
|
|
11
|
+
* import { join } from "node:path";
|
|
12
|
+
*
|
|
13
|
+
* const deleteFileOrDir = async () => {
|
|
14
|
+
* try {
|
|
15
|
+
* await remove(join("/tmp", "my-file.txt"));
|
|
16
|
+
* console.log("File /tmp/my-file.txt removed.");
|
|
17
|
+
*
|
|
18
|
+
* await remove(join("/tmp", "my-empty-dir"));
|
|
19
|
+
* console.log("Directory /tmp/my-empty-dir removed.");
|
|
20
|
+
*
|
|
21
|
+
* await remove(join("/tmp", "my-dir-with-contents"));
|
|
22
|
+
* console.log("Directory /tmp/my-dir-with-contents and its contents removed.");
|
|
23
|
+
* } catch (error) {
|
|
24
|
+
* console.error("Failed to remove path:", error);
|
|
25
|
+
* }
|
|
26
|
+
* };
|
|
27
|
+
*
|
|
28
|
+
* deleteFileOrDir();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
declare const remove: (path: URL | string, options?: RetryOptions) => Promise<void>;
|
|
32
|
+
export default remove;
|