-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathdefaults.js
More file actions
48 lines (40 loc) · 1.33 KB
/
defaults.js
File metadata and controls
48 lines (40 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var _ = require('lodash');
var presets = {
bem: require('../presets/bem.json')
};
/**
* Sets options
* @param {Object|String} [options] options or preset name
* @param {String} [options.preset]
* @param {String[]} [options.ignoreAttributes]
* @param {String[]} [options.compareAttributesAsJSON]
* @param {Boolean} [options.ignoreWhitespaces=true]
* @param {Boolean} [options.ignoreComments=true]
* @param {Boolean} [options.ignoreEndTags=false]
* @param {Boolean} [options.ignoreDuplicateAttributes=false]
* @param {Boolean} [options.ignoreEmptyAttributes=false]
* returns {Object}
*/
module.exports = function (options) {
if (typeof options === 'string') {
options = { preset: options };
}
if (options && options.preset) {
var preset = String(options.preset);
if (!presets.hasOwnProperty(preset)) {
throw Error(preset + ' is an invalid preset name.');
}
delete options.preset;
options = _.defaults(options, presets[preset]);
}
return _.defaults(options || {}, {
ignoreAttributes: [],
compareAttributesAsJSON: [],
ignoreWhitespaces: true,
ignoreComments: true,
ignoreEndTags: false,
ignoreDuplicateAttributes: false,
ignoreEmptyAttributes: false
});
};
module.exports.presets = presets;