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

@turf/line-to-polygon

Package Overview
Dependencies
Maintainers
4
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/line-to-polygon - npm Package Compare versions

Comparing version 5.1.5 to 6.0.0

index.ts

106

index.js

@@ -1,5 +0,6 @@

import turfBBox from '@turf/bbox';
import { getCoords, getType } from '@turf/invariant';
import { polygon, multiPolygon, lineString, isObject } from '@turf/helpers';
"use strict";
exports.__esModule = true;
var bbox_1 = require("@turf/bbox");
var invariant_1 = require("@turf/invariant");
var helpers_1 = require("@turf/helpers");
/**

@@ -24,30 +25,21 @@ * Converts (Multi)LineString(s) to Polygon(s).

function lineToPolygon(lines, options) {
if (options === void 0) { options = {}; }
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var properties = options.properties;
var autoComplete = options.autoComplete;
var orderCoords = options.orderCoords;
// validation
if (!lines) throw new Error('lines is required');
// default params
autoComplete = (autoComplete !== undefined) ? autoComplete : true;
orderCoords = (orderCoords !== undefined) ? orderCoords : true;
var type = getType(lines);
switch (type) {
case 'FeatureCollection':
case 'GeometryCollection':
var coords = [];
var features = (lines.features) ? lines.features : lines.geometries;
features.forEach(function (line) {
coords.push(getCoords(lineStringToPolygon(line, {}, autoComplete, orderCoords)));
});
return multiPolygon(coords, properties);
switch (lines.type) {
case 'FeatureCollection':
var coords = [];
lines.features.forEach(function (line) {
coords.push(invariant_1.getCoords(lineStringToPolygon(line, {}, autoComplete, orderCoords)));
});
return helpers_1.multiPolygon(coords, properties);
default:
return lineStringToPolygon(lines, properties, autoComplete, orderCoords);
}
return lineStringToPolygon(lines, properties, autoComplete, orderCoords);
}
/**

@@ -64,36 +56,38 @@ * LineString to Polygon

function lineStringToPolygon(line, properties, autoComplete, orderCoords) {
properties = properties || line.properties || {};
var coords = getCoords(line);
var type = getType(line);
if (!coords.length) throw new Error('line must contain coordinates');
properties = properties ? properties : (line.type === 'Feature') ? line.properties : {};
var geom = invariant_1.getGeom(line);
var coords = geom.coordinates;
var type = geom.type;
if (!coords.length)
throw new Error('line must contain coordinates');
switch (type) {
case 'LineString':
if (autoComplete) coords = autoCompleteCoords(coords);
return polygon([coords], properties);
case 'MultiLineString':
var multiCoords = [];
var largestArea = 0;
coords.forEach(function (coord) {
if (autoComplete) coord = autoCompleteCoords(coord);
// Largest LineString to be placed in the first position of the coordinates array
if (orderCoords) {
var area = calculateArea(turfBBox(lineString(coord)));
if (area > largestArea) {
multiCoords.unshift(coord);
largestArea = area;
} else multiCoords.push(coord);
} else {
multiCoords.push(coord);
}
});
return polygon(multiCoords, properties);
default:
throw new Error('geometry type ' + type + ' is not supported');
case 'LineString':
if (autoComplete)
coords = autoCompleteCoords(coords);
return helpers_1.polygon([coords], properties);
case 'MultiLineString':
var multiCoords = [];
var largestArea = 0;
coords.forEach(function (coord) {
if (autoComplete)
coord = autoCompleteCoords(coord);
// Largest LineString to be placed in the first position of the coordinates array
if (orderCoords) {
var area = calculateArea(bbox_1["default"](helpers_1.lineString(coord)));
if (area > largestArea) {
multiCoords.unshift(coord);
largestArea = area;
}
else
multiCoords.push(coord);
}
else {
multiCoords.push(coord);
}
});
return helpers_1.polygon(multiCoords, properties);
default:
throw new Error('geometry type ' + type + ' is not supported');
}
}
/**

@@ -118,3 +112,2 @@ * Auto Complete Coords - matches first & last coordinates

}
/**

@@ -134,3 +127,2 @@ * area - quick approximate area calculation (used to sort)

}
export default lineToPolygon;
exports["default"] = lineToPolygon;
{
"name": "@turf/line-to-polygon",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf line-to-polygon module",
"main": "main.js",
"module": "main.es.js",
"types": "index.d.ts",
"main": "index",
"files": [
"index.js",
"index.d.ts",
"main.js",
"main.es.js"
"index.ts"
],
"scripts": {
"pretest": "rollup -c ../../rollup.config.js",
"test": "node -r @std/esm test.js",
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js",
"bench": "node -r @std/esm bench.js",
"pretest": "tsc",
"test": "node test.js",
"bench": "node bench.js",
"docs": "node ../../scripts/generate-readmes"

@@ -42,6 +37,5 @@ },

"devDependencies": {
"@std/esm": "*",
"benchmark": "*",
"load-json-file": "*",
"rollup": "*",
"typescript": "*",
"tape": "*",

@@ -52,9 +46,5 @@ "write-json-file": "*"

"@turf/bbox": "^5.1.5",
"@turf/helpers": "^5.1.5",
"@turf/invariant": "^5.1.5"
},
"@std/esm": {
"esm": "js",
"cjs": true
"@turf/helpers": "6.x",
"@turf/invariant": "6.x"
}
}
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