From 01ce7638a2e9284d11c648891aff564958562773 Mon Sep 17 00:00:00 2001 From: Nick Chmielewski Date: Wed, 9 Aug 2017 17:16:45 +1000 Subject: [PATCH] Add assigned to export.countries 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. --- index.js | 7 +++++++ test/countries.js | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/index.js b/index.js index ce5ffd8..2702c54 100644 --- a/index.js +++ b/index.js @@ -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') { @@ -30,6 +35,8 @@ _.each(countriesAll, function (country) { } }); +exports.countries['assigned'] = assignedCountries + exports.currencies = { all: currenciesAll, }; diff --git a/test/countries.js b/test/countries.js index b90e1fb..6da15c8 100644 --- a/test/countries.js +++ b/test/countries.js @@ -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');