Helpful functions to work with emoji in Golang
Go to file
Vlad Gukasov da2f8099da
add support of skin tone emojis (#7)
Co-authored-by: Vlad Gukasov <v.gukasov@space307.com>
2022-01-13 12:28:14 +03:00
.gitignore Implemented core functions (#1) 2021-01-02 18:50:08 +03:00
.golangci.yml Implemented core functions (#1) 2021-01-02 18:50:08 +03:00
LICENSE Added LICENSE 2021-01-02 18:10:22 +03:00
Makefile Fix an issue when digits were considered as emojis. Add new emojis. Add new functions: remove all emoji from a string, get emoji description (#5) 2021-12-29 19:53:44 +03:00
README.md add support of skin tone emojis (#7) 2022-01-13 12:28:14 +03:00
data.go add support of skin tone emojis (#7) 2022-01-13 12:28:14 +03:00
go.mod Fix an issue when digits were considered as emojis. Add new emojis. Add new functions: remove all emoji from a string, get emoji description (#5) 2021-12-29 19:53:44 +03:00
go.sum Fix an issue when digits were considered as emojis. Add new emojis. Add new functions: remove all emoji from a string, get emoji description (#5) 2021-12-29 19:53:44 +03:00
gomoji.go Fix an issue when digits were considered as emojis. Add new emojis. Add new functions: remove all emoji from a string, get emoji description (#5) 2021-12-29 19:53:44 +03:00
gomoji_test.go add support of skin tone emojis (#7) 2022-01-13 12:28:14 +03:00

README.md

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)
}

Result:

[]gomoji.Emoji{
    {
        Slug:        "person-in-steamy-room",
        Character:   "🧖",
        UnicodeName: "E5.0 person in steamy room",
        CodePoint:   "1F9D6",
        Group:       "People & Body",
        SubGroup:    "person-activity",
    },
    {
        Slug:        "butterfly",
        Character:   "🦋",
        UnicodeName: "E3.0 butterfly",
        CodePoint:   "1F98B",
        Group:       "Animals & Nature",
        SubGroup:    "animal-bug",
    },
}

Get all

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

package main

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

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

Remove all emojis

The function removes all emojis from given string:

res := gomoji.RemoveEmojis("🧖 hello 🦋world")
println(res) // "hello world"

Get emoji info

The function returns info about provided emoji:

info, err := gomoji.GetInfo("1") // error: the string is not emoji
info, err := gomoji.GetInfo("1⃣")
println(info)

Result:

gomoji.Entity{
    Slug:        "keycap-1",
    Character:   "1⃣",
    UnicodeName: "E0.6 keycap: 1",
    CodePoint:   "0031 FE0F 20E3",
    Group:       "Symbols",
    SubGroup:    "keycap",
}

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:        "butterfly",
        Character:   "🦋",
        UnicodeName: "E3.0 butterfly",
        CodePoint:   "1F98B",
        Group:       "Animals & Nature",
        SubGroup:    "animal-bug",
    },
    {
        Slug:        "roll-of-paper",
        Character:   "🧻",
        UnicodeName: "E11.0 roll of paper",
        CodePoint:   "1F9FB",
        Group:       "Objects",
        SubGroup:    "household",
    },
}

Performance

GoMoji Benchmarks

goos: darwin
goarch: amd64
pkg: github.com/forPelevin/gomoji
cpu: Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
BenchmarkContainsEmojiParallel
BenchmarkContainsEmojiParallel-8   	 7439398	       159.2 ns/op	     144 B/op	       3 allocs/op
BenchmarkContainsEmoji
BenchmarkContainsEmoji-8           	 2457042	       482.2 ns/op	     144 B/op	       3 allocs/op
BenchmarkRemoveEmojisParallel
BenchmarkRemoveEmojisParallel-8    	 4589841	       265.8 ns/op	     236 B/op	       5 allocs/op
BenchmarkRemoveEmojis
BenchmarkRemoveEmojis-8            	 1456464	       831.9 ns/op	     236 B/op	       5 allocs/op
BenchmarkGetInfoParallel
BenchmarkGetInfoParallel-8         	272416886	         4.433 ns/op	       0 B/op	       0 allocs/op
BenchmarkGetInfo
BenchmarkGetInfo-8                 	64521932	        19.86 ns/op	       0 B/op	       0 allocs/op
BenchmarkFindAllParallel
BenchmarkFindAllParallel-8         	 3989124	       295.9 ns/op	     456 B/op	       5 allocs/op
BenchmarkFindAll
BenchmarkFindAll-8                 	 1304463	       913.7 ns/op	     456 B/op	       5 allocs/op

Contact

Vlad Gukasov @vgukasov

License

GoMoji source code is available under the MIT License.