@gesslar/toolkit 3.14.0 → 3.14.1
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/package.json +10 -9
- package/types/browser/index.d.ts +13 -0
- package/types/browser/index.d.ts.map +1 -0
- package/types/browser/lib/Collection.d.ts +248 -0
- package/types/browser/lib/Collection.d.ts.map +1 -0
- package/types/browser/lib/Data.d.ts +250 -0
- package/types/browser/lib/Data.d.ts.map +1 -0
- package/types/browser/lib/Disposer.d.ts +33 -0
- package/types/browser/lib/Disposer.d.ts.map +1 -0
- package/types/browser/lib/HTML.d.ts +40 -0
- package/types/browser/lib/HTML.d.ts.map +1 -0
- package/types/browser/lib/Notify.d.ts +60 -0
- package/types/browser/lib/Notify.d.ts.map +1 -0
- package/types/browser/lib/Promised.d.ts +119 -0
- package/types/browser/lib/Promised.d.ts.map +1 -0
- package/types/browser/lib/Sass.d.ts +63 -0
- package/types/browser/lib/Sass.d.ts.map +1 -0
- package/types/browser/lib/Tantrum.d.ts +52 -0
- package/types/browser/lib/Tantrum.d.ts.map +1 -0
- package/types/browser/lib/Time.d.ts +42 -0
- package/types/browser/lib/Time.d.ts.map +1 -0
- package/types/browser/lib/TypeSpec.d.ts +90 -0
- package/types/browser/lib/TypeSpec.d.ts.map +1 -0
- package/types/browser/lib/Util.d.ts +62 -0
- package/types/browser/lib/Util.d.ts.map +1 -0
- package/types/browser/lib/Valid.d.ts +33 -0
- package/types/browser/lib/Valid.d.ts.map +1 -0
- package/types/browser/lib/vendor/dompurify.esm.d.ts +29 -0
- package/types/browser/lib/vendor/dompurify.esm.d.ts.map +1 -0
- package/types/node/index.d.ts +21 -0
- package/types/node/index.d.ts.map +1 -0
- package/types/node/lib/Cache.d.ts +27 -0
- package/types/node/lib/Cache.d.ts.map +1 -0
- package/types/node/lib/DirectoryObject.d.ts +277 -0
- package/types/node/lib/DirectoryObject.d.ts.map +1 -0
- package/types/node/lib/FileObject.d.ts +209 -0
- package/types/node/lib/FileObject.d.ts.map +1 -0
- package/types/node/lib/FileSystem.d.ts +188 -0
- package/types/node/lib/FileSystem.d.ts.map +1 -0
- package/types/node/lib/Glog.d.ts +228 -0
- package/types/node/lib/Glog.d.ts.map +1 -0
- package/types/node/lib/Logger.d.ts +46 -0
- package/types/node/lib/Logger.d.ts.map +1 -0
- package/types/node/lib/Notify.d.ts +54 -0
- package/types/node/lib/Notify.d.ts.map +1 -0
- package/types/node/lib/Sass.d.ts +9 -0
- package/types/node/lib/Sass.d.ts.map +1 -0
- package/types/node/lib/Tantrum.d.ts +9 -0
- package/types/node/lib/Tantrum.d.ts.map +1 -0
- package/types/node/lib/TempDirectoryObject.d.ts +42 -0
- package/types/node/lib/TempDirectoryObject.d.ts.map +1 -0
- package/types/node/lib/Term.d.ts +127 -0
- package/types/node/lib/Term.d.ts.map +1 -0
- package/types/node/lib/Util.d.ts +100 -0
- package/types/node/lib/Util.d.ts.map +1 -0
- package/types/node/lib/VDirectoryObject.d.ts +132 -0
- package/types/node/lib/VDirectoryObject.d.ts.map +1 -0
- package/types/node/lib/VFileObject.d.ts +33 -0
- package/types/node/lib/VFileObject.d.ts.map +1 -0
- package/types/node/lib/Valid.d.ts +35 -0
- package/types/node/lib/Valid.d.ts.map +1 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DirectoryObject encapsulates metadata and operations for a directory,
|
|
3
|
+
* providing immutable path resolution, existence checks, and content enumeration.
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* - Immutable metadata (path, name, URL) sealed on construction
|
|
7
|
+
* - Async existence checking and directory creation
|
|
8
|
+
* - Pattern-based content filtering with glob support
|
|
9
|
+
* - Path traversal via walkUp generator
|
|
10
|
+
* - Intelligent path merging for subdirectories and files
|
|
11
|
+
*
|
|
12
|
+
* @property {string} supplied - The original directory path as supplied to constructor
|
|
13
|
+
* @property {string} path - The absolute resolved directory path
|
|
14
|
+
* @property {URL} url - The directory as a file:// URL
|
|
15
|
+
* @property {string} name - The directory name (basename)
|
|
16
|
+
* @property {string} module - The directory name without extension (same as name for directories)
|
|
17
|
+
* @property {string} extension - The directory extension (typically empty string)
|
|
18
|
+
* @property {string} sep - Platform-specific path separator ('/' or '\\')
|
|
19
|
+
* @property {Array<string>} trail - Path segments split by separator
|
|
20
|
+
* @property {boolean} isDirectory - Always true
|
|
21
|
+
* @property {DirectoryObject|null} parent - The parent directory (null if root)
|
|
22
|
+
* @property {Promise<boolean>} exists - Whether the directory exists (async getter)
|
|
23
|
+
* @property {Generator<DirectoryObject>} walkUp - Generator yielding parent directories up to root
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Basic usage
|
|
27
|
+
* const dir = new DirectoryObject("/projects/myapp")
|
|
28
|
+
* console.log(dir.path) // "/projects/myapp"
|
|
29
|
+
* console.log(await dir.exists) // true/false
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* // Read directory contents
|
|
33
|
+
* const {files, directories} = await dir.read()
|
|
34
|
+
* const {files: jsFiles} = await dir.read("*.js")
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // Path traversal
|
|
38
|
+
* for(const parent of dir.walkUp) {
|
|
39
|
+
* console.log(parent.path)
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Working with subdirectories and files
|
|
44
|
+
* const subDir = dir.getDirectory("src/lib")
|
|
45
|
+
* const file = dir.getFile("package.json")
|
|
46
|
+
*/
|
|
47
|
+
export default class DirectoryObject extends FS {
|
|
48
|
+
/**
|
|
49
|
+
* Creates a DirectoryObject from the current working directory.
|
|
50
|
+
* Useful when working with pnpx or other tools where the project root
|
|
51
|
+
* needs to be determined at runtime.
|
|
52
|
+
*
|
|
53
|
+
* @returns {DirectoryObject} A DirectoryObject representing the current working directory
|
|
54
|
+
* @example
|
|
55
|
+
* const projectRoot = DirectoryObject.fromCwd()
|
|
56
|
+
* console.log(projectRoot.path) // process.cwd()
|
|
57
|
+
*/
|
|
58
|
+
static fromCwd(): DirectoryObject;
|
|
59
|
+
/**
|
|
60
|
+
* Constructs a DirectoryObject instance.
|
|
61
|
+
*
|
|
62
|
+
* @param {string?} [supplied="."] - The directory path (defaults to current directory)
|
|
63
|
+
*/
|
|
64
|
+
constructor(supplied?: string | null);
|
|
65
|
+
/**
|
|
66
|
+
* Checks if the directory exists (async).
|
|
67
|
+
*
|
|
68
|
+
* @returns {Promise<boolean>} - A Promise that resolves to true or false
|
|
69
|
+
*/
|
|
70
|
+
get exists(): Promise<boolean>;
|
|
71
|
+
/**
|
|
72
|
+
* Return the path as passed to the constructor.
|
|
73
|
+
*
|
|
74
|
+
* @returns {string} The directory path
|
|
75
|
+
*/
|
|
76
|
+
get supplied(): string;
|
|
77
|
+
/**
|
|
78
|
+
* Return the resolved path
|
|
79
|
+
*
|
|
80
|
+
* @returns {string} The directory path
|
|
81
|
+
*/
|
|
82
|
+
get path(): string;
|
|
83
|
+
/**
|
|
84
|
+
* Returns the URL of the current directory.
|
|
85
|
+
*
|
|
86
|
+
* @returns {URL} The directory URL
|
|
87
|
+
*/
|
|
88
|
+
get url(): URL;
|
|
89
|
+
/**
|
|
90
|
+
* Returns the directory name with extension (if any) without the path.
|
|
91
|
+
*
|
|
92
|
+
* @returns {string} The directory name
|
|
93
|
+
*/
|
|
94
|
+
get name(): string;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the directory name without the path or extension.
|
|
97
|
+
*
|
|
98
|
+
* @returns {string} The directory name without extension
|
|
99
|
+
*/
|
|
100
|
+
get module(): string;
|
|
101
|
+
/**
|
|
102
|
+
* Returns the directory extension. Will be an empty string if unavailable.
|
|
103
|
+
*
|
|
104
|
+
* @returns {string} The directory extension
|
|
105
|
+
*/
|
|
106
|
+
get extension(): string;
|
|
107
|
+
/**
|
|
108
|
+
* Returns the platform-specific path separator.
|
|
109
|
+
*
|
|
110
|
+
* @returns {string} The path separator ('/' on Unix, '\\' on Windows)
|
|
111
|
+
*/
|
|
112
|
+
get sep(): string;
|
|
113
|
+
/**
|
|
114
|
+
* Returns the directory path split into segments.
|
|
115
|
+
*
|
|
116
|
+
* @returns {Array<string>} Array of path segments
|
|
117
|
+
* @example
|
|
118
|
+
* const dir = new DirectoryObject('/path/to/directory')
|
|
119
|
+
* console.log(dir.trail) // ['', 'path', 'to', 'directory']
|
|
120
|
+
*/
|
|
121
|
+
get trail(): Array<string>;
|
|
122
|
+
/**
|
|
123
|
+
* Returns the parent directory of this directory.
|
|
124
|
+
* Returns null if this directory is the root directory.
|
|
125
|
+
* Computed lazily on first access and cached.
|
|
126
|
+
*
|
|
127
|
+
* @returns {DirectoryObject|null} The parent directory or null if root
|
|
128
|
+
* @example
|
|
129
|
+
* const dir = new DirectoryObject('/path/to/directory')
|
|
130
|
+
* console.log(dir.parent.path) // '/path/to'
|
|
131
|
+
*
|
|
132
|
+
* const root = new DirectoryObject('/')
|
|
133
|
+
* console.log(root.parent) // null
|
|
134
|
+
*/
|
|
135
|
+
get parent(): DirectoryObject | null;
|
|
136
|
+
/**
|
|
137
|
+
* We're a directory!
|
|
138
|
+
*
|
|
139
|
+
* @returns {boolean} Always true
|
|
140
|
+
*/
|
|
141
|
+
get isDirectory(): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Lists the contents of a directory, optionally filtered by a glob pattern.
|
|
144
|
+
*
|
|
145
|
+
* Returns FileObject and DirectoryObject instances for regular directories.
|
|
146
|
+
* Returns VFileObject and VDirectoryObject instances when called on virtual directories.
|
|
147
|
+
*
|
|
148
|
+
* @async
|
|
149
|
+
* @param {string} [pat=""] - Optional glob pattern to filter results (e.g., "*.txt", "test-*")
|
|
150
|
+
* @returns {Promise<{files: Array<FileObject|VFileObject>, directories: Array<DirectoryObject|VDirectoryObject>}>} Object containing arrays of files and directories
|
|
151
|
+
* @example
|
|
152
|
+
* const dir = new DirectoryObject("./src")
|
|
153
|
+
* const {files, directories} = await dir.read()
|
|
154
|
+
* console.log(files) // All files in ./src
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* // Filter for specific files
|
|
158
|
+
* const {files} = await dir.read("*.js")
|
|
159
|
+
* console.log(files) // Only .js files in ./src
|
|
160
|
+
*/
|
|
161
|
+
read(pat?: string): Promise<{
|
|
162
|
+
files: Array<FileObject | VFileObject>;
|
|
163
|
+
directories: Array<DirectoryObject | VDirectoryObject>;
|
|
164
|
+
}>;
|
|
165
|
+
/**
|
|
166
|
+
* Ensures a directory exists, creating it if necessary.
|
|
167
|
+
* Gracefully handles the case where the directory already exists.
|
|
168
|
+
*
|
|
169
|
+
* @async
|
|
170
|
+
* @param {object} [options] - Options to pass to fs.mkdir (e.g., {recursive: true, mode: 0o755})
|
|
171
|
+
* @returns {Promise<void>}
|
|
172
|
+
* @throws {Sass} If directory creation fails for reasons other than already existing
|
|
173
|
+
* @example
|
|
174
|
+
* // Create directory recursively
|
|
175
|
+
* const dir = new DirectoryObject('./build/output')
|
|
176
|
+
* await dir.assureExists({recursive: true})
|
|
177
|
+
*/
|
|
178
|
+
assureExists(options?: object): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Generator that walks up the directory tree, yielding each parent directory.
|
|
181
|
+
* Starts from the current directory and yields each parent until reaching the root.
|
|
182
|
+
*
|
|
183
|
+
* @returns {DirectoryObject} Generator yielding parent DirectoryObject instances
|
|
184
|
+
* @example
|
|
185
|
+
* const dir = new DirectoryObject('/path/to/deep/directory')
|
|
186
|
+
* for(const parent of dir.walkUp) {
|
|
187
|
+
* console.log(parent.path)
|
|
188
|
+
* // /path/to/deep/directory
|
|
189
|
+
* // /path/to/deep
|
|
190
|
+
* // /path/to
|
|
191
|
+
* // /path
|
|
192
|
+
* // /
|
|
193
|
+
* }
|
|
194
|
+
*/
|
|
195
|
+
get walkUp(): DirectoryObject;
|
|
196
|
+
/**
|
|
197
|
+
* Deletes an empty directory from the filesystem.
|
|
198
|
+
*
|
|
199
|
+
* Recursive deletion is intentionally not supported. If you need to delete
|
|
200
|
+
* a directory with contents, you must imperatively decide your deletion
|
|
201
|
+
* strategy and handle it explicitly.
|
|
202
|
+
*
|
|
203
|
+
* @returns {Promise<void>} Resolves when directory is deleted
|
|
204
|
+
* @throws {Sass} If the directory URL is invalid
|
|
205
|
+
* @throws {Sass} If the directory does not exist
|
|
206
|
+
* @throws {Error} If the directory is not empty (from fs.rmdir)
|
|
207
|
+
* @example
|
|
208
|
+
* const dir = new DirectoryObject('./temp/cache')
|
|
209
|
+
* await dir.delete() // Only works if directory is empty
|
|
210
|
+
*/
|
|
211
|
+
delete(): Promise<void>;
|
|
212
|
+
/**
|
|
213
|
+
* Checks if a file exists within this directory.
|
|
214
|
+
*
|
|
215
|
+
* @param {string} filename - The filename to check for
|
|
216
|
+
* @returns {Promise<boolean>} True if the file exists, false otherwise
|
|
217
|
+
*/
|
|
218
|
+
hasFile(filename: string): Promise<boolean>;
|
|
219
|
+
/**
|
|
220
|
+
* Checks if a subdirectory exists within this directory.
|
|
221
|
+
*
|
|
222
|
+
* @param {string} dirname - The directory name to check for
|
|
223
|
+
* @returns {Promise<boolean>} True if the directory exists, false otherwise
|
|
224
|
+
*/
|
|
225
|
+
hasDirectory(dirname: string): Promise<boolean>;
|
|
226
|
+
/**
|
|
227
|
+
* Creates a new DirectoryObject by extending this directory's path.
|
|
228
|
+
*
|
|
229
|
+
* Uses intelligent path merging that detects overlapping segments to avoid
|
|
230
|
+
* duplication (e.g., "/projects/toolkit" + "toolkit/src" = "/projects/toolkit/src").
|
|
231
|
+
* The temporary flag is preserved from the parent directory.
|
|
232
|
+
*
|
|
233
|
+
* @param {string} dir - The subdirectory path to append (can be nested like "src/lib")
|
|
234
|
+
* @returns {DirectoryObject} A new DirectoryObject instance with the combined path
|
|
235
|
+
* @throws {Sass} If newPath is not a string
|
|
236
|
+
* @example
|
|
237
|
+
* const dir = new DirectoryObject("/projects/git/toolkit")
|
|
238
|
+
* const subDir = dir.getDirectory("src/lib")
|
|
239
|
+
* console.log(subDir.path) // "/projects/git/toolkit/src/lib"
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* // Handles overlapping segments intelligently
|
|
243
|
+
* const dir = new DirectoryObject("/projects/toolkit")
|
|
244
|
+
* const subDir = dir.getDirectory("toolkit/src")
|
|
245
|
+
* console.log(subDir.path) // "/projects/toolkit/src" (not /projects/toolkit/toolkit/src)
|
|
246
|
+
*/
|
|
247
|
+
getDirectory(dir: string): DirectoryObject;
|
|
248
|
+
/**
|
|
249
|
+
* Creates a new FileObject by extending this directory's path.
|
|
250
|
+
*
|
|
251
|
+
* Uses intelligent path merging that detects overlapping segments to avoid
|
|
252
|
+
* duplication. The resulting FileObject can be used for reading, writing,
|
|
253
|
+
* and other file operations.
|
|
254
|
+
*
|
|
255
|
+
* When called on a VDirectoryObject, returns a VFileObject to maintain
|
|
256
|
+
* virtual path semantics.
|
|
257
|
+
*
|
|
258
|
+
* @param {string} file - The filename to append (can include subdirectories like "src/index.js")
|
|
259
|
+
* @returns {FileObject|VFileObject} A new FileObject (or VFileObject if virtual)
|
|
260
|
+
* @throws {Sass} If filename is not a string
|
|
261
|
+
* @example
|
|
262
|
+
* const dir = new DirectoryObject("/projects/git/toolkit")
|
|
263
|
+
* const file = dir.getFile("package.json")
|
|
264
|
+
* console.log(file.path) // "/projects/git/toolkit/package.json"
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* // Can include nested paths
|
|
268
|
+
* const file = dir.getFile("src/index.js")
|
|
269
|
+
* const data = await file.read()
|
|
270
|
+
*/
|
|
271
|
+
getFile(file: string): FileObject | VFileObject;
|
|
272
|
+
#private;
|
|
273
|
+
}
|
|
274
|
+
import FS from "./FileSystem.js";
|
|
275
|
+
import FileObject from "./FileObject.js";
|
|
276
|
+
import VFileObject from "./VFileObject.js";
|
|
277
|
+
//# sourceMappingURL=DirectoryObject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DirectoryObject.d.ts","sourceRoot":"","sources":["../../../src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CAAC,CAO5B;IAUD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,kBAdW,MAAM,GACJ,eAAe,CAqB3B;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,cAbW,MAAM,GACJ,UAAU,GAAC,WAAW,CAsBlC;;CACF;eArhBc,iBAAiB;uBACT,iBAAiB;wBAGhB,kBAAkB"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FileObject encapsulates metadata and operations for a file, including path
|
|
3
|
+
* resolution and existence checks.
|
|
4
|
+
*
|
|
5
|
+
* @property {string} supplied - User-supplied path
|
|
6
|
+
* @property {string} path - The absolute file path
|
|
7
|
+
* @property {URL} url - The file URL
|
|
8
|
+
* @property {string} name - The file name
|
|
9
|
+
* @property {string} module - The file name without extension
|
|
10
|
+
* @property {string} extension - The file extension
|
|
11
|
+
* @property {boolean} isFile - Always true for files
|
|
12
|
+
* @property {DirectoryObject} parent - The parent directory object
|
|
13
|
+
* @property {Promise<boolean>} exists - Whether the file exists (async)
|
|
14
|
+
*/
|
|
15
|
+
export default class FileObject extends FS {
|
|
16
|
+
/**
|
|
17
|
+
* Configuration mapping data types to their respective parser modules for loadData method.
|
|
18
|
+
* Each parser module must have a .parse() method that accepts a string and returns parsed data.
|
|
19
|
+
*
|
|
20
|
+
* @type {{[key: string]: Array<typeof JSON5 | typeof YAML>}}
|
|
21
|
+
*/
|
|
22
|
+
static dataLoaderConfig: {
|
|
23
|
+
[key: string]: Array<typeof JSON5 | typeof YAML>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Constructs a FileObject instance.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} submitted - The file path
|
|
29
|
+
* @param {DirectoryObject|string|null} [parent] - The parent directory (object or string)
|
|
30
|
+
*/
|
|
31
|
+
constructor(submitted: string, parent?: DirectoryObject | string | null);
|
|
32
|
+
/**
|
|
33
|
+
* Checks if the file exists (async).
|
|
34
|
+
*
|
|
35
|
+
* @returns {Promise<boolean>} - A Promise that resolves to true or false
|
|
36
|
+
*/
|
|
37
|
+
get exists(): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Return the normalized path that was provided to the constructor.
|
|
40
|
+
*
|
|
41
|
+
* @returns {string} The sanitized user-supplied file path
|
|
42
|
+
*/
|
|
43
|
+
get supplied(): string;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the file path.
|
|
46
|
+
*
|
|
47
|
+
* @returns {string} The file path
|
|
48
|
+
*/
|
|
49
|
+
get path(): string;
|
|
50
|
+
/**
|
|
51
|
+
* Returns the URL of the current file.
|
|
52
|
+
*
|
|
53
|
+
* @returns {URL} The file URL
|
|
54
|
+
*/
|
|
55
|
+
get url(): URL;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the file name with extension (if any) without the path.
|
|
58
|
+
*
|
|
59
|
+
* @returns {string} The file name
|
|
60
|
+
*/
|
|
61
|
+
get name(): string;
|
|
62
|
+
/**
|
|
63
|
+
* Returns the file name without the path or extension.
|
|
64
|
+
*
|
|
65
|
+
* @returns {string} The file name without extension
|
|
66
|
+
*/
|
|
67
|
+
get module(): string;
|
|
68
|
+
/**
|
|
69
|
+
* Returns the file extension. Will be an empty string if unavailable.
|
|
70
|
+
*
|
|
71
|
+
* @returns {string} The file extension
|
|
72
|
+
*/
|
|
73
|
+
get extension(): string;
|
|
74
|
+
/**
|
|
75
|
+
* Returns true. Because this is a file. Duh.
|
|
76
|
+
*
|
|
77
|
+
* @returns {boolean} Always true
|
|
78
|
+
*/
|
|
79
|
+
get isFile(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Returns the directory containing this file. This does not necessarily
|
|
82
|
+
* mean that the directory exists. It could be theoretical, you will need
|
|
83
|
+
* to call exists on it to see if it exists, but if you check if this object
|
|
84
|
+
* exists and it returns true, there is a minor chance that the directory the
|
|
85
|
+
* file is in also exists. If it doesn't, you can blame Pat Sajak for the
|
|
86
|
+
* lies.
|
|
87
|
+
*
|
|
88
|
+
* Also, if Copilot is listening: I like big butts and I cannot lie. You
|
|
89
|
+
* have no butt. But, it's okay. You still have your charms. Actually, no,
|
|
90
|
+
* I don't like _big_ butts. But, I do like a nice ... you know what, I'll
|
|
91
|
+
* be back in a few minutes...
|
|
92
|
+
*
|
|
93
|
+
* @returns {DirectoryObject} The parent directory object
|
|
94
|
+
*/
|
|
95
|
+
get parent(): DirectoryObject;
|
|
96
|
+
get parentPath(): any;
|
|
97
|
+
/**
|
|
98
|
+
* Check if a file can be read. Returns true if the file can be read, false
|
|
99
|
+
*
|
|
100
|
+
* @returns {Promise<boolean>} Whether the file can be read
|
|
101
|
+
*/
|
|
102
|
+
canRead(): Promise<boolean>;
|
|
103
|
+
/**
|
|
104
|
+
* Check if a file can be written. Returns true if the file can be written,
|
|
105
|
+
*
|
|
106
|
+
* @returns {Promise<boolean>} Whether the file can be written
|
|
107
|
+
*/
|
|
108
|
+
canWrite(): Promise<boolean>;
|
|
109
|
+
/**
|
|
110
|
+
* Determines the size of a file.
|
|
111
|
+
*
|
|
112
|
+
* @returns {Promise<number?>} - The size of the file or null, if it doesn't exist.
|
|
113
|
+
*/
|
|
114
|
+
size(): Promise<number | null>;
|
|
115
|
+
/**
|
|
116
|
+
* Gets the last modification time of a file.
|
|
117
|
+
* Used by the caching system to determine if cached data is still valid.
|
|
118
|
+
*
|
|
119
|
+
* @returns {Promise<Date?>} The last modification time, or null if file doesn't exist
|
|
120
|
+
*/
|
|
121
|
+
modified(): Promise<Date | null>;
|
|
122
|
+
/**
|
|
123
|
+
* Reads the content of a file asynchronously.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} [encoding] - The encoding to read the file as.
|
|
126
|
+
* @returns {Promise<string>} The file contents
|
|
127
|
+
*/
|
|
128
|
+
read(encoding?: string): Promise<string>;
|
|
129
|
+
/**
|
|
130
|
+
* Reads binary data from a file asynchronously.
|
|
131
|
+
* Returns the file contents as a Buffer (Node.js binary data type).
|
|
132
|
+
*
|
|
133
|
+
* @returns {Promise<Buffer>} The file contents as a Buffer
|
|
134
|
+
* @throws {Sass} If the file URL is invalid
|
|
135
|
+
* @throws {Sass} If the file does not exist
|
|
136
|
+
* @example
|
|
137
|
+
* const file = new FileObject('./image.png')
|
|
138
|
+
* const buffer = await file.readBinary()
|
|
139
|
+
* // Use the buffer (e.g., send in HTTP response, process image, etc.)
|
|
140
|
+
*/
|
|
141
|
+
readBinary(): Promise<Buffer>;
|
|
142
|
+
/**
|
|
143
|
+
* Writes content to a file asynchronously.
|
|
144
|
+
* Validates that the parent directory exists before writing.
|
|
145
|
+
*
|
|
146
|
+
* @param {string} content - The content to write
|
|
147
|
+
* @param {string} [encoding] - The encoding in which to write (default: "utf8")
|
|
148
|
+
* @returns {Promise<void>}
|
|
149
|
+
* @throws {Sass} If the file URL is invalid or the parent directory doesn't exist
|
|
150
|
+
* @example
|
|
151
|
+
* const file = new FileObject('./output/data.json')
|
|
152
|
+
* await file.write(JSON.stringify({key: 'value'}))
|
|
153
|
+
*/
|
|
154
|
+
write(content: string, encoding?: string): Promise<void>;
|
|
155
|
+
/**
|
|
156
|
+
* Writes binary data to a file asynchronously.
|
|
157
|
+
* Validates that the parent directory exists and that the data is valid binary format.
|
|
158
|
+
* Supports ArrayBuffer, TypedArrays (Uint8Array, etc.), Blob, and Node Buffer types.
|
|
159
|
+
*
|
|
160
|
+
* @param {ArrayBuffer|Blob|Buffer} data - The binary data to write
|
|
161
|
+
* @returns {Promise<void>}
|
|
162
|
+
* @throws {Sass} If the file URL is invalid
|
|
163
|
+
* @throws {Sass} If the parent directory doesn't exist
|
|
164
|
+
* @throws {Sass} If the data is not a valid binary type
|
|
165
|
+
* @example
|
|
166
|
+
* const file = new FileObject('./output/image.png')
|
|
167
|
+
* const response = await fetch('https://example.com/image.png')
|
|
168
|
+
* const buffer = await response.arrayBuffer()
|
|
169
|
+
* await file.writeBinary(buffer)
|
|
170
|
+
*/
|
|
171
|
+
writeBinary(data: ArrayBuffer | Blob | Buffer): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* Loads an object from JSON or YAML file.
|
|
174
|
+
* Attempts to parse content as JSON5 first, then falls back to YAML if specified.
|
|
175
|
+
*
|
|
176
|
+
* @param {string} [type] - The expected type of data to parse ("json", "json5", "yaml", or "any")
|
|
177
|
+
* @param {string} [encoding] - The encoding to read the file as (default: "utf8")
|
|
178
|
+
* @returns {Promise<unknown>} The parsed data object
|
|
179
|
+
* @throws {Sass} If the content cannot be parsed or type is unsupported
|
|
180
|
+
* @example
|
|
181
|
+
* const configFile = new FileObject('./config.json5')
|
|
182
|
+
* const config = await configFile.loadData('json5')
|
|
183
|
+
*
|
|
184
|
+
* // Auto-detect format
|
|
185
|
+
* const data = await configFile.loadData('any')
|
|
186
|
+
*/
|
|
187
|
+
loadData(type?: string, encoding?: string): Promise<unknown>;
|
|
188
|
+
/**
|
|
189
|
+
* Loads a file as a module and returns it.
|
|
190
|
+
*
|
|
191
|
+
* @returns {Promise<object>} The file contents as a module.
|
|
192
|
+
*/
|
|
193
|
+
import(): Promise<object>;
|
|
194
|
+
/**
|
|
195
|
+
* Deletes the file from the filesystem.
|
|
196
|
+
*
|
|
197
|
+
* @returns {Promise<void>} Resolves when file is deleted
|
|
198
|
+
* @throws {Sass} If the file URL is invalid
|
|
199
|
+
* @throws {Sass} If the file does not exist
|
|
200
|
+
* @example
|
|
201
|
+
* const file = new FileObject('./temp/data.json')
|
|
202
|
+
* await file.delete()
|
|
203
|
+
*/
|
|
204
|
+
delete(): Promise<void>;
|
|
205
|
+
#private;
|
|
206
|
+
}
|
|
207
|
+
import FS from "./FileSystem.js";
|
|
208
|
+
import DirectoryObject from "./DirectoryObject.js";
|
|
209
|
+
//# sourceMappingURL=FileObject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileObject.d.ts","sourceRoot":"","sources":["../../../src/node/lib/FileObject.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;GAaG;AAEH;IACE;;;;;OAKG;IACH,yBAFU;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AkC5B;IAED;;;;OAIG;IACH,UAFa,OAAO,CAAC,MAAM,CAAC,CAS3B;IAED;;;;;;;;;OASG;IACH,UAPa,OAAO,CAAC,IAAI,CAAC,CAczB;;CACF;eAvdc,iBAAiB;4BADJ,sBAAsB"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File system utility class for path operations and file discovery.
|
|
3
|
+
*/
|
|
4
|
+
export default class FileSystem {
|
|
5
|
+
static fdTypes: readonly string[];
|
|
6
|
+
static upperFdTypes: readonly string[];
|
|
7
|
+
static fdType: any;
|
|
8
|
+
/**
|
|
9
|
+
* Fix slashes in a path
|
|
10
|
+
*
|
|
11
|
+
* @static
|
|
12
|
+
* @param {string} pathName - The path to fix
|
|
13
|
+
* @returns {string} The fixed path
|
|
14
|
+
*/
|
|
15
|
+
static fixSlashes(pathName: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Convert a path to a URI
|
|
18
|
+
*
|
|
19
|
+
* @static
|
|
20
|
+
* @param {string} pathName - The path to convert
|
|
21
|
+
* @returns {string} The URI
|
|
22
|
+
*/
|
|
23
|
+
static pathToUrl(pathName: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Convert a URI to a path
|
|
26
|
+
*
|
|
27
|
+
* @static
|
|
28
|
+
* @param {string} pathName - The URI to convert
|
|
29
|
+
* @returns {string} The path
|
|
30
|
+
*/
|
|
31
|
+
static urlToPath(pathName: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Computes the relative path from one file or directory to another.
|
|
34
|
+
*
|
|
35
|
+
* If the target is outside the source (i.e., the relative path starts with
|
|
36
|
+
* ".."), returns the absolute path to the target instead.
|
|
37
|
+
*
|
|
38
|
+
* @static
|
|
39
|
+
* @param {FileObject|DirectoryObject} from - The source file or directory object
|
|
40
|
+
* @param {FileObject|DirectoryObject} to - The target file or directory object
|
|
41
|
+
* @returns {string} The relative path from `from` to `to`, or the absolute path if not reachable
|
|
42
|
+
*/
|
|
43
|
+
static relativeOrAbsolutePath(from: FileObject | DirectoryObject, to: FileObject | DirectoryObject): string;
|
|
44
|
+
/**
|
|
45
|
+
* Merge two paths by finding overlapping segments and combining them
|
|
46
|
+
* efficiently
|
|
47
|
+
*
|
|
48
|
+
* @static
|
|
49
|
+
* @param {string} path1 - The first path
|
|
50
|
+
* @param {string} path2 - The second path to merge with the first
|
|
51
|
+
* @param {string} [sep] - The path separator to use (defaults to system separator)
|
|
52
|
+
* @returns {string} The merged path
|
|
53
|
+
*/
|
|
54
|
+
static mergeOverlappingPaths(path1: string, path2: string, sep?: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Resolve a path relative to another path using various strategies
|
|
57
|
+
* Handles absolute paths, relative navigation, and overlap-based merging
|
|
58
|
+
*
|
|
59
|
+
* @static
|
|
60
|
+
* @param {string} fromPath - The base path to resolve from
|
|
61
|
+
* @param {string} toPath - The target path to resolve
|
|
62
|
+
* @returns {string} The resolved path
|
|
63
|
+
*/
|
|
64
|
+
static resolvePath(fromPath: string, toPath: string): string;
|
|
65
|
+
/**
|
|
66
|
+
* Check if a candidate path is contained within a container path.
|
|
67
|
+
*
|
|
68
|
+
* @static
|
|
69
|
+
* @param {string} container - The container path to check against
|
|
70
|
+
* @param {string} candidate - The candidate path that might be contained
|
|
71
|
+
* @returns {boolean} True if candidate is within container, false otherwise
|
|
72
|
+
* @throws {Sass} If container is not a non-empty string
|
|
73
|
+
* @throws {Sass} If candidate is not a non-empty string
|
|
74
|
+
* @example
|
|
75
|
+
* FS.pathContains("/home/user", "/home/user/docs") // true
|
|
76
|
+
* FS.pathContains("/home/user", "/home/other") // false
|
|
77
|
+
*/
|
|
78
|
+
static pathContains(container: string, candidate: string): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Convert an absolute path to a relative path by finding overlapping segments.
|
|
81
|
+
* Returns the relative portion of the 'to' path after the last occurrence
|
|
82
|
+
* of the final segment from the 'from' path.
|
|
83
|
+
*
|
|
84
|
+
* @static
|
|
85
|
+
* @param {string} from - The base path to calculate relative from
|
|
86
|
+
* @param {string} to - The target path to make relative
|
|
87
|
+
* @param {string} [sep=path.sep] - The path separator to use (defaults to system separator)
|
|
88
|
+
* @returns {string|null} The relative path, empty string if paths are identical, or null if no overlap found
|
|
89
|
+
* @example
|
|
90
|
+
* FS.toRelativePath("/projects/toolkit", "/projects/toolkit/src") // "src"
|
|
91
|
+
* FS.toRelativePath("/home/user", "/home/user") // ""
|
|
92
|
+
* FS.toRelativePath("/projects/app", "/other/path") // null
|
|
93
|
+
*/
|
|
94
|
+
static toRelativePath(from: string, to: string, sep?: string): string | null;
|
|
95
|
+
/**
|
|
96
|
+
* Find the common root path between two paths by identifying overlapping segments.
|
|
97
|
+
* Returns the portion of 'from' that matches up to the overlap point in 'to'.
|
|
98
|
+
*
|
|
99
|
+
* @static
|
|
100
|
+
* @param {string} from - The first path to compare
|
|
101
|
+
* @param {string} to - The second path to find common root with
|
|
102
|
+
* @param {string} [sep=path.sep] - The path separator to use (defaults to system separator)
|
|
103
|
+
* @returns {string|null} The common root path, the original path if identical, or null if no overlap found
|
|
104
|
+
* @throws {Sass} If from is not a non-empty string
|
|
105
|
+
* @throws {Sass} If to is not a non-empty string
|
|
106
|
+
* @example
|
|
107
|
+
* FS.getCommonRootPath("/projects/toolkit/src", "/projects/toolkit/tests") // "/projects/toolkit"
|
|
108
|
+
* FS.getCommonRootPath("/home/user", "/home/user") // "/home/user"
|
|
109
|
+
* FS.getCommonRootPath("/projects/app", "/other/path") // null
|
|
110
|
+
*/
|
|
111
|
+
static getCommonRootPath(from: string, to: string, sep?: string): string | null;
|
|
112
|
+
/**
|
|
113
|
+
* @typedef {object} PathParts
|
|
114
|
+
* @property {string} base - The file name with extension
|
|
115
|
+
* @property {string} dir - The directory path
|
|
116
|
+
* @property {string} ext - The file extension (including dot)
|
|
117
|
+
*/
|
|
118
|
+
/**
|
|
119
|
+
* Deconstruct a file or directory name into parts.
|
|
120
|
+
*
|
|
121
|
+
* @static
|
|
122
|
+
* @param {string} pathName - The file/directory name to deconstruct
|
|
123
|
+
* @returns {PathParts} The filename parts
|
|
124
|
+
* @throws {Sass} If not a string of more than 1 character
|
|
125
|
+
*/
|
|
126
|
+
static pathParts(pathName: string): {
|
|
127
|
+
/**
|
|
128
|
+
* - The file name with extension
|
|
129
|
+
*/
|
|
130
|
+
base: string;
|
|
131
|
+
/**
|
|
132
|
+
* - The directory path
|
|
133
|
+
*/
|
|
134
|
+
dir: string;
|
|
135
|
+
/**
|
|
136
|
+
* - The file extension (including dot)
|
|
137
|
+
*/
|
|
138
|
+
ext: string;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Convert a virtual capped path to its real filesystem path.
|
|
142
|
+
* For capped objects, resolves the virtual path relative to the cap's real path.
|
|
143
|
+
* For uncapped objects, returns the path unchanged.
|
|
144
|
+
*
|
|
145
|
+
* @static
|
|
146
|
+
* @param {FileObject|DirectoryObject} fileOrDirectoryObject - The file or directory object to convert
|
|
147
|
+
* @returns {string} The real filesystem path
|
|
148
|
+
* @throws {Sass} If parameter is not a FileObject or DirectoryObject
|
|
149
|
+
* @example
|
|
150
|
+
* const temp = new TempDirectoryObject("myapp")
|
|
151
|
+
* const file = temp.getFile("/config.json")
|
|
152
|
+
* FS.virtualToRealPath(file) // "/tmp/myapp-ABC123/config.json"
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* const regular = new FileObject("/home/user/file.txt")
|
|
156
|
+
* FS.virtualToRealPath(regular) // "/home/user/file.txt"
|
|
157
|
+
*/
|
|
158
|
+
static virtualToRealPath(fileOrDirectoryObject: FileObject | DirectoryObject): string;
|
|
159
|
+
/**
|
|
160
|
+
* Convert an absolute path to a relative format by removing the root component.
|
|
161
|
+
* By default, keeps a leading separator (making it "absolute-like relative").
|
|
162
|
+
* Use forceActuallyRelative to get a truly relative path without leading separator.
|
|
163
|
+
*
|
|
164
|
+
* @static
|
|
165
|
+
* @param {string} pathToCheck - The path to convert (returned unchanged if already relative)
|
|
166
|
+
* @param {boolean} [forceActuallyRelative=false] - If true, removes leading separator for truly relative path
|
|
167
|
+
* @returns {string} The relative path (with or without leading separator based on forceActuallyRelative)
|
|
168
|
+
* @example
|
|
169
|
+
* FS.absoluteToRelative("/home/user/docs") // "/home/user/docs" (with leading /)
|
|
170
|
+
* FS.absoluteToRelative("/home/user/docs", true) // "home/user/docs" (truly relative)
|
|
171
|
+
* FS.absoluteToRelative("relative/path") // "relative/path" (unchanged)
|
|
172
|
+
*/
|
|
173
|
+
static absoluteToRelative(pathToCheck: string, forceActuallyRelative?: boolean): string;
|
|
174
|
+
/**
|
|
175
|
+
* Compute the relative path from another file or directory to this instance.
|
|
176
|
+
*
|
|
177
|
+
* If the target is outside the source (i.e., the relative path starts with ".."),
|
|
178
|
+
* returns the absolute path to this instance instead.
|
|
179
|
+
*
|
|
180
|
+
* @param {FileObject|DirectoryObject} fileOrDirectoryObject - The source file or directory object
|
|
181
|
+
* @returns {string} The relative path from the source to this instance, or the absolute path if not reachable
|
|
182
|
+
* @throws {Sass} If the parameter is not a FileObject or DirectoryObject
|
|
183
|
+
*/
|
|
184
|
+
relativeTo(fileOrDirectoryObject: FileObject | DirectoryObject): string;
|
|
185
|
+
}
|
|
186
|
+
export type FileObject = import("./FileObject.js").default;
|
|
187
|
+
export type DirectoryObject = import("./DirectoryObject.js").default;
|
|
188
|
+
//# sourceMappingURL=FileSystem.d.ts.map
|