1 | const _ = require('lodash');
|
2 |
|
3 | const VALID_STRATEGIES = ['inline', 'symbol'];
|
4 |
|
5 | function validateStrategy(options) {
|
6 | let strategyOpt = options.strategy;
|
7 |
|
8 | if (!(_.isString(strategyOpt) || _.isArray(strategyOpt))) {
|
9 | return 'Invalid strategy value. It must be a string or an array.';
|
10 | }
|
11 |
|
12 | let isInvalid = _
|
13 | .castArray(strategyOpt)
|
14 | .some((strategy) => VALID_STRATEGIES.indexOf(strategy) === -1);
|
15 |
|
16 | if (isInvalid) {
|
17 | let validOptions = VALID_STRATEGIES.join(', ');
|
18 | return `Invalid strategy found. Valid options are ${validOptions}.`;
|
19 | }
|
20 | }
|
21 |
|
22 | module.exports = function validateOptions(options) {
|
23 | let validators = [
|
24 | validateStrategy
|
25 | ];
|
26 |
|
27 | validators.forEach((validate) => {
|
28 | let error = validate(options);
|
29 |
|
30 | if (error) {
|
31 | throw new Error(`ember-svg-jar: ${error}`);
|
32 | }
|
33 | });
|
34 | };
|