twemoji-parser is a lightweight JavaScript library developed by Twitter, specifically designed for identifying emoji entities within a given text string. It processes the input and returns an array of structured objects, each describing an identified emoji. These objects include properties such as the emoji's URL (typically pointing to Twemoji assets on a CDN), its `indices` within the original string, the `text` of the emoji itself, and its `type` (always 'emoji'). This library's primary function is to facilitate the rendering of emojis as Twemoji assets, a process that mirrors its internal use within Twitter's own mobile rendering systems. The current stable version is 14.0.0, aligning with the Unicode 14.0 and Emoji 14.0 specifications. While a precise release cadence is not explicitly stated, its official backing and active maintenance by Twitter ensure its ongoing relevance and stability. A key differentiator is its direct integration and compatibility with the broader Twemoji ecosystem, focusing solely on the parsing aspect rather than direct emoji rendering.
npm install twemoji-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and use the `parse` function to extract emoji entities from a string, including their text, indices, and asset URLs. It also shows a conceptual way to replace them with HTML image tags.
Review parsing results for new or complex emoji sequences if upgrading from an older major version. Ensure your Twemoji asset CDN (e.g., twemoji.maxcdn.com) is also serving 14.x assets to match parsing results.
When using `twemoji-parser` to replace emojis with `<img>` tags in HTML, always ensure that the surrounding HTML content is properly sanitized. Consider using DOM manipulation methods (e.g., `document.createElement`) or a secure templating engine, rather than direct `innerHTML` assignments, especially for user-generated content.
If precise control over Twemoji asset versions is needed for caching or consistency, implement a custom `buildUrl` option in the `parse` function to specify a fixed version number in the asset path (e.g., `v/14.0.0`). Consult the `twemoji` project's CDN documentation for available versioned asset paths.
Use a named import for ESM (`import { parse } from 'twemoji-parser';`) or correctly destructure for CommonJS (`const { parse } = require('twemoji-parser');`).Ensure you are using the `url` property from the parsed entities to correctly reference Twemoji assets (e.g., `<img src="entity.url" />`). Verify your CDN access (e.g., `twemoji.maxcdn.com`) and that your HTML/CSS allows images to display. Check for network errors loading the emoji images.
Install the type definitions: `npm install --save-dev @types/twemoji-parser`. Ensure that the `@types` package version is compatible with your `twemoji-parser` version. You might need to adjust `tsconfig.json` `moduleResolution` if you encounter issues with module detection.
No dependency data recorded yet.