更新记录
1.1.0(2019-12-05) 下载此版本
优化地址识别!
平台兼容性
China's delivery address parse
Test
Usage
import
import AddressParse from './dist/zh-address-parse.min.js'
// 参数0表示使用正则解析,1表示采用树查找
const parseResult = AddressParse('your address', 0)
// The parseResult is an object contain { province: '', name: '', city: '', area: '', detail: '', phone: '', postalCode: '' }
script引入
<script async defer src="./zh-address-parse.min.js"></script>
<script>
const parse = () => {
const onTextAreaBlur = (e) => {
const address = e.target.value
const parseResult = window.ZhAddressParse(address, 0)
// The parseResult is an object contain { province: '', name: '', city: '', area: '', detail: '', phone: '', postalCode: '' }
console.log(parseResult)
$('#result').empty();
$('#result').append(`<ul>${Object.entries(parseResult).map(([k, v]) => `<li>${k}:${v}</li>`).join('')}</ul>`)
}
$('#addressContent').bind('input propertychange', onTextAreaBlur)
$('#addressList li').on('click', (e) => {
$('#addressContent').val(e.target.innerText)
$('#addressContent')[0].dispatchEvent(new Event('input'));
})
}
parse()
</script>
Setup
Install dependencies
$ npm install
Development
Run the local webpack-dev-server with livereload and autocompile on http://localhost:8080/
$ npm run dev
Deployment
Build the current application
$ npm run build