@spurreiter/geocoder
Advanced tools
Comparing version 1.2.0 to 1.2.1
{ | ||
"name": "@spurreiter/geocoder", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Node geocoding library, google maps, bing maps, mapquest, mapbox, here maps, arcgis, nominatim, ...", | ||
@@ -23,2 +23,6 @@ "keywords": [ | ||
], | ||
"homepage": "https://github.com/spurreiter/geocoder#readme", | ||
"bugs": { | ||
"url": "https://github.com/spurreiter/geocoder/issues" | ||
}, | ||
"repository": { | ||
@@ -61,3 +65,4 @@ "type": "git", | ||
"agentkeepalive": "^4.1.4", | ||
"got": "^11.8.2" | ||
"got": "^11.8.2", | ||
"i18n-iso-countries": "^6.7.0" | ||
}, | ||
@@ -64,0 +69,0 @@ "devDependencies": { |
import { AbstractGeocoder } from './abstract.js' | ||
import { HttpError } from '../utils/index.js' | ||
import { HttpError, countryCode, countryName } from '../utils/index.js' | ||
@@ -38,3 +38,8 @@ const undef = (s) => s === '' ? undefined : s | ||
const { apiKey, limit: maxLocations, language: langCode, ...params } = options | ||
const { | ||
apiKey, | ||
limit: maxLocations, | ||
language: langCode, | ||
...params | ||
} = options | ||
@@ -70,3 +75,4 @@ if (!apiKey) { | ||
address: query, | ||
outFields: 'AddNum,Addr_type,City,Country,LongLabel,Place_addr,PlaceName,Postal,Rank,Region,StName,StPreDir,StType,Type' | ||
outFields: | ||
'AddNum,Addr_type,City,Country,LongLabel,Place_addr,PlaceName,Postal,Rank,Region,StName,StPreDir,StType,Type' | ||
} | ||
@@ -98,3 +104,3 @@ | ||
} | ||
const results = result.candidates.map(this._formatResult) | ||
const results = result.candidates.map(this._formatResult.bind(this, params.langCode)) | ||
return this.wrapRaw(results, result) | ||
@@ -108,3 +114,9 @@ } | ||
async _reverse (query) { | ||
const { lat, lng, language: langCode, limit: maxLocations, ...other } = query | ||
const { | ||
lat, | ||
lng, | ||
language: langCode, | ||
limit: maxLocations, | ||
...other | ||
} = query | ||
const params = { | ||
@@ -132,3 +144,3 @@ ...this.params, | ||
} | ||
const results = [result].map(this._formatResultRev) | ||
const results = [result].map(this._formatResultRev.bind(this, params.langCode)) | ||
return this.wrapRaw(results, result) | ||
@@ -142,3 +154,3 @@ } | ||
*/ | ||
_formatResult (result) { | ||
_formatResult (language, result) { | ||
const { | ||
@@ -153,11 +165,18 @@ // address, | ||
const { | ||
AddNum, Addr_type, City, Country, LongLabel, PlaceName, Postal, Rank, Region, StName, StPreDir, StType, Type | ||
AddNum, | ||
Addr_type, | ||
City, | ||
Country, | ||
LongLabel, | ||
PlaceName, | ||
Postal, | ||
Rank, | ||
Region, | ||
StName, | ||
StPreDir, | ||
StType, | ||
Type | ||
} = attributes | ||
const { | ||
xmin, | ||
ymin, | ||
xmax, | ||
ymax | ||
} = extent | ||
const { xmin, ymin, xmax, ymax } = extent | ||
@@ -177,3 +196,4 @@ const extra = { | ||
longitude: location.x, | ||
countryCode: undef(Country), | ||
country: countryName(Country), | ||
countryCode: countryCode(undef(Country), language), | ||
state: undef(Region), | ||
@@ -195,7 +215,4 @@ city: undef(City), | ||
*/ | ||
_formatResultRev (result) { | ||
const { | ||
address = {}, | ||
location = {} | ||
} = result || {} | ||
_formatResultRev (language, result) { | ||
const { address = {}, location = {} } = result || {} | ||
@@ -225,7 +242,9 @@ const { | ||
longitude: location.x, | ||
countryCode: undef(CountryCode), | ||
country: countryName(CountryCode), | ||
countryCode: countryCode(undef(CountryCode), language), | ||
state: undef(Region), | ||
city: undef(City), | ||
zipcode: undef(Postal), | ||
streetName: Address && AddNum ? Address.replace(AddNum, '').trim() : undef(Address), | ||
streetName: | ||
Address && AddNum ? Address.replace(AddNum, '').trim() : undef(Address), | ||
streetNumber: undef(AddNum), | ||
@@ -232,0 +251,0 @@ extra |
import { AbstractGeocoder } from './abstract.js' | ||
import { HttpError } from '../utils/index.js' | ||
import { HttpError, countryName } from '../utils/index.js' | ||
@@ -130,3 +130,3 @@ /** | ||
longitude: location.lng, | ||
// country: undefined, | ||
country: countryName(address.country), | ||
countryCode: address.country, | ||
@@ -133,0 +133,0 @@ state: address.state, |
import { AbstractGeocoder } from './abstract.js' | ||
import { HttpError } from '../utils/index.js' | ||
import { HttpError, countryCode } from '../utils/index.js' | ||
@@ -119,3 +119,3 @@ /** | ||
country: address.countryName, | ||
countryCode: address.countryCode, | ||
countryCode: countryCode(address.countryCode), | ||
state: address.state, | ||
@@ -122,0 +122,0 @@ county: address.county, |
import { AbstractGeocoder } from './abstract.js' | ||
import { HttpError } from '../utils/index.js' | ||
import { HttpError, countryName } from '../utils/index.js' | ||
@@ -135,6 +135,13 @@ /** | ||
const formatted = { | ||
formattedAddress: [street, adminArea5, (adminArea3 + ' ' + postalCode).trim(), adminArea1].filter(Boolean).join(', '), | ||
formattedAddress: [ | ||
street, | ||
adminArea5, | ||
(adminArea3 + ' ' + postalCode).trim(), | ||
adminArea1 | ||
] | ||
.filter(Boolean) | ||
.join(', '), | ||
latitude: latLng.lat, | ||
longitude: latLng.lng, | ||
country: undefined, | ||
country: countryName(adminArea1 || undefined), | ||
countryCode: adminArea1 || undefined, | ||
@@ -141,0 +148,0 @@ state: adminArea3 || undefined, |
import { AbstractGeocoder } from './abstract.js' | ||
import { HttpError } from '../utils/index.js' | ||
import { HttpError, countryCode } from '../utils/index.js' | ||
@@ -109,3 +109,3 @@ /** | ||
country: properties.country, | ||
countryCode: properties.country_a, | ||
countryCode: countryCode(properties.country_a), | ||
state: properties.region, | ||
@@ -112,0 +112,0 @@ county: properties.country, |
@@ -1,2 +0,3 @@ | ||
export * from "./httperror.js"; | ||
export * from "./toUpperCase.js"; | ||
export * from "./httperror"; | ||
export * from "./isocode"; | ||
export * from "./toUpperCase"; |
export * from './httperror.js' | ||
export * from './isocode.js' | ||
export * from './toUpperCase.js' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
213746
95
7038
3
+ Addedi18n-iso-countries@^6.7.0
+ Addeddiacritics@1.3.0(transitive)
+ Addedi18n-iso-countries@6.8.0(transitive)