Skip to content

Use country-regex instead of constants file #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"alpha-shape": "^1.0.0",
"arraytools": "^1.0.0",
"convex-hull": "^1.0.3",
"country-regex": "^1.0.0",
"d3": "^3.5.12",
"delaunay-triangulate": "^1.1.6",
"es6-promise": "^3.0.2",
Expand Down
268 changes: 0 additions & 268 deletions src/constants/country-name_to_iso3.js

This file was deleted.

17 changes: 7 additions & 10 deletions src/lib/geo_location_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,20 @@

'use strict';

var locationUtils = module.exports = {};
var countryRegex = require('country-regex');
var Lib = require('./');

var Plotly = require('../plotly');

// an hash object iso3 to regex string
var countryNameData = require('../constants/country-name_to_iso3');

// make list of all country iso3 ids from at runtime
var countryIds = Object.keys(countryNameData);
var countryIds = Object.keys(countryRegex);

var locationmodeToIdFinder = {
'ISO-3': Plotly.Lib.identity,
'USA-states': Plotly.Lib.identity,
'ISO-3': Lib.identity,
'USA-states': Lib.identity,
'country names': countryNameToISO3
};

locationUtils.locationToFeature = function(locationmode, location, features) {
exports.locationToFeature = function(locationmode, location, features) {
var locationId = getLocationId(locationmode, location);
var feature;

Expand All @@ -51,7 +48,7 @@ function countryNameToISO3(countryName) {

for(var i = 0; i < countryIds.length; i++) {
iso3 = countryIds[i];
regex = new RegExp(countryNameData[iso3]);
regex = new RegExp(countryRegex[iso3]);

if(regex.test(countryName.toLowerCase())) return iso3;
}
Expand Down