[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?
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 {};
};
This file is a ini
file. You can try this parser, but any node-ini parser should do the job :).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With