New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@turf/line-distance

Package Overview
Dependencies
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/line-distance - npm Package Compare versions

Comparing version 3.3.3 to 3.5.2-alpha.d2c36ee7

6

index.js

@@ -5,6 +5,6 @@ var distance = require('@turf/distance');

/**
* Takes a {@link LineString|line} and measures its length in the specified units.
* Takes a {@link LineString} or {@link Polygon} and measures its length in the specified units.
*
* @name lineDistance
* @param {Feature<LineString>} line line to measure
* @param {Feature<(LineString|Polygon)>|FeatureCollection<(LineString|Polygon)>} line line to measure
* @param {String} [units=kilometers] can be degrees, radians, miles, or kilometers

@@ -53,3 +53,3 @@ * @return {Number} length of the input line

return d;
} else if (line.type === 'MultiPolygon') {
} else if (geometry.type === 'MultiPolygon') {
d = 0;

@@ -56,0 +56,0 @@ for (i = 0; i < geometry.coordinates.length; i++) {

{
"name": "@turf/line-distance",
"version": "3.3.3",
"version": "3.5.2-alpha.d2c36ee7",
"description": "turf-line-distance ---",

@@ -32,5 +32,5 @@ "main": "index.js",

"dependencies": {
"@turf/distance": "^3.3.3",
"@turf/helpers": "^3.3.3"
"@turf/distance": "^3.5.2-alpha.d2c36ee7",
"@turf/helpers": "^3.5.2-alpha.d2c36ee7"
}
}

@@ -5,7 +5,7 @@ # @turf/line-distance

Takes a [line](http://geojson.org/geojson-spec.html#linestring) and measures its length in the specified units.
Takes a [LineString](http://geojson.org/geojson-spec.html#linestring) or [Polygon](http://geojson.org/geojson-spec.html#polygon) and measures its length in the specified units.
**Parameters**
- `line` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;[LineString](http://geojson.org/geojson-spec.html#linestring)>** line to measure
- `line` **([Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;([LineString](http://geojson.org/geojson-spec.html#linestring) \| [Polygon](http://geojson.org/geojson-spec.html#polygon))> | [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)&lt;([LineString](http://geojson.org/geojson-spec.html#linestring) \| [Polygon](http://geojson.org/geojson-spec.html#polygon))>)** line to measure
- `units` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** can be degrees, radians, miles, or kilometers (optional, default `kilometers`)

@@ -41,2 +41,6 @@

<!-- This file is automatically generated. Please don't edit it directly:
if you find an error, edit the source file (likely index.js), and re-run
./scripts/generate-readmes in the turf project. -->
---

@@ -43,0 +47,0 @@

@@ -8,17 +8,36 @@ var test = require('tape');

test('LineString', function (t) {
t.equal(Math.round(lineDistance(route1, 'miles')), 202);
t.true((lineDistance(route2, 'kilometers') - 742) < 1 &&
(lineDistance(route2, 'kilometers') - 742) > (-1) );
test('Geometry', function (t) {
t.equal(Math.round(lineDistance(route1.geometry, 'miles')), 202);
t.true((lineDistance(route2.geometry, 'kilometers') - 742) < 1 && (lineDistance(route2.geometry, 'kilometers') - 742) > (-1) );
t.end();
});
test('turf-line-distance with geometries', function (t) {
t.equal(Math.round(lineDistance(route1.geometry, 'miles')), 202);
t.true((lineDistance(route2.geometry, 'kilometers') - 742) < 1 &&
(lineDistance(route2.geometry, 'kilometers') - 742) > (-1) );
test('Point', function (t) {
var point1 = {
type: "Feature",
geometry: {type: "Point", coordinates: [-75.343, 39.984]}
};
t.throws(function() {
lineDistance(point1, 'miles');
});
t.end();
});
test('MultiPoint', function (t) {
var multiPoint1 = {
type: "Feature",
geometry: {type: "MultiPoint", coordinates: [[-75.343, 39.984], [-75.534, 39.123]]}
};
t.throws(function() {
lineDistance(multiPoint1, 'miles');
});
t.end();
});
test('LineString', function (t) {
t.equal(Math.round(lineDistance(route1, 'miles')), 202);
t.true((lineDistance(route2, 'kilometers') - 742) < 1 && (lineDistance(route2, 'kilometers') - 742) > (-1) );
t.end();
});
test('Polygon', function (t) {

@@ -28,3 +47,3 @@ var feat = JSON.parse(fs.readFileSync(__dirname + '/test/polygon.geojson'));

t.end();
})
});

@@ -35,4 +54,10 @@ test('MultiLineString', function (t) {

t.end();
})
});
test('MultiPolygon', function (t) {
var feat = JSON.parse(fs.readFileSync(__dirname + '/test/multipolygon.geojson'));
t.equal(Math.round(1000 * lineDistance(feat, 'kilometers')), 8334);
t.end();
});
test('FeatureCollection', function (t) {

@@ -42,2 +67,2 @@ var feat = JSON.parse(fs.readFileSync(__dirname + '/test/featurecollection.geojson'));

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