Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/koala-interactive/is-emoji-supported
Detect if the current attached device support the specified emoji
https://github.com/koala-interactive/is-emoji-supported
detect emoji emojione joypixels support unicode
Last synced: 19 days ago
JSON representation
Detect if the current attached device support the specified emoji
- Host: GitHub
- URL: https://github.com/koala-interactive/is-emoji-supported
- Owner: koala-interactive
- License: mit
- Created: 2020-06-15T10:11:27.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-07-13T02:01:11.000Z (over 1 year ago)
- Last Synced: 2024-11-28T23:37:52.655Z (24 days ago)
- Topics: detect, emoji, emojione, joypixels, support, unicode
- Language: TypeScript
- Homepage:
- Size: 1.35 MB
- Stars: 20
- Watchers: 12
- Forks: 7
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
![Logo](https://koala-interactive.com/logo.e927957b.svg)
# 🦄 is-emoji-supported
![No dependency](https://img.shields.io/badge/dependencies-none-blue.svg)
[![license: MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
![lint](https://github.com/koala-interactive/is-emoji-supported/workflows/lint/badge.svg?branch=master)
![e2e](https://github.com/koala-interactive/is-emoji-supported/workflows/e2e/badge.svg?branch=master)## Description
**is-emoji-supported** is a library allowing you to detect if the running device supports the specified emoji and helps you providing a solution if it does not support it.
## 📖 Table of content
- [Installation](#🚀-installation)
- [How to use](#🖥️-how-to-use)
- [How to test](#⏳-how-to-test)
- [How to contribute](#🤝-how-to-contribute)
- [List of our other package](#📦-list-of-our-other-package)
- [Join us](#⛵-join-us)
- [License](#license)## 🚀 Installation
Install with [yarn](https://yarnpkg.com):
$ yarn add is-emoji-supported
Or install using [npm](https://npmjs.org):
$ npm i is-emoji-supported
## 🖥️ How to use
### Basic usage
The most basic usage is to use the function directly to detect is the current device support the emoji.
```ts
import { isEmojiSupported } from "is-emoji-supported";if (isEmojiSupported("🦄")) {
alert("Houra 🦄 is supported");
} else {
alert("No support for unicorn emoji yet");
}
```### Usage with your own cache handler
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`](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Map) interface.```ts
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));
},
});
```### Fallback to images
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](https://www.joypixels.com/), [Twemoji](https://twemoji.twitter.com/) or others services.```jsx
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) ? (
{unicode}
) : (
);
};
```## ⏳ How to test
$ npm test
## 🤝 How to contribute
- fork the project
- (write how to to launch it)
- create a branch from main/master like that$ contribution/fix/your-github-identity
OR
$ contribution/improvment/your-github-identity
- push several (if needed) clear commits
- add tests following the way of the other ones have been wrote
- make sure that all test runs
- push your code## 📦 List of our other package
- [frenchkiss](https://www.npmjs.com/package/frenchkiss)
- [wowza-webrtc-player](https://www.npmjs.com/package/wowza-webrtc-player)
- [react-rich-mentions](https://www.npmjs.com/package/react-rich-mentions)
- [react-anchor-navigation](https://www.npmjs.com/package/react-anchor-navigation)## ⛵ Join us
May you want to share more than a pull request
check our [jobs opportunity](https://www.linkedin.com/company/koala-interactive/jobs/)## License
Copyright (c) 2023 [Koala-Interactive](https://koala-interactive.com/)
This project is [MIT](link-to-your-license-file) licensed.