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

lcn

v5.0.6

Published

中华人民共和国行政区划,省市区数据

Downloads

136

Readme

lcn

npm GitHub

中华人民共和国行政区划,省市区数据。

支持 umd es cjs 等模块格式。

各版本对应的数据源

| lcn 版本 | 数据源 | | --- | --- | | v5.x | 2022 年中华人民共和国行政区划代码 | | v1.x ~ v4.x | 2020 年 12 月中华人民共和国县以上行政区划代码 |

使用

安装

npm install lcn

or

yarn add lcn

示例

import { data, getPCA, getPC, parseAreaCode } from 'lcn';

// 获取内地省市区三级联动表单格式数据
const pca = getPCA({
  inland: true,
  fieldNames: { code: 'value', name: 'label' },
});
console.log(pca);

文档

  • 主要数据和方法

    • data - 全部省市区数据
    • getPCA - 获取省/市/区三级联动数据
    • getPC - 获取省/市二级联动数据
    • parseAreaCode - 解析地区码
  • 其他工具方法

    • isProvinceCode - 是否为省级码
    • isCityCode - 是否为市级码
    • isAreaCode - 是否为区级码
    • isInland - 是否为大陆内地区码
    • getProvinceCode - 获取 2 位省级编码
    • getCityCode - 获取 4 位市级编码
    • isCrownCountryCityCode - 是否为直辖市或直辖县的市级编码

data

全部省市区数据。

[
  { code: '110000', name: '北京市' },
  { code: '110100', name: '北京市' },
  { code: '110101', name: '东城区' },
  { code: '110102', name: '西城区' },
  // ...
];

getPCA(options)

  • options <object> 配置项
  • options.inland <boolean> 仅包含内地数据。默认为 false
  • options.fieldNames <{ code?: string; name?: string; children?: string; }> 自定义字段名
  • options.dataSource <{ code: string; name: string; }[]> 自定义数据源,默认 data
  • options.emptyChildrenValue <'array' | 'null' | 'none'> 子级为空时的值,默认 'array' 。array 表示为[],null 表示为 null,none 表示删除该子级。

获取省/市/区三级联动数据。

通过自定义字段名,可将数据成直接用于 antd element-ui 的表单组件中。

import { getPCA } from 'lcn';

const data1 = getPCA();
console.log(data1);

[
  {
    code: '110000',
    name: '北京市',
    children: [
      // ...
    ],
  },
  // ...
];

const data2 = getPCA({
  inland: true,
  fieldNames: { code: 'value', name: 'label' },
});
console.log(data2);

[
  {
    value: '110000',
    label: '北京市',
    children: [
      // ...
    ],
  },
  // ...
];

getPC(options)

获取省/市二级联动数据。参数及用法同 getPCA 方法。

parseAreaCode(areaCode, options?)

  • areaCode <string> 地区码
  • options <object> 配置项
  • options.dataSource <{ code: string; name: string; }[]> 自定义数据源,默认 data
  • options.ignoreCrownCountryCityName <boolean> 是否忽略直辖市或直辖县的市级名称,默认 false

解析地区码,返回一个元组 [省,市,区]

parseAreaCode('410102'); // => [{ code: '410000', name: '河南省' }, { code: '410100', name: '郑州市' }, { code: '410102', name: '中原区' }];
parseAreaCode('410100'); // => [{ code: '410000', name: '河南省' }, { code: '410100', name: '郑州市' }, null];
parseAreaCode('410000'); // => [{ code: '410000', name: '河南省' }, null, null];
parseAreaCode('000000'); // => [null, null, null];

注意,以下数据修正

1. 直辖市补充市级数据

  • 北京市(110000)
    • 北京市(110100)
  • 天津市(120000)
    • 天津市(120100)
  • 上海市(310000)
    • 上海市(310100)
  • 重庆市(500000)
    • 重庆市(500100)
    • 县(500200)

2. 部分省补充县级行政区划

3. 海南省三沙市补充区级数据

数据源自国家统计局 - 统计用区划和城乡划分代码

  • 海南省(460000)
    • 三沙市(460300)
      • 西沙群岛(460321)
      • 南沙群岛(460322)
      • 中沙群岛的岛礁及其海域(460323)

4. 以下几个特殊地级市,属于“不设区的市”

  • 广东省东莞市(441900)
  • 广东省中山市(442000)
  • 甘肃省嘉峪关市(620200)
  • 海南省儋州市(460400)

更多数据格式

如果在客户端中使用,并且没有用到全部数据,建议保存对应数据到本地。比如只用到省市联动数据,将 pc.json 保存本地即可。

| 文件 | 数据格式 | 描述 | | ---------------- | ------------------------------ | -------------------- | | pca.json | Array<{code, name, children?}> | 省/市/区三级联动数据 | | pc.json | Array<{code, name, children?}> | 省/市二级联动数据 | | data.json | Array<{code, name}> | 全部数据 | | provinces.json | Array<{code, name}> | 省份数据 | | cities.json | Array<{code, name}> | 市级数据 | | areas.json | Array<{code, name}> | 区级数据 |

参考