Skip to content

Commit

Permalink
Centralize extension supported check
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Mar 15, 2023
1 parent 7eceded commit 0d20f71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,7 @@ function getStore(config, router) {
return Boolean(state.conformsTo.find(uri => uri.match(regexp)));
},
supportsExtension: state => schemaUri => {
let extensions = [];
if (state.data instanceof STAC && Array.isArray(state.data['stac_extensions'])) {
extensions = state.data['stac_extensions'];
}
let regexp = new RegExp('^' + schemaUri.replaceAll('*', '[^/]+') + '$');
return !!extensions.find(uri => uri.match(regexp));
return Utils.supportsExtension(state.data, schemaUri);
},

items: state => {
Expand Down
8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,12 @@ export default class Utils {
return { href, rel };
}

static supportsExtension(data, pattern) {
if (!Utils.isObject(data) || !Array.isArray(data['stac_extensions'])) {
return false;
}
let regexp = new RegExp('^' + pattern.replaceAll('*', '[^/]+') + '$');
return Boolean(data['stac_extensions'].find(uri => regexp.test(uri)));
}

}

0 comments on commit 0d20f71

Please sign in to comment.