summaryrefslogtreecommitdiffstats
path: root/fastify-busboy/benchmarks/common/contestantResolver.js
diff options
context:
space:
mode:
Diffstat (limited to 'fastify-busboy/benchmarks/common/contestantResolver.js')
-rw-r--r--fastify-busboy/benchmarks/common/contestantResolver.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/fastify-busboy/benchmarks/common/contestantResolver.js b/fastify-busboy/benchmarks/common/contestantResolver.js
new file mode 100644
index 0000000..7cfc90e
--- /dev/null
+++ b/fastify-busboy/benchmarks/common/contestantResolver.js
@@ -0,0 +1,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
+}