go-moji-ui

A Golang library that provides functions to detect, remove, and count emojis in a string, including those composed of multiple runes.
Emojis can enhance terminal output, but they can also introduce rendering issues. Some terminals render emojis with incorrect spacing, causing misalignment and disrupting text layout. This library is designed to address these issues by providing utilities to detect, remove, or process emojis in text effectively.
This was created for JukeTUI, but can be useful elsewhere.
Library Features
- Emoji Detection: Identify the presence of emojis in a string via regex
- Emoji Removal: Strip emojis from a given string via regex
- Emoji Rune Count: Issues arise when emojis are 2+ runes. If we can account for the runes in each emoji, we can account for these spacing issues.
- Emoji Size Based Removal: Remove all emojis that have n or more runes based on a requested size (n).
Installation
Install the library on your terminal:
go get github.com/Treyson-Grange/go-moji-ui
Usage
import (
moji "github.com/Treyson-Grange/go-moji-ui"
)
func main() {
text := "Hello, World! ๐"
fmt.Println(moji.ContainsEmoji(text)) // Prints: true
text = "No Mojis! ๐ค๐ค๐ค๐ค๐ค๐ค๐ค๐ค๐ค"
fmt.Println(moji.RemoveEmoji(text)) // Prints: No Mojis!
text = "grapheme cluster moji! ๐จโ๐ฉโ๐งโ๐ฆ"
fmt.Println(moji.CountEmojiRunes(text)) // Prints: map[๐จโ๐ฉโ๐งโ๐ฆ:7]
text = "remove me: โค๏ธ Don't remove me: ๐"
fmt.Println(moji.FilterEmojisBySize(text, 2)) // Prints: remove me: Don't remove me: ๐
}