@hestia-earth/schema-convert 20.1.0 → 20.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/json.js +34 -25
  2. package/package.json +1 -1
package/json.js CHANGED
@@ -242,19 +242,22 @@ var validateGeoJSONFormat = function (value) {
242
242
  return (!allowedGeoJSONTypes.includes(value.type)
243
243
  ? throwError("Invalid GeoJSON \"type\". Allowed values are: ".concat(allowedGeoJSONTypes.join(', ')))
244
244
  : 'geometries' in value
245
- ? (value.geometries || []).every(validateGeoJSONGeometryType)
245
+ ? !value.geometries.length
246
+ ? throwError('This GeoJSON appears to be empty. Please either add coordinates or remove the field.')
247
+ : (value.geometries || []).every(validateGeoJSONGeometryType)
246
248
  : 'geometry' in value
247
249
  ? validateGeoJSONGeometryType(value.geometry)
248
250
  : 'features' in value
249
- ? (value.features || []).every(validateGeoJSONFormat)
251
+ ? !value.features.length
252
+ ? throwError('This GeoJSON appears to be empty. Please either add coordinates or remove the field.')
253
+ : (value.features || []).every(validateGeoJSONFormat)
250
254
  : true)
251
255
  ? value
252
256
  : null;
253
257
  };
254
- var parseGeoJSONValue = function (value) {
255
- var result;
258
+ var parseWtkValue = function (value) {
256
259
  try {
257
- result = {
260
+ return {
258
261
  type: 'FeatureCollection',
259
262
  features: [{
260
263
  type: 'Feature',
@@ -263,30 +266,36 @@ var parseGeoJSONValue = function (value) {
263
266
  }]
264
267
  };
265
268
  }
266
- catch (e1) {
267
- try {
268
- var data = JSON.parse(value);
269
- return result = ['Polygon', 'MultiPolygon'].includes(data.type)
269
+ catch (error) {
270
+ return null;
271
+ }
272
+ };
273
+ var parseJsonValue = function (value) {
274
+ try {
275
+ var data = JSON.parse(value);
276
+ return ['Polygon', 'MultiPolygon'].includes(data.type)
277
+ ? {
278
+ type: 'FeatureCollection',
279
+ features: [{
280
+ type: 'Feature',
281
+ properties: {},
282
+ geometry: data
283
+ }]
284
+ }
285
+ : ['Feature'].includes(data.type)
270
286
  ? {
271
287
  type: 'FeatureCollection',
272
- features: [{
273
- type: 'Feature',
274
- properties: {},
275
- geometry: data
276
- }]
288
+ features: [__assign(__assign({}, data), { properties: {} // make sure they are set or it is invalid
289
+ })]
277
290
  }
278
- : ['Feature'].includes(data.type)
279
- ? {
280
- type: 'FeatureCollection',
281
- features: [__assign(__assign({}, data), { properties: {} // make sure they are set or it is invalid
282
- })]
283
- }
284
- : data;
285
- }
286
- catch (e2) {
287
- return throwError('Unable to parse GeoJSON value. Please make sure the formatting is correct.');
288
- }
291
+ : data;
289
292
  }
293
+ catch (error) {
294
+ return throwError('Unable to parse GeoJSON value. Please make sure the formatting is correct.');
295
+ }
296
+ };
297
+ var parseGeoJSONValue = function (value) {
298
+ var result = parseWtkValue(value) || parseJsonValue(value);
290
299
  return result ? validateGeoJSONFormat(result) : value;
291
300
  };
292
301
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/schema-convert",
3
- "version": "20.1.0",
3
+ "version": "20.2.0",
4
4
  "description": "Hestia Schema Converters",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",