From 0d87357e0809fef560c2f870e01cbc3b7a164d4c Mon Sep 17 00:00:00 2001 From: Martim Passos <49573683+martimpassos@users.noreply.github.com> Date: Wed, 31 Jan 2024 18:13:32 -0300 Subject: [PATCH] Use optional chaining when extracting values --- src/plugin.js | 2 +- src/resource.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/plugin.js b/src/plugin.js index a04d66e..4d83144 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -260,7 +260,7 @@ class TropiiifyPlugin { TropiiifyPlugin.defaults = { - itemTemplate: 'Tropy Generic', + itemTemplate: 'https://tropy.org/v1/templates/generic', collectionName: 'My IIIF Collection', homepageLabel: 'Object homepage', requiredStatementLabel: 'Attribution', diff --git a/src/resource.js b/src/resource.js index cf60091..0dbd67c 100644 --- a/src/resource.js +++ b/src/resource.js @@ -39,7 +39,6 @@ class Resource { y: this.extractValue(selection, tropy('y')), width: this.extractValue(selection, tropy('width')), height: this.extractValue(selection, tropy('height')), - })) })) @@ -47,7 +46,7 @@ class Resource { } extractValue(data, property) { - return data[property]?.[0]['@value'] || data[property]?.[0]['@list']; + return data?.[property]?.[0]?.['@value'] || data?.[property]?.[0]?.['@list']; } assembleHTML(property) {