Skip to content

Commit ab70db4

Browse files
committed
fix(CornerAnnotation): Add string helper function
1 parent 52f9734 commit ab70db4

File tree

1 file changed

+19
-1
lines changed
  • Sources/Interaction/UI/CornerAnnotation

1 file changed

+19
-1
lines changed

Sources/Interaction/UI/CornerAnnotation/index.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ const KEY_MAPPING = {
1414
se: 'southEastContainer',
1515
};
1616

17+
// ----------------------------------------------------------------------------
18+
// Static helpers
19+
// ----------------------------------------------------------------------------
20+
21+
function get(path, obj, fb = `$\{${path}}`) {
22+
return path
23+
.split('.')
24+
.reduce((res, key) => (res[key] !== undefined ? res[key] : fb), obj);
25+
}
26+
27+
/* from https://gist.github.com/smeijer/6580740a0ff468960a5257108af1384e */
28+
function applyTemplate(template, map, fallback) {
29+
return template.replace(/\${([^{]+)}/g, (match) => {
30+
const path = match.substr(2, match.length - 3).trim();
31+
return get(path, map, fallback);
32+
});
33+
}
34+
1735
// ----------------------------------------------------------------------------
1836
// vtkCornerAnnotation methods
1937
// ----------------------------------------------------------------------------
@@ -143,4 +161,4 @@ export const newInstance = macro.newInstance(extend, 'vtkCornerAnnotation');
143161

144162
// ----------------------------------------------------------------------------
145163

146-
export default { newInstance, extend };
164+
export default { newInstance, extend, applyTemplate };

0 commit comments

Comments
 (0)