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

@ -19,9 +19,9 @@ class Audio {
this.supported = !bMobileDevice && !bSafari && !!this.player && !!this.player.play;
if (this.supported && this.player && this.player.canPlayType) {
this.supportedMp3 = '' !== this.player.canPlayType('audio/mpeg;').replace(/no/, '');
this.supportedWav = '' !== this.player.canPlayType('audio/wav; codecs="1"').replace(/no/, '');
this.supportedOgg = '' !== this.player.canPlayType('audio/ogg; codecs="vorbis"').replace(/no/, '');
this.supportedMp3 = !!this.player.canPlayType('audio/mpeg;').replace(/no/, '');
this.supportedWav = !!this.player.canPlayType('audio/wav; codecs="1"').replace(/no/, '');
this.supportedOgg = !!this.player.canPlayType('audio/ogg; codecs="vorbis"').replace(/no/, '');
this.supportedNotification = this.supported && this.supportedMp3;
}
@ -81,7 +81,7 @@ class Audio {
name = trim(name.substr(0, name.length - 4));
}
return '' === name ? 'audio' : name;
return name || 'audio';
}
playMp3(url, name) {

View file

@ -89,7 +89,7 @@ export function clearNewMessageCache() {
* @returns {string}
*/
export function getFolderInboxName() {
return '' === inboxFolderName ? 'INBOX' : inboxFolderName;
return inboxFolderName || 'INBOX';
}
/**
@ -97,7 +97,7 @@ export function getFolderInboxName() {
* @returns {string}
*/
export function getFolderFullNameRaw(folderHash) {
return '' !== folderHash && FOLDERS_NAME_CACHE[folderHash] ? FOLDERS_NAME_CACHE[folderHash] : '';
return folderHash && FOLDERS_NAME_CACHE[folderHash] ? FOLDERS_NAME_CACHE[folderHash] : '';
}
/**
@ -106,7 +106,7 @@ export function getFolderFullNameRaw(folderHash) {
*/
export function setFolderFullNameRaw(folderHash, folderFullNameRaw) {
FOLDERS_NAME_CACHE[folderHash] = folderFullNameRaw;
if ('INBOX' === folderFullNameRaw || '' === inboxFolderName) {
if (!inboxFolderName || 'INBOX' === folderFullNameRaw) {
inboxFolderName = folderFullNameRaw;
}
}
@ -116,7 +116,7 @@ export function setFolderFullNameRaw(folderHash, folderFullNameRaw) {
* @returns {string}
*/
export function getFolderHash(folderFullNameRaw) {
return '' !== folderFullNameRaw && FOLDERS_HASH_CACHE[folderFullNameRaw] ? FOLDERS_HASH_CACHE[folderFullNameRaw] : '';
return folderFullNameRaw && FOLDERS_HASH_CACHE[folderFullNameRaw] ? FOLDERS_HASH_CACHE[folderFullNameRaw] : '';
}
/**
@ -124,7 +124,7 @@ export function getFolderHash(folderFullNameRaw) {
* @param {string} folderHash
*/
export function setFolderHash(folderFullNameRaw, folderHash) {
if ('' !== folderFullNameRaw) {
if (folderFullNameRaw) {
FOLDERS_HASH_CACHE[folderFullNameRaw] = folderHash;
}
}
@ -134,7 +134,7 @@ export function setFolderHash(folderFullNameRaw, folderHash) {
* @returns {string}
*/
export function getFolderUidNext(folderFullNameRaw) {
return '' !== folderFullNameRaw && FOLDERS_UID_NEXT_CACHE[folderFullNameRaw]
return folderFullNameRaw && FOLDERS_UID_NEXT_CACHE[folderFullNameRaw]
? FOLDERS_UID_NEXT_CACHE[folderFullNameRaw]
: '';
}
@ -152,7 +152,7 @@ export function setFolderUidNext(folderFullNameRaw, uidNext) {
* @returns {?FolderModel}
*/
export function getFolderFromCacheList(folderFullNameRaw) {
return '' !== folderFullNameRaw && FOLDERS_CACHE[folderFullNameRaw] ? FOLDERS_CACHE[folderFullNameRaw] : null;
return folderFullNameRaw && FOLDERS_CACHE[folderFullNameRaw] ? FOLDERS_CACHE[folderFullNameRaw] : null;
}
/**

View file

@ -371,7 +371,7 @@ export function mailBox(folder, page = 1, search = '', threadUid = '') {
let result = HASH_PREFIX + 'mailbox/';
if ('' !== folder) {
if (folder) {
const resultThreadUid = pInt(threadUid);
result += window.encodeURI(folder) + (0 < resultThreadUid ? '~' + resultThreadUid : '');
}
@ -381,7 +381,7 @@ export function mailBox(folder, page = 1, search = '', threadUid = '') {
result += '/p' + page;
}
if ('' !== search) {
if (search) {
result = result.replace(/[/]+$/, '');
result += '/' + window.encodeURI(search);
}

View file

@ -561,7 +561,7 @@ class Selector {
const uid = this.getItemUid(item);
if (event && event.shiftKey) {
if ('' !== uid && '' !== this.sLastUid && uid !== this.sLastUid) {
if (uid && this.sLastUid && uid !== this.sLastUid) {
list = this.list();
checked = item.checked();
@ -585,7 +585,7 @@ class Selector {
}
}
this.sLastUid = '' === uid ? '' : uid;
this.sLastUid = uid || '';
}
/**
@ -598,7 +598,7 @@ class Selector {
if (event) {
if (event.shiftKey && !(event.ctrlKey || event.metaKey) && !event.altKey) {
click = false;
if ('' === this.sLastUid) {
if (!this.sLastUid) {
this.sLastUid = this.getItemUid(item);
}

View file

@ -68,7 +68,7 @@ export function isPosNumeric(value, includeZero = true) {
* @returns {number}
*/
export function pInt(value, defaultValur = 0) {
const result = isNormal(value) && '' !== value ? window.parseInt(value, 10) : defaultValur;
const result = isNormal(value) && value ? window.parseInt(value, 10) : defaultValur;
return window.isNaN(result) ? defaultValur : result;
}
@ -309,7 +309,7 @@ export function replySubjectAdd(prefix, subject) {
const parts = [],
prefixIsRe = !fwd;
if ('' !== subject) {
if (subject) {
subject.split(':').forEach(part => {
const trimmedPart = trim(part);
if (!drop && (/^(RE|FWD)$/i.test(trimmedPart) || /^(RE|FWD)[[(][\d]+[\])]$/i.test(trimmedPart))) {
@ -814,7 +814,7 @@ export function plainToHtml(plain, findEmailAndLinksInText = false) {
aNextText.push('~~~blockquote~~~');
aNextText.push(sLine.substr(1));
} else if (!bStart && bIn) {
if ('' !== sLine) {
if (sLine) {
bIn = false;
aNextText.push('~~~/blockquote~~~');
aNextText.push(sLine);
@ -1191,9 +1191,9 @@ export function computedPagenatorHelper(koCurrentPage, koPageCount) {
fAdd = (index, push = true, customName = '') => {
const data = {
current: index === currentPage,
name: '' === customName ? index.toString() : customName.toString(),
custom: '' !== customName,
title: '' === customName ? '' : index.toString(),
name: customName ? customName.toString() : index.toString(),
custom: !!customName,
title: customName ? index.toString() : '',
value: index.toString()
};