UNPKG

1.2 kBJavaScriptView Raw
1'use strict';
2
3var utils = require('../utils');
4
5/**
6 * Set a value on the `related` property in package.json config.
7 *
8 * ```sh
9 * $ --config=related.highlight:micromatch
10 * //=> {verb: {related: {hightlight: 'micromatch'}}}
11 *
12 * $ --config=related.list:micromatch
13 * //=> {verb: {related: {list: ['micromatch']}}}
14 *
15 * $ --config=related.list:micromatch,generate
16 * //=> {verb: {related: {list: ['micromatch', 'generate']}}}
17 * ```
18 * @cli public
19 */
20
21module.exports = function(app) {
22 return {
23 type: ['array', 'object', 'string'],
24 normalize: function(val, key, config, schema) {
25 if (typeof val === 'undefined') {
26 return;
27 }
28
29 var highlight;
30 if (utils.isObject(val) && val.highlight) {
31 highlight = val.highlight;
32
33 if (utils.isObject(val.highlight)) {
34 highlight = Object.keys(val.highlight)[0];
35 }
36 }
37
38 if (utils.isObject(val) && val.list) {
39 val.list = utils.arrayify(val.list);
40 return val;
41 }
42
43 var obj = {};
44 obj.list = utils.arrayify(val);
45 if (utils.isString(highlight)) {
46 obj.highlight = highlight;
47 }
48
49 config[key] = obj;
50 return obj;
51 }
52 };
53};
54