mirror of
https://fastgit.cc/github.com/hicccc77/WeFlow
synced 2026-04-20 21:01:15 +08:00
21 lines
438 B
TypeScript
21 lines
438 B
TypeScript
import { homedir } from 'os'
|
|
|
|
/**
|
|
* Expand "~" prefix to current user's home directory.
|
|
* Examples:
|
|
* - "~" => "/Users/alex"
|
|
* - "~/Library/..." => "/Users/alex/Library/..."
|
|
*/
|
|
export function expandHomePath(inputPath: string): string {
|
|
const raw = String(inputPath || '').trim()
|
|
if (!raw) return raw
|
|
|
|
if (raw === '~') return homedir()
|
|
if (/^~[\\/]/.test(raw)) {
|
|
return `${homedir()}${raw.slice(1)}`
|
|
}
|
|
|
|
return raw
|
|
}
|
|
|