all files / src/ validate.js

94.44% Statements 17/18
83.33% Branches 10/12
100% Functions 4/4
87.5% Lines 7/8
1 branch Ignored     
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                                      23× 253× 222×     31×          
import forEach from 'lodash.foreach';
import { is } from './utility';
import { format } from 'util';
 
const rules = {
  // hook
  extensions:         'array',
  preprocessCss:      'function',
  processCss:         'function',
  to:                 'string',
  // plugins
  append:             'array',
  prepend:            'array',
  use:                'array',
  createImportedName: 'function',
  generateScopedName: 'function|string',
  mode:               'string',
  rootDir:            'string',
};
 
export default function validate(options = {}) {
  forEach(rules, (types, rule) => {
    if (!options[rule]) {
      return;
    }
 
    Iif (!types.split('|').some(type => is(type, options[rule]))) {
      throw new Error(format('should specify %s for the %s', types, rule));
    }
  });
}