1 | 'use strict';
|
2 |
|
3 | var utils = require('../utils');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | module.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 |
|