npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jacobwolf/is-emoji-supported

v1.0.1

Published

Detect if the current device support the specified emoji

Downloads

5

Readme

🦄 @jacobwolf/is-emoji-supported

npm npm

No dependency license: MIT

A lightweight library to detect emoji support in browsers and provide fallbacks.

This is a maintained fork of the original koala-interactive/is-emoji-supported package. It fixes the original package's source map issues and adds improvements in emoji detection and fallback handling.

Features

  • Detect emoji support across different browsers and devices
  • Provide fallback options for unsupported emojis
  • Lightweight with zero dependencies
  • Customizable caching for improved performance

📖 Table of Contents

🚀 Installation

Install with yarn:

$ yarn add @jacobwolf/is-emoji-supported

Install using npm:

$ npm install @jacobwolf/is-emoji-supported

Install using pnpm:

$ pnpm add @jacobwolf/is-emoji-supported

Install using bun:

$ bun add @jacobwolf/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.

import { isEmojiSupported } from "@jacobwolf/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 interface.

import { setCacheHandler } from "@jacobwolf/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, Twemoji or others services.

import React from 'react';
import {isEmojiSupported} from '@jacobwolf/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} />
  );
};

⏳ How to test

$ npm test

🤝 How to contribute

This project is a fork of the original koala-interactive/is-emoji-supported package.

  • Fork the project on GitHub

  • Clone your forked repository:

    $ git clone https://github.com/your-username/is-emoji-supported.git
    $ cd is-emoji-supported
  • Install dependencies:

    $ npm install
  • Create a new branch from main:

    $ git checkout -b contribution/fix/your-github-username

    OR

    $ git checkout -b contribution/improvement/your-github-username
  • Make your changes and commit them with clear, descriptive messages

  • Add or update tests as necessary

  • Ensure all tests pass:

    $ npm test
  • Push your changes to your fork:

    $ git push origin your-branch-name
  • Open a pull request on the original repository

License

Original work Copyright (c) 2023 Koala-Interactive.

Modified work Copyright (c) 2024 Jacob Wolf.

This project is MIT licensed.