Comparing version 4.1.0 to 5.0.0
40
index.js
@@ -6,6 +6,7 @@ 'use strict'; | ||
const getEnvVar = () => { | ||
const getEnvironmentVariable = () => { | ||
const {env} = process; | ||
return env.SUDO_USER || | ||
return ( | ||
env.SUDO_USER || | ||
env.C9_USER /* Cloud9 */ || | ||
@@ -15,3 +16,4 @@ env.LOGNAME || | ||
env.LNAME || | ||
env.USERNAME; | ||
env.USERNAME | ||
); | ||
}; | ||
@@ -25,10 +27,8 @@ | ||
const cleanWinCmd = x => x.replace(/^.*\\/, ''); | ||
const cleanWindowsCommand = string => string.replace(/^.*\\/, ''); | ||
const noop = () => {}; | ||
module.exports = mem(() => { | ||
const envVar = getEnvVar(); | ||
if (envVar) { | ||
return Promise.resolve(envVar); | ||
module.exports = mem(async () => { | ||
const envVariable = getEnvironmentVariable(); | ||
if (envVariable) { | ||
return envVariable; | ||
} | ||
@@ -38,16 +38,18 @@ | ||
if (userInfoUsername) { | ||
return Promise.resolve(userInfoUsername); | ||
return userInfoUsername; | ||
} | ||
if (process.platform === 'win32') { | ||
return execa('whoami').then(x => cleanWinCmd(x.stdout)).catch(noop); | ||
} | ||
try { | ||
if (process.platform === 'win32') { | ||
return cleanWindowsCommand(await execa.stdout('whoami')); | ||
} | ||
return execa('id', ['-un']).then(x => x.stdout).catch(noop); | ||
return await execa.stdout('id', ['-un']); | ||
} catch (_) {} | ||
}); | ||
module.exports.sync = mem(() => { | ||
const envVar = getEnvVar(); | ||
if (envVar) { | ||
return envVar; | ||
const envVariable = getEnvironmentVariable(); | ||
if (envVariable) { | ||
return envVariable; | ||
} | ||
@@ -62,3 +64,3 @@ | ||
if (process.platform === 'win32') { | ||
return cleanWinCmd(execa.sync('whoami').stdout); | ||
return cleanWindowsCommand(execa.sync('whoami').stdout); | ||
} | ||
@@ -65,0 +67,0 @@ |
{ | ||
"name": "username", | ||
"version": "4.1.0", | ||
"version": "5.0.0", | ||
"description": "Get the username of the current user", | ||
@@ -13,9 +13,10 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
"test": "xo && ava && tsd" | ||
}, | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
@@ -32,3 +33,2 @@ "keywords": [ | ||
"env", | ||
"var", | ||
"environment", | ||
@@ -39,8 +39,9 @@ "variable" | ||
"execa": "^1.0.0", | ||
"mem": "^4.0.0" | ||
"mem": "^4.3.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.1.0", | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -5,3 +5,3 @@ # 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. | ||
This module is meant for informational purposes and not for secure identification. | ||
@@ -34,3 +34,3 @@ | ||
Returns a `Promise` for the username. | ||
Returns a `Promise<string>` with the username. | ||
@@ -37,0 +37,0 @@ ### username.sync() |
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
5246
5
82
3
Updatedmem@^4.3.0