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 5.1.0 to 6.0.0

54

index.d.ts

@@ -1,39 +0,33 @@

declare const username: {
/**
Get the username of the current user.
/**
Get the username of the current user.
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.
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.
@returns The username.
@returns The username.
@example
```
import username = require('username');
@example
```
import {username} from 'username';
(async () => {
console.log(await username());
//=> 'sindresorhus'
})();
```
*/
(): Promise<string | undefined>;
console.log(await username());
//=> 'sindresorhus'
```
*/
export function username(): Promise<string | undefined>;
/**
Synchronously get the username of the current user.
/**
Synchronously get the username of the current user.
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.
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.
@returns The username.
@returns The username.
@example
```
import username = require('username');
@example
```
import {usernameSync} from 'username';
console.log(username.sync());
//=> 'sindresorhus'
```
*/
sync(): string | undefined;
};
export = username;
console.log(usernameSync());
//=> 'sindresorhus'
```
*/
export function usernameSync(): string | undefined;

@@ -1,5 +0,5 @@

'use strict';
const os = require('os');
const execa = require('execa');
const mem = require('mem');
import process from 'node:process';
import os from 'node:os';
import execa from 'execa';
import mem from 'mem';

@@ -10,8 +10,8 @@ const getEnvironmentVariable = () => {

return (
env.SUDO_USER ||
env.C9_USER /* Cloud9 */ ||
env.LOGNAME ||
env.USER ||
env.LNAME ||
env.USERNAME
env.SUDO_USER
|| env.C9_USER
|| /* Cloud9 */ env.LOGNAME
|| env.USER
|| env.LNAME
|| env.USERNAME
);

@@ -23,3 +23,3 @@ };

return os.userInfo().username;
} catch (_) {}
} catch {}
};

@@ -31,6 +31,6 @@

module.exports = mem(async () => {
const envVariable = getEnvironmentVariable();
if (envVariable) {
return envVariable;
export const username = mem(async () => {
const environmentVariable = getEnvironmentVariable();
if (environmentVariable) {
return environmentVariable;
}

@@ -48,15 +48,17 @@

if (process.platform === 'win32') {
return cleanWindowsCommand(await execa.stdout('whoami'));
const {stdout} = await execa('whoami');
return cleanWindowsCommand(stdout);
}
const userId = await execa.stdout('id', ['-u']);
const {stdout: userId} = await execa('id', ['-u']);
try {
return await execa.stdout('id', ['-un', userId]);
} catch (_) {}
const {stdout} = await execa('id', ['-un', userId]);
return stdout;
} catch {}
return makeUsernameFromId(userId);
} catch (_) {}
} catch {}
});
module.exports.sync = mem(() => {
export const usernameSync = mem(() => {
const envVariable = getEnvironmentVariable();

@@ -77,9 +79,9 @@ if (envVariable) {

const userId = execa.sync('id', ['-u']).stdout;
const {stdout: userId} = execa.sync('id', ['-u']);
try {
return execa.sync('id', ['-un', userId]).stdout;
} catch (_) {}
} catch {}
return makeUsernameFromId(userId);
} catch (_) {}
} catch {}
});
{
"name": "username",
"version": "5.1.0",
"version": "6.0.0",
"description": "Get the username of the current user",
"license": "MIT",
"repository": "sindresorhus/username",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},

@@ -36,10 +39,10 @@ "scripts": {

"dependencies": {
"execa": "^1.0.0",
"mem": "^4.3.0"
"execa": "^5.1.1",
"mem": "^9.0.1"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.17.0",
"xo": "^0.44.0"
}
}

@@ -1,2 +0,2 @@

# username [![Build Status](https://travis-ci.org/sindresorhus/username.svg?branch=master)](https://travis-ci.org/sindresorhus/username)
# username

@@ -7,3 +7,2 @@ > Get the username of the current user

## Install

@@ -15,2 +14,3 @@

*This package only works in Node.js, not in browsers.*

@@ -20,11 +20,8 @@ ## Usage

```js
const username = require('username');
import {username} from 'username';
(async () => {
console.log(await username());
//=> 'sindresorhus'
})();
console.log(await username());
//=> 'sindresorhus'
```
## API

@@ -38,7 +35,6 @@

### username.sync()
### usernameSync()
Returns the username.
## Related

@@ -48,6 +44,1 @@

- [fullname](https://github.com/sindresorhus/fullname) - Get the fullname of the current user
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

Sorry, the diff of this file is not supported yet

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