All files / src/dsl/fp option.js

100% Statements 17/17
100% Branches 20/20
100% Functions 1/1
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 261x   1x 302x   302x 302x   302x 102x     302x 102x     302x 100x 860x 860x 860x       302x  
const {noArgumentProvidedInOption, noArgumentsProvidedInOption} = require('../../errors')
 
module.exports = (options = {}) => {
  const {key = null, args: ARGS = [], types = null, only = null, desc = '', opts = null} = options
 
  const errs = []
  const args = {}
 
  if (key === null) {
    errs.push(noArgumentProvidedInOption({options}))
  }
  
  if (ARGS === null || ARGS.length === 0) {
    errs.push(noArgumentsProvidedInOption({options}))
  }
  
  if (key !== null && ARGS !== null && ARGS.length > 0) {
    for (let i = 0; i < ARGS.length; i++) {
      const arg  = ARGS[i]
      if (typeof args[arg] === 'undefined') args[arg] = []
      args[arg].push({key, types, only, desc, opts})
    }
  }
 
  return {errs, args}
}