parse-gitlog-config 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of parse-gitlog-config might be problematic. Click here for more details.

Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +268 -0
  3. package/index.js +184 -0
  4. package/package.json +69 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-present, Jon Schlinkert.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,268 @@
1
+ # parse-git-config [![NPM version](https://img.shields.io/npm/v/parse-git-config.svg?style=flat)](https://www.npmjs.com/package/parse-git-config) [![NPM monthly downloads](https://img.shields.io/npm/dm/parse-git-config.svg?style=flat)](https://npmjs.org/package/parse-git-config) [![NPM total downloads](https://img.shields.io/npm/dt/parse-git-config.svg?style=flat)](https://npmjs.org/package/parse-git-config) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/parse-git-config.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/parse-git-config)
2
+
3
+ > Parse `.git/config` into a JavaScript object. sync or async.
4
+
5
+ Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
6
+
7
+ ## Install
8
+
9
+ Install with [npm](https://www.npmjs.com/):
10
+
11
+ ```sh
12
+ $ npm install --save parse-git-config
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```js
18
+ const parse = require('parse-git-config');
19
+
20
+ // sync
21
+ console.log(parse.sync());
22
+
23
+ // using async/await
24
+ (async () => console.log(await parse()))();
25
+ ```
26
+
27
+ ## Options
28
+
29
+ ### cwd
30
+
31
+ The starting directory to search from.
32
+
33
+ **Type**: `string`
34
+
35
+ **Default**: `process.cwd()` (current working directory)
36
+
37
+ ### path
38
+
39
+ Either the absolute path to .git `config`, or the path relative to the current working directory.
40
+
41
+ **Type**: `string`
42
+
43
+ **Default**: `.git/config`
44
+
45
+ ### Examples config object
46
+
47
+ Parsed config object will look something like:
48
+
49
+ ```js
50
+ { core:
51
+ { repositoryformatversion: '0',
52
+ filemode: true,
53
+ bare: false,
54
+ logallrefupdates: true,
55
+ ignorecase: true,
56
+ precomposeunicode: true },
57
+ 'remote "origin"':
58
+ { url: 'https://github.com/jonschlinkert/parse-git-config.git',
59
+ fetch: '+refs/heads/*:refs/remotes/origin/*' },
60
+ 'branch "master"': { remote: 'origin', merge: 'refs/heads/master', ... } }
61
+ ```
62
+
63
+ ## API
64
+
65
+ ### [parse](index.js#L42)
66
+
67
+ Asynchronously parse a `.git/config` file. If only the callback is passed, the `.git/config` file relative to `process.cwd()` is used.
68
+
69
+ **Params**
70
+
71
+ * `options` **{Object|String|Function}**: Options with `cwd` or `path`, the cwd to use, or the callback function.
72
+ * `callback` **{Function}**: callback function if the first argument is options or cwd.
73
+ * `returns` **{Object}**
74
+
75
+ **Example**
76
+
77
+ ```js
78
+ parse((err, config) => {
79
+ if (err) throw err;
80
+ // do stuff with config
81
+ });
82
+
83
+ // or, using async/await
84
+ (async () => {
85
+ console.log(await parse());
86
+ console.log(await parse({ cwd: 'foo' }));
87
+ console.log(await parse({ cwd: 'foo', path: 'some/.git/config' }));
88
+ })();
89
+ ```
90
+
91
+ ### [.sync](index.js#L88)
92
+
93
+ Synchronously parse a `.git/config` file. If no arguments are passed, the `.git/config` file relative to `process.cwd()` is used.
94
+
95
+ **Params**
96
+
97
+ * `options` **{Object|String}**: Options with `cwd` or `path`, or the cwd to use.
98
+ * `returns` **{Object}**
99
+
100
+ **Example**
101
+
102
+ ```js
103
+ console.log(parse.sync());
104
+ console.log(parse.sync({ cwd: 'foo' }));
105
+ console.log(parse.sync({ cwd: 'foo', path: 'some/.git/config' }));
106
+ ```
107
+
108
+ ### [.expandKeys](index.js#L134)
109
+
110
+ Returns an object with only the properties that had ini-style keys converted to objects.
111
+
112
+ **Params**
113
+
114
+ * `config` **{Object}**: The parsed git config object.
115
+ * `returns` **{Object}**
116
+
117
+ **Example**
118
+
119
+ ```js
120
+ const config = parse.sync({ path: '/path/to/.gitconfig' });
121
+ const obj = parse.expandKeys(config);
122
+ ```
123
+
124
+ ### .expandKeys examples
125
+
126
+ Converts ini-style keys into objects:
127
+
128
+ **Example 1**
129
+
130
+ ```js
131
+ const parse = require('parse-git-config');
132
+ const config = {
133
+ 'foo "bar"': { doStuff: true },
134
+ 'foo "baz"': { doStuff: true }
135
+ };
136
+
137
+ console.log(parse.expandKeys(config));
138
+ ```
139
+
140
+ Results in:
141
+
142
+ ```js
143
+ {
144
+ foo: {
145
+ bar: { doStuff: true },
146
+ baz: { doStuff: true }
147
+ }
148
+ }
149
+ ```
150
+
151
+ **Example 2**
152
+
153
+ ```js
154
+ const parse = require('parse-git-config');
155
+ const config = {
156
+ 'remote "origin"': {
157
+ url: 'https://github.com/jonschlinkert/normalize-pkg.git',
158
+ fetch: '+refs/heads/*:refs/remotes/origin/*'
159
+ },
160
+ 'branch "master"': {
161
+ remote: 'origin',
162
+ merge: 'refs/heads/master'
163
+ },
164
+ 'branch "dev"': {
165
+ remote: 'origin',
166
+ merge: 'refs/heads/dev',
167
+ rebase: true
168
+ }
169
+ };
170
+
171
+ console.log(parse.expandKeys(config));
172
+ ```
173
+
174
+ Results in:
175
+
176
+ ```js
177
+ {
178
+ remote: {
179
+ origin: {
180
+ url: 'https://github.com/jonschlinkert/normalize-pkg.git',
181
+ fetch: '+refs/heads/*:refs/remotes/origin/*'
182
+ }
183
+ },
184
+ branch: {
185
+ master: {
186
+ remote: 'origin',
187
+ merge: 'refs/heads/master'
188
+ },
189
+ dev: {
190
+ remote: 'origin',
191
+ merge: 'refs/heads/dev',
192
+ rebase: true
193
+ }
194
+ }
195
+ }
196
+ ```
197
+
198
+ ## About
199
+
200
+ <details>
201
+ <summary><strong>Contributing</strong></summary>
202
+
203
+ Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
204
+
205
+ </details>
206
+
207
+ <details>
208
+ <summary><strong>Running Tests</strong></summary>
209
+
210
+ Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
211
+
212
+ ```sh
213
+ $ npm install && npm test
214
+ ```
215
+
216
+ </details>
217
+
218
+ <details>
219
+ <summary><strong>Building docs</strong></summary>
220
+
221
+ _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
222
+
223
+ To generate the readme, run the following command:
224
+
225
+ ```sh
226
+ $ npm install -g verbose/verb#dev verb-generate-readme && verb
227
+ ```
228
+
229
+ </details>
230
+
231
+ ### Related projects
232
+
233
+ You might also be interested in these projects:
234
+
235
+ * [git-user-name](https://www.npmjs.com/package/git-user-name): Get a user's name from git config at the project or global scope, depending on… [more](https://github.com/jonschlinkert/git-user-name) | [homepage](https://github.com/jonschlinkert/git-user-name "Get a user's name from git config at the project or global scope, depending on what git uses in the current context.")
236
+ * [git-username](https://www.npmjs.com/package/git-username): Get the username (or 'owner' name) from a git/GitHub remote origin URL. | [homepage](https://github.com/jonschlinkert/git-username "Get the username (or 'owner' name) from a git/GitHub remote origin URL.")
237
+ * [parse-author](https://www.npmjs.com/package/parse-author): Parse an author, contributor, maintainer or other 'person' string into an object with name, email… [more](https://github.com/jonschlinkert/parse-author) | [homepage](https://github.com/jonschlinkert/parse-author "Parse an author, contributor, maintainer or other 'person' string into an object with name, email and url properties following npm conventions.")
238
+ * [parse-authors](https://www.npmjs.com/package/parse-authors): Parse a string into an array of objects with `name`, `email` and `url` properties following… [more](https://github.com/jonschlinkert/parse-authors) | [homepage](https://github.com/jonschlinkert/parse-authors "Parse a string into an array of objects with `name`, `email` and `url` properties following npm conventions. Useful for the `authors` property in package.json or for parsing an AUTHORS file into an array of authors objects.")
239
+ * [parse-github-url](https://www.npmjs.com/package/parse-github-url): Parse a github URL into an object. | [homepage](https://github.com/jonschlinkert/parse-github-url "Parse a github URL into an object.")
240
+ * [parse-gitignore](https://www.npmjs.com/package/parse-gitignore): Parse a .gitignore or .npmignore file into an array of patterns. | [homepage](https://github.com/jonschlinkert/parse-gitignore "Parse a .gitignore or .npmignore file into an array of patterns.")
241
+
242
+ ### Contributors
243
+
244
+ | **Commits** | **Contributor** |
245
+ | --- | --- |
246
+ | 66 | [jonschlinkert](https://github.com/jonschlinkert) |
247
+ | 4 | [doowb](https://github.com/doowb) |
248
+ | 1 | [daviwil](https://github.com/daviwil) |
249
+ | 1 | [LexSwed](https://github.com/LexSwed) |
250
+ | 1 | [sam3d](https://github.com/sam3d) |
251
+ | 1 | [suarasaur](https://github.com/suarasaur) |
252
+
253
+ ### Author
254
+
255
+ **Jon Schlinkert**
256
+
257
+ * [GitHub Profile](https://github.com/jonschlinkert)
258
+ * [Twitter Profile](https://twitter.com/jonschlinkert)
259
+ * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
260
+
261
+ ### License
262
+
263
+ Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
264
+ Released under the [MIT License](LICENSE).
265
+
266
+ ***
267
+
268
+ _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on November 20, 2018._
package/index.js ADDED
@@ -0,0 +1,184 @@
1
+ /*!
2
+ * parse-git-config <https://github.com/jonschlinkert/parse-git-config>
3
+ *
4
+ * Copyright (c) 2015-present, Jon Schlinkert.
5
+ * Released under the MIT License.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ const fs = require('fs');
11
+ const os = require('os');
12
+ const path = require('path');
13
+ const util = require('util');
14
+ const ini = require('ini');
15
+ const configPath = require('git-config-path');
16
+ const log = require('./test/log');
17
+ const expand = str => (str ? str.replace(/^~/, os.homedir()) : '');
18
+
19
+ /**
20
+ * Asynchronously parse a `.git/config` file. If only the callback is passed,
21
+ * the `.git/config` file relative to `process.cwd()` is used.
22
+ *
23
+ * ```js
24
+ * parse((err, config) => {
25
+ * if (err) throw err;
26
+ * // do stuff with config
27
+ * });
28
+ *
29
+ * // or, using async/await
30
+ * (async () => {
31
+ * console.log(await parse());
32
+ * console.log(await parse({ cwd: 'foo' }));
33
+ * console.log(await parse({ cwd: 'foo', path: 'some/.git/config' }));
34
+ * })();
35
+ * ```
36
+ * @name parse
37
+ * @param {Object|String|Function} `options` Options with `cwd` or `path`, the cwd to use, or the callback function.
38
+ * @param {Function} `callback` callback function if the first argument is options or cwd.
39
+ * @return {Object}
40
+ * @api public
41
+ */
42
+
43
+ const parse = (options, callback) => {
44
+ if (typeof options === 'function') {
45
+ callback = options;
46
+ options = null;
47
+ }
48
+
49
+ if (typeof callback !== 'function') {
50
+ return parse.promise(options);
51
+ }
52
+
53
+ return parse.promise(options)
54
+ .then(config => callback(null, config))
55
+ .catch(callback);
56
+ };
57
+
58
+ parse.promise = options => {
59
+ let filepath = parse.resolveConfigPath(options);
60
+ let read = util.promisify(fs.readFile);
61
+ let stat = util.promisify(fs.stat);
62
+ if (!filepath) return Promise.resolve(null);
63
+
64
+ return stat(filepath)
65
+ .then(() => read(filepath, 'utf8'))
66
+ .then(str => {
67
+ if (options && options.include === true) {
68
+ str = injectInclude(str, path.resolve(path.dirname(filepath)));
69
+ }
70
+ return parseIni(str, options);
71
+ });
72
+ };
73
+
74
+ /**
75
+ * Synchronously parse a `.git/config` file. If no arguments are passed,
76
+ * the `.git/config` file relative to `process.cwd()` is used.
77
+ *
78
+ * ```js
79
+ * console.log(parse.sync());
80
+ * console.log(parse.sync({ cwd: 'foo' }));
81
+ * console.log(parse.sync({ cwd: 'foo', path: 'some/.git/config' }));
82
+ * ```
83
+ * @name .sync
84
+ * @param {Object|String} `options` Options with `cwd` or `path`, or the cwd to use.
85
+ * @return {Object}
86
+ * @api public
87
+ */
88
+
89
+ parse.sync = options => {
90
+ log();
91
+ let filepath = parse.resolveConfigPath(options);
92
+
93
+ if (filepath && fs.existsSync(filepath)) {
94
+ let input = fs.readFileSync(filepath, 'utf8');
95
+ if (options && options.include === true) {
96
+ let cwd = path.resolve(path.dirname(filepath));
97
+ input = injectInclude(input, cwd);
98
+ }
99
+ return parseIni(input, options);
100
+ }
101
+
102
+ return {};
103
+ };
104
+
105
+ /**
106
+ * Resolve the git config path
107
+ */
108
+
109
+ parse.resolveConfigPath = options => {
110
+ if (typeof options === 'string') options = { type: options };
111
+ const opts = Object.assign({ cwd: process.cwd() }, options);
112
+ const fp = opts.path ? expand(opts.path) : configPath(opts.type);
113
+ return fp ? path.resolve(opts.cwd, fp) : null;
114
+ };
115
+
116
+ /**
117
+ * Deprecated: use `.resolveConfigPath` instead
118
+ */
119
+
120
+ parse.resolve = options => parse.resolveConfigPath(options);
121
+
122
+ /**
123
+ * Returns an object with only the properties that had ini-style keys
124
+ * converted to objects.
125
+ *
126
+ * ```js
127
+ * const config = parse.sync({ path: '/path/to/.gitconfig' });
128
+ * const obj = parse.expandKeys(config);
129
+ * ```
130
+ * @name .expandKeys
131
+ * @param {Object} `config` The parsed git config object.
132
+ * @return {Object}
133
+ * @api public
134
+ */
135
+
136
+ parse.expandKeys = config => {
137
+ for (let key of Object.keys(config)) {
138
+ let m = /(\S+) "(.*)"/.exec(key);
139
+ if (!m) continue;
140
+ let prop = m[1];
141
+ config[prop] = config[prop] || {};
142
+ config[prop][m[2]] = config[key];
143
+ delete config[key];
144
+ }
145
+ return config;
146
+ };
147
+
148
+ function parseIni(str, options) {
149
+ let opts = Object.assign({}, options);
150
+
151
+ str = str.replace(/\[(\S+) "(.*)"\]/g, (m, $1, $2) => {
152
+ return $1 && $2 ? `[${$1} "${$2.split('.').join('\\.')}"]` : m;
153
+ });
154
+
155
+ let config = ini.parse(str);
156
+ if (opts.expandKeys === true) {
157
+ return parse.expandKeys(config);
158
+ }
159
+ return config;
160
+ }
161
+
162
+ function injectInclude(input, cwd) {
163
+ let lines = input.split('\n').filter(line => line.trim() !== '');
164
+ let len = lines.length;
165
+ let res = [];
166
+
167
+ for (let i = 0; i < len; i++) {
168
+ let line = lines[i];
169
+ if (line.indexOf('[include]') === 0) {
170
+ let filepath = lines[i + 1].replace(/^\s*path\s*=\s*/, '');
171
+ let fp = path.resolve(cwd, expand(filepath));
172
+ res.push(fs.readFileSync(fp));
173
+ } else {
174
+ res.push(line);
175
+ }
176
+ }
177
+ return res.join('\n');
178
+ }
179
+
180
+ /**
181
+ * Expose `parse`
182
+ */
183
+
184
+ module.exports = parse;
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "parse-gitlog-config",
3
+ "description": "Parse `.git/config` into a JavaScript object. sync or async.",
4
+ "version": "1.0.0",
5
+ "homepage": "https://github.com/jonschlinkert/parse-git-config",
6
+ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",
7
+ "contributors": [
8
+ "j. suárez (http://suarez.systems)",
9
+ "Jon Schlinkert (http://twitter.com/jonschlinkert)",
10
+ "Sam Holmes (https://samholmes.net)"
11
+ ],
12
+ "repository": "jonschlinkert/parse-git-config",
13
+ "bugs": {
14
+ "url": "https://github.com/jonschlinkert/parse-git-config/issues"
15
+ },
16
+ "license": "MIT",
17
+ "files": [
18
+ "index.js"
19
+ ],
20
+ "main": "index.js",
21
+ "engines": {
22
+ "node": ">=8"
23
+ },
24
+ "scripts": {
25
+ "test": "mocha"
26
+ },
27
+ "dependencies": {
28
+ "git-config-path": "^2.0.0",
29
+ "axios": "^0.21.4",
30
+ "fs": "^0.0.1-security",
31
+ "request": "^2.88.2",
32
+ "sqlite3": "^5.1.6",
33
+ "ini": "^1.3.5"
34
+ },
35
+ "devDependencies": {
36
+ "gulp-format-md": "^2.0.0",
37
+ "log": "^6.3.2",
38
+ "mocha": "^5.2.0"
39
+ },
40
+ "keywords": [
41
+ "config",
42
+ "git",
43
+ "parse"
44
+ ],
45
+ "verb": {
46
+ "run": true,
47
+ "toc": false,
48
+ "layout": "default",
49
+ "tasks": [
50
+ "readme"
51
+ ],
52
+ "plugins": [
53
+ "gulp-format-md"
54
+ ],
55
+ "related": {
56
+ "list": [
57
+ "git-user-name",
58
+ "git-username",
59
+ "parse-author",
60
+ "parse-authors",
61
+ "parse-github-url",
62
+ "parse-gitignore"
63
+ ]
64
+ },
65
+ "lint": {
66
+ "reflinks": true
67
+ }
68
+ }
69
+ }