-
Notifications
You must be signed in to change notification settings - Fork 61
/
validatePrimaryOption.js
77 lines (64 loc) · 1.63 KB
/
validatePrimaryOption.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const _ = require('lodash');
module.exports = function validatePrimaryOption(actualOptions) {
// Otherwise, begin checking array options
if (!Array.isArray(actualOptions)) {
return false;
}
// Every item in the array must be a certain string or an object
// with a "type" property
if (
!actualOptions.every((item) => {
if (_.isString(item)) {
return [
'custom-properties',
'dollar-variables',
'at-variables',
'declarations',
'rules',
'at-rules',
'less-mixins',
].includes(item);
}
return _.isPlainObject(item) && !_.isUndefined(item.type);
})
) {
return false;
}
const objectItems = actualOptions.filter(_.isPlainObject);
if (
!objectItems.every((item) => {
let result = true;
if (item.type !== 'at-rule' && item.type !== 'rule') {
return false;
}
if (item.type === 'at-rule') {
// if parameter is specified, name should be specified also
if (!_.isUndefined(item.parameter) && _.isUndefined(item.name)) {
return false;
}
if (!_.isUndefined(item.hasBlock)) {
result = item.hasBlock === true || item.hasBlock === false;
}
if (!_.isUndefined(item.name)) {
result = _.isString(item.name) && item.name.length;
}
if (!_.isUndefined(item.parameter)) {
result =
(_.isString(item.parameter) && item.parameter.length) ||
_.isRegExp(item.parameter);
}
}
if (item.type === 'rule') {
if (!_.isUndefined(item.selector)) {
result =
(_.isString(item.selector) && item.selector.length) ||
_.isRegExp(item.selector);
}
}
return result;
})
) {
return false;
}
return true;
};