module

Emojis

Embeds ~200 commonly-used emoji as SVG assets from Twemoji (https://github.com/jdecked/twemoji), with an opt-in on-disk cache for the rest of the catalogue.

All curated SVGs are read and inlined at compile time (via the read_file macro), so consumers don't need to ship the data/ directory alongside their compiled binaries.

Lookup chain :

  1. The 208 curated emojis are baked into the binary and served from RAM.
  2. Anything else is looked up in the on-disk cache (cf. Emojis::Cache). The cache is empty by default — populate it via Emojis::Cache.pull (API) or emojis pull (CLI).
  3. If still not found, returns nil and the caller decides (typically substitutes with ? or text fallback).

Why two layers : the curated set covers the 90 % case of technical documentation (status, colours, dev tools…) at near-zero cost (~840 KB embedded). The cache covers the long tail without inflating every dependent binary by 18 MB.

Constants

EMOJIS = begin map = {} of String => String {% for line in (read_file("/tmp/tmp.JaIEEP/src/src" + "/../data/svg/MANIFEST.txt")).split("\n") %} {% key = (line.split("#")).first.strip %} {% if key.size > 0 %} map[{{ key }}] = {{ read_file((("/tmp/tmp.JaIEEP/src/src" + "/../data/svg/") + key) + ".svg") }} {% end %} {% end %} map end

Compile-time hash of codepoint_key => svg_content for the curated set. Codepoint keys are lowercase hex, multi-codepoint sequences joined with - (Twemoji file naming convention). Built from data/svg/MANIFEST.txt.

TWEMOJI_VERSION = "main"

Version of Twemoji whose curated assets are embedded.

VERSION = {{ (((read_file("/tmp/tmp.JaIEEP/src/src/../shard.yml")) .lines .find(&.starts_with?("version:")) || "version: 0.0.0") .gsub(/^version:\s*/, "")) .chomp }}

Version of this Crystal shard. Lue au compile-time depuis shard.yml via le macro read_file. Cf. note mémoire feedback_shard_version_macro.md (mémoire ALOLI).

Class methods

each

Iterates over every (key, svg) pair in the embedded curated set only — the cache is intentionally NOT walked, since it can grow to thousands of entries and most callers using each want to enumerate the small fast set, not the disk one.

Source
includes?(char : Char) : Bool

Returns true when either the curated set or the cache has an SVG for the given codepoint. Cheaper than svg(...) for the curated branch (no string copy), but the cache branch still has to stat the file.

Source
includes?(codepoint : Int32) : Bool

Returns true when either the curated set or the cache has an SVG for the given codepoint. Cheaper than svg(...) for the curated branch (no string copy), but the cache branch still has to stat the file.

Source
keys

Returns every embedded codepoint key (sorted alphabetically). Useful for --list-emojis style commands or for documentation.

Source
size

Returns the number of emojis in the embedded curated set (does NOT count cached SVGs ; see Cache.size for that).

Source
svg(char : Char) : String | Nil

Returns the raw SVG content for a single-codepoint emoji. Pass a Char (most natural) or an Int32 codepoint.

Looks up first in the embedded curated set, then in the on-disk cache. Returns nil when neither has the emoji — callers should fall back to text.

Emojis.svg('✅') # => "<svg ...>"  (curated)
Emojis.svg('🦄') # => "<svg ...>" if cache populated, else nil
Emojis.svg('é') # => nil          (not an emoji)
Source
svg(codepoint : Int32) : String | Nil

Returns the raw SVG content for a single-codepoint emoji. Pass a Char (most natural) or an Int32 codepoint.

Looks up first in the embedded curated set, then in the on-disk cache. Returns nil when neither has the emoji — callers should fall back to text.

Emojis.svg('✅') # => "<svg ...>"  (curated)
Emojis.svg('🦄') # => "<svg ...>" if cache populated, else nil
Emojis.svg('é') # => nil          (not an emoji)
Source
svg(codepoints : Array(Int32)) : String | Nil

Returns the SVG for a multi-codepoint emoji sequence (e.g. an emoji modified by a skin-tone or zero-width-joiner). Pass an array of codepoints in source order.

The curated set focuses on single-codepoint emojis ; sequences are typically only available once the cache has been populated.

# 👨‍💻 = MAN (1F468) + ZWJ (200D) + LAPTOP (1F4BB)
Emojis.svg([0x1F468, 0x200D, 0x1F4BB])
Source

Nested types