Socket
Socket
Sign inDemoInstall

fullname

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fullname - npm Package Compare versions

Comparing version 3.3.0 to 4.0.0

index.d.ts

133

index.js
'use strict';
const mem = require('mem');

@@ -7,6 +6,5 @@ const execa = require('execa');

const pAny = require('p-any');
const pTry = require('p-try');
const filterObj = require('filter-obj');
const envVars = [
const environmentVariables = [
'GIT_AUTHOR_NAME',

@@ -18,51 +16,93 @@ 'GIT_COMMITTER_NAME',

function checkEnv() {
return pTry(() => {
const env = process.env;
/* eslint-disable unicorn/error-message */
async function checkEnv() {
const {env} = process;
const variableName = environmentVariables.find(variable => env[variable]);
const fullName = variableName && env[variableName];
const varName = envVars.find(x => env[x]);
const fullname = varName && env[varName];
if (!fullName) {
throw new Error();
}
return fullname || Promise.reject();
});
return fullName;
}
function checkAuthorName() {
return pTry(() => {
const fullname = require('rc')('npm')['init-author-name'];
return fullname || Promise.reject();
});
async function checkAuthorName() {
const fullName = require('rc')('npm')['init-author-name'];
if (!fullName) {
throw new Error();
}
return fullName;
}
function checkPasswd() {
return passwdUser()
.then(user => user.fullname || Promise.reject());
async function checkPasswd() {
const user = await passwdUser();
if (!user.fullName) {
throw new Error();
}
return user.fullName;
}
function checkGit() {
return execa.stdout('git', ['config', '--global', 'user.name'])
.then(fullname => fullname || Promise.reject());
async function checkGit() {
const fullName = await execa.stdout('git', [
'config',
'--global',
'user.name'
]);
if (!fullName) {
throw new Error();
}
return fullName;
}
function checkOsaScript() {
return execa.stdout('osascript', ['-e', 'long user name of (system info)'])
.then(fullname => fullname || Promise.reject());
async function checkOsaScript() {
const fullName = await execa.stdout('osascript', [
'-e',
'long user name of (system info)'
]);
if (!fullName) {
throw new Error();
}
return fullName;
}
function checkWmic() {
return execa.stdout('wmic', ['useraccount', 'where', 'name="%username%"', 'get', 'fullname'])
.then(stdout => {
const fullname = stdout.replace('FullName', '');
return fullname || Promise.reject();
});
async function checkWmic() {
const stdout = await execa.stdout('wmic', [
'useraccount',
'where',
'name="%username%"',
'get',
'fullname'
]);
const fullName = stdout.replace('FullName', '');
if (!fullName) {
throw new Error();
}
return fullName;
}
function checkGetEnt() {
return execa.shell('getent passwd $(whoami)').then(res => {
const fullname = (res.stdout.split(':')[4] || '').replace(/,.*/, '');
return fullname || Promise.reject();
});
async function checkGetEnt() {
const result = await execa.shell('getent passwd $(whoami)');
const fullName = (result.stdout.split(':')[4] || '').replace(/,.*/, '');
if (!fullName) {
throw new Error();
}
return fullName;
}
/* eslint-enable unicorn/error-message */
function fallback() {
async function fallback() {
if (process.platform === 'darwin') {

@@ -73,3 +113,3 @@ return pAny([checkPasswd(), checkOsaScript()]);

if (process.platform === 'win32') {
// Fullname is usually not set by default in the system on Windows 7+
// The full name is usually not set by default in the system on Windows 7+
return pAny([checkGit(), checkWmic()]);

@@ -81,7 +121,14 @@ }

function getFullName() {
return checkEnv()
.catch(checkAuthorName)
.catch(fallback)
.catch(() => {});
async function getFullName() {
try {
return await checkEnv();
} catch (_) {}
try {
return await checkAuthorName();
} catch (_) {}
try {
return await fallback();
} catch (_) {}
}

@@ -91,4 +138,4 @@

cacheKey() {
return JSON.stringify(filterObj(process.env, envVars));
return JSON.stringify(filterObj(process.env, environmentVariables));
}
});
{
"name": "fullname",
"version": "3.3.0",
"description": "Get the fullname of the current user",
"license": "MIT",
"repository": "sindresorhus/fullname",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"name",
"fullname",
"realname",
"full name",
"first name",
"surname",
"full",
"real",
"given",
"user",
"gecos",
"pwuid",
"uid"
],
"dependencies": {
"execa": "^0.6.0",
"filter-obj": "^1.1.0",
"mem": "^1.1.0",
"p-any": "^1.0.0",
"p-try": "^1.0.0",
"passwd-user": "^2.1.0",
"rc": "^1.1.6"
},
"devDependencies": {
"ava": "*",
"mock-require": "^2.0.0",
"require-uncached": "^1.0.3",
"xo": "*"
},
"xo": {
"esnext": true
}
"name": "fullname",
"version": "4.0.0",
"description": "Get the fullname of the current user",
"license": "MIT",
"repository": "sindresorhus/fullname",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"name",
"fullname",
"realname",
"full name",
"surname",
"full",
"real",
"given",
"user",
"gecos",
"pwuid",
"uid"
],
"dependencies": {
"execa": "^1.0.0",
"filter-obj": "^2.0.0",
"mem": "^4.3.0",
"p-any": "^2.1.0",
"passwd-user": "^3.0.0",
"rc": "^1.2.8"
},
"devDependencies": {
"ava": "^1.4.1",
"import-fresh": "^3.0.0",
"mock-require": "^3.0.3",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
# fullname [![Build Status](https://travis-ci.org/sindresorhus/fullname.svg?branch=master)](https://travis-ci.org/sindresorhus/fullname)
> Get the fullname of the current user
> Get the full name of the current user

@@ -9,3 +9,3 @@

```
$ npm install --save fullname
$ npm install fullname
```

@@ -19,8 +19,8 @@

```js
const fullname = require('fullname');
const fullName = require('fullname');
fullname().then(name => {
console.log(name);
(async () => {
console.log(await fullName());
//=> 'Sindre Sorhus'
});
})();
```

@@ -27,0 +27,0 @@

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