os-user-dirs 3.1.0 → 3.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
@@ -10,7 +10,7 @@
10
10
 
11
11
  > All-in-one OS directory paths — user directories, XDG base directories, and app-scoped project directories — with zero dependencies.
12
12
 
13
- - Node.js 20 or later
13
+ - Node.js 20+, Deno 2+, Bun 1+
14
14
 
15
15
  Replaces [`env-paths`](https://github.com/sindresorhus/env-paths), [`xdg-basedir`](https://github.com/sindresorhus/xdg-basedir), and [`platform-folders`](https://github.com/nicbarker/platform-folders) in a single package. CJS + ESM dual support, TypeScript included.
16
16
 
@@ -29,6 +29,7 @@ Replaces [`env-paths`](https://github.com/sindresorhus/env-paths), [`xdg-basedir
29
29
  | XDG search paths | **Yes** | - | **Yes** | - |
30
30
  | Project directories | **Yes** | **Yes** | - | - |
31
31
  | CJS + ESM | **Both** | ESM only (v3) | ESM only (v5) | CJS |
32
+ | Deno / Bun | **Yes** | - | - | - |
32
33
  | TypeScript | **Included** | Included | Included | - |
33
34
 
34
35
  ## Install
@@ -37,7 +38,7 @@ Replaces [`env-paths`](https://github.com/sindresorhus/env-paths), [`xdg-basedir
37
38
  $ npm install os-user-dirs
38
39
  ```
39
40
 
40
- Requires Node.js 20 or later. Works on Windows, macOS, and Linux.
41
+ Requires Node.js 20 or later. Works on Windows, macOS, and Linux. Also compatible with [Deno](https://deno.land/) and [Bun](https://bun.sh/).
41
42
 
42
43
  ## Quick Start
43
44
 
@@ -68,6 +69,25 @@ CommonJS is also supported:
68
69
  const { downloads, configDir, projectDirs } = require("os-user-dirs");
69
70
  ```
70
71
 
72
+ ### Deno
73
+
74
+ ```typescript
75
+ import { downloads, configDir } from "npm:os-user-dirs";
76
+
77
+ downloads(); //=> '/home/user/Downloads'
78
+ configDir(); //=> '/home/user/.config'
79
+ ```
80
+
81
+ ### Bun
82
+
83
+ ```javascript
84
+ import { downloads, configDir } from "os-user-dirs";
85
+ // or: const { downloads, configDir } = require("os-user-dirs");
86
+
87
+ downloads(); //=> '/home/user/Downloads'
88
+ configDir(); //=> '/home/user/.config'
89
+ ```
90
+
71
91
  ### TypeScript
72
92
 
73
93
  Full type definitions are included. `getPath()` accepts a union type for auto-completion:
@@ -167,6 +187,7 @@ Returns the path to the specified base directory. Valid names: `config`, `data`,
167
187
  | Get user's Downloads folder | `downloads()` |
168
188
  | Get user's Documents folder | `documents()` |
169
189
  | Get all app-scoped dirs at once | `projectDirs("my-app")` |
190
+ | Dump all directory paths | `getAllDirs()` |
170
191
  | Find system-wide config locations | `configDirs()` |
171
192
  | Ensure a directory exists | `ensureDir(path)` / `ensureDirSync(path)` |
172
193
  | Get user's home directory | `homeDir()` |
@@ -246,10 +267,44 @@ const dirs = projectUserDirs("my-app");
246
267
  dirs.downloads //=> '/home/user/Downloads/my-app'
247
268
  ```
248
269
 
270
+ ### Namespace Exports
271
+
272
+ For better organization, functions are also available via namespace objects:
273
+
274
+ ```javascript
275
+ import { user, base, project } from "os-user-dirs";
276
+
277
+ // User directories
278
+ user.downloads() //=> '/home/user/Downloads'
279
+ user.desktop() //=> '/home/user/Desktop'
280
+ user.homeDir() //=> '/home/user'
281
+
282
+ // XDG base directories
283
+ base.configDir() //=> '/home/user/.config'
284
+ base.dataDir() //=> '/home/user/.local/share'
285
+ base.configDirs() //=> ['/etc/xdg']
286
+
287
+ // Project directories
288
+ const dirs = project.dirs("my-app");
289
+ dirs.config //=> '/home/user/.config/my-app'
290
+
291
+ const userDirs = project.userDirs("my-app");
292
+ userDirs.downloads //=> '/home/user/Downloads/my-app'
293
+ ```
294
+
295
+ | Namespace | Functions |
296
+ |---|---|
297
+ | `user` | `desktop`, `downloads`, `documents`, `music`, `pictures`, `videos`, `templates`, `publicshare`, `homeDir`, `binDir`, `fontsDir`, `trashDir`, `applicationsDir` |
298
+ | `base` | `configDir`, `dataDir`, `cacheDir`, `stateDir`, `logDir`, `runtimeDir`, `configDirs`, `dataDirs` |
299
+ | `project` | `dirs` (= `projectDirs`), `userDirs` (= `projectUserDirs`) |
300
+
301
+ All flat exports remain available for backward compatibility.
302
+
249
303
  ### Utilities
250
304
 
251
305
  | Function | Description |
252
306
  |---|---|
307
+ | `getAllDirs()` | Returns all directory paths as a single object |
253
308
  | `ensureDirSync(dirPath)` | Creates directory recursively if needed (sync) |
254
309
  | `ensureDir(dirPath)` | Creates directory recursively if needed (async) |
255
310
  | `getXDGUserDir(key)` | Parse XDG user-dirs.dirs config |
@@ -271,6 +326,8 @@ getBasePath("unknown"); // Type error
271
326
  ## Integration guides
272
327
 
273
328
  - **[Electron Guide](docs/guide-electron.md)** — Using os-user-dirs in Electron apps: `app.getPath()` mapping, main/renderer process patterns, vendor-scoped directories
329
+ - **[Tauri Guide](docs/guide-tauri.md)** — Using os-user-dirs in Tauri apps: path API mapping, sidecar patterns, shared config with CLI companions
330
+ - **[VS Code Extension Guide](docs/guide-vscode-extension.md)** — Using os-user-dirs in VS Code extensions: `globalStorageUri` comparison, file export patterns, shared config with CLI tools
274
331
  - **[CLI Tools Guide](docs/guide-cli-tools.md)** — Using `projectDirs()` with commander, yargs, and oclif for config, cache, and log management
275
332
 
276
333
  ## Migration Guides
@@ -305,6 +362,14 @@ downloads(); // recommended: cross-platform Downloa
305
362
  getXDGUserDir("XDG_DOWNLOAD_DIR"); // direct replacement if you need XDG config parsing
306
363
  ```
307
364
 
365
+ ## Contributing
366
+
367
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, coding conventions, and pull request guidelines.
368
+
369
+ ## Security
370
+
371
+ See [SECURITY.md](SECURITY.md) for the security policy and vulnerability reporting instructions.
372
+
308
373
  ## License
309
374
 
310
375
  MIT
package/index.d.ts CHANGED
@@ -429,6 +429,110 @@ export function ensureDirSync(dirPath: string): string;
429
429
  */
430
430
  export function ensureDir(dirPath: string): Promise<string>;
431
431
 
432
+ interface GetAllDirsResult {
433
+ downloads: string;
434
+ desktop: string;
435
+ documents: string;
436
+ music: string;
437
+ pictures: string;
438
+ videos: string;
439
+ templates: string;
440
+ publicshare: string;
441
+ configDir: string;
442
+ dataDir: string;
443
+ cacheDir: string;
444
+ stateDir: string;
445
+ logDir: string;
446
+ runtimeDir: string | null;
447
+ fontsDir: string;
448
+ binDir: string | null;
449
+ applicationsDir: string;
450
+ trashDir: string | null;
451
+ homeDir: string;
452
+ }
453
+
454
+ /**
455
+ * Returns all directory paths as a single object.
456
+ * Useful for debugging, configuration dumps, or diagnostics.
457
+ * Does not include array-returning functions (`configDirs`, `dataDirs`)
458
+ * or functions requiring arguments (`projectDirs`, `projectUserDirs`).
459
+ * @example
460
+ * ```ts
461
+ * import { getAllDirs } from 'os-user-dirs';
462
+ * const dirs = getAllDirs();
463
+ * console.log(dirs.downloads); // '/home/user/Downloads'
464
+ * console.log(dirs.configDir); // '/home/user/.config'
465
+ * console.log(dirs.homeDir); // '/home/user'
466
+ * ```
467
+ */
468
+ export function getAllDirs(): GetAllDirsResult;
469
+
470
+ /**
471
+ * Namespace grouping user directory functions.
472
+ * Provides organized access to user-specific directory functions.
473
+ * @example
474
+ * ```ts
475
+ * import { user } from 'os-user-dirs';
476
+ * user.downloads(); // '/home/user/Downloads'
477
+ * user.desktop(); // '/home/user/Desktop'
478
+ * user.homeDir(); // '/home/user'
479
+ * ```
480
+ */
481
+ export const user: {
482
+ desktop: typeof desktop;
483
+ downloads: typeof downloads;
484
+ documents: typeof documents;
485
+ music: typeof music;
486
+ pictures: typeof pictures;
487
+ videos: typeof videos;
488
+ templates: typeof templates;
489
+ publicshare: typeof publicshare;
490
+ homeDir: typeof homeDir;
491
+ binDir: typeof binDir;
492
+ fontsDir: typeof fontsDir;
493
+ trashDir: typeof trashDir;
494
+ applicationsDir: typeof applicationsDir;
495
+ };
496
+
497
+ /**
498
+ * Namespace grouping XDG base directory functions.
499
+ * Provides organized access to base directory and search path functions.
500
+ * @example
501
+ * ```ts
502
+ * import { base } from 'os-user-dirs';
503
+ * base.configDir(); // '/home/user/.config'
504
+ * base.dataDir(); // '/home/user/.local/share'
505
+ * base.configDirs(); // ['/etc/xdg']
506
+ * ```
507
+ */
508
+ export const base: {
509
+ configDir: typeof configDir;
510
+ dataDir: typeof dataDir;
511
+ cacheDir: typeof cacheDir;
512
+ stateDir: typeof stateDir;
513
+ logDir: typeof logDir;
514
+ runtimeDir: typeof runtimeDir;
515
+ configDirs: typeof configDirs;
516
+ dataDirs: typeof dataDirs;
517
+ };
518
+
519
+ /**
520
+ * Namespace grouping project-scoped directory functions.
521
+ * Provides organized access to application-scoped directory functions.
522
+ * @example
523
+ * ```ts
524
+ * import { project } from 'os-user-dirs';
525
+ * const dirs = project.dirs('my-app');
526
+ * dirs.config; // '/home/user/.config/my-app'
527
+ * const userDirs = project.userDirs('my-app');
528
+ * userDirs.downloads; // '/home/user/Downloads/my-app'
529
+ * ```
530
+ */
531
+ export const project: {
532
+ dirs: typeof projectDirs;
533
+ userDirs: typeof projectUserDirs;
534
+ };
535
+
432
536
  declare const osUserDirs: typeof downloads & {
433
537
  downloads: typeof downloads;
434
538
  desktop: typeof desktop;
@@ -458,6 +562,10 @@ declare const osUserDirs: typeof downloads & {
458
562
  getXDGUserDir: typeof getXDGUserDir;
459
563
  ensureDirSync: typeof ensureDirSync;
460
564
  ensureDir: typeof ensureDir;
565
+ getAllDirs: typeof getAllDirs;
566
+ user: typeof user;
567
+ base: typeof base;
568
+ project: typeof project;
461
569
  };
462
570
 
463
571
  export default osUserDirs;
package/index.js CHANGED
@@ -374,6 +374,30 @@ function homeDir() {
374
374
  return os.homedir();
375
375
  }
376
376
 
377
+ function getAllDirs() {
378
+ return {
379
+ downloads: downloads(),
380
+ desktop: desktop(),
381
+ documents: documents(),
382
+ music: music(),
383
+ pictures: pictures(),
384
+ videos: videos(),
385
+ templates: templates(),
386
+ publicshare: publicshare(),
387
+ configDir: configDir(),
388
+ dataDir: dataDir(),
389
+ cacheDir: cacheDir(),
390
+ stateDir: stateDir(),
391
+ logDir: logDir(),
392
+ runtimeDir: runtimeDir(),
393
+ fontsDir: fontsDir(),
394
+ binDir: binDir(),
395
+ applicationsDir: applicationsDir(),
396
+ trashDir: trashDir(),
397
+ homeDir: homeDir(),
398
+ };
399
+ }
400
+
377
401
  function ensureDirSync(dirPath) {
378
402
  if (!dirPath || typeof dirPath !== "string") {
379
403
  throw new Error("ensureDirSync requires a non-empty string path");
@@ -391,6 +415,39 @@ function ensureDir(dirPath) {
391
415
  });
392
416
  }
393
417
 
418
+ // Namespace exports
419
+ const user = {
420
+ desktop: desktop,
421
+ downloads: downloads,
422
+ documents: documents,
423
+ music: music,
424
+ pictures: pictures,
425
+ videos: videos,
426
+ templates: templates,
427
+ publicshare: publicshare,
428
+ homeDir: homeDir,
429
+ binDir: binDir,
430
+ fontsDir: fontsDir,
431
+ trashDir: trashDir,
432
+ applicationsDir: applicationsDir,
433
+ };
434
+
435
+ const base = {
436
+ configDir: configDir,
437
+ dataDir: dataDir,
438
+ cacheDir: cacheDir,
439
+ stateDir: stateDir,
440
+ logDir: logDir,
441
+ runtimeDir: runtimeDir,
442
+ configDirs: configDirs,
443
+ dataDirs: dataDirs,
444
+ };
445
+
446
+ const project = {
447
+ dirs: projectDirs,
448
+ userDirs: projectUserDirs,
449
+ };
450
+
394
451
  // Backward compatibility: require("os-user-dirs")() returns Downloads path
395
452
  module.exports = downloads;
396
453
  module.exports.getPath = getPath;
@@ -421,3 +478,7 @@ module.exports.getXDGUserDir = getXDGUserDir;
421
478
  module.exports.ensureDirSync = ensureDirSync;
422
479
  module.exports.trashDir = trashDir;
423
480
  module.exports.ensureDir = ensureDir;
481
+ module.exports.getAllDirs = getAllDirs;
482
+ module.exports.user = user;
483
+ module.exports.base = base;
484
+ module.exports.project = project;
package/index.mjs CHANGED
@@ -29,3 +29,7 @@ export const getXDGUserDir = osUserDirs.getXDGUserDir;
29
29
  export const trashDir = osUserDirs.trashDir;
30
30
  export const ensureDirSync = osUserDirs.ensureDirSync;
31
31
  export const ensureDir = osUserDirs.ensureDir;
32
+ export const getAllDirs = osUserDirs.getAllDirs;
33
+ export const user = osUserDirs.user;
34
+ export const base = osUserDirs.base;
35
+ export const project = osUserDirs.project;
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "os-user-dirs",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Get OS-specific user directories and XDG base directories (config, data, cache, runtime) with zero dependencies.",
5
5
  "main": "index.js",
6
+ "type": "commonjs",
6
7
  "types": "index.d.ts",
7
8
  "exports": {
8
9
  ".": {