15 lines
363 B
TypeScript
Raw Normal View History

2026-01-12 21:40:22 +00:00
import os from "node:os";
import path from "node:path";
export function resolveUserPath(input: string): string {
const trimmed = input.trim();
2026-01-31 22:13:48 +09:00
if (!trimmed) {
return trimmed;
}
2026-01-12 21:40:22 +00:00
if (trimmed.startsWith("~")) {
const expanded = trimmed.replace(/^~(?=$|[\\/])/, os.homedir());
return path.resolve(expanded);
}
return path.resolve(trimmed);
}