summaryrefslogtreecommitdiffstats
path: root/fastify-busboy/benchmarks/common/contestantResolver.js
blob: 7cfc90ea2526559a0e152a723be044930839e505 (plain)
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
'use strict'

const getopts = require('getopts')

const options = getopts(process.argv.slice(1), {
  alias: {
    contestant: 'c'
  },
  default: {}
})

function resolveContestant (contestants) {
  const contestantId = options.contestant
  const contestant = Number.isFinite(contestantId)
    ? Object.values(contestants)[contestantId]
    : contestants[contestantId]

  if (!contestant) {
    throw new Error(`Unknown contestant ${contestantId}`)
  }
  return contestant
}

module.exports = {
  resolveContestant
}