1.0.4 β’ Published 6 months ago
emoji-contextualizer v1.0.4
Emoji Contextualizer
Emoji Contextualizer is a lightweight & customizable JavaScript library that transforms plain text into fun, expressive emoji-enhanced text by replacing specific words or phrases with contextually appropriate emojis. Ideal for chat applications, social media platforms, or anywhere you want to add a touch of emoji magic! πͺβ¨
Link to the package on npm
Features
- Replace words or phrases in a string with relevant emojis based on customizable mappings.
- Case-insensitive matching for seamless transformations.
- Add your own custom emoji mappings, appending to or creating new mappings for the library.
- Option to replace the word with the emoji or append the emoji after the word.
- Perfect for social media platforms, chatbots, and fun blogs!
- Outputs:
- Original Text: The input text as-is.
- Modified Text: The text with emojis substituted.
- Found Emojis: A list of emojis and their corresponding words found in the text.
- Emoji Mapping: The emoji mappings used to transform the text, including the default mappings and any custom mappings passed by the user.
- Replace Type: The type of replacement used (replace or append).
Installation
Install the package via npm:
npm install emoji-contextualizer
Usage
Hereβs how you can use Emoji Contextualizer:
// Import the library
const EmojiContextualizer = require("emoji-contextualizer");
// Initialize the library with custom mappings (Optional)
const customMapping = {
"π": ["happy"],
"π": ["star", "shine"],
};
// Create an instance of the EmojiContextualizer class with custom mappings
const contextualizer = new EmojiContextualizer(customMapping);
// Input text to be contextualized
const inputText = "I love pizza, laughing, and shining like a star.";
// Contextualize the input text & log the result
const result = contextualizer.contextualize(inputText);
console.log(result);
/*
The result will consist of the original text, modified text, found emojis, and emoji mapping as follows
{
originalText: 'I love pizza, laughing, and shining like a star.',
modifiedText: 'I β€οΈ π , π , and shining like a π .',
foundEmojis: {
'β€οΈ': [ 'love' ],
'π': [ 'laughing' ],
'π': [ 'pizza' ],
'π': [ 'star' ]
},
emojiMapping: {
'β€οΈ': [ 'love', 'heart' ],
'π': [ 'laugh', 'funny', 'lol', 'laughing', 'happy' ],
'π': [ 'pizza', 'food' ],
'π': [ 'cool', 'style' ],
'π': [ 'star', 'shine' ]
}
}
*/
For Maintainers
After making changes to the library, follow these steps to publish a new version to npm:
- Change the version in
package.json
. - Run
npm publish --access public
to publish the package to npm.