Skip to content

Commit

Permalink
Change streetAddress to textarea.
Browse files Browse the repository at this point in the history
Remove additional trailing comma from .eslintcrc.js.

Move states and countryCodes into bin.
  • Loading branch information
aljones15 committed Feb 26, 2019
1 parent c5d4be9 commit 9b384eb
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
@@ -1,6 +1,6 @@
module.exports = {
env: {
browser: true,
browser: true
},
extends: [
'eslint-config-digitalbazaar/vue'
Expand Down
8 changes: 5 additions & 3 deletions BrAddressForm.vue
Expand Up @@ -6,6 +6,7 @@
v-model="streetAddress.value"
:float-label="streetAddress.label"
class="q-pa-sm q-mt-md"
type="textarea"
autocomplete="street-address"
@blur="$v.streetAddress.$touch"
@keyup="$v.streetAddress.$touch" />
Expand Down Expand Up @@ -131,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 @@ -218,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 @@ -262,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 9b384eb

Please sign in to comment.