geojson-flatten
Advanced tools
Comparing version 0.2.2 to 0.2.3
80
index.js
@@ -1,40 +0,42 @@ | ||
function flatten(gj) { | ||
switch ((gj && gj.type) || null) { | ||
case 'FeatureCollection': | ||
gj.features = gj.features.reduce(function(mem, feature) { | ||
return mem.concat(flatten(feature)); | ||
}, []); | ||
return gj; | ||
case 'Feature': | ||
if (!gj.geometry) return gj; | ||
return flatten(gj.geometry).map(function(geom) { | ||
return { | ||
type: 'Feature', | ||
properties: JSON.parse(JSON.stringify(gj.properties)), | ||
geometry: geom | ||
}; | ||
}); | ||
case 'MultiPoint': | ||
return gj.coordinates.map(function(_) { | ||
return { type: 'Point', coordinates: _ }; | ||
}); | ||
case 'MultiPolygon': | ||
return gj.coordinates.map(function(_) { | ||
return { type: 'Polygon', coordinates: _ }; | ||
}); | ||
case 'MultiLineString': | ||
return gj.coordinates.map(function(_) { | ||
return { type: 'LineString', coordinates: _ }; | ||
}); | ||
case 'GeometryCollection': | ||
return gj.geometries.map(flatten).reduce(function(memo, geoms) { | ||
return memo.concat(geoms); | ||
}, []); | ||
case 'Point': | ||
case 'Polygon': | ||
case 'LineString': | ||
return [gj]; | ||
} | ||
export default function flatten(gj) { | ||
switch ((gj && gj.type) || null) { | ||
case "FeatureCollection": | ||
gj.features = gj.features.reduce(function(mem, feature) { | ||
return mem.concat(flatten(feature)); | ||
}, []); | ||
return gj; | ||
case "Feature": | ||
if (!gj.geometry) return gj; | ||
return flatten(gj.geometry).map(function(geom) { | ||
var data = { | ||
type: "Feature", | ||
properties: JSON.parse(JSON.stringify(gj.properties)), | ||
geometry: geom | ||
}; | ||
if (gj.id !== undefined) { | ||
data.id = gj.id; | ||
} | ||
return data; | ||
}); | ||
case "MultiPoint": | ||
return gj.coordinates.map(function(_) { | ||
return { type: "Point", coordinates: _ }; | ||
}); | ||
case "MultiPolygon": | ||
return gj.coordinates.map(function(_) { | ||
return { type: "Polygon", coordinates: _ }; | ||
}); | ||
case "MultiLineString": | ||
return gj.coordinates.map(function(_) { | ||
return { type: "LineString", coordinates: _ }; | ||
}); | ||
case "GeometryCollection": | ||
return gj.geometries.map(flatten).reduce(function(memo, geoms) { | ||
return memo.concat(geoms); | ||
}, []); | ||
case "Point": | ||
case "Polygon": | ||
case "LineString": | ||
return [gj]; | ||
} | ||
} | ||
module.exports = flatten; |
{ | ||
"name": "geojson-flatten", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "transform geojson into single-parts", | ||
"main": "index.js", | ||
"source": "index.js", | ||
"main": "dist/index.js", | ||
"umd:main": "dist/index.umd.js", | ||
"unpkg": "dist/index.umd.js", | ||
"module": "dist/index.es.js", | ||
"files": [ | ||
"index.js", | ||
"dist", | ||
"geojson-flatten" | ||
@@ -18,7 +23,10 @@ ], | ||
"test": "eslint index.js && tap --coverage test/flatten.js", | ||
"make": "browserify -s geojsonFlatten index.js > geojson-flatten.js" | ||
"pretest": "microbundle --name geojsonFlatten", | ||
"prepare": "microbundle --name geojsonFlatten", | ||
"make": "browserify -s geojsonFlatten index.js > geojson-flatten.js", | ||
"release": "standard-version" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/mapbox/geojson-flatten.git" | ||
"url": "git://github.com/node-geojson/geojson-flatten.git" | ||
}, | ||
@@ -33,15 +41,15 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/mapbox/geojson-flatten/issues" | ||
"url": "https://github.com/node-geojson/geojson-flatten/issues" | ||
}, | ||
"homepage": "https://github.com/mapbox/geojson-flatten", | ||
"homepage": "https://github.com/node-geojson/geojson-flatten", | ||
"dependencies": { | ||
"concat-stream": "~1.6.0", | ||
"get-stdin": "^6.0.0", | ||
"minimist": "1.2.0" | ||
}, | ||
"devDependencies": { | ||
"tap": "^10.3.2", | ||
"browserify": "^14.3.0", | ||
"eslint": "~1.00.0", | ||
"eslint-config-unstyled": "^1.1.0" | ||
"eslint": "^5.12.1", | ||
"microbundle": "^0.9.0", | ||
"standard-version": "^4.4.0", | ||
"tap": "^12.4.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
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
13496
11
56
+ Addedget-stdin@^6.0.0
+ Addedget-stdin@6.0.0(transitive)
- Removedconcat-stream@~1.6.0
- Removedbuffer-from@1.1.2(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@1.0.0(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedutil-deprecate@1.0.2(transitive)