Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

utils-homedir

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

utils-homedir - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

35

lib/index.js

@@ -7,2 +7,3 @@ 'use strict';

isWindows = require( 'check-if-windows' ),
platform = require( 'utils-platform' ),
os = require( 'os' );

@@ -17,15 +18,33 @@

*
* @returns {String} directory
* @returns {String|Null} directory
*/
function homedir() {
if ( isFunction( os.homedir ) ) {
return os.homedir();
}
// Node < v4
var env = process.env,
home,
user;
if ( isWindows ) {
// https://github.com/libuv/libuv/blob/764877fd9e4ea67c0cbe27bf81b2b294ed33b0f5/src/win/util.c#L1170
return process.env[ 'USERPROFILE' ];
// https://en.wikipedia.org/wiki/Environment_variable#Windows
home = env[ 'USERPROFILE' ] || env[ 'HOMEDRIVE' ]+env[ 'HOMEPATH' ] || env[ 'HOME' ];
return ( home ) ? home : null;
}
// https://github.com/libuv/libuv/blob/9fbcca048181b927cfcdb5c6c49e5bdff173aad5/src/unix/core.c#L1030
return process.env[ 'HOME' ];
home = env[ 'HOME' ];
if ( home ) {
return home;
}
// Get the current user account (https://docs.python.org/2/library/getpass.html):
user = env[ 'LOGNAME' ] || env[ 'USER' ] || env[ 'LNAME' ] || env[ 'USERNAME' ];
// If on Mac OSX, use the Mac path convention (http://apple.stackexchange.com/questions/119230/what-is-standard-for-os-x-filesystem-e-g-opt-vs-usr)...
if ( platform === 'darwin' ) {
return ( user ) ? '/Users/'+user : null;
}
// Check if running as 'root' (https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard)...
if ( process.getuid() === 0 ) {
return '/root';
}
// If on Linux, use the Linux path convention (https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard)...
return ( user ) ? '/home/'+user : null;
} // end FUNCTION homedir()

@@ -36,2 +55,2 @@

module.exports = homedir;
module.exports = isFunction( os.homedir ) ? os.homedir : homedir;
{
"name": "utils-homedir",
"version": "1.0.1",
"version": "2.0.0",
"description": "Returns the current user's home directory.",

@@ -51,2 +51,3 @@ "author": {

"pkginfo": "^0.3.0",
"utils-platform": "^1.0.0",
"validate.io-function": "^1.0.2"

@@ -53,0 +54,0 @@ },

@@ -1,2 +0,2 @@

Home Directory
Home
===

@@ -27,6 +27,18 @@ [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][codecov-image]][codecov-url] [![Dependencies][dependencies-image]][dependencies-url]

var home = homedir();
// returns <dirpath>
// => e.g., /Users/<username>
```
If unable to locate a `home` directory, the module returns `null`.
``` javascript
var home = homedir();
// returns null
```
## Notes
* This module primarily checks various [environment variables](https://en.wikipedia.org/wiki/Environment_variable) to locate a `home` directory. Note that this approach has __security vulnerabilities__, as attackers can tamper with [environment variables](https://en.wikipedia.org/wiki/Environment_variable).
## Examples

@@ -72,2 +84,3 @@

$ homedir
# => e.g., /Users/<username>
```

@@ -74,0 +87,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc