From 7956deb46e32830ab54f713040e6151de4a5ab9a Mon Sep 17 00:00:00 2001 From: Noritaka Kobayashi Date: Sun, 21 Sep 2025 13:14:09 +0900 Subject: [PATCH] refactor: replace if-then-else flow by a single return statement --- src/lib/isBase32.js | 6 +----- src/lib/isBase58.js | 5 +---- src/lib/isIBAN.js | 6 +----- src/lib/isIdentityCard.js | 12 ++---------- 4 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/lib/isBase32.js b/src/lib/isBase32.js index 5e2969cbc..81d30c9f5 100644 --- a/src/lib/isBase32.js +++ b/src/lib/isBase32.js @@ -16,9 +16,5 @@ export default function isBase32(str, options) { return crockfordBase32.test(str); } - const len = str.length; - if (len % 8 === 0 && base32.test(str)) { - return true; - } - return false; + return str.length % 8 === 0 && base32.test(str); } diff --git a/src/lib/isBase58.js b/src/lib/isBase58.js index 05c46dc18..f974d70d0 100644 --- a/src/lib/isBase58.js +++ b/src/lib/isBase58.js @@ -5,8 +5,5 @@ const base58Reg = /^[A-HJ-NP-Za-km-z1-9]*$/; export default function isBase58(str) { assertString(str); - if (base58Reg.test(str)) { - return true; - } - return false; + return base58Reg.test(str); } diff --git a/src/lib/isIBAN.js b/src/lib/isIBAN.js index ed0abd6c0..affd7a097 100644 --- a/src/lib/isIBAN.js +++ b/src/lib/isIBAN.js @@ -101,11 +101,7 @@ function hasOnlyValidCountryCodes(countryCodeArray) { const countryCodeArrayFilteredWithObjectIbanCode = countryCodeArray .filter(countryCode => !(countryCode in ibanRegexThroughCountryCode)); - if (countryCodeArrayFilteredWithObjectIbanCode.length > 0) { - return false; - } - - return true; + return countryCodeArrayFilteredWithObjectIbanCode.length === 0; } /** diff --git a/src/lib/isIdentityCard.js b/src/lib/isIdentityCard.js index fc37d4a29..7e20064e1 100644 --- a/src/lib/isIdentityCard.js +++ b/src/lib/isIdentityCard.js @@ -217,11 +217,7 @@ const validators = { // sanitize user input const sanitized = str.trim(); - // validate the data structure - if (!NIN.test(sanitized)) { - return false; - } - return true; + return NIN.test(sanitized); }, 'ar-TN': (str) => { const DNI = /^\d{8}$/; @@ -229,11 +225,7 @@ const validators = { // sanitize user input const sanitized = str.trim(); - // validate the data structure - if (!DNI.test(sanitized)) { - return false; - } - return true; + return DNI.test(sanitized); }, 'zh-CN': (str) => { const provincesAndCities = [