npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

china-address-parse

v1.2.1

Published

chinese address parse

Downloads

301

Readme

China's delivery address parse

本仓库 fork 自 ldwonday/zh-address-parse,在原版基础上进行了定制化改进,以 china-address-parse 为包名发布。

New Feature

v1.1.0 新增 cn-division 外部数据源支持,数据来源更可靠,更新更及时。 v1.1.1 Breaking changeprovinceCodecityCodecountyCode 类型由 number 改为 string(如 '11''1101''110105')。 v1.2.0 升级 [email protected],新增 nocode 独立入口(支持 china-address-parse/nocode)以减少打包体积,优化多版本构建导出。 v1.2.1 新增分机号解析支持(支持从地址提取 电话-分机号 格式,并可通过 telExtensionIn 选项配置分机号默认追加到姓名和地址末尾)。

Preview

Test page

Syntax

AddressParse(address[, [option|0|1]])

option可选参数属性列表

|参数名| 说明 | 类型 | 是否必填 | 默认值 | |----|----------|------------------------------------------------------------|------|-----| |type| 解析方式 | Number | 否 | 0 | |textFilter| 预过滤字段 | Array | 否 | [] | |nameMaxLength| 中文名最大长度 | Number | 否 | 4 | |dataSource| 数据源类型 | 'default' | 'cn-code' | 'cn-nocode' | 否 | 'default' | |includeCode| 是否返回行政区划编码 | Boolean | 否 | false | |extraGovData| 额外的省市县数据 | { city?: GovData[]; county: GovData[]; province: GovData[] } | 否 | - |

extraGovData 定义如下:

type GovData = {
    code: string;
    provinceCode?: string;
    cityCode?: string;
    name: string;
}

Usage

安装

npm i china-address-parse cn-division -s

基础使用

import AddressParse from 'china-address-parse'

// 默认使用内置数据源
const result = AddressParse('北京市朝阳区朝外大街19号华普大厦 张三 13800138000')
// { provinceName: '北京市', cityName: '北京市', countyName: '朝阳区', address: '朝外大街19号华普大厦', name: '张三', telNumber: '13800138000', postalCode: '' }

使用外部数据源 cn-division(推荐)

cn-division 提供更准确、更及时的行政区划数据。

import AddressParse from 'china-address-parse'

// 使用 cn-division 带编码数据源
const result = AddressParse('北京市朝阳区朝外大街19号华普大厦 张三 13800138000', {
    dataSource: 'cn-code',
    includeCode: true  // 返回行政区划编码
})
// {
//   provinceName: '北京市',
//   cityName: '北京市',
//   countyName: '朝阳区',
//   address: '朝外大街19号华普大厦',
//   name: '张三',
//   telNumber: '13800138000',
//   postalCode: '',
//   provinceCode: '11',
//   cityCode: '1101',
//   countyCode: '110105'
// }

// 使用 cn-division 不带编码数据源(体积更小)
const result2 = AddressParse('your address', {
    dataSource: 'cn-nocode'
})

使用 nocode 独立入口(体积最小)

如果不需要行政区划编码,可使用 nocode 入口,打包体积更小:

import AddressParse from 'china-address-parse/nocode'

const result = AddressParse('北京市朝阳区朝外大街19号华普大厦 张三 13800138000')

完整配置示例

import AddressParse from 'china-address-parse'

const options = {
  type: 0, // 解析方式:0-正则,1-树查找
  textFilter: [], // 预清洗的字段
  nameMaxLength: 4, // 中文名最大长度
  dataSource: 'cn-code', // 数据源:'default' | 'cn-code' | 'cn-nocode'
  includeCode: true, // 是否返回行政区划编码
  extraGovData: { // 额外的省市县数据
    city: [{ name: 'name', code: 'code', provinceCode: 'provinceCode' }],
    province: [{ name: 'name', code: 'code' }],
    county: [{ name: 'name', code: 'code', provinceCode: 'provinceCode', cityCode: 'cityCode' }]
  }
}
const parseResult = AddressParse('your address', options)

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, { type: 0, textFilter: ['电話', '電話', '聯系人'] })
            // The parseResult is an object contain { provinceName: '', name: '', cityName: '', countyName: '', address: '', telNumber: '', 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