Comparing version 1.0.0 to 1.0.1
@@ -1,21 +0,21 @@ | ||
// haversine | ||
// By Nick Justice (niix) | ||
// https://github.com/niix/haversine | ||
var haversine = (function () { | ||
var haversine = (function() { | ||
// convert to radians | ||
var toRad = function(num) { | ||
var toRad = function (num) { | ||
return num * Math.PI / 180 | ||
} | ||
return function haversine(start, end, options) { | ||
var km = 6371 | ||
var mile = 3960 | ||
return function haversine (start, end, options) { | ||
options = options || {} | ||
var R = options.unit === 'mile' ? | ||
mile : | ||
km | ||
var radii = { | ||
km: 6371, | ||
mile: 3960, | ||
meter: 6371000 | ||
} | ||
var R = options.unit in radii | ||
? radii[options.unit] | ||
: radii.km | ||
var dLat = toRad(end.latitude - start.latitude) | ||
@@ -32,5 +32,5 @@ var dLon = toRad(end.longitude - start.longitude) | ||
return options.threshold > (R * c) | ||
} else { | ||
return R * c | ||
} | ||
return R * c | ||
} | ||
@@ -40,2 +40,4 @@ | ||
module.exports = haversine | ||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = haversine | ||
} |
{ | ||
"name": "haversine", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A simple haversine module", | ||
@@ -5,0 +5,0 @@ "main": "haversine.js", |
# Haversine | ||
A simple haversine formula module for Node.js | ||
I created this small module for an application I created and figured I would package it up to share. | ||
## Installation | ||
@@ -10,3 +8,3 @@ `$ npm install haversine` | ||
## Usage | ||
### haversine(start, end, options) | ||
### haversine (start, end, options) | ||
@@ -25,7 +23,14 @@ var haversine = require('haversine') | ||
console.log(haversine(start, end)) | ||
console.log(haversine(start, end, {unit: 'km'})) | ||
console.log(haversine(start, end, {unit: 'mile'})) | ||
console.log(haversine(start, end, {unit: 'meter'})) | ||
console.log(haversine(start, end, {threshold: 1})) | ||
console.log(haversine(start, end, {threshold: 1, unit: 'km'})) | ||
- | ||
console.log(haversine(start, end, {threshold: 1, unit: 'mile'})) | ||
console.log(haversine(start, end, {threshold: 1, unit: 'meter'})) | ||
#### api | ||
- `options.unit` - Unit of measurement applied to result (default `km`) | ||
- `options.threshold` - If passed, will result in library returning `boolean` value of whether or not the start and end points are within that supplied threshold. (default `null`) | ||
[MIT License](http://opensource.org/licenses/MIT) |
@@ -26,7 +26,7 @@ var haversine = require('../haversine') | ||
test('it should return ' + t[2] + ' mi for ' + t[0] + ' .. ' + t[1], function(){ | ||
assert.equal(Math.abs((haversine(t[0],t[1])-t[2])/t[2]).toFixed(2), "0.61") | ||
assert.equal(Math.abs((haversine(t[0],t[1], {unit: 'mile'})-t[2])/t[2]).toFixed(2), "0.00") | ||
}) | ||
} else { | ||
test('it should return ' + t[2] + ' km for ' + t[0] + ' .. ' + t[1], function(){ | ||
assert.equal(Math.abs((haversine(t[0],t[1])-t[2])/t[2], {unit: 'km'}).toFixed(2), "0.00") | ||
assert.equal(Math.abs((haversine(t[0],t[1])-t[2])/t[2]).toFixed(2), "0.00") | ||
}) | ||
@@ -33,0 +33,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4065
8
76
35