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

region-tree-data

v1.0.1

Published

`npm install region-tree-data` <br> 或 <br> `yarn add region-tree-data`

Downloads

9

Readme

region-tree-data

region-tree-data 最新中国区域编码级联数据

安装

npm install region-tree-data yarn add region-tree-data

使用

参照element-china-area-data

import {setData, getByArea, provinceAndCityData, regionData, provinceAndCityDataPlus, regionDataPlus, CodeToText, TextToCode } from 'region-tree-data'

let {setData, getByArea, provinceAndCityData, regionData, provinceAndCityDataPlus, regionDataPlus, CodeToText, TextToCode } = require('region-tree-data')
  1. provinceAndCityData是省市二级联动数据(不带“全部”选项)
  2. regionData是省市区三级联动数据(不带“全部”选项)
  3. provinceAndCityDataPlus是省市区三级联动数据(带“全部”选项)
  4. regionDataPlus是省市区三级联动数据(带“全部”选项)
  5. "全部"选项绑定的value是空字符串""
  6. CodeToText是个大对象,属性是区域码,属性值是汉字 用法例如:CodeToText['110000']输出北京市
  7. TextToCode是个大对象,属性是汉字,属性值是区域码 用法例如:TextToCode['北京市'].code输出110000,TextToCode['北京市']['市辖区'].code输出110100,TextToCode['北京市']['市辖区']['朝阳区'].code输出110105

在element-china-area-data基础上新增两个配置:

1.setData是自定义数据来源。 参照格式:

 var REGION_DATA = [{ "value": "110000","label": "北京市", "children": [{ "value": "110100", "label": "市辖区",  "children": [{"value": "110101", "label": "东城区"}]}]}]

用法:

import {setData, getByArea, provinceAndCityData, regionData, provinceAndCityDataPlus, regionDataPlus, CodeToText, TextToCode } from 'region-tree-data'
setData(REGION_DATA)
console.log('regionData',regionData)
// regionData [{ "value": "110000","label": "北京市", "children": [{ "value": "110100", "label": "市辖区",  "children": [{"value": "110101", "label": "东城区"}]}]}]

// 说明: setData之后所有对象获取到的值包括getByArea都是setData自定义数据之后的值

2.getByArea是获取任意层级数的数据

/**
* area :number 需要获取的层级数,超过数据层级则获取所有的数据 
**/
getByArea(area)

用法:

import {setData, getByArea, provinceAndCityData, regionData, provinceAndCityDataPlus, regionDataPlus, CodeToText, TextToCode } from 'region-tree-data'
setData(REGION_DATA)
console.log('regionData',getByArea(1))
// regionData [{ "value": "110000","label": "北京市"}]
console.log('regionData',getByArea(2))
// regionData [{ "value": "110000","label": "北京市", "children": [{ "value": "110100", "label": "市辖区"}]}]

数据来源

我爬取的 国家统计局最新(2019)中国省市区县三级行政区划代码(需要5级省市区县乡镇行政区划代码的童鞋同样可以从这里获取)