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

@ -361,7 +361,7 @@ class AttachmentModel extends AbstractModel {
*/
linkThumbnailPreviewStyle() {
const link = this.linkThumbnail();
return '' === link ? '' : 'background:url(' + link + ')';
return link ? 'background:url(' + link + ')' : '';
}
/**

View file

@ -46,8 +46,7 @@ class ComposeAttachmentModel extends AbstractModel {
});
this.title = ko.computed(() => {
const error = this.error();
return '' !== error ? error : this.fileName();
return this.error() || this.fileName();
});
this.friendlySize = ko.computed(() => {

View file

@ -35,14 +35,14 @@ class ContactModel extends AbstractModel {
name = trim(property[1] + ' ' + name);
} else if (ContactPropertyType.LastName === property[0]) {
name = trim(name + ' ' + property[1]);
} else if ('' === email && ContactPropertyType.Email === property[0]) {
} else if (!email && ContactPropertyType.Email === property[0]) {
email = property[1];
}
}
});
}
return '' === email ? null : [email, name];
return email ? [email, name] : null;
}
/**

View file

@ -47,7 +47,7 @@ class EmailModel {
* @returns {boolean}
*/
validate() {
return '' !== this.name || '' !== this.email;
return this.name || this.email;
}
/**
@ -87,7 +87,7 @@ class EmailModel {
this.dkimStatus = trim(json.DkimStatus || '');
this.dkimValue = trim(json.DkimValue || '');
result = '' !== this.email;
result = !!this.email;
this.clearDuplicateName();
}
@ -102,8 +102,8 @@ class EmailModel {
*/
toLine(friendlyView, wrapWithLink = false, useEncodeHtml = false) {
let result = '';
if ('' !== this.email) {
if (friendlyView && '' !== this.name) {
if (this.email) {
if (friendlyView && this.name) {
result = wrapWithLink
? '<a href="mailto:' +
encodeHtml(this.email) +
@ -119,7 +119,7 @@ class EmailModel {
// '" target="_blank" tabindex="-1">' + encodeHtml(this.name) + '</a>' : (useEncodeHtml ? encodeHtml(this.name) : this.name);
} else {
result = this.email;
if ('' !== this.name) {
if (this.name) {
if (wrapWithLink) {
result =
encodeHtml('"' + this.name + '" <') +
@ -197,7 +197,7 @@ class EmailModel {
*/
parse(emailAddress) {
emailAddress = trim(emailAddress);
if ('' === emailAddress) {
if (!emailAddress) {
return false;
}

View file

@ -118,13 +118,13 @@ class FilterModel extends AbstractModel {
this.regDisposables(
this.name.subscribe((sValue) => {
this.name.error('' === sValue);
this.name.error(!sValue);
})
);
this.regDisposables(
this.actionValue.subscribe((sValue) => {
this.actionValue.error('' === sValue);
this.actionValue.error(!sValue);
})
);
@ -139,7 +139,7 @@ class FilterModel extends AbstractModel {
}
verify() {
if ('' === this.name()) {
if (!this.name()) {
this.name.error(true);
return false;
}
@ -150,7 +150,7 @@ class FilterModel extends AbstractModel {
}
}
if ('' === this.actionValue()) {
if (!this.actionValue()) {
if ([
FiltersAction.MoveTo,
FiltersAction.Forward,
@ -170,7 +170,7 @@ class FilterModel extends AbstractModel {
if (
FiltersAction.Vacation === this.actionType() &&
'' !== this.actionValueFourth() &&
this.actionValueFourth() &&
!this.actionValueFourth().includes('@')
) {
this.actionValueFourth.error(true);

View file

@ -43,12 +43,12 @@ class FilterConditionModel extends AbstractModel {
}
verify() {
if ('' === this.value()) {
if (!this.value()) {
this.value.error(true);
return false;
}
if (FilterConditionField.Header === this.field() && '' === this.valueSecond()) {
if (FilterConditionField.Header === this.field() && !this.valueSecond()) {
this.valueSecond.error(true);
return false;
}

View file

@ -210,7 +210,7 @@ class FolderModel extends AbstractModel {
}
}
if (('' !== suffix && '(' + name + ')' === suffix) || '(inbox)' === suffix.toLowerCase()) {
if ((suffix && '(' + name + ')' === suffix) || '(inbox)' === suffix.toLowerCase()) {
suffix = '';
}
@ -224,7 +224,7 @@ class FolderModel extends AbstractModel {
}
});
this.hasUnreadMessages = ko.computed(() => 0 < this.messageCountUnread() && '' !== this.printableUnreadCount());
this.hasUnreadMessages = ko.computed(() => 0 < this.messageCountUnread() && this.printableUnreadCount());
this.hasSubScribedUnreadMessagesSubfolders = ko.computed(
() =>

View file

@ -21,7 +21,7 @@ class IdentityModel extends AbstractModel {
this.signatureInsertBefore = ko.observable(false);
this.deleteAccess = ko.observable(false);
this.canBeDeleted = ko.computed(() => '' !== this.id());
this.canBeDeleted = ko.computed(() => !!this.id());
}
/**
@ -31,7 +31,7 @@ class IdentityModel extends AbstractModel {
const name = this.name(),
email = this.email();
return '' !== name ? name + ' (' + email + ')' : email;
return name ? name + ' (' + email + ')' : email;
}
}

View file

@ -353,7 +353,7 @@ class MessageModel extends AbstractModel {
attachment = AttachmentModel.newInstanceFromJson(json['@Collection'][index]);
if (attachment) {
if (
'' !== attachment.cidWithOutTags &&
attachment.cidWithOutTags &&
this.foundedCIDs.includes(attachment.cidWithOutTags)
) {
attachment.isLinked = true;
@ -475,7 +475,7 @@ class MessageModel extends AbstractModel {
'important': this.isImportant(),
'withAttachments': this.hasAttachments(),
'new': this.newForAnimation(),
'emptySubject': '' === this.subject(),
'emptySubject': !this.subject(),
// 'hasChildrenMessage': 1 < this.threadsLen(),
'hasUnseenSubMessage': this.hasUnseenSubMessage(),
'hasFlaggedSubMessage': this.hasFlaggedSubMessage()
@ -783,7 +783,7 @@ class MessageModel extends AbstractModel {
$('[' + attr + ']', this.body).each(function() {
const $this = $(this); // eslint-disable-line no-invalid-this
let style = trim($this.attr('style'));
style = '' === style ? '' : ';' === style.substr(-1) ? style + ' ' : style + '; ';
style = style ? (';' === style.substr(-1) ? style + ' ' : style + '; ') : '';
$this.attr('style', style + $this.attr(attr));
});
@ -840,9 +840,9 @@ class MessageModel extends AbstractModel {
if (attachment && attachment.linkPreview) {
name = $this.attr('data-x-style-cid-name');
if ('' !== name) {
if (name) {
style = trim($this.attr('style'));
style = '' === style ? '' : ';' === style.substr(-1) ? style + ' ' : style + '; ';
style = style ? (';' === style.substr(-1) ? style + ' ' : style + '; ') : '';
$this.attr('style', style + name + ": url('" + attachment.linkPreview() + "')");
}
}