联合来文地址
基于一个惊人的作品 OpenCage 数据 这是Javascript的应用 这件事情.
这个库几乎可以格式化来自
开放街道地图 诺米纳蒂姆 API
输入 address 字段。 其他相容数据来源
例如 光子 可能也会被使用.
它能自动检测到这个国家
格式化自定义,但允许您使用 选择特定的国家
格式此外,它允许你 缩写常见的名字,
例如 Avenue 或者说 Road。 。 。 .
全世界的格式规格是 目前没有计划准备 面积有限的小型建筑.
安装和使用
节点
npm i @fragaria/address-formatter
// import addressFormatter from '@fragaria/address-formatter';
const addressFormatter = require('@fragaria/address-formatter');
// Basic examples
const formatted = addressFormatter.format({
"houseNumber": 301,
"road": "Hamilton Avenue",
"neighbourhood": "Crescent Park",
"city": "Palo Alto",
"postcode": 94303,
"county": "Santa Clara County",
"state": "California",
"country": "United States of America",
"countryCode": "US",
});
/*
301 Hamilton Avenue
Palo Alto, CA 94303
United States of America
*/
const formattedWithAppendedCountry = addressFormatter.format({
"houseNumber": 301,
"road": "Hamilton Avenue",
"neighbourhood": "Crescent Park",
"city": "Palo Alto",
"postcode": 94303,
"county": "Santa Clara County",
"state": "California",
"countryCode": "US",
}, {
appendCountry: true
});
/*
301 Hamilton Avenue
Palo Alto, CA 94303
United States of America
*/
// You can overwrite the country code incoming from the map service
const abbreviatedUkFormat = addressFormatter.format({
"houseNumber": 301,
"road": "Hamilton Avenue",
"neighbourhood": "Crescent Park",
"city": "Palo Alto",
"postcode": 94303,
"county": "Santa Clara County",
"state": "California",
"country": "United States of America",
"countryCode": "US",
}, {
abbreviate: true,
countryCode: 'UK'
});
/*
301 Hamilton Ave
Palo Alto
94303
USA
*/
// You can use a fallback to keep the library working when the country code is wrong
const fallbackCountryCode = addressFormatter.format({
"houseNumber": 301,
"road": "Hamilton Avenue",
"neighbourhood": "Crescent Park",
"city": "Palo Alto",
"postcode": 94303,
"county": "Santa Clara County",
"state": "California",
"country": "United States of America",
"countryCode": "yu",
}, {
abbreviate: true,
fallbackCountryCode: 'UK'
});
/*
301 Hamilton Ave
Palo Alto
94303
USA
*/
// You can get the address as a list of lines to make your formatting easier
const formattedAsLines = addressFormatter.format({
"houseNumber": 301,
"road": "Hamilton Avenue",
"neighbourhood": "Crescent Park",
"city": "Palo Alto",
"postcode": 94303,
"county": "Santa Clara County",
"state": "California",
"country": "United States of America",
"countryCode": "US",
}, {
output: 'array'
});
/*
[
'301 Hamilton Avenue',
'Palo Alto, CA 94303',
'United States of America'
]
*/
网页直接使用
<script type="text/javascript" src="https://unpkg.com/@fragaria/address-formatter@latest"></script>
<script type="text/javascript">
const formatted = window.addressFormatter.format({
"houseNumber": 301,
"road": "Hamilton Avenue",
"neighbourhood": "Crescent Park",
"city": "Palo Alto",
"postcode": 94303,
"county": "Santa Clara County",
"state": "California",
"country": "United States of America",
"countryCode": "US",
});
/*
301 Hamilton Avenue
Palo Alto, CA 94303
United States of America
*/
</script>
开发和测试
$ git clone [email protected]:fragaria/address-formatter.git
$ cd address-formatter
# Install the proper NodeJS
$ nvm install
# Download the /OpenCageData/address-formatting/ spec
$ npm run pull-submodules
# Install dependencies
$ npm install
# Generate JS-friendly spec
$ npm run prepare-templates
# Run the tests
$ npm test
释放
$ npm version X.Y.Z
$ git push origin master && git push origin vX.Y.Z
而CI服务器负责其他的
需要帮助
所有拉动请求都是绝对欢迎的. 如果有一个地址 格式化不良,直接向 原始仓库 最小本地化测试箱.
承认
得益于这些执行