Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

city

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

city - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

8

index.js

@@ -5,3 +5,2 @@ #!/usr/bin/env node

var version = require('./package.json').version;
var generator = require('./lib/generator.js');

@@ -19,4 +18,4 @@ commander

.option('-u --update','重新抓取原始数据')
.option('-k --key [value]','对象键名 name,children,code')
// .option('-t --type','输出类型,array/object')
// .option('-k --key','对象键名,name/zipcode/')
// .option('-f --flatten','扁平化输出')

@@ -38,5 +37,6 @@ // .option('-z --zipcode','包含邮编')

cmd:commander.cmd,
pretty:commander.pretty
pretty:commander.pretty,
keys:commander.key
};
generator.generate(options);
require('./lib/generator.js').generate(options);
}
exports.generate = function(options) {
var level = options.level || 3;
var cityData = require('./citydata.json');
var currLevel = 0;
if(!options.keys || typeof options.keys !== 'string' || !options.keys.length){
options.keys = ['name','children','code'];
}else{
options.keys = options.keys.split(',');
}
var fillRet = function(arr){

@@ -15,10 +19,9 @@ currLevel++;

}
var tmpObj = {
name:item.name
};
var tmpObj = {};
tmpObj[options.keys[0]] = item.name;
if(options.code && item.code){
tmpObj.code = item.code;
tmpObj[options.keys[2]] = item.code;
}
if(level > currLevel && item.sub){
tmpObj.sub = fillRet(item.sub);
if(level > currLevel && item.children){
tmpObj[options.keys[1]] = fillRet(item.children);
}

@@ -25,0 +28,0 @@ return tmpObj;

@@ -33,3 +33,3 @@ var restler = require('restler');

var overseasObj = {name:'海外'};
overseasObj.sub = overseasRawData.map(function(item){
overseasObj.children = overseasRawData.map(function(item){
return {

@@ -121,6 +121,6 @@ name:item

var parent = currItem[thisLevel - 2];
if(!parent.sub){
parent.sub = [];
if(!parent.children){
parent.children = [];
}
parent.sub.push(cityItem);
parent.children.push(cityItem);
currItem[thisLevel - 1] = cityItem;

@@ -127,0 +127,0 @@ }

{
"name": "city",
"description": "中国国家行政区划数据",
"version": "0.1.0",
"version": "0.1.1",
"author": "basecss <i@basecss.net>",

@@ -6,0 +6,0 @@ "contributors": [

city
========
一款用于生成行政区划联动数据的小工具
一款用于生成行政区划联动数据的小工具,如
```json
[{
"name":"北京市",
"children":[{
"name":"东城区"
},{
"name":"西城区"
}]
},{
"name":"天津市",
"children":[{
"name":"和平区"
}]
}]
```
### 特色

@@ -11,2 +27,3 @@

- 自由选择生成一级(省)、二级(省市)、三级(省市县)数据
- 可自定义数据对象键名(key)
- 支持输出JSON、原生js文件、AMD/CMD规范js文件

@@ -35,4 +52,5 @@ - 支持输出压缩后的代码及格式化后的代码

- `-l` `--level level` 输出指定级别行政区数据,取值1-3
- `-k` `--key name,children,code` 自定义输出格式中的对象键名(必须包含三个值)
- `-o` `--output fileName` 输出文件路径
- `-j` `--js varibleName` 以指定变量名输出js文件
- `-j` `--js varibleName` 以指定变量名输出js文件(配合`--output`选项写入文件)
- `-a` `--amd` 以AMD规范输出js文件

@@ -43,2 +61,7 @@ - `-m` `--cmd` 以CMD规范输出js文件

- `-c` `--code` 包含地区编码(身份证前6位)
- `-u` `--update` 重新抓取原始数据
- `-u` `--update` 重新抓取原始数据
### Todo
- [ ] 海外地区支持按拼音排序<https://github.com/TooBug/city/issues/1>
- [ ] 支持更多格式的输出<https://github.com/TooBug/city/issues/2>

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc