@visulima/fs 5.0.0-alpha.7 → 5.0.0-alpha.9
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 +46 -0
- package/LICENSE.md +155 -126
- package/dist/eol.d.ts +6 -35
- package/dist/error.d.ts +43 -7
- package/dist/glob-parent.d.ts +5 -0
- package/dist/glob-parent.js +90 -0
- package/dist/glob.d.ts +5 -0
- package/dist/glob.js +2 -0
- package/dist/index.d.ts +81 -36
- package/dist/index.js +16 -11
- package/dist/ini.d.ts +10 -0
- package/dist/ini.js +4 -0
- package/dist/is-glob.d.ts +5 -0
- package/dist/is-glob.js +9 -0
- package/dist/json5.d.ts +12 -0
- package/dist/json5.js +4 -0
- package/dist/jsonc.d.ts +10 -0
- package/dist/jsonc.js +4 -0
- package/dist/match.d.ts +5 -0
- package/dist/match.js +15 -0
- package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +5 -0
- package/dist/packem_shared/build-rm-options-Cl3VDY4O.js +12 -0
- package/dist/packem_shared/{collect-BnUYRrRI.js → collect-CqQ3eVab.js} +1 -1
- package/dist/packem_shared/{collectSync-D5G2RGDI.js → collectSync-noE08NNv.js} +1 -1
- package/dist/packem_shared/{emptyDir-Df4Tfjtk.js → emptyDir-DnwENOaV.js} +3 -1
- package/dist/packem_shared/{emptyDirSync-BD8-1Ytl.js → emptyDirSync-6WiHBo8a.js} +3 -1
- package/dist/packem_shared/glob-DY8l7izD.js +5 -0
- package/dist/packem_shared/glob-sync.d-B83kqwUd.d.ts +4 -0
- package/dist/packem_shared/globSync-5P2KJf_g.js +5 -0
- package/dist/packem_shared/index-C8W8sfzP.js +830 -0
- package/dist/packem_shared/index-bhgnhm4u.js +167 -0
- package/dist/packem_shared/index-xe4o3cYi.js +1784 -0
- package/dist/packem_shared/{parseJson-BedVi91S.js → indexToLineColumn-BUb0GPKl-BF770uX7.js} +1 -62
- package/dist/packem_shared/ini-preserve-Dq_Q_Jgb.js +251 -0
- package/dist/packem_shared/{isFsCaseSensitive-D-ayleCy.js → isFsCaseSensitive-DunL7Iry.js} +6 -6
- package/dist/packem_shared/json-error.d-DgKaeuIf.d.ts +10 -0
- package/dist/packem_shared/jsonc-merge-C6jWcfWh.js +72 -0
- package/dist/packem_shared/parseJson-BIp89Xjo.js +63 -0
- package/dist/packem_shared/readIni-CJ2xfpjB.js +10 -0
- package/dist/packem_shared/readIniSync-9LUjaSSp.js +10 -0
- package/dist/packem_shared/{readJson-D0G0ndHL.js → readJson-C_rwm-wq.js} +1 -1
- package/dist/packem_shared/readJson5-mBoTZppy.js +15 -0
- package/dist/packem_shared/readJson5Sync-8WS2yUok.js +15 -0
- package/dist/packem_shared/{readJsonSync-B7oicPaL.js → readJsonSync-BMEmCcJ6.js} +1 -1
- package/dist/packem_shared/readJsonc-j-OS-APg.js +28 -0
- package/dist/packem_shared/readJsoncSync-Aw6EMlWO.js +16 -0
- package/dist/packem_shared/readToml-B2MHaSes.js +9 -0
- package/dist/packem_shared/readTomlSync-DNbK8NEb.js +9 -0
- package/dist/packem_shared/{remove-CNkjFFkQ.js → remove-C8_gl3jF.js} +2 -1
- package/dist/packem_shared/{removeSync-AnawYpPv.js → removeSync-BJR_wTwN.js} +2 -1
- package/dist/packem_shared/types.d-dP-lAGNn.d.ts +145 -0
- package/dist/packem_shared/{walk-D5yHruvk.js → walk-CSZgCuDx.js} +10 -3
- package/dist/packem_shared/{walkSync-09nKPVw4.js → walkSync-C4Cy28xb.js} +10 -3
- package/dist/packem_shared/writeIni-i55QrL8y.js +65 -0
- package/dist/packem_shared/writeIniSync-CLqJE5t3.js +64 -0
- package/dist/packem_shared/writeJson5-vVmHUQOd.js +53 -0
- package/dist/packem_shared/writeJson5Sync-oJ546h5k.js +53 -0
- package/dist/packem_shared/writeJsonc-BufH_oC5.js +60 -0
- package/dist/packem_shared/writeJsoncSync-DB9be1YL.js +59 -0
- package/dist/packem_shared/writeToml-DgTW_-7F.js +8 -0
- package/dist/packem_shared/writeTomlSync-DiBiE9ja.js +8 -0
- package/dist/size.d.ts +10 -254
- package/dist/toml.d.ts +9 -0
- package/dist/toml.js +4 -0
- package/dist/utils.d.ts +15 -6
- package/dist/utils.js +1 -1
- package/dist/yaml.d.ts +14 -5
- package/package.json +58 -4
- package/dist/constants.d.ts +0 -42
- package/dist/ensure/ensure-dir-sync.d.ts +0 -14
- package/dist/ensure/ensure-dir.d.ts +0 -14
- package/dist/ensure/ensure-file-sync.d.ts +0 -15
- package/dist/ensure/ensure-file.d.ts +0 -27
- package/dist/ensure/ensure-link-sync.d.ts +0 -16
- package/dist/ensure/ensure-link.d.ts +0 -16
- package/dist/ensure/ensure-symlink-sync.d.ts +0 -23
- package/dist/ensure/ensure-symlink.d.ts +0 -23
- package/dist/ensure/utils/get-file-info-type.d.ts +0 -7
- package/dist/ensure/utils/is-stats-identical.d.ts +0 -3
- package/dist/ensure/utils/resolve-symlink-target.d.ts +0 -2
- package/dist/error/already-exists-error.d.ts +0 -39
- package/dist/error/directory-error.d.ts +0 -47
- package/dist/error/json-error.d.ts +0 -52
- package/dist/error/not-empty-error.d.ts +0 -51
- package/dist/error/not-found-error.d.ts +0 -44
- package/dist/error/permission-error.d.ts +0 -45
- package/dist/error/walk-error.d.ts +0 -51
- package/dist/find/collect-sync.d.ts +0 -31
- package/dist/find/collect.d.ts +0 -35
- package/dist/find/find-up-sync.d.ts +0 -42
- package/dist/find/find-up.d.ts +0 -46
- package/dist/find/utils/glob-to-regexp.d.ts +0 -2
- package/dist/find/utils/walk-include.d.ts +0 -2
- package/dist/find/walk-sync.d.ts +0 -34
- package/dist/find/walk.d.ts +0 -37
- package/dist/is-accessible-sync.d.ts +0 -3
- package/dist/is-accessible.d.ts +0 -29
- package/dist/move/index.d.ts +0 -68
- package/dist/move/types.d.ts +0 -36
- package/dist/move/utils/internal-move-file-sync.d.ts +0 -3
- package/dist/move/utils/internal-move-file.d.ts +0 -3
- package/dist/move/utils/validate-same-directory.d.ts +0 -2
- package/dist/read/read-file-sync.d.ts +0 -37
- package/dist/read/read-file.d.ts +0 -41
- package/dist/read/read-json-sync.d.ts +0 -5
- package/dist/read/read-json.d.ts +0 -5
- package/dist/read/read-yaml-sync.d.ts +0 -4
- package/dist/read/read-yaml.d.ts +0 -4
- package/dist/remove/empty-dir-sync.d.ts +0 -23
- package/dist/remove/empty-dir.d.ts +0 -28
- package/dist/remove/remove-sync.d.ts +0 -27
- package/dist/remove/remove.d.ts +0 -32
- package/dist/sanitize.d.ts +0 -31
- package/dist/types.d.ts +0 -304
- package/dist/utils/assert-valid-file-contents.d.ts +0 -27
- package/dist/utils/assert-valid-file-or-directory-path.d.ts +0 -26
- package/dist/utils/parse-json.d.ts +0 -5
- package/dist/utils/strip-json-comments.d.ts +0 -44
- package/dist/write/utils/to-uint-8-array.d.ts +0 -2
- package/dist/write/write-file-sync.d.ts +0 -30
- package/dist/write/write-file.d.ts +0 -30
- package/dist/write/write-json-sync.d.ts +0 -29
- package/dist/write/write-json.d.ts +0 -30
- package/dist/write/write-yaml-sync.d.ts +0 -4
- package/dist/write/write-yaml.d.ts +0 -4
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Asserts that the provided contents are valid for writing to a file.
|
|
3
|
-
* Valid contents can be a string, an ArrayBuffer, or an ArrayBuffer view (e.g., Uint8Array).
|
|
4
|
-
* @param contents The file contents to validate.
|
|
5
|
-
* @throws {TypeError} If the contents are not a string, ArrayBuffer, or ArrayBuffer view.
|
|
6
|
-
* @example
|
|
7
|
-
* ```javascript
|
|
8
|
-
* import { assertValidFileContents } from "@visulima/fs"; // Assuming this util is exported
|
|
9
|
-
*
|
|
10
|
-
* try {
|
|
11
|
-
* assertValidFileContents("Hello, world!");
|
|
12
|
-
* assertValidFileContents(new Uint8Array([72, 101, 108, 108, 111])); // "Hello"
|
|
13
|
-
* assertValidFileContents(new ArrayBuffer(8));
|
|
14
|
-
* console.log("File contents are valid.");
|
|
15
|
-
* } catch (error) {
|
|
16
|
-
* console.error(error.message); // File contents must be a string, ArrayBuffer, or ArrayBuffer view.
|
|
17
|
-
* }
|
|
18
|
-
*
|
|
19
|
-
* try {
|
|
20
|
-
* assertValidFileContents(123); // Invalid content type
|
|
21
|
-
* } catch (error) {
|
|
22
|
-
* console.error(error.message); // File contents must be a string, ArrayBuffer, or ArrayBuffer view.
|
|
23
|
-
* }
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
declare const assertValidFileContents: (contents: any) => void;
|
|
27
|
-
export default assertValidFileContents;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Asserts that the provided path is a valid file or directory path.
|
|
3
|
-
* A valid path must be a non-empty string or a URL instance.
|
|
4
|
-
* @param fileOrDirectoryPath The path to validate.
|
|
5
|
-
* @throws {TypeError} If the path is not a non-empty string or a URL.
|
|
6
|
-
* @example
|
|
7
|
-
* ```javascript
|
|
8
|
-
* import { assertValidFileOrDirectoryPath } from "@visulima/fs"; // Assuming this util is exported
|
|
9
|
-
*
|
|
10
|
-
* try {
|
|
11
|
-
* assertValidFileOrDirectoryPath("/path/to/file.txt");
|
|
12
|
-
* assertValidFileOrDirectoryPath(new URL("file:///path/to/file.txt"));
|
|
13
|
-
* console.log("Path is valid.");
|
|
14
|
-
* } catch (error) {
|
|
15
|
-
* console.error(error.message); // Path must be a non-empty string or URL.
|
|
16
|
-
* }
|
|
17
|
-
*
|
|
18
|
-
* try {
|
|
19
|
-
* assertValidFileOrDirectoryPath(""); // Invalid path
|
|
20
|
-
* } catch (error) {
|
|
21
|
-
* console.error(error.message); // Path must be a non-empty string or URL.
|
|
22
|
-
* }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
declare const assertValidFileOrDirectoryPath: (fileOrDirectoryPath: any) => void;
|
|
26
|
-
export default assertValidFileOrDirectoryPath;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { JsonValue } from "type-fest";
|
|
2
|
-
import type { CodeFrameOptions, JsonReviver } from "../types.d.ts";
|
|
3
|
-
declare function parseJson(string: string, filename?: string, options?: CodeFrameOptions): JsonValue;
|
|
4
|
-
declare function parseJson(string: string, reviver: JsonReviver, fileName?: string, options?: CodeFrameOptions): JsonValue;
|
|
5
|
-
export default parseJson;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Strips comments from a JSON string.
|
|
3
|
-
* Handles both single-line (//) and multi-line (/* ... */) comments.
|
|
4
|
-
* @param jsonString The JSON string possibly containing comments.
|
|
5
|
-
* @param [options] Optional configuration for stripping comments.
|
|
6
|
-
* @param [options.whitespace] If `true` (default), comments are replaced with whitespace to preserve line numbers and character positions. If `false`, comments are removed entirely.
|
|
7
|
-
* @returns The JSON string with comments stripped.
|
|
8
|
-
* @example
|
|
9
|
-
* ```javascript
|
|
10
|
-
* import { stripJsonComments } from "@visulima/fs"; // Assuming this util is exported
|
|
11
|
-
*
|
|
12
|
-
* const jsonWithComments = `{
|
|
13
|
-
* // This is a single-line comment
|
|
14
|
-
* "name": "John Doe",
|
|
15
|
-
* "age": 30, /* This is a
|
|
16
|
-
* multi-line comment */
|
|
17
|
-
* "city": "New York"
|
|
18
|
-
* }`;
|
|
19
|
-
*
|
|
20
|
-
* const stripped = stripJsonComments(jsonWithComments);
|
|
21
|
-
* console.log(stripped);
|
|
22
|
-
* // Output (with whitespace=true):
|
|
23
|
-
* // {
|
|
24
|
-
* //
|
|
25
|
-
* // "name": "John Doe",
|
|
26
|
-
* // "age": 30, /*
|
|
27
|
-
* //
|
|
28
|
-
* // "city": "New York"
|
|
29
|
-
* // }
|
|
30
|
-
*
|
|
31
|
-
* const strippedWithoutWhitespace = stripJsonComments(jsonWithComments, { whitespace: false });
|
|
32
|
-
* console.log(strippedWithoutWhitespace);
|
|
33
|
-
* // Output (with whitespace=false):
|
|
34
|
-
* // {
|
|
35
|
-
* // "name": "John Doe",
|
|
36
|
-
* // "age": 30,
|
|
37
|
-
* // "city": "New York"
|
|
38
|
-
* // }
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
declare const stripJsonComments: (jsonString: string, options?: {
|
|
42
|
-
whitespace?: boolean;
|
|
43
|
-
}) => string;
|
|
44
|
-
export default stripJsonComments;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { WriteFileOptions } from "../types.d.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Synchronously writes data to a file, replacing the file if it already exists.
|
|
4
|
-
* This function includes safeguards like writing to a temporary file first and then renaming, and handling permissions.
|
|
5
|
-
* @param path The path to the file to write. Can be a file URL or a string path.
|
|
6
|
-
* @param content The data to write. Can be a string, Buffer, ArrayBuffer, or ArrayBufferView.
|
|
7
|
-
* @param options Optional configuration for writing the file. See {@link WriteFileOptions}.
|
|
8
|
-
* @returns void
|
|
9
|
-
* @example
|
|
10
|
-
* ```javascript
|
|
11
|
-
* import { writeFileSync } from "@visulima/fs";
|
|
12
|
-
* import { join } from "node:path";
|
|
13
|
-
*
|
|
14
|
-
* const writeMyFileSync = () => {
|
|
15
|
-
* try {
|
|
16
|
-
* writeFileSync(join("/tmp", "my-new-file-sync.txt"), "Hello World Synchronously!");
|
|
17
|
-
* console.log("File written successfully (sync).");
|
|
18
|
-
*
|
|
19
|
-
* writeFileSync(join("/tmp", "another-file-sync.txt"), "Some other sync content", { encoding: 'utf16le', mode: 0o600 });
|
|
20
|
-
* console.log("Another file written with specific options (sync).");
|
|
21
|
-
* } catch (error) {
|
|
22
|
-
* console.error("Failed to write file (sync):", error);
|
|
23
|
-
* }
|
|
24
|
-
* };
|
|
25
|
-
*
|
|
26
|
-
* writeMyFileSync();
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
declare const writeFileSync: (path: URL | string, content: ArrayBuffer | ArrayBufferView | string, options?: WriteFileOptions) => void;
|
|
30
|
-
export default writeFileSync;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { WriteFileOptions } from "../types.d.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Asynchronously writes data to a file, replacing the file if it already exists.
|
|
4
|
-
* This function includes safeguards like writing to a temporary file first and then renaming, and handling permissions.
|
|
5
|
-
* @param path The path to the file to write. Can be a file URL or a string path.
|
|
6
|
-
* @param content The data to write. Can be a string, Buffer, ArrayBuffer, or ArrayBufferView.
|
|
7
|
-
* @param options Optional configuration for writing the file. See {@link WriteFileOptions}.
|
|
8
|
-
* @returns A promise that resolves when the file has been written.
|
|
9
|
-
* @example
|
|
10
|
-
* ```javascript
|
|
11
|
-
* import { writeFile } from "@visulima/fs";
|
|
12
|
-
* import { join } from "node:path";
|
|
13
|
-
*
|
|
14
|
-
* const writeMyFile = async () => {
|
|
15
|
-
* try {
|
|
16
|
-
* await writeFile(join("/tmp", "my-new-file.txt"), "Hello World!");
|
|
17
|
-
* console.log("File written successfully.");
|
|
18
|
-
*
|
|
19
|
-
* await writeFile(join("/tmp", "another-file.txt"), "Some other content", { encoding: 'utf16le', mode: 0o600 });
|
|
20
|
-
* console.log("Another file written with specific options.");
|
|
21
|
-
* } catch (error) {
|
|
22
|
-
* console.error("Failed to write file:", error);
|
|
23
|
-
* }
|
|
24
|
-
* };
|
|
25
|
-
*
|
|
26
|
-
* writeMyFile();
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
declare const writeFile: (path: URL | string, content: ArrayBuffer | ArrayBufferView | string, options?: WriteFileOptions) => Promise<void>;
|
|
30
|
-
export default writeFile;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { WriteJsonOptions } from "../types.d.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Synchronously writes an object to a JSON file.
|
|
4
|
-
* Handles indentation detection, custom stringifiers, and gracefully manages existing files.
|
|
5
|
-
* @param path The path to the JSON file to write. Can be a file URL or a string path.
|
|
6
|
-
* @param data The data to serialize and write. Can be any JavaScript value that can be stringified by `JSON.stringify` or a custom stringifier.
|
|
7
|
-
* @param options Optional configuration for writing the JSON file. See {@link WriteJsonOptions}.
|
|
8
|
-
* @example
|
|
9
|
-
* ```javascript
|
|
10
|
-
* import { writeJsonSync } from "@visulima/fs";
|
|
11
|
-
* import { join } from "node:path";
|
|
12
|
-
*
|
|
13
|
-
* const writeMyJsonSync = () => {
|
|
14
|
-
* try {
|
|
15
|
-
* writeJsonSync(join("/tmp", "my-config-sync.json"), { setting: "enabled", value: 456 });
|
|
16
|
-
* console.log("JSON file written successfully (sync).");
|
|
17
|
-
*
|
|
18
|
-
* writeJsonSync(join("/tmp", "another-config-sync.json"), { user: "testSync", id: "def" }, { indent: 4, replacer: ["id"] });
|
|
19
|
-
* console.log("Another JSON file written with specific options (sync, indent 4, only 'id' key).");
|
|
20
|
-
* } catch (error) {
|
|
21
|
-
* console.error("Failed to write JSON file (sync):", error);
|
|
22
|
-
* }
|
|
23
|
-
* };
|
|
24
|
-
*
|
|
25
|
-
* writeMyJsonSync();
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
declare const writeJsonSync: (path: URL | string, data: unknown, options?: WriteJsonOptions) => void;
|
|
29
|
-
export default writeJsonSync;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { WriteJsonOptions } from "../types.d.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Asynchronously writes an object to a JSON file.
|
|
4
|
-
* Handles indentation detection, custom stringifiers, and gracefully manages existing files.
|
|
5
|
-
* @param path The path to the JSON file to write. Can be a file URL or a string path.
|
|
6
|
-
* @param data The data to serialize and write. Can be any JavaScript value that can be stringified by `JSON.stringify` or a custom stringifier.
|
|
7
|
-
* @param options Optional configuration for writing the JSON file. See {@link WriteJsonOptions}.
|
|
8
|
-
* @returns A promise that resolves when the JSON file has been written.
|
|
9
|
-
* @example
|
|
10
|
-
* ```javascript
|
|
11
|
-
* import { writeJson } from "@visulima/fs";
|
|
12
|
-
* import { join } from "node:path";
|
|
13
|
-
*
|
|
14
|
-
* const writeMyJson = async () => {
|
|
15
|
-
* try {
|
|
16
|
-
* await writeJson(join("/tmp", "my-config.json"), { setting: "enabled", value: 123 });
|
|
17
|
-
* console.log("JSON file written successfully.");
|
|
18
|
-
*
|
|
19
|
-
* await writeJson(join("/tmp", "another-config.json"), { user: "test", id: "abc" }, { indent: 2, replacer: ["user"] });
|
|
20
|
-
* console.log("Another JSON file written with specific options (indent 2, only 'user' key).");
|
|
21
|
-
* } catch (error) {
|
|
22
|
-
* console.error("Failed to write JSON file:", error);
|
|
23
|
-
* }
|
|
24
|
-
* };
|
|
25
|
-
*
|
|
26
|
-
* writeMyJson();
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
declare const writeJson: (path: URL | string, data: unknown, options?: WriteJsonOptions) => Promise<void>;
|
|
30
|
-
export default writeJson;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { JsonReplacer, WriteYamlOptions } from "../types.d.ts";
|
|
2
|
-
declare function writeYamlSync(path: URL | string, data: any, options?: WriteYamlOptions): void;
|
|
3
|
-
declare function writeYamlSync(path: URL | string, data: any, replacer?: JsonReplacer, options?: WriteYamlOptions | number | string): void;
|
|
4
|
-
export default writeYamlSync;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { JsonReplacer, WriteYamlOptions } from "../types.d.ts";
|
|
2
|
-
declare function writeYaml(path: URL | string, data: any, options?: WriteYamlOptions): Promise<void>;
|
|
3
|
-
declare function writeYaml(path: URL | string, data: any, replacer?: JsonReplacer, options?: WriteYamlOptions | number | string): Promise<void>;
|
|
4
|
-
export default writeYaml;
|