4
[user]
        name = Alvin J. Alexander
        email = [omitted]
[merge]
        tool = vimdiff

This is what ~/.gitconfig file looks like. I've never encountered such data objects before. Does this format have a name like json files? Or is this a custom format?

My goal is to extract data from this file to fill out a package.json template. I want to research this format to better understand how to parse it. Do parsing functions already exist for this?


For Reference

This is a template for how to parse it:

(requires iniparser module to be installed)

var iniparser = require('iniparser');
  var fs = require('fs');
  var home_dir = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
  console.log (home_dir);
  var config_file = home_dir+'/.gitconfig';
  var exists = fs.existsSync(config_file);
  if (exists) {
    console.log("Getting some information from the git configuration...");
    var config = iniparser.parseSync(config_file);
    console.log(config);
    return config;
  }
  else {
    console.log("Git configuration file does not exist...");
    return {};
  };

1 Answer 1

12

This file is a ini file. You can try this parser, but any node-ini parser should do the job :).

Sign up to request clarification or add additional context in comments.

4 Comments

Well, isn't this embarrassing. I guess too much web programming and new toys are preventing me from exploring the basics and makes me forget them :) Thank you!
A git config file is not exactly the same as a INI file... for instance, sections can have names e.g. [submodule "mysubmodule"]
Is there a reason for recommending "node-iniparser" over npmjs.org/package/ini? The latter has vastly larger community.
I just randomly googled. That's why I put that last sentence there :). I'llc hange it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.