From 924151463227250e69e745b1d43462ba5f431a6a Mon Sep 17 00:00:00 2001 From: Hayden Faulds Date: Wed, 13 Jul 2022 16:22:44 +0100 Subject: [PATCH] remove conditional chaining operator --- lib/utils/otplease.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/utils/otplease.js b/lib/utils/otplease.js index 44f9aaa89b7a3..6e6eb961d0491 100644 --- a/lib/utils/otplease.js +++ b/lib/utils/otplease.js @@ -6,11 +6,7 @@ async function otplease (npm, opts, fn) { throw err } - const isClassicOTP = - err.code === 'EOTP' || (err.code === 'E401' && /one-time pass/.test(err.body)) - const isWebOTP = err.code === 'EOTP' && err.body?.authUrl && err.body?.doneUrl - - if (isWebOTP) { + if (isWebOTP(err)) { const webAuth = require('./web-auth') const openUrlPrompt = require('./open-url-prompt') @@ -26,7 +22,7 @@ async function otplease (npm, opts, fn) { return await fn({ ...opts, otp }) } - if (isClassicOTP) { + if (isClassicOTP(err)) { const readUserInfo = require('./read-user-info.js') const otp = await readUserInfo.otp('This operation requires a one-time password.\nEnter OTP:') return await fn({ ...opts, otp }) @@ -36,4 +32,15 @@ async function otplease (npm, opts, fn) { } } +function isWebOTP (err) { + if (!err.code === 'EOTP' || !err.body) { + return false + } + return err.body?.authUrl && err.body?.doneUrl +} + +function isClassicOTP (err) { + return err.code === 'EOTP' || (err.code === 'E401' && /one-time pass/.test(err.body)) +} + module.exports = otplease