forked from nexu-io/open-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaths.ts
More file actions
20 lines (18 loc) · 656 Bytes
/
Copy pathpaths.ts
File metadata and controls
20 lines (18 loc) · 656 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import path from 'node:path';
import { homedir } from 'node:os';
export function expandConfiguredEnv(configuredEnv: unknown): Record<string, string> {
const out: Record<string, string> = {};
if (!configuredEnv || typeof configuredEnv !== 'object') return out;
for (const [key, value] of Object.entries(configuredEnv)) {
if (typeof value !== 'string') continue;
out[key] = expandHomePath(value);
}
return out;
}
export function expandHomePath(value: string): string {
if (value === '~') return homedir();
if (value.startsWith('~/') || value.startsWith('~\\')) {
return path.join(homedir(), value.slice(2));
}
return value;
}