diff --git a/doctoc.js b/doctoc.js index 578dfa9..184d1b2 100755 --- a/doctoc.js +++ b/doctoc.js @@ -4,13 +4,14 @@ var path = require('path') , fs = require('fs') + , os = require('os') , minimist = require('minimist') , file = require('./lib/file') , transform = require('./lib/transform') , files; -function cleanPath(path) { - var homeExpanded = (path.indexOf('~') === 0) ? process.env.HOME + path.substr(1) : path; +function cleanPath(filepath) { + var homeExpanded = (filepath.indexOf('~') === 0) ? path.join(os.homedir(), filepath.substr(1)) : filepath; // Escape all spaces return homeExpanded.replace(/\s/g, '\\ ');