UNPKG

emoji-contextualizer

Version:

Emoji Contextualizer is a lightweight and customizable JavaScript library that replaces specific words or phrases in a string with contextually appropriate emojis. Perfect for chat applications, social media, or fun text transformations.

80 lines (62 loc) β€’ 2.91 kB
# 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](https://www.npmjs.com/package/emoji-contextualizer) ## 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: ```bash npm install emoji-contextualizer ``` ## Usage Here’s how you can use Emoji Contextualizer: ```javascript // 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: 1. Change the version in `package.json`. 2. Run `npm publish --access public` to publish the package to npm.