├── .editorconfig ├── .gitattributes ├── .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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '6' 4 | - '4' 5 | - '0.12' 6 | - '0.10' 7 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var os = require('os'); 3 | var username = require('username'); 4 | var osHomedir = require('os-homedir'); 5 | var passwdUser = require('passwd-user'); 6 | 7 | module.exports = os.userInfo || function () { 8 | if (process.platform === 'win32') { 9 | return { 10 | uid: -1, 11 | gid: -1, 12 | username: username.sync(), 13 | homedir: osHomedir(), 14 | shell: null 15 | }; 16 | } 17 | 18 | var res = passwdUser.sync(process.getuid()); 19 | 20 | return { 21 | uid: res.uid, 22 | gid: res.gid, 23 | username: res.username, 24 | homedir: res.homedir, 25 | shell: res.shell 26 | }; 27 | }; 28 | -------------------------------------------------------------------------------- /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": "user-info", 3 | "version": "2.0.0", 4 | "description": "Node.js `os.userInfo()` ponyfill", 5 | "license": "MIT", 6 | "repository": "sindresorhus/user-info", 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 | "userInfo", 23 | "os", 24 | "user", 25 | "info", 26 | "builtin", 27 | "core", 28 | "ponyfill", 29 | "polyfill", 30 | "shim", 31 | "passwd", 32 | "shell", 33 | "uid", 34 | "gid", 35 | "homedir", 36 | "username" 37 | ], 38 | "dependencies": { 39 | "os-homedir": "^1.0.1", 40 | "passwd-user": "^1.2.1", 41 | "username": "^1.0.1" 42 | }, 43 | "devDependencies": { 44 | "ava": "*", 45 | "xo": "*" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Deprecated 2 | 3 | This package is no longer relevant as Node.js 4 is unmaintained. 4 | 5 | --- 6 | 7 | # user-info [![Build Status](https://travis-ci.org/sindresorhus/user-info.svg?branch=master)](https://travis-ci.org/sindresorhus/user-info) 8 | 9 | > Node.js [`os.userInfo()`](https://nodejs.org/api/os.html#os_os_userinfo_options) [ponyfill](https://ponyfill.com) 10 | 11 | 12 | ## Install 13 | 14 | ``` 15 | $ npm install --save user-info 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```js 22 | const userInfo = require('user-info'); 23 | 24 | console.log(userInfo()); 25 | /* 26 | { 27 | uid: 501, 28 | gid: 20, 29 | username: 'sindresorhus', 30 | homedir: '/Users/sindresorhus', 31 | shell: '/bin/zsh' 32 | } 33 | */ 34 | ``` 35 | 36 | 37 | ## API 38 | 39 | See the [`os.userInfo()` docs](https://nodejs.org/api/os.html#os_os_userinfo_options). 40 | 41 | The `encoding` option is not supported. 42 | 43 | 44 | ## License 45 | 46 | MIT © [Sindre Sorhus](https://sindresorhus.com) 47 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import os from 'os'; 3 | import test from 'ava'; 4 | 5 | os.userInfo = null; 6 | 7 | const m = require('./'); 8 | 9 | test(t => { 10 | const pwd = m(); 11 | 12 | console.log(pwd); 13 | 14 | if (process.platform === 'win32') { 15 | t.is(pwd.uid, -1); 16 | t.is(pwd.gid, -1); 17 | t.is(pwd.shell, null); 18 | } else { 19 | t.is(typeof pwd.uid, 'number'); 20 | t.is(typeof pwd.gid, 'number'); 21 | t.true(pwd.shell.indexOf(path.sep) !== -1); 22 | } 23 | 24 | t.is(typeof pwd.username, 'string'); 25 | t.true(pwd.homedir.indexOf(path.sep) !== -1); 26 | }); 27 | --------------------------------------------------------------------------------