All files / src/toOpts option.js

100% Statements 17/17
100% Branches 12/12
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 26 27 28 297x   7x 618x 618x         618x   618x 1x 617x 383x 1444x 1444x   1444x 1444x       618x     7x    
const {illegalKeyName} = require('../errors')
 
const option = (opt = {}) => {
  const errs = []
  const args = {}
 
  const {
    key = null,
    args: ARGS = []
  } = opt
 
  if (key === '_') {
    errs.push(illegalKeyName({key, option: opt}))
  } else 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] = []
 
      const {__proto__: _2, ...rest} = opt
      args[arg].push(rest)
    }
  }
 
  return {errs, args}
}
 
module.exports = {
  option
}