Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

username

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

username - npm Package Compare versions

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()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc