UNPKG

geohash-cli

Version:

CLI to find as much info as possible about today's (or any date's) geohashes.

56 lines (37 loc) 1.59 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug); var _geoGraticule = require('geo-graticule'); var _geoGraticule2 = _interopRequireDefault(_geoGraticule); var _keyBy = require('lodash/keyBy'); var _keyBy2 = _interopRequireDefault(_keyBy); var _transform = require('lodash/transform'); var _transform2 = _interopRequireDefault(_transform); var _geohashCoordinates = require('geohash-coordinates'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var debug = (0, _debug2.default)('geohash:coordinates'); var toGeo = function toGeo(val) { return new _geoGraticule2.default(val); }; var getCoordinates = function getCoordinates(options, cb) { var location = toGeo(options.location); (0, _geohashCoordinates.latest)(options, function (err, result) { if (err) return cb(err); var graticule = toGeo(result[0].graticule); debug('Location ' + location); debug('Graticule: ' + graticule); var byDate = (0, _transform2.default)((0, _keyBy2.default)(result, 'date'), function (result, value, key) { var global = toGeo(value.global); var geohashes = value.neighbors.map(toGeo); debug('Global ' + key + ' ' + location); debug('Geohashes ' + key + ' ' + geohashes); result[key] = { global: global, geohashes: geohashes }; }); // Geoify everything cb(null, { byDate: byDate, graticule: graticule, location: location }); }); }; exports.default = getCoordinates;