Skip to content

Commit

Permalink
refactor/ changed import to require to support browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
hendurhance committed Aug 15, 2023
1 parent 4ca59eb commit fda749b
Show file tree
Hide file tree
Showing 257 changed files with 348 additions and 775,647 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ dist
.idea/

# Automation to Build Json Data
*.py
automate.py
minify.py
**/*.zip
backup
**/*.min.json
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@amplifiedhq/countries-atlas",
"version": "1.0.1",
"version": "1.0.2",
"description": "Uncover the world with a single lightweight library - countries, codes, currencies, flags, languages, cities, and more 🌎",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
26 changes: 26 additions & 0 deletions scripts/sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json
import os

# Check if the countries and states are in sync
countries_file = os.path.join(os.path.dirname(__file__), '../src/data/atlas.json')
states_path = os.path.join(os.path.dirname(__file__), '../src/data/countries')

with open(countries_file) as f:
countries = json.load(f)

for country in countries:
country_name = country['iso2']
country_file = os.path.join(states_path, country_name.lower() + '.json')
if not os.path.exists(country_file):
raise Exception('Missing file: ' + country_file)
print('All countries are in sync, count are : ' + str(len(countries)))

# Check if the flags are in sync
flags_path = os.path.join(os.path.dirname(__file__), '../flags/svg')
flags = os.listdir(flags_path)
for country in countries:
country_name = country['iso2'].lower() + '.svg'
if country_name not in flags:
raise Exception('Missing flag: ' + country_name)
print('All flags are in sync, count are : ' + str(len(flags)))
exit(0)
23 changes: 17 additions & 6 deletions src/__tests__/ValidatorAtlas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,25 @@ describe('ValidatorAtlas', () => {
});

describe('isValidStateCode', () => {
it('should return true if the state code is valid', async () => {
const isValid = await ValidatorAtlas.isValidStateCode('US', 'AZ');
expect(isValid).toBe(true);
// eslint-disable-next-line jest/no-commented-out-tests
// it('should return true if the state code is valid', async () => {
// const isValid = await ValidatorAtlas.isValidStateCode('US', 'AZ');
// expect(isValid).toBe(true);
// });

// eslint-disable-next-line jest/no-commented-out-tests
// it('should return false if the state code is invalid', async () => {
// const isValid = await ValidatorAtlas.isValidStateCode('US', 'XX');
// expect(isValid).toBe(false);
// });

it('should return true if the state code is valid', () => {
expect(ValidatorAtlas.isValidStateCode('US', 'AZ')).toBe(true);
});

it('should return false if the state code is invalid', async () => {
const isValid = await ValidatorAtlas.isValidStateCode('US', 'XX');
expect(isValid).toBe(false);
it('should return false if the state code is invalid', () => {
expect(ValidatorAtlas.isValidStateCode('US', 'XX')).toBe(false);
});
});

});
112 changes: 1 addition & 111 deletions src/data/countries/ad.json
Original file line number Diff line number Diff line change
@@ -1,111 +1 @@
{
"code": "AD",
"states": [
{
"name": "Andorra la Vella",
"state_code": "07",
"latitude": "42.50631740",
"longitude": "1.52183550",
"cities": [
{
"name": "Andorra la Vella",
"latitude": "42.50779000",
"longitude": "1.52109000"
}
]
},
{
"name": "Canillo",
"state_code": "02",
"latitude": "42.59782490",
"longitude": "1.65663770",
"cities": [
{
"name": "Canillo",
"latitude": "42.56760000",
"longitude": "1.59756000"
},
{
"name": "El Tarter",
"latitude": "42.57952000",
"longitude": "1.65362000"
}
]
},
{
"name": "Encamp",
"state_code": "03",
"latitude": "42.53597640",
"longitude": "1.58367730",
"cities": [
{
"name": "Encamp",
"latitude": "42.53474000",
"longitude": "1.58014000"
},
{
"name": "Pas de la Casa",
"latitude": "42.54277000",
"longitude": "1.73361000"
}
]
},
{
"name": "Escaldes-Engordany",
"state_code": "08",
"latitude": "42.49093790",
"longitude": "1.58869660",
"cities": [
{
"name": "les Escaldes",
"latitude": "42.50729000",
"longitude": "1.53414000"
}
]
},
{
"name": "La Massana",
"state_code": "04",
"latitude": "42.54562500",
"longitude": "1.51473920",
"cities": [
{
"name": "Arinsal",
"latitude": "42.57205000",
"longitude": "1.48453000"
},
{
"name": "la Massana",
"latitude": "42.54499000",
"longitude": "1.51483000"
}
]
},
{
"name": "Ordino",
"state_code": "05",
"latitude": "42.59944330",
"longitude": "1.54023270",
"cities": [
{
"name": "Ordino",
"latitude": "42.55623000",
"longitude": "1.53319000"
}
]
},
{
"name": "Sant Julià de Lòria",
"state_code": "06",
"latitude": "42.45296310",
"longitude": "1.49182350",
"cities": [
{
"name": "Sant Julià de Lòria",
"latitude": "42.46372000",
"longitude": "1.49129000"
}
]
}
]
}
{"code":"AD","states":[{"name":"Andorra la Vella","state_code":"07","latitude":"42.50631740","longitude":"1.52183550","cities":[{"name":"Andorra la Vella","latitude":"42.50779000","longitude":"1.52109000"}]},{"name":"Canillo","state_code":"02","latitude":"42.59782490","longitude":"1.65663770","cities":[{"name":"Canillo","latitude":"42.56760000","longitude":"1.59756000"},{"name":"El Tarter","latitude":"42.57952000","longitude":"1.65362000"}]},{"name":"Encamp","state_code":"03","latitude":"42.53597640","longitude":"1.58367730","cities":[{"name":"Encamp","latitude":"42.53474000","longitude":"1.58014000"},{"name":"Pas de la Casa","latitude":"42.54277000","longitude":"1.73361000"}]},{"name":"Escaldes-Engordany","state_code":"08","latitude":"42.49093790","longitude":"1.58869660","cities":[{"name":"les Escaldes","latitude":"42.50729000","longitude":"1.53414000"}]},{"name":"La Massana","state_code":"04","latitude":"42.54562500","longitude":"1.51473920","cities":[{"name":"Arinsal","latitude":"42.57205000","longitude":"1.48453000"},{"name":"la Massana","latitude":"42.54499000","longitude":"1.51483000"}]},{"name":"Ordino","state_code":"05","latitude":"42.59944330","longitude":"1.54023270","cities":[{"name":"Ordino","latitude":"42.55623000","longitude":"1.53319000"}]},{"name":"Sant Julià de Lòria","state_code":"06","latitude":"42.45296310","longitude":"1.49182350","cities":[{"name":"Sant Julià de Lòria","latitude":"42.46372000","longitude":"1.49129000"}]}]}
Loading

0 comments on commit fda749b

Please sign in to comment.