master
jonschlinkert 10 years ago
parent d2382fee74
commit defd6cfea0

@ -7,11 +7,23 @@
## Usage
```js
var parseGitConfig = require('{%= name %}');
var gitConfig = require('{%= name %}');
```
## API
{%= apidocs("index.js") %}
### async
```js
gitConfig(function (err, config) {
// do stuff with err/config
});
```
### sync
```js
gitConfig.sync();
```
## Run tests

@ -10,29 +10,33 @@
var fs = require('fs');
var path = require('path');
var ini = require('ini');
var lookup = require('look-up');
module.exports = config;
/**
* Expose `config`
*/
module.exports = git;
function config(cwd, cb) {
function git(cwd, cb) {
if (typeof cwd === 'function') {
cb = cwd; cwd = null;
}
var fp = path.join(cwd || process.cwd(), '.git/config');
read(fp, function (err, buffer) {
if (typeof cb !== 'function') {
throw new TypeError('parse-git-config async expects a callback function.');
}
read(resolve(cwd), function (err, buffer) {
if (err) {
cb(err);
return;
}
var data = ini.parse(buffer.toString());
return cb(null, data);
cb(null, ini.parse(buffer.toString()));
});
}
config.sync = function configSync(cwd) {
var fp = path.join(cwd || process.cwd(), '.git/config');
git.sync = function configSync(cwd) {
var fp = resolve(cwd);
if (!fs.existsSync(fp)) {
throw new Error('.git/config does not exist.');
}
@ -41,12 +45,17 @@ config.sync = function configSync(cwd) {
function read(fp, cb) {
try {
fs.readFile(fp, function (err, data) {
if (err) return cb(err);
return cb(null, data);
fs.readFile(fp, function (err, config) {
if (err) {
return cb(err);
}
cb(null, config);
});
} catch (err) {
cb(err);
}
}
function resolve(cwd) {
return path.join(cwd || process.cwd(), '.git/config');
}

@ -1,6 +1,6 @@
{
"name": "parse-git-config",
"description": "Parse .git/config into a JavaScript object.",
"description": "Parse `.git/config` into a JavaScript object. sync or async.",
"version": "0.1.0",
"homepage": "https://github.com/jonschlinkert/parse-git-config",
"author": {
@ -29,12 +29,14 @@
"test": "mocha"
},
"dependencies": {
"ini": "^1.3.3",
"look-up": "^0.6.0"
"ini": "^1.3.3"
},
"devDependencies": {
"mocha": "*",
"should": "*"
},
"keywords": []
"keywords": [
"config",
"git"
]
}
Loading…
Cancel
Save