emoji

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: MIT Imports: 5 Imported by: 2

README

About emoji

emoji provides standardized ways for translating unicode code points for Emoji to/from their emoji cheat sheet encoding, and is most useful when working with third-party APIs such as Slack, GitHub, etc.

emoji was written because other emoji packages for Go only provided cheat sheet names to unicode conversion and not the inverse. Additionally, there were no comprehensive emoticon packages available at the time.

Gemoji Data

Data for this package is generated from GitHub's gemoji project:

$ cd $GOPATH/src/github.com/kenshaw/emoji
$ go generate

Installing

Install in the usual Go fashion:

$ go get -u github.com/kenshaw/emoji

Using

emoji can be used similarly to the following:

// _example/example.go
package main

import (
	"log"

	"github.com/kenshaw/emoji"
)

func main() {
	a := emoji.FromEmoticon(":-)")
	log.Printf(":-) %+v", a)

	b := emoji.FromAlias("slightly_smiling_face")
	log.Printf(":-) %+v", b)

	s := emoji.ReplaceEmoticonsWithAliases(":-) :D >:(")
	log.Printf("s: %s", s)

	n := emoji.ReplaceEmoticonsWithCodes(":-) :D >:(")
	log.Printf("n: %s", n)
}

Please see the GoDoc listing for the complete API listing.

TODO

  • Convert UnicodeVersion and IOSVersion fields of Emoji type to something more easily comparable (ie, int)

Documentation

Overview

Package emoji provides standard tools for working with emoji unicode codes and aliases.

Example
package main

import (
	"fmt"

	"github.com/kenshaw/emoji"
)

func main() {
	e1 := emoji.FromEmoticon(":-)")
	fmt.Println(":-)", "--", e1.Emoji)

	e2 := emoji.FromAlias("slightly_smiling_face")
	fmt.Println(":-)", "--", e2.Emoji)

	s1 := emoji.ReplaceEmoticonsWithAliases(":-) :D >:(")
	fmt.Println(":-) :D >:(", "--", s1)

	s2 := emoji.ReplaceEmoticonsWithCodes(":-) :D >:(")
	fmt.Println(":-) :D >:(", "--", s2)

}
Output:

:-) -- 🙂
:-) -- 🙂
:-) :D >:( -- :slightly_smiling_face: :smile: :angry:
:-) :D >:( -- 🙂 😄 😠

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReplaceAliases

func ReplaceAliases(s string) string

ReplaceAliases replaces all aliases of the form ":alias:" with its corresponding unicode value.

func ReplaceAliasesWithEmoticons

func ReplaceAliasesWithEmoticons(s string) string

ReplaceAliasesWithEmoticons replaces all emoji aliases (in the form of :alias:) with its corresponding emoticon (ie, :D, :p, etc) (ie, the alias ":monkey_face:" will be replaced with ":o)").

func ReplaceCodes

func ReplaceCodes(s string) string

ReplaceCodes replaces all emoji codes with the first corresponding emoji alias (in the form of ":alias:") (ie, "\u2618" will be converted to ":shamrock:").

func ReplaceEmoticonsWithAliases

func ReplaceEmoticonsWithAliases(s string) string

ReplaceEmoticonsWithAliases replaces all emoticons (ie, :D, :p, etc) with the first corresponding emoji alias (in the form of :alias:) (ie, the monkey face emoticon ":o)" will be replaced with ":monkey_face:").

func ReplaceEmoticonsWithCodes

func ReplaceEmoticonsWithCodes(s string) string

ReplaceEmoticonsWithCodes replaces all emoticons (ie, :D, :p, etc) with the corresponding emoji code (ie, the monkey face emoticon ":o)" will be replaced with "\U0001f435").

Types

type Emoji

type Emoji struct {
	Emoji          string   `json:"emoji"`
	Description    string   `json:"description"`
	Category       string   `json:"category"`
	Aliases        []string `json:"aliases"`
	Tags           []string `json:"tags"`
	UnicodeVersion string   `json:"unicode_version"`
	IOSVersion     string   `json:"ios_version"`
	SkinTones      bool     `json:"skin_tones"`
}

Emoji represents a single emoji and associated data.

func FromAlias

func FromAlias(alias string) *Emoji

FromAlias retrieves the emoji data based on the provided alias in the form "alias" or ":alias:" (ie, "shamrock" or ":shamrock:" will return the Gemoji data for "shamrock").

func FromCode

func FromCode(code string) *Emoji

FromCode retrieves the emoji data based on the provided unicode code (ie, "\u2618" will return the Gemoji data for "shamrock").

func FromEmoticon

func FromEmoticon(emoticon string) *Emoji

FromEmoticon retrieves the emoji data based on the provided emoticon (ie, ":o)" will return the Gemoji data for "monkey face").

func Gemoji

func Gemoji() []Emoji

Gemoji returns the set of original Gemoji emoji data.

See: https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json

func (Emoji) Format added in v0.3.0

func (emoji Emoji) Format(f fmt.State, verb rune)

Format satisfies the fmt.Formatter interface.

func (Emoji) Tone added in v0.3.0

func (emoji Emoji) Tone(skinTone SkinTone) string

Tone applies a skin tone to the emoji, if applicable.

type SkinTone added in v0.3.0

type SkinTone rune

SkinTone is a skin tone modifier.

Example
package main

import (
	"fmt"
	"strings"

	"github.com/kenshaw/emoji"
)

func main() {
	for _, alias := range []string{"thumbsup", "man_technologist", "couplekiss_woman_woman", "female_detective"} {
		e := emoji.FromAlias(alias)
		s := []string{e.Emoji}
		for skinTone := emoji.Light; skinTone <= emoji.Dark; skinTone++ {
			s = append(s, e.Tone(skinTone))
		}
		fmt.Println(strings.Join(s, " "))
	}
}
Output:

👍 👍🏻 👍🏼 👍🏽 👍🏾 👍🏿
👨‍💻 👨🏻‍💻 👨🏼‍💻 👨🏽‍💻 👨🏾‍💻 👨🏿‍💻
👩‍❤️‍💋‍👩 👩🏻‍❤️‍💋‍👩🏻 👩🏼‍❤️‍💋‍👩🏼 👩🏽‍❤️‍💋‍👩🏽 👩🏾‍❤️‍💋‍👩🏾 👩🏿‍❤️‍💋‍👩🏿
🕵️‍♀️ 🕵🏻️‍♀️ 🕵🏼️‍♀️ 🕵🏽️‍♀️ 🕵🏾️‍♀️ 🕵🏿️‍♀️
const (
	Neutral     SkinTone = 0
	Light       SkinTone = 0x1f3fb
	MediumLight SkinTone = 0x1f3fc
	Medium      SkinTone = 0x1f3fd
	MediumDark  SkinTone = 0x1f3fe
	Dark        SkinTone = 0x1f3ff
)

Skin tone values.

func (SkinTone) String added in v0.3.1

func (s SkinTone) String() string

String satisfies the fmt.Stringer interface.

Directories

Path Synopsis
example/example.go
example/example.go

Jump to

Keyboard shortcuts

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