os-user-dirs 2.6.0 → 2.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.
- package/README.md +30 -0
- package/index.d.ts +21 -0
- package/index.js +36 -5
- package/index.mjs +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,6 +99,27 @@ dirs.runtime //=> '/run/user/1000/my-app' (or null)
|
|
|
99
99
|
// With suffix option
|
|
100
100
|
const dirs2 = projectDirs("my-app", { suffix: "-nodejs" });
|
|
101
101
|
dirs2.config //=> '/home/user/.config/my-app-nodejs'
|
|
102
|
+
|
|
103
|
+
// With vendor option
|
|
104
|
+
const dirs3 = projectDirs("my-app", { vendor: "My Org" });
|
|
105
|
+
dirs3.config //=> '/home/user/.config/my-org/my-app' (Linux)
|
|
106
|
+
dirs3.config //=> '~/Library/Application Support/My Org/my-app' (macOS)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### Project user directories
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
import { projectUserDirs } from "os-user-dirs";
|
|
113
|
+
|
|
114
|
+
const dirs = projectUserDirs("my-app");
|
|
115
|
+
dirs.desktop //=> '/home/user/Desktop/my-app'
|
|
116
|
+
dirs.downloads //=> '/home/user/Downloads/my-app'
|
|
117
|
+
dirs.documents //=> '/home/user/Documents/my-app'
|
|
118
|
+
dirs.music //=> '/home/user/Music/my-app'
|
|
119
|
+
dirs.pictures //=> '/home/user/Pictures/my-app'
|
|
120
|
+
dirs.videos //=> '/home/user/Videos/my-app'
|
|
121
|
+
dirs.templates //=> '/home/user/Templates/my-app'
|
|
122
|
+
dirs.publicshare //=> '/home/user/Public/my-app'
|
|
102
123
|
```
|
|
103
124
|
|
|
104
125
|
### CommonJS
|
|
@@ -216,11 +237,20 @@ Returns an object with app-scoped directories for the given application name. Th
|
|
|
216
237
|
**Parameters:**
|
|
217
238
|
- `name` (string) — Application name
|
|
218
239
|
- `options.suffix` (string, optional) — Suffix appended to the app name (e.g. `"-nodejs"`)
|
|
240
|
+
- `options.vendor` (string, optional) — Vendor/organization name used as a parent directory. On Linux, the vendor name is normalized to lowercase with spaces replaced by hyphens (e.g. `"My Org"` → `"my-org"`). On macOS and Windows, it is used as-is.
|
|
219
241
|
|
|
220
242
|
**Returns:** `{ config, data, cache, state, log, temp, runtime }`
|
|
221
243
|
|
|
222
244
|
On Windows, each directory uses a subdirectory structure (e.g. `%LOCALAPPDATA%/my-app/Config`, `%LOCALAPPDATA%/my-app/Data`).
|
|
223
245
|
|
|
246
|
+
#### `projectUserDirs(name)`
|
|
247
|
+
Returns an object with project-scoped user directories. Each value is the corresponding user directory with the app name appended as a subdirectory.
|
|
248
|
+
|
|
249
|
+
**Parameters:**
|
|
250
|
+
- `name` (string) — Application name
|
|
251
|
+
|
|
252
|
+
**Returns:** `{ desktop, downloads, documents, music, pictures, videos, templates, publicshare }`
|
|
253
|
+
|
|
224
254
|
## License
|
|
225
255
|
|
|
226
256
|
MIT
|
package/index.d.ts
CHANGED
|
@@ -81,6 +81,8 @@ export function getBasePath(name: BaseDirName): string | null;
|
|
|
81
81
|
interface ProjectDirsOptions {
|
|
82
82
|
/** Suffix appended to the app name (default: ""). */
|
|
83
83
|
suffix?: string;
|
|
84
|
+
/** Vendor/organization name used as a parent directory (e.g. "My Org"). On Linux, normalized to lowercase with hyphens. */
|
|
85
|
+
vendor?: string;
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
interface ProjectDirsResult {
|
|
@@ -100,6 +102,24 @@ interface ProjectDirsResult {
|
|
|
100
102
|
*/
|
|
101
103
|
export function projectDirs(name: string, options?: ProjectDirsOptions): ProjectDirsResult;
|
|
102
104
|
|
|
105
|
+
interface ProjectUserDirsResult {
|
|
106
|
+
desktop: string;
|
|
107
|
+
downloads: string;
|
|
108
|
+
documents: string;
|
|
109
|
+
music: string;
|
|
110
|
+
pictures: string;
|
|
111
|
+
videos: string;
|
|
112
|
+
templates: string;
|
|
113
|
+
publicshare: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Returns project-scoped user directories for the given app name.
|
|
118
|
+
* Each value is the user directory path with the app name appended as a subdirectory.
|
|
119
|
+
* @param name - Application name used to derive directory paths
|
|
120
|
+
*/
|
|
121
|
+
export function projectUserDirs(name: string): ProjectUserDirsResult;
|
|
122
|
+
|
|
103
123
|
/**
|
|
104
124
|
* Returns the path to the user applications directory.
|
|
105
125
|
* Linux: `$XDG_DATA_HOME/applications` (default `~/.local/share/applications`)
|
|
@@ -144,6 +164,7 @@ declare const osUserDirs: typeof downloads & {
|
|
|
144
164
|
dataDirs: typeof dataDirs;
|
|
145
165
|
projectDirs: typeof projectDirs;
|
|
146
166
|
applicationsDir: typeof applicationsDir;
|
|
167
|
+
projectUserDirs: typeof projectUserDirs;
|
|
147
168
|
getXDGUserDir: typeof getXDGUserDir;
|
|
148
169
|
getXDGDownloadDir: typeof getXDGDownloadDir;
|
|
149
170
|
};
|
package/index.js
CHANGED
|
@@ -241,31 +241,48 @@ const PROJECT_DIR_WIN32_SUB = {
|
|
|
241
241
|
log: "Log",
|
|
242
242
|
};
|
|
243
243
|
|
|
244
|
+
function normalizeVendor(vendor, platform) {
|
|
245
|
+
if (platform === "linux") {
|
|
246
|
+
return vendor.toLowerCase().replace(/\s+/g, "-");
|
|
247
|
+
}
|
|
248
|
+
return vendor;
|
|
249
|
+
}
|
|
250
|
+
|
|
244
251
|
function projectDirs(name, options) {
|
|
245
252
|
if (!name || typeof name !== "string") {
|
|
246
253
|
throw new Error("projectDirs requires a non-empty string name");
|
|
247
254
|
}
|
|
248
255
|
|
|
249
256
|
const suffix = (options && options.suffix != null) ? options.suffix : "";
|
|
257
|
+
const vendor = (options && options.vendor) ? options.vendor : "";
|
|
250
258
|
const appName = name + suffix;
|
|
251
259
|
|
|
252
260
|
const homedir = os.homedir();
|
|
253
261
|
const platform = process.platform;
|
|
262
|
+
const vendorDir = vendor ? normalizeVendor(vendor, platform) : "";
|
|
263
|
+
|
|
264
|
+
function joinWithVendor() {
|
|
265
|
+
var segments = Array.prototype.slice.call(arguments);
|
|
266
|
+
if (vendorDir) {
|
|
267
|
+
segments.splice(1, 0, vendorDir);
|
|
268
|
+
}
|
|
269
|
+
return path.join.apply(path, segments);
|
|
270
|
+
}
|
|
254
271
|
|
|
255
272
|
function resolveProject(kind) {
|
|
256
273
|
if (kind === "temp") {
|
|
257
274
|
if (platform === "win32") {
|
|
258
275
|
const localAppData = process.env.LOCALAPPDATA || path.join(homedir, "AppData", "Local");
|
|
259
|
-
return
|
|
276
|
+
return joinWithVendor(localAppData, "Temp", appName);
|
|
260
277
|
}
|
|
261
|
-
return
|
|
278
|
+
return joinWithVendor(os.tmpdir(), appName);
|
|
262
279
|
}
|
|
263
280
|
|
|
264
281
|
if (kind === "runtime") {
|
|
265
282
|
if (platform === "linux") {
|
|
266
283
|
const envVal = process.env.XDG_RUNTIME_DIR;
|
|
267
284
|
if (envVal) {
|
|
268
|
-
return
|
|
285
|
+
return joinWithVendor(path.resolve(envVal), appName);
|
|
269
286
|
}
|
|
270
287
|
}
|
|
271
288
|
return null;
|
|
@@ -276,10 +293,10 @@ function projectDirs(name, options) {
|
|
|
276
293
|
|
|
277
294
|
const sub = PROJECT_DIR_WIN32_SUB[kind];
|
|
278
295
|
if (platform === "win32" && sub) {
|
|
279
|
-
return
|
|
296
|
+
return joinWithVendor(base, appName, sub);
|
|
280
297
|
}
|
|
281
298
|
|
|
282
|
-
return
|
|
299
|
+
return joinWithVendor(base, appName);
|
|
283
300
|
}
|
|
284
301
|
|
|
285
302
|
return {
|
|
@@ -293,6 +310,19 @@ function projectDirs(name, options) {
|
|
|
293
310
|
};
|
|
294
311
|
}
|
|
295
312
|
|
|
313
|
+
function projectUserDirs(name) {
|
|
314
|
+
if (!name || typeof name !== "string") {
|
|
315
|
+
throw new Error("projectUserDirs requires a non-empty string name");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
var result = {};
|
|
319
|
+
var keys = Object.keys(XDG_KEYS);
|
|
320
|
+
for (var i = 0; i < keys.length; i++) {
|
|
321
|
+
result[keys[i]] = path.join(resolve(keys[i]), name);
|
|
322
|
+
}
|
|
323
|
+
return result;
|
|
324
|
+
}
|
|
325
|
+
|
|
296
326
|
function applicationsDir() {
|
|
297
327
|
var homedir = os.homedir();
|
|
298
328
|
var platform = process.platform;
|
|
@@ -340,6 +370,7 @@ module.exports.configDirs = configDirs;
|
|
|
340
370
|
module.exports.dataDirs = dataDirs;
|
|
341
371
|
module.exports.projectDirs = projectDirs;
|
|
342
372
|
module.exports.applicationsDir = applicationsDir;
|
|
373
|
+
module.exports.projectUserDirs = projectUserDirs;
|
|
343
374
|
module.exports.getXDGUserDir = getXDGUserDir;
|
|
344
375
|
|
|
345
376
|
// Deprecated: kept for backward compatibility
|
package/index.mjs
CHANGED
|
@@ -23,5 +23,6 @@ export const configDirs = osUserDirs.configDirs;
|
|
|
23
23
|
export const dataDirs = osUserDirs.dataDirs;
|
|
24
24
|
export const projectDirs = osUserDirs.projectDirs;
|
|
25
25
|
export const applicationsDir = osUserDirs.applicationsDir;
|
|
26
|
+
export const projectUserDirs = osUserDirs.projectUserDirs;
|
|
26
27
|
export const getXDGUserDir = osUserDirs.getXDGUserDir;
|
|
27
28
|
export const getXDGDownloadDir = osUserDirs.getXDGDownloadDir;
|
package/package.json
CHANGED