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 🙏

© 2024 – Pkg Stats / Ryan Hefner

province-city-china

v8.5.8

Published

An util to query china province, city and district data. 中华人民共和国国家标准 GB/T 2260 行政区划代码。

Downloads

2,386

Readme

中华人民共和国行政区划代码

Github Issues Github Forks Github Stars Github Release no dependencies npm package

中华人民共和国行政区划(五级):省级、地级、县级、乡级和村级。来自中华人民共和国民政部,用于查询中国省,市和区数据的网站。

数据更新时间:2021/03/22 15:39:04 GMT+0800 (中国标准时间)

数据更新 Diff

安装

npm install province-city-china --save-dev

| 包名 | 说明 | 版本 | 大小 | | ---- | ---- | ---- | ---- | | province-city-china | 包含所有包内容 | npm package | - | | @province-city-china/country | 国家和地区代码列表 | npm package | | | @province-city-china/data | 总数据(省/地/县/乡) | npm package | | | @province-city-china/province | 省级(省/直辖市/特别行政区) | npm package | | | @province-city-china/city | 地级(城市) | npm package | | | @province-city-china/area | 县级(区县) | npm package | | | @province-city-china/town | 乡级(乡镇/街) | npm package | | | @province-city-china/level | 总数据(省/地/县/乡)层级数据 | npm package | | | @province-city-china/utils | 提供使用数据方法 | npm package | | | @province-city-china/types | 类型文件 | npm package | - | | @province-city-china/district-code | 国内长途电话区号 | npm package | - |

使用

const { data, province, city, area, town } = require('province-city-china/data');
  • data - 总数据(省/地/县/乡)
  • province - 省级(省/直辖市/特别行政区)
  • city - 地级(城市)
  • area - 县级(区县)
  • town - 乡级(乡镇/街)

所有数据

const provinces = require('province-city-china/dist/data.json');
// provinces 输出 ===>
[
  {"code":"110000","name":"北京市","province":"11","city":0,"area":0,"town":0},
  {"code":"110101","name":"东城区","province":"11","city":"01","area":"01","town":0},
  {"code":"110102","name":"西城区","province":"11","city":"01","area":"02","town":0},
  {"code":"110105","name":"朝阳区","province":"11","city":"01","area":"05","town":0},
  ....
]

规则:

  • province - 省级(省/直辖市/特别行政区) - city=0, area=0, town=0
  • city - 地级(城市) - area=0, town=0
  • area - 县级(区县) - town=0 其它不为 0
  • town - 乡级(乡镇/街) - 所有值不为 0

province 第一位表示:华北区1,东北区2,华东区3,中南区4,西南区5,西北区6。 如 湖北省 -> 424 开头,表示为 中南区

获取城市数据

const city = require('province-city-china/dist/city.json');
// city 输出 ===>
[
  {"code":"01","name":"石家庄市","province":"13"},
  {"code":"02","name":"唐山市","province":"13"},
  {"code":"03","name":"秦皇岛市","province":"13"},
  {"code":"04","name":"邯郸市","province":"13"},
  {"code":"05","name":"邢台市","province":"13"},
  ....
]

说明:

  • code - 城市代码
  • name - 城市名称
  • province - 省/直辖市/特别行政区代码

更多数据

可以通过 UNPKG 下载使用 CDN 资源: https://unpkg.com/province-city-china/dist/

| 文件列表 | JSON | CSV | SQL | CDN | | ---- | ---- | ---- | ---- | ---- | | 国家和地区代码列表(#13) | country.json (min) | country.csv | - | csv / json | | 总数据(省/地/县/乡) | data.json (min) | data.csv | data.sql | data.sql / csv / json | | 总数据(省/地/县/乡)层级数据 | level.json (min) | - | - | level.json | | 省级(省/直辖市/特别行政区) | province.json (min) | province.csv | - | province.json / csv | | 地级(城市) | city.json (min) | city.csv | - | city.json / csv | | 县级(区县) | area.json (min) | area.csv | - | area.json / csv | | 乡级(乡镇/街) | town.json (min) | town.csv | - | town.json / csv | | 县市区没有乡级数据 | not-found-town.json (min) | - | - | not-found-town.json | | 香港澳门<区>数据 | hongkong.json macau.json | hongkong.csv / macau.csv | - | hongkong.json (csv) macau.json (csv) | | 国内长途电话区号 | district-code.json | district-code.csv | - | district-code.json / csv |

更多 CDN 数据访问

  • https://unpkg.com/province-city-china/dist/city.json
  • https://raw.githack.com/uiwjs/province-city-china/gh-pages/city.json
  • https://cdn.statically.io/gh/uiwjs/province-city-china/gh-pages/city.json
✅ > <省>数据:34
  ✔ 数据保存: data/province.json
  ✔ 数据保存: data/province.csv
  ✔ 数据保存: data/province.min.json
✅ > <市>数据:337
  ✔ 数据保存: data/city.json
  ✔ 数据保存: data/city.csv
  ✔ 数据保存: data/city.min.json
✅ > <区>数据:2846
  ✔ 数据保存: data/area.json
  ✔ 数据保存: data/area.csv
  ✔ 数据保存: data/area.min.json
✅ > <省><市><区>总数据:3217
  ✔ 数据保存: data/data.json
  ✔ 数据保存: data/data.min.json
  ✔ 数据保存: data/data.csv
✅ > <省市区>层级数据:
  ✔ 数据保存: data/level.json
  ✔ 数据保存: data/level.min.json

国家和地区代码列表

country.json | country.min.json | country.csv

id=序号cnname=中文简称name=英文简称fullname=英文全称alpha2=两字母代码alpha3=三字母代码numeric=数字代码

[
  {
    "id": 1,
    "cnname": "阿富汗",
    "name": "Afghanistan",
    "fullname": "the Islamic Republic of Afghanistan",
    "alpha2": "AF",
    "alpha3": "AFG",
    "town": 4
  },
  {
    "id": 45,
    "cnname": "中国",
    "name": "China",
    "fullname": "the People's Republic of China",
    "alpha2": "CN",
    "alpha3": "CHN",
    "town": 156
  }
  // ...
]

压缩数据说明 country.min.json

id: 'i'
cnname: 'c'
name: 'n'
fullname: 'f'
alpha2: 'a2'
alpha3: 'a3'
numeric: 'r'

总数据(省/地/县/乡)

data.json | data.min.json | data.csv | data.sql

包含香港澳门<区>数据

[
  {
    "code": "110000",
    "name": "北京市",
    "province": "11",
    "city": 0,
    "area": 0,
    "town": 0
  },
  // ...
]

压缩数据说明 data.min.json

code: 'c'
name: 'n'
province: 'p'
city: 'y'
area: 'a'
town: 't'

省/地/县/乡层级数据

level.json | level.min.json

包含香港澳门<区>数据

[
  {
    "code": "420000",
    "name": "湖北省",
    "province": "42",
    "children": [
      {
        "code": "420100",
        "name": "武汉市",
        "province": "42",
        "city": "01",
        "children": [
          {
            "code": "420102",
            "name": "江岸区",
            "province": "42",
            "city": "01",
            "area": "02"
          },
          // ...
        ]
      }
      // ...
    ]
  }
  // ...
]

压缩数据说明 level.min.json

code: 'c'
name: 'n'
province: 'p'
city: 'y'
area: 'a'
children: 'd'

省级(省/直辖市/特别行政区)

province.json | province.min.json | province.csv

[
  {
    "code": "110000",
    "name": "北京市",
    "province": "11"
  },
  {
    "code": "120000",
    "name": "天津市",
    "province": "12"
  },
  // ...
]

压缩数据说明 level.min.json

code: 'c'
name: 'n'
province: 'p'
city: 'y'
area: 'a'
children: 'd'

地级(城市)

city.json | city.min.json | city.csv

[
  {
    "code": "130100",
    "name": "石家庄市",
    "province": "13",
    "city": "01"
  },
  // ...
]

压缩数据说明 city.min.json

code: 'c'
name: 'n'
province: 'p'
city: 'y'

县级(区县)

area.json | area.min.json | area.csv

[
  {
    "code": "110101",
    "name": "东城区",
    "province": "11",
    "city": "01",
    "area": "01"
  },
  // ...
]

压缩数据说明 city.min.json

code: 'c'
name: 'n'
province: 'p'
city: 'y'
area: 'a'

乡级(乡镇/街)

town.json | town.min.json | town.csv

[
  {
    "code": "110101001000",
    "name": "东华门街道",
    "province": "11",
    "city": "01",
    "area": "01",
    "town": "001000"
  },
  // ...
]

压缩数据说明 city.min.json

code: 'c'
name: 'n'
province: 'p'
city: 'y'
area: 'a'
town: 't'

县市区没有乡级数据

not-found-town.json | not-found-town.min.json

[
  {
    "code": "659010",
    "name": "胡杨河市",
    "province": "65",
    "city": "90",
    "area": "10",
    "town": 0
  },
  // ...
]

压缩数据说明 not-found-town.min.json

code: 'c'
name: 'n'
province: 'p'
city: 'y'
area: 'a'
town: 't'

香港澳门<区>数据

hongkong.json | hongkong.csv | macau.json | macau.csv

[
  {
    "code": "810002",
    "name": "湾仔区",
    "province": "81",
    "city": "00",
    "area": "02"
  },
  // ...
]

国内长途电话区号

district-code.json | district-code.csv

[
  { "name": "北京市", "code": "010" },
  // ...
]

脚本获取数据说明

① 获取<省><市>数据

中华人民共和国民政部-总省市区数据 上有完整的公开省市区数据。

获取省数据: http://www.mca.gov.cn/article/sj/xzqh/2020/20201201.html

② 校验四个<自治区直辖县级行政区划> & 以及其它数据

省市区数据来源于 ~~中华人民共和国民政部-总省市区数据~~,数据太老,自治区直辖县级行政区划 中有数据不存在,校验此数据。

🚧 注意:部分省份下面有 省直辖县级行政区划 如(湖北省河南省等),需要将此部分数据重新爬下来进行校验数据,如 [新疆维吾尔自治区-自治区直辖县级行政区划] 缺 新星市

为提升速度,通过 标记 校验哪些特殊省份有这类数据。

http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2021/<省>/<省><自治区直辖县级行政区划>.html

- 42 湖北省         -> # 自治区直辖县级行政区划
- 46 海南省         -> # 自治区直辖县级行政区划
- 65 新疆维吾尔自治区 -> # 自治区直辖县级行政区划
- 41 河南省         -> # 省直辖县级行政区划
# - 46 重庆市 -> 🚧 县
# - 23 黑龙江省 -> 🚧 大兴安岭地区

上面 4 个省区比较特殊的 自治区直辖县级行政区划,都有独立的 城市 代码,里面的数据拥有 代码,所以放到 数据中,例如:湖北省的 自治区直辖县级行政区划 编码为 90

[
  { code: '429004', name: '仙桃市', province: '42', city: '90' },
  { code: '429005', name: '潜江市', province: '42', city: '90' },
  { code: '429006', name: '天门市', province: '42', city: '90' },
  { code: '429021', name: '神农架林区', province: '42', city: '90' }
]

③ 处理四个<北京市|上海市|天津市|重庆市>直辖市数据

在 ① 步已获取直辖市数据:http://www.mca.gov.cn/article/sj/xzqh/2020/20201201.html

🚧 这里只是在生成层级数据的时候,需要特殊处理,因为它只有市区数据。

④ 分别存储<省><市><区>数据

分别存储 <省><市><区> 提供 csv, min.json, level.json, level.min.json 等数据。

⑤ 缓存<区>数据

此数据用于<街道>数据获取,避免中断从头爬数据。

⑥ 通过<街道>数据获取街道数据

□□□□□□  □□□  □□□
┈┈┬┈┈┈  ┈┬┈  ┈┬┈
  ╰┈┈┈┈┈┈┆┈┈┈┈┆┈┈┈┈→ ¹<省市区>代码
         ╰┈┈┈┈┆┈┈┈┈→ ²<乡镇街道>代码
              ╰┈┈┈┈→ ³<居民委员会>和<村民委员会>的代码

第²二段代码

  1. 001—099 表示街道的代码,应在本地区的范围内由小到大顺序编写;
  2. 100—199 表示镇的代码,应在本地区的范围内由小到大顺序编写;
  3. 200—399 表示乡的代码,应在本地区的范围内由小到大顺序编写;
  4. 400—599 表示政企合一单位的代码,应在本地区的范围内由小到大顺序编写。

第³三段代码

  1. 居民委员会的代码从001—199由小到大顺序编写;
  2. 村民委员会的代码从200-399由小到大顺序编写。

参考链接

Contributors

License

MIT