Helpful functions to work with emoji in Golang
Go to file
Vlad Gukasov 5fcf0e4051 fix the generator success message 2021-07-18 19:00:15 +03:00
cmd/openemojigen fix the generator success message 2021-07-18 19:00:15 +03:00
examples/openemoji README fix 2021-01-02 18:52: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 Implemented core functions (#1) 2021-01-02 18:50:08 +03:00
README.md README fix 2021-01-02 18:52:14 +03:00
data.go add a CLI tool to generate emoji data (data.go) automatically 2021-07-18 18:58:44 +03:00
go.mod add a CLI tool to generate emoji data (data.go) automatically 2021-07-18 18:58:44 +03:00
go.sum add a CLI tool to generate emoji data (data.go) automatically 2021-07-18 18:58:44 +03:00
gomoji.go Implemented core functions (#1) 2021-01-02 18:50:08 +03:00
gomoji_test.go Implemented core functions (#1) 2021-01-02 18:50:08 +03:00
openemoji.go Implemented core functions (#1) 2021-01-02 18:50:08 +03:00
service.go Implemented core functions (#1) 2021-01-02 18:50:08 +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)
}

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.