Skip to content

Commit 2a8c9d6

Browse files
committed
validation
1 parent 5d830cd commit 2a8c9d6

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/validate.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
export default function validate() {}
1+
import forEach from 'lodash.foreach';
2+
import { is } from './utility';
3+
import { format } from 'util';
4+
5+
const rules = {
6+
// hook
7+
extensions: 'array',
8+
preprocessCss: 'function',
9+
processCss: 'function',
10+
to: 'string',
11+
// plugins
12+
append: 'array',
13+
prepend: 'array',
14+
use: 'array',
15+
createImportedName: 'function',
16+
generateScopedName: 'function|string',
17+
mode: 'string',
18+
rootDir: 'string',
19+
};
20+
21+
export default function validate(options = {}) {
22+
forEach(rules, (types, rule) => {
23+
if (!options[rule]) {
24+
return;
25+
}
26+
27+
if (!types.split('|').some(type => is(type, options[rule]))) {
28+
throw new Error(format('should specify %s for the %s', types, rule));
29+
};
30+
});
31+
}

0 commit comments

Comments
 (0)