Skip to content

Commit a54c39b

Browse files
committed
🎉 initial
0 parents  commit a54c39b

9 files changed

Lines changed: 354 additions & 0 deletions

File tree

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Thumbs.db
2+
.DS_Store
3+
4+
node_modules
5+
bower_components
6+
7+
npm-debug.log

.travis.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
notifications:
2+
email: false
3+
4+
# Quick boot options
5+
sudo: false
6+
cache:
7+
directories:
8+
- node_modules
9+
10+
# Ignore version tags
11+
branches:
12+
except:
13+
- /^v[0-9]/
14+
15+
# Language options
16+
language: node_js
17+
before_install:
18+
- if [[ `npm -v` != 3* ]]; then npm i -g npm@3; fi
19+
node_js:
20+
- 4
21+
before_script:
22+
- npm prune
23+
script:
24+
- npm run build
25+
- npm run test
26+
- npm run lint
27+
28+
# Npm publish options
29+
deploy:
30+
skip_cleanup: true # keep the devDependencies
31+
provider: npm
32+
email: i59naga@icloud.com
33+
api_key:
34+
secure: Y+nt75BAkBSshHgS/FCjC7BBmtadNyFmcT5PTEjFxneLpW5SBPe/58iUhxkt5xSDZbxr1l7TH+eOgROxmHx13OROuCUcWrK3m4tbHBbiaI3GcQ7hCEfpnqWeUF53seqDabikypttHcYmELJtW1H+il6U2U5YwPDrEuSOGhnmx1yoZOZ6DCXuLSi/JgLhCY9m7AuvckH40B/7kGMad58Df81EKZYM37/icuG85pWgCoJcPIV1XoF3KTl5T9rPn9pxLdx25xBB/P4tjJ7v+gKuiKiVBJTSpTtlJEQCba/1dWNH1q1/305cgJ/16PlMs0yENQxwVxtcyHpXoULHb0WnGf6Y3YsjG23N/b0GFtgC/lvH/+PBmvbinguu4vrSk53gxqPyZX2+vyvHAtcYN2cssVMe0D3RmPC95U24qeNZ3sqo6w8/C7dk+UjkaBs2/6dUxF0buUmE+iyOmCMQgSiphsGgoqtqCus/qt7vxs6LpIHl/AB+H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laKTUJzxaCgB1/pkThmZO25bP6Pxi7OnGSQ23K1OdKzXITOiAdQ4AtBq+Fi/ECjQNpT6o3IaiTfZ8Q/FgFb5izBLsbbALs7HFJ9loNqPhVaZJ8RUcEM1vRuYd4gjVoegzbsUwZYz7QYipDWVb9+TKsDUp76XLjNdMDlPG1V//YR09hkpvgIpW9+3lxn1aumrhYa1ULgxWGt685yRJHOUx0FBJmjjWbKRfl2rrxdAlMZ5xig9oJlGaay/16aqSAED/wdwQlIJKq1Jhg7mcEIBLoLHSPCeZ3mO0pafUBwWhPBclKJG4lA0HaWdeN0XLX0II7cWFG5Zj/8hjgq5OZrB5gx91PHZCsvvmRkoT3mr2blpfx3eFGDxkE02qQ+fjVAIOAuu6L5Ftab9g6SARo5H9m5dhKoRX8dvKaNlwMS+a9pkb470X3TNnTFF1QlrNsHQoJlQrflPJjAmbkd2hnq6nkR/03+YVslERXa7yOgS7oVx0EjDf2QG2s+ugoQAoXqeR0aVIqUL4H6uIWZQWj7SxU=
43+
44+
# Cloud testing
45+
after_deploy:
46+
- npm install
47+
- npm run setup
48+
- npm run test-cloud

.zuul.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# See: https://github.com/defunctzombie/zuul/wiki/zuul.yml
2+
ui: mocha-bdd
3+
browsers:
4+
- name: chrome
5+
version: latest
6+
- name: ie
7+
version: 9..latest
8+
- name: firefox
9+
version: latest
10+
- name: safari
11+
version: latest
12+
- name: iphone
13+
version: latest
14+
- name: ipad
15+
version: latest
16+
- name: android
17+
version: 4.1..latest
18+
19+
browserify:
20+
- transform: brfs

README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
`zipcode-ja`
2+
---
3+
4+
<p align="right">
5+
<a href="https://npmjs.org/package/zipcode-ja">
6+
<img src="https://img.shields.io/npm/v/zipcode-ja.svg?style=flat-square">
7+
</a>
8+
<a href="https://travis-ci.org/59naga/zipcode-ja">
9+
<img src="http://img.shields.io/travis/59naga/zipcode-ja.svg?style=flat-square">
10+
</a>
11+
<a href="https://codeclimate.com/github/59naga/zipcode-ja/coverage">
12+
<img src="https://img.shields.io/codeclimate/github/59naga/zipcode-ja.svg?style=flat-square">
13+
</a>
14+
<a href="https://codeclimate.com/github/59naga/zipcode-ja">
15+
<img src="https://img.shields.io/codeclimate/coverage/github/59naga/zipcode-ja.svg?style=flat-square">
16+
</a>
17+
<a href="https://gemnasium.com/59naga/zipcode-ja">
18+
<img src="https://img.shields.io/gemnasium/59naga/zipcode-ja.svg?style=flat-square">
19+
</a>
20+
</p>
21+
22+
<p align="center">
23+
<a href="https://saucelabs.com/u/59798">
24+
<img src="http://soysauce.berabou.me/u/59798/zipcode-ja.svg">
25+
</a>
26+
</p>
27+
28+
[日本郵便 平成28年5月31日更新 郵便番号データ](http://www.post.japanpost.jp/zipcode/dl/kogaki-zip.html) NodeJS / ブラウザ用 JavaScript
29+
30+
インストール
31+
---
32+
33+
**NodeJS**
34+
```bash
35+
npm install zipcode-ja --save
36+
```
37+
38+
```js
39+
import zipcodeJa from 'zipcode-ja';
40+
console.log(zipcodeJa.version, zipcodeJa.lastModified); // '0.0.0', '2016-05-31'
41+
```
42+
43+
**ブラウザ**[Download Latest](https://npmcdn.com/zipcode-ja/lib/zipcode-ja.js)
44+
```html
45+
<script src="https://npmcdn.com/zipcode-ja/lib/zipcode-ja.js"></script>
46+
<script>
47+
console.log(zipcodeJa.version, zipcodeJa.lastModified); // '0.0.0', '2016-05-31'
48+
</script>
49+
```
50+
51+
使用方法
52+
---
53+
54+
`zipcodeJa`は、一つの巨大なオブジェクトです。実在する住所をキーとして与えると、対応する住所を返します。
55+
56+
```js
57+
console.log(zipcodeJa['1000002']);
58+
// {
59+
// zipcode: '1000002',
60+
// zipcodeOld: '100',
61+
// jisX0402: '13101',
62+
// address: [
63+
// '東京都',
64+
// '千代田区',
65+
// '皇居外苑'
66+
// ],
67+
// ruby: [
68+
// 'とうきょうと',
69+
// 'ちよだく',
70+
// 'こうきょがいえん'
71+
// ],
72+
// status: [
73+
// 0,
74+
// 0,
75+
// 0,
76+
// 0,
77+
// 0,
78+
// 0
79+
// ]
80+
// }
81+
```
82+
83+
それぞれのプロパティは、元データである[郵便番号データの説明](http://www.post.japanpost.jp/zipcode/dl/readme.html)の情報に対応しています。
84+
85+
* `zipcode``郵便番号(7桁)`
86+
* `zipcodeOld``(旧)郵便番号(5桁)`
87+
* `jisX0402``全国地方公共団体コード(JIS X0401、X0402)`
88+
* `address``都道府県名/漢字`, `市区町村名/漢字`, `町域名/漢字`
89+
* `ruby``都道府県名/半角カタカナ`, `市区町村名/半角カタカナ`, `町域名/半角カタカナ`
90+
* `status`
91+
0. `一町域が二以上の郵便番号で表される場合の表示`
92+
1. `小字毎に番地が起番されている町域の表示`
93+
2. `丁目を有する町域の場合の表示`
94+
3. `一つの郵便番号で二以上の町域を表す場合の表示`
95+
4. `更新の表示`
96+
5. `変更理由`
97+
98+
注意事項として
99+
* `address``町域名`が「以下に掲載がない場合」を「」に置換
100+
* `ruby`は半角カタカナではなく、全角ひらがなに置換
101+
を行っています。これは、他のスクリプトから利用する際の手順を省略するための調整です。
102+
103+
他のライブラリとの差異
104+
---
105+
* [AjaxZip3/yubinbango](https://github.com/ajaxzip3/ajaxzip3.github.io#readme) と違い、DOM依存を行わない
106+
* [japan-postal-code](https://github.com/mzp/japan-postal-code#readme) と違い、コールバック関数を用いない
107+
108+
開発環境
109+
---
110+
下記が[グローバルインストール](https://github.com/creationix/nvm#readme)されていることが前提です。
111+
* NodeJS v6.2.1
112+
* Npm v3.9.3 (or [pnpm](https://github.com/rstacruz/pnpm))
113+
114+
```bash
115+
git clone https://github.com/59naga/zipcode-ja
116+
cd zipcode-ja
117+
npm install
118+
119+
npm test
120+
```
121+
122+
License
123+
---
124+
[MIT](http://59naga.mit-license.org/)

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var buffer = require('fs').readFileSync(__dirname + '/lib/zipcode-ja.json.gz');
2+
var inflate = require('pako').inflate;
3+
4+
module.exports = JSON.parse(inflate(buffer, {to: 'string'}));

lib/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

package.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"name": "zipcode-ja",
3+
"version": "0.0.0",
4+
"description": "zipcodes of japanpost.jp as static properties",
5+
"main": "index.js",
6+
"files": [
7+
"index.js",
8+
"lib/zipcode-ja.js",
9+
"lib/zipcode-ja.json",
10+
"lib/zipcode-ja.json.gz"
11+
],
12+
"dependencies": {
13+
"pako": "^1.0.1"
14+
},
15+
"scripts": {
16+
"prebuild": "node update.js",
17+
"build": "browserify -t brfs index.js -s zipcodeJa > lib/zipcode-ja.js",
18+
"start": "mocha test.js --watch",
19+
"test": "mocha test.js",
20+
"lint": "xo",
21+
"test-cloud": "zuul test.js",
22+
"test-local": "zuul test.js --local --ui mocha-bdd --local 59798 --open",
23+
"postversion": "git push --follow-tags && conventional-github-releaser -p atom -r 0"
24+
},
25+
"devDependencies": {
26+
"brfs": "^1.4.3",
27+
"browserify": "^13.0.1",
28+
"conventional-github-releaser": "^1.1.2",
29+
"fast-csv": "^2.0.0",
30+
"hanzen": "^0.0.0",
31+
"iconv-lite": "^0.4.13",
32+
"japanese": "^1.1.0",
33+
"mocha": "^2.5.3",
34+
"moment": "^2.13.0",
35+
"xo": "^0.15.1",
36+
"zuul": "^3.9.0"
37+
},
38+
"xo": {
39+
"env": "mocha",
40+
"space": 2,
41+
"rules": {
42+
"no-path-concat": 0
43+
}
44+
},
45+
"keywords": [
46+
"japanese",
47+
"zip",
48+
"ajaxzip"
49+
],
50+
"repository": {
51+
"type": "git",
52+
"url": "https://github.com/59naga/zipcode-ja.git"
53+
},
54+
"author": "59naga <i59naga@icloud.com> (http://berabou.me/)",
55+
"license": "MIT",
56+
"bugs": {
57+
"url": "https://github.com/59naga/zipcode-ja/issues"
58+
},
59+
"homepage": "https://github.com/59naga/zipcode-ja#readme"
60+
}

test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var assert = require('assert');
2+
var version = require('./package').version;
3+
var zipcodeJa = require('./');
4+
5+
it('ライブラリのバージョンを取得できるべき', function () {
6+
assert(zipcodeJa.version === version);
7+
});
8+
it('住所データの更新日時を取得できるべき', function () {
9+
assert(zipcodeJa.lastModified.match(/^\w{4}-\w{2}-\w{2}$/));
10+
});
11+
it('同期的に住所を取得できるべき', function () {
12+
assert.deepEqual(zipcodeJa['1000002'], {
13+
zipcode: '1000002',
14+
zipcodeOld: '100 ',
15+
jisX0402: '13101',
16+
address: [
17+
'東京都',
18+
'千代田区',
19+
'皇居外苑'
20+
],
21+
ruby: [
22+
'とうきょうと',
23+
'ちよだく',
24+
'こうきょがいえん'
25+
],
26+
status: [
27+
0,
28+
0,
29+
0,
30+
0,
31+
0,
32+
0
33+
]
34+
});
35+
});

update.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const execSync = require('child_process').execSync;
2+
const spawn = require('child_process').spawn;
3+
const writeFileSync = require('fs').writeFileSync;
4+
const gzipSync = require('zlib').gzipSync;
5+
const moment = require('moment');
6+
const csv = require('fast-csv');
7+
const decodeStream = require('iconv-lite').decodeStream;
8+
const hiraganize = require('japanese').hiraganize;
9+
const toZenkaku = require('hanzen').toZenkaku;
10+
const version = require('./package.json').version;
11+
12+
const filename = 'lib/zipcode-ja.json';
13+
const uri = 'http://www.post.japanpost.jp/zipcode/dl/kogaki/zip/ken_all.zip';
14+
15+
const date = new Date(execSync(`curl --head ${uri}`).toString().match(/Last-Modified: (.+)/)[1]);
16+
const lastModified = moment(date).format('YYYY-MM-DD');
17+
18+
const zipcodes = {};
19+
spawn(`curl ${uri} | bsdtar -xv -O`, {shell: true})
20+
.stdout.pipe(decodeStream('SJIS'))
21+
.pipe(csv())
22+
.on('data', (line) => {
23+
if (line.length === 0) {
24+
return;
25+
}
26+
const [
27+
jisX0402, zipcodeOld, zipcode,
28+
kanaTodofuken, kanaShikuchoson, kanaChoiki,
29+
todofuken, shikuchoson, choiki,
30+
...status
31+
] = line;
32+
const data = {
33+
zipcode,
34+
zipcodeOld,
35+
jisX0402,
36+
address: [
37+
todofuken,
38+
shikuchoson,
39+
choiki === '以下に掲載がない場合' ? '' : choiki
40+
],
41+
ruby: [
42+
hiraganize(toZenkaku(kanaTodofuken)),
43+
hiraganize(toZenkaku(kanaShikuchoson)),
44+
hiraganize(toZenkaku(kanaChoiki))
45+
],
46+
status: status.map(char => Number(char))
47+
};
48+
zipcodes[zipcode] = data;
49+
})
50+
.on('end', () => {
51+
const data = JSON.stringify(Object.assign({version, lastModified}, zipcodes));
52+
writeFileSync(`${filename}`, data);
53+
writeFileSync(`${filename}.gz`, gzipSync(data));
54+
});

0 commit comments

Comments
 (0)