1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00

Remove unnecessary stringFromCodePoint function polyfill in emoji_utils

Removed the unnecessary stringFromCodePoint function polyfill from the emoji_utils.ts file. Instead, we use the built-in JavaScript function String.fromCodePoint to simplify the code.
This commit is contained in:
taichi221228 2024-04-24 10:00:13 +09:00
parent 47b82ee7c8
commit 1c4cf654d7

View file

@ -36,50 +36,6 @@ const buildSearch = (data: Data) => {
/* eslint-disable */ /* eslint-disable */
const _String = String;
const stringFromCodePoint =
_String.fromCodePoint ||
function () {
let MAX_SIZE = 0x4000;
let codeUnits = [];
let highSurrogate;
let lowSurrogate;
let index = -1;
let length = arguments.length;
if (!length) {
return '';
}
let result = '';
while (++index < length) {
let codePoint = Number(arguments[index]);
if (
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
codePoint < 0 || // not a valid Unicode code point
codePoint > 0x10ffff || // not a valid Unicode code point
Math.floor(codePoint) !== codePoint // not an integer
) {
throw RangeError('Invalid code point: ' + codePoint);
}
if (codePoint <= 0xffff) {
// BMP code point
codeUnits.push(codePoint);
} else {
// Astral code point; split in surrogate halves
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
codePoint -= 0x10000;
highSurrogate = (codePoint >> 10) + 0xd800;
lowSurrogate = (codePoint % 0x400) + 0xdc00;
codeUnits.push(highSurrogate, lowSurrogate);
}
if (index + 1 === length || codeUnits.length > MAX_SIZE) {
result += String.fromCharCode.apply(null, codeUnits);
codeUnits.length = 0;
}
}
return result;
};
const _JSON = JSON; const _JSON = JSON;
const COLONS_REGEX = /^(?::([^:]+):)(?::skin-tone-(\d):)?$/; const COLONS_REGEX = /^(?::([^:]+):)(?::skin-tone-(\d):)?$/;
@ -91,7 +47,7 @@ function unifiedToNative(unified) {
// @ts-expect-error // @ts-expect-error
codePoints = unicodes.map((u) => `0x${u}`); codePoints = unicodes.map((u) => `0x${u}`);
return stringFromCodePoint.apply(null, codePoints); return String.fromCodePoint(...codePoints);
} }
// @ts-expect-error // @ts-expect-error