Skip to content

Commit

Permalink
fix: Return array when given single feature with null geometry. (#27)
Browse files Browse the repository at this point in the history
Fixes #26.
  • Loading branch information
stevage authored Feb 6, 2020
1 parent 93789fa commit 10dcc2c
Show file tree
Hide file tree
Showing 2 changed files with 239 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function flatten(gj) {
}, []);
return gj;
case "Feature":
if (!gj.geometry) return gj;
if (!gj.geometry) return [gj];
return flatten(gj.geometry).map(function(geom) {
var data = {
type: "Feature",
Expand Down
238 changes: 238 additions & 0 deletions tap-snapshots/test-flatten.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,81 @@
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/flatten.js TAP flatten multigeometry-single.input.geojson > multigeometry-single.input.geojson 1`] = `
Array [
Object {
"geometry": Object {
"coordinates": Array [
-122.4425587930444,
37.80666418607323,
0,
],
"type": "Point",
},
"properties": Object {
"name": "SF Marina Harbor Master",
},
"type": "Feature",
},
Object {
"geometry": Object {
"coordinates": Array [
-122.4428379594768,
37.80663578323093,
0,
],
"type": "Point",
},
"properties": Object {
"name": "SF Marina Harbor Master",
},
"type": "Feature",
},
Object {
"geometry": Object {
"coordinates": Array [
Array [
-122.4425587930444,
37.80666418607323,
0,
],
Array [
-122.4428379594768,
37.80663578323093,
0,
],
],
"type": "LineString",
},
"properties": Object {
"name": "SF Marina Harbor Master",
},
"type": "Feature",
},
Object {
"geometry": Object {
"coordinates": Array [
Array [
-122.4425509770566,
37.80662588061205,
0,
],
Array [
-122.4428340530617,
37.8065999493009,
0,
],
],
"type": "LineString",
},
"properties": Object {
"name": "SF Marina Harbor Master",
},
"type": "Feature",
},
]
`

exports[`test/flatten.js TAP flatten multigeometry.input.geojson > multigeometry.input.geojson 1`] = `
Object {
"features": Array [
Expand Down Expand Up @@ -83,6 +158,49 @@ Object {
}
`

exports[`test/flatten.js TAP flatten multilinestring-single.input.geojson > multilinestring-single.input.geojson 1`] = `
Array [
Object {
"geometry": Object {
"coordinates": Array [
Array [
0,
0,
],
Array [
1,
1,
],
],
"type": "LineString",
},
"properties": Object {
"name": "SF Marina Harbor Master",
},
"type": "Feature",
},
Object {
"geometry": Object {
"coordinates": Array [
Array [
2,
2,
],
Array [
3,
3,
],
],
"type": "LineString",
},
"properties": Object {
"name": "SF Marina Harbor Master",
},
"type": "Feature",
},
]
`

exports[`test/flatten.js TAP flatten multilinestring.input.geojson > multilinestring.input.geojson 1`] = `
Object {
"features": Array [
Expand Down Expand Up @@ -129,6 +247,37 @@ Object {
}
`

exports[`test/flatten.js TAP flatten multipoint-single.input.geojson > multipoint-single.input.geojson 1`] = `
Array [
Object {
"geometry": Object {
"coordinates": Array [
0,
0,
],
"type": "Point",
},
"properties": Object {
"name": "SF Marina Harbor Master",
},
"type": "Feature",
},
Object {
"geometry": Object {
"coordinates": Array [
1,
1,
],
"type": "Point",
},
"properties": Object {
"name": "SF Marina Harbor Master",
},
"type": "Feature",
},
]
`

exports[`test/flatten.js TAP flatten multipoint.input.geojson > multipoint.input.geojson 1`] = `
Object {
"features": Array [
Expand Down Expand Up @@ -163,6 +312,65 @@ Object {
}
`

exports[`test/flatten.js TAP flatten multipolygon-single.input.geojson > multipolygon-single.input.geojson 1`] = `
Array [
Object {
"geometry": Object {
"coordinates": Array [
Array [
0,
0,
],
Array [
1,
1,
],
Array [
4,
2,
],
Array [
0,
0,
],
],
"type": "Polygon",
},
"properties": Object {
"name": "SF Marina Harbor Master",
},
"type": "Feature",
},
Object {
"geometry": Object {
"coordinates": Array [
Array [
0,
0,
],
Array [
5,
5,
],
Array [
4,
2,
],
Array [
0,
0,
],
],
"type": "Polygon",
},
"properties": Object {
"name": "SF Marina Harbor Master",
},
"type": "Feature",
},
]
`

exports[`test/flatten.js TAP flatten multipolygon.input.geojson > multipolygon.input.geojson 1`] = `
Object {
"features": Array [
Expand Down Expand Up @@ -225,6 +433,18 @@ Object {
}
`

exports[`test/flatten.js TAP flatten nullgeometry-single.input.geojson > nullgeometry-single.input.geojson 1`] = `
Array [
Object {
"geometry": null,
"properties": Object {
"name": "SF Marina Harbor Master",
},
"type": "Feature",
},
]
`

exports[`test/flatten.js TAP flatten nullgeometry.input.geojson > nullgeometry.input.geojson 1`] = `
Object {
"features": Array [
Expand All @@ -240,6 +460,24 @@ Object {
}
`

exports[`test/flatten.js TAP flatten point-single.input.geojson > point-single.input.geojson 1`] = `
Array [
Object {
"geometry": Object {
"geometries": Array [
0,
0,
],
"type": "Point",
},
"properties": Object {
"name": "SF Marina Harbor Master",
},
"type": "Feature",
},
]
`

exports[`test/flatten.js TAP flatten point.input.geojson > point.input.geojson 1`] = `
Object {
"features": Array [
Expand Down

0 comments on commit 10dcc2c

Please sign in to comment.