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

@aurouscia/china-areas

v0.6.0

Published

2025中国行政区划数据(精确到区县)及工具函数

Readme

中国大陆地区行政区划数据

数据来源

民政部官网,上次更新于2025-04-25

安装

npm install @aurouscia/china-areas

数据结构约定

  • 直辖市下的市、区、县(例如上海市-静安区),均为该直辖市的直接子级(没有中间的“虚拟地级”)
  • 省直辖县(例如湖北省-仙桃市),均为所属省的直接子级(没有中间的“虚拟地级”)
  • 缺少港澳台地区的数据(仅有省级元素,没有子级)

json使用

/dist/json目录下为json文件,有扁平的和树状结构的两种版本,两种版本各有一个.min.json压缩版。

  • 扁平版本
    • code为六位行政区划代码
    • name为行政区划名称
  • 树状版本:若有子级,则有children属性为子级数组,否则没有children属性。
  • 压缩版:重命名了属性code -> cname -> nchildren -> d,且没有空格和换行符。

js/ts使用

本包的默认导出对象,即为所有行政区划的数组(扁平的,无树状结构)

import areas from '@aurouscia/china-areas'

其中每个元素均有两个属性:

  • code为六位行政区划代码
  • name为行政区划名称 如果使用ts,可引入该元素的类型定义:
import { Division } from '@aurouscia/china-areas'

如果需要树状结构,可以使用下文介绍的工具函数。

工具函数

import { xxxx } from '@aurouscia/china-areas'

getTopDivisions

获取所有的顶级行政区划,即省、直辖市、自治区

getDivisionChildren

获取指定行政区划代码的所有子级行政区划(错误的或没有子级的会返回空数组) 第二个参数为是否严格匹配(默认为false,即允许有错误)否则会在代码不存在时抛出异常。

getDivisionParent

获取指定行政区划代码的父级行政区划(错误的或没有父级的会返回undefined) 第二个参数为是否严格匹配(默认为false,即允许有错误)否则会在代码不存在时抛出异常。

matchDivisionByCode, matchDivisionByNames

根据行政区划六位代码或名称查找行政区划。
第一个参数为名称数组/代码字符串,第二个参数为是否严格匹配(默认为false,即允许有错误)。

  • 名称:字符串数组,例如['湖北省','武汉市','江岸区']
    • 如果是一般的省-市-区三级,则数组长度最多为3
    • 如果是直辖市、省直辖县、直筒子市,则数组长度最多为2
    • 如果是港澳台地区,则数组长度最多为1
    • 会从高到底匹配,如果某一级没有匹配项,则只会返回到其上一级,例如['湖北省','武昌区']会返回[{name:'湖北省',code:'420000'}]严格匹配时会抛出异常
  • 代码:六位字符串,例如'420102'
    • 如果匹配失败,则会返回空数组
    • 如果代码长度不是六位,则会返回空数组
    • 会从高到低匹配,如果某一级没有匹配项,则只会返回到其上一级,例如'428802'会返回[{name:'湖北省',code:'420000'}]严格匹配时会抛出异常
  • 返回值(如果没有抛出异常):从高到低的区划对象数组
    • 长度为3:[{省}, {市}, {区}]
    • 长度为2:[{省}, {市/省直辖县}][{直辖市}, {区}]
    • 长度为1:[{省}]
    • 长度为0:匹配失败

isFinalDivision

判断指定行政区划代码是否为最终级行政区划(即没有子级)

isExistingCode

判断指定行政区划代码(任意级别均可)是否存在

原版数据

raw数据在/dist/raw下,为官网有关页面全选复制(并补充三沙市的两个区的缺失)获得

源码

源代码中不包含数据,只包含生成器,如果需要:

  1. 按照generator/source/README.md中的说明准备数据源(必须)
  2. 运行npm run genTs生成包含数据的代码(必须)
  3. 运行npm run genJson生成json文件
  4. 运行npm test运行单元测试
  5. 运行npm run build打包

发现错误/过期

如果发现错误或过期,请在gitee上提issue,我会及时更新
https://gitee.com/au114514/au-npm-pkgs

许可证

MIT