@radiantearth/stac-migrate 2.0.0 → 2.0.2

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 (3) hide show
  1. package/README.md +1 -1
  2. package/migrate.js +25 -9
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  A library to update STAC files to the latest version (**1.1.0** at the moment of writing).
4
4
  Supports updating **STAC versions 0.6.0 and later**.
5
5
 
6
- Version of this library: **2.0.0**
6
+ Version of this library: **2.0.2**
7
7
 
8
8
  ## Usage
9
9
 
package/migrate.js CHANGED
@@ -63,7 +63,8 @@ EXTENSIONS.collection = Object.assign(EXTENSIONS.collection, EXTENSIONS.itemAndC
63
63
  EXTENSIONS.item = Object.assign(EXTENSIONS.item, EXTENSIONS.itemAndCollection);
64
64
 
65
65
  var Ext = {
66
- parseUrl(url) {
66
+ parseExtension(url) {
67
+ // Try to match name and version from official extensions
67
68
  let match = url.match(/^https?:\/\/stac-extensions.github.io\/([^\/]+)\/v([^\/]+)\/[^.]+.json$/i);
68
69
  if (match) {
69
70
  return {
@@ -71,6 +72,21 @@ var Ext = {
71
72
  version: match[2]
72
73
  };
73
74
  }
75
+ // Try to match version from URIs
76
+ let match2 = url.match(/(\d+\.\d+(\.\d+)([a-z_.-][\w.-]+)?)/i);
77
+ if (match2) {
78
+ return {
79
+ id: url,
80
+ version: match2[1]
81
+ };
82
+ }
83
+ // Handle schortnames
84
+ if (url in SCHEMAS) {
85
+ return {
86
+ id: url,
87
+ version: '0.0.0'
88
+ };
89
+ }
74
90
  }
75
91
  };
76
92
 
@@ -88,7 +104,7 @@ var V = {
88
104
 
89
105
  if (Array.isArray(stac.stac_extensions)) {
90
106
  for (let ext of stac.stac_extensions) {
91
- let e = Ext.parseUrl(ext);
107
+ let e = Ext.parseExtension(ext);
92
108
  if (e) {
93
109
  V.extensions[e.id] = e.version;
94
110
  }
@@ -234,9 +250,9 @@ var _ = {
234
250
  },
235
251
 
236
252
  upgradeExtension(context, extension) {
237
- let { id, version } = Ext.parseUrl(extension);
253
+ let { id, version } = Ext.parseExtension(extension);
238
254
  let index = context.stac_extensions.findIndex(url => {
239
- let old = Ext.parseUrl(url);
255
+ let old = Ext.parseExtension(url);
240
256
  return (old && old.id === id && compareVersions.compare(old.version, version, '<'));
241
257
  });
242
258
  if (index !== -1) {
@@ -249,12 +265,12 @@ var _ = {
249
265
  },
250
266
 
251
267
  addExtension(context, newExtension) {
252
- let { id, version } = Ext.parseUrl(newExtension);
268
+ let { id, version } = Ext.parseExtension(newExtension);
253
269
  let index = context.stac_extensions.findIndex(url => {
254
270
  if (url === newExtension) {
255
271
  return true;
256
272
  }
257
- let old = Ext.parseUrl(url);
273
+ let old = Ext.parseExtension(url);
258
274
  if (old && old.id === id && compareVersions.compare(old.version, version, '<')) {
259
275
  return true;
260
276
  }
@@ -385,7 +401,7 @@ var _ = {
385
401
  if (!(date instanceof Date)) {
386
402
  date = new Date(date);
387
403
  }
388
- return date.toISOString().replace(/\.0+/, ''); // Don't export milliseconds if not needed
404
+ return date.toISOString().replace(/\.0+(?=[-\+Z])/, ''); // Don't export milliseconds if not needed
389
405
  },
390
406
 
391
407
  formatString(obj, key, format) {
@@ -929,8 +945,8 @@ var Fields = {
929
945
 
930
946
  file(obj, context, summaries) {
931
947
  _.rename(obj, 'file:bits_per_sample', 'raster:bits_per_sample') && _.addExtension(context, SCHEMAS.raster) && DONE;
932
- _.rename(obj, 'file:data_type', 'data_type') && _.addExtension(context, SCHEMAS.raster) && DONE;
933
- _.rename(obj, 'file:unit', 'unit') && _.addExtension(context, SCHEMAS.raster) && DONE;
948
+ _.rename(obj, 'file:data_type', 'data_type') && DONE;
949
+ _.rename(obj, 'file:unit', 'unit') && DONE;
934
950
 
935
951
  if (Array.isArray(obj['file:nodata']) && obj['file:nodata'].length > 1) {
936
952
  // In case of more than one no-data value we need to create a custom property
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radiantearth/stac-migrate",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "A library to update STAC files to the latest version.",
5
5
  "main": "migrate.js",
6
6
  "bin": {