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

@turf/polygon-to-line

Package Overview
Dependencies
Maintainers
4
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 5.1.5 to 6.0.0

index.ts

80

index.js

@@ -1,4 +0,5 @@

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

@@ -8,3 +9,3 @@ * Converts a {@link Polygon} to {@link LineString|(Multi)LineString} or {@link MultiPolygon} to a {@link FeatureCollection} of {@link LineString|(Multi)LineString}.

* @name polygonToLine
* @param {Feature<Polygon|MultiPolygon>} polygon Feature to convert
* @param {Feature<Polygon|MultiPolygon>} poly Feature to convert
* @param {Object} [options={}] Optional parameters

@@ -21,34 +22,47 @@ * @param {Object} [options.properties={}] translates GeoJSON properties to Feature

*/
function polygonToLine(polygon, options) {
// Optional parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var properties = options.properties;
// Variables
var geom = getType(polygon);
var coords = getCoords(polygon);
properties = properties || polygon.properties || {};
if (!coords.length) throw new Error('polygon must contain coordinates');
switch (geom) {
case 'Polygon':
return coordsToLine(coords, properties);
case 'MultiPolygon':
var lines = [];
coords.forEach(function (coord) {
lines.push(coordsToLine(coord, properties));
});
return featureCollection(lines);
default:
throw new Error('geom ' + geom + ' not supported');
function default_1(poly, options) {
if (options === void 0) { options = {}; }
var geom = invariant_1.getGeom(poly);
switch (geom.type) {
case 'Polygon': return polygonToLine(geom, options);
case 'MultiPolygon': return multiPolygonToLine(geom, options);
default: throw new Error('invalid poly');
}
}
exports["default"] = default_1;
/**
* @private
*/
function polygonToLine(poly, options) {
if (options === void 0) { options = {}; }
var geom = invariant_1.getGeom(poly);
var type = geom.type;
var coords = geom.coordinates;
var properties = options.properties ? options.properties : poly.type === 'Feature' ? poly.properties : {};
return coordsToLine(coords, properties);
}
exports.polygonToLine = polygonToLine;
/**
* @private
*/
function multiPolygonToLine(multiPoly, options) {
if (options === void 0) { options = {}; }
var geom = invariant_1.getGeom(multiPoly);
var type = geom.type;
var coords = geom.coordinates;
var properties = options.properties ? options.properties : multiPoly.type === 'Feature' ? multiPoly.properties : {};
var lines = [];
coords.forEach(function (coord) {
lines.push(coordsToLine(coord, properties));
});
return helpers_1.featureCollection(lines);
}
exports.multiPolygonToLine = multiPolygonToLine;
/**
* @private
*/
function coordsToLine(coords, properties) {
if (coords.length > 1) return multiLineString(coords, properties);
return lineString(coords[0], properties);
if (coords.length > 1)
return helpers_1.multiLineString(coords, properties);
return helpers_1.lineString(coords[0], properties);
}
export default polygonToLine;
{
"name": "@turf/polygon-to-line",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf polygon-to-line 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"

@@ -39,17 +34,12 @@ },

"devDependencies": {
"@std/esm": "*",
"benchmark": "*",
"load-json-file": "*",
"rollup": "*",
"tape": "*",
"typescript": "*",
"write-json-file": "*"
},
"dependencies": {
"@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