Socket
Socket
Sign inDemoInstall

@spurreiter/geocoder

Package Overview
Dependencies
35
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.0 to 1.4.1

lib/utils/isType.cjs

39

package.json
{
"name": "@spurreiter/geocoder",
"version": "1.4.0",
"version": "1.4.1",
"description": "Node geocoding library, google maps, bing maps, mapquest, mapbox, here maps, arcgis, nominatim, ...",

@@ -50,9 +50,8 @@ "keywords": [

"scripts": {
"all": "npm-run-all clean test build lint typings",
"clean": "rimraf typings coverage lib",
"lint": "eslint --fix \"**/*.js\"",
"all": "npm-run-all clean test build lint types",
"clean": "rimraf types coverage lib",
"lint": "eslint --fix --ext js .",
"build": "rollup -c",
"test": "c8 mocha",
"typings": "tsc src/**/*.d.ts src/*.d.ts src/**/*.js src/*.js --declaration --allowJs --emitDeclarationOnly --outDir typings",
"prepublishOnly": "npm run all"
"types": "rimraf types; tsc --emitDeclarationOnly true --noEmitOnError && cp src/*.d.ts types"
},

@@ -64,24 +63,24 @@ "mocha": {

"dependencies": {
"agentkeepalive": "^4.1.4",
"got": "^11.8.2",
"i18n-iso-countries": "^6.7.0"
"agentkeepalive": "^4.2.0",
"got": "^11.8.3",
"i18n-iso-countries": "^7.2.0"
},
"devDependencies": {
"@types/node": "^15.6.1",
"c8": "^7.7.2",
"dotenv": "^10.0.0",
"eslint": "^7.27.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.23.3",
"@types/node": "^16.11.21",
"c8": "^7.11.0",
"dotenv": "^15.0.0",
"eslint": "^7.32.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.3.1",
"mocha": "^8.4.0",
"mocha": "^9.2.0",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2",
"rollup": "^2.50.3",
"sinon": "^10.0.0",
"typescript": "^4.3.2"
"rollup": "^2.66.1",
"sinon": "^13.0.0",
"typescript": "^4.5.5"
},
"engines": {
"node": ">=12"
"node": ">=14"
},

@@ -88,0 +87,0 @@ "publishConfig": {

import got from 'got'
// @ts-ignore
import HttpAgent from 'agentkeepalive'
import { isNumber } from './utils/index.js'
const { HttpsAgent } = HttpAgent
/** @typedef {import('./types').AdapterOptions} AdapterOptions */
/** @typedef {import('./types').fetchAdapterFn} fetchAdapterFn */
const USER_AGENT = 'user-agent'

@@ -14,2 +19,6 @@

/**
* @param {AdapterOptions} [opts]
* @returns {fetchAdapterFn}
*/
export function fetchAdapter (opts) {

@@ -34,2 +43,3 @@ const globalOpts = {

if (typeof url === 'object') {
// @ts-ignore
const { url: _url, ...other } = url

@@ -42,4 +52,13 @@ url = _url

const opts = { ...globalOpts, ...options, headers }
if (isNumber(opts.timeout)) {
opts.timeout = { request: opts.timeout }
}
if (isNumber(opts.retry)) {
opts.retry = { limit: opts.retry }
}
// console.log(url, opts)
// @ts-ignore
return got(url, opts)
// @ts-ignore
.then((res) => new Response(res))

@@ -50,4 +69,12 @@ // .then(logger)

class Response {
constructor ({ statusCode, statusMessage, redirectUrls, headers, body }) {
export class Response {
/**
* @param {object} param0
* @param {number} param0.statusCode
* @param {string} param0.statusMessage
* @param {any[]} [param0.redirectUrls]
* @param {object} param0.headers
* @param {object} param0.body
*/
constructor ({ statusCode, statusMessage, redirectUrls, headers, body, ...others }) {
this.status = statusCode

@@ -54,0 +81,0 @@ this.statusText = statusMessage

import { CircuitBreaker } from './circuitbreaker.js'
/** @typedef {import('./geocoder/abstract').AbstractGeocoder} AbstractGeocoder */
/** @typedef {import('./types').CascadeOptions} CascadeOptions */
/** @typedef {import('./types').ForwardQuery} ForwardQuery */
/** @typedef {import('./types').ReverseQuery} ReverseQuery */
/** @typedef {import('./types').GeocoderResult} GeocoderResult */
export class Cascade {
/**
* @param {AbstractGeocoder[]} geocoders
* @param {CascadeOptions} options
*/
constructor (geocoders, options = {}) {

@@ -28,2 +38,6 @@ const { addProvider = true, ...options1 } = options

/**
* @param {ForwardQuery} query
* @returns {Promise<GeocoderResult[]>}
*/
async forward (query) {

@@ -33,2 +47,6 @@ return this._method(query, 'forward')

/**
* @param {ReverseQuery} query
* @returns {Promise<GeocoderResult[]>}
*/
async reverse (query) {

@@ -35,0 +53,0 @@ return this._method(query, 'reverse')

@@ -0,2 +1,15 @@

/** @typedef {import('./geocoder/abstract').AbstractGeocoder} AbstractGeocoder */
/** @typedef {import('./types').CircuitBreakerError} CircuitBreakerError */
/** @typedef {import('./types').CircuitBreakerOptions} CircuitBreakerOptions */
/** @typedef {import('./types').ForwardQuery} ForwardQuery */
/** @typedef {import('./types').ReverseQuery} ReverseQuery */
/** @typedef {import('./types').GeocoderResult} GeocoderResult */
/**
* @param {string} provider
* @returns {CircuitBreakerError}
*/
function CircuitBreakerError (provider = '') {
/** @type {CircuitBreakerError} */
// @ts-ignore
const err = new Error(`${provider} is temporarily offline`)

@@ -10,2 +23,6 @@ err.status = 429

export class CircuitBreaker {
/**
* @param {AbstractGeocoder} geocoder
* @param {CircuitBreakerOptions} param1
*/
constructor (geocoder, { timeout, excludeStatusCode } = {}) {

@@ -21,3 +38,2 @@ this.geocoder = geocoder

* @private
* @returns
*/

@@ -30,3 +46,3 @@ _checkOffline () {

}
throw new CircuitBreakerError(this.geocoder.name)
throw CircuitBreakerError(this.geocoder.name)
}

@@ -37,3 +53,2 @@ }

* @private
* @returns
*/

@@ -47,2 +62,6 @@ _turnOff (status) {

/**
* @param {ForwardQuery} query
* @returns {Promise<GeocoderResult[]>}
*/
async forward (query) {

@@ -52,3 +71,3 @@ this._checkOffline()

return await this.geocoder.forward(query)
} catch (err) {
} catch (/** @type {any} */ err) {
this._turnOff(err.response?.status || err.status)

@@ -59,2 +78,6 @@ throw err

/**
* @param {ReverseQuery} query
* @returns {Promise<GeocoderResult[]>}
*/
async reverse (query) {

@@ -64,3 +87,3 @@ this._checkOffline()

return await this.geocoder.reverse(query)
} catch (err) {
} catch (/** @type {any} */ err) {
this._turnOff(err.response?.status)

@@ -67,0 +90,0 @@ throw err

import { CircuitBreaker } from './circuitbreaker.js'
/** @typedef {import('./geocoder/abstract').AbstractGeocoder} AbstractGeocoder */
/** @typedef {import('./types').CombineOptions} CombineOptions */
/** @typedef {import('./types').ForwardQuery} ForwardQuery */
/** @typedef {import('./types').ReverseQuery} ReverseQuery */
/** @typedef {import('./types').GeocoderResult} GeocoderResult */
export class Combine {
/**
* @param {AbstractGeocoder[]} geocoders
* @param {CombineOptions} options
*/
constructor (geocoders, options = {}) {

@@ -10,2 +20,5 @@ const { addProvider = true, ...options1 } = options

/**
* @private
*/
async _method (query, method) {

@@ -16,2 +29,3 @@ const allResponses = await Promise.allSettled(

// @ts-ignore
return allResponses.reduce((a, { status, value }, i) => {

@@ -22,2 +36,3 @@ if (status === 'fulfilled' && value.length) {

if (this.addProvider) result.provider = provider
// @ts-ignore
a.push(result)

@@ -30,2 +45,6 @@ })

/**
* @param {ForwardQuery} query
* @returns {Promise<GeocoderResult[]>}
*/
async forward (query) {

@@ -35,2 +54,6 @@ return this._method(query, 'forward')

/**
* @param {ReverseQuery} query
* @returns {Promise<GeocoderResult[]>}
*/
async reverse (query) {

@@ -37,0 +60,0 @@ return this._method(query, 'reverse')

@@ -0,8 +1,18 @@

/** @typedef {import('../types').GeocoderResult} GeocoderResult */
/** @typedef {import('../types').GeoJsonFeature} GeoJsonFeature */
/** @typedef {import('../types').GeoJsonFeatureCollection} GeoJsonFeatureCollection */
/**
* @see https://github.com/geocoders/geocodejson-spec
* @see https://datatracker.ietf.org/doc/html/rfc7946
* @param {GeoJsonFeature[]} features
* @param {object} [param1]
* @param {string} [param1.license]
* @param {string} [param1.attribution]
* @param {string} [param1.query]
* @returns {GeoJsonFeatureCollection}
*/
const featureCollection = (
features,
{ license = null, attribution = null, query = null } = {}
{ license, attribution, query } = {}
) => ({

@@ -19,2 +29,6 @@ type: 'FeatureCollection',

/**
* @param {GeocoderResult} param0
* @returns {GeoJsonFeature}
*/
const feature = ({

@@ -41,2 +55,3 @@ formattedAddress,

geometry: {
type: 'Point',
coordinates: [longitude, latitude]

@@ -46,4 +61,4 @@ },

geocoding: {
label: formattedAddress,
// "type": ??,
label: formattedAddress,
country: countryCode,

@@ -71,2 +86,7 @@ state: state,

/**
* @param {GeocoderResult[]} results
* @param {object} opts
* @returns
*/
export function geoJsonFormatter (

@@ -73,0 +93,0 @@ results,

@@ -0,3 +1,13 @@

/** @typedef {import('../types').GeocoderResult} GeocoderResult */
/**
* @param {any} s
* @returns {string}
*/
const escQuote = (s) => String(s).replace(/"/g, '\\"')
/**
* @param {string|undefined} s
* @returns {string}
*/
const escXml = (s) =>

@@ -16,2 +26,9 @@ (s || '').replace(/&amp;/g, '&').replace(

/**
* @param {object} param0
* @param {number} param0.latitude
* @param {number} param0.longitude
* @param {string} [param0.formattedAddress]
* @returns {string}
*/
const gpxWaypoint = ({ latitude, longitude, formattedAddress }) => `

@@ -22,2 +39,6 @@ <wpt lat="${escQuote(latitude)}" lon="${escQuote(longitude)}"><name>${escXml(

/**
* @param {GeocoderResult[]} results
* @returns {string}
*/
export const gpxFormatter = (results) => `<?xml version="1.0" encoding="UTF-8"?>

@@ -24,0 +45,0 @@ <gpx version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/0" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">${results.map(

@@ -0,2 +1,3 @@

// @ts-nocheck
export * from './geojson.js'
export * from './gpx.js'
export * from './geojson.js'

@@ -0,1 +1,2 @@

// @ts-ignore
import net from 'net'

@@ -9,40 +10,11 @@ import { URL, URLSearchParams } from 'url'

/**
* @typedef {object} ForwardQuery
* @property {string} address address being queried
* @property {string} [language] search results language
* @property {number} [limit] limit search results
*/
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
/** @typedef {import('../types').ForwardQuery} ForwardQuery */
/** @typedef {import('../types').ReverseQuery} ReverseQuery */
/** @typedef {import('../types').GeocoderResult} GeocoderResult */
/**
* @typedef {object} ReverseQuery {
* @property {number} lat latitude
* @property {number} lng longitude
* @property {string} [language] search results language
* @property {number} [limit] limit search results
*/
/**
* @typedef {object} GeocoderResult
* @property {number} latitude latitude of search result
* @property {number} longitude longitude of search result
* @property {string} [formattedAddress]
* @property {string} [country]
* @property {string} [countryCode] country code as ISO 3166-1 alpha-2 or ISO 3166-1 alpha-3
* @property {string} [state]
* @property {string} [region]
* @property {string} [city]
* @property {string} [zipcode]
* @property {string} [streetName]
* @property {string} [streetNumber]
* @property {object} [extra]
* @property {string|number} [extra.id]
* @property {number} [extra.confidence] confidence [0..1] higher values = higher confidence
* @property {number[]} [extra.bbox] bounding box as `[minLng, minLat, maxLng, maxLat]`
*/
export class AbstractGeocoder {
/**
* @param {fetchAdapter} adapter
* @param {object} [options]
* @param {fetchAdapterFn} adapter
* @param {object} options
* @param {boolean} [options.raw] append raw response to results

@@ -57,2 +29,4 @@ */

this._name = this.constructor.name.replace(/Geocoder$/i, '').toLowerCase()
this.supportIPv4 = false
this.supportIPv6 = false
}

@@ -137,7 +111,11 @@

/**
* @typedef {Array} WrappedResults
* @property {any} raw
*/
/**
* wraps raw response on results object
* @protected
* @param {Array} results
* @param {any} results
* @param {object} body
* @returns {Array}
* @returns {WrappedResults}
*/

@@ -155,5 +133,6 @@ wrapRaw (results = [], body) {

* @param {string|ForwardQuery} query address string or ip address
* @param {boolean} [isIP]
* @returns {Promise<GeocoderResult[]>}
*/
_forward () {
_forward (query, isIP) {
throw wrapError400(

@@ -170,3 +149,3 @@ new Error(`${this.constructor.name} does not support geocoding`)

*/
_reverse () {
_reverse (query) {
throw wrapError400(

@@ -173,0 +152,0 @@ new Error(`${this.constructor.name} does not support reverse geocoding`)

import { AbstractGeocoder } from './abstract.js'
import { HttpError, countryCode, countryName } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
const undef = (s) => s === '' ? undefined : s

@@ -13,2 +15,3 @@

* @property {string} [preferredLabelValues]
* @property {string} [language]
*/

@@ -25,2 +28,3 @@

* @property {string} [preferredLabelValues]
* @property {string} [language]
*/

@@ -31,9 +35,10 @@

* available options
* @see
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options
* @param {string} options.apiKey
* @param {number} [limit]
* @param {number} [options.limit]
* @param {string} [options.language]
*/
constructor (adapter, options = {}) {
constructor (adapter, options = { apiKey: '' }) {
// @ts-ignore
super(adapter, options)

@@ -81,3 +86,3 @@

if (query.address) {
if (typeof query !== 'string' && query.address) {
const {

@@ -99,3 +104,3 @@ address,

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -112,3 +117,3 @@ const result = await res.json()

/**
* @param {string|ArcGisReverseQuery} query
* @param {ArcGisReverseQuery} query
* @returns {Promise<object>}

@@ -139,3 +144,3 @@ */

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -197,3 +202,3 @@ const result = await res.json()

country: countryName(Country),
countryCode: countryCode(undef(Country), language),
countryCode: countryCode(undef(Country)),
state: undef(Region),

@@ -242,3 +247,3 @@ city: undef(City),

country: countryName(CountryCode),
countryCode: countryCode(undef(CountryCode), language),
countryCode: countryCode(undef(CountryCode)),
state: undef(Region),

@@ -245,0 +250,0 @@ city: undef(City),

import { AbstractGeocoder } from './abstract.js'
import { HttpError } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
const hasResult = (result) => {

@@ -26,2 +28,3 @@ const { statusCode, resourceSets } = result || {}

* @property {number} [limit]
* @property {string} [language]
*/

@@ -35,2 +38,3 @@

* @property {number} [limit]
* @property {string} [language]
*/

@@ -42,8 +46,10 @@

* @see https://docs.microsoft.com/en-us/bingmaps/rest-services/
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options
* @param {string} options.apiKey
* @param {number} [limit]
* @param {number} [options.limit]
* @param {string} [options.language]
*/
constructor (adapter, options = {}) {
constructor (adapter, options = { apiKey: '' }) {
// @ts-ignore
super(adapter, options)

@@ -71,3 +77,3 @@

/**
* @param {string|BingMapsForwardQuery} query
* @param {BingMapsForwardQuery|string} query
* @returns {Promise<object>}

@@ -78,9 +84,4 @@ */

if (query.address) {
const {
address: q,
limit: maxResults,
language,
...other
} = query
if (typeof query !== 'string' && query.address) {
const { address: q, limit: maxResults, language, ...other } = query
params = { ...params, ...other, q, maxResults }

@@ -96,3 +97,3 @@ }

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -109,3 +110,3 @@ const result = await res.json()

/**
* @param {string|BingMapsReverseQuery} query
* @param {BingMapsReverseQuery} query
* @returns {Promise<object>}

@@ -128,3 +129,3 @@ */

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -131,0 +132,0 @@ const result = await res.json()

import { AbstractGeocoder } from './abstract.js'
import { HttpError, countryName } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
/**

@@ -29,9 +31,10 @@ * see https://www.geocod.io/docs/#single-address

* @see https://www.geocod.io/features/api/
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options
* @param {string} options.apiKey
* @param {string} [language]
* @param {string} [options.language]
* @param {number} [options.limit]
*/
constructor (adapter, options = {}) {
constructor (adapter, options = { apiKey: '' }) {
// @ts-ignore
super(adapter, options)

@@ -67,3 +70,3 @@

if (query.address) {
if (typeof query !== 'string' && query.address) {
const { address, language, ...other } = query

@@ -81,3 +84,3 @@ params = { ...params, ...other, q: address }

if (res.status !== 200 && res.status !== 422) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -92,3 +95,2 @@ if (!result?.results) {

/**
* @see
* @param {GeocodioReverseQuery} query

@@ -108,3 +110,3 @@ * @returns {Promise<object>}

if (res.status !== 200 && res.status !== 422) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -111,0 +113,0 @@ const result = await res.json()

import { AbstractGeocoder } from './abstract.js'
import { HttpError, objToCamelCase } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
function hasResult (result) {

@@ -21,9 +23,11 @@ return result && !!result.location

* available options
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options
* @param {string} [options.endpoint=https://geolite.info/geoip/v2.1/city]
* @param {string} [options.endpoint='https://geolite.info/geoip/v2.1/city']
* @param {string} [options.accountId] MaxMind account ID
* @param {string} [options.apiKey] MaxMind license key
* @param {string} [options.language]
*/
constructor (adapter, options = {}) {
// @ts-ignore
super(adapter, options)

@@ -60,3 +64,3 @@

if (query.address) {
if (typeof query !== 'string' && query.address) {
const { address, ...other } = query

@@ -76,3 +80,3 @@ searchtext = address

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -79,0 +83,0 @@ const result = await res.json()

import { AbstractGeocoder } from './abstract.js'
import { HttpError } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
// status can be "OK", "ZERO_RESULTS", "OVER_QUERY_LIMIT", "REQUEST_DENIED", "INVALID_REQUEST", or "UNKNOWN_ERROR"

@@ -52,8 +54,9 @@ const NO_ERROR = ['OK', 'ZERO_RESULTS']

* @see https://developers.google.com/maps/documentation/geocoding/overview
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options
* @param {string} options.apiKey
* @param {string} [language]
* @param {string} [options.language]
*/
constructor (adapter, options = {}) {
constructor (adapter, options = { apiKey: '' }) {
// @ts-ignore
super(adapter, options)

@@ -67,2 +70,3 @@

// @ts-ignore
params.key = apiKey

@@ -83,3 +87,3 @@ this.params = params

if (query.address) {
if (typeof query !== 'string' && query.address) {
const { address, ...other } = query

@@ -96,3 +100,3 @@ params = { ...params, ...other, address }

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -110,3 +114,3 @@ const result = await res.json()

/**
* @param {string|GoogleReverseQuery} query
* @param {GoogleReverseQuery} query
* @returns {Promise<object>}

@@ -129,3 +133,3 @@ */

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -132,0 +136,0 @@ const result = await res.json()

import { AbstractGeocoder } from './abstract.js'
import { HttpError, countryCode } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
/**

@@ -31,9 +33,10 @@ * @typedef {object} HereForwardQuery

* @see https://developer.here.com/documentation/geocoding-search-api/dev_guide/index.html
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options
* @param {string} options.apiKey
* @param {string} [language]
* @param {string} [options.language]
* @param {number} [options.limit]
*/
constructor (adapter, options = {}) {
constructor (adapter, options = { apiKey: '' }) {
// @ts-ignore
super(adapter, options)

@@ -64,3 +67,3 @@

if (query.address) {
if (typeof query !== 'string' && query.address) {
const { address, ...other } = query

@@ -77,3 +80,3 @@ params = { ...params, ...other, q: address }

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -90,3 +93,3 @@ const result = await res.json()

* @see https://developer.here.com/documentation/geocoding-search-api/api-reference-swagger.html
* @param {string|HereReverseQuery} query
* @param {HereReverseQuery} query
* @returns {Promise<object>}

@@ -105,3 +108,3 @@ */

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -108,0 +111,0 @@ const result = await res.json()

@@ -0,1 +1,2 @@

// @ts-nocheck
export * from './abstract.js'

@@ -2,0 +3,0 @@ export * from './arcgis.js'

import { AbstractGeocoder } from './abstract.js'
import { HttpError } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
function hasResult (result) {

@@ -12,2 +14,4 @@ return result && !!result.type

* @see https://ipstack.com/documentation
* @param {fetchAdapterFn} adapter
* @param {object} options
*/

@@ -31,2 +35,5 @@ constructor (adapter, options = {}) {

/**
* @param {object|string} query
*/
async _forward (query = '') {

@@ -36,3 +43,3 @@ let params = this.params

if (query.address) {
if (typeof query !== 'string' && query.address) {
const { address, ...other } = query

@@ -50,3 +57,3 @@ searchtext = address

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -53,0 +60,0 @@ const result = await res.json()

import { AbstractGeocoder } from './abstract.js'
import { HttpError, toUpperCase } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
/**

@@ -38,3 +40,3 @@ * @typedef {object} LocationIqForwardQuery

* @see https://locationiq.com/docs
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options

@@ -46,3 +48,4 @@ * @param {string} options.apiKey

*/
constructor (adapter, options = {}) {
constructor (adapter, options = { apiKey: '' }) {
// @ts-ignore
super(adapter, options)

@@ -74,3 +77,3 @@

if (query.address) {
if (typeof query !== 'string' && query.address) {
const { address, ...other } = query

@@ -87,3 +90,3 @@ params = { ...params, ...other, q: address }

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -113,3 +116,3 @@ const result = await res.json()

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -116,0 +119,0 @@ const result = await res.json()

import { AbstractGeocoder } from './abstract.js'
import { HttpError } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
/**

@@ -31,3 +33,3 @@ * @typedef {object} MapBoxForwardQuery

* @see https://docs.mapbox.com/api/search/geocoding/
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options

@@ -38,3 +40,4 @@ * @param {string} options.apiKey

*/
constructor (adapter, options = {}) {
constructor (adapter, options = { apiKey: '' }) {
// @ts-ignore
super(adapter, options)

@@ -48,2 +51,3 @@

// @ts-ignore
params.access_token = apiKey

@@ -65,3 +69,3 @@ this.params = params

if (query.address) {
if (typeof query !== 'string' && query.address) {
const { address, ...other } = query

@@ -73,3 +77,3 @@ searchtext = address

const url = this.createUrl(
`${this.endpoint}/${encodeURIComponent(searchtext)}.json`,
`${this.endpoint}/${encodeURIComponent(String(searchtext))}.json`,
params

@@ -80,3 +84,3 @@ )

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -92,3 +96,3 @@ const result = await res.json()

/**
* @param {string|MapBoxReverseQuery} query
* @param {MapBoxReverseQuery} query
* @returns {Promise<object>}

@@ -107,3 +111,3 @@ */

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -110,0 +114,0 @@ const result = await res.json()

import { AbstractGeocoder } from './abstract.js'
import { HttpError, countryName } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
/**

@@ -31,3 +33,3 @@ * @typedef {object} MapQuestForwardQuery

* @see https://developer.mapquest.com/documentation/geocoding-api
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options

@@ -39,3 +41,4 @@ * @param {string} options.apiKey

*/
constructor (adapter, options = {}) {
constructor (adapter, options = { apiKey: '' }) {
// @ts-ignore
super(adapter, options)

@@ -68,3 +71,3 @@

if (query.address) {
if (typeof query !== 'string' && query.address) {
const { address, limit, ...other } = query

@@ -81,3 +84,3 @@ params = { ...params, ...other, location: address, maxResults: limit }

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -94,3 +97,3 @@ const result = await res.json()

/**
* @param {string|MapQuestReverseQuery} query
* @param {MapQuestReverseQuery} query
* @returns {Promise<object>}

@@ -114,3 +117,3 @@ */

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -117,0 +120,0 @@ const result = await res.json()

import { AbstractGeocoder } from './abstract.js'
import { HttpError, toUpperCase } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
/**

@@ -44,3 +46,3 @@ * @typedef {object} OpenCageForwardQuery

* @see https://opencagedata.com/api#quickstart
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options

@@ -53,6 +55,7 @@ * @param {string} options.apiKey

*/
constructor (adapter, options = {}) {
constructor (adapter, options = { apiKey: '' }) {
// @ts-ignore
super(adapter, options)
const { apiKey, params } = options
const { apiKey, ...params } = options

@@ -77,3 +80,3 @@ if (!apiKey) {

if (query.address) {
if (typeof query !== 'string' && query.address) {
const { address, ...other } = query

@@ -90,3 +93,3 @@ params = { ...params, ...other, q: address }

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -103,3 +106,3 @@ const result = await res.json()

/**
* @param {string|OpenCageReverseQuery} query
* @param {OpenCageReverseQuery} query
* @returns {Promise<object>}

@@ -118,3 +121,3 @@ */

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -121,0 +124,0 @@ const result = await res.json()

import { AbstractGeocoder } from './abstract.js'
import { HttpError } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
/**

@@ -24,10 +26,12 @@ * see https://geo.api.gouv.fr/adresse

* @see https://geo.api.gouv.fr/adresse
* @param {function} adapter
* @param {object} options
* @param {string} options.apiKey
* @param {fetchAdapterFn} adapter
* @param {object} [options]
* @param {number} [options.limit]
* @param {string} [options.language]
*/
constructor (adapter, options = {}) {
// @ts-ignore
super(adapter, options)
// @ts-ignore
const { apiKey, language, ...params } = options

@@ -53,3 +57,4 @@

if (query.address) {
if (typeof query !== 'string' && query.address) {
// @ts-ignore
const { address, language, ...other } = query

@@ -66,3 +71,3 @@ params = { ...params, ...other, q: address }

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -82,2 +87,3 @@ const result = await res.json()

async _reverse (query) {
// @ts-ignore
const { lat, lng: lon, language, ...other } = query

@@ -93,3 +99,3 @@ const params = { ...this.params, ...other, lon, lat }

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -96,0 +102,0 @@ const result = await res.json()

import { OsmGeocoder } from './osm.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
/**

@@ -31,9 +33,9 @@ * see https://developer.mapquest.com/documentation/open/nominatim-search/search/

* @see https://developer.mapquest.com/documentation/open/nominatim-search/
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options
* @param {string} options.apiKey
* @param {string} options.apiKey MapQuest API Key
* @param {number} [options.limit=10]
* @param {string} [options.language]
*/
constructor (adapter, options = {}) {
constructor (adapter, options = { apiKey: '' }) {
super(adapter, options)

@@ -40,0 +42,0 @@

import { AbstractGeocoder } from './abstract.js'
import { HttpError, toUpperCase } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
const ACCEPT_LANGUAGE = 'accept-language'

@@ -60,3 +62,3 @@

* @see https://nominatim.org/release-docs/develop/api/Search/
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options

@@ -74,2 +76,3 @@ * @param {number} [options.limit=10]

constructor (adapter, options = {}) {
// @ts-ignore
super(adapter, options)

@@ -80,2 +83,3 @@

revEndpoint = 'https://nominatim.openstreetmap.org/reverse',
// @ts-ignore
apiKey,

@@ -102,3 +106,3 @@ ...params

if (query.address) {
if (typeof query !== 'string' && query.address) {
const { address, ...other } = query

@@ -113,3 +117,3 @@ params = { ...params, ...other, q: address }

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -125,3 +129,3 @@ const result = await res.json()

/**
* @param {string|OsmReverseQuery} query
* @param {OsmReverseQuery} query
* @returns {Promise<object>}

@@ -137,3 +141,3 @@ */

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -140,0 +144,0 @@ const result = await res.json()

import { AbstractGeocoder } from './abstract.js'
import { HttpError, countryCode } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
/**

@@ -19,3 +21,3 @@ * @typedef {object} PeliasForwardQuery

* @see https://github.com/pelias/documentation/blob/master/README.md
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options

@@ -25,4 +27,6 @@ * @param {string} [options.origin='https://api.geocode.earth'] protocol + hostname for server

constructor (adapter, options = {}) {
// @ts-ignore
super(adapter, options)
// @ts-ignore
const { origin, apiKey, ...other } = options

@@ -40,2 +44,3 @@ if (!origin && !apiKey) {

if (apiKey) {
// @ts-ignore
this.params.api_key = apiKey

@@ -60,3 +65,3 @@ }

if (query.address) {
if (typeof query !== 'string' && query.address) {
const { address, ...other } = query

@@ -70,3 +75,3 @@ params = { ...params, ...other, text: address }

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -83,3 +88,3 @@ const result = await res.json()

/**
* @param {string|PeliasReverseQuery} query
* @param {PeliasReverseQuery} query
* @returns {Promise<object>}

@@ -95,3 +100,3 @@ */

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -98,0 +103,0 @@ const result = await res.json()

import { OsmGeocoder } from './osm.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
/**

@@ -31,3 +33,3 @@ * see https://pickpoint.io/api-reference#forward-geocoding

* @see https://pickpoint.io/api-reference
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options

@@ -38,3 +40,3 @@ * @param {string} options.apiKey

*/
constructor (adapter, options = {}) {
constructor (adapter, options = { apiKey: '' }) {
super(adapter, options)

@@ -41,0 +43,0 @@

@@ -9,2 +9,4 @@ /**

/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
function getEmbeddedPath (parent, path, def) {

@@ -45,3 +47,3 @@ const elements = path.split('/')

* @see https://developers.teleport.org/api/resources/
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options

@@ -73,3 +75,3 @@ */

if (query.address) {
if (typeof query !== 'string' && query.address) {
const { address, ...other } = query

@@ -83,3 +85,3 @@ params = { ...params, ...other, search: address }

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -98,3 +100,3 @@ const result = await res.json()

/**
* @param {string|TeleportReverseQuery} query
* @param {TeleportReverseQuery} query
* @returns {Promise<object>}

@@ -117,3 +119,3 @@ */

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -120,0 +122,0 @@ const result = await res.json()

import { AbstractGeocoder } from './abstract.js'
import { HttpError } from '../utils/index.js'
/** @typedef {import('../adapter').fetchAdapterFn} fetchAdapterFn */
/**

@@ -25,3 +27,3 @@ * @see https://yandex.com/dev/maps/geocoder/doc/desc/concepts/input_params.html

* @see https://yandex.com/dev/maps/geocoder/doc/desc/concepts/input_params.html
* @param {function} adapter
* @param {fetchAdapterFn} adapter
* @param {object} options

@@ -31,5 +33,7 @@ * @param {string} options.apiKey

*/
constructor (adapter, options = {}) {
constructor (adapter, options = { apiKey: '' }) {
// @ts-ignore
super(adapter, options)
// @ts-ignore
const { apiKey, limit, ...params } = options

@@ -59,3 +63,4 @@

if (query.address) {
if (typeof query !== 'string' && query.address) {
// @ts-ignore
const { address, limit, ...other } = query

@@ -72,3 +77,3 @@ params = { ...params, ...other, geocode: address }

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -88,2 +93,3 @@ const result = await res.json()

async _reverse (query) {
// @ts-ignore
const { lat, lng, limit, ...other } = query

@@ -99,3 +105,3 @@ const params = { ...this.params, ...other, geocode: `${lng},${lat}` }

if (res.status !== 200) {
throw new HttpError(res)
throw HttpError(res)
}

@@ -102,0 +108,0 @@ const result = await res.json()

@@ -0,1 +1,2 @@

// @ts-nocheck
export * from './adapter.js'

@@ -2,0 +3,0 @@ export * from './cascade.js'

/**
* @param {string} str
* @returns {string}
*/
export const toCamelCase = (str) => str.replace(/_(.)/g, (_, c) => c.toUpperCase())
/**
* @param {object} obj
* @returns {object}
*/
export function objToCamelCase (obj) {

@@ -5,0 +13,0 @@ return Object.entries(obj).reduce((o, [k, v]) => {

@@ -0,4 +1,13 @@

/** @typedef {import('../adapter').Response} Response */
/** @typedef {import('../types').HttpError} HttpErrorType */
/**
* @param {Response} response
* @returns {HttpErrorType}
*/
export function HttpError (response) {
const status = response.status || 500
const err = new Error(status)
/** @type {HttpErrorType} */
// @ts-ignore
const err = new Error('' + status)
err.status = status

@@ -8,2 +17,2 @@ err.response = response

return err
};
}

@@ -0,4 +1,6 @@

// @ts-nocheck
export * from './camelCase.js'
export * from './httperror.js'
export * from './isocode.js'
export * from './isType.js'
export * from './toUpperCase.js'

@@ -0,1 +1,2 @@

// @ts-ignore
import countries from 'i18n-iso-countries'

@@ -18,3 +19,3 @@

* @param {string} [language='en']
* @returns {string}
* @returns {string|undefined}
*/

@@ -24,4 +25,5 @@ export const countryName = (code, language = 'en') => {

const lang = language.split('-')[0]
const name = countries.getName(code, lang, OPTS)
return name || countries.getName(code, 'en', OPTS)
// @ts-ignore
const name = countries.getName(code, lang, OPTS) || countries.getName(code, 'en', OPTS)
return name
}

@@ -0,1 +1,5 @@

/**
* @param {string|any} str
* @returns {any}
*/
export function toUpperCase (str) {

@@ -2,0 +6,0 @@ return (typeof str === 'string')

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

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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc