emojitoolkit

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

README

Emoji toolkit

Go Reference

A package to check if runes are Emojis or strings contain Emojis and flags.

The standard Unicode package does not provide any functionality to work with Emojis as of go 1.25.

How Emojis work

Emojis are a complicated feature of the Unicode Standard. A simple Emoji like ✨ (U+2728 SPARKLES) is repressented as a single codepoint or rune in go. This character has the properties Emoji=Yes and Emoji_Presentation=Yes according to the Unicode Character Database (UCD). Emoji_Presentation=Yes means that this character will appear as a Emoji by default. See section Emoji Character Properties of UTS #51 for further information.

Some characters can appear as Emoji but appear as text by default. A example of such a character is ⛓ (U+26D3 CHAINS) because it has the properties Emoji=Yes and Emoji_Presentation=No. Putting U+FE0F VARIATION SELECTOR-16 after the character forces it to appear as an Emoji which looks like this: ⛓️ (U+26D3 CHAINS U+FE0F VARIATION SELECTOR-16). Note: This requires two codepoints or runes to store the Emoji.

Emoji Keycap Sequences like #️⃣*️⃣0️⃣1️⃣2️⃣3️⃣ are not seperate characters. They are made using the ASCII # (U+0023), * (U+002A) and digits (U+0030 .. U+0039) followed by U+FE0F VARIATION SELECTOR-16 and U+20E3 COMBINING ENCLOSING KEYCAP. A spacial case is 🔟 (U+1F51F KEYCAP TEN) which is a independent character with the properties Emoji=Yes and Emoji_Presentation=Yes making it appear as an Emoji by default.

Flags 🇺🇳 🇪🇺 🇩🇪 also require two codepoints. This is because they are repressented by a second alphabet, the regional indicator symbols, that is used to write a two letter country code. Example: 🇩🇪 (U+1F1E9 REGIONAL INDICATOR SYMBOL LETTER A U+1F1EA REGIONAL INDICATOR SYMBOL LETTER E).

Features

  • Detects all Emojis listed in emoji-sequences.txt.
  • Detect Emojis in a single rune (only default emoji presentation character)
  • Unicode Standard 17.0.0
  • Unit tests and fuzzing
    • ContainsEmoji() was fuzzed with 107745299 input strings

Development

Download ucd.nounihan.flat.zip and place ucd.nounihan.flat.xml in the repository root.

References

License

Copyright 2025 Daniel Gekeler

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

View Source
const Version = "17.0.0"

Supported Unicode version

Variables

This section is empty.

Functions

func ContainsEmoji

func ContainsEmoji(s string) bool

Matches all* emojis

  • default emoji presentation character (ED-6)
  • emoji presentation sequence (ED-9a)
  • emoji keycap sequence (ED-14c)
  • emoji flag sequence (ED-14)

This should include all basic emoji defined by ED-20.

See emoji-sequences.txt for a list of matching emojis.

Examples:

"A" -> false // U+0041
"⏳" -> true // U+231B
"🌍" -> true // U+1F30D
"☀" -> false // U+2600
"♻" -> false // U+267B
"☀️":  true // U+2600 U+FE0F
"♻️":  true // U+267B U+FE0F

func ContainsFlag

func ContainsFlag(s string) bool

Matches a string that contains atleast one flag emoji officially known as emoji flag sequence (ED-14). Does not check if the flag is valid.

func IsFlagSequence

func IsFlagSequence(runes []rune) bool

Matches flag emojis officially known as emoji flag sequence (ED-14). Does not check if the flag is valid.

func IsSingleCharacterEmoji

func IsSingleCharacterEmoji(r rune) bool

Matches codepoints that are default emoji presentation character (ED-6) that can be repressented as a single rune / codepoint.

Codepoints that appear as text by default (ED-7) but can appear as emoji using emoji presentation sequence (ED-9a) are not matched because the pressence of U+FE0F VARIATION SELECTOR-16 (VS16) can not be verified from a single rune.

See section Basic_Emoji of emoji-sequences.txt for a list of matching emojis.

Examples:

'A' -> false // U+0041
'⏳' -> true // U+231B
'🌍' -> true // U+1F30D
'☀' -> false // U+2600
'♻' -> false // U+267B

This function can also be defined as Emoji_Presentation=Yes and Emoji_Component=No

func ToEmojiPresentation added in v1.1.0

func ToEmojiPresentation(s string) string

Make all emojis in a given string appear in their emoji variants. Numbers remain unchanged.

This is done using the U+FE0F VARIATION SELECTOR-16 (VS16) to form a ED-9a text presentation sequence. This can only be done to characters listed in emoji-variation-sequences.txt.

Examples

"1" -> "1"
"☀" -> "☀️"

func ToTextPresentation added in v1.1.0

func ToTextPresentation(s string) string

Make all emojis in a given string appear in their text variants. Numbers remain unchanged.

This is done using the U+FE0E VARIATION SELECTOR-15 (VS15) to form a ED-8a text presentation sequence. This can only be done to characters listed in emoji-variation-sequences.txt.

Examples

"1" -> "1"
"⏳" -> "⏳︎"

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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