Comparing version 3.0.0 to 4.0.0
26
index.js
@@ -6,4 +6,4 @@ 'use strict'; | ||
function getEnvVar() { | ||
const env = process.env; | ||
const getEnvVar = () => { | ||
const {env} = process; | ||
@@ -16,9 +16,7 @@ return env.SUDO_USER || | ||
env.USERNAME; | ||
} | ||
}; | ||
function cleanWinCmd(x) { | ||
return x.replace(/^.*\\/, ''); | ||
} | ||
const cleanWinCmd = x => x.replace(/^.*\\/, ''); | ||
function noop() {} | ||
const noop = () => {}; | ||
@@ -36,9 +34,7 @@ module.exports = mem(() => { | ||
if (process.platform === 'darwin' || process.platform === 'linux') { | ||
return execa('id', ['-un']).then(x => x.stdout).catch(noop); | ||
} else if (process.platform === 'win32') { | ||
if (process.platform === 'win32') { | ||
return execa('whoami').then(x => cleanWinCmd(x.stdout)).catch(noop); | ||
} | ||
return Promise.resolve(); | ||
return execa('id', ['-un']).then(x => x.stdout).catch(noop); | ||
}); | ||
@@ -58,8 +54,8 @@ | ||
try { | ||
if (process.platform === 'darwin' || process.platform === 'linux') { | ||
return execa.sync('id', ['-un']).stdout; | ||
} else if (process.platform === 'win32') { | ||
if (process.platform === 'win32') { | ||
return cleanWinCmd(execa.sync('whoami').stdout); | ||
} | ||
} catch (err) {} | ||
return execa.sync('id', ['-un']).stdout; | ||
} catch (_) {} | ||
}); |
{ | ||
"name": "username", | ||
"version": "3.0.0", | ||
"description": "Get the username of the current user", | ||
"license": "MIT", | ||
"repository": "sindresorhus/username", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"username", | ||
"user", | ||
"login", | ||
"name", | ||
"logname", | ||
"lname", | ||
"whoami", | ||
"shell", | ||
"env", | ||
"var", | ||
"environment", | ||
"variable" | ||
], | ||
"dependencies": { | ||
"execa": "^0.7.0", | ||
"mem": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
"name": "username", | ||
"version": "4.0.0", | ||
"description": "Get the username of the current user", | ||
"license": "MIT", | ||
"repository": "sindresorhus/username", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"username", | ||
"user", | ||
"login", | ||
"name", | ||
"logname", | ||
"lname", | ||
"whoami", | ||
"shell", | ||
"env", | ||
"var", | ||
"environment", | ||
"variable" | ||
], | ||
"dependencies": { | ||
"execa": "^0.11.0", | ||
"mem": "^3.0.1" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
} |
@@ -5,3 +5,5 @@ # username [![Build Status](https://travis-ci.org/sindresorhus/username.svg?branch=master)](https://travis-ci.org/sindresorhus/username) | ||
This module is meant for informational purposes, and not for secure identification. | ||
## Install | ||
@@ -19,6 +21,6 @@ | ||
username().then(username => { | ||
console.log(username); | ||
(async () => { | ||
console.log(await username()); | ||
//=> 'sindresorhus' | ||
}); | ||
})(); | ||
``` | ||
@@ -29,3 +31,3 @@ | ||
First tries to get the username from the `SUDO_USER` `LOGNAME` `USER` `LNAME` `USERNAME` environment variables. Then falls back to `$ id -un` on macOS / Linux and `$ whoami` on Windows, in the rare case none of the environment variables are set. The result is cached. | ||
It first tries to get the username from the `SUDO_USER` `LOGNAME` `USER` `LNAME` `USERNAME` environment variables. Then falls back to `$ id -un` on macOS / Linux and `$ whoami` on Windows, in the rare case none of the environment variables are set. The result is cached. | ||
@@ -32,0 +34,0 @@ ### username() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
49
1
3867
43
+ Addedcross-spawn@6.0.5(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexeca@0.11.0(transitive)
+ Addedget-stream@4.1.0(transitive)
+ Addedmem@3.0.1(transitive)
+ Addednice-try@1.0.5(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedp-is-promise@1.1.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedcross-spawn@5.1.0(transitive)
- Removedexeca@0.7.0(transitive)
- Removedget-stream@3.0.0(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removedmem@1.1.0(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedyallist@2.1.2(transitive)
Updatedexeca@^0.11.0
Updatedmem@^3.0.1