Skip to content

Commit

Permalink
Add assigned to export.countries
Browse files Browse the repository at this point in the history
This is so you can get a list of current countries without having to
filter everything yourself.

Particularly useful if you want a country picker for something that
needs current countries, like an address form.
  • Loading branch information
hackling committed Aug 9, 2017
1 parent 011dbb6 commit 01ce763
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ exports.countries = {
all: countriesAll,
};

var assignedCountries = []
_.each(countriesAll, function (country) {
if (country.status === 'assigned') {
assignedCountries.push(country)
}

// prefer assigned country codes over inactive ones
var exportedAlpha2 = exports.countries[country.alpha2];
if (!exportedAlpha2 || exportedAlpha2.status === 'deleted') {
Expand All @@ -30,6 +35,8 @@ _.each(countriesAll, function (country) {
}
});

exports.countries['assigned'] = assignedCountries

exports.currencies = {
all: currenciesAll,
};
Expand Down
15 changes: 15 additions & 0 deletions test/countries.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ describe('countries', function () {
});
});

describe('assigned', function () {
it('should only contain assigned countries', function () {
assert( _.isArray(countries.assigned) );
assert(countries.assigned.length < countries.all.length);

var exceptionalReservation = countries.SU
var deletedCode = countries.YD
var transitionalReservation = countries.BU

assert(countries.assigned.indexOf(exceptionalReservation) === -1)
assert(countries.assigned.indexOf(deletedCode) === -1)
assert(countries.assigned.indexOf(transitionalReservation) === -1)
});
});

describe('alpha2', function () {
it('should find USA', function () {
assert.equal( countries.BE.name, 'Belgium');
Expand Down

0 comments on commit 01ce763

Please sign in to comment.