Friendly emoji lookups and parsing utilities for Node.js. π
Node Emoji Nuxt Module supporting v3
- Add
node-emoji-nuxt
dependency to your project
npx nuxi@latest module add node-emoji-nuxt
- Add
node-emoji-nuxt
to themodules
section ofnuxt.config.ts
export default defineNuxtConfig({
modules: [
'node-emoji-nuxt'
]
})
You can use the provided $emoji
to access node-emoji-nuxt in template.
<template>
<div>
{{ $emoji.emojify("I :heart: :coffee:!") }}
</div>
</template>
You can use the useEmoji,useEmojify and useUnemojify composable to access node-emoji-nuxt anywhere.
const emoji = useEmoji()
emoji.emojify("I :heart: :coffee:!") // 'I β€οΈ βοΈ!'
// or use the useEmojify composable
emoji.unemojify('The π¦ is a fictitious animal.') // 'The :unicorn: is a fictitious animal.'
// or use the useUnemojify composable
Parse all markdown-encoded emojis in a string.
Parameters:
input
(string
): The input string containing the markdown-encoding emojis.options
(optional):fallback
(string
; default:""
): The string to fallback to if an emoji was not found.format
(() => (emoji: string, part: string, string: string) => string
; default:value => value
): Add a middleware layer to modify each matched emoji after parsing.
const emoji = useEmoji()
console.log(emoji.emojify('The :unicorn: is a fictitious animal.'))
// 'The π¦ is a fictitious animal.'
Get the name and character of an emoji.
Parameters:
emoji
(string
): The emoji to get the data of.
const emoji = useEmoji()
console.log(emoji.find('π¦'))
// { name: 'unicorn', emoji: 'π¦' }
Get an emoji from an emoji name.
Parameters:
name
(string
): The name of the emoji to get.
const emoji = useEmoji()
console.log(emoji.get('unicorn'))
// 'π¦'
Check if this library supports a specific emoji.
Parameters:
emoji
(string
): The emoji to check.
const emoji = useEmoji()
console.log(emoji.has('π¦'))
// true
Get a random emoji.
const emoji = useEmoji()
console.log(emoji.random())
// { name: 'unicorn', emoji: 'π¦' }
Replace the emojis in a string.
Parameters:
input
(string
): The input string.replacement
(string | (emoji: string, index: number, string: string) => string
): The character to replace the emoji with. Can be either a string or a callback that returns a string.
const emoji = useEmoji()
console.log(emoji.replace('The π¦ is a fictitious animal.', 'unicorn'))
// 'The unicorn is a fictitious animal.'
Search for emojis containing the provided name in their name.
Parameters:
keyword
(string
): The keyword to search for.
const emoji = useEmoji()
console.log(emoji.search('honey'))
// [ { name: 'honeybee', emoji: 'π' }, { name: 'honey_pot', emoji: 'π―' } ]
Remove all of the emojis from a string.
Parameters:
-
input
(string
): The input string to strip the emojis from. -
options
(optional):preserveSpaces
(boolean
): Whether to keep the extra space after a stripped emoji.
const emoji = useEmoji()
console.log(emoji.strip('π¦ The unicorn is a fictitious animal.'))
// 'The unicorn is a fictitious animal.'
console.log(
emoji.strip('π¦ The unicorn is a fictitious animal.', {
preserveSpaces: true,
}),
)
// ' The unicorn is a fictitious animal.'
Convert all emojis in a string to their markdown-encoded counterparts.
Parameters:
input
(string
): The input string containing the emojis.
const emoji = useEmoji()
console.log(emoji.unemojify('The π¦ is a fictitious animal.'))
// 'The :unicorn: is a fictitious animal.'
Get an emoji name from an emoji.
Parameters:
emoji
(string
): The emoji to get the name of.options
(optional):markdown
(boolean
; default:false
): Whether to return a":emoji:"
string instead of"emoji"
const emoji = useEmoji()
console.log(emoji.which('π¦'))
// 'unicorn'
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the playground
npm run dev:build
# Run ESLint
npm run lint
# Run Vitest
npm run test
npm run test:watch
# Release new version
npm run release