|
1 | 1 | var _ = require('lodash'); |
2 | 2 |
|
| 3 | +var presets = { |
| 4 | + bem: require('../../presets/bem.json') |
| 5 | +}; |
| 6 | + |
3 | 7 | /** |
4 | 8 | * Sets options |
5 | | - * @param {Object} [options] |
| 9 | + * @param {Object|String} [options] options or preset name |
| 10 | + * @param {String} [options.preset] |
6 | 11 | * @param {String[]} [options.ignoreAttributes] |
7 | 12 | * @param {String[]} [options.compareAttributesAsJSON] |
8 | 13 | * @param {Boolean} [options.ignoreWhitespaces=true] |
9 | 14 | * @param {Boolean} [options.ignoreComments=true] |
10 | | - * @param {Boolean} [options.ignoreClosingTags=false] |
| 15 | + * @param {Boolean} [options.ignoreEndTags=false] |
11 | 16 | * @param {Boolean} [options.ignoreDuplicateAttributes=false] |
12 | 17 | * returns {Object} |
13 | 18 | */ |
14 | 19 | module.exports = function (options) { |
15 | 20 | if (typeof options === 'string') { |
16 | | - if (options === 'bem') { |
17 | | - options = { |
18 | | - // ignore generated attributes |
19 | | - ignoreAttributes: ['id', 'for', 'aria-labelledby', 'aria-describedby'], |
20 | | - compareAttributesAsJSON: [ |
21 | | - 'data-bem', |
22 | | - { name: 'onclick', isFunction: true }, |
23 | | - { name: 'ondblclick', isFunction: true } |
24 | | - ] |
25 | | - }; |
26 | | - } else { |
27 | | - console.error(options.bold.red + ' is an invalid preset name. Use ' + 'bem'.bold.green + ' instead.'); |
28 | | - process.exit(1); |
| 21 | + options = { preset: options }; |
| 22 | + } |
| 23 | + |
| 24 | + if (options && options.preset) { |
| 25 | + var preset = String(options.preset); |
| 26 | + if (!presets.hasOwnProperty(preset)) { |
| 27 | + throw Error(preset + ' is an invalid preset name.'); |
29 | 28 | } |
| 29 | + |
| 30 | + delete options.preset; |
| 31 | + options = _.defaults(options, presets[preset]); |
30 | 32 | } |
31 | 33 |
|
32 | 34 | return _.defaults(options || {}, { |
|
0 commit comments