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

node-geocoder

Package Overview
Dependencies
Maintainers
1
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-geocoder - npm Package Compare versions

Comparing version 3.29.0 to 4.0.0

6

CHANGELOG.md

@@ -133,1 +133,7 @@ ## 3.0.0

- Integrations test for TomTom, Here and Mapbox
# 4.0.0
- Support nodejs >= 12
- Remove http adapter (#332)
- Remove deprecated option from here geocoder (#333)

106

lib/geocoder/googlegeocoder.js

@@ -14,3 +14,10 @@ 'use strict';

var GoogleGeocoder = function GoogleGeocoder(httpAdapter, options) {
this.options = ['language', 'apiKey', 'clientId', 'region', 'excludePartialMatches', 'channel'];
this.options = [
'language',
'apiKey',
'clientId',
'region',
'excludePartialMatches',
'channel'
];

@@ -31,3 +38,4 @@ GoogleGeocoder.super_.call(this, httpAdapter, options);

// Google geocoding API endpoint
GoogleGeocoder.prototype._endpoint = 'https://maps.googleapis.com/maps/api/geocode/json';
GoogleGeocoder.prototype._endpoint =
'https://maps.googleapis.com/maps/api/geocode/json';

@@ -40,3 +48,2 @@ /**

GoogleGeocoder.prototype._geocode = function (value, callback) {
var _this = this;

@@ -92,10 +99,22 @@ var params = this._prepareQueryString();

if (result.status !== 'OK') {
return callback(new Error('Status is ' + result.status + '.' + (result.error_message ? ' ' + result.error_message : '')), {raw: result});
return callback(
new Error(
'Status is ' +
result.status +
'.' +
(result.error_message ? ' ' + result.error_message : '')
),
{ raw: result }
);
}
for (var i = 0; i < result.results.length; i++) {
var currentResult = result.results[i];
if (excludePartialMatches && excludePartialMatches === true && typeof currentResult.partial_match !== 'undefined' && currentResult.partial_match === true) {
if (
excludePartialMatches &&
excludePartialMatches === true &&
typeof currentResult.partial_match !== 'undefined' &&
currentResult.partial_match === true
) {
continue;

@@ -110,5 +129,3 @@ }

}
});
};

@@ -118,3 +135,3 @@

var params = {
'sensor': false
sensor: false
};

@@ -140,3 +157,6 @@

if (this.options.excludePartialMatches && this.options.excludePartialMatches === true) {
if (
this.options.excludePartialMatches &&
this.options.excludePartialMatches === true
) {
params.excludePartialMatches = true;

@@ -146,12 +166,13 @@ }

return params;
};
GoogleGeocoder.prototype._signedRequest = function (endpoint, params) {
if (this.options.clientId) {
var request = url.parse(endpoint);
var fullRequestPath = request.path + url.format({query: params});
var fullRequestPath = request.path + url.format({ query: params });
var decodedKey = new Buffer(this.options.apiKey.replace('-', '+').replace('_', '/'), 'base64');
var decodedKey = Buffer.from(
this.options.apiKey.replace('-', '+').replace('_', '/'),
'base64'
);
var hmac = crypto.createHmac('sha1', decodedKey);

@@ -170,3 +191,2 @@ hmac.update(fullRequestPath);

GoogleGeocoder.prototype._formatResult = function (result) {
var googleConfidenceLookup = {

@@ -191,4 +211,3 @@ ROOFTOP: 1,

},
administrativeLevels: {
}
administrativeLevels: {}
};

@@ -207,24 +226,34 @@

case 'administrative_area_level_1':
extractedObj.administrativeLevels.level1long = result.address_components[i].long_name;
extractedObj.administrativeLevels.level1short = result.address_components[i].short_name;
extractedObj.administrativeLevels.level1long =
result.address_components[i].long_name;
extractedObj.administrativeLevels.level1short =
result.address_components[i].short_name;
break;
//Administrative Level 2
case 'administrative_area_level_2':
extractedObj.administrativeLevels.level2long = result.address_components[i].long_name;
extractedObj.administrativeLevels.level2short = result.address_components[i].short_name;
extractedObj.administrativeLevels.level2long =
result.address_components[i].long_name;
extractedObj.administrativeLevels.level2short =
result.address_components[i].short_name;
break;
//Administrative Level 3
case 'administrative_area_level_3':
extractedObj.administrativeLevels.level3long = result.address_components[i].long_name;
extractedObj.administrativeLevels.level3short = result.address_components[i].short_name;
extractedObj.administrativeLevels.level3long =
result.address_components[i].long_name;
extractedObj.administrativeLevels.level3short =
result.address_components[i].short_name;
break;
//Administrative Level 4
case 'administrative_area_level_4':
extractedObj.administrativeLevels.level4long = result.address_components[i].long_name;
extractedObj.administrativeLevels.level4short = result.address_components[i].short_name;
extractedObj.administrativeLevels.level4long =
result.address_components[i].long_name;
extractedObj.administrativeLevels.level4short =
result.address_components[i].short_name;
break;
//Administrative Level 5
case 'administrative_area_level_5':
extractedObj.administrativeLevels.level5long = result.address_components[i].long_name;
extractedObj.administrativeLevels.level5short = result.address_components[i].short_name;
extractedObj.administrativeLevels.level5long =
result.address_components[i].long_name;
extractedObj.administrativeLevels.level5short =
result.address_components[i].short_name;
break;

@@ -250,6 +279,8 @@ // City

case 'subpremise':
extractedObj.extra.subpremise = result.address_components[i].long_name;
extractedObj.extra.subpremise =
result.address_components[i].long_name;
break;
case 'establishment':
extractedObj.extra.establishment = result.address_components[i].long_name;
extractedObj.extra.establishment =
result.address_components[i].long_name;
break;

@@ -260,4 +291,5 @@ case 'sublocality_level_1':

case 'neighborhood':
if(!extractedObj.extra.neighborhood) {
extractedObj.extra.neighborhood = result.address_components[i].long_name;
if (!extractedObj.extra.neighborhood) {
extractedObj.extra.neighborhood =
result.address_components[i].long_name;
}

@@ -305,3 +337,11 @@ break;

if (result.status !== 'OK') {
return callback(new Error('Status is ' + result.status + '.' + (result.error_message ? ' ' + result.error_message : '')), {raw: result});
return callback(
new Error(
'Status is ' +
result.status +
'.' +
(result.error_message ? ' ' + result.error_message : '')
),
{ raw: result }
);
}

@@ -321,3 +361,3 @@

GoogleGeocoder.prototype._encodeSpecialChars = function(value) {
GoogleGeocoder.prototype._encodeSpecialChars = function (value) {
if (typeof value === 'string') {

@@ -324,0 +364,0 @@ return value.replace(/\u001a/g, ' ');

@@ -31,3 +31,2 @@ const readline = require('readline');

// appId and appCode are deprecated
if (!this.options.apiKey && !(this.options.appId && this.options.appCode)) {

@@ -70,3 +69,3 @@ throw new Error('You must specify apiKey to use Here Geocoder');

this.httpAdapter.get(this._geocodeEndpoint, params, function(err, result) {
this.httpAdapter.get(this._geocodeEndpoint, params, function (err, result) {
var results = [];

@@ -109,3 +108,3 @@ results.raw = result;

this.httpAdapter.get(this._reverseEndpoint, params, function(err, result) {
this.httpAdapter.get(this._reverseEndpoint, params, function (err, result) {
var results = [];

@@ -232,33 +231,45 @@ results.raw = result;

async __createJob(values) {
const { country } = this.options;
const body =
`recId|searchText${country ? '|country' : ''}` + '\n' +
values.map((value, ix) => `${ix + 1}|"${value}"${country ? `|${country}` : ''}`).join(' \n') + '\n';
const params = {
...this._prepareQueryString(),
action: 'run',
outdelim: '|',
indelim: '|',
header: false,
outputcombined: true,
outcols: 'latitude,longitude,locationLabel,houseNumber,street,district,city,postalCode,county,state,addressDetailsCountry,country,building,locationId'
};
const options = {
body,
headers: {
'content-type': 'text/plain',
accept: 'application/json'
}
};
const creteJobReq = await new Promise((resolve, reject) => {
this.httpAdapter.post(this._batchGeocodeEndpoint, params, options, (err, result) => {
const { country } = this.options;
const body =
`recId|searchText${country ? '|country' : ''}` +
'\n' +
values
.map(
(value, ix) => `${ix + 1}|"${value}"${country ? `|${country}` : ''}`
)
.join(' \n') +
'\n';
const params = {
...this._prepareQueryString(),
action: 'run',
outdelim: '|',
indelim: '|',
header: false,
outputcombined: true,
outcols:
'latitude,longitude,locationLabel,houseNumber,street,district,city,postalCode,county,state,addressDetailsCountry,country,building,locationId'
};
const options = {
body,
headers: {
'content-type': 'text/plain',
accept: 'application/json'
}
};
const creteJobReq = await new Promise((resolve, reject) => {
this.httpAdapter.post(
this._batchGeocodeEndpoint,
params,
options,
(err, result) => {
if (err) return reject(err);
resolve(result);
});
});
const jobRes = await creteJobReq.json();
if (jobRes.type === 'ApplicationError') {
throw new Error(jobRes.Details);
}
return jobRes.Response.MetaInfo.RequestId;
}
);
});
const jobRes = await creteJobReq.json();
if (jobRes.type === 'ApplicationError') {
throw new Error(jobRes.Details);
}
return jobRes.Response.MetaInfo.RequestId;
}

@@ -298,6 +309,11 @@

const jobResult = await new Promise((resolve, reject) => {
this.httpAdapter.get(`${this._batchGeocodeEndpoint}/${jobId}/result`, params, (err, result) => {
if (err) return reject(err);
resolve(result);
}, true);
this.httpAdapter.get(
`${this._batchGeocodeEndpoint}/${jobId}/result`,
params,
(err, result) => {
if (err) return reject(err);
resolve(result);
},
true
);
});

@@ -312,5 +328,5 @@ const jobResultLineReadeer = readline.createInterface({

recId,
/*seqNumber*/,
/*seqLength*/,
latitude,
,
,
/*seqNumber*/ /*seqLength*/ latitude,
longitude,

@@ -352,6 +368,11 @@ locationLabel,

const jobErrors = await new Promise((resolve, reject) => {
this.httpAdapter.get(`${this._batchGeocodeEndpoint}/${jobId}/errors`, params, (err, result) => {
if (err) return reject(err);
resolve(result);
}, true);
this.httpAdapter.get(
`${this._batchGeocodeEndpoint}/${jobId}/errors`,
params,
(err, result) => {
if (err) return reject(err);
resolve(result);
},
true
);
});

@@ -381,3 +402,13 @@ const jobErrorsLineReader = readline.createInterface({

value: values.map(value => {
const { latitude, longitude, district, city, county, state, addressDetailsCountry, country, building } = value;
const {
latitude,
longitude,
district,
city,
county,
state,
addressDetailsCountry,
country,
building
} = value;
return {

@@ -399,3 +430,3 @@ formattedAddress: value.locationLabel,

herePlaceId: value.locationId,
confidence: null,
confidence: null
},

@@ -413,3 +444,3 @@ provider: 'here'

_geocodeEndpoint: {
get: function() {
get: function () {
return 'https://geocoder.ls.hereapi.com/6.2/geocode.json';

@@ -421,3 +452,3 @@ }

_reverseEndpoint: {
get: function() {
get: function () {
return 'https://reverse.geocoder.ls.hereapi.com/6.2/reversegeocode.json';

@@ -429,9 +460,8 @@ }

_batchGeocodeEndpoint: {
get: function() {
get: function () {
return 'https://batch.geocoder.ls.hereapi.com/6.2/jobs';
}
},
}
});
module.exports = HereGeocoder;

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

const AbstractGeocoder = require('./abstractgeocoder')
const AbstractGeocoder = require('./abstractgeocoder');
/**
* available options
* available options
* @see https://docs.mapbox.com/api/search/geocoding/

@@ -17,7 +17,7 @@ */

'routing'
]
];
const OPTIONS_MAP = {
apiKey: 'access_token'
}
};

@@ -30,9 +30,8 @@ /**

class MapBoxGeocoder extends AbstractGeocoder {
constructor (httpAdapter, options) {
super(httpAdapter, options)
this.options = options || {}
constructor(httpAdapter, options) {
super(httpAdapter, options);
this.options = options || {};
// appId and appCode are deprecated
if (!this.options.apiKey) {
throw new Error('You must specify apiKey to use MapBox Geocoder')
throw new Error('You must specify apiKey to use MapBox Geocoder');
}

@@ -46,30 +45,32 @@ }

*/
_geocode (value, callback) {
let params = this._prepareQueryString({})
let searchtext = value
_geocode(value, callback) {
let params = this._prepareQueryString({});
let searchtext = value;
if (value.address) {
params = this._prepareQueryString(value)
searchtext = value.address
params = this._prepareQueryString(value);
searchtext = value.address;
}
const endpoint = `${this._geocodeEndpoint}/${encodeURIComponent(searchtext)}.json`
const endpoint = `${this._geocodeEndpoint}/${encodeURIComponent(
searchtext
)}.json`;
this.httpAdapter.get(endpoint, params, (err, result) => {
let results = []
results.raw = result
let results = [];
results.raw = result;
if (err) {
return callback(err, results)
return callback(err, results);
} else {
const view = result.features
const view = result.features;
if (!view) {
return callback(false, results)
return callback(false, results);
}
results = view.map(this._formatResult)
results.raw = result
results = view.map(this._formatResult);
results.raw = result;
callback(false, results)
callback(false, results);
}
})
});
}

@@ -82,46 +83,48 @@

*/
_reverse (query, callback) {
const { lat, lon, ...other } = query
_reverse(query, callback) {
const { lat, lon, ...other } = query;
const params = this._prepareQueryString(other)
const endpoint = `${this._geocodeEndpoint}/${encodeURIComponent(`${lon},${lat}`)}.json`
const params = this._prepareQueryString(other);
const endpoint = `${this._geocodeEndpoint}/${encodeURIComponent(
`${lon},${lat}`
)}.json`;
this.httpAdapter.get(endpoint, params, (err, result) => {
let results = []
results.raw = result
let results = [];
results.raw = result;
if (err) {
return callback(err, results)
return callback(err, results);
} else {
const view = result.features
const view = result.features;
if (!view) {
return callback(false, results)
return callback(false, results);
}
results = view.map(this._formatResult)
results.raw = result
results = view.map(this._formatResult);
results.raw = result;
callback(false, results)
callback(false, results);
}
})
});
}
_formatResult (result) {
_formatResult(result) {
const context = (result.context || []).reduce((o, item) => {
// possible types: country, region, postcode, district, place, locality, neighborhood, address
const [type] = item.id.split('.')
const [type] = item.id.split('.');
if (type) {
o[type] = item.text
o[type] = item.text;
if (type === 'country' && item.short_code) {
o.countryCode = item.short_code.toUpperCase()
o.countryCode = item.short_code.toUpperCase();
}
}
return o
}, {})
return o;
}, {});
// get main type
const [type] = result.id.split('.')
const [type] = result.id.split('.');
if (type) {
context[type] = result.text
context[type] = result.text;
}
const properties = result.properties || {}
const properties = result.properties || {};

@@ -145,17 +148,17 @@ const extractedObj = {

}
}
};
return extractedObj
return extractedObj;
}
_prepareQueryString (params) {
OPTIONS.forEach((key) => {
const val = this.options[key]
_prepareQueryString(params) {
OPTIONS.forEach(key => {
const val = this.options[key];
if (val) {
const _key = OPTIONS_MAP[key] || key
params[_key] = val
const _key = OPTIONS_MAP[key] || key;
params[_key] = val;
}
})
});
return params
return params;
}

@@ -167,7 +170,7 @@ }

get: function () {
return 'https://api.mapbox.com/geocoding/v5/mapbox.places'
return 'https://api.mapbox.com/geocoding/v5/mapbox.places';
}
}
})
});
module.exports = MapBoxGeocoder
module.exports = MapBoxGeocoder;

@@ -6,5 +6,2 @@ 'use strict';

const HttpAdapter = require('./httpadapter/httpadapter.js');
const HttpsAdapter = require('./httpadapter/httpsadapter.js');
const RequestAdapter = require('./httpadapter/requestadapter.js');
const FetchAdapter = require('./httpadapter/fetchadapter.js');

@@ -44,11 +41,2 @@

_getHttpAdapter: function (adapterName, options) {
if (adapterName === 'http') {
return new HttpAdapter(null, options);
}
if (adapterName === 'https') {
return new HttpsAdapter(null, options);
}
if (adapterName === 'request') {
return new RequestAdapter(null, options);
}
if (adapterName === 'fetch') {

@@ -191,11 +179,9 @@ return new FetchAdapter(options);

* @param <string|object> geocoderAdapter Geocoder adapter name or adapter object
* @param <string|object> httpAdapter Http adapter name or adapter object
* @param <array> extra Extra parameters array
* @return <object>
*/
getGeocoder: function (geocoderAdapter, httpAdapter, extra) {
getGeocoder: function (geocoderAdapter, extra) {
if (typeof geocoderAdapter === 'object') {
extra = geocoderAdapter;
geocoderAdapter = null;
httpAdapter = null;
}

@@ -207,6 +193,2 @@

if (extra.httpAdapter) {
httpAdapter = extra.httpAdapter;
}
if (extra.provider) {

@@ -216,6 +198,2 @@ geocoderAdapter = extra.provider;

if (!httpAdapter) {
httpAdapter = 'fetch';
}
if (!geocoderAdapter) {

@@ -225,5 +203,3 @@ geocoderAdapter = 'google';

if (Helper.isString(httpAdapter)) {
httpAdapter = this._getHttpAdapter(httpAdapter, extra);
}
const httpAdapter = this._getHttpAdapter('fetch', extra);

@@ -230,0 +206,0 @@ if (Helper.isString(geocoderAdapter)) {

{
"name": "node-geocoder",
"version": "3.29.0",
"version": "4.0.0",
"description": "Node Geocoder, node geocoding library, supports google maps, mapquest, open street map, tom tom, promise",
"main": "index.js",
"engines": {
"node": ">=12"
},
"scripts": {

@@ -34,5 +37,3 @@ "test": "jest --maxWorkers=2 ./test",

"bluebird": "^3.5.2",
"node-fetch": "^2.6.0",
"request": "^2.88.0",
"request-promise": "^4.2.2"
"node-fetch": "^2.6.0"
},

@@ -39,0 +40,0 @@ "devDependencies": {

@@ -131,6 +131,2 @@ # node-geocoder

## Http adapter
Http adapter is deprecated, you can now use the `fetch` to provide your own fetch method compatible with the Fetch API [https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
## Fetch option

@@ -137,0 +133,0 @@

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