Socket
Socket
Sign inDemoInstall

homedir-polyfill

Package Overview
Dependencies
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.0.2

84

index.js
'use strict';
var os = require('os');
var fs = require('fs');
var parse = require('parse-passwd');
function homedir() {
// The following logic is from looking at logic used in the different platform
// versions of the uv_os_homedir function found in https://github.com/libuv/libuv
// This is the function used in modern versions of node.js
if (process.platform === 'win32') {
// check the USERPROFILE first
if (process.env.USERPROFILE) {
return process.env.USERPROFILE;
}
// check HOMEDRIVE and HOMEPATH
if (process.env.HOMEDRIVE && process.env.HOMEPATH) {
return process.env.HOMEDRIVE + process.env.HOMEPATH;
}
// fallback to HOME
if (process.env.HOME) {
return process.env.HOME;
}
return null;
}
// check HOME environment variable first
if (process.env.HOME) {
return process.env.HOME;
}
// on linux platforms (including OSX) find the current user and get their homedir from the /etc/passwd file
var passwd = tryReadFileSync('/etc/passwd');
var home = find(parse(passwd), getuid());
if (home) {
return home;
}
// fallback to using user environment variables
var user = process.env.LOGNAME || process.env.USER || process.env.LNAME || process.env.USERNAME;
if (!user) {
return null;
}
if (process.platform === 'darwin') {
return '/Users/' + user;
}
return '/home/' + user;
if (typeof os.homedir !== 'undefined') {
module.exports = os.homedir;
} else {
module.exports = require('./polyfill.js');
}
function find(arr, uid) {
var len = arr.length;
for (var i = 0; i < len; i++) {
if (+arr[i].uid === uid) {
return arr[i].homedir;
}
}
}
function getuid() {
if (typeof process.geteuid === 'function') {
return process.geteuid();
}
return process.getuid();
}
function tryReadFileSync(fp) {
try {
return fs.readFileSync(fp, 'utf8');
} catch (err) {
return '';
}
}
if (typeof os.homedir === 'undefined') {
module.exports = homedir;
} else {
module.exports = os.homedir;
}

2

package.json
{
"name": "homedir-polyfill",
"description": "Node.js os.homedir polyfill for older versions of node.js.",
"version": "1.0.1",
"version": "1.0.2",
"homepage": "https://github.com/doowb/homedir-polyfill",

@@ -6,0 +6,0 @@ "author": "Brian Woodward (https://github.com/doowb)",

@@ -1,5 +0,7 @@

# homedir-polyfill [![NPM version](https://img.shields.io/npm/v/homedir-polyfill.svg?style=flat)](https://www.npmjs.com/package/homedir-polyfill) [![NPM downloads](https://img.shields.io/npm/dm/homedir-polyfill.svg?style=flat)](https://npmjs.org/package/homedir-polyfill) [![Linux Build Status](https://img.shields.io/travis/doowb/homedir-polyfill.svg?style=flat&label=Travis)](https://travis-ci.org/doowb/homedir-polyfill) [![Windows Build Status](https://img.shields.io/appveyor/ci/doowb/homedir-polyfill.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/doowb/homedir-polyfill)
# homedir-polyfill [![NPM version](https://img.shields.io/npm/v/homedir-polyfill.svg?style=flat)](https://www.npmjs.com/package/homedir-polyfill) [![NPM monthly downloads](https://img.shields.io/npm/dm/homedir-polyfill.svg?style=flat)](https://npmjs.org/package/homedir-polyfill) [![NPM total downloads](https://img.shields.io/npm/dt/homedir-polyfill.svg?style=flat)](https://npmjs.org/package/homedir-polyfill) [![Linux Build Status](https://img.shields.io/travis/doowb/homedir-polyfill.svg?style=flat&label=Travis)](https://travis-ci.org/doowb/homedir-polyfill) [![Windows Build Status](https://img.shields.io/appveyor/ci/doowb/homedir-polyfill.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/doowb/homedir-polyfill)
> Node.js os.homedir polyfill for older versions of node.js.
Please consider following this project's author, [Brian Woodward](https://github.com/doowb), and consider starring the project to show your :heart: and support.
## Install

@@ -33,30 +35,48 @@

### Related projects
<details>
<summary><strong>Contributing</strong></summary>
[parse-passwd](https://www.npmjs.com/package/parse-passwd): Parse a passwd file into a list of users. | [homepage](https://github.com/doowb/parse-passwd "Parse a passwd file into a list of users.")
### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Please read the [contributing guide](contributing.md) for avice on opening issues, pull requests, and coding standards.
Please read the [contributing guide](contributing.md) for advice on opening issues, pull requests, and coding standards.
### Building docs
</details>
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
<details>
<summary><strong>Running Tests</strong></summary>
To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm install -g verb verb-generate-readme && verb
$ npm install && npm test
```
### Running tests
</details>
Install dev dependencies:
<details>
<summary><strong>Building docs</strong></summary>
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -d && npm test
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
</details>
### Related projects
You might also be interested in these projects:
[parse-passwd](https://www.npmjs.com/package/parse-passwd): Parse a passwd file into a list of users. | [homepage](https://github.com/doowb/parse-passwd "Parse a passwd file into a list of users.")
### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 19 | [doowb](https://github.com/doowb) |
| 2 | [martinheidegger](https://github.com/martinheidegger) |
### Author

@@ -66,12 +86,13 @@

* [github/doowb](https://github.com/doowb)
* [twitter/doowb](http://twitter.com/doowb)
* [GitHub Profile](https://github.com/doowb)
* [Twitter Profile](https://twitter.com/doowb)
* [LinkedIn Profile](https://linkedin.com/in/woodwardbrian)
### License
Copyright © 2016, [Brian Woodward](https://github.com/doowb).
Released under the [MIT license](LICENSE).
Copyright © 2016 - 2019, [Brian Woodward](https://github.com/doowb).
Released under the [MIT License](LICENSE).
***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on October 19, 2016._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on February 21, 2019._
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc