type Continent
type Continent = (typeof CONTINENTS)[number];
A continent's two letters: "AF", "AN", "AS", "EU", "NA", "OC" or "SA".
@johnmorrisdotca/kuni 1.3.0 · 8 entry points · 72 exports
@johnmorrisdotca/kuniContinent continentName CONTINENTS countries CountriesOptions country Country COUNTRY_CODES countryByName CountryCode countryName CountryNameOptions CountryOrder flag fold isCountryCode Language LANGUAGES Subdivision SubdivisionType subregionName VERSION
type Continent = (typeof CONTINENTS)[number];
A continent's two letters: "AF", "AN", "AS", "EU", "NA", "OC" or "SA".
continentName: (continent: Continent, language?: Language) => string | null
A continent's name, from CLDR.
continent One of the seven two-letter continents.language "en" (the default) or "ja".Returns The name; `null` for anything that is not one of the seven.
import { continentName } from "@johnmorrisdotca/kuni";
continentName("AS"); // "Asia"
continentName("AS", "ja"); // "アジア"CONTINENTS: readonly ["AF", "AN", "AS", "EU", "NA", "OC", "SA"]
The seven continents, as two letters: Africa, Antarctica, Asia, Europe, North America, Oceania, South America.
import { CONTINENTS, continentName } from "@johnmorrisdotca/kuni";
CONTINENTS.length; // 7
CONTINENTS.map((one) => continentName(one, "ja"))[0]; // "アフリカ"countries: (options?: CountriesOptions) => readonly Country[]
Every country: the 249 ISO 3166-1 codes and Kosovo (XK). order: "en" sorts by the English name folded (accents and case set aside); order: "ja" by the Japanese name in kana, its reading where it is written in kanji, in plain kana order (not a full Japanese collation).
options `order`: "code" (the default), "en" or "ja".Returns The 250 countries, the list and its objects frozen and shared.
import { countries } from "@johnmorrisdotca/kuni";
countries().length; // 250
countries({ order: "en" })[0].name.en; // "Afghanistan"
countries({ order: "ja" })[0].name.ja; // "アイスランド"interface CountriesOptions
What countries() may be asked.
order?: CountryOrder | undefinedcountry: (code: string) => Country | null
One country by its code.
code Alpha-2 ("JP", "jp"), alpha-3 ("JPN") or numeric ("392").Returns The country, frozen; `null` for anything that is not one of the 250 codes.
import { country } from "@johnmorrisdotca/kuni";
country("JP")?.name.en; // "Japan"
country("jpn")?.alpha2; // "JP"
country("392")?.name.ja; // "日本"
country("JP")?.capital; // { "en": "Tokyo", "ja": "東京" }
country("XX"); // nullinterface Country
A country, or a territory with an ISO 3166-1 code of its own, as the lookups hand it out (frozen).
alpha2: stringalpha3: stringnumeric: stringkind: "iso" | "user"name: { en: string; ja: string; local?: string; }shortName?: { en?: string; ja?: string; } | undefinedreading?: string | undefinedflag: stringcontinent: "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA"subregion?: string | undefinedcallingCode?: string | undefinedcurrency?: string[] | undefinedtld?: string | undefinedcapital?: { en: string; ja: string; } | undefinedzones?: string[] | undefinedlanguages?: string[] | undefinedsubdivisionType?: "atoll" | "autonomous-community" | "autonomous-region" | "borough" | "canton" | "capital-district" | "circuit" | "city" | "council-area" | "country" | "county" | "department" | "district" | "division" | "emirate" | "governorate" | "island" | "krai" | "metropolis" | "municipality" | "oblast" | "parish" | "prefecture" | "principal-area" | "province" | "quarter" | "region" | "republic" | "special-administrative-region" | "state" | "territory" | "unitary-authority" | "urban-prefecture" | "voivodeship" | "zone" | undefinedaliases?: string[] | undefinedioc?: string | undefinedCOUNTRY_CODES: readonly ["AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH"…
The 250 country codes: the 249 ISO 3166-1 alpha-2 codes and XK for Kosovo, in alphabetical order.
import { COUNTRY_CODES } from "@johnmorrisdotca/kuni/codes";
COUNTRY_CODES.length; // 250
COUNTRY_CODES[0]; // "AD"countryByName: (text: string) => Country | null
A country from what somebody typed: its name or short name in English or Japanese ("Germany", ドイツ, どいつ), its own name ("Deutschland"), a name it is also known by ("Holland", "UK", 米国), or a code. Case, accents, width, kana and punctuation do not matter.
text What was typed.Returns The country, frozen; `null` when nothing matches, never a near miss.
import { countryByName } from "@johnmorrisdotca/kuni";
countryByName("ドイツ")?.alpha2; // "DE"
countryByName("Holland")?.name.ja; // "オランダ"
countryByName("USA")?.alpha2; // "US"
countryByName("cote d'ivoire")?.alpha2; // "CI"
countryByName("Narnia"); // nulltype CountryCode = (typeof COUNTRY_CODES)[number];
One of the 250 country codes, as a type: "JP" | "US" | ...
countryName: (code: string, language?: Language, options?: CountryNameOptions) => string | null
A country's name in English or Japanese.
code Any code `country()` takes.language "en" (the default) or "ja".options `short: true` for the short form where CLDR has one ("UK", アメリカ).Returns The name; `null` for a code that is not a country, or a language that is not one of the two.
import { countryName } from "@johnmorrisdotca/kuni";
countryName("US"); // "United States"
countryName("US", "ja", { short: true }); // "アメリカ"
countryName("GB", "en", { short: true }); // "UK"
countryName("XX"); // nullinterface CountryNameOptions
What countryName() may be asked.
short?: boolean | undefinedtype CountryOrder = "code" | "en" | "ja";
The order countries() lists them in: "code" (alpha-2), "en" (by English name) or "ja" (by Japanese name, in kana).
flag: (code: string) => string | null
The flag of a country as an emoji: two regional-indicator letters, which most systems draw as the flag and some (Windows) as the two letters. Write the country's name beside it.
code Any code `country()` takes.Returns The emoji; `null` for a code that is not a country.
import { flag } from "@johnmorrisdotca/kuni";
flag("JP"); // "🇯🇵"
flag("XX"); // nullfold: (text: string) => string
What two ways of typing a name have in common: width (full-width letters to ASCII, half-width katakana to full), case, accents (except the two marks that make が and ぱ), katakana to hiragana, apostrophes dropped, and every other run of punctuation or space to one space. The lookups compare names folded, and so can a page.
text Any text.Returns The text folded; "" for text that is only punctuation or space.
import { fold } from "@johnmorrisdotca/kuni";
fold("Côte d'Ivoire"); // "cote divoire"
fold("USA"); // "usa"
fold("ドイツ"); // "どいつ"isCountryCode: (value: unknown) => value is CountryCode
Whether a value is one of the 250 codes exactly as ISO writes it: two capital letters ("JP", and "XK" for Kosovo). Lower case is not a code here; country() in the main entry is the forgiving one.
value Anything.Returns True for one of the 250 codes; false for anything else, a lower-case code included.
import { isCountryCode } from "@johnmorrisdotca/kuni/codes";
isCountryCode("JP"); // true
isCountryCode("jp"); // false
isCountryCode("XX"); // falsetype Language = (typeof LANGUAGES)[number];
A language every name is kept in: "en" or "ja".
LANGUAGES: readonly ["en", "ja"]
The two languages every name is kept in.
import { LANGUAGES } from "@johnmorrisdotca/kuni";
LANGUAGES; // ["en", "ja"]interface Subdivision
A subdivision of a country (a state, a province, a prefecture), with its ISO 3166-2 code, as the lookups hand it out (frozen).
code: stringcountry: stringshortCode: stringtype: "atoll" | "autonomous-community" | "autonomous-region" | "borough" | "canton" | "capital-district" | "circuit" | "city" | "council-area" | "country" | "county" | "department" | "district" | "division" | "emirate" | "governorate" | "island" | "krai" | "metropolis" | "municipality" | "oblast" | "parish" | "prefecture" | "principal-area" | "province" | "quarter" | "region" | "republic" | "special-administrative-region" | "state" | "territory" | "unitary-authority" | "urban-prefecture" | "voivodeship" | "zone" | nulllevel: 2 | 1 | 3parent?: string | undefinedname: { en: string; ja: string | null; }reading?: string | undefinedtype SubdivisionType = (typeof SUBDIVISION_TYPES)[number];
A kind of subdivision, in kebab case: "prefecture", "state", "autonomous-community".
subregionName: (subregion: string, language?: Language) => string | null
A UN M49 subregion's name, from CLDR.
subregion Three digits, as `Country.subregion` gives it: "030".language "en" (the default) or "ja".Returns The name; `null` for a code no country is in.
import { subregionName } from "@johnmorrisdotca/kuni";
subregionName("030"); // "Eastern Asia"
subregionName("030", "ja"); // "東アジア"VERSION: "1.3.0"
The package's version, the same as package.json's.
import { VERSION } from "@johnmorrisdotca/kuni";
console.log(`kuni ${VERSION}`);@johnmorrisdotca/kuni/codesCOUNTRY_CODES CountryCode isCountryCode
COUNTRY_CODES: readonly ["AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH"…
The 250 country codes: the 249 ISO 3166-1 alpha-2 codes and XK for Kosovo, in alphabetical order.
import { COUNTRY_CODES } from "@johnmorrisdotca/kuni/codes";
COUNTRY_CODES.length; // 250
COUNTRY_CODES[0]; // "AD"type CountryCode = (typeof COUNTRY_CODES)[number];
One of the 250 country codes, as a type: "JP" | "US" | ...
isCountryCode: (value: unknown) => value is CountryCode
Whether a value is one of the 250 codes exactly as ISO writes it: two capital letters ("JP", and "XK" for Kosovo). Lower case is not a code here; country() in the main entry is the forgiving one.
value Anything.Returns True for one of the 250 codes; false for anything else, a lower-case code included.
import { isCountryCode } from "@johnmorrisdotca/kuni/codes";
isCountryCode("JP"); // true
isCountryCode("jp"); // false
isCountryCode("XX"); // false@johnmorrisdotca/kuni/subdivisionsallSubdivisions Level subdivision Subdivision SUBDIVISION_TYPES subdivisionByName SubdivisionByNameOptions subdivisionByShortCode subdivisions subdivisionsByName SubdivisionsOptions SubdivisionType subdivisionTypeLabel
allSubdivisions: () => readonly Subdivision[]
Every subdivision of every country, every level, in code order.
Returns The 5,050 subdivisions, frozen and shared.
import { allSubdivisions } from "@johnmorrisdotca/kuni/subdivisions";
allSubdivisions().length; // 5050type Level = 1 | 2 | 3 | "all";
A level of subdivision: 1 for a country's first division, 2 and 3 for those inside one, or "all".
subdivision: (code: string) => Subdivision | null
One subdivision by its ISO 3166-2 code.
code The full code, either case: "JP-13", "ca-on".Returns The subdivision, frozen; `null` for anything that is not one.
import { subdivision } from "@johnmorrisdotca/kuni/subdivisions";
subdivision("JP-13")?.name.ja; // "東京都"
subdivision("ca-on")?.name.en; // "Ontario"
subdivision("FR-75C")?.parent; // "FR-IDF"
subdivision("XX-99"); // nullinterface Subdivision
A subdivision of a country (a state, a province, a prefecture), with its ISO 3166-2 code, as the lookups hand it out (frozen).
code: stringcountry: stringshortCode: stringtype: "atoll" | "autonomous-community" | "autonomous-region" | "borough" | "canton" | "capital-district" | "circuit" | "city" | "council-area" | "country" | "county" | "department" | "district" | "division" | "emirate" | "governorate" | "island" | "krai" | "metropolis" | "municipality" | "oblast" | "parish" | "prefecture" | "principal-area" | "province" | "quarter" | "region" | "republic" | "special-administrative-region" | "state" | "territory" | "unitary-authority" | "urban-prefecture" | "voivodeship" | "zone" | nulllevel: 2 | 1 | 3parent?: string | undefinedname: { en: string; ja: string | null; }reading?: string | undefinedSUBDIVISION_TYPES: readonly ["atoll", "autonomous-community", "autonomous-region", "borough", "canton", "capital-district", "circuit", "city", "council-area", "country", "county", "department", "district", "division", "emirate", "governorate", "island", "krai", "metropolis", "municipality", "oblast", "parish", "prefecture", "principal-area", "province", "quarter", "region", "republic", "special-administrative-region…
The kinds of subdivision, in kebab case. Most are read from what Wikidata says each place is an instance of; Japan's four come from the last character of the prefecture's name.
import { SUBDIVISION_TYPES } from "@johnmorrisdotca/kuni/subdivisions";
SUBDIVISION_TYPES.includes("prefecture"); // truesubdivisionByName: (text: string, options?: SubdivisionByNameOptions) => Subdivision | null
The one subdivision a typed name means. When the name is at more than one level, the highest level wins (a region over a department of the same name).
text What was typed: "Ontario", オンタリオ州, オンタリオ.options `country` and `level`, to narrow the search.Returns The subdivision, frozen; `null` when nothing matches, or when the name is still more than one place (Punjab is in India and in Pakistan): name the country.
import { subdivisionByName } from "@johnmorrisdotca/kuni/subdivisions";
subdivisionByName("オンタリオ州", { country: "CA" })?.code; // "CA-ON"
subdivisionByName("Punjab"); // null
subdivisionByName("Punjab", { country: "PK" })?.code; // "PK-PB"interface SubdivisionByNameOptions
What subdivisionByName() and subdivisionsByName() may be narrowed to.
country?: string | undefinedlevel?: Level | undefinedsubdivisionByShortCode: (countryCode: string, shortCode: string) => Subdivision | null
One subdivision by its country and the part of its code after the hyphen.
countryCode An alpha-2 code, either case.shortCode The part after the hyphen: "ON", "13".Returns The subdivision, frozen; `null` where the two make no code.
import { subdivisionByShortCode } from "@johnmorrisdotca/kuni/subdivisions";
subdivisionByShortCode("CA", "ON")?.code; // "CA-ON"
subdivisionByShortCode("JP", "99"); // nullsubdivisions: (countryCode: string, options?: SubdivisionsOptions) => readonly Subdivision[] | null
A country's subdivisions, in code order: the first level unless level asks for another or for "all".
countryCode An alpha-2 code, either case.options `level`: 1 (the default), 2, 3 or "all".Returns The list, frozen; an empty list for a country that has none (Antarctica); `null` for a code that is not a country.
import { subdivisions } from "@johnmorrisdotca/kuni/subdivisions";
subdivisions("JP")?.length; // 47
subdivisions("FR")?.length; // 26
subdivisions("FR", { level: "all" })?.length; // 124
subdivisions("XX"); // nullsubdivisionsByName: (text: string, options?: SubdivisionByNameOptions) => readonly Subdivision[]
Every subdivision a typed name could be, in code order: its English or Japanese name, its Japanese name without the word for its kind (オンタリオ, 東京), a prefecture's reading, or its full code. Folded as fold folds, so case, accents, width and kana do not matter.
text What was typed.options `country` and `level`, to narrow the search.Returns The subdivisions it could be, frozen; an empty list for none.
import { subdivisionsByName } from "@johnmorrisdotca/kuni/subdivisions";
subdivisionsByName("Punjab").map((one) => one.code); // ["IN-PB", "PK-PB"]
subdivisionsByName("とうきょうと").map((one) => one.code); // ["JP-13"]
subdivisionsByName("Narnia"); // []interface SubdivisionsOptions
What subdivisions() may be asked.
level?: Level | undefinedtype SubdivisionType = (typeof SUBDIVISION_TYPES)[number];
A kind of subdivision, in kebab case: "prefecture", "state", "autonomous-community".
subdivisionTypeLabel: (code: string, language?: Language) => string | null
The word for a kind of subdivision. Given a subdivision's code, its own kind ("JP-13" is "metropolis", 都); given a country's code, the kind most of its first-level subdivisions are ("JP" is "prefecture", 県). In English the kind's name with spaces; in Japanese the word the names of that kind in that country end in.
code A subdivision's code ("JP-13") or a country's alpha-2 code ("JP").language "en" (the default) or "ja".Returns The word; `null` where the kind is not known, or, in Japanese, where the names do not agree on one.
import { subdivisionTypeLabel } from "@johnmorrisdotca/kuni/subdivisions";
subdivisionTypeLabel("JP-13"); // "metropolis"
subdivisionTypeLabel("JP-13", "ja"); // "都"
subdivisionTypeLabel("CA", "ja"); // "州"
subdivisionTypeLabel("XX"); // null@johnmorrisdotca/kuni/loadloadSubdivisions: (countryCode: string) => Promise<readonly Subdivision[] | null>
The subdivisions of one country, every level, in code order: the same list as
countryCode An alpha-2 code, either case.Returns The list, frozen; an empty list for a country that has none (Antarctica); `null` for a code that is not a country.
import { loadSubdivisions } from "@johnmorrisdotca/kuni/load";
(await loadSubdivisions("CA"))?.length; // 13
(await loadSubdivisions("jp"))?.[12].name.ja; // "東京都"
await loadSubdivisions("AQ"); // []
await loadSubdivisions("XX"); // nullinterface Subdivision
A subdivision of a country (a state, a province, a prefecture), with its ISO 3166-2 code, as the lookups hand it out (frozen).
code: stringcountry: stringshortCode: stringtype: "atoll" | "autonomous-community" | "autonomous-region" | "borough" | "canton" | "capital-district" | "circuit" | "city" | "council-area" | "country" | "county" | "department" | "district" | "division" | "emirate" | "governorate" | "island" | "krai" | "metropolis" | "municipality" | "oblast" | "parish" | "prefecture" | "principal-area" | "province" | "quarter" | "region" | "republic" | "special-administrative-region" | "state" | "territory" | "unitary-authority" | "urban-prefecture" | "voivodeship" | "zone" | nulllevel: 2 | 1 | 3parent?: string | undefinedname: { en: string; ja: string | null; }reading?: string | undefined@johnmorrisdotca/kuni/factsallFacts CountryFacts distanceKm DrivingSide facts FACTS_READ HourCycle LatLon MeasurementSystem PaperSize WeekStart
allFacts: () => readonly CountryFacts[]
The facts about every country, in alpha-2 order: one object for each of the 250 codes, the list and its objects frozen and shared. Plain numbers and codes, so a build script can write them out as JSON as they are.
Returns Every country's facts.
import { allFacts } from "@johnmorrisdotca/kuni/facts";
const crowded = allFacts()
.filter((one) => one.population !== null && one.areaKm2 !== null)
.sort((a, b) => b.population! / b.areaKm2! - a.population! / a.areaKm2!)[0].alpha2; // "MC"interface CountryFacts
The facts about one country, from the /facts entry: plain numbers and codes, null where a source has none.
alpha2: stringpopulation: number | nullpopulationYear: number | nullareaKm2: number | nullareaYear: number | nullareaOf: "whole" | "land" | nullpoint: LatLon | nullcapitalPoint: LatLon | nullborders: readonly string[]drivingSide: DrivingSide | nullweekStart: WeekStartmeasurement: MeasurementSystempaper: PaperSizehourCycle: HourCycledistanceKm: (from: LatLon, to: LatLon) => number
The great-circle distance between two points, in kilometres, on a sphere of the earth's mean radius (6,371 km). Within about half a percent of the distance on the ground.
from A point, `{ lat, lon }` in degrees.to Another point.Returns The distance in kilometres.
import { distanceKm, facts } from "@johnmorrisdotca/kuni/facts";
Math.round(distanceKm(facts("JP")!.capitalPoint!, facts("GB")!.capitalPoint!)); // 9558type DrivingSide = "left" | "right";
The side of the road a country drives on.
facts: (code: string) => CountryFacts | null
The facts about one country, by its alpha-2 code in either case.
code An ISO 3166-1 alpha-2 code, "JP" or "jp"; for an alpha-3 or numeric code, pass `country(code)?.alpha2`.Returns The country's facts, frozen; `null` for anything that is not one of the 250 codes.
import { facts } from "@johnmorrisdotca/kuni/facts";
facts("JP")?.population; // 123802000
facts("JP")?.populationYear; // 2024
facts("FR")?.borders; // ["AD", "BE", "BR", "CH", "DE", "ES", "IT", "LU", "MC", "SR"]
facts("GB")?.drivingSide; // "left"
facts("US")?.weekStart; // "sun"
facts("XX"); // nullFACTS_READ: "2026-10-09"
The day the Wikidata snapshot was read: every figure in /facts is as Wikidata gave it on this day.
import { FACTS_READ, facts } from "@johnmorrisdotca/kuni/facts";
console.log(`${facts("JP")?.population} people in ${facts("JP")?.populationYear}, as Wikidata gave it on ${FACTS_READ}`);type HourCycle = "h12" | "h23";
The clock in everyday use, named as an hour cycle is in JavaScript: "h12" is 1 to 12 with AM and PM, "h23" is 0 to 23.
interface LatLon
A point on the earth, in degrees: north and east are positive.
lat: numberlon: numbertype MeasurementSystem = "metric" | "US" | "UK";
The system of measurement in everyday use, as CLDR writes it: the United States' and Britain's are their own.
type PaperSize = "A4" | "US-Letter";
The paper size in everyday use, as CLDR writes it.
type WeekStart = "mon" | "sun" | "sat" | "fri";
The first day of the week on a calendar there, as CLDR writes it.
@johnmorrisdotca/kuni/subdivision-factsLatLon loadSubdivisionFacts SubdivisionFacts
interface LatLon
A point on the earth, in degrees: north and east are positive.
lat: numberlon: numberloadSubdivisionFacts: (countryCode: string) => Promise<readonly SubdivisionFacts[] | null>
The facts about one country's subdivisions, every level, in code order: one object for each subdivision, with null for anything Wikidata does not give or gives two ways (docs/subdivision-facts.md counts them).
countryCode An ISO 3166-1 alpha-2 code, in either case.Returns The list, frozen; an empty list for a country with no subdivisions (Antarctica); `null` for a code that is not a country.
import { loadSubdivisionFacts } from "@johnmorrisdotca/kuni/subdivision-facts";
const prefectures = await loadSubdivisionFacts("JP");
prefectures?.[0].capital; // { en: "Sapporo", ja: "札幌市", reading: "さっぽろし" }
prefectures?.[12].population; // 14264798, for Tokyo
prefectures?.[12].populationYear; // 2022
await loadSubdivisionFacts("AQ"); // []
await loadSubdivisionFacts("XX"); // nullinterface SubdivisionFacts
The facts about one subdivision, from the /subdivision-facts entry: null where Wikidata has none, or gives two.
code: stringcapital: { en: string; ja: string | null; reading?: string; } | nullcapitalPoint: LatLon | nullpopulation: number | nullpopulationYear: number | nullareaKm2: number | nullareaYear: number | nullpoint: LatLon | null@johnmorrisdotca/kuni/groupingsgrouping Grouping GROUPING_KINDS GroupingDateOptions GroupingKind GroupingMember GroupingName GroupingOther groupings groupingsOf GroupingsOptions GroupingSource GroupingStatus membersOf
grouping: (id: string) => Grouping | null
One grouping by its id.
id The grouping's id: "eu", "nato", "m49-030", "continent-as", "middle-east", "jp-kanto".Returns The grouping, frozen; `null` for an id that is not one.
import { grouping } from "@johnmorrisdotca/kuni/groupings";
grouping("eu")?.members.length; // 27
grouping("eu")?.name.ja; // "欧州連合"
grouping("jp-kanto")?.members[5]; // "JP-13"
grouping("atlantis"); // nullinterface Grouping
A grouping of countries, or of the subdivisions inside one country.
id: stringkind: "continent" | "m49" | "membership" | "informal" | "subdivision"name: { en: string; ja: string; }shortName?: { en?: string; ja?: string; } | undefinedreading?: string | undefinedotherNames?: readonly GroupingName[] | undefinedinformal: booleancountry?: string | undefinedparent?: string | undefinedsets?: readonly string[] | undefinedmembers: readonly string[]periods?: readonly GroupingMember[] | undefinedothers?: readonly GroupingOther[] | undefineddefinition: stringnote?: string | undefinedsource: GroupingSourceasOf: stringGROUPING_KINDS: readonly ["continent", "m49", "membership", "informal", "subdivision"]
What kind of grouping it is: a continent, a UN M49 area, an international body's members, a well-known informal grouping, or a grouping of the subdivisions inside one country.
import { GROUPING_KINDS, groupings } from "@johnmorrisdotca/kuni/groupings";
GROUPING_KINDS.map((kind) => groupings({ kind }).length)[0]; // 7interface GroupingDateOptions
What groupingsOf() and membersOf() may be asked.
on?: string | undefinedkind?: "continent" | "m49" | "membership" | "informal" | "subdivision" | undefinedtype GroupingKind = (typeof GROUPING_KINDS)[number];
What kind of grouping it is: "continent", "m49", "membership", "informal" or "subdivision".
interface GroupingMember
One period of membership of a body: a member from since (or a day Wikidata does not give) until until.
code: stringsince: string | nulluntil: string | nullinterface GroupingName
Another name a grouping goes by, in English and Japanese.
en: stringja: stringreading?: string | undefinedinterface GroupingOther
A country that stands with a body without being a member: a candidate, an associate, an observer or suspended.
code: stringstatus: GroupingStatusgroupings: (options?: GroupingsOptions) => readonly Grouping[]
Every grouping, or those of one kind or inside one country, in a fixed order: continents, UN M49 areas, international bodies, informal groupings, then regions inside a country.
options `kind` to keep one kind, `country` to keep the groupings of one country's subdivisions.Returns The groupings, frozen; an empty list where none match.
import { groupings } from "@johnmorrisdotca/kuni/groupings";
groupings({ kind: "continent" }).map((one) => one.name.en); // ["Africa", "Antarctica", "Asia", "Europe", ...]
groupings({ country: "JP" }).length; // 10: the eight 地方, and the nine-region variant's twogroupingsOf: (code: string, options?: GroupingDateOptions) => readonly Grouping[]
The groupings a country, or a subdivision, is a member of: now, or on a given day.
code An alpha-2 code ("FR", either case) or an ISO 3166-2 code ("JP-13").options `on` for a day in the past, `kind` to keep one kind.Returns The groupings, frozen, in the order of `groupings()`; an empty list for a code in none, or not a code.
import { groupingsOf } from "@johnmorrisdotca/kuni/groupings";
groupingsOf("GB", { kind: "membership" }).map((one) => one.id); // ["un", "nato", "g7", ...]
groupingsOf("GB", { kind: "membership", on: "2015-01-01" }).some((one) => one.id === "eu"); // true
groupingsOf("JP-13").map((one) => one.id); // ["jp-kanto"]interface GroupingsOptions
What groupings() may be narrowed to.
kind?: "continent" | "m49" | "membership" | "informal" | "subdivision" | undefinedcountry?: string | undefinedinterface GroupingSource
Where a grouping's definition comes from, and the terms its list is under.
name: stringurl: stringlicence: stringtype GroupingStatus = "candidate" | "associate" | "observer" | "suspended";
How a country stands with a body when it is not a member.
membersOf: (id: string, options?: GroupingDateOptions) => readonly string[] | null
The members of a grouping: now, or on a given day for an international body.
id The grouping's id.options `on`, a day such as "2019-06-30".Returns The members' codes, frozen; `null` for an id that is not a grouping.
import { membersOf } from "@johnmorrisdotca/kuni/groupings";
membersOf("eu")?.includes("GB"); // false
membersOf("eu", { on: "2019-06-30" })?.includes("GB"); // true
membersOf("us-pacific"); // ["US-AK", "US-CA", "US-HI", "US-OR", "US-WA"]@johnmorrisdotca/kuni/withdrawnwithdrawn WITHDRAWN_READ withdrawnCountries WithdrawnCountry
withdrawn: (code: string) => readonly WithdrawnCountry[]
The withdrawn countries that held a code: the four-letter ISO 3166-3 code ("SUHH"), an alpha-2 ("SU"), an alpha-3 ("SUN") or a numeric code ("810"), in either case. A code can name more than one: "CS" was Czechoslovakia (CSHH) and then Serbia and Montenegro (CSXX), later first; and "BY" is a withdrawn country as well as a current one, which country("BY") answers on its own.
code Any code a withdrawn country held.Returns The matching records, the one that was withdrawn last first; an empty list for anything else, and for the code of a current country that was never withdrawn.
import { withdrawn } from "@johnmorrisdotca/kuni/withdrawn";
withdrawn("su")[0].name.en; // "Soviet Union"
withdrawn("SU")[0].until; // "1992"
withdrawn("YUCS")[0].successors; // ["CS"]: itself withdrawn, and resolved by withdrawn("CS")
withdrawn("CS").map((one) => one.code); // ["CSXX", "CSHH"]
withdrawn("JP"); // []WITHDRAWN_READ: "2026-10-10"
The day the Wikidata snapshot of the withdrawn codes was read.
import { WITHDRAWN_READ } from "@johnmorrisdotca/kuni/withdrawn";
WITHDRAWN_READ; // "2026-10-10"withdrawnCountries: () => readonly WithdrawnCountry[]
Every withdrawn country of ISO 3166-3, in order of its four-letter code. Never part of countries(), so a picker does not show them unless it asks.
Returns The 31 records, the list and its objects frozen and shared.
import { withdrawnCountries } from "@johnmorrisdotca/kuni/withdrawn";
withdrawnCountries().length; // 31
withdrawnCountries().map((one) => one.alpha2).includes("SU"); // trueinterface WithdrawnCountry
A country that was withdrawn from ISO 3166-1, as ISO 3166-3 lists it (frozen).
code: stringalpha2: stringalpha3?: string | undefinednumeric?: string | undefinedname: { en: string; ja: string | null; }since: stringuntil: stringsuccessors: readonly string[]reusedBy?: string | undefinedこの日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。