Use Array.includes instead of indexOf

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
merge-requests/1727/head
marcin mikołajczak 2022-08-12 13:47:32 +02:00
rodzic cc5bb8b8e4
commit 66216bd5b6
11 zmienionych plików z 17 dodań i 17 usunięć

Wyświetl plik

@ -37,7 +37,7 @@ if (!HTMLCanvasElement.prototype.toBlob) {
const dataURL = this.toDataURL(type, quality);
let data;
if (dataURL.indexOf(BASE64_MARKER) >= 0) {
if (dataURL.includes(BASE64_MARKER)) {
const [, base64] = dataURL.split(BASE64_MARKER);
data = decodeBase64(base64);
} else {

Wyświetl plik

@ -30,7 +30,7 @@ const textAtCursorMatchesToken = (str: string, caretPosition: number, searchToke
word = str.slice(left, right + caretPosition);
}
if (!word || word.trim().length < 3 || searchTokens.indexOf(word[0]) === -1) {
if (!word || word.trim().length < 3 || !searchTokens.includes(word[0])) {
return [null, null];
}

Wyświetl plik

@ -23,7 +23,7 @@ const textAtCursorMatchesToken = (str: string, caretPosition: number) => {
word = str.slice(left, right + caretPosition);
}
if (!word || word.trim().length < 3 || ['@', ':', '#'].indexOf(word[0]) === -1) {
if (!word || word.trim().length < 3 || !['@', ':', '#'].includes(word[0])) {
return [null, null];
}

Wyświetl plik

@ -51,7 +51,7 @@ class MediaItem extends ImmutablePureComponent {
hoverToPlay = () => {
const { autoPlayGif } = this.props;
return !autoPlayGif && ['gifv', 'video'].indexOf(this.props.attachment.get('type')) !== -1;
return !autoPlayGif && ['gifv', 'video'].includes(this.props.attachment.get('type'));
}
handleClick = e => {
@ -93,7 +93,7 @@ class MediaItem extends ImmutablePureComponent {
style={{ objectPosition: `${x}% ${y}%` }}
/>
);
} else if (['gifv', 'video'].indexOf(attachment.get('type')) !== -1) {
} else if (['gifv', 'video'].includes(attachment.get('type'))) {
const conditionalAttributes = {};
if (isIOS()) {
conditionalAttributes.playsInline = '1';

Wyświetl plik

@ -85,8 +85,8 @@ export function search(value, { emojisToShowFilter, maxResults, include, exclude
pool = {};
data.categories.forEach(category => {
const isIncluded = include && include.length ? include.indexOf(category.name.toLowerCase()) > -1 : true;
const isExcluded = exclude && exclude.length ? exclude.indexOf(category.name.toLowerCase()) > -1 : false;
const isIncluded = include && include.length ? include.includes(category.name.toLowerCase()) : true;
const isExcluded = exclude && exclude.length ? exclude.includes(category.name.toLowerCase()) : false;
if (!isIncluded || isExcluded) {
return;
}
@ -95,8 +95,8 @@ export function search(value, { emojisToShowFilter, maxResults, include, exclude
});
if (custom.length) {
const customIsIncluded = include && include.length ? include.indexOf('custom') > -1 : true;
const customIsExcluded = exclude && exclude.length ? exclude.indexOf('custom') > -1 : false;
const customIsIncluded = include && include.length ? include.includes('custom') : true;
const customIsExcluded = exclude && exclude.length ? exclude.includes('custom') : false;
if (customIsIncluded && !customIsExcluded) {
addCustomToPool(custom, pool);
}

Wyświetl plik

@ -15,7 +15,7 @@ const buildSearch = (data) => {
(split ? string.split(/[-|_|\s]+/) : [string]).forEach((s) => {
s = s.toLowerCase();
if (search.indexOf(s) === -1) {
if (!search.includes(s)) {
search.push(s);
}
});
@ -190,7 +190,7 @@ function getData(emoji, skin, set) {
function uniq(arr) {
return arr.reduce((acc, item) => {
if (acc.indexOf(item) === -1) {
if (!acc.includes(item)) {
acc.push(item);
}
return acc;
@ -201,7 +201,7 @@ function intersect(a, b) {
const uniqA = uniq(a);
const uniqB = uniq(b);
return uniqA.filter(item => uniqB.indexOf(item) >= 0);
return uniqA.filter(item => uniqB.includes(item));
}
function deepMerge(a, b) {

Wyświetl plik

@ -26,7 +26,7 @@ const addAutoPlay = (html: string): string => {
const iframe = document.querySelector('iframe');
if (iframe) {
if (iframe.src.indexOf('?') !== -1) {
if (iframe.src.includes('?')) {
iframe.src += '&';
} else {
iframe.src += '?';

Wyświetl plik

@ -92,7 +92,7 @@ export default class ModalRoot extends React.PureComponent {
}
renderLoading = modalId => () => {
return ['MEDIA', 'VIDEO', 'BOOST', 'CONFIRM', 'ACTIONS'].indexOf(modalId) === -1 ? <ModalLoading /> : null;
return !['MEDIA', 'VIDEO', 'BOOST', 'CONFIRM', 'ACTIONS'].includes(modalId) ? <ModalLoading /> : null;
}
renderError = (props) => {

Wyświetl plik

@ -28,7 +28,7 @@ const UserPanel: React.FC<IUserPanel> = ({ accountId, action, badges, domain })
if (!account) return null;
const displayNameHtml = { __html: account.get('display_name_html') };
const acct = account.get('acct').indexOf('@') === -1 && domain ? `${account.get('acct')}@${domain}` : account.get('acct');
const acct = !account.get('acct').includes('@') && domain ? `${account.get('acct')}@${domain}` : account.get('acct');
const header = account.get('header');
const verified = account.get('verified');

Wyświetl plik

@ -352,7 +352,7 @@ const UI: React.FC = ({ children }) => {
const handleDragEnter = (e: DragEvent) => {
e.preventDefault();
if (e.target && dragTargets.current.indexOf(e.target) === -1) {
if (e.target && !dragTargets.current.includes(e.target)) {
dragTargets.current.push(e.target);
}

Wyświetl plik

@ -93,7 +93,7 @@ const toServerSideType = (columnType: string): string => {
case 'thread':
return columnType;
default:
if (columnType.indexOf('list:') > -1) {
if (columnType.includes('list:')) {
return 'home';
} else {
return 'public'; // community, account, hashtag