Files
30-seconds-of-code/snippets/untildify.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

499 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Convert to absolute path node,string lighthouse 2018-01-01T17:43:18+02:00 2020-10-22T20:24:44+03:00

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'