🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

china-location

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

china-location

Chinese Administrative Division information, 中国行政区划信息

2.1.0
latest
Source
npm
Version published
Weekly downloads
244
-1.21%
Maintainers
1
Weekly downloads
 
Created
Source

china-location

npm Building Status

JS Library for 中国行政区划信息
Simplify the usage of chinese administrative division data.

An React Component For this

Usage

npm install china-location --save or yarn add china-location

import list from 'china-location/dist/location.json';
import ChinaLocation from 'china-location';
//const ChinaLocation = require('china-location');
const location = new ChinaLocation(list);

//get default location
//{
//  province: {code: '110000', name: '北京市'},
//  city: {code: '110000', name: '北京市'},
//  district: {code: '110101', name: '东城区'}
//}
const defaultLocation = location.getCurrentAddress();

//change location
const newProvince = '320000';
const newCity = '320500';
const newDistrict = '320509';
//use select html tag to change different part
location.changeProvince(newProvince);
location.changeCity(newCity);
location.changeDistrict(newDistrict);
//or you can change location at one time
location.changeLocation(newProvince, newCity, newDistrict);
//{
//  province: {code: '320000', name: '江苏省'},
//  city: {code: '320500', name: '苏州市'},
//  district: {code: '320509', name: '吴江区'}
//}
const newLocation = location.getCurrentAddress();

Build your own location.json

In case the package is not packed with the latest location data, get/clone the data from mumuy/data_location(list.json), and clone this repo and:

git clone git@github.com:JasonBoy/china-location.git
cd china-location
npm run reformat -- /path/to/data_location/list.json
# and the location(.min).json will be output to ./dist dir

And in your project, you can:

import yourNewLocation from 'path/to/location.json';
import ChinaLocation from 'china-location';
const location = new ChinaLocation(yourNewLocation);
//...

LICENSE

MIT

Keywords

china

FAQs

Package last updated on 07 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts