untildify-commonjs
Version:
Convert a tilde path to an absolute path: `~/dev` → `/Users/john/dev`
11 lines (9 loc) • 347 B
JavaScript
//require os
const os = require('os');
const homeDirectory = os.homedir();
module.exports= function untildify (pathWithTilde) {
if (typeof pathWithTilde !== 'string') {
throw new TypeError(`Expected a string, got ${typeof pathWithTilde}`);
}
return homeDirectory ? pathWithTilde.replace(/^~(?=$|\/|\\)/, homeDirectory) : pathWithTilde;
}