From defd6cfea0d282802036ab34c9437419dfe2d2ad Mon Sep 17 00:00:00 2001 From: jonschlinkert Date: Tue, 24 Feb 2015 23:13:55 -0500 Subject: [PATCH] clean up --- .verb.md | 20 ++++++++++++++++---- index.js | 37 +++++++++++++++++++++++-------------- package.json | 12 +++++++----- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/.verb.md b/.verb.md index f0960af..5e5b1c5 100644 --- a/.verb.md +++ b/.verb.md @@ -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 @@ -34,4 +46,4 @@ Pull requests and stars are always welcome. For bugs and feature requests, [plea *** -{%= include("footer") %} \ No newline at end of file +{%= include("footer") %} diff --git a/index.js b/index.js index e31ebcb..2c68c8d 100644 --- a/index.js +++ b/index.js @@ -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'); +} diff --git a/package.json b/package.json index d86b721..4e4e2e1 100644 --- a/package.json +++ b/package.json @@ -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" + ] +} \ No newline at end of file