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 ¶
ReplaceAliases replaces all aliases of the form ":alias:" with its corresponding unicode value.
func ReplaceAliasesWithEmoticons ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
FromCode retrieves the emoji data based on the provided unicode code (ie, "\u2618" will return the Gemoji data for "shamrock").
func FromEmoticon ¶
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
Format satisfies the fmt.Formatter interface.
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
String satisfies the fmt.Stringer interface.