@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/CHANGELOG.md +25 -0
- package/LICENSE.md +22 -4
- package/dist/eol.d.ts +30 -0
- package/dist/error.d.ts +243 -13
- package/dist/glob-parent.d.ts +30 -0
- package/dist/glob.d.ts +2 -3
- package/dist/index.d.ts +784 -7
- package/dist/ini.d.ts +63 -3
- package/dist/is-glob.d.ts +29 -0
- package/dist/json5.d.ts +27 -3
- package/dist/jsonc.d.ts +58 -3
- package/dist/match.d.ts +43 -2
- package/dist/packem_shared/glob-sync.d-Dsxhj3BW.d.ts +54 -0
- package/dist/packem_shared/json-error.d-DVILOyHc.d.ts +52 -0
- package/dist/packem_shared/types.d-CixEXeyM.d.ts +1660 -0
- package/dist/size.d.ts +244 -0
- package/dist/toml.d.ts +56 -2
- package/dist/utils.d.ts +91 -3
- package/dist/yaml.d.ts +2 -3
- package/package.json +18 -19
- package/dist/packem_shared/glob-sync.d-BlGjS68e.d.ts +0 -4
- package/dist/packem_shared/json-error.d-DgKaeuIf.d.ts +0 -10
- package/dist/packem_shared/types.d-CYpAhWov.d.ts +0 -145
package/dist/size.d.ts
CHANGED
|
@@ -1,12 +1,256 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
2
|
import { URL } from 'node:url';
|
|
3
3
|
import { BrotliOptions, ZlibOptions } from 'node:zlib';
|
|
4
|
+
/**
|
|
5
|
+
* Input type for size calculation functions.
|
|
6
|
+
* Can be a Buffer, Readable stream, URL object, or string (file path or content).
|
|
7
|
+
*/
|
|
4
8
|
type SizeInput = Buffer | Readable | URL | string;
|
|
9
|
+
/**
|
|
10
|
+
* Input type for synchronous size calculation functions.
|
|
11
|
+
* Can be a Buffer, URL object, or string (file path or content).
|
|
12
|
+
*/
|
|
5
13
|
type SizeInputSync = Buffer | URL | string;
|
|
14
|
+
/**
|
|
15
|
+
* Asynchronously calculates the gzipped size of the given input.
|
|
16
|
+
* The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
17
|
+
* Uses memory-efficient streaming for files and streams to avoid loading entire contents into memory.
|
|
18
|
+
* @param input The input data to gzip and measure.
|
|
19
|
+
* @param [options] Optional Zlib options for gzip compression.
|
|
20
|
+
* @returns A promise that resolves with the gzipped size in bytes.
|
|
21
|
+
* @example
|
|
22
|
+
* ```javascript
|
|
23
|
+
* import { gzipSize } from "@visulima/fs";
|
|
24
|
+
* import { Readable } from "node:stream";
|
|
25
|
+
* import { writeFile, unlink } from "node:fs/promises";
|
|
26
|
+
* import { join } from "node:path";
|
|
27
|
+
*
|
|
28
|
+
* const text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
|
|
29
|
+
* const filePath = join("temp-file.txt");
|
|
30
|
+
*
|
|
31
|
+
* async function main() {
|
|
32
|
+
* // From Buffer
|
|
33
|
+
* const buffer = Buffer.from(text);
|
|
34
|
+
* console.log(`Gzip size of buffer: ${await gzipSize(buffer)} bytes`);
|
|
35
|
+
*
|
|
36
|
+
* // From string (content)
|
|
37
|
+
* console.log(`Gzip size of string content: ${await gzipSize(text)} bytes`);
|
|
38
|
+
*
|
|
39
|
+
* // From file path
|
|
40
|
+
* await writeFile(filePath, text);
|
|
41
|
+
* console.log(`Gzip size of file: ${await gzipSize(filePath)} bytes`);
|
|
42
|
+
*
|
|
43
|
+
* // From URL
|
|
44
|
+
* const fileUrl = new URL(`file://${filePath}`);
|
|
45
|
+
* console.log(`Gzip size of URL: ${await gzipSize(fileUrl)} bytes`);
|
|
46
|
+
*
|
|
47
|
+
* // From Readable stream
|
|
48
|
+
* const stream = Readable.from(text);
|
|
49
|
+
* console.log(`Gzip size of stream: ${await gzipSize(stream)} bytes`);
|
|
50
|
+
*
|
|
51
|
+
* await unlink(filePath); // Clean up temp file
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* main().catch(console.error);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
6
57
|
declare const gzipSize: (input: SizeInput, options?: ZlibOptions) => Promise<number>;
|
|
58
|
+
/**
|
|
59
|
+
* Asynchronously calculates the Brotli compressed size of the given input.
|
|
60
|
+
* The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
61
|
+
* Uses memory-efficient streaming for files and streams to avoid loading entire contents into memory.
|
|
62
|
+
* @param input The input data to compress with Brotli and measure.
|
|
63
|
+
* @param [options] Optional Zlib options for Brotli compression.
|
|
64
|
+
* @returns A promise that resolves with the Brotli compressed size in bytes.
|
|
65
|
+
* @example
|
|
66
|
+
* ```javascript
|
|
67
|
+
* import { brotliSize } from "@visulima/fs";
|
|
68
|
+
* import { Readable } from "node:stream";
|
|
69
|
+
* import { writeFile, unlink } from "node:fs/promises";
|
|
70
|
+
* import { join } from "node:path";
|
|
71
|
+
*
|
|
72
|
+
* const text = "This is a test string for Brotli compression efficiency.";
|
|
73
|
+
* const filePath = join("temp-brotli-file.txt");
|
|
74
|
+
*
|
|
75
|
+
* async function main() {
|
|
76
|
+
* // From Buffer
|
|
77
|
+
* const buffer = Buffer.from(text);
|
|
78
|
+
* console.log(`Brotli size of buffer: ${await brotliSize(buffer)} bytes`);
|
|
79
|
+
*
|
|
80
|
+
* // From string (content)
|
|
81
|
+
* console.log(`Brotli size of string content: ${await brotliSize(text)} bytes`);
|
|
82
|
+
*
|
|
83
|
+
* // From file path
|
|
84
|
+
* await writeFile(filePath, text);
|
|
85
|
+
* console.log(`Brotli size of file: ${await brotliSize(filePath)} bytes`);
|
|
86
|
+
*
|
|
87
|
+
* // From URL
|
|
88
|
+
* const fileUrl = new URL(`file://${filePath}`);
|
|
89
|
+
* console.log(`Brotli size of URL: ${await brotliSize(fileUrl)} bytes`);
|
|
90
|
+
*
|
|
91
|
+
* // From Readable stream
|
|
92
|
+
* const stream = Readable.from(text);
|
|
93
|
+
* console.log(`Brotli size of stream: ${await brotliSize(stream)} bytes`);
|
|
94
|
+
*
|
|
95
|
+
* await unlink(filePath); // Clean up temp file
|
|
96
|
+
* }
|
|
97
|
+
*
|
|
98
|
+
* main().catch(console.error);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
7
101
|
declare const brotliSize: (input: SizeInput, options?: BrotliOptions) => Promise<number>;
|
|
102
|
+
/**
|
|
103
|
+
* Asynchronously calculates the raw (uncompressed) size of the given input.
|
|
104
|
+
* The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
105
|
+
* Uses memory-efficient streaming for files and streams to avoid loading entire contents into memory.
|
|
106
|
+
* @param input The input data to measure.
|
|
107
|
+
* @returns A promise that resolves with the raw size in bytes.
|
|
108
|
+
* @example
|
|
109
|
+
* ```javascript
|
|
110
|
+
* import { rawSize } from "@visulima/fs";
|
|
111
|
+
* import { Readable } from "node:stream";
|
|
112
|
+
* import { writeFile, unlink } from "node:fs/promises";
|
|
113
|
+
* import { join } from "node:path";
|
|
114
|
+
*
|
|
115
|
+
* const text = "Hello, World!";
|
|
116
|
+
* const filePath = join("temp-raw-file.txt");
|
|
117
|
+
*
|
|
118
|
+
* async function main() {
|
|
119
|
+
* // From Buffer
|
|
120
|
+
* const buffer = Buffer.from(text);
|
|
121
|
+
* console.log(`Raw size of buffer: ${await rawSize(buffer)} bytes`);
|
|
122
|
+
*
|
|
123
|
+
* // From string (content)
|
|
124
|
+
* console.log(`Raw size of string content: ${await rawSize(text)} bytes`);
|
|
125
|
+
*
|
|
126
|
+
* // From file path
|
|
127
|
+
* await writeFile(filePath, text);
|
|
128
|
+
* console.log(`Raw size of file: ${await rawSize(filePath)} bytes`);
|
|
129
|
+
*
|
|
130
|
+
* // From URL
|
|
131
|
+
* const fileUrl = new URL(`file://${filePath}`);
|
|
132
|
+
* console.log(`Raw size of URL: ${await rawSize(fileUrl)} bytes`);
|
|
133
|
+
*
|
|
134
|
+
* // From Readable stream
|
|
135
|
+
* const stream = Readable.from(text);
|
|
136
|
+
* console.log(`Raw size of stream: ${await rawSize(stream)} bytes`);
|
|
137
|
+
*
|
|
138
|
+
* await unlink(filePath); // Clean up temp file
|
|
139
|
+
* }
|
|
140
|
+
*
|
|
141
|
+
* main().catch(console.error);
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
8
144
|
declare const rawSize: (input: SizeInput) => Promise<number>;
|
|
145
|
+
/**
|
|
146
|
+
* Synchronously calculates the gzipped size of the given input.
|
|
147
|
+
* The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
148
|
+
* Note: For Readable streams or very large files, consider using the asynchronous `gzipSize` function for better performance and to avoid blocking.
|
|
149
|
+
* @param input The input data to gzip and measure.
|
|
150
|
+
* @param [options] Optional Zlib options for gzip compression.
|
|
151
|
+
* @returns The gzipped size in bytes.
|
|
152
|
+
* @example
|
|
153
|
+
* ```javascript
|
|
154
|
+
* import { gzipSizeSync } from "@visulima/fs";
|
|
155
|
+
* import { writeFileSync, unlinkSync } from "node:fs";
|
|
156
|
+
* import { join } from "node:path";
|
|
157
|
+
*
|
|
158
|
+
* const text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
|
|
159
|
+
* const filePath = join("temp-sync-file.txt");
|
|
160
|
+
*
|
|
161
|
+
* // From Buffer
|
|
162
|
+
* const buffer = Buffer.from(text);
|
|
163
|
+
* console.log(`Sync Gzip size of buffer: ${gzipSizeSync(buffer)} bytes`);
|
|
164
|
+
*
|
|
165
|
+
* // From string (content)
|
|
166
|
+
* console.log(`Sync Gzip size of string content: ${gzipSizeSync(text)} bytes`);
|
|
167
|
+
*
|
|
168
|
+
* // From file path
|
|
169
|
+
* try {
|
|
170
|
+
* writeFileSync(filePath, text);
|
|
171
|
+
* console.log(`Sync Gzip size of file: ${gzipSizeSync(filePath)} bytes`);
|
|
172
|
+
*
|
|
173
|
+
* // From URL
|
|
174
|
+
* const fileUrl = new URL(`file://${filePath}`);
|
|
175
|
+
* console.log(`Sync Gzip size of URL: ${gzipSizeSync(fileUrl)} bytes`);
|
|
176
|
+
* } finally {
|
|
177
|
+
* try { unlinkSync(filePath); } catch {} // Clean up temp file
|
|
178
|
+
* }
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
9
181
|
declare const gzipSizeSync: (input: SizeInputSync, options?: ZlibOptions) => number;
|
|
182
|
+
/**
|
|
183
|
+
* Synchronously calculates the Brotli compressed size of the given input.
|
|
184
|
+
* The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
185
|
+
* Note: For Readable streams or very large files, consider using the asynchronous `brotliSize` function for better performance and to avoid blocking.
|
|
186
|
+
* @param input The input data to compress with Brotli and measure.
|
|
187
|
+
* @param [options] Optional Zlib options for Brotli compression.
|
|
188
|
+
* @returns The Brotli compressed size in bytes.
|
|
189
|
+
* @example
|
|
190
|
+
* ```javascript
|
|
191
|
+
* import { brotliSizeSync } from "@visulima/fs";
|
|
192
|
+
* import { writeFileSync, unlinkSync } from "node:fs";
|
|
193
|
+
* import { join } from "node:path";
|
|
194
|
+
*
|
|
195
|
+
* const text = "This is a test string for Brotli compression efficiency, synchronously.";
|
|
196
|
+
* const filePath = join("temp-brotli-sync-file.txt");
|
|
197
|
+
*
|
|
198
|
+
* // From Buffer
|
|
199
|
+
* const buffer = Buffer.from(text);
|
|
200
|
+
* console.log(`Sync Brotli size of buffer: ${brotliSizeSync(buffer)} bytes`);
|
|
201
|
+
*
|
|
202
|
+
* // From string (content)
|
|
203
|
+
* console.log(`Sync Brotli size of string content: ${brotliSizeSync(text)} bytes`);
|
|
204
|
+
*
|
|
205
|
+
* // From file path
|
|
206
|
+
* try {
|
|
207
|
+
* writeFileSync(filePath, text);
|
|
208
|
+
* console.log(`Sync Brotli size of file: ${brotliSizeSync(filePath)} bytes`);
|
|
209
|
+
*
|
|
210
|
+
* // From URL
|
|
211
|
+
* const fileUrl = new URL(`file://${filePath}`);
|
|
212
|
+
* console.log(`Sync Brotli size of URL: ${brotliSizeSync(fileUrl)} bytes`);
|
|
213
|
+
* } finally {
|
|
214
|
+
* try { unlinkSync(filePath); } catch {} // Clean up temp file
|
|
215
|
+
* }
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
10
218
|
declare const brotliSizeSync: (input: SizeInputSync, options?: BrotliOptions) => number;
|
|
219
|
+
/**
|
|
220
|
+
* Synchronously calculates the raw (uncompressed) size of the given input.
|
|
221
|
+
* The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
222
|
+
* For file paths, it uses `statSync` to get the file size.
|
|
223
|
+
* Note: For Readable streams or very large files, consider using the asynchronous `rawSize` function for better performance and to avoid blocking.
|
|
224
|
+
* @param input The input data to measure.
|
|
225
|
+
* @returns The raw size in bytes.
|
|
226
|
+
* @example
|
|
227
|
+
* ```javascript
|
|
228
|
+
* import { rawSizeSync } from "@visulima/fs";
|
|
229
|
+
* import { writeFileSync, unlinkSync } from "node:fs";
|
|
230
|
+
* import { join } from "node:path";
|
|
231
|
+
*
|
|
232
|
+
* const text = "Hello, Synchronous World!";
|
|
233
|
+
* const filePath = join("temp-raw-sync-file.txt");
|
|
234
|
+
*
|
|
235
|
+
* // From Buffer
|
|
236
|
+
* const buffer = Buffer.from(text);
|
|
237
|
+
* console.log(`Sync Raw size of buffer: ${rawSizeSync(buffer)} bytes`);
|
|
238
|
+
*
|
|
239
|
+
* // From string (content)
|
|
240
|
+
* console.log(`Sync Raw size of string content: ${rawSizeSync(text)} bytes`);
|
|
241
|
+
*
|
|
242
|
+
* // From file path
|
|
243
|
+
* try {
|
|
244
|
+
* writeFileSync(filePath, text);
|
|
245
|
+
* console.log(`Sync Raw size of file: ${rawSizeSync(filePath)} bytes`);
|
|
246
|
+
*
|
|
247
|
+
* // From URL
|
|
248
|
+
* const fileUrl = new URL(`file://${filePath}`);
|
|
249
|
+
* console.log(`Sync Raw size of URL: ${rawSizeSync(fileUrl)} bytes`);
|
|
250
|
+
* } finally {
|
|
251
|
+
* try { unlinkSync(filePath); } catch {} // Clean up temp file
|
|
252
|
+
* }
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
11
255
|
declare const rawSizeSync: (input: SizeInputSync) => number;
|
|
12
256
|
export { brotliSize, brotliSizeSync, gzipSize, gzipSizeSync, rawSize, rawSizeSync };
|
package/dist/toml.d.ts
CHANGED
|
@@ -1,9 +1,63 @@
|
|
|
1
|
-
import { a as CompressionType,
|
|
1
|
+
import { a as CompressionType, R as ReadTomlOptions, W as WriteTomlOptions } from "./packem_shared/types.d-CixEXeyM.js";
|
|
2
2
|
import 'node:fs';
|
|
3
3
|
import 'tinyglobby';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Asynchronously reads a TOML file and parses it into an object.
|
|
6
|
+
* @template R The expected type of the parsed TOML object. Defaults to `Record<string, unknown>`.
|
|
7
|
+
* @param path The path to the TOML file to read. Can be a file URL or a string path.
|
|
8
|
+
* @param options Optional configuration for reading the file. See {@link ReadTomlOptions}.
|
|
9
|
+
* @returns A promise that resolves with the parsed TOML object of type `R`.
|
|
10
|
+
* @example
|
|
11
|
+
* ```javascript
|
|
12
|
+
* import { readToml } from "@visulima/fs/toml";
|
|
13
|
+
* import { join } from "node:path";
|
|
14
|
+
*
|
|
15
|
+
* const config = await readToml(join("path", "to", "config.toml"));
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
5
18
|
declare const readToml: <R = Record<string, unknown>>(path: URL | string, options?: ReadTomlOptions<CompressionType>) => Promise<R>;
|
|
19
|
+
/**
|
|
20
|
+
* Synchronously reads a TOML file and parses it into an object.
|
|
21
|
+
* @template R The expected type of the parsed TOML object. Defaults to `Record<string, unknown>`.
|
|
22
|
+
* @param path The path to the TOML file to read. Can be a file URL or a string path.
|
|
23
|
+
* @param options Optional configuration for reading the file. See {@link ReadTomlOptions}.
|
|
24
|
+
* @returns The parsed TOML object of type `R`.
|
|
25
|
+
* @example
|
|
26
|
+
* ```javascript
|
|
27
|
+
* import { readTomlSync } from "@visulima/fs/toml";
|
|
28
|
+
* import { join } from "node:path";
|
|
29
|
+
*
|
|
30
|
+
* const config = readTomlSync(join("path", "to", "config.toml"));
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
6
33
|
declare const readTomlSync: (path: URL | string, options?: ReadTomlOptions<CompressionType>) => Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Asynchronously writes an object to a TOML file.
|
|
36
|
+
* @param path The path to the TOML file to write. Can be a file URL or a string path.
|
|
37
|
+
* @param data The data to serialize. Must be a plain object compatible with `smol-toml.stringify`.
|
|
38
|
+
* @param options Optional configuration for writing the TOML file. See {@link WriteTomlOptions}.
|
|
39
|
+
* @returns A promise that resolves when the TOML file has been written.
|
|
40
|
+
* @example
|
|
41
|
+
* ```javascript
|
|
42
|
+
* import { writeToml } from "@visulima/fs/toml";
|
|
43
|
+
* import { join } from "node:path";
|
|
44
|
+
*
|
|
45
|
+
* await writeToml(join("/tmp", "config.toml"), { name: "app", version: 1 });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
7
48
|
declare const writeToml: (path: URL | string, data: Record<string, unknown>, options?: WriteTomlOptions) => Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Synchronously writes an object to a TOML file.
|
|
51
|
+
* @param path The path to the TOML file to write. Can be a file URL or a string path.
|
|
52
|
+
* @param data The data to serialize. Must be a plain object compatible with `smol-toml.stringify`.
|
|
53
|
+
* @param options Optional configuration for writing the TOML file. See {@link WriteTomlOptions}.
|
|
54
|
+
* @example
|
|
55
|
+
* ```javascript
|
|
56
|
+
* import { writeTomlSync } from "@visulima/fs/toml";
|
|
57
|
+
* import { join } from "node:path";
|
|
58
|
+
*
|
|
59
|
+
* writeTomlSync(join("/tmp", "config.toml"), { name: "app", version: 1 });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
8
62
|
declare const writeTomlSync: (path: URL | string, data: Record<string, unknown>, options?: WriteTomlOptions) => void;
|
|
9
63
|
export { type ReadTomlOptions, type WriteTomlOptions, readToml, readTomlSync, writeToml, writeTomlSync };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,14 +1,102 @@
|
|
|
1
|
-
export { J as JSONError } from "./packem_shared/json-error.d-
|
|
1
|
+
export { J as JSONError } from "./packem_shared/json-error.d-DVILOyHc.js";
|
|
2
2
|
import { JsonValue } from 'type-fest';
|
|
3
|
-
import { C as CodeFrameOptions, J as JsonReviver } from "./packem_shared/types.d-
|
|
3
|
+
import { C as CodeFrameOptions, J as JsonReviver } from "./packem_shared/types.d-CixEXeyM.js";
|
|
4
4
|
export { toPath } from '@visulima/path/utils';
|
|
5
5
|
import 'node:fs';
|
|
6
6
|
import 'tinyglobby';
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Asserts that the provided contents are valid for writing to a file.
|
|
9
|
+
* Valid contents can be a string, an ArrayBuffer, or an ArrayBuffer view (e.g., Uint8Array).
|
|
10
|
+
* @param contents The file contents to validate.
|
|
11
|
+
* @throws {TypeError} If the contents are not a string, ArrayBuffer, or ArrayBuffer view.
|
|
12
|
+
* @example
|
|
13
|
+
* ```javascript
|
|
14
|
+
* import { assertValidFileContents } from "@visulima/fs"; // Assuming this util is exported
|
|
15
|
+
*
|
|
16
|
+
* try {
|
|
17
|
+
* assertValidFileContents("Hello, world!");
|
|
18
|
+
* assertValidFileContents(new Uint8Array([72, 101, 108, 108, 111])); // "Hello"
|
|
19
|
+
* assertValidFileContents(new ArrayBuffer(8));
|
|
20
|
+
* console.log("File contents are valid.");
|
|
21
|
+
* } catch (error) {
|
|
22
|
+
* console.error(error.message); // File contents must be a string, ArrayBuffer, or ArrayBuffer view.
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* try {
|
|
26
|
+
* assertValidFileContents(123); // Invalid content type
|
|
27
|
+
* } catch (error) {
|
|
28
|
+
* console.error(error.message); // File contents must be a string, ArrayBuffer, or ArrayBuffer view.
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
8
32
|
declare const assertValidFileContents: (contents: any) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Asserts that the provided path is a valid file or directory path.
|
|
35
|
+
* A valid path must be a non-empty string or a URL instance.
|
|
36
|
+
* @param fileOrDirectoryPath The path to validate.
|
|
37
|
+
* @throws {TypeError} If the path is not a non-empty string or a URL.
|
|
38
|
+
* @example
|
|
39
|
+
* ```javascript
|
|
40
|
+
* import { assertValidFileOrDirectoryPath } from "@visulima/fs"; // Assuming this util is exported
|
|
41
|
+
*
|
|
42
|
+
* try {
|
|
43
|
+
* assertValidFileOrDirectoryPath("/path/to/file.txt");
|
|
44
|
+
* assertValidFileOrDirectoryPath(new URL("file:///path/to/file.txt"));
|
|
45
|
+
* console.log("Path is valid.");
|
|
46
|
+
* } catch (error) {
|
|
47
|
+
* console.error(error.message); // Path must be a non-empty string or URL.
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* try {
|
|
51
|
+
* assertValidFileOrDirectoryPath(""); // Invalid path
|
|
52
|
+
* } catch (error) {
|
|
53
|
+
* console.error(error.message); // Path must be a non-empty string or URL.
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
9
57
|
declare const assertValidFileOrDirectoryPath: (fileOrDirectoryPath: any) => void;
|
|
10
58
|
declare function parseJson(string: string, filename?: string, options?: CodeFrameOptions): JsonValue;
|
|
11
59
|
declare function parseJson(string: string, reviver: JsonReviver, fileName?: string, options?: CodeFrameOptions): JsonValue;
|
|
60
|
+
/**
|
|
61
|
+
* Strips comments from a JSON string.
|
|
62
|
+
* Handles both single-line (//) and multi-line (/* ... *&#47;) comments.
|
|
63
|
+
* @param jsonString The JSON string possibly containing comments.
|
|
64
|
+
* @param [options] Optional configuration for stripping comments.
|
|
65
|
+
* @param [options.whitespace] If `true` (default), comments are replaced with whitespace to preserve line numbers and character positions. If `false`, comments are removed entirely.
|
|
66
|
+
* @returns The JSON string with comments stripped.
|
|
67
|
+
* @example
|
|
68
|
+
* ```javascript
|
|
69
|
+
* import { stripJsonComments } from "@visulima/fs"; // Assuming this util is exported
|
|
70
|
+
*
|
|
71
|
+
* const jsonWithComments = `{
|
|
72
|
+
* // This is a single-line comment
|
|
73
|
+
* "name": "John Doe",
|
|
74
|
+
* "age": 30, /* This is a
|
|
75
|
+
* multi-line comment */
|
|
76
|
+
* "city": "New York"
|
|
77
|
+
* }`;
|
|
78
|
+
*
|
|
79
|
+
* const stripped = stripJsonComments(jsonWithComments);
|
|
80
|
+
* console.log(stripped);
|
|
81
|
+
* // Output (with whitespace=true):
|
|
82
|
+
* // {
|
|
83
|
+
* //
|
|
84
|
+
* // "name": "John Doe",
|
|
85
|
+
* // "age": 30, /*
|
|
86
|
+
* //
|
|
87
|
+
* // "city": "New York"
|
|
88
|
+
* // }
|
|
89
|
+
*
|
|
90
|
+
* const strippedWithoutWhitespace = stripJsonComments(jsonWithComments, { whitespace: false });
|
|
91
|
+
* console.log(strippedWithoutWhitespace);
|
|
92
|
+
* // Output (with whitespace=false):
|
|
93
|
+
* // {
|
|
94
|
+
* // "name": "John Doe",
|
|
95
|
+
* // "age": 30,
|
|
96
|
+
* // "city": "New York"
|
|
97
|
+
* // }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
12
100
|
declare const stripJsonComments: (jsonString: string, options?: {
|
|
13
101
|
whitespace?: boolean;
|
|
14
102
|
}) => string;
|
package/dist/yaml.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { a as CompressionType,
|
|
2
|
-
export { type
|
|
1
|
+
import { a as CompressionType, m as ReadYamlOptions, Y as YamlReviver, n as WriteYamlOptions, o as JsonReplacer } from "./packem_shared/types.d-CixEXeyM.js";
|
|
2
|
+
export { type p as YamlReplacer } from "./packem_shared/types.d-CixEXeyM.js";
|
|
3
3
|
import 'node:fs';
|
|
4
4
|
import 'tinyglobby';
|
|
5
|
-
import './options';
|
|
6
5
|
declare function readYaml<R = Record<string, unknown>>(path: URL | string, options?: ReadYamlOptions<CompressionType>): Promise<R>;
|
|
7
6
|
declare function readYaml<R = Record<string, unknown>>(path: URL | string, reviver?: YamlReviver, options?: ReadYamlOptions<CompressionType>): Promise<R>;
|
|
8
7
|
declare function readYamlSync(path: URL | string, options?: ReadYamlOptions<CompressionType>): Record<string, unknown>;
|
package/package.json
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/fs",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.13",
|
|
4
4
|
"description": "Human friendly file system utilities for Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anolilab",
|
|
7
|
+
"brotli",
|
|
7
8
|
"detect-newline",
|
|
8
9
|
"dir",
|
|
9
10
|
"directory",
|
|
10
|
-
"eol",
|
|
11
11
|
"empty-dir",
|
|
12
12
|
"ensure",
|
|
13
|
-
"ensure-file",
|
|
14
13
|
"ensure-dir",
|
|
14
|
+
"ensure-file",
|
|
15
15
|
"ensure-link",
|
|
16
16
|
"ensure-symlink",
|
|
17
|
+
"eol",
|
|
17
18
|
"file",
|
|
18
19
|
"files",
|
|
19
20
|
"filesystem",
|
|
@@ -23,10 +24,14 @@
|
|
|
23
24
|
"folder",
|
|
24
25
|
"fs",
|
|
25
26
|
"fs-safe",
|
|
27
|
+
"gzip",
|
|
28
|
+
"ini",
|
|
29
|
+
"json",
|
|
30
|
+
"json5",
|
|
31
|
+
"jsonc",
|
|
32
|
+
"jsonc-parser",
|
|
26
33
|
"look",
|
|
27
34
|
"look-up",
|
|
28
|
-
"json",
|
|
29
|
-
"read-json",
|
|
30
35
|
"match",
|
|
31
36
|
"package",
|
|
32
37
|
"parent",
|
|
@@ -34,12 +39,16 @@
|
|
|
34
39
|
"path",
|
|
35
40
|
"read",
|
|
36
41
|
"read-file",
|
|
42
|
+
"read-json",
|
|
37
43
|
"read-yaml",
|
|
38
44
|
"resolve",
|
|
39
45
|
"safe",
|
|
40
46
|
"search",
|
|
41
|
-
"
|
|
47
|
+
"size",
|
|
48
|
+
"smol-toml",
|
|
42
49
|
"standard",
|
|
50
|
+
"std",
|
|
51
|
+
"toml",
|
|
43
52
|
"up",
|
|
44
53
|
"visulima",
|
|
45
54
|
"walk",
|
|
@@ -48,16 +57,7 @@
|
|
|
48
57
|
"write-dir",
|
|
49
58
|
"write-file",
|
|
50
59
|
"write-safe",
|
|
51
|
-
"yaml"
|
|
52
|
-
"toml",
|
|
53
|
-
"jsonc",
|
|
54
|
-
"json5",
|
|
55
|
-
"ini",
|
|
56
|
-
"smol-toml",
|
|
57
|
-
"jsonc-parser",
|
|
58
|
-
"size",
|
|
59
|
-
"brotli",
|
|
60
|
-
"gzip"
|
|
60
|
+
"yaml"
|
|
61
61
|
],
|
|
62
62
|
"homepage": "https://visulima.com/packages/fs/",
|
|
63
63
|
"bugs": {
|
|
@@ -151,15 +151,14 @@
|
|
|
151
151
|
"LICENSE.md"
|
|
152
152
|
],
|
|
153
153
|
"dependencies": {
|
|
154
|
-
"@visulima/path": "3.0.0-alpha.
|
|
155
|
-
"type-fest": "5.6.0"
|
|
154
|
+
"@visulima/path": "3.0.0-alpha.10"
|
|
156
155
|
},
|
|
157
156
|
"peerDependencies": {
|
|
158
157
|
"ini": "^6.0.0",
|
|
159
158
|
"json5": "^2.2.3",
|
|
160
159
|
"jsonc-parser": "^3.3.1",
|
|
161
160
|
"smol-toml": "^1.6.1",
|
|
162
|
-
"yaml": "2.8.
|
|
161
|
+
"yaml": "2.8.4"
|
|
163
162
|
},
|
|
164
163
|
"peerDependenciesMeta": {
|
|
165
164
|
"ini": {
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { G as GlobOptions } from "./types.d-CYpAhWov.js";
|
|
2
|
-
declare const glob: (patterns: string | ReadonlyArray<string>, options?: GlobOptions) => Promise<string[]>;
|
|
3
|
-
declare const globSync: (patterns: string | ReadonlyArray<string>, options?: GlobOptions) => string[];
|
|
4
|
-
export { globSync as a, glob as g };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
declare class JSONError extends Error {
|
|
2
|
-
#private;
|
|
3
|
-
fileName: string | undefined;
|
|
4
|
-
codeFrame: string | undefined;
|
|
5
|
-
readonly name = "JSONError";
|
|
6
|
-
constructor(message: string);
|
|
7
|
-
get message(): string;
|
|
8
|
-
set message(message: string);
|
|
9
|
-
}
|
|
10
|
-
export { JSONError as J };
|