Skip to content

Commit e158f33

Browse files
committed
Generate tree data
1 parent cb83101 commit e158f33

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
coverage/
33
lib/*.json
4+
*.log

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ data/
66
.gitmodules
77
.travis.yml
88
.npmignore
9+
*.log

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"scripts": {
2525
"test": "node_modules/.bin/mocha",
26+
"data": "node scripts/generate.js",
2627
"test-cov": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha --bail",
2728
"test-lcov": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha --report lcovonly --bail"
2829
}

scripts/generate.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,28 @@ function parse(text) {
1010

1111
lines.forEach(function(line) {
1212
var bits = line.split('\t');
13-
rv[bits[0]] = bits[1];
13+
var code = bits[0], name = bits[1];
14+
15+
var p1 = code.substr(0, 2);
16+
var p2 = code.substr(0, 4);
17+
if (/[1-9]0{4,5}$/.test(code)) {
18+
rv[p1] = {
19+
name: name,
20+
code: code,
21+
prefectures: {}
22+
};
23+
} else if (/[1-9]0{2,3}$/.test(code)) {
24+
rv[p1]['prefectures'][p2] = {
25+
name: name,
26+
code: code,
27+
counties: {}
28+
};
29+
} else {
30+
rv[p1]['prefectures'][p2]['counties'][code] = {
31+
name: name,
32+
code: code
33+
};
34+
}
1435
});
1536

1637
return rv;

0 commit comments

Comments
 (0)