DEV Community

Rocktim Saikia
Rocktim Saikia

Posted on

✨ module to read git user config from the system and return it as a JSON object.

GitHub logo rocktimsaikia / read-git-user

Reads the username and email from `.gitconfig` and returns it as json object

Read-git-user is a tiny 1.3kB✨ module that can be used to retrieve the git username and email right from the systems global .gitconfig file.

How this works is that the module looks for HOME || USERPROFILE and reads the ini file from there and returns it as a parsed JSON object.

Usage

import readGitUser = require('read-git-user');

(async () => {
        const gitUser = await readGitUser();
        //=> {user: rocktimsaikia, email: rocktimsaikia@gmail.com}

        const gitUser = readGitUser.sync()
        //=> {user: rocktimsaikia, email: rocktimsaikia@gmail.com}
})();
Enter fullscreen mode Exit fullscreen mode

[ PS: I created this tool to use it in a project that I am working on. I thought someone might find it handy so made a quick post. Leave a star at the repo 🌟 if find this helpful. Thanks for reading 👋]

Latest comments (0)