anyaround API reference

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). Or take the whole family at once with npm install anyfamily.

anyaround()

anyaround(code, options?) → string

Resolves a code to a ready-to-render string. In the default smartmode 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.

Migrating from 1.x

2.0 removed the separate anyaroundInfo— they are the same functions and values, reached through the one name the package exports.

- import { anyaround, anyaroundInfo } from 'anyaround'
+ import { anyaround } from 'anyaround'

- anyaroundInfo('US')
+ anyaround.info('US')

Arguments, return values and throwing behaviour are unchanged, and nothing else in the API moved. Every any* package follows this shape from 2.0 on: the bare call does the job, everything else hangs off the same name.

anyaround.info()

anyaround.info(code, options?) → { code, type, name, flag, found }

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

anyaround.info("US", { locale: "en" });
// { code: "US", type: "region", name: "United States", flag: "🇺🇸", found: true }

anyaround.info("en", { locale: "fr" });
// { code: "en", type: "language", name: "anglais", flag: "", found: true }

anyaround.info("QZ", { mode: "region" });
// { code: "QZ", type: "region", name: "QZ", flag: "🇶🇿", found: false }

flag is "" whenever the code is not a flag-bearing alpha-2 region. found is false when Intl had no name — name is then the code or "", so you can tell a hit from a miss.

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"

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.

Options

mode"smart" | "region" | "language" | "script" | "currency" | "calendar"default: "smart"

How the code is interpreted.

localestring | string[]default: runtime locale

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

style"long" | "short" | "narrow"default: "long"

Name verbosity, forwarded to Intl.DisplayNames.

display"name" | "flag" | "flag-name" | "name-flag"default: "name"

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

fallback"code" | "none"default: "code"

On a miss, name becomes the code ("code") or "" ("none"). Either way found is false.

languageDisplay"dialect" | "standard"default: "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.

What breaks without this

Every one of these is a file somebody is maintaining by hand right now.

The hardcoded country list

250 rows, in one language, that go stale: Czechia, Türkiye and Eswatini all changed name in the last few years. Your runtime already ships the current list in 200+ languages and updates it with the platform.

Showing the code because the name is missing

"DE" in a dropdown, "BRL" on an invoice. The reader gets an identifier meant for machines, because translating the name looked like more work than it is.

An emoji table for flags

A flag emoji is not a lookup — it is the two letters of the region code rewritten as Regional Indicator symbols. The table is a data file you never needed to ship.

Languages and scripts, which are worse

Country lists at least exist to copy. Localized names for languages and scripts are far harder to find as a file, and are what Intl.DisplayNames is best at.

Recipes

Copy, paste, move on.

// Country picker with flags
countries.map((cc) => {
  const { code, name, flag } = anyaround.info(cc)
  return <option key={code} value={code}>{flag} {name}</option>
})

// Language switcher, each language in its own tongue
anyaround('de', { mode: 'language', locale: 'de' })   // "Deutsch"
anyaround('ja', { mode: 'language', locale: 'ja' })   // "日本語"

// Profile location
anyaround(user.country, { display: 'flag-name', locale: 'en' })
// "🇩🇪 Germany"

// Currency label next to an amount
anyaround(order.currency, { mode: 'currency', locale: 'en' })
// "Euro"

// Flag only, for a compact table cell
anyaround(row.country, { display: 'flag' })
// "🇺🇸" 

React / Next.js

anyaround is pure and synchronous, so it works in a component as-is. Whatanyfamily-react adds is a shared locale: set it once onAnyfamilyProvider and every hook below picks it up, so you do not thread locale through every call.

import { AnyfamilyProvider, useAnyaround } from 'anyfamily-react'

function Country({ code }: { code: string }) {
  return <span>{useAnyaround(code, { display: 'flag-name' })}</span>
}

<AnyfamilyProvider locale="en">
  <Country code={user.country} />
</AnyfamilyProvider>

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.

vs the alternatives

What you would otherwise reach for, and what changes if you do.

anyaroundi18n-iso-countriesemoji-flagsworld-countries
bundled datanone (Intl)~1 file / localesmall~1MB JSON
localized names200+ localesbundled localesnono
languagesyesnonono
scriptsyesnonono
currency namesyesnonopartial
flagsyesnoyesemoji
dependencies0000

anyaround carries no country data at all — it borrows the ICU tables already in your runtime. Zero payload, with the trade that exact strings track the runtime's ICU version rather than a version you pinned.

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.