semaphore/src/routes/_utils/testEmojiSupported.js

281 lines
4.8 KiB
JavaScript

import { isEmojiSupported, setCacheHandler } from 'is-emoji-supported'
import { QuickLRU } from '../_thirdparty/quick-lru/quick-lru.js'
import { store } from '../_store/store.js'
// avoid recomputing emoji support over and over again
// use our own LRU since the built-in one grows forever, which is a small memory leak, but still
setCacheHandler(new QuickLRU({ maxSize: 500 }))
const COUNTRY_FLAG_EMOJI = new Set(
[
'🇦🇨',
'🇦🇩',
'🇦🇪',
'🇦🇫',
'🇦🇬',
'🇦🇮',
'🇦🇱',
'🇦🇲',
'🇦🇴',
'🇦🇶',
'🇦🇷',
'🇦🇸',
'🇦🇹',
'🇦🇺',
'🇦🇼',
'🇦🇽',
'🇦🇿',
'🇧🇦',
'🇧🇧',
'🇧🇩',
'🇧🇪',
'🇧🇫',
'🇧🇬',
'🇧🇭',
'🇧🇮',
'🇧🇯',
'🇧🇱',
'🇧🇲',
'🇧🇳',
'🇧🇴',
'🇧🇶',
'🇧🇷',
'🇧🇸',
'🇧🇹',
'🇧🇻',
'🇧🇼',
'🇧🇾',
'🇧🇿',
'🇨🇦',
'🇨🇨',
'🇨🇩',
'🇨🇫',
'🇨🇬',
'🇨🇭',
'🇨🇮',
'🇨🇰',
'🇨🇱',
'🇨🇲',
'🇨🇳',
'🇨🇴',
'🇨🇵',
'🇨🇷',
'🇨🇺',
'🇨🇻',
'🇨🇼',
'🇨🇽',
'🇨🇾',
'🇨🇿',
'🇩🇪',
'🇩🇬',
'🇩🇯',
'🇩🇰',
'🇩🇲',
'🇩🇴',
'🇩🇿',
'🇪🇦',
'🇪🇨',
'🇪🇪',
'🇪🇬',
'🇪🇭',
'🇪🇷',
'🇪🇸',
'🇪🇹',
'🇪🇺',
'🇫🇮',
'🇫🇯',
'🇫🇰',
'🇫🇲',
'🇫🇴',
'🇫🇷',
'🇬🇦',
'🇬🇧',
'🇬🇩',
'🇬🇪',
'🇬🇫',
'🇬🇬',
'🇬🇭',
'🇬🇮',
'🇬🇱',
'🇬🇲',
'🇬🇳',
'🇬🇵',
'🇬🇶',
'🇬🇷',
'🇬🇸',
'🇬🇹',
'🇬🇺',
'🇬🇼',
'🇬🇾',
'🇭🇰',
'🇭🇲',
'🇭🇳',
'🇭🇷',
'🇭🇹',
'🇭🇺',
'🇮🇨',
'🇮🇩',
'🇮🇪',
'🇮🇱',
'🇮🇲',
'🇮🇳',
'🇮🇴',
'🇮🇶',
'🇮🇷',
'🇮🇸',
'🇮🇹',
'🇯🇪',
'🇯🇲',
'🇯🇴',
'🇯🇵',
'🇰🇪',
'🇰🇬',
'🇰🇭',
'🇰🇮',
'🇰🇲',
'🇰🇳',
'🇰🇵',
'🇰🇷',
'🇰🇼',
'🇰🇾',
'🇰🇿',
'🇱🇦',
'🇱🇧',
'🇱🇨',
'🇱🇮',
'🇱🇰',
'🇱🇷',
'🇱🇸',
'🇱🇹',
'🇱🇺',
'🇱🇻',
'🇱🇾',
'🇲🇦',
'🇲🇨',
'🇲🇩',
'🇲🇪',
'🇲🇫',
'🇲🇬',
'🇲🇭',
'🇲🇰',
'🇲🇱',
'🇲🇲',
'🇲🇳',
'🇲🇴',
'🇲🇵',
'🇲🇶',
'🇲🇷',
'🇲🇸',
'🇲🇹',
'🇲🇺',
'🇲🇻',
'🇲🇼',
'🇲🇽',
'🇲🇾',
'🇲🇿',
'🇳🇦',
'🇳🇨',
'🇳🇪',
'🇳🇫',
'🇳🇬',
'🇳🇮',
'🇳🇱',
'🇳🇴',
'🇳🇵',
'🇳🇷',
'🇳🇺',
'🇳🇿',
'🇴🇲',
'🇵🇦',
'🇵🇪',
'🇵🇫',
'🇵🇬',
'🇵🇭',
'🇵🇰',
'🇵🇱',
'🇵🇲',
'🇵🇳',
'🇵🇷',
'🇵🇸',
'🇵🇹',
'🇵🇼',
'🇵🇾',
'🇶🇦',
'🇷🇪',
'🇷🇴',
'🇷🇸',
'🇷🇺',
'🇷🇼',
'🇸🇦',
'🇸🇧',
'🇸🇨',
'🇸🇩',
'🇸🇪',
'🇸🇬',
'🇸🇭',
'🇸🇮',
'🇸🇯',
'🇸🇰',
'🇸🇱',
'🇸🇲',
'🇸🇳',
'🇸🇴',
'🇸🇷',
'🇸🇸',
'🇸🇹',
'🇸🇻',
'🇸🇽',
'🇸🇾',
'🇸🇿',
'🇹🇦',
'🇹🇨',
'🇹🇩',
'🇹🇫',
'🇹🇬',
'🇹🇭',
'🇹🇯',
'🇹🇰',
'🇹🇱',
'🇹🇲',
'🇹🇳',
'🇹🇴',
'🇹🇷',
'🇹🇹',
'🇹🇻',
'🇹🇼',
'🇹🇿',
'🇺🇦',
'🇺🇬',
'🇺🇲',
'🇺🇳',
'🇺🇸',
'🇺🇾',
'🇺🇿',
'🇻🇦',
'🇻🇨',
'🇻🇪',
'🇻🇬',
'🇻🇮',
'🇻🇳',
'🇻🇺',
'🇼🇫',
'🇼🇸',
'🇽🇰',
'🇾🇪',
'🇾🇹',
'🇿🇦',
'🇿🇲',
'🇿🇼',
'🏴󠁧󠁢󠁥󠁮󠁧󠁿',
'🏴󠁧󠁢󠁳󠁣󠁴󠁿',
'🏴󠁧󠁢󠁷󠁬󠁳󠁿'
]
)
export function testEmojiSupported (unicode) {
if (store.get().polyfilledCountryFlagEmoji && COUNTRY_FLAG_EMOJI.has(unicode)) {
return true // just assume it's supported; is-emoji-supported doesn't work in this case
}
return isEmojiSupported(unicode)
}