Comparing version 3.3.0 to 4.0.0
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)); | ||
} | ||
}); |
101
package.json
{ | ||
"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
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
5573
6
5
119
2
5
+ Addedaggregate-error@3.1.0(transitive)
+ Addedclean-stack@2.2.0(transitive)
+ Addedcross-spawn@6.0.5(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexeca@1.0.0(transitive)
+ Addedfilter-obj@2.0.2(transitive)
+ Addedget-stream@4.1.0(transitive)
+ Addedindent-string@4.0.0(transitive)
+ Addedmap-age-cleaner@0.1.3(transitive)
+ Addedmem@4.3.0(transitive)
+ Addedmimic-fn@2.1.0(transitive)
+ Addednice-try@1.0.5(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedp-any@2.1.0(transitive)
+ Addedp-cancelable@2.1.1(transitive)
+ Addedp-defer@1.0.0(transitive)
+ Addedp-is-promise@2.1.0(transitive)
+ Addedp-some@4.1.0(transitive)
+ Addedpasswd-user@3.0.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedtype-fest@0.3.1(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedp-try@^1.0.0
- Removedaggregate-error@1.0.0(transitive)
- Removedclean-stack@1.3.0(transitive)
- Removedcross-spawn@5.1.0(transitive)
- Removedcross-spawn-async@2.2.5(transitive)
- Removedexeca@0.4.00.6.3(transitive)
- Removedfilter-obj@1.1.0(transitive)
- Removedget-stream@3.0.0(transitive)
- Removedindent-string@3.2.0(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removedmem@1.1.0(transitive)
- Removedmimic-fn@1.2.0(transitive)
- Removednpm-run-path@1.0.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedp-any@1.1.0(transitive)
- Removedp-some@2.0.1(transitive)
- Removedp-try@1.0.0(transitive)
- Removedpasswd-user@2.1.0(transitive)
- Removedpath-key@1.0.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedyallist@2.1.2(transitive)
Updatedexeca@^1.0.0
Updatedfilter-obj@^2.0.0
Updatedmem@^4.3.0
Updatedp-any@^2.1.0
Updatedpasswd-user@^3.0.0
Updatedrc@^1.2.8