Removed isNormal() because 'null == undefined' so 'null != value' is sufficient

This commit is contained in:
djmaze 2020-08-17 21:57:56 +02:00
parent 1b811428e7
commit f6a55898c7
13 changed files with 50 additions and 68 deletions

View file

@ -8,7 +8,7 @@ import {
bMobileDevice bMobileDevice
} from 'Common/Globals'; } from 'Common/Globals';
import { isNormal, pString, detectDropdownVisibility, windowResizeCallback } from 'Common/Utils'; import { pString, detectDropdownVisibility, windowResizeCallback } from 'Common/Utils';
import { KeyState } from 'Common/Enums'; import { KeyState } from 'Common/Enums';
import { root, rootAdmin, rootUser, populateAuthSuffix } from 'Common/Links'; import { root, rootAdmin, rootUser, populateAuthSuffix } from 'Common/Links';
@ -114,7 +114,7 @@ class AbstractApp extends AbstractBoot {
* @param {string} title * @param {string} title
*/ */
setWindowTitle(title) { setWindowTitle(title) {
title = isNormal(title) && title.length ? '' + title : ''; title = pString(title);
if (Settings.settingsGet('Title')) { if (Settings.settingsGet('Title')) {
title += (title ? ' - ' : '') + Settings.settingsGet('Title'); title += (title ? ' - ' : '') + Settings.settingsGet('Title');
} }

View file

@ -3,7 +3,7 @@ import ko from 'ko';
import { root } from 'Common/Links'; import { root } from 'Common/Links';
import { getNotification } from 'Common/Translator'; import { getNotification } from 'Common/Translator';
import { StorageResultType, Notification } from 'Common/Enums'; import { StorageResultType, Notification } from 'Common/Enums';
import { pInt, isNormal } from 'Common/Utils'; import { pInt } from 'Common/Utils';
import * as Settings from 'Storage/Settings'; import * as Settings from 'Storage/Settings';
@ -153,7 +153,7 @@ class AdminApp extends AbstractApp {
LicenseStore.licenseError(''); LicenseStore.licenseError('');
Remote.licensing((result, data) => { Remote.licensing((result, data) => {
LicenseStore.licensingProcess(false); LicenseStore.licensingProcess(false);
if (StorageResultType.Success === result && data && data.Result && isNormal(data.Result.Expired)) { if (StorageResultType.Success === result && data && data.Result && null != data.Result.Expired) {
LicenseStore.licenseValid(true); LicenseStore.licenseValid(true);
LicenseStore.licenseExpired(pInt(data.Result.Expired)); LicenseStore.licenseExpired(pInt(data.Result.Expired));
LicenseStore.licenseError(''); LicenseStore.licenseError('');

View file

@ -1,5 +1,4 @@
import { import {
isNormal,
isPosNumeric, isPosNumeric,
isNonEmptyArray, isNonEmptyArray,
pInt, pInt,
@ -625,11 +624,11 @@ class AppUser extends AbstractApp {
setFolderHash(data.Result.Folder, data.Result.Hash); setFolderHash(data.Result.Folder, data.Result.Hash);
} }
if (isNormal(data.Result.MessageCount)) { if (null != data.Result.MessageCount) {
folderFromCache.messageCountAll(data.Result.MessageCount); folderFromCache.messageCountAll(data.Result.MessageCount);
} }
if (isNormal(data.Result.MessageUnseenCount)) { if (null != data.Result.MessageUnseenCount) {
if (pInt(folderFromCache.messageCountUnread()) !== pInt(data.Result.MessageUnseenCount)) { if (pInt(folderFromCache.messageCountUnread()) !== pInt(data.Result.MessageUnseenCount)) {
unreadCountChange = true; unreadCountChange = true;
} }
@ -707,11 +706,11 @@ class AppUser extends AbstractApp {
setFolderHash(item.Folder, item.Hash); setFolderHash(item.Folder, item.Hash);
} }
if (isNormal(item.MessageCount)) { if (null != item.MessageCount) {
folder.messageCountAll(item.MessageCount); folder.messageCountAll(item.MessageCount);
} }
if (isNormal(item.MessageUnseenCount)) { if (null != item.MessageUnseenCount) {
if (pInt(folder.messageCountUnread()) !== pInt(item.MessageUnseenCount)) { if (pInt(folder.messageCountUnread()) !== pInt(item.MessageUnseenCount)) {
unreadCountChange = true; unreadCountChange = true;
} }

View file

@ -1,4 +1,4 @@
import { pString, pInt, isNormal } from 'Common/Utils'; import { pString, pInt } from 'Common/Utils';
import * as Settings from 'Storage/Settings'; import * as Settings from 'Storage/Settings';
const ROOT = './', const ROOT = './',
@ -365,7 +365,7 @@ export function admin(screenName) {
* @returns {string} * @returns {string}
*/ */
export function mailBox(folder, page = 1, search = '', threadUid = '') { export function mailBox(folder, page = 1, search = '', threadUid = '') {
page = isNormal(page) ? pInt(page) : 1; page = pInt(page, 1);
search = pString(search); search = pString(search);
let result = HASH_PREFIX + 'mailbox/'; let result = HASH_PREFIX + 'mailbox/';

View file

@ -17,35 +17,23 @@ const
}, },
htmlspecialchars = str => (''+str).replace(/[&<>"']/g, m => htmlmap[m]); htmlspecialchars = str => (''+str).replace(/[&<>"']/g, m => htmlmap[m]);
/**
* @param {*} value
* @returns {boolean}
*/
export function isNormal(value) {
return undefined !== value && null !== value;
}
/** /**
* @param {(string|number)} value * @param {(string|number)} value
* @param {boolean=} includeZero = true * @param {boolean=} includeZero = true
* @returns {boolean} * @returns {boolean}
*/ */
export function isPosNumeric(value, includeZero = true) { export function isPosNumeric(value, includeZero = true) {
return !isNormal(value) return null != value && (includeZero ? /^[0-9]*$/ : /^[1-9]+[0-9]*$/).test(value.toString());
? false
: includeZero
? /^[0-9]*$/.test(value.toString())
: /^[1-9]+[0-9]*$/.test(value.toString());
} }
/** /**
* @param {*} value * @param {*} value
* @param {number=} defaultValur = 0 * @param {number=} defaultValue = 0
* @returns {number} * @returns {number}
*/ */
export function pInt(value, defaultValur = 0) { export function pInt(value, defaultValue = 0) {
const result = isNormal(value) && value ? parseInt(value, 10) : defaultValur; value = parseInt(value, 10);
return isNaN(result) ? defaultValur : result; return isNaN(value) || !isFinite(value) ? defaultValue : value;
} }
/** /**
@ -53,7 +41,7 @@ export function pInt(value, defaultValur = 0) {
* @returns {string} * @returns {string}
*/ */
export function pString(value) { export function pString(value) {
return isNormal(value) ? '' + value : ''; return null != value ? '' + value : '';
} }
/** /**
@ -101,7 +89,7 @@ export function fakeMd5(len = 32) {
* @returns {string} * @returns {string}
*/ */
export function encodeHtml(text) { export function encodeHtml(text) {
return isNormal(text) ? htmlspecialchars(text.toString()) : ''; return null != text ? htmlspecialchars(text.toString()) : '';
} }
/** /**
@ -722,11 +710,11 @@ export function folderListOptionsBuilder(
const sDeepPrefix = '\u00A0\u00A0\u00A0'; const sDeepPrefix = '\u00A0\u00A0\u00A0';
bBuildUnvisible = undefined === bBuildUnvisible ? false : !!bBuildUnvisible; bBuildUnvisible = undefined === bBuildUnvisible ? false : !!bBuildUnvisible;
bSystem = !isNormal(bSystem) ? 0 < aSystem.length : bSystem; bSystem = null == bSystem ? 0 < aSystem.length : bSystem;
iUnDeep = !isNormal(iUnDeep) ? 0 : iUnDeep; iUnDeep = null == iUnDeep ? 0 : iUnDeep;
fDisableCallback = isNormal(fDisableCallback) ? fDisableCallback : null; fDisableCallback = null != fDisableCallback ? fDisableCallback : null;
fVisibleCallback = isNormal(fVisibleCallback) ? fVisibleCallback : null; fVisibleCallback = null != fVisibleCallback ? fVisibleCallback : null;
fRenameCallback = isNormal(fRenameCallback) ? fRenameCallback : null; fRenameCallback = null != fRenameCallback ? fRenameCallback : null;
if (!isArray(aDisabled)) { if (!isArray(aDisabled)) {
aDisabled = []; aDisabled = [];

View file

@ -1,7 +1,7 @@
import ko from 'ko'; import ko from 'ko';
import { ContactPropertyType } from 'Common/Enums'; import { ContactPropertyType } from 'Common/Enums';
import { isNonEmptyArray, isNormal, pInt, pString } from 'Common/Utils'; import { isNonEmptyArray, pInt, pString } from 'Common/Utils';
import { emptyContactPic } from 'Common/Links'; import { emptyContactPic } from 'Common/Links';
import { AbstractModel } from 'Knoin/AbstractModel'; import { AbstractModel } from 'Knoin/AbstractModel';
@ -58,7 +58,7 @@ class ContactModel extends AbstractModel {
if (isNonEmptyArray(json.Properties)) { if (isNonEmptyArray(json.Properties)) {
json.Properties.forEach(property => { json.Properties.forEach(property => {
if (property && property.Type && isNormal(property.Value) && isNormal(property.TypeStr)) { if (property && property.Type && null != property.Value && null != property.TypeStr) {
this.properties.push([pInt(property.Type), pString(property.Value), pString(property.TypeStr)]); this.properties.push([pInt(property.Type), pString(property.Value), pString(property.TypeStr)]);
} }
}); });

View file

@ -1,5 +1,5 @@
import { ajax } from 'Common/Links'; import { ajax } from 'Common/Links';
import { isNormal, pString } from 'Common/Utils'; import { pInt, pString } from 'Common/Utils';
import { DEFAULT_AJAX_TIMEOUT, TOKEN_ERROR_LIMIT, AJAX_ERROR_LIMIT } from 'Common/Consts'; import { DEFAULT_AJAX_TIMEOUT, TOKEN_ERROR_LIMIT, AJAX_ERROR_LIMIT } from 'Common/Consts';
import { Notification } from 'Common/Enums'; import { Notification } from 'Common/Enums';
import { data as GlobalsData } from 'Common/Globals'; import { data as GlobalsData } from 'Common/Globals';
@ -75,7 +75,7 @@ class AbstractAjaxPromises extends AbstractBasicPromises {
if (window.AbortController) { if (window.AbortController) {
this.abort(action); this.abort(action);
const controller = new AbortController(); const controller = new AbortController();
setTimeout(() => controller.abort(), isNormal(timeOut) ? timeOut : DEFAULT_AJAX_TIMEOUT); setTimeout(() => controller.abort(), pInt(timeOut, DEFAULT_AJAX_TIMEOUT));
init.signal = controller.signal; init.signal = controller.signal;
this.oRequests[action] = controller; this.oRequests[action] = controller;
} }

View file

@ -1,5 +1,5 @@
import { UNUSED_OPTION_VALUE } from 'Common/Consts'; import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { isNormal, pInt } from 'Common/Utils'; import { pInt } from 'Common/Utils';
import { ClientSideKeyName, ServerFolderType } from 'Common/Enums'; import { ClientSideKeyName, ServerFolderType } from 'Common/Enums';
import * as Cache from 'Common/Cache'; import * as Cache from 'Common/Cache';
@ -71,11 +71,11 @@ class PromisesUserPopulator extends AbstractBasicPromises {
Cache.setFolderHash(oCacheFolder.fullNameRaw, oFolder.Extended.Hash); Cache.setFolderHash(oCacheFolder.fullNameRaw, oFolder.Extended.Hash);
} }
if (isNormal(oFolder.Extended.MessageCount)) { if (null != oFolder.Extended.MessageCount) {
oCacheFolder.messageCountAll(oFolder.Extended.MessageCount); oCacheFolder.messageCountAll(oFolder.Extended.MessageCount);
} }
if (isNormal(oFolder.Extended.MessageUnseenCount)) { if (null != oFolder.Extended.MessageUnseenCount) {
oCacheFolder.messageCountUnread(oFolder.Extended.MessageUnseenCount); oCacheFolder.messageCountUnread(oFolder.Extended.MessageUnseenCount);
} }
} }

View file

@ -1,10 +1,8 @@
import { isNormal } from 'Common/Utils';
let SETTINGS = window.__rlah_data() || null; let SETTINGS = window.__rlah_data() || null;
SETTINGS = isNormal(SETTINGS) ? SETTINGS : {}; SETTINGS = null != SETTINGS ? SETTINGS : {};
let APP_SETTINGS = SETTINGS.System || null; let APP_SETTINGS = SETTINGS.System || null;
APP_SETTINGS = isNormal(APP_SETTINGS) ? APP_SETTINGS : {}; APP_SETTINGS = null != APP_SETTINGS ? APP_SETTINGS : {};
/** /**
* @param {string} name * @param {string} name
@ -36,5 +34,5 @@ export function appSettingsGet(name) {
*/ */
export function capa(name) { export function capa(name) {
const values = settingsGet('Capa'); const values = settingsGet('Capa');
return Array.isArray(values) && isNormal(name) && values.includes(name); return Array.isArray(values) && null != name && values.includes(name);
} }

View file

@ -3,7 +3,6 @@ import ko from 'ko';
import { Layout, Focused, MessageSetAction, StorageResultType, Notification } from 'Common/Enums'; import { Layout, Focused, MessageSetAction, StorageResultType, Notification } from 'Common/Enums';
import { import {
isNormal,
pInt, pInt,
pString, pString,
plainToHtml, plainToHtml,
@ -271,7 +270,7 @@ class MessageUserStore {
} }
initUidNextAndNewMessages(folder, uidNext, newMessages) { initUidNextAndNewMessages(folder, uidNext, newMessages) {
if (getFolderInboxName() === folder && isNormal(uidNext) && uidNext) { if (getFolderInboxName() === folder && uidNext) {
if (Array.isArray(newMessages) && newMessages.length) { if (Array.isArray(newMessages) && newMessages.length) {
newMessages.forEach(item => { newMessages.forEach(item => {
addNewMessageCache(folder, item.Uid); addNewMessageCache(folder, item.Uid);
@ -545,10 +544,10 @@ class MessageUserStore {
const textBody = messagesDom.find('#' + id); const textBody = messagesDom.find('#' + id);
if (!textBody || !textBody[0]) { if (!textBody || !textBody[0]) {
let isHtml = false; let isHtml = false;
if (isNormal(data.Result.Html) && data.Result.Html) { if (data.Result.Html) {
isHtml = true; isHtml = true;
resultHtml = data.Result.Html.toString(); resultHtml = data.Result.Html.toString();
} else if (isNormal(data.Result.Plain) && data.Result.Plain) { } else if (data.Result.Plain) {
isHtml = false; isHtml = false;
resultHtml = plainToHtml(data.Result.Plain.toString(), false); resultHtml = plainToHtml(data.Result.Plain.toString(), false);
@ -746,18 +745,18 @@ class MessageUserStore {
iCount = pInt(data.Result.MessageResultCount), iCount = pInt(data.Result.MessageResultCount),
iOffset = pInt(data.Result.Offset); iOffset = pInt(data.Result.Offset);
const folder = getFolderFromCacheList(isNormal(data.Result.Folder) ? data.Result.Folder : ''); const folder = getFolderFromCacheList(null != data.Result.Folder ? data.Result.Folder : '');
if (folder && !cached) { if (folder && !cached) {
folder.interval = Date.now() / 1000; folder.interval = Date.now() / 1000;
setFolderHash(data.Result.Folder, data.Result.FolderHash); setFolderHash(data.Result.Folder, data.Result.FolderHash);
if (isNormal(data.Result.MessageCount)) { if (null != data.Result.MessageCount) {
folder.messageCountAll(data.Result.MessageCount); folder.messageCountAll(data.Result.MessageCount);
} }
if (isNormal(data.Result.MessageUnseenCount)) { if (null != data.Result.MessageUnseenCount) {
if (pInt(folder.messageCountUnread()) !== pInt(data.Result.MessageUnseenCount)) { if (pInt(folder.messageCountUnread()) !== pInt(data.Result.MessageUnseenCount)) {
unreadCountChange = true; unreadCountChange = true;
} }
@ -795,11 +794,11 @@ class MessageUserStore {
}); });
this.messageListCount(iCount); this.messageListCount(iCount);
this.messageListSearch(isNormal(data.Result.Search) ? data.Result.Search : ''); this.messageListSearch(null != data.Result.Search ? data.Result.Search : '');
this.messageListPage(Math.ceil(iOffset / SettingsStore.messagesPerPage() + 1)); this.messageListPage(Math.ceil(iOffset / SettingsStore.messagesPerPage() + 1));
this.messageListThreadUid(isNormal(data.Result.ThreadUid) ? pString(data.Result.ThreadUid) : ''); this.messageListThreadUid(null != data.Result.ThreadUid ? pString(data.Result.ThreadUid) : '');
this.messageListEndFolder(isNormal(data.Result.Folder) ? data.Result.Folder : ''); this.messageListEndFolder(null != data.Result.Folder ? data.Result.Folder : '');
this.messageListEndSearch(this.messageListSearch()); this.messageListEndSearch(this.messageListSearch());
this.messageListEndThreadUid(this.messageListThreadUid()); this.messageListEndThreadUid(this.messageListThreadUid());
this.messageListEndPage(this.messageListPage()); this.messageListEndPage(this.messageListPage());

View file

@ -12,7 +12,6 @@ import {
} from 'Common/Enums'; } from 'Common/Enums';
import { import {
isNormal,
delegateRun, delegateRun,
isNonEmptyArray, isNonEmptyArray,
clearBqSwitcher, clearBqSwitcher,
@ -387,7 +386,7 @@ class ComposePopupView extends AbstractViewNext {
if ( if (
Array.isArray(this.aDraftInfo) && Array.isArray(this.aDraftInfo) &&
3 === this.aDraftInfo.length && 3 === this.aDraftInfo.length &&
isNormal(this.aDraftInfo[2]) && null != this.aDraftInfo[2] &&
this.aDraftInfo[2].length this.aDraftInfo[2].length
) { ) {
sSentFolder = this.aDraftInfo[2]; sSentFolder = this.aDraftInfo[2];
@ -795,7 +794,7 @@ class ComposePopupView extends AbstractViewNext {
this.addEmailsTo(this.cc, aCcEmails); this.addEmailsTo(this.cc, aCcEmails);
this.addEmailsTo(this.bcc, aBccEmails); this.addEmailsTo(this.bcc, aBccEmails);
if (isNormal(sCustomSubject) && sCustomSubject && !this.subject()) { if (sCustomSubject && !this.subject()) {
this.subject(sCustomSubject); this.subject(sCustomSubject);
} }
} }
@ -863,7 +862,7 @@ class ComposePopupView extends AbstractViewNext {
lineComposeType = sType || ComposeType.Empty; lineComposeType = sType || ComposeType.Empty;
oMessageOrArray = oMessageOrArray || null; oMessageOrArray = oMessageOrArray || null;
if (oMessageOrArray && isNormal(oMessageOrArray)) { if (oMessageOrArray) {
message = message =
Array.isArray(oMessageOrArray) && 1 === oMessageOrArray.length Array.isArray(oMessageOrArray) && 1 === oMessageOrArray.length
? oMessageOrArray[0] ? oMessageOrArray[0]
@ -1050,9 +1049,9 @@ class ComposePopupView extends AbstractViewNext {
this.setFocusInPopup(); this.setFocusInPopup();
}); });
} else if (ComposeType.Empty === lineComposeType) { } else if (ComposeType.Empty === lineComposeType) {
this.subject(isNormal(sCustomSubject) ? '' + sCustomSubject : ''); this.subject(null != sCustomSubject ? '' + sCustomSubject : '');
sText = isNormal(sCustomPlainText) ? '' + sCustomPlainText : ''; sText = null != sCustomPlainText ? '' + sCustomPlainText : '';
this.editor((editor) => { this.editor((editor) => {
editor.setHtml(sText, false); editor.setHtml(sText, false);
@ -1291,7 +1290,7 @@ class ComposePopupView extends AbstractViewNext {
this.dragAndDropOver(false); this.dragAndDropOver(false);
const fileName = undefined === oData.FileName ? '' : oData.FileName.toString(), const fileName = undefined === oData.FileName ? '' : oData.FileName.toString(),
size = isNormal(oData.Size) ? pInt(oData.Size) : null, size = pInt(oData.Size, null),
attachment = new ComposeAttachmentModel(sId, fileName, size); attachment = new ComposeAttachmentModel(sId, fileName, size);
attachment.cancel = this.cancelAttachmentHelper(sId, oJua); attachment.cancel = this.cancelAttachmentHelper(sId, oJua);

View file

@ -1,7 +1,6 @@
import ko from 'ko'; import ko from 'ko';
import { StorageResultType, Notification } from 'Common/Enums'; import { StorageResultType, Notification } from 'Common/Enums';
import { isNormal } from 'Common/Utils';
import { getNotification } from 'Common/Translator'; import { getNotification } from 'Common/Translator';
import { HtmlEditor } from 'Common/HtmlEditor'; import { HtmlEditor } from 'Common/HtmlEditor';
@ -142,7 +141,7 @@ class TemplatePopupView extends AbstractViewNext {
data && data &&
data.Result && data.Result &&
'Object/Template' === data.Result['@Object'] && 'Object/Template' === data.Result['@Object'] &&
isNormal(data.Result.Body) null != data.Result.Body
) { ) {
template.body = data.Result.Body; template.body = data.Result.Body;
template.populated = true; template.populated = true;

View file

@ -1,6 +1,6 @@
import ko from 'ko'; import ko from 'ko';
import { isNormal, windowResize } from 'Common/Utils'; import { windowResize } from 'Common/Utils';
import { Capa, Focused, Layout, KeyState, EventKeyCode } from 'Common/Enums'; import { Capa, Focused, Layout, KeyState, EventKeyCode } from 'Common/Enums';
import { $htmlCL, leftPanelDisabled, moveAction } from 'Common/Globals'; import { $htmlCL, leftPanelDisabled, moveAction } from 'Common/Globals';
import { mailBox, settings } from 'Common/Links'; import { mailBox, settings } from 'Common/Links';
@ -243,7 +243,7 @@ class FolderListMailBoxUserView extends AbstractViewNext {
copy = $htmlCL.contains('rl-ctrl-key-pressed'), copy = $htmlCL.contains('rl-ctrl-key-pressed'),
uids = ui.helper.data('rl-uids'); uids = ui.helper.data('rl-uids');
if (fromFolderFullNameRaw && isNormal(fromFolderFullNameRaw) && Array.isArray(uids)) { if (fromFolderFullNameRaw && Array.isArray(uids)) {
getApp().moveMessagesToFolder(fromFolderFullNameRaw, uids, toFolder.fullNameRaw, copy); getApp().moveMessagesToFolder(fromFolderFullNameRaw, uids, toFolder.fullNameRaw, copy);
} }
} }