@reliverse/relifso 1.4.4 → 2.2.7

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.
Files changed (92) hide show
  1. package/README.md +371 -367
  2. package/dist/copy.d.ts +3 -0
  3. package/dist/copy.js +95 -0
  4. package/dist/dir.d.ts +13 -0
  5. package/dist/dir.js +113 -0
  6. package/dist/file.d.ts +12 -0
  7. package/dist/file.js +169 -0
  8. package/dist/helpers.d.ts +3 -0
  9. package/dist/helpers.js +38 -0
  10. package/dist/internal/fs.d.ts +16 -0
  11. package/dist/internal/fs.js +32 -0
  12. package/dist/internal/path.d.ts +3 -0
  13. package/dist/internal/path.js +11 -0
  14. package/dist/links.d.ts +3 -0
  15. package/dist/links.js +74 -0
  16. package/dist/mod.d.ts +40 -0
  17. package/dist/mod.js +77 -0
  18. package/dist/types.d.ts +50 -0
  19. package/dist/types.js +0 -0
  20. package/package.json +15 -42
  21. package/LICENSE +0 -21
  22. package/LICENSES +0 -16
  23. package/bin/impl/bun.d.ts +0 -11
  24. package/bin/impl/bun.js +0 -23
  25. package/bin/impl/copy.d.ts +0 -40
  26. package/bin/impl/copy.js +0 -229
  27. package/bin/impl/create.d.ts +0 -34
  28. package/bin/impl/create.js +0 -54
  29. package/bin/impl/dive.d.ts +0 -27
  30. package/bin/impl/dive.js +0 -145
  31. package/bin/impl/empty.d.ts +0 -28
  32. package/bin/impl/empty.js +0 -75
  33. package/bin/impl/extras.d.ts +0 -35
  34. package/bin/impl/extras.js +0 -112
  35. package/bin/impl/json-utils.d.ts +0 -30
  36. package/bin/impl/json-utils.js +0 -46
  37. package/bin/impl/mkdirs.d.ts +0 -7
  38. package/bin/impl/mkdirs.js +0 -28
  39. package/bin/impl/move.d.ts +0 -28
  40. package/bin/impl/move.js +0 -140
  41. package/bin/impl/output-file.d.ts +0 -17
  42. package/bin/impl/output-file.js +0 -15
  43. package/bin/impl/output-json.d.ts +0 -21
  44. package/bin/impl/output-json.js +0 -77
  45. package/bin/impl/path-exists.d.ts +0 -2
  46. package/bin/impl/path-exists.js +0 -16
  47. package/bin/impl/read-file.d.ts +0 -31
  48. package/bin/impl/read-file.js +0 -165
  49. package/bin/impl/read-json.d.ts +0 -31
  50. package/bin/impl/read-json.js +0 -241
  51. package/bin/impl/remove.d.ts +0 -2
  52. package/bin/impl/remove.js +0 -8
  53. package/bin/impl/stats.d.ts +0 -31
  54. package/bin/impl/stats.js +0 -141
  55. package/bin/impl/write-file.d.ts +0 -31
  56. package/bin/impl/write-file.js +0 -177
  57. package/bin/impl/write-json.d.ts +0 -41
  58. package/bin/impl/write-json.js +0 -135
  59. package/bin/mod.d.ts +0 -253
  60. package/bin/mod.js +0 -514
  61. package/bin/utils/json/helpers/JSONRepairError.d.ts +0 -4
  62. package/bin/utils/json/helpers/JSONRepairError.js +0 -7
  63. package/bin/utils/json/helpers/JsonSchemaError.d.ts +0 -6
  64. package/bin/utils/json/helpers/JsonSchemaError.js +0 -6
  65. package/bin/utils/json/helpers/stringUtils.d.ts +0 -64
  66. package/bin/utils/json/helpers/stringUtils.js +0 -87
  67. package/bin/utils/json/regular/jsonc.d.ts +0 -45
  68. package/bin/utils/json/regular/jsonc.js +0 -88
  69. package/bin/utils/json/regular/jsonrepair.d.ts +0 -17
  70. package/bin/utils/json/regular/jsonrepair.js +0 -576
  71. package/bin/utils/json/regular/validate.d.ts +0 -22
  72. package/bin/utils/json/regular/validate.js +0 -52
  73. package/bin/utils/json/stream/JsonStreamError.d.ts +0 -6
  74. package/bin/utils/json/stream/JsonStreamError.js +0 -6
  75. package/bin/utils/json/stream/buffer/InputBuffer.d.ts +0 -13
  76. package/bin/utils/json/stream/buffer/InputBuffer.js +0 -68
  77. package/bin/utils/json/stream/buffer/OutputBuffer.d.ts +0 -17
  78. package/bin/utils/json/stream/buffer/OutputBuffer.js +0 -101
  79. package/bin/utils/json/stream/core.d.ts +0 -10
  80. package/bin/utils/json/stream/core.js +0 -695
  81. package/bin/utils/json/stream/jsonl.d.ts +0 -21
  82. package/bin/utils/json/stream/jsonl.js +0 -55
  83. package/bin/utils/json/stream/parser.d.ts +0 -14
  84. package/bin/utils/json/stream/parser.js +0 -81
  85. package/bin/utils/json/stream/stack.d.ts +0 -19
  86. package/bin/utils/json/stream/stack.js +0 -43
  87. package/bin/utils/json/stream/stream.d.ts +0 -6
  88. package/bin/utils/json/stream/stream.js +0 -30
  89. package/bin/utils/json/stream/writer.d.ts +0 -14
  90. package/bin/utils/json/stream/writer.js +0 -44
  91. package/bin/utils/log.d.ts +0 -1
  92. package/bin/utils/log.js +0 -7
@@ -1,17 +0,0 @@
1
- import type { WriteFileOptions } from "./write-file.js";
2
- /**
3
- * Ensures that the directory for the file exists and then writes the data to the file.
4
- *
5
- * @param file - The path to the file.
6
- * @param data - The data to write.
7
- * @param options - Options for writing the file (e.g., encoding, mode, flag).
8
- */
9
- export declare function outputFileSync(file: string, data: string | Uint8Array, options?: WriteFileOptions): void;
10
- /**
11
- * Ensures that the directory for the file exists and then asynchronously writes the data to the file.
12
- *
13
- * @param file - The path to the file.
14
- * @param data - The data to write.
15
- * @param options - Options for writing the file (e.g., encoding, mode, flag).
16
- */
17
- export declare function outputFile(file: string, data: string | Uint8Array, options?: WriteFileOptions): Promise<void>;
@@ -1,15 +0,0 @@
1
- import { dirname } from "node:path";
2
- import { mkdirsSync } from "./mkdirs.js";
3
- import { mkdirs } from "./mkdirs.js";
4
- import { writeFileSync } from "./write-file.js";
5
- import { writeFile } from "./write-file.js";
6
- export function outputFileSync(file, data, options) {
7
- const dir = dirname(file);
8
- mkdirsSync(dir);
9
- writeFileSync(file, data, options);
10
- }
11
- export async function outputFile(file, data, options) {
12
- const dir = dirname(file);
13
- await mkdirs(dir);
14
- await writeFile(file, data, options);
15
- }
@@ -1,21 +0,0 @@
1
- import type { WriteJsonOptions } from "./write-json.js";
2
- import { type JsonUtilsOptions } from "./json-utils.js";
3
- export interface OutputJsonOptions extends WriteJsonOptions {
4
- useStreaming?: boolean;
5
- }
6
- /**
7
- * Ensures that the directory for the JSON file exists and then writes the JSON data to the file.
8
- *
9
- * @param file - The path to the file.
10
- * @param data - The JSON data to write.
11
- * @param options - Options for writing the JSON file (e.g., replacer, spaces).
12
- */
13
- export declare function outputJsonSync(file: string, data: unknown, options?: BufferEncoding | OutputJsonOptions): void;
14
- /**
15
- * Ensures that the directory for the JSON file exists and then asynchronously writes the JSON data to the file.
16
- *
17
- * @param file - The path to the file.
18
- * @param data - The JSON data to write.
19
- * @param options - Options for writing the JSON file (e.g., replacer, spaces).
20
- */
21
- export declare function outputJson(file: string, data: unknown, options?: BufferEncoding | OutputJsonOptions | JsonUtilsOptions): Promise<void>;
@@ -1,77 +0,0 @@
1
- import { createWriteStream } from "node:fs";
2
- import { Transform } from "node:stream";
3
- import { pipeline } from "node:stream/promises";
4
- import { logInternal } from "../utils/log.js";
5
- import { ensureJsonFileSync, ensureJsonFile } from "./json-utils.js";
6
- export function outputJsonSync(file, data, options) {
7
- const jsonOptions = typeof options === "string" ? { encoding: options } : options ?? {};
8
- ensureJsonFileSync(file, data, jsonOptions);
9
- }
10
- export async function outputJson(file, data, options) {
11
- let useStreaming = false;
12
- let encoding = "utf8";
13
- let replacer;
14
- let spaces;
15
- let flag;
16
- let mode;
17
- let throws = true;
18
- if (typeof options === "string") {
19
- encoding = options;
20
- } else if (options) {
21
- if ("encoding" in options) {
22
- encoding = options.encoding ?? encoding;
23
- }
24
- if ("replacer" in options) {
25
- replacer = options.replacer;
26
- }
27
- if ("spaces" in options) {
28
- spaces = options.spaces;
29
- }
30
- if ("flag" in options) {
31
- flag = options.flag;
32
- }
33
- if ("mode" in options) {
34
- mode = options.mode ? Number(options.mode) : void 0;
35
- }
36
- if ("useStreaming" in options) {
37
- useStreaming = options.useStreaming ?? useStreaming;
38
- }
39
- if ("throws" in options && options.throws !== void 0) {
40
- throws = options.throws;
41
- }
42
- }
43
- try {
44
- if (useStreaming) {
45
- try {
46
- const writeStream = createWriteStream(file, { encoding, mode, flags: flag });
47
- const jsonString = JSON.stringify(data, replacer, spaces);
48
- if (jsonString === void 0) {
49
- throw new Error("Failed to stringify JSON object");
50
- }
51
- const transform = new Transform({
52
- transform(chunk, _encoding, callback) {
53
- callback(null, chunk);
54
- }
55
- });
56
- transform.write(jsonString);
57
- transform.end();
58
- await pipeline(transform, writeStream);
59
- return;
60
- } catch (streamError) {
61
- }
62
- }
63
- await ensureJsonFile(file, data, {
64
- encoding,
65
- replacer,
66
- spaces,
67
- flag,
68
- mode,
69
- throws,
70
- useStreaming
71
- });
72
- } catch (err) {
73
- if (throws) {
74
- throw err;
75
- }
76
- }
77
- }
@@ -1,2 +0,0 @@
1
- export declare function pathExistsSync(path: string): boolean;
2
- export declare function pathExists(path: string): Promise<boolean>;
@@ -1,16 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { stat } from "node:fs/promises";
3
- export function pathExistsSync(path) {
4
- return existsSync(path);
5
- }
6
- export async function pathExists(path) {
7
- try {
8
- await stat(path);
9
- return true;
10
- } catch (error) {
11
- if (error.code === "ENOENT") {
12
- return false;
13
- }
14
- throw error;
15
- }
16
- }
@@ -1,31 +0,0 @@
1
- export interface ReadFileOptions {
2
- encoding?: BufferEncoding | null;
3
- flag?: string;
4
- isJson?: boolean;
5
- useStreaming?: boolean;
6
- reviver?: (key: string, value: unknown) => unknown;
7
- }
8
- /**
9
- * Synchronously reads the entire contents of a file.
10
- *
11
- * @param path - The path to the file.
12
- * @param options - Options for reading the file. Can be an encoding string or an object.
13
- * @returns The contents of the file as a string.
14
- */
15
- export declare function readFileSync(path: string, options?: BufferEncoding | ReadFileOptions): string;
16
- export declare function readFileSync(path: string, encoding: BufferEncoding): string;
17
- export declare function readFileSync(path: string, options: {
18
- encoding: BufferEncoding;
19
- }): string;
20
- /**
21
- * Asynchronously reads the entire contents of a file.
22
- *
23
- * @param path - The path to the file.
24
- * @param options - Options for reading the file. Can be an encoding string or an object.
25
- * @returns A promise that resolves with the contents of the file as a string.
26
- */
27
- export declare function readFile(path: string, options?: BufferEncoding | ReadFileOptions): Promise<string>;
28
- export declare function readFile(path: string, encoding: BufferEncoding): Promise<string>;
29
- export declare function readFile(path: string, options: {
30
- encoding: BufferEncoding;
31
- }): Promise<string>;
@@ -1,165 +0,0 @@
1
- import { readFileSync as nodeReadFileSync } from "node:fs";
2
- import { createReadStream } from "node:fs";
3
- import { readFile as nodeReadFileAsync } from "node:fs/promises";
4
- import { Transform } from "node:stream";
5
- import { pipeline } from "node:stream/promises";
6
- import { jsonrepair } from "../utils/json/regular/jsonrepair.js";
7
- import { logInternal } from "../utils/log.js";
8
- import { isBun, getFileBun } from "./bun.js";
9
- export function readFileSync(path, options) {
10
- let encoding;
11
- let flag;
12
- if (typeof options === "string") {
13
- encoding = options;
14
- } else if (options) {
15
- encoding = options.encoding;
16
- flag = options.flag;
17
- }
18
- if (isBun) {
19
- try {
20
- const file = getFileBun(path);
21
- if (encoding) {
22
- try {
23
- const text = file.text();
24
- if (text instanceof Promise) {
25
- throw new Error("Bun's text() returned a Promise in sync context");
26
- }
27
- return text;
28
- } catch (_error) {
29
- const buffer = file.arrayBuffer();
30
- if (buffer instanceof Promise) {
31
- throw new Error("Bun's arrayBuffer() returned a Promise in sync context");
32
- }
33
- return Buffer.from(buffer).toString(encoding);
34
- }
35
- }
36
- try {
37
- const buffer = file.arrayBuffer();
38
- if (buffer instanceof Promise) {
39
- throw new Error("Bun's arrayBuffer() returned a Promise in sync context");
40
- }
41
- return Buffer.from(buffer).toString(encoding || "utf8");
42
- } catch (_error) {
43
- const text = file.text();
44
- if (text instanceof Promise) {
45
- throw new Error("Bun's text() returned a Promise in sync context");
46
- }
47
- return text;
48
- }
49
- } catch (error) {
50
- }
51
- }
52
- if (encoding) {
53
- return nodeReadFileSync(path, { encoding, flag });
54
- }
55
- return nodeReadFileSync(path, { encoding: "utf8", flag });
56
- }
57
- export async function readFile(path, options) {
58
- let encoding;
59
- let flag;
60
- let isJson = false;
61
- let useStreaming = false;
62
- let reviver;
63
- if (typeof options === "string") {
64
- encoding = options;
65
- } else if (options) {
66
- encoding = options.encoding;
67
- flag = options.flag;
68
- isJson = options.isJson ?? isJson;
69
- useStreaming = options.useStreaming ?? useStreaming;
70
- reviver = options.reviver;
71
- }
72
- if (isBun) {
73
- try {
74
- const file = getFileBun(path);
75
- if (encoding) {
76
- try {
77
- const result = await file.text();
78
- if (isJson) {
79
- try {
80
- return JSON.stringify(JSON.parse(result, reviver));
81
- } catch (_parseError) {
82
- const repaired = jsonrepair(result);
83
- return JSON.stringify(JSON.parse(repaired, reviver));
84
- }
85
- }
86
- return result;
87
- } catch (_error) {
88
- const buffer = await file.arrayBuffer();
89
- const text = Buffer.from(buffer).toString(encoding);
90
- if (isJson) {
91
- try {
92
- return JSON.stringify(JSON.parse(text, reviver));
93
- } catch (_parseError) {
94
- const repaired = jsonrepair(text);
95
- return JSON.stringify(JSON.parse(repaired, reviver));
96
- }
97
- }
98
- return text;
99
- }
100
- }
101
- try {
102
- const buffer = await file.arrayBuffer();
103
- const text = Buffer.from(buffer).toString(encoding || "utf8");
104
- if (isJson) {
105
- try {
106
- return JSON.stringify(JSON.parse(text, reviver));
107
- } catch (_parseError) {
108
- const repaired = jsonrepair(text);
109
- return JSON.stringify(JSON.parse(repaired, reviver));
110
- }
111
- }
112
- return text;
113
- } catch (_error) {
114
- const text = await file.text();
115
- if (isJson) {
116
- try {
117
- return JSON.stringify(JSON.parse(text, reviver));
118
- } catch (_parseError) {
119
- const repaired = jsonrepair(text);
120
- return JSON.stringify(JSON.parse(repaired, reviver));
121
- }
122
- }
123
- return text;
124
- }
125
- } catch (error) {
126
- }
127
- }
128
- if (useStreaming && encoding) {
129
- try {
130
- const chunks = [];
131
- const transform = new Transform({
132
- transform(chunk, _encoding, callback) {
133
- chunks.push(chunk.toString());
134
- callback();
135
- }
136
- });
137
- const readStream = createReadStream(path, { encoding, flags: flag });
138
- await pipeline(readStream, transform);
139
- const text = chunks.join("");
140
- if (isJson) {
141
- try {
142
- return JSON.stringify(JSON.parse(text, reviver));
143
- } catch (_parseError) {
144
- const repaired = jsonrepair(text);
145
- return JSON.stringify(JSON.parse(repaired, reviver));
146
- }
147
- }
148
- return text;
149
- } catch (streamError) {
150
- }
151
- }
152
- if (encoding) {
153
- const text = await nodeReadFileAsync(path, { encoding, flag });
154
- if (isJson) {
155
- try {
156
- return JSON.stringify(JSON.parse(text, reviver));
157
- } catch (_parseError) {
158
- const repaired = jsonrepair(text);
159
- return JSON.stringify(JSON.parse(repaired, reviver));
160
- }
161
- }
162
- return text;
163
- }
164
- return await nodeReadFileAsync(path, { encoding: "utf8", flag });
165
- }
@@ -1,31 +0,0 @@
1
- export interface ReadJsonOptions {
2
- encoding?: BufferEncoding | null;
3
- flag?: string;
4
- reviver?: (key: string, value: unknown) => unknown;
5
- throws?: boolean;
6
- defaultValue?: unknown;
7
- ensure?: boolean;
8
- useStreaming?: boolean;
9
- /**
10
- * Whether to preserve comments when reading JSONC files
11
- * @default false
12
- */
13
- preserveComments?: boolean;
14
- }
15
- /**
16
- * Reads a JSON file and then parses it into an object.
17
- * If the file doesn't exist and ensure is true, creates the file with defaultValue.
18
- *
19
- * @param file - The path to the file.
20
- * @param options - Options for reading the file or parsing JSON. Can be an encoding string or an object.
21
- * @returns The parsed JSON object.
22
- */
23
- export declare function readJsonSync<T = unknown>(file: string, options?: BufferEncoding | ReadJsonOptions): T;
24
- /**
25
- * Asynchronously reads a JSON file and then parses it into an object.
26
- *
27
- * @param file - The path to the file.
28
- * @param options - Options for reading the file or parsing JSON. Can be an encoding string or an object.
29
- * @returns A promise that resolves with the parsed JSON object.
30
- */
31
- export declare function readJson<T = unknown>(file: string, options?: BufferEncoding | ReadJsonOptions): Promise<T>;
@@ -1,241 +0,0 @@
1
- import { readFileSync, createReadStream } from "node:fs";
2
- import { readFile } from "node:fs/promises";
3
- import { extname } from "node:path";
4
- import { Transform } from "node:stream";
5
- import { pipeline } from "node:stream/promises";
6
- import { parseJsonc, isValidJsonc } from "../utils/json/regular/jsonc.js";
7
- import { jsonrepair } from "../utils/json/regular/jsonrepair.js";
8
- import { logInternal } from "../utils/log.js";
9
- import { isBun, getFileBun } from "./bun.js";
10
- import { ensureJsonFileSync } from "./json-utils.js";
11
- import { pathExistsSync } from "./path-exists.js";
12
- export function readJsonSync(file, options) {
13
- let encoding = "utf8";
14
- let reviver;
15
- let throws = true;
16
- let defaultValue = { sync: true };
17
- let ensure = true;
18
- let preserveComments = false;
19
- if (typeof options === "string") {
20
- encoding = options;
21
- } else if (options) {
22
- encoding = options.encoding ?? encoding;
23
- reviver = options.reviver;
24
- if (options.throws !== void 0) {
25
- throws = options.throws;
26
- }
27
- if (options.defaultValue !== void 0) {
28
- defaultValue = options.defaultValue;
29
- }
30
- if (options.ensure !== void 0) {
31
- ensure = options.ensure;
32
- }
33
- if (options.preserveComments !== void 0) {
34
- preserveComments = options.preserveComments;
35
- }
36
- }
37
- try {
38
- if (!pathExistsSync(file) && ensure) {
39
- ensureJsonFileSync(file, defaultValue);
40
- return defaultValue;
41
- }
42
- if (isBun) {
43
- try {
44
- const fileRef = getFileBun(file);
45
- try {
46
- const parsed = fileRef.json();
47
- if (parsed instanceof Promise) {
48
- throw new Error("Bun's json() returned a Promise in sync context");
49
- }
50
- if (parsed === null || typeof parsed !== "object") {
51
- if (throws) {
52
- throw new Error("Invalid JSON data: expected an object");
53
- }
54
- return defaultValue;
55
- }
56
- return parsed;
57
- } catch (parseError) {
58
- if (throws) {
59
- throw parseError;
60
- }
61
- return defaultValue;
62
- }
63
- } catch (error) {
64
- }
65
- }
66
- const data = readFileSync(file, { encoding });
67
- if (!data || !data.trim()) {
68
- return defaultValue;
69
- }
70
- const isJsonc = extname(file).toLowerCase() === ".jsonc" || isValidJsonc(data);
71
- try {
72
- if (isJsonc) {
73
- const parsed = parseJsonc(data, { preserveComments, throws });
74
- if (parsed === null || typeof parsed !== "object") {
75
- if (throws) {
76
- throw new Error("Invalid JSONC data: expected an object");
77
- }
78
- return defaultValue;
79
- }
80
- return parsed;
81
- } else {
82
- const parsed = JSON.parse(data, reviver);
83
- if (parsed === null || typeof parsed !== "object") {
84
- if (throws) {
85
- throw new Error("Invalid JSON data: expected an object");
86
- }
87
- return defaultValue;
88
- }
89
- return parsed;
90
- }
91
- } catch (parseError) {
92
- try {
93
- const repaired = jsonrepair(data);
94
- const parsed = JSON.parse(repaired, reviver);
95
- if (parsed === null || typeof parsed !== "object") {
96
- if (throws) {
97
- throw parseError;
98
- }
99
- return defaultValue;
100
- }
101
- return parsed;
102
- } catch (_repairError) {
103
- if (throws) {
104
- throw parseError;
105
- }
106
- return defaultValue;
107
- }
108
- }
109
- } catch (err) {
110
- if (throws) {
111
- throw err;
112
- }
113
- return defaultValue;
114
- }
115
- }
116
- export async function readJson(file, options) {
117
- let encoding = "utf8";
118
- let reviver;
119
- let throws = true;
120
- let flag;
121
- let defaultValue = {};
122
- let useStreaming = false;
123
- if (typeof options === "string") {
124
- encoding = options;
125
- } else if (options) {
126
- encoding = options.encoding ?? encoding;
127
- reviver = options.reviver;
128
- flag = options.flag;
129
- useStreaming = options.useStreaming ?? useStreaming;
130
- if (options.throws !== void 0) {
131
- throws = options.throws;
132
- }
133
- if (options.defaultValue !== void 0) {
134
- defaultValue = options.defaultValue;
135
- }
136
- }
137
- try {
138
- if (isBun) {
139
- try {
140
- const fileRef = getFileBun(file);
141
- try {
142
- const parsed = await fileRef.json();
143
- if (parsed === null || typeof parsed !== "object") {
144
- if (throws) {
145
- throw new Error("Invalid JSON data: expected an object");
146
- }
147
- return defaultValue;
148
- }
149
- return parsed;
150
- } catch (parseError) {
151
- if (throws) {
152
- throw parseError;
153
- }
154
- return defaultValue;
155
- }
156
- } catch (error) {
157
- }
158
- }
159
- if (useStreaming) {
160
- try {
161
- const chunks = [];
162
- const transform = new Transform({
163
- transform(chunk, _encoding, callback) {
164
- chunks.push(chunk.toString());
165
- callback();
166
- }
167
- });
168
- const readStream = createReadStream(file, { encoding, flags: flag });
169
- await pipeline(readStream, transform);
170
- const data2 = chunks.join("");
171
- if (!data2 || !data2.trim()) {
172
- return defaultValue;
173
- }
174
- try {
175
- const parsed = JSON.parse(data2, reviver);
176
- if (parsed === null || typeof parsed !== "object") {
177
- if (throws) {
178
- throw new Error("Invalid JSON data: expected an object");
179
- }
180
- return defaultValue;
181
- }
182
- return parsed;
183
- } catch (parseError) {
184
- try {
185
- const repaired = jsonrepair(data2);
186
- const parsed = JSON.parse(repaired, reviver);
187
- if (parsed === null || typeof parsed !== "object") {
188
- if (throws) {
189
- throw parseError;
190
- }
191
- return defaultValue;
192
- }
193
- return parsed;
194
- } catch (_repairError) {
195
- if (throws) {
196
- throw parseError;
197
- }
198
- return defaultValue;
199
- }
200
- }
201
- } catch (streamError) {
202
- }
203
- }
204
- const data = await readFile(file, { encoding, flag });
205
- if (!data || !data.trim()) {
206
- return defaultValue;
207
- }
208
- try {
209
- const parsed = JSON.parse(data, reviver);
210
- if (parsed === null || typeof parsed !== "object") {
211
- if (throws) {
212
- throw new Error("Invalid JSON data: expected an object");
213
- }
214
- return defaultValue;
215
- }
216
- return parsed;
217
- } catch (parseError) {
218
- try {
219
- const repaired = jsonrepair(data);
220
- const parsed = JSON.parse(repaired, reviver);
221
- if (parsed === null || typeof parsed !== "object") {
222
- if (throws) {
223
- throw parseError;
224
- }
225
- return defaultValue;
226
- }
227
- return parsed;
228
- } catch (_repairError) {
229
- if (throws) {
230
- throw parseError;
231
- }
232
- return defaultValue;
233
- }
234
- }
235
- } catch (err) {
236
- if (throws) {
237
- throw err;
238
- }
239
- return defaultValue;
240
- }
241
- }
@@ -1,2 +0,0 @@
1
- export declare function removeSync(path: string): void;
2
- export declare function remove(path: string): Promise<void>;
@@ -1,8 +0,0 @@
1
- import { rmSync } from "node:fs";
2
- import { rm } from "node:fs/promises";
3
- export function removeSync(path) {
4
- return rmSync(path, { recursive: true, force: true });
5
- }
6
- export async function remove(path) {
7
- return rm(path, { recursive: true, force: true });
8
- }
@@ -1,31 +0,0 @@
1
- import type { Stats } from "node:fs";
2
- /**
3
- * Convert Bun file stats to Node.js Stats object
4
- * Uses Bun's optimized API when available, falls back to Node.js
5
- */
6
- export declare function toNodeStats(path: string): Promise<Stats>;
7
- /**
8
- * Get file stats with fallback to Node.js
9
- * Uses Bun's optimized API when available
10
- */
11
- export declare function getStats(path: string): Promise<Stats>;
12
- /**
13
- * Get file stats synchronously with fallback to Node.js
14
- * Uses Bun's optimized API when available
15
- */
16
- export declare function getStatsSync(path: string): Stats;
17
- /**
18
- * Check if a file exists
19
- * Uses Bun's optimized API when available, falls back to Node.js
20
- */
21
- export declare function getFileExists(path: string): Promise<boolean>;
22
- /**
23
- * Get file size
24
- * Uses Bun's optimized API when available, falls back to Node.js
25
- */
26
- export declare function getFileSize(path: string): Promise<number>;
27
- /**
28
- * Get file last modified time
29
- * Uses Bun's optimized API when available, falls back to Node.js
30
- */
31
- export declare function getFileLastModified(path: string): Promise<Date>;