Helpful functions to work with emoji in Golang

GoMoji

work with emoji in the most convenient way

GoMoji is a Go package that provides a fast and simple way to work with emojis in strings. It has features such as:

Getting Started

Installing

To start using GoMoji, install Go and run go get:

$ go get -u github.com/forPelevin/gomoji

This will retrieve the package.

Check string contains emoji

package main

import (
    "github.com/forPelevin/gomoji"
)

func main() {
    res := gomoji.ContainsEmoji("hello world")
    println(res) // false
    
    res = gomoji.ContainsEmoji("hello world 🤗")
    println(res) // true
}

Find all

The function searches for all emoji occurrences in a string. It returns a nil slice if there are no emojis.

package main

import (
    "github.com/forPelevin/gomoji"
)

func main() {
    res := gomoji.FindAll("🧖 hello 🦋 world")
    println(res)
}

Get all

The function returns all existed emojis. You can do whatever you need with the list.

package main

import (
    "github.com/forPelevin/gomoji"
)

func main() {
    emojis := gomoji.AllEmojis()
    println(emojis)
}

Emoji entity

All searching methods return the Emoji entity which contains comprehensive info about emoji.

type Emoji struct {
    Slug        string `json:"slug"`
    Character   string `json:"character"`
    UnicodeName string `json:"unicode_name"`
    CodePoint   string `json:"code_point"`
    Group       string `json:"group"`
    SubGroup    string `json:"sub_group"`
}

Example:

[]gomoji.Emoji{
    {
        Slug:        "e3-0-butterfly",
        Character:   "🦋",
        UnicodeName: "E3.0 butterfly",
        CodePoint:   "1F98B",
        Group:       "animals-nature",
        SubGroup:    "animal-bug",
    },
    {
        Slug:        "roll-of-paper",
        Character:   "🧻",
        UnicodeName: "roll of paper",
        CodePoint:   "1F9FB",
        Group:       "objects",
        SubGroup:    "household",
    },
}

Performance

Benchmarks of GoMoji

BenchmarkContainsEmojiParallel-8   	94079461	        13.1 ns/op	       0 B/op	       0 allocs/op
BenchmarkContainsEmoji-8           	23728635	        49.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkFindAllParallel-8         	10220854	       115 ns/op	     288 B/op	       2 allocs/op
BenchmarkFindAll-8                 	 4023626	       294 ns/op	     288 B/op	       2 allocs/op

Contact

Vlad Gukasov @vgukasov

License

GoMoji source code is available under the MIT License.

Owner
Vlad Gukasov
SWE from St. Petersburg, Russia
Vlad Gukasov
Comments
  • Added collect all function to find all emojis in a string without eliminating duplicates

    Added collect all function to find all emojis in a string without eliminating duplicates

    I really wanted to use gomoji but it's missing a way to collect all emojis in a string as-is, without ignoring repeating emojis.

    I am building a service that analyzes emojis in strings and need a way to detect which emojis appear and how many times.

    I also feel like this behavior is more suiting the name FindAll and the current behavior of FindAll should be relocated to a FindAllDistinct.

  • Add support for

    Add support for "new-button"

    Seems like 🆕 is not included in the list (ref).

    @forPelevin I don't know what to put in UnicodeName so I left a ? for now, let me know what to put there.

  • Regional indicators are not supported.

    Regional indicators are not supported.

    I have a json like so:

    [{"emoji": "🇦", "id": 855898699988205598},
    {"emoji": "🇧", "id": 855908027546468414},
    {"emoji": "🇨", "id": 855910336619872306},
    {"emoji": "🇩", "id": 874810967303802891},
    {"emoji": "🇪", "id": 855908176960552971},
    {"emoji": "🇫", "id": 855895610129645598},
    {"emoji": "🇬", "id": 856311847765934080},
    {"emoji": "🇭", "id": 863577067869437962},
    {"emoji": "🇮", "id": 855998416941481984},
    {"emoji": "🇯", "id": 872964477518229524},
    {"emoji": "🇰", "id": 855901430544203787},
    {"emoji": "🇱", "id": 856312436171997214},
    {"emoji": "🇲", "id": 892549953568788511},
    {"emoji": "🇳", "id": 856661374465474590},
    {"emoji": "🇴", "id": 875603397171097660},
    {"emoji": "🇵", "id": 855910253577240628},
    {"emoji": "🇶", "id": 855895290828423168},
    {"emoji": "🇷", "id": 855896139885445151}]
    

    using

    gomoji.CollectAll(s)
    

    Returns an empty slice.

  • Skintone support

    Skintone support

    	gomoji.ContainsEmoji(👍🏿) 
    

    returns false

    while

    	gomoji.ContainsEmoji(👍) 
    

    is true. I can open a PR to fix this but i see your emoji's are generated by some generator.go file that is not included in this Repo @forPelevin

  • All numbers are judged as emoji

    All numbers are judged as emoji

    Hi there, I found if the string including any number, there will always return true, for example:

    package main
    
    import (
    	"fmt"
    
    	"github.com/forPelevin/gomoji"
    )
    
    func main() {
    	fmt.Println(gomoji.ContainsEmoji("1"))
    	// output: true
    
    	fmt.Println(gomoji.ContainsEmoji("asdf1"))
    	// output: true
    
    	fmt.Println(gomoji.ContainsEmoji("asdf"))
    	// output: false
    }
    
    
  • Support for latest emoji release https://unicode.org/emoji/charts-14.0/emoji-released.html

    Support for latest emoji release https://unicode.org/emoji/charts-14.0/emoji-released.html

    Thanks for this library. It's very useful for detecting emojis in a fast and efficient manner.

    This library is using the emoji api which only supports Emojis up to v13.0 currently. Can we update it to support the latest release https://emojipedia.org/unicode-14.0/ too? Could possibly fetch the API and then statically add the new ones in generator.go until the Emoji API is updated for this?

    Official release: https://unicode.org/emoji/charts-14.0/emoji-released.html

  • Feature request: Emoji replacement

    Feature request: Emoji replacement

    Hi @forPelevin, thank you for maintaining the project.

    I'm glad that I discovered this project as I find myself needing to work with emojis in Golang 😄 However, one of my use cases involves replacing all emojis within a string with a given rune.

    Since I've already worked on it on my own fork, I'll open up a PR against the main branch to see what you think 👍

  • Don't require golangci-lint

    Don't require golangci-lint

    Not having the golangci-lint package (incl all its dependencies) as an explicit module requirement avoids triggering dozens of Snyk alerts in projects that are requiring gomoji.

A minimalistic emoji package for Go (golang)

emoji ?? ?? ?? emoji is a minimalistic emoji library for Go. It lets you use emoji characters in strings. Inspired by spatie/emoji Install ?? go get g

Dec 14, 2022
A golang package to work with Decentralized Identifiers (DIDs)

did did is a Go package that provides tools to work with Decentralized Identifiers (DIDs). Install go get github.com/ockam-network/did Example packag

Nov 25, 2022
Package sanitize provides functions for sanitizing text in golang strings.

sanitize Package sanitize provides functions to sanitize html and paths with go (golang). FUNCTIONS sanitize.Accents(s string) string Accents replaces

Dec 5, 2022
Golang metrics for calculating string similarity and other string utility functions

strutil strutil provides string metrics for calculating string similarity as well as other string utility functions. Full documentation can be found a

Jan 3, 2023
This package provides Go (golang) types and helper functions to do some basic but useful things with mxGraph diagrams in XML, which is most famously used by app.diagrams.net, the new name of draw.io.

Go Draw - Golang MX This package provides types and helper functions to do some basic but useful things with mxGraph diagrams in XML, which is most fa

Aug 30, 2022
A collection of well-known string hash functions, implemented in Go

This library is a collection of "well-known" 32-bit string hashes, implemented in Go. It includes: Java string hash ELF-32 Jenkins' One-A

Mar 3, 2022
Useful template functions for Go templates.

Sprig: Template functions for Go templates The Go language comes with a built-in template language, but not very many template functions. Sprig is a l

Dec 31, 2022
[Crawler/Scraper for Golang]🕷A lightweight distributed friendly Golang crawler framework.一个轻量的分布式友好的 Golang 爬虫框架。

Goribot 一个分布式友好的轻量的 Golang 爬虫框架。 完整文档 | Document !! Warning !! Goribot 已经被迁移到 Gospider|github.com/zhshch2002/gospider。修复了一些调度问题并分离了网络请求部分到另一个仓库。此仓库会继续

Oct 29, 2022
golang 在线预览word,excel,pdf,MarkDown(Online Preview Word,Excel,PPT,PDF,Image by Golang)
golang 在线预览word,excel,pdf,MarkDown(Online Preview Word,Excel,PPT,PDF,Image by Golang)

Go View File 在线体验地址 http://39.97.98.75:8082/view/upload (不会经常更新,保留最基本的预览功能。服务器配置较低,如果出现链接超时请等待几秒刷新重试,或者换Chrome) 目前已经完成 docker部署 (不用为运行环境烦恼) Wor

Dec 26, 2022
bluemonday: a fast golang HTML sanitizer (inspired by the OWASP Java HTML Sanitizer) to scrub user generated content of XSS

bluemonday bluemonday is a HTML sanitizer implemented in Go. It is fast and highly configurable. bluemonday takes untrusted user generated content as

Jan 4, 2023
Elegant Scraper and Crawler Framework for Golang

Colly Lightning Fast and Elegant Scraping Framework for Gophers Colly provides a clean interface to write any kind of crawler/scraper/spider. With Col

Dec 30, 2022
wcwidth for golang

go-runewidth Provides functions to get fixed width of the character or string. Usage runewidth.StringWidth("つのだ☆HIRO") == 12 Author Yasuhiro Matsumoto

Dec 11, 2022
Parses the Graphviz DOT language in golang

Parses the Graphviz DOT language and creates an interface, in golang, with which to easily create new and manipulate existing graphs which can be writ

Dec 25, 2022
Go (Golang) GNU gettext utilities package

Gotext GNU gettext utilities for Go. Features Implements GNU gettext support in native Go. Complete support for PO files including: Support for multil

Dec 18, 2022
htmlquery is golang XPath package for HTML query.

htmlquery Overview htmlquery is an XPath query package for HTML, lets you extract data or evaluate from HTML documents by an XPath expression. htmlque

Jan 4, 2023
omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.
omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.

omniparser Omniparser is a native Golang ETL parser that ingests input data of various formats (CSV, txt, fixed length/width, XML, EDI/X12/EDIFACT, JS

Jan 4, 2023
Pagser is a simple, extensible, configurable parse and deserialize html page to struct based on goquery and struct tags for golang crawler
Pagser is a simple, extensible, configurable parse and deserialize html page to struct based on goquery and struct tags for golang crawler

Pagser Pagser inspired by page parser。 Pagser is a simple, extensible, configurable parse and deserialize html page to struct based on goquery and str

Dec 13, 2022
iTunes and RSS 2.0 Podcast Generator in Golang

podcast Package podcast generates a fully compliant iTunes and RSS 2.0 podcast feed for GoLang using a simple API. Full documentation with detailed ex

Dec 23, 2022
TOML parser for Golang with reflection.

THIS PROJECT IS UNMAINTAINED The last commit to this repo before writing this message occurred over two years ago. While it was never my intention to

Dec 30, 2022