├── .editorconfig ├── .gitattributes ├── .github ├── funding.yml └── security.md ├── .gitignore ├── .travis.yml ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.github/funding.yml: -------------------------------------------------------------------------------- 1 | tidelift: npm/os-homedir 2 | -------------------------------------------------------------------------------- /.github/security.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '6' 5 | - '4' 6 | - '0.12' 7 | - '0.10' 8 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var os = require('os'); 3 | 4 | function homedir() { 5 | var env = process.env; 6 | var home = env.HOME; 7 | var user = env.LOGNAME || env.USER || env.LNAME || env.USERNAME; 8 | 9 | if (process.platform === 'win32') { 10 | return env.USERPROFILE || env.HOMEDRIVE + env.HOMEPATH || home || null; 11 | } 12 | 13 | if (process.platform === 'darwin') { 14 | return home || (user ? '/Users/' + user : null); 15 | } 16 | 17 | if (process.platform === 'linux') { 18 | return home || (process.getuid() === 0 ? '/root' : (user ? '/home/' + user : null)); 19 | } 20 | 21 | return home || null; 22 | } 23 | 24 | module.exports = typeof os.homedir === 'function' ? os.homedir : homedir; 25 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Sindre Sorhus (sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "os-homedir", 3 | "version": "1.0.2", 4 | "description": "Node.js 4 `os.homedir()` ponyfill", 5 | "license": "MIT", 6 | "repository": "sindresorhus/os-homedir", 7 | "author": { 8 | "name": "Sindre Sorhus", 9 | "email": "sindresorhus@gmail.com", 10 | "url": "sindresorhus.com" 11 | }, 12 | "engines": { 13 | "node": ">=0.10.0" 14 | }, 15 | "scripts": { 16 | "test": "xo && ava" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [ 22 | "builtin", 23 | "core", 24 | "ponyfill", 25 | "polyfill", 26 | "shim", 27 | "os", 28 | "homedir", 29 | "home", 30 | "dir", 31 | "directory", 32 | "folder", 33 | "user", 34 | "path" 35 | ], 36 | "devDependencies": { 37 | "ava": "*", 38 | "path-exists": "^2.0.0", 39 | "xo": "^0.16.0" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Deprecated 2 | 3 | This is not needed anymore. Use `require('os').homedir()` instead. 4 | 5 | --- 6 | 7 | 8 | # os-homedir [![Build Status](https://travis-ci.org/sindresorhus/os-homedir.svg?branch=master)](https://travis-ci.org/sindresorhus/os-homedir) 9 | 10 | > Node.js 4 [`os.homedir()`](https://nodejs.org/api/os.html#os_os_homedir) [ponyfill](https://ponyfill.com) 11 | 12 | 13 | ## Install 14 | 15 | ``` 16 | $ npm install --save os-homedir 17 | ``` 18 | 19 | 20 | ## Usage 21 | 22 | ```js 23 | const osHomedir = require('os-homedir'); 24 | 25 | console.log(osHomedir()); 26 | //=> '/Users/sindresorhus' 27 | ``` 28 | 29 | 30 | ## Related 31 | 32 | - [user-home](https://github.com/sindresorhus/user-home) - Same as this module but caches the result 33 | - [home-or-tmp](https://github.com/sindresorhus/home-or-tmp) - Get the user home directory with fallback to the system temp directory 34 | 35 | 36 | --- 37 | 38 |
39 | 40 | Get professional support for this package with a Tidelift subscription 41 | 42 |
43 | 44 | Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. 45 |
46 |
47 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import pathExists from 'path-exists'; 3 | import m from './'; 4 | 5 | test(t => { 6 | const homeDir = m(); 7 | t.true(homeDir.length > 0); 8 | t.true(pathExists.sync(homeDir)); 9 | }); 10 | --------------------------------------------------------------------------------