index.js 239 B

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