All files / src/old parser.js

100% Statements 11/11
100% Branches 24/24
100% Functions 3/3
100% Lines 9/9

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 29 303x 3x 3x 3x     154x   154x               154x   154x                 3x    
const {pipe} = require('./pipe')
const {then} = require('./then')
const {toArgs: TO_ARGS} = require('./toArgs')
const {toOpts: TO_OPTS} = require('./toOpts')
 
function parser (stages = {}, options = {}) {
  const {checks = {}, parsers = {}, mode = 'sync'} = options
 
  const checksAndStages = {
    argv: [...(checks.argv || []), ...(stages.argv || [])],
    toOpts: stages.toOpts,
    opts: [...(checks.opts || []), ...(stages.opts || [])],
    toArgs: stages.toArgs,
    args: [...(checks.args || []), ...(stages.args || [])]
  }
 
  const {argv, toOpts = TO_OPTS, opts, toArgs, args} = checksAndStages
 
  return ({opts: OPTS = []} = {}) => (ARGV, ERRS) => (mode === 'async' ? then : pipe)(
    ...argv,
    toOpts(OPTS),
    ...opts,
    toArgs || TO_ARGS({_: parser(stages, {mode}), ...parsers, __: parser(stages, {mode})}, mode),
    ...args
  )({errs: ERRS, argv: ARGV})
}
 
module.exports = {
  parser
}