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

turf-explode

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turf-explode - npm Package Compare versions

Comparing version 0.1.3 to 1.0.0

bench.js

76

index.js

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

var flatten = require('flatten')
var featureCollection = require('turf-featurecollection')
var point = require('turf-point')
var flatten = require('flatten');
var featureCollection = require('turf-featurecollection');
var point = require('turf-point');

@@ -8,82 +8,82 @@ module.exports = function(fc){

for(var i in fc.features){
var coordinates
var coordinates ;
switch(fc.features[i].geometry.type){
case 'Point':
coordinates = [fc.features[i].geometry.coordinates]
coordinates = [fc.features[i].geometry.coordinates];
break
case 'LineString':
coordinates = fc.features[i].geometry.coordinates
coordinates = fc.features[i].geometry.coordinates;
break
case 'Polygon':
coordinates = fc.features[i].geometry.coordinates
coordinates = flatCoords(coordinates)
coordinates = fc.features[i].geometry.coordinates;
coordinates = flatCoords(coordinates);
break
case 'MultiPoint':
coordinates = fc.features[i].geometry.coordinates
coordinates = fc.features[i].geometry.coordinates;
break
case 'MultiLineString':
coordinates = fc.features[i].geometry.coordinates
coordinates = flatCoords(coordinates)
coordinates = fc.features[i].geometry.coordinates;
coordinates = flatCoords(coordinates);
break
case 'MultiPolygon':
coordinates = fc.features[i].geometry.coordinates
coordinates = flatCoords(coordinates)
coordinates = fc.features[i].geometry.coordinates;
coordinates = flatCoords(coordinates);
break
}
if(!fc.features[i].geometry && fc.features[i].properties){
return new Error('Unknown Geometry Type')
return new Error('Unknown Geometry Type');
}
}
var exploded = featureCollection([])
var exploded = featureCollection([]);
coordinates.forEach(function(coords){
exploded.features.push(point(coords[0], coords[1]))
exploded.features.push(point(coords[0], coords[1]));
})
return exploded
return exploded;
}
else{
var coordinates
var geometry
var coordinates ;
var geometry;
if(fc.type === 'Feature'){
geometry = fc.geometry
geometry = fc.geometry;
}
else{
geometry = fc
geometry = fc;
}
switch(geometry.type){
case 'Point':
coordinates = [geometry.coordinates]
coordinates = [geometry.coordinates];
break
case 'LineString':
coordinates = geometry.coordinates
coordinates = geometry.coordinates;
break
case 'Polygon':
coordinates = geometry.coordinates
coordinates = flatCoords(coordinates)
coordinates = geometry.coordinates;
coordinates = flatCoords(coordinates);
break
case 'MultiPoint':
coordinates = geometry.coordinates
coordinates = geometry.coordinates;
break
case 'MultiLineString':
coordinates = geometry.coordinates
coordinates = flatCoords(coordinates)
coordinates = geometry.coordinates;
coordinates = flatCoords(coordinates);
break
case 'MultiPolygon':
coordinates = geometry.coordinates
coordinates = flatCoords(coordinates)
coordinates = geometry.coordinates;
coordinates = flatCoords(coordinates);
break
}
if(!geometry){
return new Error('No Geometry Found')
return new Error('No Geometry Found');
}
var exploded = featureCollection([])
var exploded = featureCollection([]);
coordinates.forEach(function(coords){
exploded.features.push(point(coords[0], coords[1]))
exploded.features.push(point(coords[0], coords[1]));
})
return exploded
return exploded;
}

@@ -93,9 +93,9 @@ }

function flatCoords(coords){
var newCoords = []
coords = flatten(coords)
var newCoords = [];
coords = flatten(coords);
coords.forEach(function(c, i){
if(i % 2 == 0) // if is even
newCoords.push([c, coords[i+1]])
newCoords.push([c, coords[i+1]]);
})
return newCoords
return newCoords;
}
{
"name": "turf-explode",
"version": "0.1.3",
"version": "1.0.0",
"description": "turf explode module",

@@ -26,2 +26,3 @@ "main": "index.js",

"devDependencies": {
"benchmark": "^1.0.0",
"tape": "^2.13.4",

@@ -28,0 +29,0 @@ "turf-featurecollection": "^0.1.0",

@@ -1,21 +0,21 @@

var test = require('tape')
var polygon = require('turf-polygon')
var point = require('turf-point')
var featurecollection = require('turf-featurecollection')
var explode = require('./')
var test = require('tape');
var polygon = require('turf-polygon');
var point = require('turf-point');
var featurecollection = require('turf-featurecollection');
var explode = require('./');
test('explode', function(t){
var poly = polygon([[[0,0], [0,10], [10,10] , [10,0]]])
var poly = polygon([[[0,0], [0,10], [10,10] , [10,0]]]);
var p1 = point(0,0),
p2 = point(0,10),
p3 = point(10,10),
p4 = point(10,0)
var fc = featurecollection([p1,p2,p3,p4])
p4 = point(10,0);
var fc = featurecollection([p1,p2,p3,p4]);
var exploded = explode(poly)
var exploded = explode(poly);
t.ok(exploded.features, 'should take a feature or feature collection and return all vertices')
t.deepEqual(exploded, fc)
t.ok(exploded.features, 'should take a feature or feature collection and return all vertices');
t.deepEqual(exploded, fc);
t.end()
t.end();
})
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