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

geokit

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geokit - npm Package Compare versions

Comparing version 0.0.3 to 0.1.1

16

CHANGELOG.md

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

#### 0.1.1 (2018-06-02)
##### Bug Fixes
* **distance:** set default unit so doesn't fail ([0001a29e](https://github.com/MichaelSolati/geokit/commit/0001a29e507ca90f45959fcf97d0f79d583e8ef5))
### 0.1.0 (2018-06-02)
##### Chores
* update dependencies ([af42f559](https://github.com/MichaelSolati/geokit/commit/af42f5594351d91500ac9b7331535101b9e880d5))
##### New Features
* **decodeHash:** add functionality to decode a geohash ([5922a2f0](https://github.com/MichaelSolati/geokit/commit/5922a2f06851f8fb3885b2046d0ac4d90f207cb9))
#### 0.0.3 (2018-03-24)

@@ -2,0 +18,0 @@

@@ -21,2 +21,8 @@ import { LatLngLiteral } from './interfaces';

static hash(coordinates: LatLngLiteral, precision?: number): string;
/**
* Decodes a Geohash into a LatLngLiteral.
* @param hash Geohash string.
* @returns Coordinates to hash.
*/
static decodeHash(hash: string): LatLngLiteral;
}

25

dist/geokit.js

@@ -18,2 +18,3 @@ "use strict";

Geokit.distance = function (start, end, unit) {
if (unit === void 0) { unit = 'km'; }
var startValid = helpers_1.validateCoordinates(start);

@@ -27,3 +28,3 @@ if (startValid instanceof Error) {

}
var radius = (unit === 'miles') ? 3963 : 6371;
var radius = (unit.toLowerCase() === 'miles') ? 3963 : 6371;
var dLat = helpers_1.toRad(end.lat - start.lat);

@@ -67,4 +68,26 @@ var dLon = helpers_1.toRad(end.lng - start.lng);

};
/**
* Decodes a Geohash into a LatLngLiteral.
* @param hash Geohash string.
* @returns Coordinates to hash.
*/
Geokit.decodeHash = function (hash) {
var even = true;
var latRng = [-90, 90];
var lngRng = [-180, 180];
var hashChars = hash.split('');
while (hashChars.length) {
var chunk = helpers_1.decimalChunk(hashChars.shift());
for (var i = 0; i < 5; i++) {
var mask = [16, 8, 4, 2, 1][i];
var range = (even) ? lngRng : latRng;
var middle = (range[0] + range[1]) / 2;
range[((chunk & mask) ? 0 : 1)] = middle;
even = !even;
}
}
return { lat: ((latRng[0] + latRng[1]) / 2), lng: ((lngRng[0] + lngRng[1]) / 2) };
};
return Geokit;
}());
exports.Geokit = Geokit;

@@ -9,2 +9,8 @@ import { LatLngLiteral } from './interfaces';

/**
* Get decimal chunk (5 bit binary value) from Base 32 character.
* @param value Base 32 character.
* @returns Decimal value of chunk (5 bit binary value).
*/
export declare function decimalChunk(value: string): number;
/**
* Determine if coordinate is greater than midle of range in a bit representation.

@@ -11,0 +17,0 @@ * @param point Coordinates.

@@ -13,2 +13,11 @@ "use strict";

/**
* Get decimal chunk (5 bit binary value) from Base 32 character.
* @param value Base 32 character.
* @returns Decimal value of chunk (5 bit binary value).
*/
function decimalChunk(value) {
return '0123456789bcdefghjkmnpqrstuvwxyz'.indexOf(value.toLowerCase());
}
exports.decimalChunk = decimalChunk;
/**
* Determine if coordinate is greater than midle of range in a bit representation.

@@ -15,0 +24,0 @@ * @param point Coordinates.

21

package.json
{
"name": "geokit",
"version": "0.0.3",
"version": "0.1.1",
"description": "An assortment of geolocation related tools, all packaged in one easy to use kit.",

@@ -23,3 +23,4 @@ "main": "dist/index.js",

"coordinates",
"geohash"
"geohash",
"toolkit"
],

@@ -33,12 +34,12 @@ "author": "Michael Solati",

"devDependencies": {
"@types/chai": "^4.1.2",
"@types/mocha": "^2.2.48",
"@types/chai": "^4.1.3",
"@types/mocha": "^5.2.1",
"chai": "^4.1.2",
"firebase-tools": "^3.12.0",
"generate-changelog": "^1.5.0",
"mocha": "^5.0.4",
"ts-node": "^5.0.1",
"typedoc": "^0.8.0",
"typescript": "^2.5.3"
"firebase-tools": "^3.18.5",
"generate-changelog": "^1.7.1",
"mocha": "^5.2.0",
"ts-node": "^6.0.5",
"typedoc": "^0.11.1",
"typescript": "^2.9.1"
}
}

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

# geokit [![Build Status](https://travis-ci.org/MichaelSolati/geokit.svg?branch=master)](https://travis-ci.org/MichaelSolati/geokit)
An assortment of geolocation related tools, all packaged in one easy to use kit.
# Geokit [![Build Status](https://travis-ci.org/MichaelSolati/geokit.svg?branch=master)](https://travis-ci.org/MichaelSolati/geokit) [![npm version](https://badge.fury.io/js/geokit.svg)](https://badge.fury.io/js/geokit)
An assortment of geolocation related tools, all packaged in one easy to use kit.
## Methods
### `Geokit.distance(start: LatLngLiteral, end: LatLngLiteral, unit?: string): number`
Static method which returns the distance, in kilometers, between `start` and `end`.
`start` and `end` must be LatLngLiterals `{ lat: 0, lng: 0 }`.
There exists an optional third argument, where if the string `'miles'` is inputted, the result returned will be in miles rather than kilometers.
```TypeScript
import { Geokit, LatLngLiteral } from 'geokit';
const start: LatLngLiteral = { lat: 40.7128, lng: -74.0060 };
const end: LatLngLiteral = { lat: 37.7749, lng: -122.4194 };
const distance: number = Geokit.distance(location1, location2, 'miles'); // distance === 2568.4458439997047
```
### `Geokit.hash(coordinates: LatLngLiteral, precision?: number): string`
Static method which generates the geohash of a point.
`coordinates` must be LatLngLiterals `{ lat: 0, lng: 0 }`.
There exists an optional second argument of precision, where the hash produced will be as many characters as the number inputted. It defaults to 10.
```TypeScript
import { Geokit, LatLngLiteral } from 'geokit';
const coordinates: LatLngLiteral = { lat: 41.3083, lng: -72.9279 };
const hash: string = Geokit.hash(coordinates); // hash === 'drk4urzw2c'
```
### `Geokit.decodeHash(hash: string): LatLngLiteral`
Static method which decodes geohash into its Latitude and Longitude as a LatLngLiteral.
```TypeScript
import { Geokit, LatLngLiteral } from 'geokit';
const hash: string = 'r3gx2f77b';
const coordinates: LatLngLiteral = Geokit.decodeHash(hash); // coordinates === { lat: -33.86881113052368, lng: 151.2093186378479 }
```

@@ -32,2 +32,10 @@ import { Geokit } from '../src/geokit';

});
it('Hash \'drk4urzw2c\' should yield coordinates 41.30830138921738, -72.9278951883316', () => {
expect(Geokit.decodeHash('drk4urzw2c')).to.deep.equal({ lat: 41.30830138921738, lng: -72.9278951883316 });
});
it('Hash \'r3gx2f77b\' should yield coordinates -33.86881113052368, 151.2093186378479', () => {
expect(Geokit.decodeHash('r3gx2f77b')).to.deep.equal({ lat: -33.86881113052368, lng: 151.2093186378479 });
});
});
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