Socket
Socket
Sign inDemoInstall

addrtozip

Package Overview
Dependencies
103
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.1.0

db/.gitkeep

7

CHANGELOG.md
## Changelog
#### 1.0.6
_2014-05-23
* Add CHANGELOG
_2014-09-02
* Add support to get list of cities/areas
#### 1.0.6
_2014-05-23
* Add CHANGELOG
* Add README
#### 1.0.0
#### 1.0.0
_2014-05-23_
* Created initial version
/*jslint node: true, nomen: true, plusplus: true, stupid: true, vars: true, indent: 2 */
'use strict';
var _DB_PATH = 'db/zipcode.db';
var _CSV_PATH = 'db/201403.csv';
var _DB_PATH = __dirname + '/../db/zipcode.db';
var _ZIPCODE_CSV_PATH = __dirname + '/../src/201407.csv';
var _CITY_LIST_PATH = __dirname + '/../src/cityList.csv';
var _AREA_LIST_PATH = __dirname + '/../src/areaList.csv';

@@ -59,7 +61,27 @@ var async = require('async');

db.run('DROP TABLE IF EXISTS gradual;');
db.run('DROP TABLE IF EXISTS cities;');
db.run('DROP TABLE IF EXISTS areas;');
db.run('CREATE TABLE precise(addr_str TEXT, rule_str TEXT, zipcode TEXT, PRIMARY KEY (addr_str, rule_str))');
db.run('CREATE TABLE gradual(addr_str TEXT PRIMARY KEY, zipcode TEXT)');
db.run('CREATE TABLE cities(cityName TEXT PRIMARY KEY, zh_tw TEXT)');
db.run('CREATE TABLE areas(areaName TEXT, zh_tw TEXT, belongCity TEXT, PRIMARY KEY (areaName, belongCity))');
});
var lines = fs.readFileSync(_CSV_PATH, 'utf-8').trim().split('\n');
// Build cities list
var cities = fs.readFileSync(_CITY_LIST_PATH, 'utf8');
var lines = cities.trim().split('\n');
for(var i = 0, len = lines.length; i < len; i++) {
var line = lines[i].trim().split(',');
db.run('INSERT INTO cities VALUES (?, ?)', line[1], line[0]);
}
// Build areas list
var areas = fs.readFileSync(_AREA_LIST_PATH, 'utf8');
var lines = areas.trim().split('\n');
for(var i = 0, len = lines.length; i < len; i++) {
var line = lines[i].trim().split(',');
db.run('INSERT INTO areas VALUES (?, ?, ?)', line[1], line[0], line[2]);
}
var lines = fs.readFileSync(_ZIPCODE_CSV_PATH, 'utf-8').trim().split('\n');
var i = 0;

@@ -164,2 +186,2 @@ var fileLen = lines.length - 1;

}
);
);

@@ -8,4 +8,3 @@ /*jslint node: true, nomen: true, plusplus: true, stupid: true, vars: true, indent: 2 */

var path = require('path');
var _DB_PATH = path.join(__dirname, '../db/zipcode.db');
var _DB_PATH = __dirname + '/../db/zipcode.db';
var _NO = 1;

@@ -45,2 +44,12 @@ var _SUBNO = 2;

zipcode.find = function (addr, callback) {
// Check callback exist
if (typeof callback !== 'function') {
return;
}
// Check addr exist
if (!addr || (typeof addr !== 'string')) {
return callback({});
}
var addrOri = addr;

@@ -178,3 +187,36 @@ addr = address.normalize(addr);

// Get list of cities
zipcode.getCities = function(callback) {
// Check callback exist
if (typeof callback !== 'function') {
return;
}
db.all('SELECT * FROM cities', function (err, rows) {
callback(err, rows);
});
}
// Get list of areas by provided city
zipcode.getAreas = function(city, callback) {
// Check callback exist
if (typeof callback !== 'function') {
return;
}
// Check city exist
if (!city || (typeof city !== 'string')) {
return callback({});
}
if (!/\w/.test(city)) {
city = address.normalize(city);
}
db.all('SELECT T2.* FROM cities T1 JOIN areas T2 ON T2.belongCity = T1.cityName WHERE T1.cityName = ? OR T1.zh_tw = ?', city, city, function (err, rows) {
callback(err, rows);
});
}
module.exports = zipcode;
}());
{
"name": "addrtozip",
"version": "1.0.2",
"version": "1.1.0",
"description": "API for finding zipcode by address in Taiwan",

@@ -5,0 +5,0 @@ "main": "lib/zipcode.js",

@@ -40,3 +40,3 @@ ## API for finding zipcode in Taiwan [![NPM version](https://badge.fury.io/js/addrtozip.svg)](http://badge.fury.io/js/addrtozip) [![Build Status](https://drone.io/github.com/milly-chuang/addrtozip/status.png)](https://drone.io/github.com/milly-chuang/addrtozip/latest)

```json
{ zipcode: '11001', addr: '台北市信義區市府路45號' }
{ "zipcode": '11001', "addr": '台北市信義區市府路45號' }
```

@@ -65,3 +65,81 @@

## Get city list
Just get city list
```javascript
var addrtozip = require('addrtozip');
addrtozip.getCities(function (err, cities) {
/*
[ { cityName: 'Taipei City', zh_tw: '臺北市' },
{ cityName: 'Lienchiang County', zh_tw: '連江縣' },
{ cityName: 'Hsinchu City', zh_tw: '新竹市' },
{ cityName: 'New Taipei City', zh_tw: '新北市' },
{ cityName: 'Taoyuan County', zh_tw: '桃園縣' },
{ cityName: 'Miaoli County', zh_tw: '苗栗縣' },
{ cityName: 'Taichung City', zh_tw: '臺中市' },
{ cityName: 'Changhua County', zh_tw: '彰化縣' },
{ cityName: 'Nantou County', zh_tw: '南投縣' },
{ cityName: 'Chiayi City', zh_tw: '嘉義市' },
{ cityName: 'Chiayi County', zh_tw: '嘉義縣' },
{ cityName: 'Yunlin County', zh_tw: '雲林縣' },
{ cityName: 'Tainan City', zh_tw: '臺南市' },
{ cityName: 'Kaohsiung City', zh_tw: '高雄市' },
{ cityName: 'Penghu County', zh_tw: '澎湖縣' },
{ cityName: 'Kinmen County', zh_tw: '金門縣' },
{ cityName: 'Pingtung County', zh_tw: '屏東縣' },
{ cityName: 'Taitung County', zh_tw: '臺東縣' },
{ cityName: 'Hualien County', zh_tw: '花蓮縣' },
{ cityName: 'Keelung City', zh_tw: '基隆市' },
{ cityName: 'Hsinchu County', zh_tw: '新竹縣' },
{ cityName: 'Yilan County', zh_tw: '宜蘭縣' } ]
*/
})
```
## Get cityareas list
Just get cityareas list
```javascript
var addrtozip = require('addrtozip');
addrtozip.getAreas('台北市', function (err, areas) {
/*
[ { areaName: 'Zhongzheng Dist.',
zh_tw: '中正區',
belongCity: 'Taipei City' },
{ areaName: 'Datong Dist.',
zh_tw: '大同區',
belongCity: 'Taipei City' },
{ areaName: 'Zhongshan Dist.',
zh_tw: '中山區',
belongCity: 'Taipei City' },
{ areaName: 'Songshan Dist.',
zh_tw: '松山區',
belongCity: 'Taipei City' },
{ areaName: 'Da’an Dist.',
zh_tw: '大安區',
belongCity: 'Taipei City' },
{ areaName: 'Wanhua Dist.',
zh_tw: '萬華區',
belongCity: 'Taipei City' },
{ areaName: 'Xinyi Dist.',
zh_tw: '信義區',
belongCity: 'Taipei City' },
{ areaName: 'Shilin Dist.',
zh_tw: '士林區',
belongCity: 'Taipei City' },
{ areaName: 'Beitou Dist.',
zh_tw: '北投區',
belongCity: 'Taipei City' },
{ areaName: 'Neihu Dist.',
zh_tw: '內湖區',
belongCity: 'Taipei City' },
{ areaName: 'Nangang Dist.',
zh_tw: '南港區',
belongCity: 'Taipei City' },
{ areaName: 'Wenshan Dist.',
zh_tw: '文山區',
belongCity: 'Taipei City' } ]
*/
})
```
If any adress is legal, but return wrong zipcode.
Please let me know. Thanks.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc