Skip to content

Commit 30b9cc6

Browse files
committed
Merge pull request #461 from plotly/country-regex
Use country-regex instead of constants file
2 parents 0f9ea7f + 857265c commit 30b9cc6

File tree

3 files changed

+8
-278
lines changed

3 files changed

+8
-278
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"alpha-shape": "^1.0.0",
4949
"arraytools": "^1.0.0",
5050
"convex-hull": "^1.0.3",
51+
"country-regex": "^1.0.0",
5152
"d3": "^3.5.12",
5253
"delaunay-triangulate": "^1.1.6",
5354
"es6-promise": "^3.0.2",

src/constants/country-name_to_iso3.js

-268
This file was deleted.

src/lib/geo_location_utils.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@
99

1010
'use strict';
1111

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

14-
var Plotly = require('../plotly');
15-
16-
// an hash object iso3 to regex string
17-
var countryNameData = require('../constants/country-name_to_iso3');
1815

1916
// make list of all country iso3 ids from at runtime
20-
var countryIds = Object.keys(countryNameData);
17+
var countryIds = Object.keys(countryRegex);
2118

2219
var locationmodeToIdFinder = {
23-
'ISO-3': Plotly.Lib.identity,
24-
'USA-states': Plotly.Lib.identity,
20+
'ISO-3': Lib.identity,
21+
'USA-states': Lib.identity,
2522
'country names': countryNameToISO3
2623
};
2724

28-
locationUtils.locationToFeature = function(locationmode, location, features) {
25+
exports.locationToFeature = function(locationmode, location, features) {
2926
var locationId = getLocationId(locationmode, location);
3027
var feature;
3128

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

5249
for(var i = 0; i < countryIds.length; i++) {
5350
iso3 = countryIds[i];
54-
regex = new RegExp(countryNameData[iso3]);
51+
regex = new RegExp(countryRegex[iso3]);
5552

5653
if(regex.test(countryName.toLowerCase())) return iso3;
5754
}

0 commit comments

Comments
 (0)