Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
is-emoji-supported
Advanced tools
is-emoji-supported is a library allowing you to detect if the running device supports the specified emoji.
As of March 2020, the Unicode Standard includes a total of 3 304 emojis. The latest version introduced 117 new ones and vendors have troubles implementing them. In fact there are no operating system supporting all of them. Therefore there is a need to know if a specified emoji isn't supported by the browser to fallback to an image.
Install with yarn:
$ yarn add is-emoji-supported
Or install using npm:
$ npm i is-emoji-supported
$ npm test
The most basic usage is to use the function directly to detect is the current device support the emoji.
import {isEmojiSupported} from 'is-emoji-supported';
if (isEmojiSupported('🦄')) {
alert('Houra 🦄 is supported');
} else {
alert('No support for unicorn emoji yet');
}
This library is doing pixel comparison to determine if an emoji is supported. This check can be slow so there is a memory cache implemented.
For some reasons you may want to use your own cache implementation to store the result in either localStorage, IndexedDB or anything else for persistent cache.
You only need to match the Map
interface.
import {setCacheHandler} from 'is-emoji-supported';
const key = 'emoji-cache';
const cache = JSON.parse(localStorage.getItem(key) || {});
setCacheHandler({
has: (unicode: string) => unicode in cache,
get: (unicode: string) => cache[unicode],
set: (unicode: string, supported: boolean) => {
cache[unicode] = supported;
localStorage.setItem(key, JSON.stringify(cache));
}
});
In most of the cases, you will want to fallback to images to handle unsupported emojis. The best way for this is to build an object with a fallback to all supported images. You can build your own or use the one given by JoyPixel, Twemoji or others services.
import React from 'react';
import {isEmojiSupported} from 'is-emoji-supported';
const emojiMap = {
'🦄': {
alt: 'unicorn',
src: '/images/unicorn.png'
},
...
};
export const Emoji = ({ unicode }) => {
const attrs = emojiMap[unicode];
return !attrs ? null : isEmojiSupported(unicode) ? (
<span role="img" aria-label={attrs.alt}>
{unicode}
</span>
) : (
<img {...attrs} />
);
};
FAQs
Detect if the current device support the specified emoji
The npm package is-emoji-supported receives a total of 29,422 weekly downloads. As such, is-emoji-supported popularity was classified as popular.
We found that is-emoji-supported demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.