Skip to content

Commit

Permalink
Add countries common name
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadsalem committed Sep 18, 2023
1 parent 0cb37d4 commit 51b80b4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import CountryISO from '@mohammad231/iso_3166-1';
CountryISO.get();

// You can pass multiple search critera, the tool will look and return the first match
// The priority of the search is alpha_2, alpha_3, numeric, name and official_name
// The priority of the search is alpha_2, alpha_3, numeric, name, common name and official_name
CountryISO.get({
alpha_2: '', // ISO 3166-1 Alpha-2
alpha_3: '', // ISO 3166-1 Alpha-3
numeric: '', //ISO 3166-1 Numeric
name: '', // Country name
common_name: '', // Country common name
official_name: '', // Official name
});
```
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Country, CountryQuery} from './iso_3166-1';

/**
* Get country by country name, ISO 3166-1 Alpha-2, ISO 3166-1 Alpha-3, ISO 3166-1 Numeric or official name
* Get country by ISO 3166-1 Alpha-2, ISO 3166-1 Alpha-3, ISO 3166-1 Numeric, country name, common name or official name
*
* @param {CountryQuery} CountryQuery
* @returns {Country | null}
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports.get = void 0;
(async () => {
const iso_3166_1 = await require('./iso_3166-1.json');
/**
Get country by ISO 3166-1 Alpha-2, ISO 3166-1 Alpha-3, ISO 3166-1 Numeric, country name or official name
Get country by ISO 3166-1 Alpha-2, ISO 3166-1 Alpha-3, ISO 3166-1 Numeric, country name, common name or official name
*
* @param {CountryQuery} CountryQuery
* @returns {Country[] | Country | null}
Expand Down Expand Up @@ -39,6 +39,12 @@ exports.get = void 0;
return match;
}
}
if (CountryQuery?.common_name) {
match = country?.common_name === CountryQuery.common_name;
if (match) {
return match;
}
}
if (CountryQuery?.official_name) {
match = country?.official_name === CountryQuery.official_name;
if (match) {
Expand Down
2 changes: 2 additions & 0 deletions iso_3166-1.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface Country {
alpha_3: string;
numeric: string;
name: string;
common_name?: string;
official_name?: string;
flag: string;
}
Expand All @@ -14,5 +15,6 @@ export interface CountryQuery {
alpha_3?: string;
numeric?: string;
name?: string;
common_name?: string;
official_name?: string;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mohammad231/iso_3166-1",
"version": "1.0.0",
"version": "1.0.1",
"description": "Countries iso_3166-1 from https://salsa.debian.org/iso-codes-team/iso-codes",
"main": "index.js",
"types": "index.d.ts",
Expand Down

0 comments on commit 51b80b4

Please sign in to comment.