Last active
November 18, 2022 18:04
-
-
Save nichoth/c32fe84e09ec5d38851401b97f36440d to your computer and use it in GitHub Desktop.
untildify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const os = require('os'); | |
const homeDirectory = os.homedir(); | |
module.exports = pathWithTilde => { | |
if (typeof pathWithTilde !== 'string') { | |
throw new TypeError(`Expected a string, got ${typeof pathWithTilde}`); | |
} | |
return homeDirectory ? pathWithTilde.replace(/^~(?=$|\/|\\)/, homeDirectory) : pathWithTilde; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment