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

haversine

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

haversine - npm Package Compare versions

Comparing version 0.0.4 to 1.0.0

Makefile

8

haversine.js

@@ -13,7 +13,9 @@ // haversine

return function haversine(start, end, options) {
var miles = 3960
var km = 6371
var mile = 3960
options = options || {}
var R = options.unit === 'km' ? km : miles
var R = options.unit === 'mile' ?
mile :
km

@@ -33,3 +35,3 @@ var dLat = toRad(end.latitude - start.latitude)

return R * c
}
}
}

@@ -36,0 +38,0 @@

{
"name": "haversine",
"version": "0.0.4",
"version": "1.0.0",
"description": "A simple haversine module",

@@ -10,3 +10,3 @@ "main": "haversine.js",

"scripts": {
"test": "./test/test.js"
"test": "mocha test/test.js --ui tdd"
},

@@ -24,3 +24,6 @@ "repository": {

"author": "Nick Justice (niix)",
"license": "MIT"
"license": "MIT",
"devDependencies": {
"mocha": "*"
}
}

@@ -26,2 +26,5 @@ # Haversine

console.log(haversine(start, end, {threshold: 1}))
console.log(haversine(start, end, {threshold: 1, unit: 'km'}))
console.log(haversine(start, end, {threshold: 1, unit: 'km'}))
-
[MIT License](http://opensource.org/licenses/MIT)

@@ -1,26 +0,42 @@

var haversine = require('../haversine');
var haversine = require('../haversine')
, assert = require('assert')
start = {
latitude: 30.849635,
longitude: -83.24559
}
suite('haversine', function(){
end = {
latitude: 27.950575,
longitude: -82.457178
}
var start = {
latitude: 38.898556,
longitude: -77.037852
}
// inserting values directly
console.log(haversine({latitude: 12, longitude: 11}, {latitude: 10, longitude: 10}))
var end = {
latitude: 38.897147,
longitude: -77.043934
}
// using objects
console.log(haversine(start, end))
// All tests are rounded for sanity.
// using objects with unit conversion
console.log(haversine(start, end, {unit: 'km'}))
var tests = [
[start, end, 0.341],
[start, end, 0.549]
]
// utilizing the threshold option
console.log(haversine(start, end, {threshold: 1}))
tests.forEach(function(t, i) {
if (i === 0) {
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")
})
} 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")
})
}
})
// utilizing the threshold option & unit conversion
console.log(haversine(start, end, {threshold: 1, unit: 'km'}))
test('it should return false that distance is within 1 mi threshold', function(){
assert.equal(false, haversine(tests[0], tests[0], {threshold: 1}))
})
test('it should return false that distance is within 1 km threshold', function(){
assert.equal(false, haversine(tests[1], tests[1], {threshold: 1, unit: 'km'}))
})
})
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