From b2e05ad1e70c3f45f2241ee516ab66b743c5c139 Mon Sep 17 00:00:00 2001 From: andrewjones Date: Tue, 26 Feb 2019 13:14:28 -0600 Subject: [PATCH] Move states and countryCodes into bin. --- BrAddressForm.vue | 7 ++++--- bin/.eslintrc.js | 5 +++++ countryCodes.js => bin/countryCodes.js | 0 bin/index.js | 28 ++++++++++++-------------- states.js => bin/states.js | 0 5 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 bin/.eslintrc.js rename countryCodes.js => bin/countryCodes.js (100%) rename states.js => bin/states.js (100%) diff --git a/BrAddressForm.vue b/BrAddressForm.vue index a282adb..014fcbd 100644 --- a/BrAddressForm.vue +++ b/BrAddressForm.vue @@ -132,7 +132,6 @@ import {minLength, required} from 'vuelidate/lib/validators'; import rawCountryCodes from './countries'; -import states from './states'; export default { name: 'BrAddressForm', @@ -219,7 +218,9 @@ export default { computed: { regions() { if(!this.addressCountryExists) { - return states; + return rawCountryCodes + .find(c => c.iso === 'US') + .children.map(region => ({label: region, value: region})); } const prefix = this.addressCountry.value; const country = rawCountryCodes.find(c => c.iso === prefix); @@ -263,7 +264,7 @@ export default { this.countryOptions = rawCountryCodes.map(val => ({ label: val.name, value: val.iso - })).slice(0, 252); + })).slice(0, rawCountryCodes.length); const updatedLabels = _applyDefaultLabels({ data: this.value, labels: { diff --git a/bin/.eslintrc.js b/bin/.eslintrc.js new file mode 100644 index 0000000..696e9cb --- /dev/null +++ b/bin/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + env: { + node: true + } +} diff --git a/countryCodes.js b/bin/countryCodes.js similarity index 100% rename from countryCodes.js rename to bin/countryCodes.js diff --git a/bin/index.js b/bin/index.js index 82beb5c..c4b2843 100644 --- a/bin/index.js +++ b/bin/index.js @@ -4,7 +4,7 @@ const path = require('path'); const config = require('./config.json'); -const COUNTRIES='http://download.geonames.org/export/dump/countryInfo.txt'; +const COUNTRIES = 'http://download.geonames.org/export/dump/countryInfo.txt'; function requestChildren(id, username = 'demo') { const base = 'http://api.geonames.org/childrenJSON'; @@ -37,32 +37,30 @@ class Country { this.getChildren = this.getChildren.bind(this); } getChildren() { - if (this.area >= 1000000) { + if(this.area >= 1000000) { return requestChildren(this.geoname_id, config.username) .then(children => { - console.log('children', this.geoname_id, children); - if (children && children.geonames) { + if(children && children.geonames) { this.children = children.geonames.map(gn => gn.name); - } - return this; - }); + } + return this; + }); } return this; - } + } } - function parseCountries(text) { const lines = text.split('\n'); const notCommentedOut = lines.filter(l => !l.startsWith('#')); - const cells = notCommentedOut.map(l => l.split('\t')) + const cells = notCommentedOut.map(l => l.split('\t')); const countries = cells.map(c => new Country(c)); return Promise.all(countries.map(c => c.getChildren())); } function saveCountries(data) { const countries = data.map(country => { - for(key in country) { + for(const key in country) { if(!config.include.includes(key)) { delete country[key]; } @@ -70,15 +68,15 @@ function saveCountries(data) { return country; }); const filepath = path.join(__dirname, `${config.filename}`); - fs.writeFile(filepath, JSON.stringify(countries, null, 2),'utf-8', console.error); -}; - + fs.writeFile( + filepath, JSON.stringify(countries, null, 2), 'utf-8', console.error); +} function getCountries() { return fetch(COUNTRIES) .then(r => r.text()) .then(parseCountries) .then(saveCountries); -}; +} getCountries().then(c => console.log('countries', c)); diff --git a/states.js b/bin/states.js similarity index 100% rename from states.js rename to bin/states.js