Skip to content

Instantly share code, notes, and snippets.

@nichoth
Last active November 18, 2022 18:04
Show Gist options
  • Save nichoth/c32fe84e09ec5d38851401b97f36440d to your computer and use it in GitHub Desktop.
Save nichoth/c32fe84e09ec5d38851401b97f36440d to your computer and use it in GitHub Desktop.
untildify
'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