UNPKG

815 BJavaScriptView Raw
1'use strict';
2
3var utils = require('../utils');
4
5module.exports = function(app, options) {
6 return function(val, key, config, schema) {
7 if (typeof val === 'undefined') {
8 return;
9 }
10
11 if (val === true) {
12 return { show: true };
13 }
14
15 if (typeof val === 'string') {
16 val = val.split(',');
17 }
18
19 if (Array.isArray(val)) {
20 val = { list: val };
21 }
22
23 if (utils.isObject(val) && val.list) {
24 if (typeof val.list === 'string') {
25 val.list = val.list.split(',');
26 }
27
28 // we might have something like `{related: {list: {foo: true}}}`
29 if (utils.isObject(val.list)) {
30 val.list = Object.keys(val.list);
31 }
32
33 val.list = utils.unique(utils.unify(val.list));
34 val.list.sort();
35 }
36
37 config[key] = val;
38 return val;
39 };
40};