+1
-0
@@ -20,2 +20,3 @@ import provinces from './data/provinces'; | ||
| // 台、港、澳 | ||
| return provId === '71' || provId === '81' || provId === '82'; | ||
@@ -22,0 +23,0 @@ }; |
+1
-1
| { | ||
| "name": "areacity", | ||
| "version": "1.0.0", | ||
| "version": "1.0.3", | ||
| "main": "index.js", | ||
@@ -5,0 +5,0 @@ "types": "index.d.ts", |
+85
-1
| # 简介 | ||
| > 作者:Perfumere<1061393710@qq.com>, 问题咨询请联系~ | ||
| > 作者:Perfumere, 问题咨询请联系~ | ||
| > 数据来源: [中华人民共和国民政部-民政数据-行政区编码](https://www.mca.gov.cn/mzsj/xzqh/2022/202201xzqh.html) | ||
| *数据的更新时间: 2023-12-18* | ||
| - 📦 内存存储、极速查询, 逻辑复杂度O(1) | ||
| - ⚡️ Speed: 4核2.7Ghz 单机qps: 10^7 级 | ||
| - ☔️ 无缓存, 基于实时查询 | ||
| - ✈️ 完美匹配腾讯地图adcode/city_code/乡镇/街道编码的逆解析过程 | ||
| ## 获取国内行政区信息(港澳除外) | ||
@@ -88,1 +97,76 @@ | ||
| ``` | ||
| ## 代码示例 | ||
| - 获取省/市/区县(县级市)/街道(乡镇) 列表 | ||
| ```ts | ||
| getProvinceList(); | ||
| // 传入北京的行政编码 [{id: number, name: 'string'}] | ||
| getCityList(11); | ||
| // 传入东城区行政编码 | ||
| getAreaList(110101); | ||
| // 传入山东的行政编码 [{id: number, name: 'string'}] | ||
| getCityList(37); | ||
| // 传入济南市行政编码 [{id: number, name: 'string'}] | ||
| getAreaList(3701); | ||
| // 传入历下区行政编码 [{id: number, name: 'string'}] | ||
| getTownList(370102); | ||
| ``` | ||
| - 判定是否为直辖市/省管县区/特别行政区 | ||
| ```ts | ||
| // 传长度 >= 2的有效数字字符串 | ||
| isDirectProvince('1101'); // 北京 true | ||
| // 传长度 >= 6的有效数字字符串 | ||
| isDirectArea('659001005'); // 新疆-石河子市-石河子市 true | ||
| // 传长度 >= 2的有效数字字符串 | ||
| isSpecialArea('1101'); // 北京 false | ||
| isSpecialArea('71'); // 台湾 true | ||
| isSpecialArea('81'); // 香港 true | ||
| isSpecialArea('82'); // 澳门 true | ||
| ``` | ||
| - 查找4级行政代码对应的名称 | ||
| ```ts | ||
| // 直辖市使用3级表示, 跳过 北京-(北京市)-东城区-朝阳门街道 | ||
| getNameFromCode('110101007'); | ||
| // 山东某地 | ||
| getNameFromCode('371728001'); | ||
| // 新疆省直管县(县级市), 编码的第3位、第4位对应9、0 | ||
| getNameFromCode('659001005'); | ||
| // 河北某地 | ||
| getNameFromCode('130102002'); | ||
| ``` | ||
| 执行结果如下: | ||
| ```ts | ||
| { | ||
| province: { id: 11, name: '北京' }, | ||
| city: { id: 110101, name: '东城区' }, | ||
| area: { id: 110101007, name: '朝阳门街道' }, | ||
| town: null | ||
| } | ||
| { | ||
| province: { id: 37, name: '山东' }, | ||
| city: { id: 3717, name: '菏泽市' }, | ||
| area: { id: 371728, name: '东明县' }, | ||
| town: { id: 371728001, name: '城关街道' } | ||
| } | ||
| { | ||
| province: { id: 65, name: '新疆' }, | ||
| city: { id: 659001, name: '石河子市' }, | ||
| area: { id: 659001000, name: '石河子市' }, | ||
| town: { id: 659001005, name: '东城街道' } | ||
| } | ||
| { | ||
| province: { id: 13, name: '河北' }, | ||
| city: { id: 1301, name: '石家庄市' }, | ||
| area: { id: 130102, name: '长安区' }, | ||
| town: { id: 130102002, name: '青园街道' } | ||
| } | ||
| ``` |
4171785
0.06%176310
0172
95.45%