wemoji: Universal Emoji Database
wemoji is a JavaScript library providing a universal emoji database, designed as a near drop-in replacement for `gemoji`. Currently at version `1.0.1`, the project appears to have an infrequent release cadence, with the last significant activity dating back to 2016. Its primary differentiators include a dataset reported to be superior to `gemoji`, and a comprehensive set of perfectly matched CSS and emoji picker assets for consistent visual display across various platforms (Apple, Google, Twitter styles). It is built upon the `emoji-data` project and aims to provide harmony between front-end and back-end emoji rendering, although its asset management relies on older tools like Bower and manual file copying.
Common errors
-
ReferenceError: require is not defined in ES module scope
cause Attempting to use `require()` in a JavaScript file that is treated as an ES module (e.g., by having `"type": "module"` in `package.json` or a `.mjs` extension) for a CommonJS-only library.fixEither convert your file to CommonJS (`.js` extension without `"type": "module"`) or use a bundler (like Webpack or Rollup) configured to handle CommonJS modules within an ES module project. -
TypeError: Cannot read properties of undefined (reading 'dragon')
cause The `wemoji` object or its nested properties (`name`, `unicode`) were not correctly loaded or are undefined, often due to an incorrect `require` or `import` statement, or the package not being installed.fixVerify that `wemoji` is correctly installed (`npm install wemoji`) and that `const wemoji = require('wemoji');` successfully retrieves the package's exports. Ensure you are accessing `wemoji.name` or `wemoji.unicode` after the `wemoji` object has been loaded. -
Emoji images are not appearing, or only text descriptions are shown.
cause The necessary front-end CSS files (e.g., `wemoji-tw.css`) and their corresponding image assets are missing, not correctly linked, or their paths are misconfigured.fixManually copy the CSS and image assets from the `wemoji` GitHub repository's `dist` folder or the `emoji-data` project. Ensure the CSS files are included in your HTML and that the image paths specified within the CSS are correct and accessible.
Warnings
- breaking The wemoji project is abandoned; its last significant commit was in 2016. This means the emoji database is severely outdated and will not include newer Unicode emoji beyond version 9.0. There will be no security updates, bug fixes, or new feature development.
- gotcha wemoji is primarily designed for CommonJS environments. Attempting to use native ES module `import` syntax will result in errors (e.g., 'require is not defined') unless a bundler (like Webpack or Rollup) is specifically configured for CommonJS interop.
- deprecated Front-end assets (CSS and images for different platform styles) are recommended to be installed via `bower`, which is a largely deprecated package manager. The manual asset management process detailed in the README (copying from `emoji-data` submodule) is cumbersome and error-prone.
- gotcha The `platforms` array (e.g., `tw`, `a`, `g`) in emoji data refers to Twitter, Apple, and Google emoji styles. Displaying these requires corresponding CSS files (e.g., `wemoji-tw.css`) and image assets, which are not included in the main `wemoji` npm package and must be installed/managed separately.
Install
-
npm install wemoji -
yarn add wemoji -
pnpm add wemoji
Imports
- wemoji
import wemoji from 'wemoji';
const wemoji = require('wemoji'); - wemoji.name
import { name } from 'wemoji';const dragonEmoji = wemoji.name['dragon'];
- wemoji.unicode
import { unicode } from 'wemoji';const loveHotelEmoji = wemoji.unicode['🏩'];
Quickstart
const wemoji = require('wemoji');
// Access emoji data by short name
const dragonEmoji = wemoji.name['dragon'];
console.log('Dragon Emoji Data:', dragonEmoji);
/*
Yields:
{
emoji: '🐉',
platforms: [ 'tw', 'a', 'g' ],
description: 'DRAGON',
name: 'dragon',
css: 'dragon',
category: 'animal'
}
*/
// Access emoji data by unicode character
const loveHotelEmoji = wemoji.unicode['🏩'];
console.log('Love Hotel Emoji Data:', loveHotelEmoji);
/*
Yields:
{
emoji: '🏩',
platforms: [ 'tw', 'a', 'g' ],
description: 'LOVE HOTEL',
name: 'love_hotel',
css: 'love_hotel',
category: 'travel'
}
*/