@gesslar/toolkit 2.0.0 → 2.2.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.
package/README.md CHANGED
@@ -31,7 +31,7 @@ Includes all browser functionality plus Node.js-specific modules for file I/O, l
31
31
  | Cache | Cache management for file I/O operations |
32
32
  | CappedDirectoryObject | Directory operations constrained to a specific tree |
33
33
  | Contract | Contract management and validation |
34
- | DirectoryObject | File system wrapper for directory operations |
34
+ | DirectoryObject | Directory metadata and operations including path resolution, existence checks, and traversal |
35
35
  | FileObject | File system wrapper for file operations |
36
36
  | FS | Base class for file system operations with static utilities |
37
37
  | Glog | Logging framework |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gesslar/toolkit",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "A collection of utilities for Node.js and browser environments.",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -28,14 +28,14 @@
28
28
  ],
29
29
  "sideEffects": false,
30
30
  "engines": {
31
- "node": ">=20"
31
+ "node": ">=22"
32
32
  },
33
33
  "scripts": {
34
34
  "types:build": "node -e \"require('fs').rmSync('src/types',{recursive:true,force:true});\" && tsc -p tsconfig.types.json",
35
35
  "prepublishOnly": "npm run types:build",
36
36
  "lint": "eslint src/",
37
37
  "lint:fix": "eslint src/ --fix",
38
- "submit": "npm publish --access public",
38
+ "submit": "npm publish --access public --//registry.npmjs.org/:_authToken=\"${NPM_ACCESS_TOKEN}\"",
39
39
  "update": "npx npm-check-updates -u && npm install",
40
40
  "test": "node --test tests/**/*.test.js",
41
41
  "pr": "gt submit --publish --restack --ai"
@@ -169,10 +169,10 @@ export default class CappedDirectoryObject extends DirectoryObject {
169
169
  * @throws {Sass} If the path contains traversal (..)
170
170
  * @example
171
171
  * const capped = new TempDirectoryObject("myapp")
172
- * const subDir = capped.addDirectory("data")
172
+ * const subDir = capped.getDirectory("data")
173
173
  * console.log(subDir.path) // "/tmp/myapp-ABC123/data"
174
174
  */
175
- addDirectory(newPath) {
175
+ getDirectory(newPath) {
176
176
  Valid.type(newPath, "String")
177
177
 
178
178
  // Prevent absolute paths
@@ -203,10 +203,10 @@ export default class CappedDirectoryObject extends DirectoryObject {
203
203
  * @throws {Sass} If the path contains traversal (..)
204
204
  * @example
205
205
  * const capped = new TempDirectoryObject("myapp")
206
- * const file = capped.addFile("config.json")
206
+ * const file = capped.getFile("config.json")
207
207
  * console.log(file.path) // "/tmp/myapp-ABC123/config.json"
208
208
  */
209
- addFile(filename) {
209
+ getFile(filename) {
210
210
  Valid.type(filename, "String")
211
211
 
212
212
  // Prevent absolute paths
@@ -4,7 +4,7 @@
4
4
  * resolution and existence checks.
5
5
  */
6
6
 
7
- import {mkdir, opendir, readdir, rmdir} from "node:fs/promises"
7
+ import {glob, mkdir, opendir, readdir, rmdir} from "node:fs/promises"
8
8
  import path from "node:path"
9
9
  import {URL} from "node:url"
10
10
  import util from "node:util"
@@ -16,17 +16,51 @@ import Sass from "./Sass.js"
16
16
 
17
17
  /**
18
18
  * DirectoryObject encapsulates metadata and operations for a directory,
19
- * including path resolution and existence checks.
19
+ * providing immutable path resolution, existence checks, and content enumeration.
20
20
  *
21
- * @property {string} supplied - The supplied directory
22
- * @property {string} path - The resolved path
23
- * @property {URL} url - The directory URL
24
- * @property {string} name - The directory name
25
- * @property {string} module - The directory name without extension
26
- * @property {string} extension - The directory extension (usually empty)
27
- * @property {boolean} isFile - Always false
21
+ * Features:
22
+ * - Immutable metadata (path, name, URL) sealed on construction
23
+ * - Async existence checking and directory creation
24
+ * - Pattern-based content filtering with glob support
25
+ * - Path traversal via walkUp generator
26
+ * - Intelligent path merging for subdirectories and files
27
+ * - Support for temporary directory management
28
+ *
29
+ * @property {string} supplied - The original directory path as supplied to constructor
30
+ * @property {string} path - The absolute resolved directory path
31
+ * @property {URL} url - The directory as a file:// URL
32
+ * @property {string} name - The directory name (basename)
33
+ * @property {string} module - The directory name without extension (same as name for directories)
34
+ * @property {string} extension - The directory extension (typically empty string)
35
+ * @property {string} sep - Platform-specific path separator ('/' or '\\')
36
+ * @property {Array<string>} trail - Path segments split by separator
37
+ * @property {boolean} temporary - Whether this is marked as a temporary directory
38
+ * @property {boolean} isFile - Always false (this is a directory)
28
39
  * @property {boolean} isDirectory - Always true
29
- * @property {Promise<boolean>} exists - Whether the directory exists (async)
40
+ * @property {Promise<boolean>} exists - Whether the directory exists (async getter)
41
+ * @property {Generator<DirectoryObject>} walkUp - Generator yielding parent directories up to root
42
+ *
43
+ * @example
44
+ * // Basic usage
45
+ * const dir = new DirectoryObject("/projects/myapp")
46
+ * console.log(dir.path) // "/projects/myapp"
47
+ * console.log(await dir.exists) // true/false
48
+ *
49
+ * @example
50
+ * // Read directory contents
51
+ * const {files, directories} = await dir.read()
52
+ * const {files: jsFiles} = await dir.read("*.js")
53
+ *
54
+ * @example
55
+ * // Path traversal
56
+ * for(const parent of dir.walkUp) {
57
+ * console.log(parent.path)
58
+ * }
59
+ *
60
+ * @example
61
+ * // Working with subdirectories and files
62
+ * const subDir = dir.getDirectory("src/lib")
63
+ * const file = dir.getFile("package.json")
30
64
  */
31
65
  export default class DirectoryObject extends FS {
32
66
  /**
@@ -289,12 +323,32 @@ export default class DirectoryObject extends FS {
289
323
  }
290
324
 
291
325
  /**
292
- * Lists the contents of a directory.
326
+ * Lists the contents of a directory, optionally filtered by a glob pattern.
293
327
  *
294
- * @returns {Promise<{files: Array<FileObject>, directories: Array<DirectoryObject>}>} The files and directories in the directory.
328
+ * @async
329
+ * @param {string} [pat=""] - Optional glob pattern to filter results (e.g., "*.txt", "test-*")
330
+ * @returns {Promise<{files: Array<FileObject>, directories: Array<DirectoryObject>}>} Object containing arrays of files and directories
331
+ * @example
332
+ * const dir = new DirectoryObject("./src")
333
+ * const {files, directories} = await dir.read()
334
+ * console.log(files) // All files in ./src
335
+ *
336
+ * @example
337
+ * // Filter for specific files
338
+ * const {files} = await dir.read("*.js")
339
+ * console.log(files) // Only .js files in ./src
295
340
  */
296
- async read() {
297
- const found = await readdir(this.url, {withFileTypes: true})
341
+ async read(pat="") {
342
+ const cwd = this.path, withFileTypes = true
343
+ const found = !pat
344
+ ? await readdir(this.url, {withFileTypes})
345
+ : await Array.fromAsync(
346
+ glob(pat, {
347
+ cwd,
348
+ withFileTypes,
349
+ exclude: candidate => candidate.parentPath !== cwd
350
+ })
351
+ )
298
352
 
299
353
  const files = found
300
354
  .filter(dirent => dirent.isFile())
@@ -443,17 +497,25 @@ export default class DirectoryObject extends FS {
443
497
  /**
444
498
  * Creates a new DirectoryObject by extending this directory's path.
445
499
  *
446
- * Uses overlapping path segment detection to intelligently combine paths.
447
- * Preserves the temporary flag from the current directory.
500
+ * Uses intelligent path merging that detects overlapping segments to avoid
501
+ * duplication (e.g., "/projects/toolkit" + "toolkit/src" = "/projects/toolkit/src").
502
+ * The temporary flag is preserved from the parent directory.
448
503
  *
449
- * @param {string} newPath - The path to append to this directory's path.
450
- * @returns {DirectoryObject} A new DirectoryObject with the extended path.
504
+ * @param {string} newPath - The subdirectory path to append (can be nested like "src/lib")
505
+ * @returns {DirectoryObject} A new DirectoryObject instance with the combined path
506
+ * @throws {Sass} If newPath is not a string
451
507
  * @example
452
508
  * const dir = new DirectoryObject("/projects/git/toolkit")
453
- * const subDir = dir.addDirectory("src/lib")
509
+ * const subDir = dir.getDirectory("src/lib")
454
510
  * console.log(subDir.path) // "/projects/git/toolkit/src/lib"
511
+ *
512
+ * @example
513
+ * // Handles overlapping segments intelligently
514
+ * const dir = new DirectoryObject("/projects/toolkit")
515
+ * const subDir = dir.getDirectory("toolkit/src")
516
+ * console.log(subDir.path) // "/projects/toolkit/src" (not /projects/toolkit/toolkit/src)
455
517
  */
456
- addDirectory(newPath) {
518
+ getDirectory(newPath) {
457
519
  Valid.type(newPath, "String")
458
520
 
459
521
  const thisPath = this.path
@@ -465,16 +527,24 @@ export default class DirectoryObject extends FS {
465
527
  /**
466
528
  * Creates a new FileObject by extending this directory's path.
467
529
  *
468
- * Uses overlapping path segment detection to intelligently combine paths.
530
+ * Uses intelligent path merging that detects overlapping segments to avoid
531
+ * duplication. The resulting FileObject can be used for reading, writing,
532
+ * and other file operations.
469
533
  *
470
- * @param {string} filename - The filename to append to this directory's path.
471
- * @returns {FileObject} A new FileObject with the extended path.
534
+ * @param {string} filename - The filename to append (can include subdirectories like "src/index.js")
535
+ * @returns {FileObject} A new FileObject instance with the combined path
536
+ * @throws {Sass} If filename is not a string
472
537
  * @example
473
538
  * const dir = new DirectoryObject("/projects/git/toolkit")
474
- * const file = dir.addFile("package.json")
539
+ * const file = dir.getFile("package.json")
475
540
  * console.log(file.path) // "/projects/git/toolkit/package.json"
541
+ *
542
+ * @example
543
+ * // Can include nested paths
544
+ * const file = dir.getFile("src/index.js")
545
+ * const data = await file.read()
476
546
  */
477
- addFile(filename) {
547
+ getFile(filename) {
478
548
  Valid.type(filename, "String")
479
549
 
480
550
  const thisPath = this.path
package/src/lib/FS.js CHANGED
@@ -153,9 +153,8 @@ export default class FS {
153
153
  const to = path2.split(sep).filter(Boolean)
154
154
 
155
155
  // If they're the same, just return path1
156
- if(to.length === from.length && from.every((f, i) => to[i] === f)) {
156
+ if(to.length === from.length && from.every((f, i) => to[i] === f))
157
157
  return path1
158
- }
159
158
 
160
159
  const overlapIndex = from.findLastIndex(curr => curr === to.at(0))
161
160
 
@@ -109,12 +109,12 @@ export default class TempDirectoryObject extends CappedDirectoryObject {
109
109
  * @throws {Sass} If the path contains traversal (..)
110
110
  * @example
111
111
  * const temp = new TempDirectoryObject("myapp")
112
- * const subDir = temp.addDirectory("data")
112
+ * const subDir = temp.getDirectory("data")
113
113
  * console.log(subDir.path) // "/tmp/myapp-ABC123/data"
114
114
  */
115
- addDirectory(newPath) {
116
- // Delegate to base class addDirectory() which will call TempDirectoryObject constructor
117
- return super.addDirectory(newPath)
115
+ getDirectory(newPath) {
116
+ // Delegate to base class getDirectory() which will call TempDirectoryObject constructor
117
+ return super.getDirectory(newPath)
118
118
  }
119
119
 
120
120
  /**
@@ -129,12 +129,12 @@ export default class TempDirectoryObject extends CappedDirectoryObject {
129
129
  * @throws {Sass} If the path contains traversal (..)
130
130
  * @example
131
131
  * const temp = new TempDirectoryObject("myapp")
132
- * const file = temp.addFile("config.json")
132
+ * const file = temp.getFile("config.json")
133
133
  * console.log(file.path) // "/tmp/myapp-ABC123/config.json"
134
134
  */
135
- addFile(filename) {
136
- // Delegate to base class addFile() which handles security checks
137
- return super.addFile(filename)
135
+ getFile(filename) {
136
+ // Delegate to base class getFile() which handles security checks
137
+ return super.getFile(filename)
138
138
  }
139
139
 
140
140
  /**
package/src/lib/Util.js CHANGED
@@ -1,7 +1,10 @@
1
1
  import {createHash} from "node:crypto"
2
2
  import {EventEmitter} from "node:events"
3
- import Sass from "./Sass.js"
4
3
  import {Util as BrowserUtil} from "../browser/index.js"
4
+ import Sass from "./Sass.js"
5
+ import process from "node:process"
6
+ import JSON5 from "json5"
7
+ import Valid from "./Valid.js"
5
8
 
6
9
  /**
7
10
  * Utility class providing common helper functions for string manipulation,
@@ -152,4 +155,45 @@ export default class Util extends BrowserUtil {
152
155
  )
153
156
  }
154
157
  }
158
+
159
+ /**
160
+ * Retrieves an environment variable and parses it as JSON5.
161
+ *
162
+ * This method fetches the value of the specified environment variable and
163
+ * attempts to parse it using JSON5. If the variable doesn't exist or is
164
+ * empty, the default value is returned. If parsing fails, an error is
165
+ * thrown.
166
+ *
167
+ * Example:
168
+ * // export MY_CONFIG='{"debug": true, timeout: 5000}'
169
+ * Util.getEnv("MY_CONFIG", {debug: false})
170
+ * → {debug: true, timeout: 5000}
171
+ *
172
+ * Edge cases:
173
+ * - If the environment variable doesn't exist, returns the default value
174
+ * - If the value is an empty string, returns the default value
175
+ * - If JSON5 parsing fails, throws a Sass error with context
176
+ *
177
+ * @param {string} ev - Name of the environment variable to retrieve
178
+ * @param {unknown} [def=undefined] - Default value if variable doesn't exist or is empty
179
+ * @returns {unknown} Parsed JSON5 value or default
180
+ * @throws {Sass} If JSON5 parsing fails
181
+ */
182
+ static getEnv(ev, def=undefined) {
183
+ Valid.type(ev, "String")
184
+
185
+ const value = process.env[ev]
186
+
187
+ if(!value)
188
+ return def
189
+
190
+ try {
191
+ return JSON5.parse(value)
192
+ } catch(error) {
193
+ throw Sass.new(
194
+ `Failed to parse environment variable '${ev}' as JSON5`,
195
+ error
196
+ )
197
+ }
198
+ }
155
199
  }
@@ -50,10 +50,10 @@ export default class CappedDirectoryObject extends DirectoryObject {
50
50
  * @throws {Sass} If the path contains traversal (..)
51
51
  * @example
52
52
  * const capped = new TempDirectoryObject("myapp")
53
- * const subDir = capped.addDirectory("data")
53
+ * const subDir = capped.getDirectory("data")
54
54
  * console.log(subDir.path) // "/tmp/myapp-ABC123/data"
55
55
  */
56
- addDirectory(newPath: string): CappedDirectoryObject;
56
+ getDirectory(newPath: string): CappedDirectoryObject;
57
57
  #private;
58
58
  }
59
59
  import DirectoryObject from "./DirectoryObject.js";
@@ -1,16 +1,50 @@
1
1
  /**
2
2
  * DirectoryObject encapsulates metadata and operations for a directory,
3
- * including path resolution and existence checks.
3
+ * providing immutable path resolution, existence checks, and content enumeration.
4
4
  *
5
- * @property {string} supplied - The supplied directory
6
- * @property {string} path - The resolved path
7
- * @property {URL} url - The directory URL
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
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
+ * - Support for temporary directory management
12
+ *
13
+ * @property {string} supplied - The original directory path as supplied to constructor
14
+ * @property {string} path - The absolute resolved directory path
15
+ * @property {URL} url - The directory as a file:// URL
16
+ * @property {string} name - The directory name (basename)
17
+ * @property {string} module - The directory name without extension (same as name for directories)
18
+ * @property {string} extension - The directory extension (typically empty string)
19
+ * @property {string} sep - Platform-specific path separator ('/' or '\\')
20
+ * @property {Array<string>} trail - Path segments split by separator
21
+ * @property {boolean} temporary - Whether this is marked as a temporary directory
22
+ * @property {boolean} isFile - Always false (this is a directory)
12
23
  * @property {boolean} isDirectory - Always true
13
- * @property {Promise<boolean>} exists - Whether the directory exists (async)
24
+ * @property {Promise<boolean>} exists - Whether the directory exists (async getter)
25
+ * @property {Generator<DirectoryObject>} walkUp - Generator yielding parent directories up to root
26
+ *
27
+ * @example
28
+ * // Basic usage
29
+ * const dir = new DirectoryObject("/projects/myapp")
30
+ * console.log(dir.path) // "/projects/myapp"
31
+ * console.log(await dir.exists) // true/false
32
+ *
33
+ * @example
34
+ * // Read directory contents
35
+ * const {files, directories} = await dir.read()
36
+ * const {files: jsFiles} = await dir.read("*.js")
37
+ *
38
+ * @example
39
+ * // Path traversal
40
+ * for(const parent of dir.walkUp) {
41
+ * console.log(parent.path)
42
+ * }
43
+ *
44
+ * @example
45
+ * // Working with subdirectories and files
46
+ * const subDir = dir.getDirectory("src/lib")
47
+ * const file = dir.getFile("package.json")
14
48
  */
15
49
  export default class DirectoryObject extends FS {
16
50
  [x: number]: () => object;
@@ -121,11 +155,22 @@ export default class DirectoryObject extends FS {
121
155
  */
122
156
  get isDirectory(): boolean;
123
157
  /**
124
- * Lists the contents of a directory.
158
+ * Lists the contents of a directory, optionally filtered by a glob pattern.
125
159
  *
126
- * @returns {Promise<{files: Array<FileObject>, directories: Array<DirectoryObject>}>} The files and directories in the directory.
160
+ * @async
161
+ * @param {string} [pat=""] - Optional glob pattern to filter results (e.g., "*.txt", "test-*")
162
+ * @returns {Promise<{files: Array<FileObject>, directories: Array<DirectoryObject>}>} Object containing arrays of files and directories
163
+ * @example
164
+ * const dir = new DirectoryObject("./src")
165
+ * const {files, directories} = await dir.read()
166
+ * console.log(files) // All files in ./src
167
+ *
168
+ * @example
169
+ * // Filter for specific files
170
+ * const {files} = await dir.read("*.js")
171
+ * console.log(files) // Only .js files in ./src
127
172
  */
128
- read(): Promise<{
173
+ read(pat?: string): Promise<{
129
174
  files: Array<FileObject>;
130
175
  directories: Array<DirectoryObject>;
131
176
  }>;
@@ -193,30 +238,46 @@ export default class DirectoryObject extends FS {
193
238
  /**
194
239
  * Creates a new DirectoryObject by extending this directory's path.
195
240
  *
196
- * Uses overlapping path segment detection to intelligently combine paths.
197
- * Preserves the temporary flag from the current directory.
241
+ * Uses intelligent path merging that detects overlapping segments to avoid
242
+ * duplication (e.g., "/projects/toolkit" + "toolkit/src" = "/projects/toolkit/src").
243
+ * The temporary flag is preserved from the parent directory.
198
244
  *
199
- * @param {string} newPath - The path to append to this directory's path.
200
- * @returns {DirectoryObject} A new DirectoryObject with the extended path.
245
+ * @param {string} newPath - The subdirectory path to append (can be nested like "src/lib")
246
+ * @returns {DirectoryObject} A new DirectoryObject instance with the combined path
247
+ * @throws {Sass} If newPath is not a string
201
248
  * @example
202
249
  * const dir = new DirectoryObject("/projects/git/toolkit")
203
- * const subDir = dir.addDirectory("src/lib")
250
+ * const subDir = dir.getDirectory("src/lib")
204
251
  * console.log(subDir.path) // "/projects/git/toolkit/src/lib"
252
+ *
253
+ * @example
254
+ * // Handles overlapping segments intelligently
255
+ * const dir = new DirectoryObject("/projects/toolkit")
256
+ * const subDir = dir.getDirectory("toolkit/src")
257
+ * console.log(subDir.path) // "/projects/toolkit/src" (not /projects/toolkit/toolkit/src)
205
258
  */
206
- addDirectory(newPath: string): DirectoryObject;
259
+ getDirectory(newPath: string): DirectoryObject;
207
260
  /**
208
261
  * Creates a new FileObject by extending this directory's path.
209
262
  *
210
- * Uses overlapping path segment detection to intelligently combine paths.
263
+ * Uses intelligent path merging that detects overlapping segments to avoid
264
+ * duplication. The resulting FileObject can be used for reading, writing,
265
+ * and other file operations.
211
266
  *
212
- * @param {string} filename - The filename to append to this directory's path.
213
- * @returns {FileObject} A new FileObject with the extended path.
267
+ * @param {string} filename - The filename to append (can include subdirectories like "src/index.js")
268
+ * @returns {FileObject} A new FileObject instance with the combined path
269
+ * @throws {Sass} If filename is not a string
214
270
  * @example
215
271
  * const dir = new DirectoryObject("/projects/git/toolkit")
216
- * const file = dir.addFile("package.json")
272
+ * const file = dir.getFile("package.json")
217
273
  * console.log(file.path) // "/projects/git/toolkit/package.json"
274
+ *
275
+ * @example
276
+ * // Can include nested paths
277
+ * const file = dir.getFile("src/index.js")
278
+ * const data = await file.read()
218
279
  */
219
- addFile(filename: string): FileObject;
280
+ getFile(filename: string): FileObject;
220
281
  #private;
221
282
  }
222
283
  import FS from "./FS.js";
@@ -1 +1 @@
1
- {"version":3,"file":"DirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/DirectoryObject.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;GAaG;AACH;uBA4Fe,MAAM;IAjEnB;;;;;OAKG;IACH,yCAFW,OAAO,EA6BjB;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,GAAG,CAIf;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,iBAFa,OAAO,CAInB;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,UATa,OAAO,CAAC,IAAI,CAAC,CA0BzB;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,CAkBpF;IAED;;;;;;;;;;;;OAYG;IACH,uBARW,MAAM,GACJ,OAAO,CAAC,IAAI,CAAC,CAqBzB;IA8BD;;;;;;;;;;;;;;;OAeG;IACH,cAZa,MAAM,CAclB;IAED;;;;;;;;;;;;;;OAcG;IACH,UARa,OAAO,CAAC,IAAI,CAAC,CAkBzB;IAED;;;;;OAKG;IACH,kBAHW,MAAM,GACJ,OAAO,CAAC,OAAO,CAAC,CAM5B;IAED;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,OAAO,CAAC,OAAO,CAAC,CAO5B;IAED;;;;;;;;;;;;OAYG;IACH,sBAPW,MAAM,GACJ,eAAe,CAa3B;IAED;;;;;;;;;;;OAWG;IACH,kBAPW,MAAM,GACJ,UAAU,CAatB;;CACF;eAxdc,SAAS;uBACD,iBAAiB"}
1
+ {"version":3,"file":"DirectoryObject.d.ts","sourceRoot":"","sources":["../../lib/DirectoryObject.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH;uBA4Fe,MAAM;IAjEnB;;;;;OAKG;IACH,yCAFW,OAAO,EA6BjB;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,GAAG,CAIf;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,iBAFa,OAAO,CAInB;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,UATa,OAAO,CAAC,IAAI,CAAC,CA0BzB;IAED;;;;OAIG;IACH,cAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,mBAFa,OAAO,CAInB;IAiBD;;;;;;;;;;;;;;;OAeG;IACH,WAZW,MAAM,GACJ,OAAO,CAAC;QAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QAAC,WAAW,EAAE,KAAK,CAAC,eAAe,CAAC,CAAA;KAAC,CAAC,CAoCpF;IAED;;;;;;;;;;;;OAYG;IACH,uBARW,MAAM,GACJ,OAAO,CAAC,IAAI,CAAC,CAqBzB;IA8BD;;;;;;;;;;;;;;;OAeG;IACH,cAZa,MAAM,CAclB;IAED;;;;;;;;;;;;;;OAcG;IACH,UARa,OAAO,CAAC,IAAI,CAAC,CAkBzB;IAED;;;;;OAKG;IACH,kBAHW,MAAM,GACJ,OAAO,CAAC,OAAO,CAAC,CAM5B;IAED;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,OAAO,CAAC,OAAO,CAAC,CAO5B;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,sBAdW,MAAM,GACJ,eAAe,CAoB3B;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,kBAbW,MAAM,GACJ,UAAU,CAmBtB;;CACF;eA9hBc,SAAS;uBACD,iBAAiB"}
@@ -1 +1 @@
1
- {"version":3,"file":"FS.d.ts","sourceRoot":"","sources":["../../lib/FS.js"],"names":[],"mappings":"AAwBA;;GAEG;AACH;IACE,kCAAwB;IACxB,uCAAkC;IAClC,mBAAsB;IAEtB;;;;;;OAMG;IACH,4BAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;OAMG;IACH,2BAHW,MAAM,GACJ,MAAM,CAUlB;IAED;;;;;;OAMG;IACH,2BAHW,MAAM,GACJ,MAAM,CAQlB;IAED;;;;;;;;OAQG;IACH,sBALW,MAAM,GAAC,KAAK,CAAC,MAAM,CAAC,GAClB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAmCtC;IAED;;;;;;;;;;OAUG;IACH,oCAJW,UAAU,GAAC,eAAe,MAC1B,UAAU,GAAC,eAAe,GACxB,MAAM,CAYlB;IAED;;;;;;;;OAQG;IACH,oCALW,MAAM,SACN,MAAM,QACN,MAAM,GACJ,MAAM,CA2BlB;IAED;;;;;;;;OAQG;IACH,6BAJW,MAAM,UACN,MAAM,GACJ,MAAM,CAgClB;CACF;yBAzMa,OAAO,iBAAiB,EAAE,OAAO;8BACjC,OAAO,sBAAsB,EAAE,OAAO"}
1
+ {"version":3,"file":"FS.d.ts","sourceRoot":"","sources":["../../lib/FS.js"],"names":[],"mappings":"AAwBA;;GAEG;AACH;IACE,kCAAwB;IACxB,uCAAkC;IAClC,mBAAsB;IAEtB;;;;;;OAMG;IACH,4BAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;OAMG;IACH,2BAHW,MAAM,GACJ,MAAM,CAUlB;IAED;;;;;;OAMG;IACH,2BAHW,MAAM,GACJ,MAAM,CAQlB;IAED;;;;;;;;OAQG;IACH,sBALW,MAAM,GAAC,KAAK,CAAC,MAAM,CAAC,GAClB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAmCtC;IAED;;;;;;;;;;OAUG;IACH,oCAJW,UAAU,GAAC,eAAe,MAC1B,UAAU,GAAC,eAAe,GACxB,MAAM,CAYlB;IAED;;;;;;;;OAQG;IACH,oCALW,MAAM,SACN,MAAM,QACN,MAAM,GACJ,MAAM,CA0BlB;IAED;;;;;;;;OAQG;IACH,6BAJW,MAAM,UACN,MAAM,GACJ,MAAM,CAgClB;CACF;yBAxMa,OAAO,iBAAiB,EAAE,OAAO;8BACjC,OAAO,sBAAsB,EAAE,OAAO"}
@@ -56,10 +56,10 @@ export default class TempDirectoryObject extends CappedDirectoryObject {
56
56
  * @throws {Sass} If the path contains traversal (..)
57
57
  * @example
58
58
  * const temp = new TempDirectoryObject("myapp")
59
- * const subDir = temp.addDirectory("data")
59
+ * const subDir = temp.getDirectory("data")
60
60
  * console.log(subDir.path) // "/tmp/myapp-ABC123/data"
61
61
  */
62
- addDirectory(newPath: string): TempDirectoryObject;
62
+ getDirectory(newPath: string): TempDirectoryObject;
63
63
  /**
64
64
  * Creates a new FileObject by extending this directory's path.
65
65
  *
@@ -72,10 +72,10 @@ export default class TempDirectoryObject extends CappedDirectoryObject {
72
72
  * @throws {Sass} If the path contains traversal (..)
73
73
  * @example
74
74
  * const temp = new TempDirectoryObject("myapp")
75
- * const file = temp.addFile("config.json")
75
+ * const file = temp.getFile("config.json")
76
76
  * console.log(file.path) // "/tmp/myapp-ABC123/config.json"
77
77
  */
78
- addFile(filename: string): FileObject;
78
+ getFile(filename: string): FileObject;
79
79
  #private;
80
80
  }
81
81
  import CappedDirectoryObject from "./CappedDirectoryObject.js";
@@ -71,6 +71,30 @@ export default class Util extends BrowserUtil {
71
71
  * @returns {Promise<void>} Resolves when all listeners have completed, but no grapes.
72
72
  */
73
73
  static asyncEmitQuack(emitter: object, event: string, ...args: unknown[]): Promise<void>;
74
+ /**
75
+ * Retrieves an environment variable and parses it as JSON5.
76
+ *
77
+ * This method fetches the value of the specified environment variable and
78
+ * attempts to parse it using JSON5. If the variable doesn't exist or is
79
+ * empty, the default value is returned. If parsing fails, an error is
80
+ * thrown.
81
+ *
82
+ * Example:
83
+ * // export MY_CONFIG='{"debug": true, timeout: 5000}'
84
+ * Util.getEnv("MY_CONFIG", {debug: false})
85
+ * → {debug: true, timeout: 5000}
86
+ *
87
+ * Edge cases:
88
+ * - If the environment variable doesn't exist, returns the default value
89
+ * - If the value is an empty string, returns the default value
90
+ * - If JSON5 parsing fails, throws a Sass error with context
91
+ *
92
+ * @param {string} ev - Name of the environment variable to retrieve
93
+ * @param {unknown} [def=undefined] - Default value if variable doesn't exist or is empty
94
+ * @returns {unknown} Parsed JSON5 value or default
95
+ * @throws {Sass} If JSON5 parsing fails
96
+ */
97
+ static getEnv(ev: string, def?: unknown): unknown;
74
98
  }
75
99
  import { Util as BrowserUtil } from "../browser/index.js";
76
100
  //# sourceMappingURL=Util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Util.d.ts","sourceRoot":"","sources":["../../lib/Util.js"],"names":[],"mappings":"AAKA;;;GAGG;AACH;IACE;;;;;OAKG;IACH,iBAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,mCAHW,MAAM,GACJ,KAAK,CAAC,MAAM,CAAC,CAazB;IAED;;;;;;;;OAQG;IACH,+CALW,MAAM,SACN,MAAM,WACH,OAAO,EAAA,GACR,OAAO,CAAC,IAAI,CAAC,CAmBzB;IAED;;;;;;;;;;;;OAYG;IACH,0BALW,YAAY,SACZ,MAAM,WACH,OAAO,EAAA,GACR,OAAO,CAAC,IAAI,CAAC,CAqBzB;IAED;;;;;;;;;;OAUG;IACH,+BALW,MAAM,SACN,MAAM,WACH,OAAO,EAAA,GACR,OAAO,CAAC,IAAI,CAAC,CAyBzB;CACF;oCAvJiC,qBAAqB"}
1
+ {"version":3,"file":"Util.d.ts","sourceRoot":"","sources":["../../lib/Util.js"],"names":[],"mappings":"AAQA;;;GAGG;AACH;IACE;;;;;OAKG;IACH,iBAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,mCAHW,MAAM,GACJ,KAAK,CAAC,MAAM,CAAC,CAazB;IAED;;;;;;;;OAQG;IACH,+CALW,MAAM,SACN,MAAM,WACH,OAAO,EAAA,GACR,OAAO,CAAC,IAAI,CAAC,CAmBzB;IAED;;;;;;;;;;;;OAYG;IACH,0BALW,YAAY,SACZ,MAAM,WACH,OAAO,EAAA,GACR,OAAO,CAAC,IAAI,CAAC,CAqBzB;IAED;;;;;;;;;;OAUG;IACH,+BALW,MAAM,SACN,MAAM,WACH,OAAO,EAAA,GACR,OAAO,CAAC,IAAI,CAAC,CAyBzB;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,kBALW,MAAM,QACN,OAAO,GACL,OAAO,CAmBnB;CACF;oCApMiC,qBAAqB"}