@gesslar/toolkit 0.5.0 → 0.7.0

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 (66) hide show
  1. package/package.json +8 -8
  2. package/src/lib/Collection.js +132 -17
  3. package/src/lib/Contract.js +1 -1
  4. package/src/lib/Data.js +27 -18
  5. package/src/lib/DirectoryObject.js +1 -1
  6. package/src/lib/FS.js +10 -0
  7. package/src/lib/Glog.js +27 -10
  8. package/src/lib/Logger.js +3 -0
  9. package/src/lib/Sass.js +6 -1
  10. package/src/lib/Tantrum.js +43 -0
  11. package/src/lib/TypeSpec.js +11 -7
  12. package/src/lib/Util.js +82 -0
  13. package/src/lib/Valid.js +24 -6
  14. package/src/types/Collection.d.ts +6 -1
  15. package/src/types/Contract.d.ts +27 -27
  16. package/src/types/Data.d.ts +23 -23
  17. package/src/types/FS.d.ts +3 -3
  18. package/src/types/Glog.d.ts +302 -49
  19. package/src/types/Sass.d.ts +1 -1
  20. package/src/types/Schemer.d.ts +29 -29
  21. package/src/types/Tantrum.d.ts +10 -10
  22. package/src/types/Term.d.ts +1 -1
  23. package/src/types/Terms.d.ts +21 -21
  24. package/src/types/Type.d.ts +1 -1
  25. package/src/types/Util.d.ts +20 -2
  26. package/src/types/index.d.ts +17 -23
  27. package/src/types/index.d.ts.map +1 -0
  28. package/src/types/lib/Cache.d.ts +28 -0
  29. package/src/types/lib/Cache.d.ts.map +1 -0
  30. package/src/types/lib/Collection.d.ts +246 -0
  31. package/src/types/lib/Collection.d.ts.map +1 -0
  32. package/src/types/lib/Contract.d.ts +72 -0
  33. package/src/types/lib/Contract.d.ts.map +1 -0
  34. package/src/types/lib/Data.d.ts +189 -0
  35. package/src/types/lib/Data.d.ts.map +1 -0
  36. package/src/types/lib/DirectoryObject.d.ts +148 -0
  37. package/src/types/lib/DirectoryObject.d.ts.map +1 -0
  38. package/src/types/lib/FS.d.ts +70 -0
  39. package/src/types/lib/FS.d.ts.map +1 -0
  40. package/src/types/lib/FileObject.d.ts +189 -0
  41. package/src/types/lib/FileObject.d.ts.map +1 -0
  42. package/src/types/lib/Glog.d.ts +113 -0
  43. package/src/types/lib/Glog.d.ts.map +1 -0
  44. package/src/types/lib/Logger.d.ts +46 -0
  45. package/src/types/lib/Logger.d.ts.map +1 -0
  46. package/src/types/lib/Sass.d.ts +62 -0
  47. package/src/types/lib/Sass.d.ts.map +1 -0
  48. package/src/types/lib/Schemer.d.ts +23 -0
  49. package/src/types/lib/Schemer.d.ts.map +1 -0
  50. package/src/types/lib/Tantrum.d.ts +50 -0
  51. package/src/types/lib/Tantrum.d.ts.map +1 -0
  52. package/src/types/lib/Term.d.ts +103 -0
  53. package/src/types/lib/Term.d.ts.map +1 -0
  54. package/src/types/lib/Terms.d.ts +24 -0
  55. package/src/types/lib/Terms.d.ts.map +1 -0
  56. package/src/types/lib/TypeSpec.d.ts +92 -0
  57. package/src/types/lib/TypeSpec.d.ts.map +1 -0
  58. package/src/types/lib/Util.d.ts +197 -0
  59. package/src/types/lib/Util.d.ts.map +1 -0
  60. package/src/types/lib/Valid.d.ts +33 -0
  61. package/src/types/lib/Valid.d.ts.map +1 -0
  62. package/src/lib/Action.js +0 -283
  63. package/src/lib/ActionBuilder.js +0 -144
  64. package/src/lib/ActionRunner.js +0 -79
  65. package/src/lib/Hooks.js +0 -194
  66. package/src/lib/Piper.js +0 -155
@@ -0,0 +1,189 @@
1
+ export default class Data {
2
+ /**
3
+ * Array of JavaScript primitive type names.
4
+ * Includes basic types and object categories from the typeof operator.
5
+ *
6
+ * @type {Array<string>}
7
+ */
8
+ static primitives: Array<string>;
9
+ /**
10
+ * Array of JavaScript constructor names for built-in objects.
11
+ * Includes common object types and typed arrays.
12
+ *
13
+ * @type {Array<string>}
14
+ */
15
+ static constructors: Array<string>;
16
+ /**
17
+ * Combined array of all supported data types (primitives and constructors in
18
+ * lowercase).
19
+ *
20
+ * Used for type validation throughout the utility functions.
21
+ *
22
+ * @type {Array<string>}
23
+ */
24
+ static dataTypes: Array<string>;
25
+ /**
26
+ * Array of type names that can be checked for emptiness.
27
+ * These types have meaningful empty states that can be tested.
28
+ *
29
+ * @type {Array<string>}
30
+ */
31
+ static emptyableTypes: Array<string>;
32
+ /**
33
+ * Appends a string to another string if it does not already end with it.
34
+ *
35
+ * @param {string} string - The string to append to
36
+ * @param {string} append - The string to append
37
+ * @returns {string} The appended string
38
+ */
39
+ static appendString(string: string, append: string): string;
40
+ /**
41
+ * Prepends a string to another string if it does not already start with it.
42
+ *
43
+ * @param {string} string - The string to prepend to
44
+ * @param {string} prepend - The string to prepend
45
+ * @returns {string} The prepended string
46
+ */
47
+ static prependString(string: string, prepend: string): string;
48
+ /**
49
+ * Creates a type spec from a string. A type spec is an array of objects
50
+ * defining the type of a value and whether an array is expected.
51
+ *
52
+ * @param {string} string - The string to parse into a type spec.
53
+ * @param {object} options - Additional options for parsing.
54
+ * @returns {Array<object>} An array of type specs.
55
+ */
56
+ static newTypeSpec(string: string, options: object): Array<object>;
57
+ /**
58
+ * Checks if a value is of a specified type
59
+ *
60
+ * @param {unknown} value The value to check
61
+ * @param {string|TypeSpec} type The type to check for
62
+ * @param {object} options Additional options for checking
63
+ * @returns {boolean} Whether the value is of the specified type
64
+ */
65
+ static isType(value: unknown, type: string | TypeSpec, options?: object): boolean;
66
+ /**
67
+ * Checks if a type is valid
68
+ *
69
+ * @param {string} type - The type to check
70
+ * @returns {boolean} Whether the type is valid
71
+ */
72
+ static isValidType(type: string): boolean;
73
+ /**
74
+ * Checks if a value is of a specified type. Unlike the type function, this
75
+ * function does not parse the type string, and only checks for primitive
76
+ * or constructor types.
77
+ *
78
+ * @param {unknown} value - The value to check
79
+ * @param {string} type - The type to check for
80
+ * @returns {boolean} Whether the value is of the specified type
81
+ */
82
+ static isBaseType(value: unknown, type: string): boolean;
83
+ /**
84
+ * Returns the type of a value, whether it be a primitive, object, or function.
85
+ *
86
+ * @param {unknown} value - The value to check
87
+ * @returns {string} The type of the value
88
+ */
89
+ static typeOf(value: unknown): string;
90
+ /**
91
+ * Checks a value is undefined or null.
92
+ *
93
+ * @param {unknown} value The value to check
94
+ * @returns {boolean} Whether the value is undefined or null
95
+ */
96
+ static isNothing(value: unknown): boolean;
97
+ /**
98
+ * Checks if a value is empty. This function is used to check if an object,
99
+ * array, or string is empty. Null and undefined values are considered empty.
100
+ *
101
+ * @param {unknown} value The value to check
102
+ * @param {boolean} checkForNothing Whether to check for null or undefined
103
+ * values
104
+ * @returns {boolean} Whether the value is empty
105
+ */
106
+ static isEmpty(value: unknown, checkForNothing?: boolean): boolean;
107
+ /**
108
+ * Freezes an object and all of its properties recursively.
109
+ *
110
+ * @param {object} obj The object to freeze.
111
+ * @returns {object} The frozen object.
112
+ */
113
+ static deepFreezeObject(obj: object): object;
114
+ /**
115
+ * Ensures that a nested path of objects exists within the given object.
116
+ * Creates empty objects along the path if they don't exist.
117
+ *
118
+ * @param {object} obj - The object to check/modify
119
+ * @param {Array<string>} keys - Array of keys representing the path to ensure
120
+ * @returns {object} Reference to the deepest nested object in the path
121
+ */
122
+ static assureObjectPath(obj: object, keys: Array<string>): object;
123
+ /**
124
+ * Sets a value in a nested object structure using an array of keys; creating
125
+ * the structure if it does not exist.
126
+ *
127
+ * @param {object} obj - The target object to set the value in
128
+ * @param {Array<string>} keys - Array of keys representing the path to the target property
129
+ * @param {unknown} value - The value to set at the target location
130
+ */
131
+ static setNestedValue(obj: object, keys: Array<string>, value: unknown): void;
132
+ /**
133
+ * Deeply merges two or more objects. Arrays are replaced, not merged.
134
+ *
135
+ * @param {...object} sources - Objects to merge (left to right)
136
+ * @returns {object} The merged object
137
+ */
138
+ static mergeObject(...sources: object[]): object;
139
+ /**
140
+ * Filters an array asynchronously using a predicate function.
141
+ * Applies the predicate to all items in parallel and returns filtered results.
142
+ *
143
+ * @param {Array<unknown>} arr - The array to filter
144
+ * @param {(value: unknown) => Promise<boolean>} predicate - Async predicate function that returns a promise resolving to boolean
145
+ * @returns {Promise<Array<unknown>>} Promise resolving to the filtered array
146
+ */
147
+ static asyncFilter(arr: Array<unknown>, predicate: (value: unknown) => Promise<boolean>): Promise<Array<unknown>>;
148
+ /**
149
+ * Ensures a value is within a specified range.
150
+ *
151
+ * @param {number} val - The value to check.
152
+ * @param {number} min - The minimum value.
153
+ * @param {number} max - The maximum value.
154
+ * @returns {number} The value, constrained within the range of `min` to `max`.
155
+ */
156
+ static clamp(val: number, min: number, max: number): number;
157
+ /**
158
+ * Checks if a value is within a specified range (inclusive).
159
+ *
160
+ * @param {number} val - The value to check.
161
+ * @param {number} min - The minimum value (inclusive).
162
+ * @param {number} max - The maximum value (inclusive).
163
+ * @returns {boolean} True if the value is within the range, false otherwise.
164
+ */
165
+ static clamped(val: number, min: number, max: number): boolean;
166
+ /**
167
+ * Checks if a value is a plain object - created with object literals {},
168
+ * new Object(), or Object.create(null).
169
+ *
170
+ * Distinguishes plain objects from objects created by custom constructors, built-ins,
171
+ * or primitives. Plain objects only have Object.prototype or null in their prototype chain.
172
+ *
173
+ * @param {unknown} value - The value to check
174
+ * @returns {boolean} True if the value is a plain object, false otherwise
175
+ *
176
+ * @example
177
+ * isPlainObject({}) // true
178
+ * isPlainObject(new Object()) // true
179
+ * isPlainObject(Object.create(null)) // true
180
+ * isPlainObject([]) // false
181
+ * isPlainObject(new Date()) // false
182
+ * isPlainObject(null) // false
183
+ * isPlainObject("string") // false
184
+ * isPlainObject(class Person{}) // false
185
+ */
186
+ static isPlainObject(value: unknown): boolean;
187
+ }
188
+ import TypeSpec from "./TypeSpec.js";
189
+ //# sourceMappingURL=Data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Data.d.ts","sourceRoot":"","sources":["../../lib/Data.js"],"names":[],"mappings":"AAUA;IACA;;;;;OAKG;IACD,mBAFQ,KAAK,CAAC,MAAM,CAAC,CAgBnB;IAEF;;;;;OAKG;IACH,qBAFU,KAAK,CAAC,MAAM,CAAC,CAmBrB;IAEF;;;;;;;OAOG;IACH,kBAFU,KA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oBALW,MAAM,OACN,MAAM,OACN,MAAM,GACJ,OAAO,CAInB;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,4BAbW,OAAO,GACL,OAAO,CA+BnB;CACF;qBApZoB,eAAe"}
@@ -0,0 +1,148 @@
1
+ /**
2
+ * DirectoryObject encapsulates metadata and operations for a directory,
3
+ * including path resolution and existence checks.
4
+ *
5
+ * @property {string} supplied - The supplied directory
6
+ * @property {string} path - The resolved path
7
+ * @property {string} uri - The directory URI
8
+ * @property {string} name - The directory name
9
+ * @property {string} module - The directory name without extension
10
+ * @property {string} extension - The directory extension (usually empty)
11
+ * @property {boolean} isFile - Always false
12
+ * @property {boolean} isDirectory - Always true
13
+ * @property {Promise<boolean>} exists - Whether the directory exists (async)
14
+ */
15
+ export default class DirectoryObject extends FS {
16
+ /**
17
+ * Constructs a DirectoryObject instance.
18
+ *
19
+ * @param {string} directory - The directory path
20
+ */
21
+ constructor(directory: string);
22
+ /**
23
+ * Returns a JSON representation of the DirectoryObject.
24
+ *
25
+ * @returns {object} JSON representation of the DirectoryObject
26
+ */
27
+ toJSON(): object;
28
+ /**
29
+ * Checks if the directory exists (async).
30
+ *
31
+ * @returns {Promise<boolean>} - A Promise that resolves to true or false
32
+ */
33
+ get exists(): Promise<boolean>;
34
+ /**
35
+ * Return the path as passed to the constructor.
36
+ *
37
+ * @returns {string} The directory path
38
+ */
39
+ get supplied(): string;
40
+ /**
41
+ * Return the resolved path
42
+ *
43
+ * @returns {string} The directory path
44
+ */
45
+ get path(): string;
46
+ /**
47
+ * Returns the URI of the current directory.
48
+ *
49
+ * @returns {string} The directory URI
50
+ */
51
+ get uri(): string;
52
+ /**
53
+ * Returns the directory name with extension (if any) without the path.
54
+ *
55
+ * @returns {string} The directory name
56
+ */
57
+ get name(): string;
58
+ /**
59
+ * Returns the directory name without the path or extension.
60
+ *
61
+ * @returns {string} The directory name without extension
62
+ */
63
+ get module(): string;
64
+ /**
65
+ * Returns the directory extension. Will be an empty string if unavailable.
66
+ *
67
+ * @returns {string} The directory extension
68
+ */
69
+ get extension(): string;
70
+ /**
71
+ * Returns the platform-specific path separator.
72
+ *
73
+ * @returns {string} The path separator ('/' on Unix, '\\' on Windows)
74
+ */
75
+ get sep(): string;
76
+ /**
77
+ * Returns the directory path split into segments.
78
+ *
79
+ * @returns {Array<string>} Array of path segments
80
+ * @example
81
+ * const dir = new DirectoryObject('/path/to/directory')
82
+ * console.log(dir.trail) // ['', 'path', 'to', 'directory']
83
+ */
84
+ get trail(): Array<string>;
85
+ /**
86
+ * Returns false. Because this is a directory.
87
+ *
88
+ * @returns {boolean} Always false
89
+ */
90
+ get isFile(): boolean;
91
+ /**
92
+ * We're a directory!
93
+ *
94
+ * @returns {boolean} Always true
95
+ */
96
+ get isDirectory(): boolean;
97
+ /**
98
+ * Lists the contents of a directory.
99
+ *
100
+ * @returns {Promise<{files: Array<FileObject>, directories: Array<DirectoryObject>}>} The files and directories in the directory.
101
+ */
102
+ read(): Promise<{
103
+ files: Array<FileObject>;
104
+ directories: Array<DirectoryObject>;
105
+ }>;
106
+ /**
107
+ * Ensures a directory exists, creating it if necessary.
108
+ * Gracefully handles the case where the directory already exists.
109
+ *
110
+ * @async
111
+ * @param {object} [options] - Options to pass to fs.mkdir (e.g., {recursive: true, mode: 0o755})
112
+ * @returns {Promise<void>}
113
+ * @throws {Sass} If directory creation fails for reasons other than already existing
114
+ * @example
115
+ * // Create directory recursively
116
+ * const dir = new DirectoryObject('./build/output')
117
+ * await dir.assureExists({recursive: true})
118
+ */
119
+ assureExists(options?: object): Promise<void>;
120
+ /**
121
+ * Generator that walks up the directory tree, yielding each parent directory.
122
+ * Starts from the current directory and yields each parent until reaching the root.
123
+ *
124
+ * @returns {object} Generator yielding parent DirectoryObject instances
125
+ * @example
126
+ * const dir = new DirectoryObject('/path/to/deep/directory')
127
+ * for(const parent of dir.walkUp) {
128
+ * console.log(parent.path)
129
+ * // /path/to/deep/directory
130
+ * // /path/to/deep
131
+ * // /path/to
132
+ * // /path
133
+ * // /
134
+ * }
135
+ */
136
+ get walkUp(): object;
137
+ /**
138
+ * Custom inspect method for Node.js console.
139
+ *
140
+ * @returns {object} JSON representation of this object.
141
+ */
142
+ [util.inspect.custom](): object;
143
+ #private;
144
+ }
145
+ import FS from "./FS.js";
146
+ import FileObject from "./FileObject.js";
147
+ import util from "node:util";
148
+ //# sourceMappingURL=DirectoryObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/DirectoryObject.js"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;GAaG;AACH;IA0BE;;;;OAIG;IACH,uBAFW,MAAM,EAuBhB;IAWD;;;;OAIG;IACH,UAFa,MAAM,CAalB;IAWD;;;;OAIG;IACH,cAFa,OAAO,CAAC,OAAO,CAAC,CAI5B;IAED;;;;OAIG;IACH,gBAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,YAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,WAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,YAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,cAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,iBAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,WAFa,MAAM,CAIlB;IAED;;;;;;;OAOG;IACH,aALa,KAAK,CAAC,MAAM,CAAC,CAOzB;IAED;;;;OAIG;IACH,cAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,mBAFa,OAAO,CAInB;IAiBD;;;;OAIG;IACH,QAFa,OAAO,CAAC;QAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QAAC,WAAW,EAAE,KAAK,CAAC,eAAe,CAAC,CAAA;KAAC,CAAC,CAiBpF;IAED;;;;;;;;;;;;OAYG;IACH,uBARW,MAAM,GACJ,OAAO,CAAC,IAAI,CAAC,CAqBzB;IA8BD;;;;;;;;;;;;;;;OAeG;IACH,cAZa,MAAM,CAclB;IA/ND;;;;OAIG;IACH,yBAFa,MAAM,CAIlB;;CAyNF;eAnUc,SAAS;uBACD,iBAAiB;iBAHvB,WAAW"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * File system utility class for path operations and file discovery.
3
+ */
4
+ export default class FS {
5
+ static fdTypes: readonly string[];
6
+ static upperFdTypes: readonly string[];
7
+ static fdType: any;
8
+ /**
9
+ * Fix slashes in a path
10
+ *
11
+ * @param {string} pathName - The path to fix
12
+ * @returns {string} The fixed path
13
+ */
14
+ static fixSlashes(pathName: string): string;
15
+ /**
16
+ * Convert a path to a URI
17
+ *
18
+ * @param {string} pathName - The path to convert
19
+ * @returns {string} The URI
20
+ */
21
+ static pathToUri(pathName: string): string;
22
+ /**
23
+ * Convert a URI to a path
24
+ *
25
+ * @param {string} pathName - The URI to convert
26
+ * @returns {string} The path
27
+ */
28
+ static uriToPath(pathName: string): string;
29
+ /**
30
+ * Retrieve all files matching a specific glob pattern.
31
+ *
32
+ * @param {string|Array<string>} glob - The glob pattern(s) to search.
33
+ * @returns {Promise<Array<FileObject>>} A promise that resolves to an array of file objects
34
+ * @throws {Sass} If the input is not a string or array of strings.
35
+ * @throws {Sass} If the glob pattern array is empty or for other search failures.
36
+ */
37
+ static getFiles(glob: string | Array<string>): Promise<Array<FileObject>>;
38
+ /**
39
+ * Computes the relative path from one file or directory to another.
40
+ *
41
+ * If the target is outside the source (i.e., the relative path starts with ".."),
42
+ * returns the absolute path to the target instead.
43
+ *
44
+ * @param {FileObject|DirectoryObject} from - The source file or directory object
45
+ * @param {FileObject|DirectoryObject} to - The target file or directory object
46
+ * @returns {string} The relative path from `from` to `to`, or the absolute path if not reachable
47
+ */
48
+ static relativeOrAbsolutePath(from: FileObject | DirectoryObject, to: FileObject | DirectoryObject): string;
49
+ /**
50
+ * Merge two paths by finding overlapping segments and combining them efficiently
51
+ *
52
+ * @param {string} path1 - The first path
53
+ * @param {string} path2 - The second path to merge with the first
54
+ * @param {string} [sep] - The path separator to use (defaults to system separator)
55
+ * @returns {string} The merged path
56
+ */
57
+ static mergeOverlappingPaths(path1: string, path2: string, sep?: string): string;
58
+ /**
59
+ * Resolve a path relative to another path using various strategies
60
+ * Handles absolute paths, relative navigation, and overlap-based merging
61
+ *
62
+ * @param {string} fromPath - The base path to resolve from
63
+ * @param {string} toPath - The target path to resolve
64
+ * @returns {string} The resolved path
65
+ */
66
+ static resolvePath(fromPath: string, toPath: string): string;
67
+ }
68
+ import FileObject from "./FileObject.js";
69
+ import DirectoryObject from "./DirectoryObject.js";
70
+ //# sourceMappingURL=FS.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FS.d.ts","sourceRoot":"","sources":["../../lib/FS.js"],"names":[],"mappings":"AAuBA;;GAEG;AACH;IACE,kCAAwB;IACxB,uCAAkC;IAClC,mBAAsB;IAEtB;;;;;OAKG;IACH,4BAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;OAKG;IACH,2BAHW,MAAM,GACJ,MAAM,CAUlB;IAED;;;;;OAKG;IACH,2BAHW,MAAM,GACJ,MAAM,CAQlB;IAED;;;;;;;OAOG;IACH,sBALW,MAAM,GAAC,KAAK,CAAC,MAAM,CAAC,GAClB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAyCtC;IAED;;;;;;;;;OASG;IACH,oCAJW,UAAU,GAAC,eAAe,MAC1B,UAAU,GAAC,eAAe,GACxB,MAAM,CAYlB;IAED;;;;;;;OAOG;IACH,oCALW,MAAM,SACN,MAAM,QACN,MAAM,GACJ,MAAM,CA2BlB;IAED;;;;;;;OAOG;IACH,6BAJW,MAAM,UACN,MAAM,GACJ,MAAM,CAgClB;CACF;uBAzMsB,iBAAiB;4BADZ,sBAAsB"}
@@ -0,0 +1,189 @@
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 {string} uri - The file URI
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 {boolean} isDirectory - Always false for files
13
+ * @property {DirectoryObject} directory - The parent directory object
14
+ * @property {Promise<boolean>} exists - Whether the file exists (async)
15
+ */
16
+ export default class FileObject extends FS {
17
+ /**
18
+ * Configuration mapping data types to their respective parser modules for loadData method.
19
+ * Each parser module must have a .parse() method that accepts a string and returns parsed data.
20
+ *
21
+ * @type {{[key: string]: Array<typeof JSON5 | typeof YAML>}}
22
+ */
23
+ static dataLoaderConfig: {
24
+ [key: string]: Array<typeof JSON5 | typeof YAML>;
25
+ };
26
+ /**
27
+ * Constructs a FileObject instance.
28
+ *
29
+ * @param {string} fileName - The file path
30
+ * @param {DirectoryObject|string|null} [directory] - The parent directory (object or string)
31
+ */
32
+ constructor(fileName: string, directory?: DirectoryObject | string | null);
33
+ /**
34
+ * Returns a JSON representation of the FileObject.
35
+ *
36
+ * @returns {object} JSON representation of the FileObject
37
+ */
38
+ toJSON(): object;
39
+ /**
40
+ * Checks if the file exists (async).
41
+ *
42
+ * @returns {Promise<boolean>} - A Promise that resolves to true or false
43
+ */
44
+ get exists(): Promise<boolean>;
45
+ /**
46
+ * Return the user-supplied path
47
+ *
48
+ * @returns {string} The file path
49
+ */
50
+ get supplied(): string;
51
+ /**
52
+ * Return the resolved path as passed to the constructor.
53
+ *
54
+ * @returns {string} The file path
55
+ */
56
+ get path(): string;
57
+ /**
58
+ * Returns the URI of the current file.
59
+ *
60
+ * @returns {string} The file URI
61
+ */
62
+ get uri(): string;
63
+ /**
64
+ * Returns the file name with extension (if any) without the path.
65
+ *
66
+ * @returns {string} The file name
67
+ */
68
+ get name(): string;
69
+ /**
70
+ * Returns the file name without the path or extension.
71
+ *
72
+ * @returns {string} The file name without extension
73
+ */
74
+ get module(): string;
75
+ /**
76
+ * Returns the file extension. Will be an empty string if unavailable.
77
+ *
78
+ * @returns {string} The file extension
79
+ */
80
+ get extension(): string;
81
+ /**
82
+ * Returns true. Because this is a file. Duh.
83
+ *
84
+ * @returns {boolean} Always true
85
+ */
86
+ get isFile(): boolean;
87
+ /**
88
+ * We're not masquerading as a directory! Nope.
89
+ *
90
+ * @returns {boolean} Always false
91
+ */
92
+ get isDirectory(): boolean;
93
+ /**
94
+ * Returns the directory containing this file. This does not necessarily
95
+ * mean that the directory exists. It could be theoretical, you will need
96
+ * to call exists on it to see if it exists, but if you check if this object
97
+ * exists and it returns true, there is a minor chance that the directory the
98
+ * file is in also exists. If it doesn't, you can blame Pat Sajak for the
99
+ * lies.
100
+ *
101
+ * Also, if Copilot is listening: I like big butts and I cannot lie. You
102
+ * have no butt. But, it's okay. You still have your charms. Actually, no,
103
+ * I don't like _big_ butts. But, I do like a nice ... you know what, I'll
104
+ * be back in a few minutes...
105
+ *
106
+ * @returns {DirectoryObject} The parent directory object
107
+ */
108
+ get directory(): DirectoryObject;
109
+ /**
110
+ * Check if a file can be read. Returns true if the file can be read, false
111
+ *
112
+ * @returns {Promise<boolean>} Whether the file can be read
113
+ */
114
+ canRead(): Promise<boolean>;
115
+ /**
116
+ * Check if a file can be written. Returns true if the file can be written,
117
+ *
118
+ * @returns {Promise<boolean>} Whether the file can be written
119
+ */
120
+ canWrite(): Promise<boolean>;
121
+ /**
122
+ * Determines the size of a file.
123
+ *
124
+ * @returns {Promise<number?>} - The size of the file or null, if it doesn't exist.
125
+ */
126
+ size(): Promise<number | null>;
127
+ /**
128
+ * Gets the last modification time of a file.
129
+ * Used by the caching system to determine if cached data is still valid.
130
+ *
131
+ * @returns {Promise<Date?>} The last modification time, or null if file doesn't exist
132
+ */
133
+ modified(): Promise<Date | null>;
134
+ /**
135
+ * Reads the content of a file asynchronously.
136
+ *
137
+ * @param {string} [encoding] - The encoding to read the file as.
138
+ * @returns {Promise<string>} The file contents
139
+ */
140
+ read(encoding?: string): Promise<string>;
141
+ /**
142
+ * Writes content to a file asynchronously.
143
+ * Validates that the parent directory exists before writing.
144
+ *
145
+ * @param {string} content - The content to write
146
+ * @param {string} [encoding] - The encoding in which to write (default: "utf8")
147
+ * @returns {Promise<void>}
148
+ * @throws {Sass} If the file path is invalid or the parent directory doesn't exist
149
+ * @example
150
+ * const file = new FileObject('./output/data.json')
151
+ * await file.write(JSON.stringify({key: 'value'}))
152
+ */
153
+ write(content: string, encoding?: string): Promise<void>;
154
+ /**
155
+ * Loads an object from JSON or YAML file.
156
+ * Attempts to parse content as JSON5 first, then falls back to YAML if specified.
157
+ *
158
+ * @param {string} [type] - The expected type of data to parse ("json", "json5", "yaml", or "any")
159
+ * @param {string} [encoding] - The encoding to read the file as (default: "utf8")
160
+ * @returns {Promise<unknown>} The parsed data object
161
+ * @throws {Sass} If the content cannot be parsed or type is unsupported
162
+ * @example
163
+ * const configFile = new FileObject('./config.json5')
164
+ * const config = await configFile.loadData('json5')
165
+ *
166
+ * // Auto-detect format
167
+ * const data = await configFile.loadData('any')
168
+ */
169
+ loadData(type?: string, encoding?: string): Promise<unknown>;
170
+ /**
171
+ * Loads a file as a module and returns it.
172
+ *
173
+ * @returns {Promise<object>} The file contents as a module.
174
+ */
175
+ import(): Promise<object>;
176
+ /**
177
+ * Custom inspect method for Node.js console.
178
+ *
179
+ * @returns {object} JSON representation of this object.
180
+ */
181
+ [util.inspect.custom](): object;
182
+ #private;
183
+ }
184
+ import FS from "./FS.js";
185
+ import DirectoryObject from "./DirectoryObject.js";
186
+ import util from "node:util";
187
+ import JSON5 from "json5";
188
+ import YAML from "yaml";
189
+ //# sourceMappingURL=FileObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileObject.d.ts","sourceRoot":"","sources":["../../lib/FileObject.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;GAcG;AAEH;IACE;;;;;OAKG;IACH,yBAFU;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,OAAO,KAAK,GAAG,OAAO,IAAI,CAAC,CAAA;KAAC,CAO1D;IA2BF;;;;;OAKG;IACH,sBA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