emoji

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 4 Imported by: 0

README

emoji-go

🔍 Go library to search for Unicode emoji information.

goreport GoDoc MIT License

Provides go structures to list or search the latest emoji symbols.

Library Usage

Exposes a constant array of all emoji symbols and an interface for performing a fuzzy search on the dataset.

See the godoc for more information.

CLI Usage

Install the CLI with go get outside a go module.

go get github.com/mrosales/emoji-go/cmd/emoji

You can look up an emoji symbol directly

emoji --limit 1 rocket
🚀

Or view all the emoji information

emoji -f json rocket
[
    {
        "name": "rocket",
        "category": "Travel \u0026 Places",
        "alternate_names": [
            "rocket"
        ],
        "unified": "1f680",
        "character": "🚀",
        "sheet_x": 33,
        "sheet_y": 50,
        "added_in": "0.6",
        "platform_support": {
            "Apple": true,
            "Facebook": true,
            "Google": true,
            "Twitter": true
        }
    }
]

# skin tones are also supported
emoji --skin medium_dark wave
👋🏾

Maintenance

Updating the dataset

The dataset generation script populates data.go in the repo root and can be run by executing go generate in the repo root.

The tag revision in cmd/emojigen/internal/importer/cdn.go must be updated to support new emoji versions.

Documentation

Overview

Package emoji provides a convenient interface for working with emojis in go.

Index

Constants

This section is empty.

Variables

View Source
var All = []Info{}/* 1903 elements not displayed */

Functions

This section is empty.

Types

type ImageData

type ImageData struct {
	// A hyphen separated sequence of hex-encoded codepoints.
	// Includes zero-width-joiner character for multi code sequences.
	Unified string `json:"unified"`
	// Character is the actual emoji character consisting of one or more codepoints.
	Character string `json:"character"`
	// SheetX is the X index of the image in the sprite sheet.
	SheetX int `json:"sheet_x"`
	// SheetY is the Y index of the image in the sprite sheet.
	SheetY int `json:"sheet_y"`
	// AddedIn is the unicode revision that the emoji was added in
	AddedIn string `json:"added_in,omitempty"`
	// PlatformSupport defines the supported platforms.
	PlatformSupport map[Platform]bool `json:"platform_support,omitempty"`
	// Obsoletes is set if the emoji replaces another emoji from an older Unicode revision.
	Obsoletes string `json:"obsoletes,omitempty"`
	// ObsoletedBy is set if the emoji is replaced by another emoji from a newer Unicode revision.
	ObsoletedBy string `json:"obsoleted_by,omitempty"`
}

ImageData contains the details pertinent to displaying an emoji.

type Info

type Info struct {
	// Name is the canonical short name.
	Name string `json:"name"`
	// Category is the category of emoji.
	Category string `json:"category"`
	// PlainText is defined if the character has a canonical plaintext representation.
	PlainText string `json:"plain_text,omitempty"`
	// AlternateNames is a list of alternative string names or keywords
	AlternateNames []string `json:"alternate_names,omitempty"`
	// ImageData is an embedded struct with details about the actual image.
	ImageData
	// SkinVariations is the map of alternative emojis for different skin tones.
	SkinVariations map[Modifier]ImageData `json:"skin_variations,omitempty"`
}

Info contains metadata about an emoji.

func (Info) ImageForModifier

func (i Info) ImageForModifier(mod Modifier) ImageData

ImageForModifier returns the ImageData for the given emoji modifier sequence. Currently only skin tone modifications are supported.

func (Info) String

func (i Info) String() string

String representation of the modifier sequence. Implements the fmt.Stringer interface.

type Modifier

type Modifier int

Modifier is a string representation of an emoji modifier sequence.

const (
	// SkinToneNone means no modifier was set.
	SkinToneNone Modifier = iota
	// SkinToneLight represents a light skin tone 👋🏻.
	SkinToneLight
	// SkinToneMediumLight represents a medium light skin tone 👋🏼.
	SkinToneMediumLight
	// SkinToneMedium represents a medium skin tone 👋🏽.
	SkinToneMedium
	// SkinToneMediumDark represents a medium dark skin tone 👋🏾.
	SkinToneMediumDark
	// SkinToneDark represents a dark skin tone 👋🏿.
	SkinToneDark
)

func NewModifier

func NewModifier(text string) (Modifier, error)

NewModifier creates a modifier from a string. An empty string is interpreted as `SkinToneNone`.

func (Modifier) MarshalText

func (m Modifier) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface. This function also determines how a modifier is marshaled to JSON.

func (Modifier) String

func (m Modifier) String() string

String implements fmt.Stringer and returns a string representation of the modifier.

func (Modifier) Unicode

func (m Modifier) Unicode() []rune

Unicode returns the sequence of unicode runes that represent the modifier.

func (*Modifier) UnmarshalText

func (m *Modifier) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface. This function also determines how a modifier is unmarshaled from JSON.

type Platform

type Platform int

Platform defines constants that represent different emoji platforms.

const (
	// PlatformNone represents no specific platform.
	PlatformNone Platform = iota
	// PlatformApple is the Apple Platform.
	PlatformApple
	// PlatformGoogle is the Google and Android platform.
	PlatformGoogle
	// PlatformTwitter is the Twitter platform.
	PlatformTwitter
	// PlatformFacebook is the Facebook platform.
	PlatformFacebook
)

func (Platform) MarshalText

func (p Platform) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface. This function also determines how a modifier is marshaled to JSON.

func (Platform) String

func (p Platform) String() string

String implements fmt.Stringer and returns a string representation of the platform.

func (*Platform) UnmarshalText

func (p *Platform) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface. This function also determines how a modifier is unmarshaled from JSON.

type SearchIndex

type SearchIndex struct {
	// contains filtered or unexported fields
}

SearchIndex is allows a keyword-based search of the emoji dataset.

func NewSearchIndex

func NewSearchIndex(opts ...SearchOption) *SearchIndex

NewSearchIndex creates a keyword fuzzy search index.

func (*SearchIndex) Search

func (si *SearchIndex) Search(query string, opts ...SearchOption) []Info

Search performs a fuzzy search on the emoji keywords to find a matching symbol. The response array will contain up to the configured limit number of terms that are less than the maximum distance from the search term.

Options provided directly to the search term override the defaults passed to NewSearchIndex.

type SearchOption

type SearchOption func(option *searchOptionSet)

SearchOption represents an option that is used to search the dataset.

func WithLimit

func WithLimit(limit int) SearchOption

WithLimit sets the maximum number of results that will be returned. A 0 value means no limit.

func WithMaxDistance

func WithMaxDistance(maxDistance int) SearchOption

WithMaxDistance configures the maximum Levenshtein distance for keyword matches. A 0 value means no maximum distance and the result will always contain the maximum limit of results.

Directories

Path Synopsis
cmd
emojigen
Package main implements a CLI that downloads emoji data and images.
Package main implements a CLI that downloads emoji data and images.

Jump to

Keyboard shortcuts

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