This is just a simple emoji parser that I built to get more experience in writing npm packages. You can view it here: simple-emoji-parser
This is a very light-weight package, so there's not much to it.
The main type that describes emojis.
interface Emoji {
name?: string, // optional - unique naming
id?: number, // optional - useful if you have duplicates
trigger: string, // the trigger word
url: string // the image URL to replace the trigger
}
The id
parameter is totally optional and is only useful for duplicates and/or where you need to manually tamper with the Emojis
array directly from the parser.
The central class of the package - where all the magic happens.
You need to initialize the class and pass the emojis array as a variable:
const parser = new EmojiParser(emojis);
parse(string: string, callback: (result: string) => void): void
| Parse a message that may contain emoji triggers and will return the parsed string in a callback.
parseSync(string: string): Promise<string>
| An asychronous method of the regular callback parse()
method.
You can access the emojis array through the getters & setters in EmojiParser
:
// Get all current emojis in the object
get emojis(): Array<Emoji> {
return this._emojis;
}
// Replace all current emojis
set emojis(emoji: Array<Emoji>) {
this._emojis = emoji;
}
All contribution is done through the official GitHub Repository. As usual, create a branch, do your work, and make a pull request.
<3