slackmoji
v1.1.0
Published
Tiny, zero-dependency converter from Slack :shortcode: emoji to real Unicode emoji.
Maintainers
Readme
slackmoji
Tiny, zero-dependency converter from Slack :shortcode: emoji to real Unicode emoji.
Slack sends messages with emoji as shortcodes (:tada:, :+1:). When you relay
that text to another channel (WhatsApp, SMS, email) the shortcodes show up
literally. slackmoji swaps them for the actual Unicode characters.
- ~45 KB of data, no dependencies
- Shortcodes sourced from iamcal/emoji-data — the same set Slack uses
- CJS + ESM + TypeScript types
Install
npm install slackmojiUsage
import { emojify } from 'slackmoji'
// const { emojify } = require('slackmoji')
emojify('shipped it :tada: :rocket:') // → 'shipped it 🎉 🚀'
emojify(':+1: lgtm') // → '👍 lgtm'
emojify('unknown :not_real: stays') // → 'unknown :not_real: stays'Skin-tone modifiers combine with the preceding emoji, as in Slack:
emojify(':wave::skin-tone-5:') // → '👋🏾'Handling unknown shortcodes
By default, shortcodes with no known emoji (e.g. custom Slack workspace emoji)
are left in place. Pass onUnknown to change that:
emojify(':rocket: :made_up:') // → '🚀 :made_up:' (default: 'keep')
emojify(':rocket: :made_up:', { onUnknown: 'strip' }) // → '🚀 '
emojify(':rocket: :made_up:', { onUnknown: 'error' }) // throws ErrorSingle lookups and the raw map are also exported:
import { get, emoji } from 'slackmoji'
get('rocket') // → '🚀'
get(':rocket:') // → '🚀'
emoji.fire // → '🔥'API
| Export | Description |
| ------------------ | ------------------------------------------------------------------------ |
| emojify(text, options?) | Replace every :shortcode: in text. options.onUnknown = 'keep' (default), 'strip', or 'error'. |
| get(shortcode) | Unicode emoji for one shortcode (with or without colons), or undefined.|
| emoji | The raw { shortcode: emoji } map. |
emojify is also the default export.
Regenerating the data
npm run generate # refreshes src/emoji.json from the upstream datasetLicense
MIT
