@visulima/fs 5.0.0-alpha.11 → 5.0.0-alpha.13

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/dist/ini.d.ts CHANGED
@@ -1,10 +1,70 @@
1
- import { a as CompressionType, n as ReadIniOptions, o as WriteIniOptions } from "./packem_shared/types.d-CYpAhWov.js";
2
- export { type I as IniEncodeOptions, type p as IniLineEnding } from "./packem_shared/types.d-CYpAhWov.js";
1
+ import { a as CompressionType, j as ReadIniOptions, k as WriteIniOptions } from "./packem_shared/types.d-CixEXeyM.js";
2
+ export { type I as IniEncodeOptions, type l as IniLineEnding } from "./packem_shared/types.d-CixEXeyM.js";
3
3
  import 'node:fs';
4
4
  import 'tinyglobby';
5
- import './options';
5
+ /**
6
+ * Asynchronously reads an INI file and parses it into an object.
7
+ * @template R The expected type of the parsed object. Defaults to `Record<string, unknown>`.
8
+ * @param path The path to the INI file. Can be a file URL or a string path.
9
+ * @param options Optional configuration. See {@link ReadIniOptions}.
10
+ * @returns A promise that resolves with the parsed object.
11
+ * @example
12
+ * ```javascript
13
+ * import { readIni } from "@visulima/fs/ini";
14
+ *
15
+ * const config = await readIni("./config.ini");
16
+ * ```
17
+ */
6
18
  declare const readIni: <R = Record<string, unknown>>(path: URL | string, options?: ReadIniOptions<CompressionType>) => Promise<R>;
19
+ /**
20
+ * Synchronously reads an INI file and parses it into an object.
21
+ * @template R The expected type of the parsed object. Defaults to `Record&lt;string, unknown>`.
22
+ * @param path The path to the INI file. Can be a file URL or a string path.
23
+ * @param options Optional configuration. See {@link ReadIniOptions}.
24
+ * @returns The parsed object.
25
+ * @example
26
+ * ```javascript
27
+ * import { readIniSync } from "@visulima/fs/ini";
28
+ *
29
+ * const config = readIniSync("./config.ini");
30
+ * ```
31
+ */
7
32
  declare const readIniSync: (path: URL | string, options?: ReadIniOptions<CompressionType>) => Record<string, unknown>;
33
+ /**
34
+ * Asynchronously writes an object to an INI file.
35
+ *
36
+ * When an existing file is present and `preserveStyle` is `true` (the default), the original file's
37
+ * whitespace-around-`=` style and line endings are auto-detected and retained, and any line whose
38
+ * parsed value is unchanged is kept verbatim — preserving trailing whitespace and inline `;`/`#`
39
+ * comments. Explicit `whitespace` / `eol` options always win over detection.
40
+ * @param path The path to the INI file. Can be a file URL or a string path.
41
+ * @param data The data to serialize.
42
+ * @param options Optional configuration. See {@link WriteIniOptions}.
43
+ * @returns A promise that resolves when the file has been written.
44
+ * @example
45
+ * ```javascript
46
+ * import { writeIni } from "@visulima/fs/ini";
47
+ *
48
+ * await writeIni("./config.ini", { server: { port: 8080 } });
49
+ * ```
50
+ */
8
51
  declare const writeIni: (path: URL | string, data: Record<string, unknown>, options?: WriteIniOptions) => Promise<void>;
52
+ /**
53
+ * Synchronously writes an object to an INI file.
54
+ *
55
+ * When an existing file is present and `preserveStyle` is `true` (the default), the original file's
56
+ * whitespace-around-`=` style and line endings are auto-detected and retained, and any line whose
57
+ * parsed value is unchanged is kept verbatim — preserving trailing whitespace and inline `;`/`#`
58
+ * comments. Explicit `whitespace` / `eol` options always win over detection.
59
+ * @param path The path to the INI file. Can be a file URL or a string path.
60
+ * @param data The data to serialize.
61
+ * @param options Optional configuration. See {@link WriteIniOptions}.
62
+ * @example
63
+ * ```javascript
64
+ * import { writeIniSync } from "@visulima/fs/ini";
65
+ *
66
+ * writeIniSync("./config.ini", { server: { port: 8080 } });
67
+ * ```
68
+ */
9
69
  declare const writeIniSync: (path: URL | string, data: Record<string, unknown>, options?: WriteIniOptions) => void;
10
70
  export { type ReadIniOptions, type WriteIniOptions, readIni, readIniSync, writeIni, writeIniSync };
package/dist/is-glob.d.ts CHANGED
@@ -1,5 +1,34 @@
1
+ /**
2
+ * Options accepted by {@link isGlob}.
3
+ */
1
4
  interface IsGlobOptions {
5
+ /**
6
+ * When `false`, matches more permissively — any string containing unescaped glob
7
+ * meta characters (`*`, `?`, `{}`, `()`, `[]`) is treated as a glob, even when the
8
+ * sequence is not a valid glob expression.
9
+ * @default true
10
+ */
2
11
  strict?: boolean;
3
12
  }
13
+ /**
14
+ * Returns `true` if the given value looks like a glob pattern (including extglobs like `@(foo|bar)`).
15
+ *
16
+ * Escaped meta characters (e.g. `\\*`) are not considered globs. Non-string values always return `false`.
17
+ *
18
+ * Powered by [`is-glob`](https://github.com/micromatch/is-glob) which is bundled into the built output so it does
19
+ * not appear as a runtime dependency of `@visulima/fs`.
20
+ * @param value The value to inspect.
21
+ * @param options Optional configuration. See {@link IsGlobOptions}.
22
+ * @returns `true` if `value` looks like a glob pattern, otherwise `false`.
23
+ * @example
24
+ * ```javascript
25
+ * import { isGlob } from "@visulima/fs";
26
+ *
27
+ * isGlob("src/**\/*.ts"); // true
28
+ * isGlob("src/index.ts"); // false
29
+ * isGlob("src/\\*.ts"); // false — escaped
30
+ * isGlob("!foo.js"); // true — negation
31
+ * ```
32
+ */
4
33
  declare const isGlob: (value: unknown, options?: IsGlobOptions) => boolean;
5
34
  export { type IsGlobOptions, isGlob as default };
package/dist/json5.d.ts CHANGED
@@ -1,12 +1,36 @@
1
- import { a as CompressionType, j as ReadJson5Options, k as Json5Reviver, l as WriteJson5Options } from "./packem_shared/types.d-CYpAhWov.js";
2
- export { type m as Json5Replacer } from "./packem_shared/types.d-CYpAhWov.js";
1
+ import { a as CompressionType, f as ReadJson5Options, g as Json5Reviver, h as WriteJson5Options } from "./packem_shared/types.d-CixEXeyM.js";
2
+ export { type i as Json5Replacer } from "./packem_shared/types.d-CixEXeyM.js";
3
3
  import 'node:fs';
4
4
  import 'tinyglobby';
5
- import './options';
6
5
  declare function readJson5<R = unknown>(path: URL | string, options?: ReadJson5Options<CompressionType>): Promise<R>;
7
6
  declare function readJson5<R = unknown>(path: URL | string, reviver: Json5Reviver, options?: ReadJson5Options<CompressionType>): Promise<R>;
8
7
  declare function readJson5Sync(path: URL | string, options?: ReadJson5Options<CompressionType>): unknown;
9
8
  declare function readJson5Sync(path: URL | string, reviver: Json5Reviver, options?: ReadJson5Options<CompressionType>): unknown;
9
+ /**
10
+ * Asynchronously writes a value to a JSON5 file.
11
+ * @param path The path to the JSON5 file. Can be a file URL or a string path.
12
+ * @param data The data to serialize.
13
+ * @param options Optional configuration. See {@link WriteJson5Options}.
14
+ * @returns A promise that resolves when the file has been written.
15
+ * @example
16
+ * ```javascript
17
+ * import { writeJson5 } from "@visulima/fs/json5";
18
+ *
19
+ * await writeJson5("./config.json5", { name: "app" }, { indent: 2, quote: "'" });
20
+ * ```
21
+ */
10
22
  declare const writeJson5: (path: URL | string, data: unknown, options?: WriteJson5Options) => Promise<void>;
23
+ /**
24
+ * Synchronously writes a value to a JSON5 file.
25
+ * @param path The path to the JSON5 file. Can be a file URL or a string path.
26
+ * @param data The data to serialize.
27
+ * @param options Optional configuration. See {@link WriteJson5Options}.
28
+ * @example
29
+ * ```javascript
30
+ * import { writeJson5Sync } from "@visulima/fs/json5";
31
+ *
32
+ * writeJson5Sync("./config.json5", { name: "app" }, { indent: 2 });
33
+ * ```
34
+ */
11
35
  declare const writeJson5Sync: (path: URL | string, data: unknown, options?: WriteJson5Options) => void;
12
36
  export { type Json5Reviver, type ReadJson5Options, type WriteJson5Options, readJson5, readJson5Sync, writeJson5, writeJson5Sync };
package/dist/jsonc.d.ts CHANGED
@@ -1,10 +1,65 @@
1
- import { a as CompressionType, d as ReadJsoncOptions, e as WriteJsoncOptions } from "./packem_shared/types.d-CYpAhWov.js";
2
- export { type f as JsoncFormattingOptions, type g as JsoncParseOptions } from "./packem_shared/types.d-CYpAhWov.js";
1
+ import { a as CompressionType, b as ReadJsoncOptions, c as WriteJsoncOptions } from "./packem_shared/types.d-CixEXeyM.js";
2
+ export { type d as JsoncFormattingOptions, type e as JsoncParseOptions } from "./packem_shared/types.d-CixEXeyM.js";
3
3
  import 'node:fs';
4
4
  import 'tinyglobby';
5
- import './options';
5
+ /**
6
+ * Asynchronously reads a JSONC (JSON with comments) file and parses it into a JavaScript value.
7
+ * Supports `//` and `/* *\/` comments and, optionally, trailing commas via `jsonc-parser`.
8
+ * @param path The path to the JSONC file. Can be a file URL or a string path.
9
+ * @param options Optional configuration. See {@link ReadJsoncOptions}.
10
+ * @returns A promise that resolves with the parsed value.
11
+ * @example
12
+ * ```javascript
13
+ * import { readJsonc } from "@visulima/fs/jsonc";
14
+ *
15
+ * const config = await readJsonc("./tsconfig.json", { allowTrailingComma: true });
16
+ * ```
17
+ */
6
18
  declare const readJsonc: (path: URL | string, options?: ReadJsoncOptions<CompressionType>) => Promise<unknown>;
19
+ /**
20
+ * Synchronously reads a JSONC (JSON with comments) file and parses it into a JavaScript value.
21
+ * Supports `//` and `/* *\/` comments and, optionally, trailing commas via `jsonc-parser`.
22
+ * @param path The path to the JSONC file. Can be a file URL or a string path.
23
+ * @param options Optional configuration. See {@link ReadJsoncOptions}.
24
+ * @returns The parsed value.
25
+ * @example
26
+ * ```javascript
27
+ * import { readJsoncSync } from "@visulima/fs/jsonc";
28
+ *
29
+ * const config = readJsoncSync("./tsconfig.json", { allowTrailingComma: true });
30
+ * ```
31
+ */
7
32
  declare const readJsoncSync: (path: URL | string, options?: ReadJsoncOptions<CompressionType>) => unknown;
33
+ /**
34
+ * Asynchronously writes a value to a JSONC file. When `preserveComments` is `true` (the default)
35
+ * and the target file already exists, existing comments and formatting are preserved by computing
36
+ * a minimal diff against the new value via `jsonc-parser`'s `modify` API.
37
+ * @param path The path to the JSONC file. Can be a file URL or a string path.
38
+ * @param data The data to serialize.
39
+ * @param options Optional configuration. See {@link WriteJsoncOptions}.
40
+ * @returns A promise that resolves when the file has been written.
41
+ * @example
42
+ * ```javascript
43
+ * import { writeJsonc } from "@visulima/fs/jsonc";
44
+ *
45
+ * // Preserves comments inside an existing tsconfig.json
46
+ * await writeJsonc("./tsconfig.json", { ...tsconfig, compilerOptions: { target: "es2024" } });
47
+ * ```
48
+ */
8
49
  declare const writeJsonc: (path: URL | string, data: unknown, options?: WriteJsoncOptions) => Promise<void>;
50
+ /**
51
+ * Synchronously writes a value to a JSONC file. When `preserveComments` is `true` (the default)
52
+ * and the target file already exists, existing comments and formatting are preserved by computing
53
+ * a minimal diff against the new value via `jsonc-parser`'s `modify` API.
54
+ * @param path The path to the JSONC file. Can be a file URL or a string path.
55
+ * @param data The data to serialize.
56
+ * @param options Optional configuration. See {@link WriteJsoncOptions}.
57
+ * @example
58
+ * ```javascript
59
+ * import { writeJsoncSync } from "@visulima/fs/jsonc";
60
+ *
61
+ * writeJsoncSync("./tsconfig.json", updated);
62
+ * ```
63
+ */
9
64
  declare const writeJsoncSync: (path: URL | string, data: unknown, options?: WriteJsoncOptions) => void;
10
65
  export { type ReadJsoncOptions, type WriteJsoncOptions, readJsonc, readJsoncSync, writeJsonc, writeJsoncSync };
package/dist/match.d.ts CHANGED
@@ -1,5 +1,46 @@
1
- import { PicomatchOptions } from 'picomatch';
2
- type MatchOptions = PicomatchOptions;
1
+ import picomatch from './lib/picomatch';
2
+ /**
3
+ * Options accepted by {@link match} and {@link matcher}.
4
+ *
5
+ * Passed straight through to [`picomatch`](https://github.com/micromatch/picomatch#options); see its documentation for the full list.
6
+ */
7
+ type MatchOptions = picomatch.PicomatchOptions;
8
+ /**
9
+ * Tests whether a path matches one or more glob patterns.
10
+ *
11
+ * Powered by [`picomatch`](https://github.com/micromatch/picomatch) which is bundled into the built output so it does
12
+ * not appear as a runtime dependency of `@visulima/fs`.
13
+ *
14
+ * If you match many values against the same pattern, prefer {@link matcher} to compile the pattern once.
15
+ * @param value The path (or paths) to test.
16
+ * @param pattern A single glob or array of globs.
17
+ * @param options Optional picomatch options. See {@link MatchOptions}.
18
+ * @returns `true` if `value` matches any of `pattern`.
19
+ * @example
20
+ * ```javascript
21
+ * import { match } from "@visulima/fs";
22
+ *
23
+ * match("src/index.ts", "src/**\/*.ts"); // true
24
+ * match("src/index.ts", ["**\/*.js", "**\/*.ts"]); // true
25
+ * match("src/index.ts", "**\/*.js"); // false
26
+ * ```
27
+ */
3
28
  declare const match: (value: string | string[], pattern: string | string[], options?: MatchOptions) => boolean;
29
+ /**
30
+ * Compiles a glob pattern into a reusable matcher function.
31
+ *
32
+ * Powered by [`picomatch`](https://github.com/micromatch/picomatch) which is bundled into the built output so it does
33
+ * not appear as a runtime dependency of `@visulima/fs`.
34
+ * @param pattern A single glob or array of globs.
35
+ * @param options Optional picomatch options. See {@link MatchOptions}.
36
+ * @returns A function that returns `true` when its argument matches the compiled pattern.
37
+ * @example
38
+ * ```javascript
39
+ * import { matcher } from "@visulima/fs";
40
+ *
41
+ * const isTs = matcher("**\/*.ts");
42
+ * ["a.ts", "b.js", "c.ts"].filter(isTs); // ["a.ts", "c.ts"]
43
+ * ```
44
+ */
4
45
  declare const matcher: (pattern: string | string[], options?: MatchOptions) => (value: string) => boolean;
5
46
  export { MatchOptions, match, matcher };
@@ -0,0 +1,54 @@
1
+ import { G as GlobOptions } from "./types.d-CixEXeyM.js";
2
+ /**
3
+ * Asynchronously matches files on disk using one or more glob patterns.
4
+ *
5
+ * Powered by [`tinyglobby`](https://github.com/SuperchupuDev/tinyglobby); `tinyglobby` is bundled into the
6
+ * built output so it does not appear as a runtime dependency of `@visulima/fs`.
7
+ *
8
+ * Pattern forms:
9
+ *
10
+ * - Plain glob — `src/**\/*.ts`
11
+ * - Negated pattern — `!src/**\/*.spec.ts` inside `patterns` adds to the internal ignore list (same as passing it via `ignore`).
12
+ * - Negated ignore — a leading `!` inside {@link GlobOptions.ignore} _un-ignores_ entries that an earlier ignore pattern would drop, e.g. `ignore: ["dist/**", "!dist/index.d.ts"]`.
13
+ * @param patterns A single glob pattern or an array of glob patterns.
14
+ * @param options Optional glob options. See {@link GlobOptions}.
15
+ * @returns A promise resolving to the array of matched paths. Paths are relative to {@link GlobOptions.cwd} unless {@link GlobOptions.absolute} is `true`.
16
+ * @example
17
+ * ```javascript
18
+ * import { glob } from "@visulima/fs";
19
+ *
20
+ * const jsFiles = await glob("src/**\/*.{js,ts}", { cwd: process.cwd(), ignore: ["**\/node_modules/**"] });
21
+ * console.log(jsFiles);
22
+ *
23
+ * // Negated ignore: drop everything under `ignored/` except `ignored/keep.ts`.
24
+ * const keep = await glob("**\/*.ts", { ignore: ["ignored/**", "!ignored/keep.ts"] });
25
+ * ```
26
+ */
27
+ declare const glob: (patterns: string | ReadonlyArray<string>, options?: GlobOptions) => Promise<string[]>;
28
+ /**
29
+ * Synchronously matches files on disk using one or more glob patterns.
30
+ *
31
+ * Synchronous counterpart of `glob`. Powered by [`tinyglobby`](https://github.com/SuperchupuDev/tinyglobby);
32
+ * bundled into the built output so it does not appear as a runtime dependency of `@visulima/fs`.
33
+ *
34
+ * Pattern forms:
35
+ *
36
+ * - Plain glob — `src/**\/*.ts`
37
+ * - Negated pattern — `!src/**\/*.spec.ts` inside `patterns` adds to the internal ignore list.
38
+ * - Negated ignore — a leading `!` inside {@link GlobOptions.ignore} _un-ignores_ entries that an earlier ignore pattern would drop, e.g. `ignore: ["dist/**", "!dist/index.d.ts"]`.
39
+ * @param patterns A single glob pattern or an array of glob patterns.
40
+ * @param options Optional glob options. See {@link GlobOptions}.
41
+ * @returns The array of matched paths. Paths are relative to {@link GlobOptions.cwd} unless {@link GlobOptions.absolute} is `true`.
42
+ * @example
43
+ * ```javascript
44
+ * import { globSync } from "@visulima/fs";
45
+ *
46
+ * const jsFiles = globSync(["src/**\/*.ts", "!**\/*.spec.ts"]);
47
+ * console.log(jsFiles);
48
+ *
49
+ * // Negated ignore: drop everything under `ignored/` except `ignored/keep.ts`.
50
+ * const keep = globSync("**\/*.ts", { ignore: ["ignored/**", "!ignored/keep.ts"] });
51
+ * ```
52
+ */
53
+ declare const globSync: (patterns: string | ReadonlyArray<string>, options?: GlobOptions) => string[];
54
+ export { globSync as a, glob as g };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Custom error class for handling JSON parsing or related errors.
3
+ * It can optionally include a file name and a code frame for better debugging.
4
+ * @example
5
+ * ```javascript
6
+ * import { JSONError } from "@visulima/fs/error";
7
+ * import { readJsonSync } from "@visulima/fs"; // Or any function that might throw this
8
+ * import { join } from "node:path";
9
+ *
10
+ * try {
11
+ * // Imagine readJsonSync encounters a malformed JSON file and throws JSONError
12
+ * // Forcing the scenario for demonstration:
13
+ * const simulateJsonError = (filePath, content) => {
14
+ * const err = new JSONError(`Unexpected token '}' at position 15`);
15
+ * err.fileName = filePath;
16
+ * // A real implementation might generate a code frame using a library
17
+ * err.codeFrame = ` 13 | "key": "value",
18
+ * > 14 | "anotherKey": "anotherValue",}
19
+ * | ^
20
+ * 15 | "lastKey": "end"
21
+ * `;
22
+ * throw err;
23
+ * };
24
+ *
25
+ * simulateJsonError(join("path", "to", "corrupted.json"), '{ "key": "value", "anotherKey": "anotherValue",} ');
26
+ * // const jsonData = readJsonSync(join("path", "to", "corrupted.json"));
27
+ * } catch (error) {
28
+ * if (error instanceof JSONError) {
29
+ * console.error(`JSON Error: ${error.message}`);
30
+ * // message property will include fileName and codeFrame if they were set.
31
+ * // console.error(`File: ${error.fileName}`);
32
+ * // console.error(`Code Frame:\n${error.codeFrame}`);
33
+ * } else {
34
+ * console.error("An unexpected error occurred:", error);
35
+ * }
36
+ * }
37
+ * ```
38
+ */
39
+ declare class JSONError extends Error {
40
+ #private;
41
+ fileName: string | undefined;
42
+ codeFrame: string | undefined;
43
+ override readonly name = "JSONError";
44
+ /**
45
+ * Creates a new JSONError instance.
46
+ * @param message The primary error message.
47
+ */
48
+ constructor(message: string);
49
+ override get message(): string;
50
+ override set message(message: string);
51
+ }
52
+ export { JSONError as J };