1.0.4 β€’ Published 6 months ago

emoji-contextualizer v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

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:

  1. Change the version in package.json.
  2. Run npm publish --access public to publish the package to npm.
1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago