Skip to content

Latest commit

 

History

History
16 lines (12 loc) · 396 Bytes

untildify.md

File metadata and controls

16 lines (12 loc) · 396 Bytes
title tags
untildify
node,string,beginner

Converts a tilde path to an absolute path.

  • Use String.prototype.replace() with a regular expression and OS.homedir() to replace the ~ in the start of the path with the home directory.
const untildify = str => str.replace(/^~($|\/|\\)/, `${require('os').homedir()}$1`);
untildify('~/node'); // '/Users/aUser/node'