mirror of
https://github.com/mastodon/mastodon.git
synced 2025-01-10 04:06:27 +01:00
Refactor buildSearch function in emoji_utils.ts
The buildSearch function has been refactored for better coding practices. More explicit typings and declaration were used, and the logic related to array search has been simplified for better readability. The 'eslint-disable' comment line was moved to a more appropriate location after these changes.
This commit is contained in:
parent
ac2b7a6cfb
commit
88afeb3654
@ -1,28 +1,25 @@
|
||||
// This code is largely borrowed from:
|
||||
// https://github.com/missive/emoji-mart/blob/5f2ffcc/src/utils/index.js
|
||||
|
||||
/* eslint-disable */
|
||||
import type { Emoji } from 'emoji-mart/dist-es/utils/data';
|
||||
|
||||
import * as data from './emoji_mart_data_light';
|
||||
|
||||
// @ts-expect-error
|
||||
const buildSearch = (data) => {
|
||||
// @ts-expect-error
|
||||
const search = [];
|
||||
type Data = Pick<Emoji, 'short_names' | 'name' | 'keywords' | 'emoticons'>;
|
||||
|
||||
// @ts-expect-error
|
||||
let addToSearch = (strings, split) => {
|
||||
const buildSearch = (data: Data) => {
|
||||
const search: string[] = [];
|
||||
|
||||
const addToSearch = (strings: Data[keyof Data], split: boolean) => {
|
||||
if (!strings) {
|
||||
return;
|
||||
}
|
||||
|
||||
(Array.isArray(strings) ? strings : [strings]).forEach((string) => {
|
||||
// @ts-expect-error
|
||||
(split ? string.split(/[-|_|\s]+/) : [string]).forEach((s) => {
|
||||
s = s.toLowerCase();
|
||||
|
||||
// @ts-expect-error
|
||||
if (search.indexOf(s) === -1) {
|
||||
if (!search.includes(s)) {
|
||||
search.push(s);
|
||||
}
|
||||
});
|
||||
@ -34,10 +31,11 @@ const buildSearch = (data) => {
|
||||
addToSearch(data.keywords, false);
|
||||
addToSearch(data.emoticons, false);
|
||||
|
||||
// @ts-expect-error
|
||||
return search.join(',');
|
||||
};
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
const _String = String;
|
||||
|
||||
const stringFromCodePoint =
|
||||
|
Loading…
x
Reference in New Issue
Block a user