geojson-flatten
Advanced tools
Comparing version 0.1.0 to 0.2.0
13
index.js
@@ -1,4 +0,2 @@ | ||
module.exports = flatten; | ||
function flatten(gj, up) { | ||
function flatten(gj) { | ||
switch ((gj && gj.type) || null) { | ||
@@ -11,2 +9,3 @@ case 'FeatureCollection': | ||
case 'Feature': | ||
if (!gj.geometry) return gj; | ||
return flatten(gj.geometry).map(function(geom) { | ||
@@ -32,3 +31,5 @@ return { | ||
case 'GeometryCollection': | ||
return gj.geometries; | ||
return gj.geometries.map(flatten).reduce(function(memo, geoms) { | ||
return memo.concat(geoms); | ||
}, []); | ||
case 'Point': | ||
@@ -38,5 +39,5 @@ case 'Polygon': | ||
return [gj]; | ||
default: | ||
return gj; | ||
} | ||
} | ||
module.exports = flatten; |
{ | ||
"name": "geojson-flatten", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "transform geojson into single-parts", | ||
@@ -13,3 +13,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "node test/flatten.js", | ||
"test": "tap --coverage test/flatten.js", | ||
"make": "browserify -s geojsonFlatten index.js > geojson-flatten.js" | ||
@@ -33,10 +33,10 @@ }, | ||
"dependencies": { | ||
"concat-stream": "~1.2.1", | ||
"minimist": "0.0.5", | ||
"concat-stream": "~1.2.1", | ||
"sharkdown": "~0.1.0" | ||
}, | ||
"devDependencies": { | ||
"tap": "~0.4.6", | ||
"browserify": "~3.18.0" | ||
"tap": "^2.3.1", | ||
"browserify": "^12.0.1" | ||
} | ||
} |
# geojson-flatten | ||
[![build status](https://secure.travis-ci.org/mapbox/geojson-flatten.svg)](http://travis-ci.org/mapbox/geojson-flatten) | ||
Flatten MultiPoint, MultiPolygon, MultiLineString, and GeometryCollection | ||
@@ -4,0 +6,0 @@ geometries in [GeoJSON](http://geojson.org/) files into simple non-complex |
@@ -5,14 +5,22 @@ var flatten = require('../'), | ||
function f(_) { | ||
return JSON.parse(fs.readFileSync(_, 'utf8')); | ||
} | ||
test('flatten', function(t) { | ||
t.deepEqual(flatten(f('./test/multigeometry.input.geojson')), f('./test/multigeometry.output.geojson'), | ||
'expands geometrycollection'); | ||
t.deepEqual(flatten(f('./test/point.input.geojson')), f('./test/point.input.geojson'), | ||
'does not touch point'); | ||
t.deepEqual(flatten(f('./test/linestring.geojson')), f('./test/linestring.geojson'), | ||
'does not touch line'); | ||
t.end(); | ||
test('flatten', function(group) { | ||
fs.readdirSync(__dirname + '/fixture') | ||
.filter(function(fix) { return fix.match(/input/); }) | ||
.forEach(function(fixture) { | ||
group.test(fixture, function(t) { | ||
var result = flatten( | ||
JSON.parse( | ||
fs.readFileSync(__dirname + '/fixture/' + fixture))); | ||
if (process.env.UPDATE) { | ||
fs.writeFileSync(__dirname + '/fixture/' + fixture.replace('input', 'output'), | ||
JSON.stringify(result, null, 2)); | ||
} | ||
t.deepEqual(result, | ||
JSON.parse( | ||
fs.readFileSync( | ||
__dirname + '/fixture/' + fixture.replace('input', 'output')))); | ||
t.end(); | ||
}); | ||
}); | ||
group.end(); | ||
}); |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
16116
23
22
2
63