index.js 331 B

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