@turf/polygon-to-line
Advanced tools
Comparing version 5.1.5 to 6.0.0
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" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5
9320
5
135
1
+ Added@turf/helpers@6.5.0(transitive)
+ Added@turf/invariant@6.5.0(transitive)
- Removed@turf/helpers@5.1.5(transitive)
- Removed@turf/invariant@5.2.0(transitive)
Updated@turf/helpers@6.x
Updated@turf/invariant@6.x