Skip to content

Commit b5d7918

Browse files
committed
Added setConfigDefaults method.
Added tests.
1 parent 8e027c3 commit b5d7918

File tree

5 files changed

+87
-4
lines changed

5 files changed

+87
-4
lines changed

DOCUMENTATION.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Parse an input file with parser.
3535

3636
Parse array of directory globs and/or files, and then render the parsed data through the defined layout plugin.
3737

38-
parseInputs(['src/main.js'], {'parser': 'dox', 'layout': 'markdown'}).then(content => {});
38+
parseInputs(['src/main.js'], {'ignore': [], 'parser': 'dox', 'layout': 'markdown'}).then(content => {});
3939

4040

4141

@@ -44,6 +44,7 @@ Parse array of directory globs and/or files, and then render the parsed data thr
4444

4545
- **inputs** `Array` Array of directory globs and/or files.
4646
- **config** `Object` Configuration object.
47+
- **config.ignore** `String` Array of paths to ignore.
4748
- **config.parser** `String` String representing the parser to be used.
4849
- **config.layout** `String` String representing the layout plugin to be used.
4950

@@ -187,5 +188,28 @@ Format an array of directories and/or files to be ignored by globby by adding a
187188

188189

189190

191+
#### setConfigDefaults(config)
192+
193+
Sets default configuration values.
194+
195+
console.log(setConfigDefaults({}));
196+
197+
198+
199+
200+
##### Parameters
201+
202+
- **config** `Object` Custom configuration object.
203+
204+
205+
206+
207+
##### Returns
208+
209+
210+
- `Object` Modified configuration object.
211+
212+
213+
190214

191215
*Documentation generated with [doxdox](https://github.com/neogeek/doxdox).*

lib/doxdox.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ const parseInput = (input, config) =>
5353
/**
5454
* Parse array of directory globs and/or files, and then render the parsed data through the defined layout plugin.
5555
*
56-
* parseInputs(['src/main.js'], {'parser': 'dox', 'layout': 'markdown'}).then(content => {});
56+
* parseInputs(['src/main.js'], {'ignore': [], 'parser': 'dox', 'layout': 'markdown'}).then(content => {});
5757
*
5858
* @param {Array} inputs Array of directory globs and/or files.
5959
* @param {Object} config Configuration object.
60+
* @param {String} config.ignore Array of paths to ignore.
6061
* @param {String} config.parser String representing the parser to be used.
6162
* @param {String} config.layout String representing the layout plugin to be used.
6263
* @return {Object} Promise

lib/utils.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
const fs = require('fs');
44
const path = require('path');
55

6+
const DEFAULT_CONFIG_IGNORE_PATHS = [];
7+
const DEFAULT_CONFIG_PARSER = 'dox';
8+
const DEFAULT_CONFIG_PLUGIN = 'markdown';
9+
610
/**
711
* Finds package.json file from either the directory the script was called from or a supplied path.
812
*
@@ -60,7 +64,24 @@ const findPackageFileInPath = input => {
6064
const formatPathsArrayToIgnore = paths =>
6165
paths.map(path => `!${path.replace(/^!/, '')}`);
6266

67+
/**
68+
* Sets default configuration values.
69+
*
70+
* console.log(setConfigDefaults({}));
71+
*
72+
* @param {Object} config Custom configuration object.
73+
* @return {Object} Modified configuration object.
74+
* @public
75+
*/
76+
77+
const setConfigDefaults = config => Object.assign({}, {
78+
'ignore': DEFAULT_CONFIG_IGNORE_PATHS,
79+
'parser': DEFAULT_CONFIG_PARSER,
80+
'plugin': DEFAULT_CONFIG_PLUGIN
81+
}, config);
82+
6383
module.exports = {
6484
findPackageFileInPath,
65-
formatPathsArrayToIgnore
85+
formatPathsArrayToIgnore,
86+
setConfigDefaults
6687
};

test/fixtures/doxdox.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Parse an input file with parser.
3434

3535
Parse array of directory globs and/or files, and then render the parsed data through the defined layout plugin.
3636

37-
parseInputs(['src/main.js'], {'parser': 'dox', 'layout': 'markdown'}).then(content => {});
37+
parseInputs(['src/main.js'], {'ignore': [], 'parser': 'dox', 'layout': 'markdown'}).then(content => {});
3838

3939

4040

@@ -43,6 +43,7 @@ Parse array of directory globs and/or files, and then render the parsed data thr
4343

4444
- **inputs** `Array` Array of directory globs and/or files.
4545
- **config** `Object` Configuration object.
46+
- **config.ignore** `String` Array of paths to ignore.
4647
- **config.parser** `String` String representing the parser to be used.
4748
- **config.layout** `String` String representing the layout plugin to be used.
4849

test/specs/utils.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,40 @@ describe('doxdox utils', () => {
5454

5555
});
5656

57+
describe('setConfigDefaults', () => {
58+
59+
it('set defaults on empty object', () => {
60+
61+
assert.deepEqual(utils.setConfigDefaults({}), {
62+
'ignore': [],
63+
'parser': 'dox',
64+
'plugin': 'markdown'
65+
});
66+
67+
});
68+
69+
it('set defaults with no object', () => {
70+
71+
assert.deepEqual(utils.setConfigDefaults(), {
72+
'ignore': [],
73+
'parser': 'dox',
74+
'plugin': 'markdown'
75+
});
76+
77+
});
78+
79+
it('set defaults on object with custom values', () => {
80+
81+
assert.deepEqual(utils.setConfigDefaults({
82+
'plugin': 'bootstrap'
83+
}), {
84+
'ignore': [],
85+
'parser': 'dox',
86+
'plugin': 'bootstrap'
87+
});
88+
89+
});
90+
91+
});
92+
5793
});

0 commit comments

Comments
 (0)