Skip to content

Instantly share code, notes, and snippets.

@avimar
Last active September 15, 2016 04:20
Show Gist options
  • Save avimar/bcc7a8159d214c51b5496be5f5e14362 to your computer and use it in GitHub Desktop.
Save avimar/bcc7a8159d214c51b5496be5f5e14362 to your computer and use it in GitHub Desktop.
north-america-area-codes
var NorthAmerica=require('./NorthAmerica.json');
var fp = require('lodash/fp');
function getRegionForAreaCode(areaCode){
return fp.findKey(function(o) {
return o.includes(areaCode);
})(NorthAmerica);
}
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