Skip to content

Commit

Permalink
Move states and countryCodes into bin.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Feb 26, 2019
1 parent 969a58e commit b2e05ad
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
7 changes: 4 additions & 3 deletions BrAddressForm.vue
Expand Up @@ -132,7 +132,6 @@
import {minLength, required} from 'vuelidate/lib/validators';
import rawCountryCodes from './countries';
import states from './states';
export default {
name: 'BrAddressForm',
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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: {
Expand Down
5 changes: 5 additions & 0 deletions bin/.eslintrc.js
@@ -0,0 +1,5 @@
module.exports = {
env: {
node: true
}
}
File renamed without changes.
28 changes: 13 additions & 15 deletions bin/index.js
Expand Up @@ -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';
Expand Down Expand Up @@ -37,48 +37,46 @@ 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];
}
}
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));
File renamed without changes.

0 comments on commit b2e05ad

Please sign in to comment.