Bolshakova Anna ab21a11190 lab | преди 3 седмици | |
---|---|---|
.. | ||
LICENSE | преди 3 седмици | |
README.md | преди 3 седмици | |
index.js | преди 3 седмици | |
package.json | преди 3 седмици |
Parse
.git/config
into a JavaScript object. sync or async.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install with npm:
$ npm install --save parse-git-config
const parse = require('parse-git-config');
// sync
const config = parse.sync();
// or async
parse(function (err, config) {
// do stuff with err/config
});
Custom path and/or cwd
parse.sync({cwd: 'foo', path: '.git/config'});
// async
parse({cwd: 'foo', path: '.git/config'}, function (err, config) {
// do stuff
});
Example result
Config object will be something like:
{ core:
{ repositoryformatversion: '0',
filemode: true,
bare: false,
logallrefupdates: true,
ignorecase: true,
precomposeunicode: true },
'remote "origin"':
{ url: 'https://github.com/jonschlinkert/parse-git-config.git',
fetch: '+refs/heads/*:refs/remotes/origin/*' },
'branch "master"': { remote: 'origin', merge: 'refs/heads/master', ... } }
Asynchronously parse a .git/config
file. If only the callback is passed, the .git/config
file relative to process.cwd()
is used.
Params
options
{Object|String|Function}: Options with cwd
or path
, the cwd to use, or the callback function.callback
{Function}: callback function if the first argument is options or cwd.returns
{Object}Example
parse(function(err, config) {
if (err) throw err;
// do stuff with config
});
Parse the given
Params
options
{Object|String}: Options with cwd
or path
, or the cwd to use.returns
{Object}Example
parse.promise({ path: '/path/to/.gitconfig' })
.then(config => console.log(config));
Synchronously parse a .git/config
file. If no arguments are passed, the .git/config
file relative to process.cwd()
is used.
Params
options
{Object|String}: Options with cwd
or path
, or the cwd to use.returns
{Object}Example
const config = parse.sync();
Returns an object with only the properties that had ini-style keys converted to objects.
Params
config
{Object}: The parsed git config object.returns
{Object}Example
const config = parse.sync({ path: '/path/to/.gitconfig' });
const obj = parse.expandKeys(config);
Converts ini-style keys into objects:
Example 1
const parse = require('parse-git-config');
const config = {
'foo "bar"': { doStuff: true },
'foo "baz"': { doStuff: true }
};
console.log(parse.keys(config));
Results in:
{
foo: {
bar: { doStuff: true },
baz: { doStuff: true }
}
}
Example 2
const parse = require('parse-git-config');
const config = {
'remote "origin"': {
url: 'https://github.com/jonschlinkert/normalize-pkg.git',
fetch: '+refs/heads/*:refs/remotes/origin/*'
},
'branch "master"': {
remote: 'origin',
merge: 'refs/heads/master'
},
'branch "dev"': {
remote: 'origin',
merge: 'refs/heads/dev',
rebase: true
}
};
console.log(parse.keys(config));
Results in:
{
remote: {
origin: {
url: 'https://github.com/jonschlinkert/normalize-pkg.git',
fetch: '+refs/heads/*:refs/remotes/origin/*'
}
},
branch: {
master: {
remote: 'origin',
merge: 'refs/heads/master'
},
dev: {
remote: 'origin',
merge: 'refs/heads/dev',
rebase: true
}
}
}
You might also be interested in these projects:
name
, email
and url
properties following… more | homepage| Commits | Contributor | | --- | --- | | 63 | jonschlinkert | | 4 | doowb | | 1 | daviwil | | 1 | LexSwed | | 1 | sam3d | | 1 | suarasaur |
Jon Schlinkert
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on August 19, 2018.