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 6.0.1 to 6.0.2

index.d.ts

25

index.js
"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", { value: true });
var helpers_1 = require("@turf/helpers");
var invariant_1 = require("@turf/invariant");
var helpers_1 = require("@turf/helpers");
/**
* Converts a {@link Polygon} to {@link LineString|(Multi)LineString} or {@link MultiPolygon} to a {@link FeatureCollection} of {@link LineString|(Multi)LineString}.
* Converts a {@link Polygon} to {@link LineString|(Multi)LineString} or {@link MultiPolygon} to a
* {@link FeatureCollection} of {@link LineString|(Multi)LineString}.
*

@@ -24,12 +25,12 @@ * @name polygonToLine

var geom = invariant_1.getGeom(poly);
if (!options.properties && poly.type === 'Feature') {
if (!options.properties && poly.type === "Feature") {
options.properties = poly.properties;
}
switch (geom.type) {
case 'Polygon': return polygonToLine(geom, options);
case 'MultiPolygon': return multiPolygonToLine(geom, options);
default: throw new Error('invalid poly');
case "Polygon": return polygonToLine(geom, options);
case "MultiPolygon": return multiPolygonToLine(geom, options);
default: throw new Error("invalid poly");
}
}
exports["default"] = default_1;
exports.default = default_1;
/**

@@ -43,3 +44,3 @@ * @private

var coords = geom.coordinates;
var properties = options.properties ? options.properties : poly.type === 'Feature' ? poly.properties : {};
var properties = options.properties ? options.properties : poly.type === "Feature" ? poly.properties : {};
return coordsToLine(coords, properties);

@@ -56,3 +57,4 @@ }

var coords = geom.coordinates;
var properties = options.properties ? options.properties : multiPoly.type === 'Feature' ? multiPoly.properties : {};
var properties = options.properties ? options.properties :
multiPoly.type === "Feature" ? multiPoly.properties : {};
var lines = [];

@@ -69,6 +71,7 @@ coords.forEach(function (coord) {

function coordsToLine(coords, properties) {
if (coords.length > 1)
if (coords.length > 1) {
return helpers_1.multiLineString(coords, properties);
}
return helpers_1.lineString(coords[0], properties);
}
exports.coordsToLine = coordsToLine;

@@ -1,9 +0,10 @@

import { getCoords, getGeom } from '@turf/invariant';
import { featureCollection, lineString, multiLineString } from "@turf/helpers";
import {
lineString, multiLineString, featureCollection,
Feature, FeatureCollection, Polygon, MultiPolygon, LineString, MultiLineString, Properties
} from '@turf/helpers';
Feature, FeatureCollection, LineString, MultiLineString, MultiPolygon, Polygon, Properties,
} from "@turf/helpers";
import { getCoords, getGeom } from "@turf/invariant";
/**
* Converts a {@link Polygon} to {@link LineString|(Multi)LineString} or {@link MultiPolygon} to a {@link FeatureCollection} of {@link LineString|(Multi)LineString}.
* Converts a {@link Polygon} to {@link LineString|(Multi)LineString} or {@link MultiPolygon} to a
* {@link FeatureCollection} of {@link LineString|(Multi)LineString}.
*

@@ -25,10 +26,10 @@ * @name polygonToLine

poly: Feature<G, P> | G,
options: { properties?: P } = {}
options: { properties?: any } = {},
): Feature<LineString | MultiLineString, P> | FeatureCollection<LineString | MultiLineString, P> {
const geom: any = getGeom(poly);
if (!options.properties && poly.type === 'Feature') { options.properties = poly.properties }
if (!options.properties && poly.type === "Feature") { options.properties = poly.properties; }
switch (geom.type) {
case 'Polygon': return polygonToLine(geom, options)
case 'MultiPolygon': return multiPolygonToLine(geom, options)
default: throw new Error('invalid poly')
case "Polygon": return polygonToLine(geom, options);
case "MultiPolygon": return multiPolygonToLine(geom, options);
default: throw new Error("invalid poly");
}

@@ -42,3 +43,3 @@ }

poly: Feature<G, P> | G,
options: { properties?: any } = {}
options: { properties?: any } = {},
): Feature<LineString | MultiLineString, P> {

@@ -48,3 +49,3 @@ const geom = getGeom(poly);

const coords: any[] = geom.coordinates;
const properties: any = options.properties ? options.properties : poly.type === 'Feature' ? poly.properties : {};
const properties: any = options.properties ? options.properties : poly.type === "Feature" ? poly.properties : {};

@@ -59,3 +60,3 @@ return coordsToLine(coords, properties);

multiPoly: Feature<G, P> | G,
options: { properties?: P } = {}
options: { properties?: P } = {},
): FeatureCollection<LineString | MultiLineString, P> {

@@ -65,6 +66,7 @@ const geom = getGeom(multiPoly);

const coords: any[] = geom.coordinates;
const properties: any = options.properties ? options.properties : multiPoly.type === 'Feature' ? multiPoly.properties : {};
const properties: any = options.properties ? options.properties :
multiPoly.type === "Feature" ? multiPoly.properties : {};
const lines: Feature<LineString | MultiLineString, P>[] = [];
coords.forEach(function (coord) {
const lines: Array<Feature<LineString | MultiLineString, P>> = [];
coords.forEach((coord) => {
lines.push(coordsToLine(coord, properties));

@@ -78,5 +80,8 @@ });

*/
export function coordsToLine<P = Properties>(coords: number[][][], properties: P): Feature<LineString | MultiLineString, P> {
if (coords.length > 1) return multiLineString(coords, properties);
export function coordsToLine<P = Properties>(
coords: number[][][],
properties: P,
): Feature<LineString | MultiLineString, P> {
if (coords.length > 1) { return multiLineString(coords, properties); }
return lineString(coords[0], properties);
}
{
"name": "@turf/polygon-to-line",
"version": "6.0.1",
"version": "6.0.2",
"description": "turf polygon-to-line module",
"main": "index",
"types": "index.d.ts",
"files": [
"index.js",
"index.ts"
"index.ts",
"index.d.ts"
],
"scripts": {
"prepare": "tsc",
"pretest": "tsc",

@@ -38,3 +41,5 @@ "test": "node test.js",

"typescript": "*",
"write-json-file": "*"
"write-json-file": "*",
"tslint": "*",
"@types/tape": "*"
},

@@ -41,0 +46,0 @@ "dependencies": {

@@ -7,9 +7,9 @@ # @turf/polygon-to-line

Converts a [Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) to [(Multi)LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4) or [MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7) to a [FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) of [(Multi)LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4).
Converts a [Polygon][1] to [(Multi)LineString][2] or [MultiPolygon][3] to a [FeatureCollection][4] of [(Multi)LineString][2].
**Parameters**
- `polygon` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;([Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) \| [MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7))>** Feature to convert
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`)
- `options.properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** translates GeoJSON properties to Feature (optional, default `{}`)
- `poly` **[Feature][5]&lt;([Polygon][6] \| [MultiPolygon][7])>** Feature to convert
- `options` **[Object][8]** Optional parameters (optional, default `{}`)
- `options.properties` **[Object][8]** translates GeoJSON properties to Feature (optional, default `{}`)

@@ -27,4 +27,24 @@ **Examples**

Returns **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;([LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4) | MultiLinestring)>)** converted (Multi)Polygon to (Multi)LineString
Returns **([FeatureCollection][9] \| [Feature][5]&lt;([LineString][10] | MultiLinestring)>)** converted (Multi)Polygon to (Multi)LineString
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.6
[2]: https://tools.ietf.org/html/rfc7946#section-3.1.4
[3]: https://tools.ietf.org/html/rfc7946#section-3.1.7
[4]: https://tools.ietf.org/html/rfc7946#section-3.3
[5]: https://tools.ietf.org/html/rfc7946#section-3.2
[6]: https://tools.ietf.org/html/rfc7946#section-3.1.6
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.7
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[9]: https://tools.ietf.org/html/rfc7946#section-3.3
[10]: https://tools.ietf.org/html/rfc7946#section-3.1.4
<!-- This file is automatically generated. Please don't edit it directly:

@@ -31,0 +51,0 @@ if you find an error, edit the source file (likely index.js), and re-run

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