From 562c8778fbf463b67bfabc3422e1f0be05110be5 Mon Sep 17 00:00:00 2001 From: taichi221228 Date: Wed, 24 Apr 2024 10:01:27 +0900 Subject: [PATCH] Refactor unifiedToNative function in emoji_utils The unifiedToNative function in emoji_utils.ts has been refactored for cleaner coding practices. Lint disabling has been moved to a different part of the code, and type checking has been revised to specify that the input unified is of type Emoji['unified']. The function's variables have been updated to const for better securities against undesired changes. --- .../mastodon/features/emoji/emoji_utils.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/javascript/mastodon/features/emoji/emoji_utils.ts b/app/javascript/mastodon/features/emoji/emoji_utils.ts index e1c8bbda08..3dc193b2ab 100644 --- a/app/javascript/mastodon/features/emoji/emoji_utils.ts +++ b/app/javascript/mastodon/features/emoji/emoji_utils.ts @@ -34,22 +34,20 @@ const buildSearch = (data: Data) => { return search.join(','); }; -/* eslint-disable */ - const _JSON = JSON; const COLONS_REGEX = /^(?::([^:]+):)(?::skin-tone-(\d):)?$/; const SKINS = ['1F3FA', '1F3FB', '1F3FC', '1F3FD', '1F3FE', '1F3FF']; -// @ts-expect-error -function unifiedToNative(unified) { - let unicodes = unified.split('-'), - // @ts-expect-error - codePoints = unicodes.map((u) => `0x${u}`); +function unifiedToNative(unified: Emoji['unified']) { + const unicodes = unified?.split('-') ?? []; + const codePoints = unicodes.map((u) => +`0x${u}`); return String.fromCodePoint(...codePoints); } +/* eslint-disable */ + // @ts-expect-error function sanitize(emoji) { let {