Code coverage report for home/index.js

Statements: 92.31% (24 / 26)      Branches: 64.29% (9 / 14)      Functions: 100% (4 / 4)      Lines: 92.31% (24 / 26)      Ignored: none     

All files » home/ » index.js
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65    1   1       1   1 1       1     1 10       2   1       7         1 25         25 1       24   19       5       1 7 7 7 21     7    
'use strict';
 
module.exports = home;
 
var USER_HOME = process.platform == 'win32'
  ? process.env.HOMEPATH || process.env.USERPROFILE
  : process.env.HOME;
 
var node_path = require('path');
 
function home () {
  return USER_HOME;
}
 
 
var resolve = node_path.resolve;
 
// The enhanced `path.resolve`
home.resolve = function (/* [from,] */ to) {
  switch(arguments.length){
    case 0:
      return resolve();
    case 1:
      return resolve(resolve_home(to));
    case 2:
      return resolve(resolve_home(to), resolve_home(arguments[1]));
    default:
      // Actually, `node_path.resolve` has no `this` pointer,
      // however, we apply it to `node_path` 
      return resolve.apply(node_path, map_resolve(arguments));
  }
};
 
 
function resolve_home (path) {
  Iif (!path) {
    // Actually, it will lead to an TypeError of `path.resolve`
    return path;
  }
 
  if (path === '~') {
    return USER_HOME;
  }
 
  // I thought, nobody will use `'~\\path\\to'`, but only `'~/path/to'`
  if (!~path.indexOf('~/')) {
    // '~file'
    return path;
  }
 
  // '~/file' -> '/Users/xxx/file'
  return USER_HOME + path.slice(1);
}
 
 
function map_resolve (args) {
  var paths = [];
  var length = args.length;
  while(length --){
    paths[length] = resolve_home(args[length]);
  }
 
  return paths;
}