shortcode

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 3 Imported by: 0

README

go-emoji-shortcode

Go Version Go Reference CI

A small, dependency-free Go library for mapping emoji shortcodes (:smile:, :heart:, ...) to Unicode emoji characters. It is designed for text editors and TUI composers that want live shortcode preview and suggestion support.

Extracted from matcha so it can be reused by other Go projects.

Install

go get github.com/floatpane/go-emoji-shortcode

Requires Go 1.26+.

Usage

package main

import (
    "fmt"

    "github.com/floatpane/go-emoji-shortcode"
)

func main() {
    e, ok := shortcode.Lookup("smile")
    if ok {
        fmt.Println(e) // 😄
    }

    matches := shortcode.Suggest("sm")
    for _, m := range matches {
        fmt.Printf("%s -> %s\n", m.Code, m.Emoji)
    }
}

API

  • Lookup(shortcode string) (emoji string, ok bool) — exact shortcode to emoji.
  • Suggest(prefix string) []Match — fuzzy-matched suggestions for a prefix (e.g. "sm" matches :smile:, :smirk:, ...). Results are sorted by relevance.
  • All() []Match — every known shortcode/emoji pair.

Documentation

Full API reference: pkg.go.dev/github.com/floatpane/go-emoji-shortcode

Contributing

PRs welcome. See CONTRIBUTING.md.

License

MIT. See LICENSE.

Documentation

Overview

Package shortcode maps emoji shortcodes like :smile: to Unicode emoji characters and provides prefix-based suggestion lookup.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lookup

func Lookup(code string) (string, bool)

Lookup returns the exact emoji for a shortcode (without surrounding colons).

Types

type Match

type Match struct {
	Code  string // shortcode without colons, e.g. "smile"
	Emoji string // Unicode emoji, e.g. "😄"
}

Match is a shortcode lookup result.

func All

func All() []Match

All returns every shortcode/emoji pair, sorted by shortcode.

func Suggest

func Suggest(prefix string) []Match

Suggest returns fuzzy-matched shortcodes for the given prefix. The prefix is treated as the start of a shortcode, e.g. "sm" matches "smile" and "smirk". Results are sorted by exactness, then length, then alphabetically.

Jump to

Keyboard shortcuts

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