New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

geobatch

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geobatch - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

dist/geocode-stream.js

38

CHANGELOG.md

@@ -0,1 +1,39 @@

### 1.1.1 (2015-10-13)
#### Bug Fixes
* **npm-scripts:** remove `./node_modules/.bin/` from modules call ([bab003df](https://github.com/ubilabs/node-geobatch/commit/bab003df3c0d22a8e891d960e8cf44e020349264))
* **test:** use babel-core as mocha compilers plugin for testing ([54063f16](https://github.com/ubilabs/node-geobatch/commit/54063f1609e34c2fc25580cb77ba31486656a674))
* **tests:** fix rebase bug ([d5a58e14](https://github.com/ubilabs/node-geobatch/commit/d5a58e14ee0943b5fefec7f4756bd11d4cb6338a))
#### Features
* **GeoBatch:** make geocode accept streams ([0a032e74](https://github.com/ubilabs/node-geobatch/commit/0a032e74b3f1655ce7f5bec09461efdc46a3cc42))
* **geobatch:** take accessor function for address ([7588f2ca](https://github.com/ubilabs/node-geobatch/commit/7588f2ca9e3eb23c40506b658a8be6ff910adaa1))
* **geocode stream:** handle stats if input is stream ([f2cdbd89](https://github.com/ubilabs/node-geobatch/commit/f2cdbd892bd48c1294237a18ec56ff0dbaa8187c))
* **geocoder:** return full geocoding result ([ec20a890](https://github.com/ubilabs/node-geobatch/commit/ec20a8908cfec55c8ec50dfe11b2265649bebee2))
* **geocodestream:** add full input and full result to output stream ([9bd0630c](https://github.com/ubilabs/node-geobatch/commit/9bd0630cd2910695725f0aa954d0871ef2b5622e))
## 1.1.0 (2015-10-13)
#### Bug Fixes
* **npm-scripts:** remove `./node_modules/.bin/` from modules call ([bab003df](https://github.com/ubilabs/node-geobatch/commit/bab003df3c0d22a8e891d960e8cf44e020349264))
* **test:** use babel-core as mocha compilers plugin for testing ([54063f16](https://github.com/ubilabs/node-geobatch/commit/54063f1609e34c2fc25580cb77ba31486656a674))
* **tests:** fix rebase bug ([d5a58e14](https://github.com/ubilabs/node-geobatch/commit/d5a58e14ee0943b5fefec7f4756bd11d4cb6338a))
#### Features
* **GeoBatch:** make geocode accept streams ([0a032e74](https://github.com/ubilabs/node-geobatch/commit/0a032e74b3f1655ce7f5bec09461efdc46a3cc42))
* **geobatch:** take accessor function for address ([7588f2ca](https://github.com/ubilabs/node-geobatch/commit/7588f2ca9e3eb23c40506b658a8be6ff910adaa1))
* **geocode stream:** handle stats if input is stream ([f2cdbd89](https://github.com/ubilabs/node-geobatch/commit/f2cdbd892bd48c1294237a18ec56ff0dbaa8187c))
* **geocoder:** return full geocoding result ([ec20a890](https://github.com/ubilabs/node-geobatch/commit/ec20a8908cfec55c8ec50dfe11b2265649bebee2))
* **geocodestream:** add full input and full result to output stream ([9bd0630c](https://github.com/ubilabs/node-geobatch/commit/9bd0630cd2910695725f0aa954d0871ef2b5622e))
## 1.1.0 (2015-03-10)

@@ -2,0 +40,0 @@

64

dist/array-stream.js

@@ -1,6 +0,17 @@

"use strict";
'use strict';
var stream = require("stream"),
util = require("util");
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var stream = require('stream');
/**

@@ -10,23 +21,36 @@ * Create a stream from an array

*/
function ArrayStream(values) {
stream.Readable.call(this, { objectMode: true });
this.values = values;
this.currentIndex = 0;
}
util.inherits(ArrayStream, stream.Readable);
var ArrayStream = (function (_stream$Readable) {
_inherits(ArrayStream, _stream$Readable);
/**
* The _read function for the addresses stream.
*/
/* eslint-disable no-underscore-dangle */
ArrayStream.prototype._read = function () {
/* eslint-enable no-underscore-dangle */
if (this.currentIndex === this.values.length) {
return this.push(null);
function ArrayStream(values) {
_classCallCheck(this, ArrayStream);
_get(Object.getPrototypeOf(ArrayStream.prototype), 'constructor', this).call(this, { objectMode: true });
this.values = values;
this.currentIndex = 0;
}
this.push(this.values[this.currentIndex++]);
};
/**
* The _read function for the addresses stream.
*/
/* eslint-disable no-underscore-dangle */
module.exports = ArrayStream;
_createClass(ArrayStream, [{
key: '_read',
value: function _read() {
/* eslint-enable no-underscore-dangle */
if (this.currentIndex === this.values.length) {
return this.push(null);
}
this.push(this.values[this.currentIndex++]);
}
}]);
return ArrayStream;
})(stream.Readable);
exports['default'] = ArrayStream;
module.exports = exports['default'];

@@ -1,45 +0,75 @@

"use strict";
/* eslint-disable one-var */
'use strict';
var flatfile = require("flat-file-db");
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _flatFileDb = require('flat-file-db');
var _flatFileDb2 = _interopRequireDefault(_flatFileDb);
/**
* Cache instance stores already done geocodings
* @type {Function}
* Cache instance to store key value pairs.
* @type {Class}
* @param {String} cacheFile The name of the file to cache
*/
var Cache = function Cache() {
var cacheFile = arguments[0] === undefined ? "geocache.db" : arguments[0];
this.db = flatfile.sync(cacheFile);
};
var Cache = (function () {
/**
* Constructs the Cache.
* @param {String} cacheFile The filename for the cache.
*/
/**
* Add new entries to the Cache
* @param {String} address The address that shall be cached
* @param {Object} result The geocoded location
* @param {Function} callback The callback
*/
Cache.prototype.add = function (address, result) {
var callback = arguments[2] === undefined ? function () {} : arguments[2];
function Cache() {
var cacheFile = arguments.length <= 0 || arguments[0] === undefined ? 'geocache.db' : arguments[0];
this.db.put(address, result, function (error) {
if (error) {
throw error;
_classCallCheck(this, Cache);
this.db = _flatFileDb2['default'].sync(cacheFile);
}
/**
* Add new entries to the Cache
* @param {String} key The key that shall be cached
* @param {Object} value The value that should be stored in the cache
* @param {Function} callback The callback
*/
_createClass(Cache, [{
key: 'add',
value: function add(key, value) {
var callback = arguments.length <= 2 || arguments[2] === undefined ? function () {} : arguments[2];
this.db.put(key, value, function (error) {
if (error) {
throw error;
}
callback();
});
}
callback();
});
};
/**
* Add new entries to the Cache
* @param {String} key The key that should be retrieved
* @return {Object} The value
*/
}, {
key: 'get',
value: function get(key) {
return this.db.get(key);
}
}]);
/**
* Add new entries to the Cache
* @param {String} address The address that shall be cached
* @return {Object} The geocoded result
*/
Cache.prototype.get = function (address) {
return this.db.get(address);
};
return Cache;
})();
module.exports = Cache;
exports['default'] = Cache;
module.exports = exports['default'];

@@ -1,102 +0,138 @@

"use strict";
/* eslint-disable one-var */
var Cache = require("./cache"),
isEmpty = require("amp-is-empty");
'use strict';
/**
* Geocoder instance
* @type {Function}
* @param {Object} options The options for the Geocoder
*/
var Geocoder = function Geocoder() {
var options = arguments[0] === undefined ? {} : arguments[0];
Object.defineProperty(exports, '__esModule', {
value: true
});
options.clientId = options.clientId || null;
options.privateKey = options.privateKey || null;
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
if (options.clientId && !options.privateKey) {
throw new Error("Missing privateKey");
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
if (!options.clientId && options.privateKey) {
throw new Error("Missing clientId");
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
this.timeBetweenRequests = options.clientId && options.privateKey ? 100 : 200;
this.maxRequests = 20;
var _cache = require('./cache');
this.lastGeocode = new Date();
this.currentRequests = 0;
var _cache2 = _interopRequireDefault(_cache);
this.cache = new Cache(options.cacheFile);
this.googlemaps = require("googlemaps");
var _ampIsEmpty = require('amp-is-empty');
this.googlemaps.config("google-client-id", options.clientId);
this.googlemaps.config("google-private-key", options.privateKey);
};
var _ampIsEmpty2 = _interopRequireDefault(_ampIsEmpty);
/**
* Geocode a single address
* @param {String} address The address to geocode
* @return {Promise} The promise
*/
Geocoder.prototype.geocodeAddress = function (address) {
var _this = this;
var _libGoogleGeocoder = require('./lib/google-geocoder');
return new Promise(function (resolve, reject) {
_this.startGeocode(address, resolve, reject);
});
};
var _libGoogleGeocoder2 = _interopRequireDefault(_libGoogleGeocoder);
/**
* Start geocoding a single address
* @param {String} address The address to geocode
* @param {Function} resolve The Promise resolve function
* @param {Function} reject The Promise reject function
* @return {?} Something to get out
* Geocoder instance
* @type {Class}
* @param {Object} options The options for the Geocoder
*/
Geocoder.prototype.startGeocode = function (address, resolve, reject) {
var _this = this;
var cachedAddress = this.cache.get(address);
var Geocoder = (function () {
/**
* Constructs a geocoder.
* @param {Object} options Geocoder options.
*/
if (cachedAddress) {
return resolve(cachedAddress);
}
function Geocoder() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var geocoder = arguments.length <= 1 || arguments[1] === undefined ? _libGoogleGeocoder2['default'] : arguments[1];
var GeoCache = arguments.length <= 2 || arguments[2] === undefined ? _cache2['default'] : arguments[2];
var now = new Date();
_classCallCheck(this, Geocoder);
if (this.currentRequests >= this.maxRequests || now - this.lastGeocode <= this.timeBetweenRequests) {
return setTimeout(function () {
_this.startGeocode(address, resolve, reject);
}, this.timeBetweenRequests);
options.clientId = options.clientId || null;
options.privateKey = options.privateKey || null;
if (options.clientId && !options.privateKey) {
throw new Error('Missing privateKey');
}
if (!options.clientId && options.privateKey) {
throw new Error('Missing clientId');
}
this.timeBetweenRequests = options.clientId && options.privateKey ? 100 : 200;
this.maxRequests = 20;
this.lastGeocode = new Date();
this.currentRequests = 0;
this.cache = new GeoCache(options.cacheFile);
this.geocoder = geocoder.init(options);
}
this.currentRequests++;
this.lastGeocode = now;
/**
* Geocode a single address
* @param {String} address The address to geocode
* @return {Promise} The promise
*/
this.googlemaps.geocode(address.replace("'", ""), function (error, response) {
_this.currentRequests--;
_createClass(Geocoder, [{
key: 'geocodeAddress',
value: function geocodeAddress(address) {
var _this = this;
if (error) {
return reject(new Error("Wrong clientId or privateKey"));
return new Promise(function (resolve, reject) {
_this.startGeocode(address, resolve, reject);
});
}
if (response.status === "OVER_QUERY_LIMIT") {
return reject(new Error("Over query limit"));
}
/**
* Start geocoding a single address
* @param {String} address The address to geocode
* @param {Function} resolve The Promise resolve function
* @param {Function} reject The Promise reject function
* @return {?} Something to get out
*/
}, {
key: 'startGeocode',
value: function startGeocode(address, resolve, reject) {
var _this2 = this;
if (isEmpty(response.results)) {
return reject(new Error("No results found"));
var cachedAddress = this.cache.get(address);
if (cachedAddress) {
return resolve(cachedAddress);
}
var now = new Date();
if (this.currentRequests >= this.maxRequests || now - this.lastGeocode <= this.timeBetweenRequests) {
return setTimeout(function () {
_this2.startGeocode(address, resolve, reject);
}, this.timeBetweenRequests);
}
this.currentRequests++;
this.lastGeocode = now;
this.geocoder.geocode(address.replace('\'', ''), function (error, response) {
_this2.currentRequests--;
if (error) {
return reject(new Error('Wrong clientId or privateKey'));
}
if (response.status === 'OVER_QUERY_LIMIT') {
return reject(new Error('Over query limit'));
}
if ((0, _ampIsEmpty2['default'])(response.results)) {
return reject(new Error('No results found'));
}
var results = response.results;
_this2.cache.add(address, results);
return resolve(results);
});
}
}]);
var result = response.results[0];
return Geocoder;
})();
_this.cache.add(address, result);
return resolve(result);
});
};
module.exports = Geocoder;
exports['default'] = Geocoder;
module.exports = exports['default'];

@@ -1,107 +0,120 @@

"use strict";
/* eslint-disable one-var */
var stream = require("stream"),
util = require("util"),
ArrayStream = require("./array-stream"),
Geocoder = require("./geocoder");
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _intoStream = require('into-stream');
var _intoStream2 = _interopRequireDefault(_intoStream);
var _geocoder = require('./geocoder');
var _geocoder2 = _interopRequireDefault(_geocoder);
var _geocodeStream = require('./geocode-stream');
var _geocodeStream2 = _interopRequireDefault(_geocodeStream);
var _stream = require('stream');
var _stream2 = _interopRequireDefault(_stream);
/**
* GeoBatch instance
* @type {Function}
* @param {Object} options The options for the GeoBatch
* @param {Object} options The options for the GeoBatch, default is
* {cacheFile: 'geocache.db',
* clientId: null,
* privateKey: null}
* @param {Object} Geocoder A geocoder.
* @param {Object} GeocodeStream A GeocodeStream.
*/
var GeoBatch = function GeoBatch() {
var options = arguments[0] === undefined ? {} : arguments[0];
this.geocoder = new Geocoder({
cacheFile: options.cacheFile || "geocache.db",
clientId: options.clientId,
privateKey: options.privateKey
});
};
var GeoBatch = (function () {
function GeoBatch() {
var Geocoder = arguments.length <= 1 || arguments[1] === undefined ? _geocoder2['default'] : arguments[1];
/**
* Geocode the passed in addresses
* @param {Array} addresses The addresses to geocode
* @return {Function} The stream
*/
GeoBatch.prototype.geocode = function (addresses) {
var arrayStream = new ArrayStream(addresses),
geocodeStream = new GeocodeStream(this.geocoder);
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {
cacheFile: 'geocache.db',
clientId: null,
privateKey: null,
accessor: function accessor(address) {
return address;
}
} : arguments[0];
geocodeStream.stats = {
total: addresses.length,
current: 0,
startTime: new Date()
};
arrayStream.pipe(geocodeStream);
var _ref$cacheFile = _ref.cacheFile;
var cacheFile = _ref$cacheFile === undefined ? 'geocache.db' : _ref$cacheFile;
var _ref$clientId = _ref.clientId;
var clientId = _ref$clientId === undefined ? null : _ref$clientId;
var _ref$privateKey = _ref.privateKey;
var privateKey = _ref$privateKey === undefined ? null : _ref$privateKey;
var _ref$accessor = _ref.accessor;
var accessor = _ref$accessor === undefined ? function (address) {
return address;
} : _ref$accessor;
var GeocodeStream = arguments.length <= 2 || arguments[2] === undefined ? _geocodeStream2['default'] : arguments[2];
return geocodeStream;
};
_classCallCheck(this, GeoBatch);
/**
* A streaming object for the geocode
* @param {Object} geocoder The geocoder
*/
function GeocodeStream(geocoder) {
stream.Transform.call(this, { objectMode: true });
this.geocoder = new Geocoder({ cacheFile: cacheFile, clientId: clientId, privateKey: privateKey });
this.GeocodeStream = GeocodeStream;
this.accessor = accessor;
}
this.geocoder = geocoder;
}
util.inherits(GeocodeStream, stream.Transform);
/**
* Geocode the passed in addresses
* @param {Array/Stream} addresses The addresses to geocode
* @return {Function} The stream
*/
/* eslint-disable no-underscore-dangle */
/**
* The _transform function for the stream.
* @param {String} address The address to geocode
* @param {String} encoding The encoding
* @param {Function} done The done callback function
*/
GeocodeStream.prototype._transform = function (address, encoding, done) {
var _this = this;
_createClass(GeoBatch, [{
key: 'geocode',
value: function geocode(addresses) {
// If input is already stream, pass through directly.
if (addresses instanceof _stream2['default']) {
return this.geocodeStream(addresses);
}
/* eslint-enable no-underscore-dangle */
var arrayStream = _intoStream2['default'].obj(addresses),
stats = {
total: addresses.length,
current: 0,
startTime: new Date()
};
this.geocoder.geocodeAddress(address).then(function (result) {
var data = _this.getMetaInfo(address);
return this.geocodeStream(arrayStream, stats);
}
data.result = result;
data.location = result.geometry.location;
_this.push(data);
done();
})["catch"](function (error) {
var data = _this.getMetaInfo(address);
/**
* Geocode the elements of a passed in stream.
* @param {Stream} inputStream An input stream
* @param {Object} stats An object with the stream stats, defaults to {}.
* @return {Stream} A transformable stream.
*/
}, {
key: 'geocodeStream',
value: function geocodeStream(inputStream) {
var stats = arguments.length <= 1 || arguments[1] === undefined ? { current: 0 } : arguments[1];
data.error = error.message;
_this.push(data);
done();
});
};
var geocodeStream = new this.GeocodeStream(this.geocoder, stats, this.accessor);
inputStream.pipe(geocodeStream);
/**
* Get the result meta information
* @param {String} address The address
* @return {Object} The meta information
*/
GeocodeStream.prototype.getMetaInfo = function (address) {
this.stats.current++;
return geocodeStream;
}
}]);
var now = new Date(),
ratio = this.stats.current / this.stats.total;
return GeoBatch;
})();
return {
error: null,
address: address,
location: {},
result: {},
total: this.stats.total,
current: this.stats.current,
pending: this.stats.total - this.stats.current,
percent: ratio * 100,
estimatedDuration: Math.round((now - this.stats.startTime) / ratio)
};
};
module.exports = GeoBatch;
exports['default'] = GeoBatch;
module.exports = exports['default'];
{
"name": "geobatch",
"description": "Batch geocode addresses from multiple sources.",
"version": "1.1.0",
"version": "1.1.1",
"author": {

@@ -10,2 +10,9 @@ "name": "Robert Katzki",

},
"contributors": [
{
"name": "Patrick Mast",
"email": "mast@ubilabs.net",
"url": "http://ubilabs.net/"
}
],
"repository": {

@@ -17,11 +24,11 @@ "type": "git",

"scripts": {
"build": "./node_modules/.bin/babel src --out-dir dist",
"build": "babel src --out-dir dist",
"prepublish": "npm run lint && npm run build",
"pretest": "npm run lint",
"test": "./node_modules/.bin/babel-node ./node_modules/.bin/_mocha test",
"generatechangelog": "./node_modules/.bin/conventional-changelog-generator",
"test": "mocha --compilers js:babel-core/register",
"generatechangelog": "conventional-changelog-generator",
"commitchangelog": "git add CHANGELOG.md && git commit -m \"chore(changelog): new version\" && git push origin master",
"changelog": "npm run generatechangelog && git reset package.json && npm run commitchangelog && git add package.json",
"release": "git reset && ./node_modules/.bin/release-it",
"lint": "./node_modules/.bin/eslint ./src ./test"
"release": "git reset && release-it",
"lint": "eslint ./src ./test"
},

@@ -31,13 +38,19 @@ "dependencies": {

"flat-file-db": "^0.1.4",
"googlemaps": "^0.1.20"
"googlemaps": "^0.1.20",
"into-stream": "^2.0.0"
},
"devDependencies": {
"babel": "^4.7.5",
"babel": "^5.8.23",
"babel-core": "^5.8.25",
"conventional-changelog-generator": "0.0.3",
"eslint": "^0.15.1",
"eslint": "^1.6.0",
"into-stream": "^2.0.0",
"lie": "^3.0.1",
"mocha": "2.1.0",
"release-it": "0.0.15",
"should": "^5.0.1",
"should-promised": "^0.1.0"
"should": "^7.1.0",
"should-promised": "^0.1.0",
"sinon": "^1.17.1",
"stream-assert": "^2.0.3"
}
}
# node-geobatch
[![Build Status](https://travis-ci.org/ubilabs/node-geobatch.svg?branch=master)](https://travis-ci.org/ubilabs/node-geobatch) [![npm version](https://badge.fury.io/js/geobatch.svg)](http://badge.fury.io/js/geobatch)
[![forthebadge](http://forthebadge.com/images/badges/uses-badges.svg)](http://forthebadge.com)
Batch geocode addresses from multiple sources. It limits the calls to not run in `OVER_QUERY_LIMIT` by the Google Maps API. Results are cached locally to prevent duplicate geocoding requests.

@@ -28,2 +32,4 @@

`geoBatch.geocode` also accepts a stream as input.
### Result

@@ -37,2 +43,3 @@

address: 'Hamburg',
input: 'Hamburg',
location: { lat: 53.5510846, lng: 9.9936818 },

@@ -51,2 +58,14 @@ result: {

},
results: [{
address_components: [ … ],
formatted_address: 'Hamburg, Germany',
geometry: {
bounds: { northeast: [Object], southwest: [Object] },
location: { lat: 53.5510846, lng: 9.9936818 },
location_type: 'APPROXIMATE',
viewport: { northeast: [Object], southwest: [Object] } },
place_id: 'ChIJuRMYfoNhsUcRoDrWe_I9JgQ',
types: [ 'locality', 'political' ]
}]
},
total: 2,

@@ -68,2 +87,6 @@ current: 1,

#### `input`
Contains the original input. This was the input to the accessor function to get the `address`.
#### `location`

@@ -75,7 +98,11 @@

Type `Object`. The complete result from the Google Maps Geocoding API. Default `{}`.
Type `Object`. The complete first result item from the Google Maps Geocoding API. Default `{}`.
#### `results`
Type `Array`. The complete result from the Google Maps Geocoding API.
#### `total`
Type `Number`. The total number of addresses to geocode.
Type `Number`. The total number of addresses to geocode. (Not included if stream was provided.)

@@ -88,11 +115,11 @@ #### `current`

Type `Number`. The number of addresses to still geocode.
Type `Number`. The number of addresses to still geocode. (Not included if stream was provided.)
#### `percent`
Type `Number`. The percentage that got geocoded already.
Type `Number`. The percentage that got geocoded already. (Not included if stream was provided.)
#### `estimatedDuration`
Type `Number`. The estimated duration based on past progress. In milliseconds.
Type `Number`. The estimated duration based on past progress. In milliseconds. (Not included if stream was provided.)

@@ -107,3 +134,4 @@ ### Options

privateKey: 'myPrivateKey',
cacheFile: 'myGeocache.db'
cacheFile: 'myGeocache.db',
accessor: myAccessorFunction
});

@@ -124,2 +152,11 @@ ```

#### `accessor`
Type `Function`. An accessor function that extracts the address data from the provided input. Defaults to:
```js
function(address) {
return address;
}
```
## Contribution

@@ -126,0 +163,0 @@

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc