npm.io
1.0.1 • Published 1 year ago

@kvpasupuleti/text-to-emoji-converter

Licence
MIT
Version
1.0.1
Deps
3
Size
16 kB
Vulns
0
Weekly
0
Stars
1

Text to Emoji Converter

A flexible and customizable text-to-emoji converter for JavaScript and TypeScript applications.

Installation

If you are using npm

npm install @kvpasupuleti/text-to-emoji-converter

If you are using yarn

yarn add @kvpasupuleti/text-to-emoji-converter

Usage

Basic Usage
import { EmojiConverter } from '@kvpasupuleti/text-to-emoji-converter';

// Create a new converter instance
const converter = new EmojiConverter();

// Convert text to emojis
const result = converter.convert('I love pizza!');
console.log(result); // "🙋‍♂️ ❤️ 🍕!"
Custom Emoji Mappings
// Add custom mappings during initialization
const customMappings = {
  'awesome': '🌟',
  'coding': '👨‍💻',
};
const converter = new EmojiConverter(customMappings);

// Or add them later
converter.addMappings({
  'fantastic': '✨',
  'javascript': '💛',
});

// Remove specific mappings
converter.removeMappings(['coding', 'javascript']);

// Reset to default mappings
converter.resetToDefault();

// Get current mappings
const currentMappings = converter.getMappings();

API Reference

EmojiConverter
Constructor
constructor(customEmojiMap?: EmojiMap)

Creates a new EmojiConverter instance with optional custom emoji mappings.

Methods
convert(text: string): string

Converts text to emojis using the configured emoji map.

addMappings(newMappings: EmojiMap): void

Adds new emoji mappings or overrides existing ones.

removeMappings(words: string[]): void

Removes emoji mappings for specific words.

getMappings(): EmojiMap

Returns the current emoji mappings.

resetToDefault(): void

Resets the emoji map to default mappings.

Types
type EmojiMap = {
  [key: string]: string;
};

License

MIT