s-haversine
Advanced tools
Comparing version 1.0.5 to 1.1.0
39
index.js
'use strict'; | ||
var haversine = module.exports = {}; | ||
const haversine = module.exports = {}; | ||
@@ -13,3 +13,3 @@ | ||
// --------------------------------------- | ||
haversine.degreesToRadians = function(deg) { | ||
haversine.degToRad = function(deg) { | ||
return deg * (Math.PI / 180); | ||
@@ -23,16 +23,16 @@ }; | ||
var lat1 = coords1[0]; | ||
var lon1 = coords1[1]; | ||
var lat2 = coords2[0]; | ||
var lon2 = coords2[1]; | ||
const lat1 = coords1[0]; | ||
const lon1 = coords1[1]; | ||
const lat2 = coords2[0]; | ||
const lon2 = coords2[1]; | ||
var latitudeDifference = this.degreesToRadians(lat2 - lat1); | ||
var logitudeDifference = this.degreesToRadians(lon2 - lon1); | ||
const latitudeDifference = this.degToRad(lat2 - lat1); | ||
const logitudeDifference = this.degToRad(lon2 - lon1); | ||
var haversine = | ||
Math.sin(latitudeDifference/2) * Math.sin(latitudeDifference/2) + | ||
Math.cos(this.degreesToRadians(lat1)) * Math.cos(this.degreesToRadians(lat2)) * | ||
Math.sin(logitudeDifference/2) * Math.sin(logitudeDifference/2); | ||
const n = | ||
Math.sin(latitudeDifference / 2) * Math.sin(latitudeDifference / 2) + | ||
Math.cos(this.degToRad(lat1)) * Math.cos(this.degToRad(lat2)) * | ||
Math.sin(logitudeDifference / 2) * Math.sin(logitudeDifference / 2); | ||
var distance = 2 * Math.atan2(Math.sqrt(haversine), Math.sqrt(1 - haversine)); | ||
const distance = 2 * Math.atan2(Math.sqrt(n), Math.sqrt(1 - n)); | ||
@@ -49,4 +49,5 @@ return this.earthRadius * distance; | ||
str = str.toLowerCase(); // throws if input is not a string | ||
var lastChar = str.slice(-1); | ||
var negative = false; | ||
const lastChar = str.slice(-1); | ||
let negative = false; | ||
@@ -57,5 +58,7 @@ if (lastChar === 'w' || lastChar === 's') { | ||
var values = str.split(/[^0-9.]/); | ||
var i; | ||
const values = str.split(/[^0-9.]/); | ||
// convert strings to numbers | ||
let i; | ||
for (i = 0; i < values.length; i++) { | ||
@@ -78,3 +81,3 @@ | ||
var result = values[0] + (values[1] / 60) + (values[2] / 3600); | ||
const result = values[0] + (values[1] / 60) + (values[2] / 3600); | ||
@@ -81,0 +84,0 @@ if (negative) { |
{ | ||
"name": "s-haversine", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
"node": ">= 1.0.0" | ||
}, | ||
@@ -12,6 +12,15 @@ "description": "Get distance between any two latitute/longitude coordinates", | ||
}, | ||
"files": ["index.js", "test", "README.md", "etc/coverage.html"], | ||
"files": [ | ||
"index.js", | ||
"test", | ||
"README.md", | ||
"etc" | ||
], | ||
"scripts": { | ||
"test": "mocha", | ||
"coverage": "mocha --require blanket --reporter mocha-lcov-reporter > etc/lcov.info" | ||
"posttest": "npm run lint", | ||
"lint": "jscs *.js --config=./etc/.jscs.json && eslint *.js -c etc/.eslint.json", | ||
"postlint": "npm run coverage", | ||
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -dir etc --report lcovonly -- test/ -R spec", | ||
"postcoverage": "rm etc/coverage.json" | ||
}, | ||
@@ -28,3 +37,4 @@ "repository": { | ||
"distance", | ||
"haversine" | ||
"haversine", | ||
"great circle" | ||
], | ||
@@ -38,12 +48,10 @@ "author": "sebastian sandqvist", | ||
"devDependencies": { | ||
"blanket": "1.1.6", | ||
"@seabass/eslint-config": "^1.0.4", | ||
"chai": "^2.1.2", | ||
"codeclimate-test-reporter": "0.0.4", | ||
"gulp": "^3.8.11", | ||
"gulp-jshint": "^1.9.4", | ||
"gulp-mocha": "^2.0.0", | ||
"jshint-stylish": "^1.0.1", | ||
"mocha": "^2.2.1", | ||
"mocha-lcov-reporter": "0.0.2" | ||
"eslint": "^1.3.1", | ||
"istanbul": "^0.3.19", | ||
"jscs": "^2.1.1", | ||
"mocha": "^2.2.1" | ||
} | ||
} |
// ----- dependencies | ||
// --------------------------------------- | ||
require('blanket')({ | ||
pattern: function (filename) { | ||
return !/node_modules/.test(filename); | ||
} | ||
}); | ||
var expect = require('chai').expect; | ||
@@ -44,6 +38,6 @@ var haversine = require('../index.js'); | ||
it('should convert degrees to radians', function() { | ||
expect(haversine.degreesToRadians(0)).to.equal(0); | ||
expect(haversine.degreesToRadians(15)).to.equal(Math.PI / 12); | ||
expect(haversine.degreesToRadians(180)).to.equal(Math.PI); | ||
expect(haversine.degreesToRadians(360)).to.equal(Math.PI * 2); | ||
expect(haversine.degToRad(0)).to.equal(0); | ||
expect(haversine.degToRad(15)).to.equal(Math.PI / 12); | ||
expect(haversine.degToRad(180)).to.equal(Math.PI); | ||
expect(haversine.degToRad(360)).to.equal(Math.PI * 2); | ||
}); | ||
@@ -50,0 +44,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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
7
8
159
11116
1