@kvpasupuleti/text-to-emoji-converter
Version:
A flexible and customizable text-to-emoji converter for JavaScript and TypeScript applications.
98 lines (67 loc) • 1.89 kB
Markdown
A flexible and customizable text-to-emoji converter for JavaScript and TypeScript applications.
If you are using npm
```bash
npm install @kvpasupuleti/text-to-emoji-converter
```
If you are using yarn
```bash
yarn add @kvpasupuleti/text-to-emoji-converter
```
```typescript
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); // "🙋♂️ ❤️ 🍕!"
```
```typescript
// 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();
```
```typescript
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
```typescript
type EmojiMap = {
[]: string;
};
```
MIT