pax_global_header00006660000000000000000000000064134335703520014517gustar00rootroot0000000000000052 comment=e7d6e97f4cd8db18cf695a121fc8dc2addaa754b homedir-polyfill-1.0.3/000077500000000000000000000000001343357035200147775ustar00rootroot00000000000000homedir-polyfill-1.0.3/.editorconfig000066400000000000000000000002531343357035200174540ustar00rootroot00000000000000root = true [*] indent_style = space indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false homedir-polyfill-1.0.3/.eslintrc.json000066400000000000000000000111251343357035200175730ustar00rootroot00000000000000{ "ecmaFeatures": { "modules": true, "experimentalObjectRestSpread": true }, "env": { "browser": false, "es6": true, "node": true, "mocha": true }, "globals": { "document": false, "navigator": false, "window": false }, "rules": { "accessor-pairs": 2, "arrow-spacing": [ 2, { "before": true, "after": true } ], "block-spacing": [ 2, "always" ], "brace-style": [ 2, "1tbs", { "allowSingleLine": true } ], "comma-dangle": [ 2, "never" ], "comma-spacing": [ 2, { "before": false, "after": true } ], "comma-style": [ 2, "last" ], "constructor-super": 2, "curly": [ 2, "multi-line" ], "dot-location": [ 2, "property" ], "eol-last": 2, "eqeqeq": [ 2, "allow-null" ], "generator-star-spacing": [ 2, { "before": true, "after": true } ], "handle-callback-err": [ 2, "^(err|error)$" ], "indent": [ 2, 2, { "SwitchCase": 1 } ], "key-spacing": [ 2, { "beforeColon": false, "afterColon": true } ], "keyword-spacing": [ 2, { "before": true, "after": true } ], "new-cap": [ 2, { "newIsCap": true, "capIsNew": false } ], "new-parens": 2, "no-array-constructor": 2, "no-caller": 2, "no-class-assign": 2, "no-cond-assign": 2, "no-const-assign": 2, "no-control-regex": 2, "no-debugger": 2, "no-delete-var": 2, "no-dupe-args": 2, "no-dupe-class-members": 2, "no-dupe-keys": 2, "no-duplicate-case": 2, "no-empty-character-class": 2, "no-eval": 2, "no-ex-assign": 2, "no-extend-native": 2, "no-extra-bind": 2, "no-extra-boolean-cast": 2, "no-extra-parens": [ 2, "functions" ], "no-fallthrough": 2, "no-floating-decimal": 2, "no-func-assign": 2, "no-implied-eval": 2, "no-inner-declarations": [ 2, "functions" ], "no-invalid-regexp": 2, "no-irregular-whitespace": 2, "no-iterator": 2, "no-label-var": 2, "no-labels": 2, "no-lone-blocks": 2, "no-mixed-spaces-and-tabs": 2, "no-multi-spaces": 2, "no-multi-str": 2, "no-multiple-empty-lines": [ 2, { "max": 1 } ], "no-native-reassign": 0, "no-negated-in-lhs": 2, "no-new": 2, "no-new-func": 2, "no-new-object": 2, "no-new-require": 2, "no-new-wrappers": 2, "no-obj-calls": 2, "no-octal": 2, "no-octal-escape": 2, "no-proto": 0, "no-redeclare": 2, "no-regex-spaces": 2, "no-return-assign": 2, "no-self-compare": 2, "no-sequences": 2, "no-shadow-restricted-names": 2, "no-spaced-func": 2, "no-sparse-arrays": 2, "no-this-before-super": 2, "no-throw-literal": 2, "no-trailing-spaces": 0, "no-undef": 2, "no-undef-init": 2, "no-unexpected-multiline": 2, "no-unneeded-ternary": [ 2, { "defaultAssignment": false } ], "no-unreachable": 2, "no-unused-vars": [ 2, { "vars": "all", "args": "none" } ], "no-useless-call": 0, "no-with": 2, "one-var": [ 0, { "initialized": "never" } ], "operator-linebreak": [ 0, "after", { "overrides": { "?": "before", ":": "before" } } ], "padded-blocks": [ 0, "never" ], "quotes": [ 2, "single", "avoid-escape" ], "radix": 2, "semi": [ 2, "always" ], "semi-spacing": [ 2, { "before": false, "after": true } ], "space-before-blocks": [ 2, "always" ], "space-before-function-paren": [ 2, "never" ], "space-in-parens": [ 2, "never" ], "space-infix-ops": 2, "space-unary-ops": [ 2, { "words": true, "nonwords": false } ], "spaced-comment": [ 0, "always", { "markers": [ "global", "globals", "eslint", "eslint-disable", "*package", "!", "," ] } ], "use-isnan": 2, "valid-typeof": 2, "wrap-iife": [ 2, "any" ], "yoda": [ 2, "never" ] } } homedir-polyfill-1.0.3/.gitattributes000066400000000000000000000000141343357035200176650ustar00rootroot00000000000000* text=auto homedir-polyfill-1.0.3/.gitignore000066400000000000000000000000251343357035200167640ustar00rootroot00000000000000node_modules coveragehomedir-polyfill-1.0.3/.travis.yml000066400000000000000000000001531343357035200171070ustar00rootroot00000000000000sudo: false language: node_js os: - linux - osx node_js: - "6" - "5" - "4" - "0.12" - "0.10" homedir-polyfill-1.0.3/.verb.md000066400000000000000000000015061343357035200163370ustar00rootroot00000000000000## Usage ```js var homedir = require('{%= name %}'); console.log(homedir()); //=> /Users/doowb ``` ## Reasoning This library is a polyfill for the [node.js os.homedir](https://nodejs.org/api/os.html#os_os_homedir) method found in modern versions of node.js. This implementation tries to follow the implementation found in `libuv` by finding the current user using the `process.geteuid()` method and the `/etc/passwd` file. This should usually work in a linux environment, but will also fallback to looking at user specific environment variables to build the user's home directory if neccessary. Since `/etc/passwd` is not available on windows platforms, this implementation will use environment variables to find the home directory. In modern versions of node.js, [os.homedir](https://nodejs.org/api/os.html#os_os_homedir) is used. homedir-polyfill-1.0.3/LICENSE000066400000000000000000000020711343357035200160040ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2016 Brian Woodward Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. homedir-polyfill-1.0.3/README.md000066400000000000000000000073751343357035200162720ustar00rootroot00000000000000# 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 Install with [npm](https://www.npmjs.com/): ```sh $ npm install --save homedir-polyfill ``` ## Usage ```js var homedir = require('homedir-polyfill'); console.log(homedir()); //=> /Users/doowb ``` ## Reasoning This library is a polyfill for the [node.js os.homedir](https://nodejs.org/api/os.html#os_os_homedir) method found in modern versions of node.js. This implementation tries to follow the implementation found in `libuv` by finding the current user using the `process.geteuid()` method and the `/etc/passwd` file. This should usually work in a linux environment, but will also fallback to looking at user specific environment variables to build the user's home directory if neccessary. Since `/etc/passwd` is not available on windows platforms, this implementation will use environment variables to find the home directory. In modern versions of node.js, [os.homedir](https://nodejs.org/api/os.html#os_os_homedir) is used. ## About
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 advice on opening issues, pull requests, and coding standards.
Running Tests 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 && npm test ```
Building docs _(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 -g verbose/verb#dev verb-generate-readme && verb ```
### 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 **Brian Woodward** * [GitHub Profile](https://github.com/doowb) * [Twitter Profile](https://twitter.com/doowb) * [LinkedIn Profile](https://linkedin.com/in/woodwardbrian) ### 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.8.0, on February 21, 2019._ homedir-polyfill-1.0.3/appveyor.yml000066400000000000000000000011211343357035200173620ustar00rootroot00000000000000# Test against this version of Node.js environment: matrix: # node.js - nodejs_version: "6.0" - nodejs_version: "5.0" - nodejs_version: "4.0" - nodejs_version: "0.12" - nodejs_version: "0.10" # Install scripts. (runs after repo cloning) install: # Get the latest stable version of Node.js or io.js - ps: Install-Product node $env:nodejs_version # install modules - npm install # Post-install test scripts. test_script: # Output useful info for debugging. - node --version - npm --version # run tests - npm test # Don't actually build. build: off homedir-polyfill-1.0.3/contributing.md000066400000000000000000000063411343357035200200340ustar00rootroot00000000000000# Contributing to homedir-polyfill First and foremost, thank you! We appreciate that you want to contribute to homedir-polyfill, your time is valuable, and your contributions mean a lot to us. **What does "contributing" mean?** Creating an issue is the simplest form of contributing to a project. But there are many ways to contribute, including the following: - Updating or correcting documentation - Feature requests - Bug reports If you'd like to learn more about contributing in general, the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) has a lot of useful information. **Showing support for homedir-polyfill** Please keep in mind that open source software is built by people like you, who spend their free time creating things the rest the community can use. Don't have time to contribute? No worries, here are some other ways to show your support for homedir-polyfill: - star the [project](https://github.com/doowb/homedir-polyfill) - tweet your support for homedir-polyfill ## Issues ### Before creating an issue Please try to determine if the issue is caused by an underlying library, and if so, create the issue there. Sometimes this is difficult to know. We only ask that you attempt to give a reasonable attempt to find out. Oftentimes the readme will have advice about where to go to create issues. Try to follow these guidelines - **Investigate the issue**: - **Check the readme** - oftentimes you will find notes about creating issues, and where to go depending on the type of issue. - Create the issue in the appropriate repository. ### Creating an issue Please be as descriptive as possible when creating an issue. Give us the information we need to successfully answer your question or address your issue by answering the following in your issue: - **version**: please note the version of homedir-polyfill are you using - **extensions, plugins, helpers, etc** (if applicable): please list any extensions you're using - **error messages**: please paste any error messages into the issue, or a [gist](https://gist.github.com/) ## Above and beyond Here are some tips for creating idiomatic issues. Taking just a little bit extra time will make your issue easier to read, easier to resolve, more likely to be found by others who have the same or similar issue in the future. - read the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) - take some time to learn basic markdown. This [markdown cheatsheet](https://gist.github.com/jonschlinkert/5854601) is super helpful, as is the GitHub guide to [basic markdown](https://help.github.com/articles/markdown-basics/). - Learn about [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown/). And if you want to really go above and beyond, read [mastering markdown](https://guides.github.com/features/mastering-markdown/). - use backticks to wrap code. This ensures that code will retain its format, making it much more readable to others - use syntax highlighting by adding the correct language name after the first "code fence" [node-glob]: https://github.com/isaacs/node-glob [micromatch]: https://github.com/jonschlinkert/micromatch [so]: http://stackoverflow.com/questions/tagged/homedir-polyfillhomedir-polyfill-1.0.3/index.js000066400000000000000000000002501343357035200164410ustar00rootroot00000000000000'use strict'; var os = require('os'); if (typeof os.homedir !== 'undefined') { module.exports = os.homedir; } else { module.exports = require('./polyfill.js'); } homedir-polyfill-1.0.3/package.json000066400000000000000000000022021343357035200172610ustar00rootroot00000000000000{ "name": "homedir-polyfill", "description": "Node.js os.homedir polyfill for older versions of node.js.", "version": "1.0.3", "homepage": "https://github.com/doowb/homedir-polyfill", "author": "Brian Woodward (https://github.com/doowb)", "repository": "doowb/homedir-polyfill", "bugs": { "url": "https://github.com/doowb/homedir-polyfill/issues" }, "license": "MIT", "files": [ "index.js", "polyfill.js", "LICENSE" ], "main": "index.js", "engines": { "node": ">=0.10.0" }, "scripts": { "test": "mocha" }, "devDependencies": { "gulp-format-md": "^0.1.11", "mocha": "^3.1.2" }, "keywords": [ "home", "homedir", "homedirectory", "os", "os-homedir", "polyfill", "userhome" ], "verb": { "toc": false, "layout": "default", "tasks": [ "readme" ], "plugins": [ "gulp-format-md" ], "lint": { "reflinks": true }, "related": { "list": [ "parse-passwd" ] }, "reflinks": [ "verb", "verb-generate-readme" ] }, "dependencies": { "parse-passwd": "^1.0.0" } } homedir-polyfill-1.0.3/polyfill.js000066400000000000000000000034241343357035200171720ustar00rootroot00000000000000'use strict'; 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; } 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 ''; } } module.exports = homedir; homedir-polyfill-1.0.3/test.js000066400000000000000000000054541343357035200163240ustar00rootroot00000000000000'use strict'; /** * These tests are version to ensure that the correct methods are run for different platforms * and different node versions. */ require('mocha'); var fs = require('fs'); var os = require('os'); var assert = require('assert'); var parse = require('parse-passwd'); var homedir = require('./'); var user = process.env.LOGNAME || process.env.USER || process.env.LNAME || process.env.USERNAME; describe('homedir-polyfill', function() { it('should export a function', function() { assert.equal(typeof homedir, 'function'); if (typeof os.homedir === 'function') { assert.equal(homedir, os.homedir); } }); it('should return the HOME path', function() { if (process.env.HOME) { var expected = typeof os.homedir === 'function' ? os.homedir() : process.env.HOME; assert.equal(homedir(), expected); } }); if (process.platform === 'win32') { it('should use USERPROFILE', function() { process.env.USERPROFILE = 'C:\\Users\\doowb'; var expected = typeof os.homedir === 'function' ? os.homedir() : process.env.USERPROFILE; assert.equal(homedir(), expected); }); it('should fallback to HOMEDRIVE and HOMEPATH when USERPROFILE is not set', function() { delete process.env.USERPROFILE; process.env.HOMEDRIVE = 'C:'; process.env.HOMEPATH = '\\Users\\doowb'; var expected = typeof os.homedir === 'function' ? os.homedir() : process.env.HOMEDRIVE + process.env.HOMEPATH; assert.equal(homedir(), expected); }); it('should fallback to HOME when HOMEDRIVE, HOMEPATH and USERPROFILE are not set', function() { delete process.env.USERPROFILE; delete process.env.HOMEDRIVE; delete process.env.HOMEPATH; process.env.HOME = 'C:\\Users\\doowb'; var expected = typeof os.homedir === 'function' ? os.homedir() : process.env.HOME; assert.equal(homedir(), expected); }); } if (process.platform === 'darwin') { it('should use "/Users/" + username if HOME is not set', function() { delete process.env.HOME; var expected = typeof os.homedir === 'function' ? os.homedir() : '/Users/' + user; assert.equal(homedir(), expected); }); } if (process.platform === 'linux') { it('should lookup the user\'s path from `/etc/passwd` if HOME is not set', function() { var uid = typeof process.geteuid === 'function' ? process.geteuid() : process.getuid(); delete process.env.HOME; var users = parse(fs.readFileSync('/etc/passwd', 'utf8')); var home; for (var i = 0; i < users.length; i++) { if (users[i].uid === uid) { home = users[i].homedir; break; } } var expected = typeof os.homedir === 'function' ? os.homedir() : (home || '/home/' + user); assert.equal(homedir(), expected); }); } });