This file is a ini
file. You can try this parser, but any node-ini parser should do the job :).
How to read and parse gitconfig file with node.js?
-
31-05-2022 - |
Вопрос
[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 {};
};
Решение
Не связан с StackOverflow