{"id":18469392,"url":"https://github.com/fruitsbytes/country-list-ts","last_synced_at":"2026-04-30T09:33:22.201Z","repository":{"id":64534316,"uuid":"574494191","full_name":"Fruitsbytes/country-list-ts","owner":"Fruitsbytes","description":"Compiled lists, mapped lists and tagged list of the countries and values.","archived":false,"fork":false,"pushed_at":"2022-12-09T03:01:09.000Z","size":5555,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T07:49:47.187Z","etag":null,"topics":["capital","countries","currencies","flags","geo-json","javascript","languages","lists","topo-json","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Fruitsbytes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-05T12:44:22.000Z","updated_at":"2023-08-02T09:34:17.000Z","dependencies_parsed_at":"2022-12-11T04:02:10.996Z","dependency_job_id":null,"html_url":"https://github.com/Fruitsbytes/country-list-ts","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fruitsbytes%2Fcountry-list-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fruitsbytes%2Fcountry-list-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fruitsbytes%2Fcountry-list-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fruitsbytes%2Fcountry-list-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Fruitsbytes","download_url":"https://codeload.github.com/Fruitsbytes/country-list-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252839282,"owners_count":21812084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["capital","countries","currencies","flags","geo-json","javascript","languages","lists","topo-json","typescript"],"created_at":"2024-11-06T10:10:15.335Z","updated_at":"2026-04-30T09:33:22.174Z","avatar_url":"https://github.com/Fruitsbytes.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n \u003cimg src=\"./wiki/banner.png\" alt=\"Showing the title of the repository, Country list , next to the Typsript logo and the fruitsBytes logo\" width=\"800\" title=\"Country list TS banner image\"\u003e\n\u003c/p\u003e\n\n# Country List TS\n\nThis repository is based from the list of countries provided by [mledoze/countries](https://github.com/mledoze/countries). \n\nIt provides various compiled lists, mapped lists and tagged list of the property values. You can also search for a country based on the values in the property.\n\n\u003e⚠ Warning: \n\u003e\n\u003eNot all entities in this project are independent countries; refer to the independent property to know if the\ncountry is considered a sovereign state.\n\n## Features\n\n- Importable assets\n    - flags\n    - geo-json\n    - topo-json\n- 🚧 Flag WebComponent\n- List\n    - of names, capitals, languages, currencies ...\n    - mapped lists by ISO 3166-1 alpha-2\n    - with\n- Search\n\n## Installation\n\n```shell\nnpm i \n```\n\n### Compatibility table\n\n| Version | JS target | JS lib |\n|:-------:|:---------:|:------:|\n|  1.0.0  |    ES5    | ES2017 |\n\n## Usage\n\n### List\n\nGet list of country record member.\n\n#### Simple list\n```typescript\nimport {ls} from \"country-list-ts\";\n\nconst c = await ls('capital'); // ordered by country name\n\n// Output:\n// [\"Oranjestad\",\"Kabul\",\"Luanda\",\"The Valley\",\"Mariehamn\",\"Tirana\", ... ]\n````\n\nIt's the same as :\n\n```typescript\nimport {capitals} from \"country-list-ts\";\n\nconst c = (await capitals()).sort(); // reorder alphabetically\n// Output: \n// ['Abu Dhabi', 'Abuja', 'Accra', 'Adamstown', 'Addis Ababa', ... ]\n```\n\n| function call           | alias                    |\n|-------------------------|--------------------------|\n| `ls(\"cca2\")`            | `cca2s()`                |\n| `ls(\"tld\") `            | `tlds()`                 |\n| `ls(\"ccn3\")`            | `ccn3s() `               |\n| `ls(\"cca3\")`            | `cca3s()`                |\n| `ls(\"cioc\")`            | `ciocs()`                |\n| `ls(\"countryStatus\")`   | `countryStatuses()`      |\n| `ls(\"commonName\") `     | `commonNames()`          |\n| `ls(\"officialName\") `   | `officialNames()`        |\n| `ls(\"currencyCode\")`    | `currencyCodes()`        |\n| `ls(\"currencyName\")`    | `currencyNames()`        |\n| `ls(\"currencySymbol\")`  | `currencySymbols()`      |\n| `ls(\"region\")`          | `regions()`              |\n| `ls(\"subRegion\")`       | `subRegions()`           |\n| `ls(\"capital\")`         | `capitals()`             |\n| `ls(\"lang\")`            | `langs()`                |\n| `ls(\"languageName\")`    | `languageNames()`        |\n\n\n#### Tagged lists\n```typescript\nimport {lsF} from \"country-list-ts\";\n\nconst currencies = await lsF(\"currencies\");\n\n// Output:\n// [\n//  { \"currencies\":{\"AWG\":{\"name\":\"Aruban florin\",\"symbol\":\"ƒ\"}},\"cca2\":\"AW\"},\n//  { \"currencies\":{\"AFN\":{\"name\":\"Afghan afghani\",\"symbol\":\"؋\"}},\"cca2\":\"AF\"},\n//   ...\n//]\n\n```\nHere is an example with Angular ngFor:\n````typescript\n@Component({\n  selector: 'app-select-country',\n  template: '\u003cselect\u003e ' +\n          '\u003coption *ngFor=\"let country of $countryList | async\" [ngValue]=\"country.cca2\"\u003e' +\n          '{{country.name.official}}' +\n          '\u003c/option\u003e ' +\n          '\u003c/select\u003e',\n  styleUrls: ['./select-country.scss']\n})\nexport class SelectCountryComponent {\n  public $countryList = lsF(); // default list name\n}\n````\n\n#### Mapped list\n```typescript\nimport {lsM} from \"country-list-ts\";\nconst gps = await lsM(\"latLng\");\n// Output:\n// {\"AW\":[12.5,-69.96666666],\"AF\":[33,65],\"AO\":[-12.5,18.5],\"AI\":[18.25,-63.16666666],....]\n```\n\nNote, for tagged and mapped lists the available property values are:\n\u003cp\u003e\nname, tld, ccn3, cca3, cioc, independent, idd, countryStatus, currencies, region, subRegion, capitals, languages, translations, latLng, landlocked, borders, area, flag, demonyms, callingCodes\n\u003c/p\u003e\n\n### All\nYou can get a list of all the country data:\n\n```typescript\nimport {all} from \"country-list-ts\";\n\n/**\n * @var {Country[]}\n */\nconst countries = await all();\n```\n\nAn example of a Country object :\n\n```typescript\nconst austria = {\n    name: {\n        common: \"Austria\",\n        official: \"Republic of Austria\",\n        native: {\n            bar: {\n                official: \"Republik Österreich\",\n                common: \"Österreich\"\n            }\n        }\n    },\n    tld: [\".at\"],\n    cca2: \"AT\",\n    ccn3: \"040\",\n    cca3: \"AUT\",\n    cioc: \"AUT\",\n    independent: true,\n    status: \"officially-assigned\",\n    unMember: true,\n    currencies: {\n        EUR: {\n            name: \"Euro\",\n            symbol: \"€\"\n        }\n    },\n    idd: {\n        \"root\": \"+4\",\n        \"suffixes\": [\"3\"]\n    },\n    capital: [\"Vienna\"],\n    altSpellings: [\"AT\", \"Osterreich\", \"Oesterreich\"],\n    region: \"Europe\",\n    subregion: \"Western Europe\",\n    languages: {\n        bar: \"Austro-Bavarian German\"\n    },\n    translations: {\n        cym: {official: \"Republic of Austria\", common: \"Awstria\"},\n        deu: {official: \"Republik Österreich\", common: \"Österreich\"},\n        fra: {official: \"République d'Autriche\", common: \"Autriche\"},\n        hrv: {official: \"Republika Austrija\", common: \"Austrija\"},\n        ita: {official: \"Repubblica d'Austria\", common: \"Austria\"},\n        jpn: {official: \"オーストリア共和国\", common: \"オーストリア\"},\n        nld: {official: \"Republiek Oostenrijk\", common: \"Oostenrijk\"},\n        por: {official: \"República da Áustria\", common: \"Áustria\"},\n        rus: {official: \"Австрийская Республика\", common: \"Австрия\"},\n        spa: {official: \"República de Austria\", common: \"Austria\"}\n    },\n    latlng: [47.33333333, 13.33333333],\n    demonyms: {\n        fra: {\n            f: \"Autrichienne\",\n            m: \"Autrichien\"\n        },\n        spa: {\n            f: \"Austriaco\",\n            m: \"Austriaca\"\n        }\n    },\n    landlocked: true,\n    borders: [\"CZE\", \"DEU\", \"HUN\", \"ITA\", \"LIE\", \"SVK\", \"SVN\", \"CHE\"],\n    area: 83871,\n    callingCodes: [\"+43\"],\n    flag: \"🇦🇹\"\n}\n```\n\nDefinition:\n\n- `name`\n  - `common` - common name in english\n  - `official` - official name in english\n  - `native` - list of all native names\n    - key: three-letter ISO 639-3 language code\n    - value: name object\n      - key: official - official name translation\n      - key: common - common name translation\n- `tld` - country code top-level domain \n- `cca2` - code ISO 3166-1 alpha-2\n- `cca3` - code ISO 3166-1 alpha-3\n- `ccn3` - code ISO 3166-1 numeric \n- `cioc` - code International Olympic Committee\n- `independent` - ISO 3166-1 independence status  (denotes the country is considered a sovereign state)\n- `status` - ISO 3166-1 assignment status \n- `unMember` - UN Member status\n- `currencies` - list of all currencies\n  - key: ISO 4217 currency code\n  - value: currency object\n    - key: `name` name of the currency\n    - key: `symbol` symbol of the currency\n-  `idd` - International Direct Dialing info \n  - `root` - the root geographical code prefix. e.g. +6 for New Zealand, +4 for UK.\n  - `suffixes` - list of all suffixes assigned to this country. 4 for NZ, 809, 829, and 849 for Dominican Republic.\n- `capital` - capital city(ies)\n- `altSpellings` - alternative spellings \n- `region`\n- `subregion`\n- `languages` - list of official languages\n  - key: three-letter ISO 639-3 language code\n  - value: name of the language in english\n- `translations` - list of name translations\n  - key: three-letter ISO 639-3 language code\n  - value: name object\n    - key: official - official name translation\n    - key: common - common name translation\n- `latlng` - latitude and longitude\n- `demonyms` - name of residents, translated \u0026 gendered\n  - key: three-letter ISO 639-3 language code\n  - value: genderized demonym object\n    - key: `f` (female) or `m` (male)\n    - value: genderized demonym translation\n- `landlocked` - landlocked status, if the country has direct access to ports for its maritime trade\n- `borders` - land borders\n- `area` - land area in km²\n- `flag` - Emoji flag\n- `callingCodes` - calling codes\n\n### Search\n\nYou can search for a country using the property name:\n\n```typescript\nimport {find} from \"country-list-ts\";\n\n/**\n * @var {Country}\n */\nconst haiti = await find(\"name.common\", \"Haiti\") ;\nconst {capital} = await find(\"name.common\", \"Canada\"); // [\"Ottawa\"]\n```\nThe `find` frunction returns the first Country that satisfies the search value. To get a list use `get`\n\n```typescript\nimport {get} from \"country-list-ts\";\n\n/**\n * @var {Country[]}\n */\nconst tropicals = await get(\"region\", \"Caribbean\") ;\n```\n\nBoth `find` and `get` are memoized;\n\n### Assets\n\n#### Flags\n\n```typescript jsx\n// React\nimport {bra_flag} from \"@fruitsbytes/country-list-ts/dist/flags\";\n\nexport function BrasilFlag() {\n  \n    return (\n        \u003cimg src={bra_flag}/\u003e\n    )\n}\n\n```\nexample: [Brasil](./src/data/geo-json/usa.geo.json)\n\n#### Geo-JSON\n```typescript\nimport {usa_geo_json} from \"@fruitsbytes/country-list-ts/dist/geo-json\";\n```\nexample: [USA](./src/data/geo-json/usa.geo.json)\n\n\n#### Topo-JSON\n```typescript\nimport {ht} from \"@fruitsbytes/country-list-ts/dist/topo-json\";\n```\n\nexample: [USA](./src/data/topo-json/usa.topo.json)\n\n## Extend\nFor specific use case you can combine it with othe libraries:\n\n### Fuzzy search\n\n[Fuse.js](https://fusejs.io/) is a powerful, lightweight fuzzy-search library, with zero dependencies.\n\nGenerally speaking, fuzzy searching (more formally known as approximate string matching) is the technique of finding strings that are approximately equal to a given pattern (rather than exactly\n\nYou can use FuseJS for country list suggestion/TypeHead input\n\n````javascript\nimport {all} from \"country-list-ts\";\nimport Fuse from 'fuse.js';\n\nconst countries = await all();\n\nconst fuse = new Fuse(countries, {\n  keys: ['cca2', 'cca3', 'name.common']\n})\n\nconst found = fuse.search('hait');\n\n// Output:\n// [\n//   {\n//     item: {\n//        {\n//         ...\n//         \"tld\": [\".ht\"],\n//         \"cca2\": \"HT\",\n//         ...\n//        }\n//     },\n//     refIndex: 0\n//   },\n// ...\n// ]\n````\n\n\nMore examples :\n\n- [Search String Array](https://fusejs.io/examples.html#search-string-array)\n- [Search Object Array](https://fusejs.io/examples.html#search-object-array)\n- [Nested Search - dot notation](https://fusejs.io/examples.html#nested-search)\n- [Weighted Search](https://fusejs.io/examples.html#weighted-search)\n- [Extended Search](https://fusejs.io/examples.html#extended-search)\n\n### Phone number\n[libphonenumber-js](https://www.npmjs.com/package/libphonenumber-js) is a simpler and smaller rewrite of Google Android's  libphonenumber library in javascript.\n\nSee the [demo](https://catamphetamine.gitlab.io/libphonenumber-js/). \n\nYou can use this library to get the country of a phone number:\n\n```typescript\n// my-file.ts\n\nimport parsePhoneNumber from 'libphonenumber-js';\nimport {find} from \"country-list-ts\";\n\nfunction getCountryByPhonenumber(phone: string) {\n  const phoneNumber = parsePhoneNumber(phone);\n\n  if (phoneNumber) {\n    return find(\"cca2\", phoneNumber.country);\n  }\n\n  return undefined;\n}\n\n/**\n * @var {Country|undefined}\n */\nconst country = find(\"+50934524301\");\n\nconsole.log(country?.name?.common, country?.flag); // Haiti 🇭🇹\n\n```\n\n## Licence\n\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffruitsbytes%2Fcountry-list-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffruitsbytes%2Fcountry-list-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffruitsbytes%2Fcountry-list-ts/lists"}