all files / lib/helpers/ expand-home-dir.js

100% Statements 14/14
91.67% Branches 11/12
100% Functions 1/1
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29      26× 26×   26×       24× 18×                
'use strict';
 
var join = require('path').join;
 
function expandHomeDir(path) {
  var isWindows = process.platform == 'win32';
  var homeDir = process.env[isWindows ? 'USERPROFILE' : 'HOME'];
 
  if (path === '~') {
    if (!homeDir) {
      return false;
    }
    return homeDir;
  }
 
  if (!path || path[0] !== '~') {
    return path;
  }
 
  if (!homeDir) {
    return false;
  }
 
 
  return join(homeDir, path.slice(2));
}
 
module.exports = expandHomeDir;