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

View file

@ -3,7 +3,7 @@ import ko from 'ko';
import { root } from 'Common/Links';
import { getNotification } from 'Common/Translator';
import { StorageResultType, Notification } from 'Common/Enums';
import { pInt, isNormal } from 'Common/Utils';
import { pInt } from 'Common/Utils';
import * as Settings from 'Storage/Settings';
@ -153,7 +153,7 @@ class AdminApp extends AbstractApp {
LicenseStore.licenseError('');
Remote.licensing((result, data) => {
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.licenseExpired(pInt(data.Result.Expired));
LicenseStore.licenseError('');

View file

@ -1,5 +1,4 @@
import {
isNormal,
isPosNumeric,
isNonEmptyArray,
pInt,
@ -625,11 +624,11 @@ class AppUser extends AbstractApp {
setFolderHash(data.Result.Folder, data.Result.Hash);
}
if (isNormal(data.Result.MessageCount)) {
if (null != 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)) {
unreadCountChange = true;
}
@ -707,11 +706,11 @@ class AppUser extends AbstractApp {
setFolderHash(item.Folder, item.Hash);
}
if (isNormal(item.MessageCount)) {
if (null != item.MessageCount) {
folder.messageCountAll(item.MessageCount);
}
if (isNormal(item.MessageUnseenCount)) {
if (null != item.MessageUnseenCount) {
if (pInt(folder.messageCountUnread()) !== pInt(item.MessageUnseenCount)) {
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';
const ROOT = './',
@ -365,7 +365,7 @@ export function admin(screenName) {
* @returns {string}
*/
export function mailBox(folder, page = 1, search = '', threadUid = '') {
page = isNormal(page) ? pInt(page) : 1;
page = pInt(page, 1);
search = pString(search);
let result = HASH_PREFIX + 'mailbox/';

View file

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

View file

@ -1,7 +1,7 @@
import ko from 'ko';
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 { AbstractModel } from 'Knoin/AbstractModel';
@ -58,7 +58,7 @@ class ContactModel extends AbstractModel {
if (isNonEmptyArray(json.Properties)) {
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)]);
}
});

View file

@ -1,5 +1,5 @@
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 { Notification } from 'Common/Enums';
import { data as GlobalsData } from 'Common/Globals';
@ -75,7 +75,7 @@ class AbstractAjaxPromises extends AbstractBasicPromises {
if (window.AbortController) {
this.abort(action);
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;
this.oRequests[action] = controller;
}

View file

@ -1,5 +1,5 @@
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 * as Cache from 'Common/Cache';
@ -71,11 +71,11 @@ class PromisesUserPopulator extends AbstractBasicPromises {
Cache.setFolderHash(oCacheFolder.fullNameRaw, oFolder.Extended.Hash);
}
if (isNormal(oFolder.Extended.MessageCount)) {
if (null != oFolder.Extended.MessageCount) {
oCacheFolder.messageCountAll(oFolder.Extended.MessageCount);
}
if (isNormal(oFolder.Extended.MessageUnseenCount)) {
if (null != 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;
SETTINGS = isNormal(SETTINGS) ? SETTINGS : {};
SETTINGS = null != SETTINGS ? SETTINGS : {};
let APP_SETTINGS = SETTINGS.System || null;
APP_SETTINGS = isNormal(APP_SETTINGS) ? APP_SETTINGS : {};
APP_SETTINGS = null != APP_SETTINGS ? APP_SETTINGS : {};
/**
* @param {string} name
@ -36,5 +34,5 @@ export function appSettingsGet(name) {
*/
export function capa(name) {
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 {
isNormal,
pInt,
pString,
plainToHtml,
@ -271,7 +270,7 @@ class MessageUserStore {
}
initUidNextAndNewMessages(folder, uidNext, newMessages) {
if (getFolderInboxName() === folder && isNormal(uidNext) && uidNext) {
if (getFolderInboxName() === folder && uidNext) {
if (Array.isArray(newMessages) && newMessages.length) {
newMessages.forEach(item => {
addNewMessageCache(folder, item.Uid);
@ -545,10 +544,10 @@ class MessageUserStore {
const textBody = messagesDom.find('#' + id);
if (!textBody || !textBody[0]) {
let isHtml = false;
if (isNormal(data.Result.Html) && data.Result.Html) {
if (data.Result.Html) {
isHtml = true;
resultHtml = data.Result.Html.toString();
} else if (isNormal(data.Result.Plain) && data.Result.Plain) {
} else if (data.Result.Plain) {
isHtml = false;
resultHtml = plainToHtml(data.Result.Plain.toString(), false);
@ -746,18 +745,18 @@ class MessageUserStore {
iCount = pInt(data.Result.MessageResultCount),
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) {
folder.interval = Date.now() / 1000;
setFolderHash(data.Result.Folder, data.Result.FolderHash);
if (isNormal(data.Result.MessageCount)) {
if (null != 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)) {
unreadCountChange = true;
}
@ -795,11 +794,11 @@ class MessageUserStore {
});
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.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.messageListEndThreadUid(this.messageListThreadUid());
this.messageListEndPage(this.messageListPage());

View file

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

View file

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

View file

@ -1,6 +1,6 @@
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 { $htmlCL, leftPanelDisabled, moveAction } from 'Common/Globals';
import { mailBox, settings } from 'Common/Links';
@ -243,7 +243,7 @@ class FolderListMailBoxUserView extends AbstractViewNext {
copy = $htmlCL.contains('rl-ctrl-key-pressed'),
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);
}
}