JavaScript string compare '' is always a ToBoolean

See https://www.ecma-international.org/ecma-262/5.1/#sec-9.2
This commit is contained in:
djmaze 2020-07-28 17:20:14 +02:00
parent 82bed1ed80
commit 2ba34532c2
57 changed files with 213 additions and 218 deletions

View file

@ -65,8 +65,8 @@ class LoginAdminView extends AbstractViewNext {
this.loginError(false);
this.passwordError(false);
this.loginError('' === trim(this.login()));
this.passwordError('' === trim(this.password()));
this.loginError(!trim(this.login()));
this.passwordError(!trim(this.password()));
if (this.loginError() || this.passwordError()) {
return false;

View file

@ -44,8 +44,8 @@ class AccountPopupView extends AbstractViewNext {
@command((self) => !self.submitRequest())
addAccountCommand() {
this.emailError('' === trim(this.email()));
this.passwordError('' === trim(this.password()));
this.emailError(!trim(this.email()));
this.passwordError(!trim(this.password()));
if (this.emailError() || this.passwordError()) {
return false;

View file

@ -47,7 +47,7 @@ class ActivatePopupView extends AbstractViewNext {
}
@command(
(self) => !self.activateProcess() && '' !== self.domain() && '' !== self.key() && !self.activationSuccessed()
(self) => !self.activateProcess() && self.domain() && self.key() && !self.activationSuccessed()
)
activateCommand() {
this.activateProcess(true);
@ -110,7 +110,7 @@ class ActivatePopupView extends AbstractViewNext {
validateSubscriptionKey() {
const value = this.key();
return (
'' === value ||
!value ||
RAINLOOP_TRIAL_KEY === value ||
!!/^RL[\d]+-[A-Z0-9-]+Z$/.test(trim(value).replace(/[^A-Z0-9-]/gi, ''))
);

View file

@ -39,7 +39,7 @@ class AddOpenPgpKeyPopupView extends AbstractViewNext {
keyTrimmed = keyTrimmed.replace(/[\r]+/g, '').replace(/[\n]{2,}/g, '\n\n');
}
this.key.error('' === keyTrimmed);
this.key.error(!keyTrimmed);
this.key.errorMessage('');
if (!openpgpKeyring || this.key.error()) {

View file

@ -46,7 +46,7 @@ class AdvancedSearchPopupView extends AbstractViewNext {
@command()
searchCommand() {
const search = this.buildSearchString();
if ('' !== search) {
if (search) {
MessageStore.mainMessageListSearch(search);
}
@ -87,15 +87,15 @@ class AdvancedSearchPopupView extends AbstractViewNext {
isPart = [],
hasPart = [];
if (from_ && '' !== from_) {
if (from_) {
result.push('from:' + this.buildSearchStringValue(from_));
}
if (to && '' !== to) {
if (to) {
result.push('to:' + this.buildSearchStringValue(to));
}
if (subject && '' !== subject) {
if (subject) {
result.push('subject:' + this.buildSearchStringValue(subject));
}
@ -123,7 +123,7 @@ class AdvancedSearchPopupView extends AbstractViewNext {
result.push('date:' + searchSubtractFormatDateHelper(this.selectedDateValue()) + '/');
}
if (text && '' !== text) {
if (text) {
result.push('text:' + this.buildSearchStringValue(text));
}

View file

@ -227,12 +227,12 @@ class ComposePopupView extends AbstractViewNext {
this.attachmentsInProcess = ko.computed(() => this.attachments().filter(item => item && !item.complete()));
this.attachmentsInReady = ko.computed(() => this.attachments().filter(item => item && item.complete()));
this.attachmentsInError = ko.computed(() => this.attachments().filter(item => item && '' !== item.error()));
this.attachmentsInError = ko.computed(() => this.attachments().filter(item => item && item.error()));
this.attachmentsCount = ko.computed(() => this.attachments().length);
this.attachmentsInErrorCount = ko.computed(() => this.attachmentsInError().length);
this.attachmentsInProcessCount = ko.computed(() => this.attachmentsInProcess().length);
this.isDraftFolderMessage = ko.computed(() => '' !== this.draftFolder() && '' !== this.draftUid());
this.isDraftFolderMessage = ko.computed(() => this.draftFolder() && this.draftUid());
this.attachmentsPlace = ko.observable(false);
@ -360,7 +360,7 @@ class ComposePopupView extends AbstractViewNext {
this.attachmentsPlace(true);
}
if ('' === sTo && '' === sCc && '' === sBcc) {
if (!sTo && !sCc && !sBcc) {
this.emptyToError(true);
}
@ -380,7 +380,7 @@ class ComposePopupView extends AbstractViewNext {
sSentFolder = UNUSED_OPTION_VALUE;
}
if ('' === sSentFolder) {
if (!sSentFolder) {
showScreenPopup(require('View/Popup/FolderSystem'), [SetSystemFoldersNotification.Sent]);
} else {
this.sendError(false);
@ -564,7 +564,7 @@ class ComposePopupView extends AbstractViewNext {
reloadDraftFolder() {
const draftFolder = FolderStore.draftFolder();
if ('' !== draftFolder && UNUSED_OPTION_VALUE !== draftFolder) {
if (draftFolder && UNUSED_OPTION_VALUE !== draftFolder) {
setFolderHash(draftFolder, '');
if (FolderStore.currentFolderFullNameRaw() === draftFolder) {
getApp().reloadMessageList(true);
@ -736,7 +736,7 @@ class ComposePopupView extends AbstractViewNext {
signature = signature.replace(/[\r]/g, '');
fromLine = this.oLastMessage ? this.emailArrayToStringLineHelper(this.oLastMessage.from, true) : '';
if ('' !== fromLine) {
if (fromLine) {
signature = signature.replace(/{{FROM-FULL}}/g, fromLine);
if (!fromLine.includes(' ') && 0 < fromLine.indexOf('@')) {
@ -793,7 +793,7 @@ class ComposePopupView extends AbstractViewNext {
let isHtml = false,
signature = identity.signature();
if ('' !== signature) {
if (signature) {
if (':HTML:' === signature.substr(0, 6)) {
isHtml = true;
signature = signature.substr(6);
@ -837,7 +837,7 @@ class ComposePopupView extends AbstractViewNext {
this.addEmailsTo(this.cc, aCcEmails);
this.addEmailsTo(this.bcc, aBccEmails);
if (isNormal(sCustomSubject) && '' !== sCustomSubject && '' === this.subject()) {
if (isNormal(sCustomSubject) && sCustomSubject && !this.subject()) {
this.subject(sCustomSubject);
}
}
@ -862,7 +862,7 @@ class ComposePopupView extends AbstractViewNext {
values = emails.map(item => item ? item.toLine(false) : null)
.filter((value, index, self) => !!value && self.indexOf(value) == index);
fKoValue(value + ('' === value ? '' : ', ') + trim(values.join(', ')));
fKoValue(value + (value ? ', ' : '') + trim(values.join(', ')));
}
}
@ -939,7 +939,7 @@ class ComposePopupView extends AbstractViewNext {
this.bcc(this.emailArrayToStringLineHelper(aBccEmails));
}
if ('' !== lineComposeType && message) {
if (lineComposeType && message) {
sDate = momentorFormat(message.dateTimeStampInUTC(), 'FULL');
sSubject = message.subject();
aDraftInfo = message.aDraftInfo;
@ -1171,7 +1171,7 @@ class ComposePopupView extends AbstractViewNext {
setFocusInPopup() {
if (!bMobileDevice) {
setTimeout(() => {
if ('' === this.to()) {
if (!this.to()) {
this.to.focused(true);
} else if (this.oEditor) {
if (!this.to.focused()) {
@ -1379,7 +1379,7 @@ class ComposePopupView extends AbstractViewNext {
}
if (attachment) {
if ('' !== error && error.length) {
if (error && error.length) {
attachment
.waiting(false)
.uploading(false)
@ -1413,7 +1413,7 @@ class ComposePopupView extends AbstractViewNext {
prepearAttachmentsForSendOrSave() {
const result = {};
this.attachmentsInReady().forEach(item => {
if (item && '' !== item.tempName() && item.enabled()) {
if (item && item.tempName() && item.enabled()) {
result[item.tempName()] = [item.fileName(), item.isInline ? '1' : '0', item.CID, item.contentLocation];
}
});
@ -1552,7 +1552,7 @@ class ComposePopupView extends AbstractViewNext {
!this.replyTo().length &&
!this.subject().length &&
withoutAttachment &&
(!this.oEditor || '' === this.oEditor.getData())
(!this.oEditor || !this.oEditor.getData())
);
}
@ -1606,7 +1606,7 @@ class ComposePopupView extends AbstractViewNext {
* @returns {Array}
*/
getAttachmentsDownloadsForUpload() {
return this.attachments().filter(item => item && '' === item.tempName()).map(
return this.attachments().filter(item => item && !item.tempName()).map(
item => item.id
);
}

View file

@ -345,15 +345,15 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
this.resultCallback = fCallback;
if ('' !== sTo) {
if (sTo) {
rec.push(sTo);
}
if ('' !== sCc) {
if (sCc) {
rec.push(sCc);
}
if ('' !== sBcc) {
if (sBcc) {
rec.push(sBcc);
}
@ -361,7 +361,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
rec = rec.map(value => {
email.clear();
email.parse(trim(value));
return '' === email.email ? false : email.email;
return email.email || false;
}).filter(value => !!value);
if (identity && identity.email()) {

View file

@ -116,7 +116,7 @@ class ContactsPopupView extends AbstractViewNext {
this.viewHasNonEmptyRequiredProperties = ko.computed(() => {
const names = this.viewPropertiesNames(),
emails = this.viewPropertiesEmails(),
fFilter = (property) => '' !== trim(property.value());
fFilter = (property) => !!trim(property.value());
return !!(names.find(fFilter) || emails.find(fFilter));
});
@ -126,12 +126,12 @@ class ContactsPopupView extends AbstractViewNext {
);
this.viewPropertiesEmailsNonEmpty = ko.computed(() =>
this.viewPropertiesNames().filter(property => '' !== trim(property.value()))
this.viewPropertiesNames().filter(property => !!trim(property.value()))
);
const propertyFocused = (property) => {
const focused = property.focused();
return '' === trim(property.value()) && !focused;
return !trim(property.value()) && !focused;
};
this.viewPropertiesEmailsEmptyAndOnFocused = ko.computed(() =>
@ -303,7 +303,7 @@ class ContactsPopupView extends AbstractViewNext {
properties = [];
this.viewProperties().forEach(oItem => {
if (oItem.type() && oItem.type() !== ContactPropertyType.FullName && '' !== trim(oItem.value())) {
if (oItem.type() && oItem.type() !== ContactPropertyType.FullName && trim(oItem.value())) {
properties.push([oItem.type(), oItem.value(), oItem.typeStr()]);
}
});
@ -320,7 +320,7 @@ class ContactsPopupView extends AbstractViewNext {
oData.Result.RequestUid === requestUid &&
0 < pInt(oData.Result.ResultID)
) {
if ('' === this.viewID()) {
if (!this.viewID()) {
this.viewID(pInt(oData.Result.ResultID));
}
@ -610,7 +610,7 @@ class ContactsPopupView extends AbstractViewNext {
this.contacts(list);
this.contacts.loading(false);
this.viewClearSearch('' !== this.search());
this.viewClearSearch(!!this.search());
},
offset,
CONTACTS_PER_PAGE,

View file

@ -97,10 +97,9 @@ class DomainPopupView extends AbstractViewNext {
result += ' ← ' + aliasName;
}
} else {
result =
'' === name
? i18n('POPUPS_DOMAIN/TITLE_ADD_DOMAIN')
: i18n('POPUPS_DOMAIN/TITLE_ADD_DOMAIN_WITH_NAME', { 'NAME': name });
result = name
? i18n('POPUPS_DOMAIN/TITLE_ADD_DOMAIN_WITH_NAME', { 'NAME': name })
: i18n('POPUPS_DOMAIN/TITLE_ADD_DOMAIN');
}
return result;
@ -117,11 +116,11 @@ class DomainPopupView extends AbstractViewNext {
useSieve = this.useSieve();
return (
'' !== this.name() &&
'' !== this.imapServer() &&
'' !== this.imapPort() &&
(allowSieve && useSieve ? '' !== this.sieveServer() && '' !== this.sievePort() : true) &&
(('' !== this.smtpServer() && '' !== this.smtpPort()) || usePhpMail)
this.name() &&
this.imapServer() &&
this.imapPort() &&
(allowSieve && useSieve ? this.sieveServer() && this.sievePort() : true) &&
((this.smtpServer() && this.smtpPort()) || usePhpMail)
);
});
@ -134,19 +133,19 @@ class DomainPopupView extends AbstractViewNext {
// smart form improvements
this.imapServerFocus.subscribe((value) => {
if (value && '' !== this.name() && '' === this.imapServer()) {
if (value && this.name() && !this.imapServer()) {
this.imapServer(this.name().replace(/[.]?[*][.]?/g, ''));
}
});
this.sieveServerFocus.subscribe((value) => {
if (value && '' !== this.imapServer() && '' === this.sieveServer()) {
if (value && this.imapServer() && !this.sieveServer()) {
this.sieveServer(this.imapServer());
}
});
this.smtpServerFocus.subscribe((value) => {
if (value && '' !== this.imapServer() && '' === this.smtpServer()) {
if (value && this.imapServer() && !this.smtpServer()) {
this.smtpServer(this.imapServer().replace(/imap/gi, 'smtp'));
}
});
@ -381,7 +380,7 @@ class DomainPopupView extends AbstractViewNext {
}
onShowWithDelay() {
if ('' === this.name() && !bMobileDevice) {
if (!this.name() && !bMobileDevice) {
this.name.focused(true);
}
}

View file

@ -35,7 +35,7 @@ class DomainAliasPopupView extends AbstractViewNext {
this.domains().map(item => ({ optValue: item.name, optText: item.name }))
);
this.canBeSaved = ko.computed(() => !this.saving() && '' !== this.name() && '' !== this.alias());
this.canBeSaved = ko.computed(() => !this.saving() && this.name() && this.alias());
this.onDomainAliasCreateOrSaveResponse = this.onDomainAliasCreateOrSaveResponse.bind(this);
}
@ -65,7 +65,7 @@ class DomainAliasPopupView extends AbstractViewNext {
}
onShowWithDelay() {
if ('' === this.name() && !bMobileDevice) {
if (!this.name() && !bMobileDevice) {
this.name.focused(true);
}
}

View file

@ -36,7 +36,7 @@ class FolderCreateView extends AbstractViewNext {
top.push(['', '']);
let fDisableCallback = null;
if ('' !== FolderStore.namespace) {
if (FolderStore.namespace) {
fDisableCallback = (item) => FolderStore.namespace !== item.fullNameRaw.substr(0, FolderStore.namespace.length);
}
@ -49,7 +49,7 @@ class FolderCreateView extends AbstractViewNext {
@command((self) => self.simpleFolderNameValidation(self.folderName()))
createFolderCommand() {
let parentFolderName = this.selectedParentValue();
if ('' === parentFolderName && 1 < FolderStore.namespace.length) {
if (!parentFolderName && 1 < FolderStore.namespace.length) {
parentFolderName = FolderStore.namespace.substr(0, FolderStore.namespace.length - 1);
}

View file

@ -62,7 +62,7 @@ class IdentityPopupView extends AbstractViewNext {
}
if (!this.email.hasError()) {
this.email.hasError('' === trim(this.email()));
this.email.hasError(!trim(this.email()));
}
if (this.email.hasError()) {
@ -151,7 +151,7 @@ class IdentityPopupView extends AbstractViewNext {
this.signature(identity.signature());
this.signatureInsertBefore(identity.signatureInsertBefore());
this.owner('' === this.id);
this.owner(!this.id);
} else {
this.id = fakeMd5();
}

View file

@ -39,13 +39,13 @@ class NewOpenPgpKeyPopupView extends AbstractViewNext {
const userId = {},
openpgpKeyring = PgpStore.openpgpKeyring;
this.email.error('' === trim(this.email()));
this.email.error(!trim(this.email()));
if (!openpgpKeyring || this.email.error()) {
return false;
}
userId.email = this.email();
if ('' !== this.name()) {
if (this.name()) {
userId.name = this.name();
}

View file

@ -28,7 +28,7 @@ class PluginPopupView extends AbstractViewNext {
this.configures = ko.observableArray([]);
this.hasReadme = ko.computed(() => '' !== this.readme());
this.hasReadme = ko.computed(() => !!this.readme());
this.hasConfiguration = ko.computed(() => 0 < this.configures().length);
this.readmePopoverConf = {

View file

@ -49,8 +49,8 @@ class TemplatePopupView extends AbstractViewNext {
addTemplateCommand() {
this.populateBodyFromEditor();
this.name.error('' === trim(this.name()));
this.body.error('' === trim(this.body()) || ':HTML:' === trim(this.body()));
this.name.error(!trim(this.name()));
this.body.error(!trim(this.body()) || ':HTML:' === trim(this.body()));
if (this.name.error() || this.body.error()) {
return false;

View file

@ -25,7 +25,7 @@ class TwoFactorTestPopupView extends AbstractViewNext {
this.testing = ko.observable(false);
}
@command((self) => '' !== self.code() && !self.testing())
@command((self) => self.code() && !self.testing())
testCodeCommand() {
this.testing(true);
Remote.testTwoFactor((result, data) => {

View file

@ -115,7 +115,7 @@ class LoginUserView extends AbstractViewNext {
this.submitErrorAddidional = ko.observable('');
this.submitError.subscribe((value) => {
if ('' === value) {
if (!value) {
this.submitErrorAddidional('');
}
});
@ -154,12 +154,12 @@ class LoginUserView extends AbstractViewNext {
this.emailError(false);
this.passwordError(false);
this.emailError('' === trim(this.email()));
this.passwordError('' === trim(this.password()));
this.emailError(!trim(this.email()));
this.passwordError(!trim(this.password()));
if (this.additionalCode.visibility()) {
this.additionalCode.error(false);
this.additionalCode.error('' === trim(this.additionalCode()));
this.additionalCode.error(!trim(this.additionalCode()));
}
if (
@ -195,7 +195,7 @@ class LoginUserView extends AbstractViewNext {
if (0 < pluginResultCode) {
this.submitError(getNotification(pluginResultCode));
return false;
} else if ('' !== pluginResultMessage) {
} else if (pluginResultMessage) {
this.submitError(pluginResultMessage);
return false;
}
@ -230,7 +230,7 @@ class LoginUserView extends AbstractViewNext {
this.submitError(getNotificationFromResponse(oData));
if ('' === this.submitError()) {
if (!this.submitError()) {
this.submitError(getNotification(Notification.UnknownError));
} else if (oData.ErrorMessageAdditional) {
this.submitErrorAddidional(oData.ErrorMessageAdditional);
@ -269,11 +269,11 @@ class LoginUserView extends AbstractViewNext {
}
onShowWithDelay() {
if ('' !== this.email() && '' !== this.password()) {
if (this.email() && this.password()) {
this.passwordFocus(true);
} else if ('' === this.email()) {
} else if (!this.email()) {
this.emailFocus(true);
} else if ('' === this.password()) {
} else if (!this.password()) {
this.passwordFocus(true);
} else {
this.emailFocus(true);

View file

@ -245,7 +245,7 @@ class FolderListMailBoxUserView extends AbstractViewNext {
copy = $htmlCL.contains('rl-ctrl-key-pressed'),
uids = ui.helper.data('rl-uids');
if (isNormal(fromFolderFullNameRaw) && '' !== fromFolderFullNameRaw && isArray(uids)) {
if (fromFolderFullNameRaw && isNormal(fromFolderFullNameRaw) && isArray(uids)) {
getApp().moveMessagesToFolder(fromFolderFullNameRaw, uids, toFolder.fullNameRaw, copy);
}
}

View file

@ -135,7 +135,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
this.messageListSearchDesc = ko.computed(() => {
const value = MessageStore.messageListEndSearch();
return '' === value ? '' : i18n('MESSAGE_LIST/SEARCH_RESULT_FOR', { 'SEARCH': value });
return value ? i18n('MESSAGE_LIST/SEARCH_RESULT_FOR', { 'SEARCH': value }) : '';
});
this.messageListPagenator = ko.computed(
@ -172,25 +172,25 @@ class MessageListMailBoxUserView extends AbstractViewNext {
this.hasCheckedOrSelectedLines = ko.computed(() => 0 < this.messageListCheckedOrSelected().length);
this.isSpamFolder = ko.computed(
() => FolderStore.spamFolder() === this.messageListEndFolder() && '' !== FolderStore.spamFolder()
() => FolderStore.spamFolder() === this.messageListEndFolder() && FolderStore.spamFolder()
);
this.isSpamDisabled = ko.computed(() => UNUSED_OPTION_VALUE === FolderStore.spamFolder());
this.isTrashFolder = ko.computed(
() => FolderStore.trashFolder() === this.messageListEndFolder() && '' !== FolderStore.trashFolder()
() => FolderStore.trashFolder() === this.messageListEndFolder() && FolderStore.trashFolder()
);
this.isDraftFolder = ko.computed(
() => FolderStore.draftFolder() === this.messageListEndFolder() && '' !== FolderStore.draftFolder()
() => FolderStore.draftFolder() === this.messageListEndFolder() && FolderStore.draftFolder()
);
this.isSentFolder = ko.computed(
() => FolderStore.sentFolder() === this.messageListEndFolder() && '' !== FolderStore.sentFolder()
() => FolderStore.sentFolder() === this.messageListEndFolder() && FolderStore.sentFolder()
);
this.isArchiveFolder = ko.computed(
() => FolderStore.archiveFolder() === this.messageListEndFolder() && '' !== FolderStore.archiveFolder()
() => FolderStore.archiveFolder() === this.messageListEndFolder() && FolderStore.archiveFolder()
);
this.isArchiveDisabled = ko.computed(() => UNUSED_OPTION_VALUE === FolderStore.archiveFolder());
@ -538,7 +538,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
* @returns {void}
*/
setActionForAll(sFolderFullNameRaw, iSetAction, sThreadUid = '') {
if ('' !== sFolderFullNameRaw) {
if (sFolderFullNameRaw) {
let cnt = 0;
const uids = [];
@ -728,9 +728,9 @@ class MessageListMailBoxUserView extends AbstractViewNext {
clearListIsVisible() {
return (
'' === this.messageListSearchDesc() &&
'' === this.messageListError() &&
'' === this.messageListEndThreadUid() &&
!this.messageListSearchDesc() &&
!this.messageListError() &&
!this.messageListEndThreadUid() &&
this.messageList().length &&
(this.isSpamFolder() || this.isTrashFolder())
);
@ -910,10 +910,10 @@ class MessageListMailBoxUserView extends AbstractViewNext {
// cancel search
key('esc', KeyState.MessageList, () => {
if ('' !== this.messageListSearchDesc()) {
if (this.messageListSearchDesc()) {
this.cancelSearch();
return false;
} else if ('' !== this.messageListEndThreadUid()) {
} else if (this.messageListEndThreadUid()) {
this.cancelThreadUid();
return false;
}

View file

@ -297,7 +297,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
if (pic !== this.viewUserPic() && lastEmail === email) {
this.viewUserPicVisible(false);
this.viewUserPic(DATA_IMAGE_USER_DOT_PIC);
if ('' !== pic) {
if (pic) {
this.viewUserPicVisible(true);
this.viewUserPic(pic);
}
@ -386,7 +386,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
if (dom && 1 === dom.length) {
let aC = dom;
while ('' === result) {
while (!result) {
limit -= 1;
if (0 >= limit) {
break;
@ -456,7 +456,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
// return sLine ? [window.decodeURIComponent(sLine)].map(sItem => {
// var oEmailModel = new EmailModel();
// oEmailModel.parse(sItem);
// return '' !== oEmailModel.email ? oEmailModel : null;
// return oEmailModel.email ? oEmailModel : null;
// }).filter(value => !!value) : null;
// }
// ;
@ -930,7 +930,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
* @returns {void}
*/
readReceipt(oMessage) {
if (oMessage && '' !== oMessage.readReceipt()) {
if (oMessage && oMessage.readReceipt()) {
Remote.sendReadReceiptMessage(
noop,
oMessage.folderFullNameRaw,