mirror of
https://github.com/mastodon/mastodon.git
synced 2025-01-10 12:16:23 +01:00
Rename emoji_utils.js to TS
This commit is contained in:
parent
35683ac154
commit
9c4f3ecdf6
@ -1,6 +1,9 @@
|
|||||||
// This code is largely borrowed from:
|
// This code is largely borrowed from:
|
||||||
// https://github.com/missive/emoji-mart/blob/5f2ffcc/src/utils/index.js
|
// https://github.com/missive/emoji-mart/blob/5f2ffcc/src/utils/index.js
|
||||||
|
|
||||||
|
/* eslint-disable */
|
||||||
|
// @ts-nocheck
|
||||||
|
|
||||||
import * as data from './emoji_mart_data_light';
|
import * as data from './emoji_mart_data_light';
|
||||||
|
|
||||||
const buildSearch = (data) => {
|
const buildSearch = (data) => {
|
||||||
@ -32,7 +35,9 @@ const buildSearch = (data) => {
|
|||||||
|
|
||||||
const _String = String;
|
const _String = String;
|
||||||
|
|
||||||
const stringFromCodePoint = _String.fromCodePoint || function () {
|
const stringFromCodePoint =
|
||||||
|
_String.fromCodePoint ||
|
||||||
|
function () {
|
||||||
let MAX_SIZE = 0x4000;
|
let MAX_SIZE = 0x4000;
|
||||||
let codeUnits = [];
|
let codeUnits = [];
|
||||||
let highSurrogate;
|
let highSurrogate;
|
||||||
@ -48,18 +53,20 @@ const stringFromCodePoint = _String.fromCodePoint || function () {
|
|||||||
if (
|
if (
|
||||||
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
|
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
|
||||||
codePoint < 0 || // not a valid Unicode code point
|
codePoint < 0 || // not a valid Unicode code point
|
||||||
codePoint > 0x10FFFF || // not a valid Unicode code point
|
codePoint > 0x10ffff || // not a valid Unicode code point
|
||||||
Math.floor(codePoint) !== codePoint // not an integer
|
Math.floor(codePoint) !== codePoint // not an integer
|
||||||
) {
|
) {
|
||||||
throw RangeError('Invalid code point: ' + codePoint);
|
throw RangeError('Invalid code point: ' + codePoint);
|
||||||
}
|
}
|
||||||
if (codePoint <= 0xFFFF) { // BMP code point
|
if (codePoint <= 0xffff) {
|
||||||
|
// BMP code point
|
||||||
codeUnits.push(codePoint);
|
codeUnits.push(codePoint);
|
||||||
} else { // Astral code point; split in surrogate halves
|
} else {
|
||||||
|
// Astral code point; split in surrogate halves
|
||||||
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
||||||
codePoint -= 0x10000;
|
codePoint -= 0x10000;
|
||||||
highSurrogate = (codePoint >> 10) + 0xD800;
|
highSurrogate = (codePoint >> 10) + 0xd800;
|
||||||
lowSurrogate = (codePoint % 0x400) + 0xDC00;
|
lowSurrogate = (codePoint % 0x400) + 0xdc00;
|
||||||
codeUnits.push(highSurrogate, lowSurrogate);
|
codeUnits.push(highSurrogate, lowSurrogate);
|
||||||
}
|
}
|
||||||
if (index + 1 === length || codeUnits.length > MAX_SIZE) {
|
if (index + 1 === length || codeUnits.length > MAX_SIZE) {
|
||||||
@ -70,14 +77,10 @@ const stringFromCodePoint = _String.fromCodePoint || function () {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const _JSON = JSON;
|
const _JSON = JSON;
|
||||||
|
|
||||||
const COLONS_REGEX = /^(?::([^:]+):)(?::skin-tone-(\d):)?$/;
|
const COLONS_REGEX = /^(?::([^:]+):)(?::skin-tone-(\d):)?$/;
|
||||||
const SKINS = [
|
const SKINS = ['1F3FA', '1F3FB', '1F3FC', '1F3FD', '1F3FE', '1F3FF'];
|
||||||
'1F3FA', '1F3FB', '1F3FC',
|
|
||||||
'1F3FD', '1F3FE', '1F3FF',
|
|
||||||
];
|
|
||||||
|
|
||||||
function unifiedToNative(unified) {
|
function unifiedToNative(unified) {
|
||||||
let unicodes = unified.split('-'),
|
let unicodes = unified.split('-'),
|
||||||
@ -87,7 +90,16 @@ function unifiedToNative(unified) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sanitize(emoji) {
|
function sanitize(emoji) {
|
||||||
let { name, short_names, skin_tone, skin_variations, emoticons, unified, custom, imageUrl } = emoji,
|
let {
|
||||||
|
name,
|
||||||
|
short_names,
|
||||||
|
skin_tone,
|
||||||
|
skin_variations,
|
||||||
|
emoticons,
|
||||||
|
unified,
|
||||||
|
custom,
|
||||||
|
imageUrl,
|
||||||
|
} = emoji,
|
||||||
id = emoji.id || short_names[0],
|
id = emoji.id || short_names[0],
|
||||||
colons = `:${id}:`;
|
colons = `:${id}:`;
|
||||||
|
|
||||||
@ -206,7 +218,7 @@ function intersect(a, b) {
|
|||||||
const uniqA = uniq(a);
|
const uniqA = uniq(a);
|
||||||
const uniqB = uniq(b);
|
const uniqB = uniq(b);
|
||||||
|
|
||||||
return uniqA.filter(item => uniqB.indexOf(item) >= 0);
|
return uniqA.filter((item) => uniqB.indexOf(item) >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deepMerge(a, b) {
|
function deepMerge(a, b) {
|
Loading…
x
Reference in New Issue
Block a user