index.js (331B)
1 'use strict'; 2 const os = require('os'); 3 4 const homeDirectory = os.homedir(); 5 6 module.exports = pathWithTilde => { 7 if (typeof pathWithTilde !== 'string') { 8 throw new TypeError(`Expected a string, got ${typeof pathWithTilde}`); 9 } 10 11 return homeDirectory ? pathWithTilde.replace(/^~(?=$|\/|\\)/, homeDirectory) : pathWithTilde; 12 };