Comparing version 0.1.2 to 1.0.0
76
index.js
@@ -1,50 +0,30 @@ | ||
#!/usr/bin/env node | ||
var commander = require('commander'); | ||
var version = require('./package.json').version; | ||
const axios = require('axios') | ||
const api = 'https://city-grabber.herokuapp.com/api/v1' | ||
commander | ||
.version(version) | ||
.option('-l --level <n>','输出指定级别行政区数据',parseInt) | ||
.option('-o --output [value]','输出文件') | ||
.option('-j --js [value]','以指定全局对象输出js文件') | ||
.option('-a --amd','以AMD规范输出js文件') | ||
.option('-m --cmd','以CMD规范输出js文件') | ||
.option('-p --pretty','格式化输出') | ||
.option('-s --overseas','包含海外地区') | ||
.option('-y --pinyin','输出pinyin') | ||
.option('-i --ignore [value]','忽略 \'省|市|区|地区|县\'') | ||
.option('-c --code','包含地区编码(身份证前6位)') | ||
.option('-u --update','重新抓取原始数据,或在citydata.json丢失的情况下使用') | ||
.option('-k --key [value]','对象键名 name,children,code,pinyin,顺序不能改变,例如n,s,c,p') | ||
.option('-f --flat [value]','扁平化输出,可以指定parentId参数名称') | ||
.option('--closed','地区树默认为关闭状态') | ||
.option('--father [value]','转出指定父节点的所有子节点,不含父节点') | ||
.option('-r --reverse','转出以子节点为根的树,便于倒查父节点') | ||
// .option('-t --type','输出类型,array/object') | ||
// .option('-z --zipcode','包含邮编') | ||
.parse(process.argv); | ||
if(commander.update){ | ||
require('./lib/update').update(); | ||
}else{ | ||
var options = { | ||
level:commander.level, | ||
code:commander.code, | ||
overseas:commander.overseas, | ||
output:commander.output, | ||
js:commander.js, | ||
amd:commander.amd, | ||
cmd:commander.cmd, | ||
pretty:commander.pretty, | ||
keys:commander.key, | ||
pinyin:commander.pinyin, | ||
ignore:commander.ignore, | ||
flat:commander.flat, | ||
closed:commander.closed, | ||
father:commander.father, | ||
reverse:commander.reverse | ||
}; | ||
require('./lib/generator.js').generate(options); | ||
} | ||
module.exports = { | ||
/** | ||
* This will return the City and Country from GPS coordinates | ||
* @param {Number} latitude The latitude value | ||
* @param {Number} longitude The longitude value | ||
* @param {Number | Null} size The city size value | ||
* @param {String} apiKey The API key | ||
* @return {Object} | ||
*/ | ||
get: async( latitude, longitude, size = null, apiKey ) => { | ||
const route = '/cities/nearest' | ||
let url = api + route + '?latitude=' + latitude + '&longitude=' + longitude | ||
if ( size !== null ) url += '&size=' + size | ||
const headers = {} | ||
if ( apiKey ) headers[ 'x-api-key' ] = apiKey | ||
const response = await axios(url, { | ||
method: 'GET', | ||
headers | ||
}).catch( e => { | ||
return Promise.reject( e.response.data ) | ||
}) | ||
return Promise.resolve( response.data ) | ||
} | ||
} |
{ | ||
"name": "city", | ||
"description": "中国国家行政区划数据", | ||
"version": "0.1.2", | ||
"author": "basecss <i@basecss.net>", | ||
"contributors": [ | ||
{ | ||
"name": "TooBug", | ||
"email": "i@toobug.net", | ||
"url": "http://www.toobug.net/" | ||
} | ||
], | ||
"dependencies": { | ||
"cheerio": "^0.17.0", | ||
"commander": "~2.2.0", | ||
"pinyin": "^2.6.2", | ||
"restler": "^3.2.2" | ||
}, | ||
"devDependencies": {}, | ||
"version": "1.0.0", | ||
"description": "TheCity API returns the city from a latitude and longitude using spatial mapping and data anlysis.", | ||
"main": "index.js", | ||
"bin": { | ||
"city": "index.js" | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/TooBug/city.git" | ||
}, | ||
"keywords": [ | ||
"city", | ||
"城市数据", | ||
"国家行政区划数据" | ||
"City", | ||
"Location", | ||
"Latitude", | ||
"Longitude", | ||
"Country", | ||
"GPS", | ||
"API" | ||
], | ||
"scripts": { | ||
"test": "echo no test" | ||
}, | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
"license": "MIT" | ||
"author": "WilliamDaniels1995@gmail.com", | ||
"license": "ISC", | ||
"dependencies": { | ||
"axios": "^0.21.1" | ||
} | ||
} |
149
README.md
@@ -1,96 +0,89 @@ | ||
city | ||
======== | ||
# City Grabber | ||
This is a wrapper for the City Grabber API which gets a city or closest city from a latitude and longitude. | ||
一款用于生成行政区划联动数据的小工具,如 | ||
City grabber uses an algorithim that utilises spatial mapping and sophisticated data analysis to give you a blazing fast and accurate response from over 150,000 cities from every country across the globe. | ||
```json | ||
[{ | ||
"name":"北京市", | ||
"children":[{ | ||
"name":"东城区" | ||
},{ | ||
"name":"西城区" | ||
}] | ||
},{ | ||
"name":"天津市", | ||
"children":[{ | ||
"name":"和平区" | ||
}] | ||
}] | ||
``` | ||
This package requires an API key which can be generated [Here](https://city.rocket-solutions.co.uk/key). | ||
### 特色 | ||
<img src="https://city.rocket-solutions.co.uk/img/logo2.6271016e.png" alt="logo" width="100" height="100" /> | ||
- 数据权威,来自国家统计局,每年更新 | ||
- 自由选择是否包含海外国家列表数据(来自维基百科) | ||
- 自由选择生成一级(省)、二级(省市)、三级(省市县)数据 | ||
- 可自定义数据对象键名(key) | ||
- 支持输出JSON、原生js文件、AMD/CMD规范js文件 | ||
- 支持输出压缩后的代码及格式化后的代码 | ||
- 支持输出地区代码(身份证前6位) | ||
- 支持拼音输出 | ||
- 支持自定义去除 省|市|区|地区|县 等后缀 | ||
## Installation | ||
`npm i city-grabber --save` | ||
## Usage | ||
### 使用方法 | ||
使用npm安装 | ||
```sh | ||
npm install -g city | ||
``` | ||
const cityGrabber = require( 'city-grabber' ) | ||
使用: | ||
```sh | ||
city | ||
//Using Promises | ||
cityGrabber.get( latitude, longitude, size, apiKey ) | ||
.then( response => { | ||
const { city, country, population, distance } = response | ||
}) | ||
.catch( e => console.log( e )) | ||
//Async await | ||
const { city, country, population, distance } = await cityGrabber.get( latitude, longitude, size, apiKey ) | ||
``` | ||
支持参数: | ||
## City Sizes | ||
| Size | Description | ||
| ----------- | -------------------------- | | ||
|`NULL` | This will search through every city of every size | ||
|`0` | Major Cities, 1m+ population | ||
|`1` | Big Cities, 250k - 1m population | ||
|`2` | Medium Cities, 10k - 250k population | ||
|`3` | Small cities, under 10k population | ||
- `-V` `--version` 输出版本号 | ||
- `-h` `--help` 输出菜单 | ||
- `-l` `--level level` 输出指定级别行政区数据,取值1-3 | ||
- `-k` `--key name,children,code` 自定义输出格式中的对象键名(必须包含三个值) | ||
- `-o` `--output fileName` 输出文件路径 | ||
- `-j` `--js varibleName` 以指定变量名输出js文件(配合`--output`选项写入文件) | ||
- `-a` `--amd` 以AMD规范输出js文件 | ||
- `-m` `--cmd` 以CMD规范输出js文件 | ||
- `-p` `--pretty` 格式化输出 | ||
- `-s` `--overseas` 包含海外地区 | ||
- `-c` `--code` 包含地区编码(身份证前6位) | ||
- `-u` `--update` 重新抓取原始数据 | ||
- `-y` `--pinyin` 输出pinyin | ||
- `-i` `--ignore '省|市|区|地区|县'` 忽略 省|市|区|地区|县 | ||
- `-k` `--key name,children,code,pinyin` 导出的键名(顺序不能改变,例如n,s,c,p) | ||
- `-f` `--flat 'parentId'` 扁平化输出,可以指定parentId参数名称 | ||
- `--closed` 地区树结点默认为关闭状态 | ||
- `--father` 转出指定父节点的所有子节点,不含父节点 | ||
- `-r` `--reserve` 转出以子节点为根的树,便于倒查父节点 | ||
## Demos | ||
示例: | ||
1. 嵌套方式列出所有地区,name改为n,children改为s,code改为c,并带上地区编码 | ||
```sh | ||
city -k n,s,c -o ./area.json -c | ||
``` | ||
cityGrabber.get( 35.4526317, 139.4546863, 0, apiKey ) | ||
//Response | ||
{ | ||
city: 'Yokohama'. | ||
country: 'JP', | ||
population: 3574443, | ||
distance: 17.823109463333083 | ||
} | ||
2. 平面方式列出所有地区,name改为n,children改为s,code改为c,parentId为p,并带上地区编码 | ||
```sh | ||
city -k n,s,c -o ./flat-area.json -c -f p | ||
cityGrabber.get( 42.34133262, -83.05576000, 1, apiKey ) | ||
//Response | ||
{ | ||
city: 'Detroit'. | ||
country: 'US', | ||
population: 677116, | ||
distance: 1.3745663787473823 | ||
} | ||
``` | ||
3. 倒树方式列出所有地区,子地区的code为key,val为父地区的{code:code, name:name}; | ||
```sh | ||
city -k n,s,c -o ./reverse-area.js -j reverse_area -r | ||
``` | ||
## Response | ||
| Property | Description | ||
| ----------- | -------------------- | | ||
|`city`| The city name. | ||
|`country` | The 2 letter country code which the city is located. | ||
|`population` | The last updated population of that city. | ||
|`distance` | The distance between the user and city center in km. | ||
## Errors | ||
| Status | Error | Description | ||
| ----------- | -------------------- | ---------------------------------- | | ||
|`422` |`API KEY NOT FOUND` | You need to pass your API key as a parameter. You can get one [Here](https://city.rocket-solutions.co.uk/key). | ||
|`422` |`INVALID API KEY` | Your key is invalid or badly formatted. | ||
|`422` |`INVALID SIZE` | Your size parameter is invalid. | ||
|`402` |`NO CREDITS REMAINING` | You need to purchase more credits for your key. You can do that [Here](https://city.rocket-solutions.co.uk/key).| Icons related to the business type | ||
|`422` |`INVALID COORDINATES` | Missing or invalid latitude/ longitude. | ||
### Todo | ||
## Documentation | ||
This is a brand new API launced in February 2021. Full Documentation will be here soon. | ||
- [ ] 海外地区支持按拼音排序<https://github.com/TooBug/city/issues/1> | ||
- [ ] 支持更多格式的输出<https://github.com/TooBug/city/issues/2> | ||
<s>Click [Here](https://city.rocket-solutions.co.uk/documentation) to see the full documentation</s> | ||
### Changelog | ||
2020.06.12 | ||
- 更新内置 `citydata.json` 数据 | ||
- 移除 `市辖区` 数据项 | ||
## Use cases | ||
- Location based social media | ||
- Dating services | ||
- Profiles | ||
- Location based games | ||
- Environmental evaluation | ||
- Map and directions services |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
2
1
4391
3
25
89
2
+ Addedaxios@^0.21.1
+ Addedaxios@0.21.4(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
- Removedcheerio@^0.17.0
- Removedcommander@~2.2.0
- Removedpinyin@^2.6.2
- Removedrestler@^3.2.2
- Removed@mapbox/node-pre-gyp@1.0.11(transitive)
- RemovedCSSselect@0.4.1(transitive)
- RemovedCSSwhat@0.4.7(transitive)
- Removedabbrev@1.1.1(transitive)
- Removedagent-base@6.0.2(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedaproba@2.0.0(transitive)
- Removedare-we-there-yet@2.0.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedcheerio@0.17.0(transitive)
- Removedchownr@2.0.0(transitive)
- Removedcolor-support@1.1.3(transitive)
- Removedcommander@1.1.12.2.0(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconsole-control-strings@1.1.0(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddebug@4.3.7(transitive)
- Removeddelegates@1.0.0(transitive)
- Removeddetect-libc@2.0.3(transitive)
- Removeddom-serializer@0.0.1(transitive)
- Removeddomelementtype@1.1.3(transitive)
- Removeddomhandler@2.2.1(transitive)
- Removeddomutils@1.4.31.5.1(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedentities@1.0.01.1.2(transitive)
- Removedfs-minipass@2.1.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedgauge@3.0.2(transitive)
- Removedglob@7.2.3(transitive)
- Removedhas-unicode@2.0.1(transitive)
- Removedhtmlparser2@3.7.3(transitive)
- Removedhttps-proxy-agent@5.0.1(transitive)
- Removediconv-lite@0.2.11(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedisarray@0.0.1(transitive)
- Removedkeypress@0.1.0(transitive)
- Removedlodash@2.4.2(transitive)
- Removedmake-dir@3.1.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedminipass@3.3.65.0.0(transitive)
- Removedminizlib@2.1.2(transitive)
- Removedmkdirp@1.0.4(transitive)
- Removedms@2.1.3(transitive)
- Removednode-addon-api@3.2.1(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removednodejieba@2.5.2(transitive)
- Removednopt@5.0.0(transitive)
- Removednpmlog@5.0.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpinyin@2.11.2(transitive)
- Removedqs@1.2.0(transitive)
- Removedreadable-stream@1.1.143.6.2(transitive)
- Removedrestler@3.4.0(transitive)
- Removedrimraf@3.0.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsax@0.5.8(transitive)
- Removedsemver@6.3.17.6.3(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstring_decoder@0.10.311.3.0(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedtar@6.2.1(transitive)
- Removedtr46@0.0.3(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)
- Removedwide-align@1.1.5(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedxml2js@0.4.0(transitive)
- Removedxmlbuilder@15.1.1(transitive)
- Removedyallist@4.0.0(transitive)
- Removedyaml@0.2.3(transitive)