Last active
September 15, 2016 04:20
-
-
Save avimar/bcc7a8159d214c51b5496be5f5e14362 to your computer and use it in GitHub Desktop.
north-america-area-codes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var NorthAmerica=require('./NorthAmerica.json'); | |
var fp = require('lodash/fp'); | |
function getRegionForAreaCode(areaCode){ | |
return fp.findKey(function(o) { | |
return o.includes(areaCode); | |
})(NorthAmerica); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tabletojson = require('tabletojson'); | |
var fp=require('lodash/fp'); | |
var fs=require('fs'); | |
var wikiArrayToObj = fp.flow( | |
fp.map(fp.values) | |
,fp.fromPairs | |
); | |
function saveNorthAmericaCodes(){ | |
var url = 'https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#United_States'; | |
return tabletojson.convertUrl(url) | |
.then(function(tablesAsJson) { | |
return tablesAsJson[0].concat(tablesAsJson[1]); | |
}) | |
.then(wikiArrayToObj) | |
.then(function(data){ | |
console.log(data) | |
fs.writeFile(__dirname+'/NorthAmerica.json', JSON.stringify(data)); | |
}) | |
}; | |
saveNorthAmericaCodes(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment