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

@turf/clean-coords

Package Overview
Dependencies
Maintainers
7
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/clean-coords - npm Package Compare versions

Comparing version 6.5.0 to 7.0.0-alpha.0

18

dist/es/index.js

@@ -22,4 +22,3 @@ import { feature } from "@turf/helpers";

*/
function cleanCoords(geojson, options) {
if (options === void 0) { options = {}; }
function cleanCoords(geojson, options = {}) {
// Backwards compatible with v4.0

@@ -34,3 +33,3 @@ var mutate = typeof options === "object" ? options.mutate : options;

case "LineString":
newCoords = cleanLine(geojson);
newCoords = cleanLine(geojson, type);
break;

@@ -40,3 +39,3 @@ case "MultiLineString":

getCoords(geojson).forEach(function (line) {
newCoords.push(cleanLine(line));
newCoords.push(cleanLine(line, type));
});

@@ -48,3 +47,3 @@ break;

polygons.forEach(function (ring) {
polyPoints.push(cleanLine(ring));
polyPoints.push(cleanLine(ring, type));
});

@@ -93,5 +92,6 @@ newCoords.push(polyPoints);

* @param {Array<number>|LineString} line Line
* @param {string} type Type of geometry
* @returns {Array<number>} Cleaned coordinates
*/
function cleanLine(line) {
function cleanLine(line, type) {
var points = getCoords(line);

@@ -121,4 +121,8 @@ // handle "clean" segment

newPointsLength = newPoints.length;
if (equals(points[0], points[points.length - 1]) && newPointsLength < 4)
// (Multi)Polygons must have at least 4 points, but a closed LineString with only 3 points is acceptable
if ((type === "Polygon" || type === "MultiPolygon") &&
equals(points[0], points[points.length - 1]) &&
newPointsLength < 4) {
throw new Error("invalid polygon");
}
if (isPointOnLineSegment(newPoints[newPointsLength - 3], newPoints[newPointsLength - 1], newPoints[newPointsLength - 2]))

@@ -125,0 +129,0 @@ newPoints.splice(newPoints.length - 2, 1);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var helpers_1 = require("@turf/helpers");
var invariant_1 = require("@turf/invariant");
const helpers_1 = require("@turf/helpers");
const invariant_1 = require("@turf/invariant");
// To-Do => Improve Typescript GeoJSON handling

@@ -24,4 +24,3 @@ /**

*/
function cleanCoords(geojson, options) {
if (options === void 0) { options = {}; }
function cleanCoords(geojson, options = {}) {
// Backwards compatible with v4.0

@@ -36,3 +35,3 @@ var mutate = typeof options === "object" ? options.mutate : options;

case "LineString":
newCoords = cleanLine(geojson);
newCoords = cleanLine(geojson, type);
break;

@@ -42,3 +41,3 @@ case "MultiLineString":

invariant_1.getCoords(geojson).forEach(function (line) {
newCoords.push(cleanLine(line));
newCoords.push(cleanLine(line, type));
});

@@ -50,3 +49,3 @@ break;

polygons.forEach(function (ring) {
polyPoints.push(cleanLine(ring));
polyPoints.push(cleanLine(ring, type));
});

@@ -95,5 +94,6 @@ newCoords.push(polyPoints);

* @param {Array<number>|LineString} line Line
* @param {string} type Type of geometry
* @returns {Array<number>} Cleaned coordinates
*/
function cleanLine(line) {
function cleanLine(line, type) {
var points = invariant_1.getCoords(line);

@@ -123,4 +123,8 @@ // handle "clean" segment

newPointsLength = newPoints.length;
if (equals(points[0], points[points.length - 1]) && newPointsLength < 4)
// (Multi)Polygons must have at least 4 points, but a closed LineString with only 3 points is acceptable
if ((type === "Polygon" || type === "MultiPolygon") &&
equals(points[0], points[points.length - 1]) &&
newPointsLength < 4) {
throw new Error("invalid polygon");
}
if (isPointOnLineSegment(newPoints[newPointsLength - 3], newPoints[newPointsLength - 1], newPoints[newPointsLength - 2]))

@@ -127,0 +131,0 @@ newPoints.splice(newPoints.length - 2, 1);

{
"name": "@turf/clean-coords",
"version": "6.5.0",
"version": "7.0.0-alpha.0",
"description": "turf clean-coords module",

@@ -49,6 +49,6 @@ "author": "Turf Authors",

"test:tape": "ts-node -r esm test.js",
"test:types": "tsc --esModuleInterop --noEmit types.ts"
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
},
"devDependencies": {
"@turf/truncate": "^6.5.0",
"@turf/truncate": "^7.0.0-alpha.0",
"@types/tape": "*",

@@ -65,6 +65,7 @@ "benchmark": "*",

"dependencies": {
"@turf/helpers": "^6.5.0",
"@turf/invariant": "^6.5.0"
"@turf/helpers": "^7.0.0-alpha.0",
"@turf/invariant": "^7.0.0-alpha.0",
"tslib": "^2.3.0"
},
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
}

@@ -9,10 +9,11 @@ # @turf/clean-coords

**Parameters**
### Parameters
- `geojson` **([Geometry][1] \| [Feature][2])** Feature or Geometry
- `options` **[Object][3]** Optional parameters (optional, default `{}`)
- `options.mutate` **[boolean][4]** allows GeoJSON input to be mutated (optional, default `false`)
* `geojson` **([Geometry][1] | [Feature][2])** Feature or Geometry
* `options` **[Object][3]** Optional parameters (optional, default `{}`)
**Examples**
* `options.mutate` **[boolean][4]** allows GeoJSON input to be mutated (optional, default `false`)
### Examples
```javascript

@@ -29,3 +30,3 @@ var line = turf.lineString([[0, 0], [0, 2], [0, 5], [0, 8], [0, 8], [0, 10]]);

Returns **([Geometry][1] \| [Feature][2])** the cleaned input Feature/Geometry
Returns **([Geometry][1] | [Feature][2])** the cleaned input Feature/Geometry

@@ -32,0 +33,0 @@ [1]: https://tools.ietf.org/html/rfc7946#section-3.1

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