@@ -14,6 +14,24 @@ const KEY_MAPPING = {
14
14
se : 'southEastContainer' ,
15
15
} ;
16
16
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
+
17
35
// ----------------------------------------------------------------------------
18
36
// vtkCornerAnnotation methods
19
37
// ----------------------------------------------------------------------------
@@ -143,4 +161,4 @@ export const newInstance = macro.newInstance(extend, 'vtkCornerAnnotation');
143
161
144
162
// ----------------------------------------------------------------------------
145
163
146
- export default { newInstance, extend } ;
164
+ export default { newInstance, extend, applyTemplate } ;
0 commit comments