smtp/address: use `if`/`else` instead of ternary

This commit is contained in:
Zack Schuster 2022-09-27 10:04:05 -07:00
parent dabdbbd5eb
commit 19fd8338f5
3 changed files with 22 additions and 17 deletions

View File

@ -143,8 +143,8 @@ function convertAddressTokens(tokens) {
if (addresses.length === 0) { if (addresses.length === 0) {
for (let i = texts.length - 1; i >= 0; i--) { for (let i = texts.length - 1; i >= 0; i--) {
const text = texts[i]; const text = texts[i];
texts[i] = text if ((text === null || text === void 0 ? void 0 : text.length) > 0) {
? text texts[i] = text
.replace(/\s*\b[^@\s]+@[^@\s]+\b\s*/, (address) => { .replace(/\s*\b[^@\s]+@[^@\s]+\b\s*/, (address) => {
if (addresses.length === 0) { if (addresses.length === 0) {
addresses = [address.trim()]; addresses = [address.trim()];
@ -154,8 +154,11 @@ function convertAddressTokens(tokens) {
return address; return address;
} }
}) })
.trim() .trim();
: ''; }
else {
texts[i] = '';
}
if (addresses.length > 0) { if (addresses.length > 0) {
break; break;
} }

File diff suppressed because one or more lines are too long

View File

@ -147,18 +147,20 @@ function convertAddressTokens(tokens: AddressToken[]) {
if (addresses.length === 0) { if (addresses.length === 0) {
for (let i = texts.length - 1; i >= 0; i--) { for (let i = texts.length - 1; i >= 0; i--) {
const text = texts[i]; const text = texts[i];
texts[i] = text if (text?.length > 0) {
? text texts[i] = text
.replace(/\s*\b[^@\s]+@[^@\s]+\b\s*/, (address: string) => { .replace(/\s*\b[^@\s]+@[^@\s]+\b\s*/, (address: string) => {
if (addresses.length === 0) { if (addresses.length === 0) {
addresses = [address.trim()]; addresses = [address.trim()];
return ' '; return ' ';
} else { } else {
return address; return address;
} }
}) })
.trim() .trim();
: ''; } else {
texts[i] = '';
}
if (addresses.length > 0) { if (addresses.length > 0) {
break; break;