Giter Site home page Giter Site logo

fullname's Introduction

fullname

Get the full name of the current user

Works on macOS, Linux, and Windows.

Install

npm install fullname

Usage

import fullName from 'fullname';

console.log(await fullName());
//=> 'Sindre Sorhus'

In the rare case a name cannot be found, you could fall back to username.

Related

fullname's People

Contributors

bendingbender avatar canastro avatar kevva avatar ntwb avatar richienb avatar samverschueren avatar sholladay avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fullname's Issues

Refactor

The code is quite messy right now. Would be nice to use mem on the exported function instead of assigning to the global fullname in every step. Also separate each check into a top level function, so we can easily mix and match checks for each platform, and maybe even do some checks in parallel using Promise.race(). I don't have time to do this right now, but could be an interesting exercise for anyone looking to contribute. PR welcome :)

Respect name changes

I am making first-name, which is built on top of this module.

Writing good tests for it is difficult because fullname caches the result. I could maybe use this trick but it seems ugly to do that to a dependency. And if I ever have to write a module on top of first-name where trying out different names is useful, then that modules's tests may not be able to do so because you can't always require a sub-dependency, depending on how npm structures the tree.

Any thoughts on approaches to deal with this?

More broadly, the memoization here is strange because fullname doesn't take any input. Thus it has no way to know when the computation should be performed again, which is a core tenet of memoization. And even though it may not be common, the user's name certainly can change.

My solutions:

  1. fullname.noCache() does the same work, bypassing the cache.
  2. fullname() implements a lazily updated cache. So it would have a shortcut to resolve quickly with a cached value if one is available, but would trigger a non-blocking background update of the cache so that future calls can return a more up-to-date value.
  3. We leave everything as-is but use mem's cacheKey feature to cache based on relevant properties from process.env. So changes to the environment can be returned immediately. However, unlike 2, in the event that no environment variables are defined, the module keeps behaving as it does now (i.e. you are "stuck" with a name permanently).

My favorite is 3, and it would look something like this:

module.exports = mem(getFullName, {
    cacheKey(input) {
        return JSON.stringify(filterObj(process.env, [
            'GIT_AUTHOR_NAME',
            'GIT_COMMITTER_NAME'
            // ...
        ]));
    }
});

Get the fullname from `npmconf`

Using the npmconf module, get the init.author.name prop.

Should be faster than spawning a subprocess.

Run it concurrently with the subprocess in case it's not set.

npmconf is deprecated

Getting this WARN when installing this package:

$ npm i fullname
npm WARN deprecated [email protected]: this package has been reintegrated into npm and is now out of date with respect to npm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.