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

turf-nearest

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turf-nearest - npm Package Compare versions

Comparing version 0.1.3 to 1.0.0

bench.js

26

index.js

@@ -1,23 +0,23 @@

distance = require('turf-distance')
distance = require('turf-distance');
module.exports = function(targetPoint, points){
var nearestPoint
var count = 0
var dist = Infinity
var nearestPoint;
var count = 0;
var dist = Infinity;
points.features.forEach(function(pt){
if(!nearestPoint){
nearestPoint = pt
var dist = distance(targetPoint, pt, 'miles')
nearestPoint.properties.distance = dist
nearestPoint = pt;
var dist = distance(targetPoint, pt, 'miles');
nearestPoint.properties.distance = dist;
}
else{
var dist = distance(targetPoint, pt, 'miles')
var dist = distance(targetPoint, pt, 'miles');
if(dist < nearestPoint.properties.distance){
nearestPoint = pt
nearestPoint.properties.distance = dist
nearestPoint = pt;
nearestPoint.properties.distance = dist;
}
}
})
delete nearestPoint.properties.distance
return nearestPoint
});
delete nearestPoint.properties.distance;
return nearestPoint;
}
{
"name": "turf-nearest",
"version": "0.1.3",
"version": "1.0.0",
"description": "turf nearest module",

@@ -26,7 +26,8 @@ "main": "index.js",

"devDependencies": {
"tape": "^2.13.3"
"benchmark": "^1.0.0",
"tape": "^3.0.3"
},
"dependencies": {
"turf-distance": "^0.1.4"
"turf-distance": "^1.0.0"
}
}

@@ -1,16 +0,16 @@

var test = require('tape')
var nearest = require('./')
var fs = require('fs')
var test = require('tape');
var nearest = require('./');
var fs = require('fs');
test('distance', function(t){
var pt = JSON.parse(fs.readFileSync(__dirname+'/geojson/pt.geojson'))
var pts = JSON.parse(fs.readFileSync(__dirname+'/geojson/pts.geojson'))
var pt = JSON.parse(fs.readFileSync(__dirname+'/geojson/pt.geojson'));
var pts = JSON.parse(fs.readFileSync(__dirname+'/geojson/pts.geojson'));
var closestPt = nearest(pt, pts)
var closestPt = nearest(pt, pts);
t.ok(closestPt, 'should return a point')
t.equal(closestPt.geometry.type, 'Point', 'should be a point')
t.equal(closestPt.geometry.coordinates[0], -75.33, 'lon -75.33')
t.equal(closestPt.geometry.coordinates[1], 39.44, 'lat 39.44')
t.end()
})
t.ok(closestPt, 'should return a point');
t.equal(closestPt.geometry.type, 'Point', 'should be a point');
t.equal(closestPt.geometry.coordinates[0], -75.33, 'lon -75.33');
t.equal(closestPt.geometry.coordinates[1], 39.44, 'lat 39.44');
t.end();
});
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