JavaScript SDK
Every export of the emojisense package: engine, loader, sessions, providers and fusion.
On this page
The emojisense package is the engine every integration is built on. It has no dependencies and runs in browsers, Node, Deno, Bun, Workers and extensions. Everything below is exported from the package root.
npm install emojisensepnpm add emojisenseyarn add emojisensebun add emojisenseEngine
createEngine
Builds the in-memory dictionary index from one or more packs: several languages, core and extension parts. Searching is synchronous.
function createEngine(
input: Pack | Pack[],
options?: { minCoverage?: number; culture?: Culture },
): AliasEngine;
interface AliasEngine {
search(query: string, options?: AliasSearchOptions): AliasSearchOutput;
// culture: false gives the canonical ranking, typed as alias results only
search(query: string, options: AliasSearchOptions & { culture: false }): CanonicalSearchOutput;
get(id: string): EmojiEntry | undefined;
withCulture(culture: Culture | undefined): AliasEngine; // shares the index
readonly culture: Culture | undefined;
readonly entries: readonly EmojiEntry[];
readonly locales: readonly string[];
readonly packVersion: string;
}
interface AliasSearchOptions {
limit?: number; // default 24
locale?: string; // preferred language: ranking, labels
locales?: readonly string[]; // the user's languages: only their phrases match; default every loaded pack
prefix?: boolean; // default true
culture?: boolean; // false = canonical ranking only
region?: string; // default: the device's region; "" = none; or ISO 3166-1 alpha-2, "JP"
now?: Date | number; // the day culture windows are checked against; default: the device's local day
day?: string; // "YYYY-MM-DD", wins over now
}const packs = await loadPacks({ baseUrl: "https://api.emojisense.com/v1/pack/0.1.0" });
const engine = createEngine(packs);
engine.search("greatest of all time").results;
// [{ emoji: "🐐", id: "1F410", score: 0.88, source: "alias" }, …]limitdefaults to 24.prefix(defaulttrue) treats the last word as a prefix while someone types. Passfalsefor complete queries.localeprefers phrases from that language’s pack when ranking.localesare the user’s languages: only phrases of those loaded packs match. English (it carries the shortcodes),localeand custom packs always count. Without it, every loaded pack matches, so a page that loads Portuguese for a demo would give a visitor of English and Turkish a Portuguese alias’s match.minCoverage(default 0.34) is the share of a multi-word query a phrase must cover.culture,region,nowanddaycontrol the culture layer. Without a culture file they change nothing.
Result types
type ResultSource = "alias" | "semantic" | "custom" | "culture";
interface SearchResult {
emoji: string; // "🦖", or ":shortcode:" for a custom emoji
id: string; // Emojibase hexcode of the base emoji, "1F996"; "C-<id>" for a custom emoji
score: number; // 0–1, comparable within one source only
source: ResultSource;
imageUrl?: string; // custom emoji: the image to draw
shortcode?: string; // custom emoji: the shortcode without colons
}
interface AliasResult extends SearchResult {
source: "alias" | "custom";
label: string; // the emoji's name
match: string; // the phrase that matched best
field: "name" | "shortcode" | "keyword" | "alias" | "typo" | "low";
}
interface CultureResult extends SearchResult {
source: "culture";
context: string; // why the emoji fits, in the culture file's language
cultureId: string; // e.g. "goat-football"
match: string; // the trigger that matched
field: "culture";
}
interface AliasSearchOutput {
query: string; // normalized
tokens: string[];
results: (AliasResult | CultureResult)[]; // culture results only with a culture file
confidence: number; // score of the best canonical result, 0 when nothing matched
}
interface CanonicalSearchOutput extends AliasSearchOutput {
results: AliasResult[];
}
interface EmojiEntry {
emoji: string;
id: string;
group: string;
version: number;
hasSkinTones: boolean;
labels: Record<string, string>; // per loaded locale
imageUrl?: string; // custom emoji only
shortcode?: string; // custom emoji only
}Loading packs
loadPacks
Fetches and validates the packs of one pack version. The files are immutable, so the browser’s HTTP cache does the rest. Load only the user’s languages: loadPacks({ baseUrl, locales: userLocales() }). It keeps the download small and the matches in languages the user reads.
function loadPacks(options: {
baseUrl: string; // "https://api.emojisense.com/v1/pack/0.1.0"
locales?: readonly string[]; // default ["en"]; English always loads first
part?: "core" | "ext"; // default "core"
fetch?: typeof fetch;
signal?: AbortSignal;
}): Promise<Pack[]>;
// Your app's custom emoji as a pack, searched on the device next to the standard set.
function loadCustomPack(options: {
endpoint: string; // the API base URL
key: string; // publishable key
tenant?: string; // your customer's external id (tenants, coming soon)
fetch?: typeof fetch;
signal?: AbortSignal;
}): Promise<Pack>;
// The user's languages that have a pack, most preferred first, always with English.
userLocales(); // navigator.languages ["tr-TR", "en-US", "de"] → ["tr", "en"]
userLocales({ languages: ["pt-BR"] }); // ["pt", "en"]
packLocaleOf("zh-Hans"); // "zh"; undefined for a language without a pack
PACK_LOCALES; // ["en", "zh", "hi", "es", "ar", "fr", "bn", "pt", "ru", "id", "tr"]loadCustomPack fetches your custom emoji as a pack (part: "custom", checked with isCustomPack); pass it to createEngine with the other packs. Custom rows use ids that start with CUSTOM_ID_PREFIX, and their results carry imageUrl and shortcode.
assertPack(value) validates a pack you load yourself, for example from your app bundle. PACK_FORMAT, PACK_FORMAT_VERSION, FIELDS, DEFAULT_WEIGHTS and ROW_INDEX describe the format. See Pack format.
Search sessions
createSearchSession
The controller behind every picker: dictionary results on every keystroke, then debounced, cancellable meaning results fused in. Stale answers are dropped.
function createSearchSession(options: {
engine: AliasEngine;
semantic?: SemanticProvider; // omit for fully offline search
locale?: string;
locales?: readonly string[]; // the user's languages, as in engine.search
limit?: number; // default 24
debounceMs?: number; // default 200
shouldUseSemantic?: (alias: AliasSearchOutput) => boolean;
culture?: Culture | false; // default: the engine's; false = canonical ranking only
region?: string; // default: the device's region; "" = none; "BR"; "auto" = the API's view
now?: () => Date | number; // the clock for culture windows; default Date.now
onChange: (state: SessionState) => void;
}): { update(query: string): void; dispose(): void };
interface SessionState {
query: string;
results: SearchResult[]; // with culture results after the top result
alias: CanonicalSearchOutput; // the dictionary answer, no culture
status: "idle" | "alias" | "loading" | "fused" | "error";
aliasMs: number;
semanticMs?: number;
semanticCached?: boolean;
layer?: "device" | "shard" | "api";
error?: unknown;
unsure: boolean; // no tier understood the query: show the results as guesses
confidence: number; // 0–1
}Semantic providers
A provider answers a query or returns undefined, so the next provider gets it. With no provider left, the session keeps the dictionary results.
interface SemanticProvider {
// undefined means "no answer here": the next provider gets the query.
search(
query: string,
options?: { locale?: string; limit?: number; signal?: AbortSignal },
): Promise<SemanticResponse | undefined>;
// An answer already in memory (a loaded shard, an answer seen before), with no I/O.
// A session shows it at once, with no debounce.
peek?(query: string, options?: { locale?: string; limit?: number }): SemanticResponse | undefined;
// Load what peek needs for this query; "" loads the shard indexes only.
prefetch?(query: string, options?: { locale?: string }): void;
}
// Layer 3, the API (GET /v1/search?mode=semantic)
createSemanticClient({ endpoint: "https://api.emojisense.com", key: "pk_live_…" });
// Layer 2, precomputed results as static files
createShardProvider({ baseUrl: "https://cdn.emojisense.com/p/0.1.0" });
// Both, cheapest first. Returns undefined when neither is configured.
createLayeredSemantic({ shardsUrl, endpoint, key, packVersion });
// Any providers, in order: the first answer wins.
chainProviders(shards, api);
// Search reports (emojisense/stats): how searches end and which results are picked,
// one report per page view from 1 in 10 sessions. Off unless you create it.
const stats = createStatsReporter({ endpoint: "https://stats.emojisense.com", key: "pk_live_…" });
createSearchSession({ engine, semantic, onChange: (state) => stats.observe(state) });
stats.pick(query, "1F382");| createSemanticClient option | Notes |
|---|---|
endpoint | Required. The API base URL. |
key | Publishable key, sent as ?key= so there is no CORS preflight |
packVersion | Pins the data so API results match your packs |
cacheSize | In-memory cache of recent answers. Default 200. |
overLimitCooldownMs | Skip the API for this long after an over-limit answer. Default 0: keep asking, because the edge cache may still know the next query. |
fetch | Your own fetch, for tests or proxies |
shardKeyFor(keys, query) picks the shard file for a query, for custom shard hosting. Shards are per locale: a search with locale: "tr" reads shardBaseFor(baseUrl, "tr"), which is <baseUrl>/tr; English stays at baseUrl.
Fusion
shouldUseSemantic(alias):truewhen the confidence is under 0.6, or for a phrase of two or more words under 0.9.fuse(alias, semantic, limit, calibration, ranking): dictionary results with a score of 0.9 or more stay pinned on top, in their order. Every other result of both lists is then ordered by the learned reranker, a linear score over the dictionary score, rank and confidence, the semantic score and its gap to the best one, the semantic confidence and the emoji’s popularity (Pack format §10). Pass{ popularity: engine.popularity }asranking; a search session does.rerank(input, limit, weights),rerankFeatures(input, id)andRERANK_WEIGHTSare the reranker itself. Both tiers bringRANK_DEPTH(24) candidates whatever the limit, so a short list is the top of the same ranking.- With
{ rerank: false }asranking,fusemerges with weights from the confidence of each tier instead. The dictionary weight is 0.4 + its confidence. The semantic weight goes from 0.4 to 1 as its best cosine goes fromcalibration.floortocalibration.ceiling(defaultDEFAULT_SEMANTIC_CALIBRATION, 0.35–0.53, for EmbeddingGemma at 768 dimensions). Results with a score of 0.9 or more stay pinned on top. When the dictionary is sure (confidence 0.6 or more), its results within 0.1 of its top score come next, in fused order. Semantic country flags that the dictionary results do not hold go last, unless their cosine reaches the calibration ceiling. semanticConfidence(semantic, calibration): that 0–1 value. Use your own calibration if you embed with another model.fuseResults(alias, semantic, options): the same, with your ownk(60),pinScore(0.9),aliasFloor(off),aliasWeightandsemanticWeight.assessConfidence(alias, semantic):{ confidence, unsure }. A query is unsure when the dictionary does not cover it with confidence (one phrase matches all its words,alias.coverage0.85 or more, and the top score is 0.6 or more) and the semantic list is flat or low. The session setsstate.unsurewith it; show the results as guesses then.semanticStrength(semantic, calibration): how strong a semantic list is, 0–1: the best cosine on the calibration scale, halved when it does not stand out from results 2–5. BelowSEMANTIC_SURE(0.5) the list is flat or low.
Helpers
normalize("¡Feliz cumpleaños!"); // "feliz cumpleanos"
tokenize(normalize("Ship it!")); // ["ship","it"]
applySkinTone("👍", "medium-dark"); // "👍🏾"
baseId("1F44D-1F3FD"); // "1F44D"
groupLabel("food-drink", "tr"); // "Yiyecek ve içecek"
hexcodeOf("❤️🔥"); // "2764-FE0F-200D-1F525"normalize(input, maxLength)andtokenize(normalized)follow the pack format’s normalization.MAX_QUERY_LENGTHis 64.embeddingText(input)is the lighter form the semantic tier embeds: accents, punctuation and emoji stay.applySkinTone(emoji, tone)with a tone fromSKIN_TONES.baseId(hexcode)maps a skin-tone variant to its base emoji.groupLabel(group, locale)names a pack group for the UI.hexcodeOf(emoji)gives the Emojibase hexcode of an emoji, skin tone included.boundedEditDistance(a, b, max)is the typo distance the engine uses.COMMON_REACTIONSlists the emoji people react with most (the defaults of Slack, GitHub and Discord), for a reaction bar.
Culture layer
Editorial emoji for a culture, a region and a moment (football’s greatest-of-all-time debate, Día de Muertos, Diwali), from one small file per locale at /v1/culture/<packVersion>/culture.<locale>.json. Editors, helped by AI, write and approve them. They join the results right after the top answer and never replace it.
The layer is on by default. createEngineLoader, useEmojisense, <emojisense-picker> and the CKEditor 5 and TinyMCE plugins load /v1/culture/<packVersion> next to /v1/pack/<packVersion>. cultureUrl: false turns it off (culture-url="off" on the web component, emojisense_culture_url: "off" in TinyMCE). A missing file changes nothing. A locale whose packs fall back to English uses the English culture file.
// createEngineLoader (emojisense/autocomplete) loads the culture file next to the packs.
createEngineLoader({ packUrl: "https://api.emojisense.com/v1/pack/0.1.0", locale: "es" });
createEngineLoader({ packUrl: "https://api.emojisense.com/v1/pack/0.1.0", cultureUrl: false }); // no culture layer
// Without the loader, load the file yourself.
const culture = await loadCulture({ baseUrl: "https://api.emojisense.com/v1/culture/0.1.0", locale: "es" });
const cultured = engine.withCulture(culture); // shares the index
cultured.search("goat", { locale: "es" }).results;
// [🐐 (alias), ⚽ 🇦🇷 🇵🇹 (source "culture", context, cultureId), …]
cultured.search("goat", { culture: false }); // the canonical ranking only
cultured.search("goat", { locale: "es", region: "", day: "2026-10-25" }); // no region, a fixed day
relevantNow(culture, { region: "MX", limit: 8 });
// [{ emoji: "💀", hexcode: "1F480", context: "Día de Muertos, 1 y 2 de noviembre", cultureId: "dia-de-muertos" }, …]loadCulture({ baseUrl, locale })fetches and checks a culture file (assertCulture,CULTURE_FORMAT,CULTURE_FORMAT_VERSION). Pass it tocreateEngine(packs, { culture })orengine.withCulture(culture); a search session applies it after fusion.cultureUrlFor(packUrl)gives the culture directory next to a pack version (…/v1/pack/0.1.0→…/v1/culture/0.1.0).- Culture results have
source: "culture",context(the reason, in the file’s language) andcultureId. Search optionculture: falsekeeps the canonical ranking;region(for example"BR") selects the regional entries. - A regional sense (
kind: "regional") is the one entry that can go first: only with aregionin its scope, for a query equal to its trigger, and over a canonical answer it names. “football” withregion: "GB"gives ⚽ then 🏈; without a region 🏈 stays first.matchRegionalLead(culture, query, topId, { region })applies that rule to your own list. - By default the region is the device’s region: in
engine.search, sessions, the React hooks, the web component and the editor plugins.resolveRegion(region, culture)applies the rule:undefinedor"device"(DEVICE_REGION) gives the device’s region,""gives none, and any other value stays as given.deviceRegion(zones)returns the region of the browser’s language (navigator.language"pt-BR"→"BR"), else the region of its time zone from the culture file’szones("ja"inAsia/Tokyo→"JP").regionOf(locale)reads the region of any locale tag. The region stays on the device: it only selects regional entries and is never sent. region: "auto"(AUTO_REGION;isAutoRegion(value)tests for it) is opt-in. It asks the API for the region of the request’s country: the session sendsregion=autowith its semantic requests and applies regional entries after the first API answer that reports a region.- Windows are checked against the device’s local day.
nowsets another clock (createSearchSession, andcreateSuggestionSourcefromemojisense/autocomplete).day: "YYYY-MM-DD"fixes the day of oneengine.search. - The semantic client sends
culture=0, because the session applies culture on the device, after fusion. Cached answers (shards, the API’s edge cache) hold no culture, so one cached answer serves every region and day. relevantNow(culture, options)lists featured seasonal and event emoji active today, for an optional shelf.matchCulture,insertCultureandapplyCultureapply a culture file to your own result list;isActiveOn(when, day)andlocalDay(now)evaluate windows. For a message, such as reaction suggestions,matchCultureInText(culture, text)finds triggers as whole words anywhere in the text, andapplyCulture(results, culture, text, { text: true })applies them. See Pack format §9.
Emoji sets
For hosted emoji sets: EMOJI_SETS, isEmojiSet(value) and emojiImageUrl(emoji, { endpoint, emojiSet, key }), which returns undefined for native or without an endpoint. Hosted sets need a key on a plan with sets; set EMOJI_IMAGE_REFERRER_POLICY as the referrerpolicy of set images so a publishable key can be checked against your page's origin.
EMOJI_SETS; // ["native", "twemoji", "noto", "fluent"]
isEmojiSet("noto"); // true
emojiImageUrl("🦖", { endpoint: "https://api.emojisense.com", emojiSet: "noto" });
// "https://api.emojisense.com/v1/sets/noto/1F996.svg"Vectors
For on-device meaning search experiments and for building vector files, import from emojisense/vectors (a separate entry, so pickers do not ship it): decodeVectors(buffer), encodeVectors(model, ids, rows), l2normalize(vector) and searchVectors(index, query, k). searchVectorSets(indexes, query, k, { bonus }) searches several vector files at once (for example the shared English file and one locale file), keeps each emoji's best row and adds an optional per-emoji bonus. semanticRows(indexes, query, { glyph, emojiOf }) returns the model output that shards store; scoreSemanticRows(rows, limit) from the main entry ranks it by semanticScore(row): text cosine plus GLYPH_WEIGHT × glyph cosine. The file format is in Pack format §5.