Skip to content

Commit

Permalink
code: use osenv.home()
Browse files Browse the repository at this point in the history
PR #77 improves the code to not hardcode the home directory to $HOME (which
is only a convention on Unix-like systems). This further improves that
by using `osenv` / `os-homedir`, which have more complete and robust
logic for finding a user's home directory on network shares and other
similar places.

Credit: @othiym23
PR-URL: #77
  • Loading branch information
othiym23 committed Dec 13, 2016
1 parent 20b4d56 commit 934943d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/nopt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var url = require("url")
, path = require("path")
, Stream = require("stream").Stream
, abbrev = require("abbrev")
, osenv = require("osenv")

module.exports = exports = nopt
exports.clean = clean
Expand Down Expand Up @@ -134,7 +135,7 @@ function validatePath (data, k, val) {

var isWin = process.platform === 'win32'
, homePattern = isWin ? /^~(\/|\\)/ : /^~\//
, home = isWin ? process.env.USERPROFILE : process.env.HOME
, home = osenv.home()

if (home && val.match(homePattern)) {
data[k] = path.resolve(home, val.substr(2))
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"bin": "./bin/nopt.js",
"license": "ISC",
"dependencies": {
"abbrev": "1"
"abbrev": "1",
"osenv": "^0.1.4"
},
"devDependencies": {
"tap": "^8.0.1"
Expand Down

0 comments on commit 934943d

Please # to comment.