Skip to content

Commit f06caee

Browse files
authored
refactor: replace if-then-else flow by a single return statement (#2592)
1 parent 9fa1e3a commit f06caee

File tree

4 files changed

+5
-24
lines changed

4 files changed

+5
-24
lines changed

src/lib/isBase32.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,5 @@ export default function isBase32(str, options) {
1616
return crockfordBase32.test(str);
1717
}
1818

19-
const len = str.length;
20-
if (len % 8 === 0 && base32.test(str)) {
21-
return true;
22-
}
23-
return false;
19+
return str.length % 8 === 0 && base32.test(str);
2420
}

src/lib/isBase58.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,5 @@ const base58Reg = /^[A-HJ-NP-Za-km-z1-9]*$/;
55

66
export default function isBase58(str) {
77
assertString(str);
8-
if (base58Reg.test(str)) {
9-
return true;
10-
}
11-
return false;
8+
return base58Reg.test(str);
129
}

src/lib/isIBAN.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ function hasOnlyValidCountryCodes(countryCodeArray) {
101101
const countryCodeArrayFilteredWithObjectIbanCode = countryCodeArray
102102
.filter(countryCode => !(countryCode in ibanRegexThroughCountryCode));
103103

104-
if (countryCodeArrayFilteredWithObjectIbanCode.length > 0) {
105-
return false;
106-
}
107-
108-
return true;
104+
return countryCodeArrayFilteredWithObjectIbanCode.length === 0;
109105
}
110106

111107
/**

src/lib/isIdentityCard.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,23 +217,15 @@ const validators = {
217217
// sanitize user input
218218
const sanitized = str.trim();
219219

220-
// validate the data structure
221-
if (!NIN.test(sanitized)) {
222-
return false;
223-
}
224-
return true;
220+
return NIN.test(sanitized);
225221
},
226222
'ar-TN': (str) => {
227223
const DNI = /^\d{8}$/;
228224

229225
// sanitize user input
230226
const sanitized = str.trim();
231227

232-
// validate the data structure
233-
if (!DNI.test(sanitized)) {
234-
return false;
235-
}
236-
return true;
228+
return DNI.test(sanitized);
237229
},
238230
'zh-CN': (str) => {
239231
const provincesAndCities = [

0 commit comments

Comments
 (0)