Skip to content

Commit

Permalink
Merge branch 'master' into mitodl-master
Browse files Browse the repository at this point in the history
  • Loading branch information
pdpinch committed Aug 20, 2017
2 parents 56e303c + 5a08983 commit 16d72f2
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.0.0

* Israeli names are now in English.
* Update Mexican names.
* Return `null` instead of `{}` when lookup fails for `country` and `subdivision`.

# 0.6.0

* Find country by name.
Expand Down
57 changes: 50 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
code: 'SE-O' }
```

```js
> iso3166.subdivision("UN-1");
null
```

```js
> iso3166.subdivision("SE", "O");

Expand All @@ -51,32 +56,68 @@ https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
code: 'US-IN' }
```

```js
> iso3166.country("Sweden");
{ name: 'Sweden',
sub:
{ 'SE-O': { type: 'County', name: 'Västra Götalands län' },
'SE-N': { type: 'County', name: 'Hallands län' },
'SE-M': { type: 'County', name: 'Skåne län' },
'SE-K': { type: 'County', name: 'Blekinge län' },
'SE-I': { type: 'County', name: 'Gotlands län' },
'SE-H': { type: 'County', name: 'Kalmar län' },
'SE-G': { type: 'County', name: 'Kronobergs län' },
'SE-F': { type: 'County', name: 'Jönköpings län' },
'SE-E': { type: 'County', name: 'Östergötlands län' },
'SE-D': { type: 'County', name: 'Södermanlands län' },
'SE-C': { type: 'County', name: 'Uppsala län' },
'SE-W': { type: 'County', name: 'Dalarnas län' },
'SE-Z': { type: 'County', name: 'Jämtlands län' },
'SE-Y': { type: 'County', name: 'Västernorrlands län' },
'SE-X': { type: 'County', name: 'Gävleborgs län' },
'SE-AC': { type: 'County', name: 'Västerbottens län' },
'SE-AB': { type: 'County', name: 'Stockholms län' },
'SE-BD': { type: 'County', name: 'Norrbottens län' },
'SE-T': { type: 'County', name: 'Örebro län' },
'SE-S': { type: 'County', name: 'Värmlands län' },
'SE-U': { type: 'County', name: 'Västmanlands län' } },
code: 'SE' }
```

```js
> iso3166.country("United Nations");
null
```

## Functions

### iso3166.subdivision(code)
Retrieves a subdivision by its full code, ex "SE-O", "US-IN".
Retrieves a subdivision by its full code, ex "SE-O", "US-IN". Returns
`null` if not found.

* * *

### iso3166.subdivision(country code, subdivision code)
Retrieves a subdivision by its country code and subdivision code,
ex ("SWE", "O").
Retrieves a subdivision by its country code and subdivision code, ex
("SWE", "O"). Returns `null` if not found.

* * *

### iso3166.subdivision(country code, subdivision name)
Retrieves a subdivision by its country code and subdivision name,
ex ("US", "Indiana").
Retrieves a subdivision by its country code and subdivision name, ex
("US", "Indiana"). Returns `null` if not found.

* * *

### iso3166.country(country code)
Retrieves a country by its code, ex "US", "SE", "SWE".
Retrieves a country by its code, ex "US", "SE", "SWE". Returns `null`
if not found.

* * *

### iso3166.country(country name)
Retrieves a country by its name, ex "United States", "Sweden".
Retrieves a country by its name, ex "United States", "Sweden". Returns
`null` if not found.

* * *

Expand Down Expand Up @@ -115,6 +156,8 @@ The ISO 3166-1 alpha 3 to alpha 2 conversion table, the layout is:
* Ola Holmström (@olahol)
* Ben Ilegbodu (@benmvp)
* David García (@davidgf)
* lhchavez (@lhchavez)
* Peter Pinch (@pdpinch)

[npm-image]: https://img.shields.io/npm/v/iso-3166-2.svg?style=flat-square
[npm-url]: https://npmjs.org/package/iso-3166-2
Expand Down
8 changes: 4 additions & 4 deletions data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2750,16 +2750,16 @@ Mexico,MX-BCS,Baja California Sur,State,MX
Mexico,MX-CAM,Campeche,State,MX
Mexico,MX-CHH,Chihuahua,State,MX
Mexico,MX-CHP,Chiapas,State,MX
Mexico,MX-COA,Coahuila,State,MX
Mexico,MX-COA,Coahuila de Zaragoza,State,MX
Mexico,MX-COL,Colima,State,MX
Mexico,MX-DIF,Distrito Federal,Federal district,MX
Mexico,MX-CMX,Ciudad de México,Federal District,MX
Mexico,MX-DUR,Durango,State,MX
Mexico,MX-GRO,Guerrero,State,MX
Mexico,MX-GUA,Guanajuato,State,MX
Mexico,MX-HID,Hidalgo,State,MX
Mexico,MX-JAL,Jalisco,State,MX
Mexico,MX-MEX,México,State,MX
Mexico,MX-MIC,Michoacán,State,MX
Mexico,MX-MIC,Michoacán de Ocampo,State,MX
Mexico,MX-MOR,Morelos,State,MX
Mexico,MX-NAY,Nayarit,State,MX
Mexico,MX-NLE,Nuevo León,State,MX
Expand All @@ -2773,7 +2773,7 @@ Mexico,MX-SON,Sonora,State,MX
Mexico,MX-TAB,Tabasco,State,MX
Mexico,MX-TAM,Tamaulipas,State,MX
Mexico,MX-TLA,Tlaxcala,State,MX
Mexico,MX-VER,Veracruz,State,MX
Mexico,MX-VER,Veracruz de Ignacio de la Llave,State,MX
Mexico,MX-YUC,Yucatán,State,MX
Mexico,MX-ZAC,Zacatecas,State,MX
"Micronesia, Federated States Of",FM-KSA,Kosrae,State,FM
Expand Down
6 changes: 3 additions & 3 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var functions = {

// This country code does not exist in our data set.
if (!(country in data)) {
return {};
return null;
}

// All of a countries subdivisions.
Expand All @@ -66,7 +66,7 @@ var functions = {

// If we still couldn't find it return empty record.
if (typeof record === "undefined") {
return {};
return null;
}
}

Expand Down Expand Up @@ -109,7 +109,7 @@ var functions = {

// If we still couldn't find it return empty record.
if (typeof record === "undefined") {
return {};
return null;
}

return record;
Expand Down
11 changes: 5 additions & 6 deletions iso3166.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "iso-3166-2",
"description": "Lookup information about ISO-3166-2 subdivisions.",
"version": "0.6.0",
"version": "1.0.0",
"author": "Ola Holmström <[email protected]>",
"keywords": [
"iso3166",
Expand Down
19 changes: 17 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var test = require("tape");
var iso3166 = require("../iso3166.min");

test("country()", function (t) {
t.plan(6);
t.plan(8);

var country = iso3166.country("SE");

Expand All @@ -17,10 +17,16 @@ test("country()", function (t) {
country = iso3166.country("Sweden");
t.equal(country.code, "SE");
t.equal(country.name, "Sweden");

country = iso3166.country("UN");
t.equal(country, null);

country = iso3166.country("United Nations");
t.equal(country, null);
});

test("subdivison()", function (t) {
t.plan(50);
t.plan(53);

var sub = iso3166.subdivision("SE-O");
t.equal(sub.countryCode, "SE");
Expand Down Expand Up @@ -91,6 +97,15 @@ test("subdivison()", function (t) {
t.equal(sub.code, "US-IN");
t.equal(sub.regionCode, "IN");
t.equal(sub.name, "Indiana");

sub = iso3166.subdivision("UN-1");
t.equal(sub, null);

sub = iso3166.subdivision("UN", "1");
t.equal(sub, null);

sub = iso3166.subdivision("UNN-1");
t.equal(sub, null);
});

test("general", function (t) {
Expand Down

0 comments on commit 16d72f2

Please sign in to comment.