mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-27 19:19:21 +03:00
JavaScript inArray()/indexOf() to .includes()
This commit is contained in:
parent
ec3fd5b7e4
commit
db2d95d684
20 changed files with 69 additions and 86 deletions
|
|
@ -4,7 +4,7 @@ import ko from 'ko';
|
|||
|
||||
import { FileType } from 'Common/Enums';
|
||||
import { bAllowPdfPreview } from 'Common/Globals';
|
||||
import { trim, pInt, inArray, isNonEmptyArray, getFileExtension, friendlySize } from 'Common/Utils';
|
||||
import { trim, pInt, isNonEmptyArray, getFileExtension, friendlySize } from 'Common/Utils';
|
||||
import {
|
||||
attachmentDownload,
|
||||
attachmentPreview,
|
||||
|
|
@ -30,29 +30,28 @@ export const staticFileType = _.memoize((ext, mimeType) => {
|
|||
const mimeTypeParts = mimeType.split('/');
|
||||
|
||||
switch (true) {
|
||||
case 'image' === mimeTypeParts[0] || -1 < inArray(ext, ['png', 'jpg', 'jpeg', 'gif', 'bmp']):
|
||||
case 'image' === mimeTypeParts[0] || ['png', 'jpg', 'jpeg', 'gif', 'bmp'].includes(ext):
|
||||
result = FileType.Image;
|
||||
break;
|
||||
case 'audio' === mimeTypeParts[0] || -1 < inArray(ext, ['mp3', 'ogg', 'oga', 'wav']):
|
||||
case 'audio' === mimeTypeParts[0] || ['mp3', 'ogg', 'oga', 'wav'].includes(ext):
|
||||
result = FileType.Audio;
|
||||
break;
|
||||
case 'video' === mimeTypeParts[0] || -1 < inArray(ext, ['mkv', 'avi']):
|
||||
case 'video' === mimeTypeParts[0] || ['mkv', 'avi'].includes(ext):
|
||||
result = FileType.Video;
|
||||
break;
|
||||
case -1 < inArray(ext, ['php', 'js', 'css']):
|
||||
case ['php', 'js', 'css'].includes(ext):
|
||||
result = FileType.Code;
|
||||
break;
|
||||
case 'eml' === ext || -1 < inArray(mimeType, ['message/delivery-status', 'message/rfc822']):
|
||||
case 'eml' === ext || ['message/delivery-status', 'message/rfc822'].includes(mimeType):
|
||||
result = FileType.Eml;
|
||||
break;
|
||||
case ('text' === mimeTypeParts[0] && 'html' !== mimeTypeParts[1]) || -1 < inArray(ext, ['txt', 'log']):
|
||||
case ('text' === mimeTypeParts[0] && 'html' !== mimeTypeParts[1]) || ['txt', 'log'].includes(ext):
|
||||
result = FileType.Text;
|
||||
break;
|
||||
case 'text/html' === mimeType || -1 < inArray(ext, ['html']):
|
||||
case 'text/html' === mimeType || ['html'].includes(ext):
|
||||
result = FileType.Html;
|
||||
break;
|
||||
case -1 <
|
||||
inArray(mimeTypeParts[1], [
|
||||
case [
|
||||
'zip',
|
||||
'7z',
|
||||
'tar',
|
||||
|
|
@ -70,21 +69,20 @@ export const staticFileType = _.memoize((ext, mimeType) => {
|
|||
'x-zip-compressed',
|
||||
'x-7z-compressed',
|
||||
'x-rar-compressed'
|
||||
]) || -1 < inArray(ext, ['zip', '7z', 'tar', 'rar', 'gzip', 'bzip', 'bzip2']):
|
||||
].includes(mimeTypeParts[1]) || ['zip', '7z', 'tar', 'rar', 'gzip', 'bzip', 'bzip2'].includes(ext):
|
||||
result = FileType.Archive;
|
||||
break;
|
||||
case -1 < inArray(mimeTypeParts[1], ['pdf', 'x-pdf']) || -1 < inArray(ext, ['pdf']):
|
||||
case ['pdf', 'x-pdf'].includes(mimeTypeParts[1]) || ['pdf'].includes(ext):
|
||||
result = FileType.Pdf;
|
||||
break;
|
||||
case -1 < inArray(mimeType, ['application/pgp-signature', 'application/pgp-keys']) ||
|
||||
-1 < inArray(ext, ['asc', 'pem', 'ppk']):
|
||||
case ['application/pgp-signature', 'application/pgp-keys'].includes(mimeType) ||
|
||||
['asc', 'pem', 'ppk'].includes(ext):
|
||||
result = FileType.Certificate;
|
||||
break;
|
||||
case -1 < inArray(mimeType, ['application/pkcs7-signature']) || -1 < inArray(ext, ['p7s']):
|
||||
case ['application/pkcs7-signature'].includes(mimeType) || ['p7s'].includes(ext):
|
||||
result = FileType.CertificateBin;
|
||||
break;
|
||||
case -1 <
|
||||
inArray(mimeTypeParts[1], [
|
||||
case [
|
||||
'rtf',
|
||||
'msword',
|
||||
'vnd.msword',
|
||||
|
|
@ -92,11 +90,10 @@ export const staticFileType = _.memoize((ext, mimeType) => {
|
|||
'vnd.openxmlformats-officedocument.wordprocessingml.template',
|
||||
'vnd.ms-word.document.macroEnabled.12',
|
||||
'vnd.ms-word.template.macroEnabled.12'
|
||||
]):
|
||||
].includes(mimeTypeParts[1]):
|
||||
result = FileType.WordText;
|
||||
break;
|
||||
case -1 <
|
||||
inArray(mimeTypeParts[1], [
|
||||
case [
|
||||
'excel',
|
||||
'ms-excel',
|
||||
'vnd.ms-excel',
|
||||
|
|
@ -106,11 +103,10 @@ export const staticFileType = _.memoize((ext, mimeType) => {
|
|||
'vnd.ms-excel.template.macroEnabled.12',
|
||||
'vnd.ms-excel.addin.macroEnabled.12',
|
||||
'vnd.ms-excel.sheet.binary.macroEnabled.12'
|
||||
]):
|
||||
].includes(mimeTypeParts[1]):
|
||||
result = FileType.Sheet;
|
||||
break;
|
||||
case -1 <
|
||||
inArray(mimeTypeParts[1], [
|
||||
case [
|
||||
'powerpoint',
|
||||
'ms-powerpoint',
|
||||
'vnd.ms-powerpoint',
|
||||
|
|
@ -121,7 +117,7 @@ export const staticFileType = _.memoize((ext, mimeType) => {
|
|||
'vnd.ms-powerpoint.presentation.macroEnabled.12',
|
||||
'vnd.ms-powerpoint.template.macroEnabled.12',
|
||||
'vnd.ms-powerpoint.slideshow.macroEnabled.12'
|
||||
]):
|
||||
].includes(mimeTypeParts[1]):
|
||||
result = FileType.Presentation;
|
||||
break;
|
||||
// no default
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import _ from '_';
|
|||
import ko from 'ko';
|
||||
|
||||
import { FilterRulesType, FiltersAction } from 'Common/Enums';
|
||||
import { pString, inArray, isNonEmptyArray, fakeMd5, delegateRunOnDestroy, windowResizeCallback } from 'Common/Utils';
|
||||
import { pString, isNonEmptyArray, fakeMd5, delegateRunOnDestroy, windowResizeCallback } from 'Common/Utils';
|
||||
import { i18n } from 'Common/Translator';
|
||||
import { getFolderFromCacheList } from 'Common/Cache';
|
||||
|
||||
|
|
@ -152,21 +152,19 @@ class FilterModel extends AbstractModel {
|
|||
}
|
||||
|
||||
if ('' === this.actionValue()) {
|
||||
if (
|
||||
-1 <
|
||||
inArray(this.actionType(), [
|
||||
if ([
|
||||
FiltersAction.MoveTo,
|
||||
FiltersAction.Forward,
|
||||
FiltersAction.Reject,
|
||||
FiltersAction.Vacation
|
||||
])
|
||||
].includes(this.actionType())
|
||||
) {
|
||||
this.actionValue.error(true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (FiltersAction.Forward === this.actionType() && -1 === this.actionValue().indexOf('@')) {
|
||||
if (FiltersAction.Forward === this.actionType() && !this.actionValue().includes('@')) {
|
||||
this.actionValue.error(true);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -174,7 +172,7 @@ class FilterModel extends AbstractModel {
|
|||
if (
|
||||
FiltersAction.Vacation === this.actionType() &&
|
||||
'' !== this.actionValueFourth() &&
|
||||
-1 === this.actionValueFourth().indexOf('@')
|
||||
!this.actionValueFourth().includes('@')
|
||||
) {
|
||||
this.actionValueFourth.error(true);
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import { DATA_IMAGE_LAZY_PLACEHOLDER_PIC } from 'Common/Consts';
|
|||
|
||||
import {
|
||||
pInt,
|
||||
inArray,
|
||||
isArray,
|
||||
isUnd,
|
||||
trim,
|
||||
|
|
@ -253,7 +252,7 @@ class MessageModel extends AbstractModel {
|
|||
if (json && 'Object/Message' === json['@Object']) {
|
||||
priority = pInt(json.Priority);
|
||||
this.priority(
|
||||
-1 < inArray(priority, [MessagePriority.High, MessagePriority.Low]) ? priority : MessagePriority.Normal
|
||||
[MessagePriority.High, MessagePriority.Low].includes(priority) ? priority : MessagePriority.Normal
|
||||
);
|
||||
|
||||
this.folderFullNameRaw = json.Folder;
|
||||
|
|
@ -313,7 +312,7 @@ class MessageModel extends AbstractModel {
|
|||
if (json && 'Object/Message' === json['@Object']) {
|
||||
priority = pInt(json.Priority);
|
||||
this.priority(
|
||||
-1 < inArray(priority, [MessagePriority.High, MessagePriority.Low]) ? priority : MessagePriority.Normal
|
||||
[MessagePriority.High, MessagePriority.Low].includes(priority) ? priority : MessagePriority.Normal
|
||||
);
|
||||
|
||||
this.aDraftInfo = json.DraftInfo;
|
||||
|
|
@ -362,7 +361,7 @@ class MessageModel extends AbstractModel {
|
|||
if (
|
||||
'' !== attachment.cidWithOutTags &&
|
||||
0 < this.foundedCIDs.length &&
|
||||
0 <= inArray(attachment.cidWithOutTags, this.foundedCIDs)
|
||||
this.foundedCIDs.includes(attachment.cidWithOutTags)
|
||||
) {
|
||||
attachment.isLinked = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue