@sil/data 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +408 -0
- package/dist/sil-data.cjs +4971 -0
- package/dist/sil-data.cjs.map +1 -0
- package/dist/sil-data.js +4971 -0
- package/dist/sil-data.js.map +1 -0
- package/dist/types/data/cities.d.ts +22 -0
- package/dist/types/data/continents.d.ts +9 -0
- package/dist/types/data/countries.d.ts +18 -0
- package/dist/types/data/currencies.d.ts +13 -0
- package/dist/types/data/flags.d.ts +39 -0
- package/dist/types/data/geography.d.ts +33 -0
- package/dist/types/data/phoneCodes.d.ts +16 -0
- package/dist/types/data/states.d.ts +18 -0
- package/dist/types/data/worldMap.d.ts +122 -0
- package/dist/types/index.d.ts +29 -0
- package/dist/types/types/index.d.ts +220 -0
- package/dist/types/utils/geo.d.ts +101 -0
- package/package.json +56 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { City } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Major world cities with geographic and demographic data.
|
|
4
|
+
* Includes the largest cities by population and all national capitals.
|
|
5
|
+
*/
|
|
6
|
+
export declare const cities: City[];
|
|
7
|
+
/**
|
|
8
|
+
* Get cities for a specific country.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getCitiesByCountry(countryCode: string): City[];
|
|
11
|
+
/**
|
|
12
|
+
* Get the capital city of a country.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getCapitalCity(countryCode: string): City | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Get cities sorted by population (largest first).
|
|
17
|
+
*/
|
|
18
|
+
export declare function getCitiesByPopulation(limit?: number): City[];
|
|
19
|
+
/**
|
|
20
|
+
* Search cities by name (case-insensitive partial match).
|
|
21
|
+
*/
|
|
22
|
+
export declare function searchCities(query: string): City[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Continent } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* The seven continents with key metadata.
|
|
4
|
+
*/
|
|
5
|
+
export declare const continents: Continent[];
|
|
6
|
+
/**
|
|
7
|
+
* Get a continent by its two-letter code.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getContinentByCode(code: string): Continent | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Country } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Complete list of world countries with ISO codes, flags, phone codes, and metadata.
|
|
4
|
+
* Based on ISO 3166-1 standard.
|
|
5
|
+
*/
|
|
6
|
+
export declare const countries: Country[];
|
|
7
|
+
/**
|
|
8
|
+
* Get a country by its ISO 3166-1 alpha-2 code.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getCountryByCode(code: string): Country | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Get countries by continent.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getCountriesByContinent(continent: Country["continent"]): Country[];
|
|
15
|
+
/**
|
|
16
|
+
* Get a country's flag emoji by its ISO 3166-1 alpha-2 code.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getCountryFlag(alpha2: string): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Currency } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Major world currencies with ISO 4217 codes, symbols, and the countries that use them.
|
|
4
|
+
*/
|
|
5
|
+
export declare const currencies: Currency[];
|
|
6
|
+
/**
|
|
7
|
+
* Get currency by its ISO 4217 code.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getCurrencyByCode(code: string): Currency | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Get the currency used by a specific country.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getCurrencyByCountry(countryCode: string): Currency | undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { FlagInfo } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Build the flagcdn.com SVG URL for a country's flag.
|
|
4
|
+
* @param alpha2 ISO 3166-1 alpha-2 country code (case-insensitive)
|
|
5
|
+
*/
|
|
6
|
+
export declare function getFlagSvgUrl(alpha2: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Build the flagcdn.com PNG URL for a country's flag.
|
|
9
|
+
* @param alpha2 ISO 3166-1 alpha-2 country code (case-insensitive)
|
|
10
|
+
* @param width Image width in pixels (40 | 80 | 160 | 320 | 640 | 1280 | 2560). Default: 320
|
|
11
|
+
*/
|
|
12
|
+
export declare function getFlagPngUrl(alpha2: string, width?: 40 | 80 | 160 | 320 | 640 | 1280 | 2560): string;
|
|
13
|
+
/**
|
|
14
|
+
* Build a Wikimedia Commons URL for a country's outline SVG map.
|
|
15
|
+
* This is a reference URL—not bundled in the package.
|
|
16
|
+
* @param alpha3 ISO 3166-1 alpha-3 code (e.g., "USA")
|
|
17
|
+
*/
|
|
18
|
+
export declare function getCountryMapSvgUrl(alpha3: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Flag metadata for all world countries.
|
|
21
|
+
*
|
|
22
|
+
* `colors` lists the most prominent flag colours (up to 4), most dominant first.
|
|
23
|
+
* `similar` lists alpha-2 codes of countries whose flags are visually similar—
|
|
24
|
+
* useful for building confusing multiple-choice options in geography games.
|
|
25
|
+
*/
|
|
26
|
+
export declare const flagData: FlagInfo[];
|
|
27
|
+
/**
|
|
28
|
+
* Get flag data for a specific country by its alpha-2 code.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getFlagData(alpha2: string): FlagInfo | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Get all countries whose flags share a given color.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getFlagsByColor(color: FlagInfo["colors"][number]): FlagInfo[];
|
|
35
|
+
/**
|
|
36
|
+
* Get all similar-flag entries for a given country.
|
|
37
|
+
* Returns an array of FlagInfo for each similar country.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getSimilarFlags(alpha2: string): FlagInfo[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { CountryGeography } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Geographic and climate data for all world countries.
|
|
4
|
+
* Includes centroid coordinates, bounding boxes, area, landlocked status,
|
|
5
|
+
* neighbouring countries, climate zone, and average annual temperature.
|
|
6
|
+
*
|
|
7
|
+
* Centroid (lat/lon) is the geographical centre of the country, used for
|
|
8
|
+
* distance and direction calculations in geography games.
|
|
9
|
+
*
|
|
10
|
+
* Climate zone follows a simplified Köppen classification.
|
|
11
|
+
* avgTemperature is approximate mean annual temperature in °C.
|
|
12
|
+
* @note The `neighbors` arrays use ISO 3166-1 alpha-2 codes, including
|
|
13
|
+
* codes for disputed/special territories such as "EH" (Western Sahara)
|
|
14
|
+
* and "XK" (Kosovo). These are included to accurately reflect shared land
|
|
15
|
+
* borders, even where sovereignty is contested.
|
|
16
|
+
*/
|
|
17
|
+
export declare const countryGeography: CountryGeography[];
|
|
18
|
+
/**
|
|
19
|
+
* Get geography data for a specific country by its alpha-2 code.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getCountryGeography(alpha2: string): CountryGeography | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Get all landlocked countries.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getLandlockedCountries(): CountryGeography[];
|
|
26
|
+
/**
|
|
27
|
+
* Get countries by climate zone.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getCountriesByClimate(climate: CountryGeography["climate"]): CountryGeography[];
|
|
30
|
+
/**
|
|
31
|
+
* Get all countries that neighbour a given country.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getNeighbors(alpha2: string): CountryGeography[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PhoneCountryCode } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Phone country codes derived from the countries list, with additional
|
|
4
|
+
* entries for territories and special regions. Suitable for use in
|
|
5
|
+
* phone number input dropdowns.
|
|
6
|
+
*/
|
|
7
|
+
export declare const phoneCountryCodes: PhoneCountryCode[];
|
|
8
|
+
/**
|
|
9
|
+
* Get a phone country code entry by its ISO 3166-1 alpha-2 code.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getPhoneCodeByCountry(code: string): PhoneCountryCode | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Get all countries with a specific phone code.
|
|
14
|
+
* Useful for finding all countries that share a dialing code (e.g., +1).
|
|
15
|
+
*/
|
|
16
|
+
export declare function getCountriesByPhoneCode(phoneCode: string): PhoneCountryCode[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { State } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Administrative divisions (states, provinces, territories, regions)
|
|
4
|
+
* for major countries around the world.
|
|
5
|
+
*/
|
|
6
|
+
export declare const states: State[];
|
|
7
|
+
/**
|
|
8
|
+
* Get all states/provinces for a specific country.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getStatesByCountry(countryCode: string): State[];
|
|
11
|
+
/**
|
|
12
|
+
* Get a state by its code and country code.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getStateByCode(code: string, countryCode: string): State | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Get all states of a specific type.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getStatesByType(type: State["type"]): State[];
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* World map SVG utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides the vector path data for 211 countries (ISO 3166-1 alpha-2 IDs)
|
|
5
|
+
* and helper functions to generate, style, and highlight countries in SVG format.
|
|
6
|
+
*
|
|
7
|
+
* Path data adapted from svg-world-maps (MIT) – https://github.com/homayounmmdy/svg-world-maps
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { getWorldMapSvg, highlightCountries } from "@sil/data";
|
|
12
|
+
*
|
|
13
|
+
* // Render a plain world map
|
|
14
|
+
* document.getElementById("map").innerHTML = getWorldMapSvg({ fill: "#e0e0e0" });
|
|
15
|
+
*
|
|
16
|
+
* // Highlight specific countries
|
|
17
|
+
* document.getElementById("map").innerHTML = highlightCountries(
|
|
18
|
+
* [{ code: "US", fill: "#4a90e2" }, { code: "DE", fill: "#e24a4a" }],
|
|
19
|
+
* { fill: "#d0d0d0" }
|
|
20
|
+
* );
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
import type { WorldMapCountry, WorldMapOptions, WorldMapHighlight } from "../types/index.js";
|
|
24
|
+
/** ViewBox for the world map SVG canvas ("0 0 2000 857"). */
|
|
25
|
+
export declare const WORLD_MAP_VIEWBOX = "0 0 2000 857";
|
|
26
|
+
/**
|
|
27
|
+
* Default styling applied when no options are supplied.
|
|
28
|
+
*/
|
|
29
|
+
export declare const WORLD_MAP_DEFAULTS: Required<WorldMapOptions>;
|
|
30
|
+
/**
|
|
31
|
+
* SVG path data for every country on the world map.
|
|
32
|
+
* Paths use ISO 3166-1 alpha-2 codes as identifiers.
|
|
33
|
+
* Countries that have no drawable path (e.g. very small island nations) have an empty `paths` array.
|
|
34
|
+
*/
|
|
35
|
+
export declare const worldMapCountries: WorldMapCountry[];
|
|
36
|
+
/**
|
|
37
|
+
* Look up the SVG path data for a single country by its ISO alpha-2 code.
|
|
38
|
+
* The look-up is case-insensitive.
|
|
39
|
+
*
|
|
40
|
+
* @param code ISO 3166-1 alpha-2 code (e.g. "US", "de")
|
|
41
|
+
* @returns The matching {@link WorldMapCountry} entry, or `undefined` if not found.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const germany = getCountryMapData("DE");
|
|
45
|
+
* // { code: "DE", name: "Germany", paths: ["M..."] }
|
|
46
|
+
*/
|
|
47
|
+
export declare function getCountryMapData(code: string): WorldMapCountry | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Return all countries whose names contain the given search string
|
|
50
|
+
* (case-insensitive).
|
|
51
|
+
*
|
|
52
|
+
* @param name Full or partial country name
|
|
53
|
+
* @returns Array of matching {@link WorldMapCountry} entries.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* searchWorldMapCountries("land"); // → Greenland, Iceland, Finland, New Zealand, …
|
|
57
|
+
*/
|
|
58
|
+
export declare function searchWorldMapCountries(name: string): WorldMapCountry[];
|
|
59
|
+
/**
|
|
60
|
+
* Generate a complete SVG world map string.
|
|
61
|
+
*
|
|
62
|
+
* Each country `<path>` element is given:
|
|
63
|
+
* - `id` set to its ISO alpha-2 code (e.g. `id="DE"`)
|
|
64
|
+
* - `data-code` – same ISO alpha-2 code
|
|
65
|
+
* - `data-name` – common country name
|
|
66
|
+
*
|
|
67
|
+
* This makes it straightforward to select and style countries via CSS or JavaScript:
|
|
68
|
+
* ```css
|
|
69
|
+
* #DE { fill: steelblue; }
|
|
70
|
+
* ```
|
|
71
|
+
* ```js
|
|
72
|
+
* document.getElementById("FR").style.fill = "red";
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @param options Optional styling overrides (merged with {@link WORLD_MAP_DEFAULTS}).
|
|
76
|
+
* @returns A complete `<svg>…</svg>` string ready for insertion into the DOM.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* const svg = getWorldMapSvg({ fill: "#e8f4f8", stroke: "#aaa", hoverFill: "#4a90e2" });
|
|
80
|
+
* document.getElementById("map").innerHTML = svg;
|
|
81
|
+
*/
|
|
82
|
+
export declare function getWorldMapSvg(options?: WorldMapOptions): string;
|
|
83
|
+
/**
|
|
84
|
+
* Generate a world map SVG with specific countries highlighted in custom colours.
|
|
85
|
+
*
|
|
86
|
+
* All other countries keep the base fill from `options`. Each highlighted
|
|
87
|
+
* country can optionally carry an accessible `<title>` (via `highlight.label`).
|
|
88
|
+
*
|
|
89
|
+
* @param highlights Array of {@link WorldMapHighlight} descriptors.
|
|
90
|
+
* @param options Optional base styling (merged with {@link WORLD_MAP_DEFAULTS}).
|
|
91
|
+
* @returns A complete `<svg>…</svg>` string.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* const svg = highlightCountries(
|
|
95
|
+
* [
|
|
96
|
+
* { code: "US", fill: "#4a90e2", label: "United States" },
|
|
97
|
+
* { code: "CA", fill: "#e24a4a" },
|
|
98
|
+
* ],
|
|
99
|
+
* { fill: "#eeeeee" }
|
|
100
|
+
* );
|
|
101
|
+
*/
|
|
102
|
+
export declare function highlightCountries(highlights: WorldMapHighlight[], options?: WorldMapOptions): string;
|
|
103
|
+
/**
|
|
104
|
+
* Generate a world map SVG where countries are coloured by group.
|
|
105
|
+
*
|
|
106
|
+
* Useful for choropleth-style maps (e.g. continent groupings, data categories).
|
|
107
|
+
* Countries not present in any group get the base `options.fill`.
|
|
108
|
+
*
|
|
109
|
+
* @param groups Map from a fill colour to an array of ISO alpha-2 codes.
|
|
110
|
+
* @param options Optional base styling.
|
|
111
|
+
* @returns A complete `<svg>…</svg>` string.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* const svg = colorizeWorldMap(
|
|
115
|
+
* {
|
|
116
|
+
* "#4a90e2": ["US", "CA", "MX"],
|
|
117
|
+
* "#e24a4a": ["GB", "DE", "FR"],
|
|
118
|
+
* },
|
|
119
|
+
* { fill: "#dddddd" }
|
|
120
|
+
* );
|
|
121
|
+
*/
|
|
122
|
+
export declare function colorizeWorldMap(groups: Record<string, string[]>, options?: WorldMapOptions): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @sil/data
|
|
3
|
+
*
|
|
4
|
+
* A comprehensive collection of reusable world data:
|
|
5
|
+
* countries, phone codes, flags, cities, states, provinces, currencies, and more.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { phoneCountryCodes, countries, cities } from "@sil/data";
|
|
10
|
+
*
|
|
11
|
+
* // Use phone country codes in a select input
|
|
12
|
+
* const options = phoneCountryCodes.map(p => ({
|
|
13
|
+
* label: `${p.flag} ${p.country} (${p.phoneCode})`,
|
|
14
|
+
* value: p.phoneCode,
|
|
15
|
+
* }));
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export type { Country, PhoneCountryCode, City, State, StateType, Continent, ContinentName, Currency, CountryGeography, CountryBounds, ClimateZone, FlagInfo, FlagColor, CardinalDirection, WorldMapCountry, WorldMapOptions, WorldMapHighlight, } from "./types/index.js";
|
|
19
|
+
export { countries, getCountryByCode, getCountriesByContinent, getCountryFlag, } from "./data/countries.js";
|
|
20
|
+
export { phoneCountryCodes, getPhoneCodeByCountry, getCountriesByPhoneCode, } from "./data/phoneCodes.js";
|
|
21
|
+
export { cities, getCitiesByCountry, getCapitalCity, getCitiesByPopulation, searchCities, } from "./data/cities.js";
|
|
22
|
+
export { states, getStatesByCountry, getStateByCode, getStatesByType, } from "./data/states.js";
|
|
23
|
+
export { continents, getContinentByCode } from "./data/continents.js";
|
|
24
|
+
export { currencies, getCurrencyByCode, getCurrencyByCountry, } from "./data/currencies.js";
|
|
25
|
+
export { countryGeography, getCountryGeography, getLandlockedCountries, getCountriesByClimate, getNeighbors, } from "./data/geography.js";
|
|
26
|
+
export { flagData, getFlagData, getFlagsByColor, getSimilarFlags, getFlagSvgUrl, getFlagPngUrl, getCountryMapSvgUrl, } from "./data/flags.js";
|
|
27
|
+
export { haversineDistance, bearing, bearingToCardinal, getDistanceBetweenCountries, getDirectionBetweenCountries, compareTemperature, compareSize, getHemisphere, getGeoHints, } from "./utils/geo.js";
|
|
28
|
+
export type { GeoHint, Hemisphere } from "./utils/geo.js";
|
|
29
|
+
export { WORLD_MAP_VIEWBOX, WORLD_MAP_DEFAULTS, worldMapCountries, getCountryMapData, searchWorldMapCountries, getWorldMapSvg, highlightCountries, colorizeWorldMap, } from "./data/worldMap.js";
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a country with standard ISO codes and metadata.
|
|
3
|
+
*/
|
|
4
|
+
export interface Country {
|
|
5
|
+
/** Full official name of the country */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Common/short name of the country */
|
|
8
|
+
nativeName?: string;
|
|
9
|
+
/** ISO 3166-1 alpha-2 code (e.g., "US") */
|
|
10
|
+
alpha2: string;
|
|
11
|
+
/** ISO 3166-1 alpha-3 code (e.g., "USA") */
|
|
12
|
+
alpha3: string;
|
|
13
|
+
/** ISO 3166-1 numeric code (e.g., "840") */
|
|
14
|
+
numeric: string;
|
|
15
|
+
/** Unicode emoji flag */
|
|
16
|
+
flag: string;
|
|
17
|
+
/** International dialing code (e.g., "+1") */
|
|
18
|
+
phoneCode: string;
|
|
19
|
+
/** Capital city name */
|
|
20
|
+
capital: string;
|
|
21
|
+
/** Continent name */
|
|
22
|
+
continent: ContinentName;
|
|
23
|
+
/** ISO 4217 currency code (e.g., "USD") */
|
|
24
|
+
currency: string;
|
|
25
|
+
/** Primary language(s) spoken */
|
|
26
|
+
languages: string[];
|
|
27
|
+
/** Top-level domain (e.g., ".us") */
|
|
28
|
+
tld?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Continent names
|
|
32
|
+
*/
|
|
33
|
+
export type ContinentName = "Africa" | "Antarctica" | "Asia" | "Europe" | "North America" | "Oceania" | "South America";
|
|
34
|
+
/**
|
|
35
|
+
* Phone country code entry, suitable for use in phone number inputs.
|
|
36
|
+
*/
|
|
37
|
+
export interface PhoneCountryCode {
|
|
38
|
+
/** Country name */
|
|
39
|
+
country: string;
|
|
40
|
+
/** ISO 3166-1 alpha-2 code */
|
|
41
|
+
code: string;
|
|
42
|
+
/** International dialing code with + prefix (e.g., "+1") */
|
|
43
|
+
phoneCode: string;
|
|
44
|
+
/** Unicode emoji flag */
|
|
45
|
+
flag: string;
|
|
46
|
+
/** Example number format (without country code) */
|
|
47
|
+
example?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Represents a city with geographic and demographic data.
|
|
51
|
+
*/
|
|
52
|
+
export interface City {
|
|
53
|
+
/** City name */
|
|
54
|
+
name: string;
|
|
55
|
+
/** ISO 3166-1 alpha-2 country code */
|
|
56
|
+
country: string;
|
|
57
|
+
/** State, province, or region */
|
|
58
|
+
state?: string;
|
|
59
|
+
/** Approximate population */
|
|
60
|
+
population?: number;
|
|
61
|
+
/** Latitude */
|
|
62
|
+
lat: number;
|
|
63
|
+
/** Longitude */
|
|
64
|
+
lon: number;
|
|
65
|
+
/** Whether this is the capital of the country */
|
|
66
|
+
capital?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Represents a state, province, or other administrative division.
|
|
70
|
+
*/
|
|
71
|
+
export interface State {
|
|
72
|
+
/** Full name of the state/province */
|
|
73
|
+
name: string;
|
|
74
|
+
/** State/province abbreviation code */
|
|
75
|
+
code: string;
|
|
76
|
+
/** ISO 3166-1 alpha-2 country code */
|
|
77
|
+
country: string;
|
|
78
|
+
/** Type of administrative division */
|
|
79
|
+
type: StateType;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Types of administrative divisions
|
|
83
|
+
*/
|
|
84
|
+
export type StateType = "state" | "province" | "territory" | "autonomous region" | "district" | "department" | "region" | "county" | "emirate" | "canton";
|
|
85
|
+
/**
|
|
86
|
+
* Continent with metadata
|
|
87
|
+
*/
|
|
88
|
+
export interface Continent {
|
|
89
|
+
/** Continent name */
|
|
90
|
+
name: ContinentName;
|
|
91
|
+
/** Two-letter continent code */
|
|
92
|
+
code: string;
|
|
93
|
+
/** Approximate population */
|
|
94
|
+
population: number;
|
|
95
|
+
/** Area in square kilometers */
|
|
96
|
+
area: number;
|
|
97
|
+
/** Number of countries */
|
|
98
|
+
countries: number;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Currency information
|
|
102
|
+
*/
|
|
103
|
+
export interface Currency {
|
|
104
|
+
/** ISO 4217 currency code */
|
|
105
|
+
code: string;
|
|
106
|
+
/** Currency name */
|
|
107
|
+
name: string;
|
|
108
|
+
/** Currency symbol */
|
|
109
|
+
symbol: string;
|
|
110
|
+
/** Countries using this currency (alpha-2 codes) */
|
|
111
|
+
countries: string[];
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Climate zones based on the Köppen climate classification (simplified).
|
|
115
|
+
*/
|
|
116
|
+
export type ClimateZone = "tropical" | "subtropical" | "arid" | "mediterranean" | "temperate" | "continental" | "subarctic" | "arctic";
|
|
117
|
+
/**
|
|
118
|
+
* Geographic bounding box of a country.
|
|
119
|
+
*/
|
|
120
|
+
export interface CountryBounds {
|
|
121
|
+
/** Northernmost latitude */
|
|
122
|
+
north: number;
|
|
123
|
+
/** Southernmost latitude */
|
|
124
|
+
south: number;
|
|
125
|
+
/** Easternmost longitude */
|
|
126
|
+
east: number;
|
|
127
|
+
/** Westernmost longitude */
|
|
128
|
+
west: number;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Geographic and climate data for a country, useful for geography games.
|
|
132
|
+
*/
|
|
133
|
+
export interface CountryGeography {
|
|
134
|
+
/** ISO 3166-1 alpha-2 code */
|
|
135
|
+
alpha2: string;
|
|
136
|
+
/** Centroid latitude of the country */
|
|
137
|
+
lat: number;
|
|
138
|
+
/** Centroid longitude of the country */
|
|
139
|
+
lon: number;
|
|
140
|
+
/** Approximate bounding box */
|
|
141
|
+
bounds: CountryBounds;
|
|
142
|
+
/** Land area in km² */
|
|
143
|
+
area: number;
|
|
144
|
+
/** Whether the country is landlocked (has no coastline) */
|
|
145
|
+
landlocked: boolean;
|
|
146
|
+
/** Neighboring country alpha-2 codes */
|
|
147
|
+
neighbors: string[];
|
|
148
|
+
/** Primary climate zone */
|
|
149
|
+
climate: ClimateZone;
|
|
150
|
+
/** Average annual temperature in Celsius */
|
|
151
|
+
avgTemperature: number;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Primary colors that can appear on a country flag.
|
|
155
|
+
*/
|
|
156
|
+
export type FlagColor = "red" | "dark-red" | "white" | "blue" | "green" | "yellow" | "orange" | "black" | "gold" | "light-blue" | "dark-blue" | "dark-green" | "purple" | "brown";
|
|
157
|
+
/**
|
|
158
|
+
* Flag metadata for a country, including visual similarity data for geography games.
|
|
159
|
+
*/
|
|
160
|
+
export interface FlagInfo {
|
|
161
|
+
/** ISO 3166-1 alpha-2 code */
|
|
162
|
+
alpha2: string;
|
|
163
|
+
/** URL to SVG flag image (via flagcdn.com) */
|
|
164
|
+
svgUrl: string;
|
|
165
|
+
/** URL to a 4×3 PNG flag image (via flagcdn.com) */
|
|
166
|
+
pngUrl: string;
|
|
167
|
+
/** Primary colors present on the flag (up to 4, most prominent first) */
|
|
168
|
+
colors: FlagColor[];
|
|
169
|
+
/**
|
|
170
|
+
* Alpha-2 codes of countries whose flags look visually similar.
|
|
171
|
+
* Useful for building "guess the flag" games with confusing options.
|
|
172
|
+
*/
|
|
173
|
+
similar: string[];
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* 8-point cardinal / intercardinal compass directions.
|
|
177
|
+
*/
|
|
178
|
+
export type CardinalDirection = "N" | "NE" | "E" | "SE" | "S" | "SW" | "W" | "NW";
|
|
179
|
+
/**
|
|
180
|
+
* SVG path data for a single country on the world map.
|
|
181
|
+
* A country may consist of multiple disjoint polygons (e.g. islands).
|
|
182
|
+
*/
|
|
183
|
+
export interface WorldMapCountry {
|
|
184
|
+
/** ISO 3166-1 alpha-2 code (e.g. "US") */
|
|
185
|
+
code: string;
|
|
186
|
+
/** Common country name */
|
|
187
|
+
name: string;
|
|
188
|
+
/** One or more SVG path `d` attribute strings */
|
|
189
|
+
paths: string[];
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Styling options for rendering the world map SVG.
|
|
193
|
+
*/
|
|
194
|
+
export interface WorldMapOptions {
|
|
195
|
+
/** Fill color for all country shapes. Default: "#d0d0d0" */
|
|
196
|
+
fill?: string;
|
|
197
|
+
/** Stroke (border) color between countries. Default: "#ffffff" */
|
|
198
|
+
stroke?: string;
|
|
199
|
+
/** Stroke width in SVG units. Default: 0.5 */
|
|
200
|
+
strokeWidth?: number;
|
|
201
|
+
/** Fill color applied to a country on hover. Default: "#a0a0a0" */
|
|
202
|
+
hoverFill?: string;
|
|
203
|
+
/** SVG element width attribute (e.g. "100%", 800). Default: "100%" */
|
|
204
|
+
width?: string | number;
|
|
205
|
+
/** SVG element height attribute (e.g. "auto", 400). Default: "auto" */
|
|
206
|
+
height?: string | number;
|
|
207
|
+
/** Optional CSS class added to the `<svg>` element. */
|
|
208
|
+
className?: string;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Describes a highlighted country on the world map.
|
|
212
|
+
*/
|
|
213
|
+
export interface WorldMapHighlight {
|
|
214
|
+
/** ISO 3166-1 alpha-2 code of the country to highlight */
|
|
215
|
+
code: string;
|
|
216
|
+
/** Fill color to use for this country. Overrides the default fill. */
|
|
217
|
+
fill: string;
|
|
218
|
+
/** Optional accessible label (written as a `<title>` element). */
|
|
219
|
+
label?: string;
|
|
220
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { CardinalDirection, ClimateZone } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Calculate the great-circle distance in kilometres between two geographic
|
|
4
|
+
* coordinates using the Haversine formula.
|
|
5
|
+
*/
|
|
6
|
+
export declare function haversineDistance(lat1: number, lon1: number, lat2: number, lon2: number): number;
|
|
7
|
+
/**
|
|
8
|
+
* Calculate the initial bearing (in degrees, 0 = north, clockwise) from one
|
|
9
|
+
* coordinate to another.
|
|
10
|
+
*/
|
|
11
|
+
export declare function bearing(lat1: number, lon1: number, lat2: number, lon2: number): number;
|
|
12
|
+
/**
|
|
13
|
+
* Convert a bearing in degrees to an 8-point cardinal/intercardinal direction.
|
|
14
|
+
*/
|
|
15
|
+
export declare function bearingToCardinal(deg: number): CardinalDirection;
|
|
16
|
+
/**
|
|
17
|
+
* Get the great-circle distance in km between two countries (by alpha-2 code),
|
|
18
|
+
* measured between their geographic centroids.
|
|
19
|
+
*
|
|
20
|
+
* Returns `null` if either country code is unknown.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getDistanceBetweenCountries(alpha2A: string, alpha2B: string): number | null;
|
|
23
|
+
/**
|
|
24
|
+
* Get the compass direction FROM country A TO country B (by alpha-2 code).
|
|
25
|
+
*
|
|
26
|
+
* For example, `getDirectionBetweenCountries("FR", "DE")` returns `"NE"`.
|
|
27
|
+
* Returns `null` if either country code is unknown.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getDirectionBetweenCountries(fromAlpha2: string, toAlpha2: string): CardinalDirection | null;
|
|
30
|
+
/**
|
|
31
|
+
* Compare the average annual temperature of two countries.
|
|
32
|
+
*
|
|
33
|
+
* Returns `"hotter"` if country B is warmer, `"colder"` if cooler, or
|
|
34
|
+
* `"similar"` if the difference is ≤ 3 °C.
|
|
35
|
+
*
|
|
36
|
+
* Useful in geography games: "The target country is hotter than your guess."
|
|
37
|
+
*/
|
|
38
|
+
export declare function compareTemperature(guessAlpha2: string, targetAlpha2: string): "hotter" | "colder" | "similar" | null;
|
|
39
|
+
/**
|
|
40
|
+
* Compare the size (area) of two countries.
|
|
41
|
+
*
|
|
42
|
+
* Returns `"larger"` if the target country is bigger, `"smaller"` if smaller,
|
|
43
|
+
* or `"similar"` if within 20 % of each other.
|
|
44
|
+
*/
|
|
45
|
+
export declare function compareSize(guessAlpha2: string, targetAlpha2: string): "larger" | "smaller" | "similar" | null;
|
|
46
|
+
/**
|
|
47
|
+
* Return a human-readable hemisphere description for a country's centroid.
|
|
48
|
+
*
|
|
49
|
+
* e.g. `"Northern"` | `"Southern"` | `"Eastern"` | `"Western"`
|
|
50
|
+
*/
|
|
51
|
+
export declare function getHemisphere(alpha2: string): Hemisphere | null;
|
|
52
|
+
/**
|
|
53
|
+
* Hemisphere of a country: north/south and east/west of the prime meridian/equator.
|
|
54
|
+
*/
|
|
55
|
+
export interface Hemisphere {
|
|
56
|
+
/** "Northern" if centroid latitude ≥ 0, otherwise "Southern" */
|
|
57
|
+
ns: "Northern" | "Southern";
|
|
58
|
+
/** "Eastern" if centroid longitude ≥ 0, otherwise "Western" */
|
|
59
|
+
ew: "Eastern" | "Western";
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A structured hint object for a geography guessing game.
|
|
63
|
+
*
|
|
64
|
+
* Given a player's guess and the secret target, produces all relevant hints.
|
|
65
|
+
*/
|
|
66
|
+
export interface GeoHint {
|
|
67
|
+
/** Distance from guessed country centroid to target centroid (km) */
|
|
68
|
+
distanceKm: number;
|
|
69
|
+
/** Compass direction from guess toward target */
|
|
70
|
+
direction: CardinalDirection;
|
|
71
|
+
/** Whether the target is hotter, colder, or similar in temperature */
|
|
72
|
+
temperature: "hotter" | "colder" | "similar";
|
|
73
|
+
/** Whether the target is larger, smaller, or similar in area */
|
|
74
|
+
size: "larger" | "smaller" | "similar";
|
|
75
|
+
/** Hemisphere of the target country */
|
|
76
|
+
hemisphere: Hemisphere;
|
|
77
|
+
/** Whether the target is landlocked */
|
|
78
|
+
landlocked: boolean;
|
|
79
|
+
/** Climate zone of the target */
|
|
80
|
+
climate: ClimateZone;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Generate all geography game hints comparing a player's guess to the target.
|
|
84
|
+
*
|
|
85
|
+
* Returns `null` if either alpha-2 code is not found in the dataset.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const hints = getGeoHints("NL", "DE");
|
|
90
|
+
* // {
|
|
91
|
+
* // distanceKm: 531,
|
|
92
|
+
* // direction: "E",
|
|
93
|
+
* // temperature: "similar",
|
|
94
|
+
* // size: "larger",
|
|
95
|
+
* // hemisphere: { ns: "Northern", ew: "Eastern" },
|
|
96
|
+
* // landlocked: false,
|
|
97
|
+
* // climate: "temperate",
|
|
98
|
+
* // }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function getGeoHints(guessAlpha2: string, targetAlpha2: string): GeoHint | null;
|