From 8a603c04d8705f8927c2840c840f1adb7ab14c1b Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Thu, 15 Jun 2017 15:29:36 +0200 Subject: [PATCH] Made `now cc add` case-unsensitive This closes #631 --- bin/now-billing-add.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/bin/now-billing-add.js b/bin/now-billing-add.js index 2725887..537663f 100644 --- a/bin/now-billing-add.js +++ b/bin/now-billing-add.js @@ -76,13 +76,34 @@ module.exports = function({ creditCards, currentTeam, user }) { if (!Object.hasOwnProperty.call(countries, country)) { continue } + if (country.startsWith(value)) { return country.substr(value.length) } + + const lowercaseCountry = country.toLowerCase() + const lowercaseValue = value.toLowerCase() + + if (lowercaseCountry.startsWith(lowercaseValue)) { + return lowercaseCountry.substr(value.length) + } } + return false }, - validateValue: value => countries[value] !== undefined + validateValue: value => { + for (const country in countries) { + if (!Object.hasOwnProperty.call(countries, country)) { + continue + } + + if (country.toLowerCase() === value.toLowerCase()) { + return true + } + } + + return false + } }, zipCode: { @@ -134,11 +155,13 @@ module.exports = function({ creditCards, currentTeam, user }) { if (key === 'cardNumber') { let brand = cardBrands[ccValidator.determineCardType(result)] piece.brand = brand + if (brand === 'American Express') { state.ccv.placeholder = '#'.repeat(4) } else { state.ccv.placeholder = '#'.repeat(3) } + brand = chalk.cyan(`[${brand}]`) const masked = chalk.gray('#### '.repeat(3)) + result.split(' ')[3] process.stdout.write(