← anyaround
docs

Overview

anyaround turns a region, language, script, currency, or calendar code into its localized name — and, for countries, an emoji flag. One function over native Intl.DisplayNames, zero dependencies.

import { anyaround } from "anyaround";

anyaround("US");                        // "United States"
anyaround("US", { display: "flag-name" }); // "🇺🇸 United States"
anyaround("US", { locale: "ru" });      // "Соединенные Штаты"
anyaround("en");                        // "English"
anyaround("Cyrl");                      // "Cyrillic"
anyaround("EUR");                       // "Euro"

Install

npm install anyaround
pnpm add anyaround
yarn add anyaround

Ships ESM + CJS with type declarations. Requires a runtime with Intl.DisplayNames (Node 18+, modern browsers).

anyaround()

anyaround(code, options?) → string

Resolves a code to a ready-to-render string. In the default smart mode the kind is inferred from the code's shape.

anyaround("FR");                     // "France"
anyaround("fr");                     // "French"
anyaround("419");                    // "Latin America and the Caribbean"
anyaround("Latn");                   // "Latin"
anyaround("JPY");                    // "Japanese Yen"
anyaround("DE", { display: "flag" }); // "🇩🇪"

Throws TypeError on an empty code and RangeError on an unknown mode.

anyaroundInfo()

anyaroundInfo(code, options?) → { code, type, name, flag }

Same arguments, structured result — build your own output or drive a <select>.

anyaroundInfo("US", { locale: "en" });
// { code: "US", type: "region", name: "United States", flag: "🇺🇸" }

anyaroundInfo("en", { locale: "fr" });
// { code: "en", type: "language", name: "anglais", flag: "" }

flag is "" whenever the code is not a flag-bearing alpha-2 region.

Modes

The mode option picks how a code is read. Default is "smart".

smart — auto-detect by shape

three digits            → region    "419"
four letters            → script    "Latn"
two uppercase letters   → region    "US"
three uppercase letters → currency  "USD"
anything else           → language  "en", "zh-Hant"

Case is the tiebreaker: "IT" is a region, "it" a language. Pin ambiguous codes with mode. calendar is never auto-detected.

region / language / script / currency / calendar

anyaround("DE", { mode: "region", display: "flag-name" }); // "🇩🇪 Germany"
anyaround("en-US", { mode: "language" });                 // "American English"
anyaround("Cyrl", { mode: "script" });                    // "Cyrillic"
anyaround("EUR", { mode: "currency" });                   // "Euro"
anyaround("gregory", { mode: "calendar" });               // "Gregorian Calendar"

Options

mode"smart" | "region" | "language" | "script" | "currency" | "calendar"= "smart"

How the code is interpreted.

localestring | string[]= runtime locale

BCP 47 tag (or fallback list) for the resolved name.

style"long" | "short" | "narrow"= "long"

Name verbosity, forwarded to Intl.DisplayNames.

display"name" | "flag" | "flag-name" | "name-flag"= "name"

Output shape for flag-bearing regions. Only in smart / region mode.

fallback"code" | "none"= "code"

What to do with a code that has no known name.

languageDisplay"dialect" | "standard"= "dialect"

Dialect ("American English") vs standard ("English (United States)"). Only in language mode.

The options type is a discriminated union on mode — TypeScript only offers display in smart / region mode and languageDisplay in language mode.

Flags

Flags are derived from a two-letter region code by mapping each letter to its Unicode Regional Indicator Symbol — no image assets, no lookup table.

anyaround("US", { display: "flag" });      // "🇺🇸"
anyaround("US", { display: "flag-name" }); // "🇺🇸 United States"
anyaround("US", { display: "name-flag" }); // "United States 🇺🇸"

Numeric M49 regions ("419") and non-region kinds have no flag, so flag display values fall back to the name.

Locales

Pass any valid BCP 47 tag, including regional variants and fallback arrays.

anyaround("US", { locale: "ru" }); // "Соединенные Штаты"
anyaround("US", { locale: "de" }); // "Vereinigte Staaten"
anyaround("US", { locale: "ja" }); // "アメリカ合衆国"
anyaround("US", { locale: ["sr-Latn-RS", "en"] });

Output is pure — no Date.now(), no environment reads — so server and client render identically. SSR-safe by construction.

Compatibility

Node.js18+
Chrome81+
Firefox86+
Safari14.1+
Edge Runtime
Cloudflare Workers
Deno

Intl.DisplayNames is required (widely available since 2021). CI runs on Node 20, 22, and 24.

Limitations

No cities

Intl has no city display names. Regions and countries only.

Names track ICU

Exact strings come from the runtime's ICU version — don't snapshot across environments.

No reverse lookup

Code → name only; name → code is not provided.

Flags are alpha-2 only

Numeric regions and non-region kinds have no flag.