Skip to content

Commit

Permalink
fix: sort overseas countries by pinyin
Browse files Browse the repository at this point in the history
also emit 中国 from oversea list
fix #1
  • Loading branch information
zhuangya committed Apr 27, 2015
1 parent 402f4ae commit fa4bc5e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/citydata.json

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions lib/update.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var restler = require('restler');
var cheerio = require('cheerio');
var pinyinSort = require('sort-by-pinyin');


exports.update = function(){
Expand Down Expand Up @@ -28,9 +29,14 @@ exports.update = function(){
return;
}

overseasRawData = pinyinSort(overseasRawData);

console.log('mixing overseas data to city data...');
var overseasObj = {name:'海外'};
overseasObj.children = overseasRawData.map(function(item){
overseasObj.children = overseasRawData.filter(function (item) {
if (item === '中国') return false;
return true;
}).map(function(item){
return {
name:item
};
Expand Down Expand Up @@ -151,4 +157,4 @@ function getOverseasRawData(url,callback){
}).on('fail',function(){
callback(new Error('fail'));
}).on('error',callback);
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"dependencies": {
"cheerio": "^0.17.0",
"commander": "~2.2.0",
"restler": "^3.2.2"
"restler": "^3.2.2",
"sort-by-pinyin": "^0.1.3"
},
"devDependencies": {},
"main": "index.js",
Expand Down

0 comments on commit fa4bc5e

Please sign in to comment.