gomojiui

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 3 Imported by: 1

README ยถ

go-moji-ui

Report Card

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: ๐Ÿ˜Š
}

Documentation ยถ

Index ยถ

Constants ยถ

This section is empty.

Variables ยถ

This section is empty.

Functions ยถ

func ContainsEmoji ยถ

func ContainsEmoji(text string) bool

Checks if a string contains any emoji.

func CountEmojiRunes ยถ

func CountEmojiRunes(text string) map[string]int

CountEmojiRunes counts the number of runes for each emoji in a string. Returns a map of emoji to rune count.

func FilterEmojisBySize ยถ added in v1.0.2

func FilterEmojisBySize(text string, runes int) string

Removes emojis that are larger or equal to the number of runes provided.

func RemoveEmoji ยถ

func RemoveEmoji(text string) string

Removes all emojis from a string.

Types ยถ

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL