diff options
Diffstat (limited to 'main.js')
-rw-r--r-- | main.js | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -1,5 +1,15 @@ -/* Import the interpolate function*/ -import interpolate from "interpolate.js"; +/* Define the interpolate function */ +function interpolate(template, variables) { + return template.replace(/\${[^{]+}/g, (match) => { + const path = match.slice(2, -1).trim(); + return getObjPath(path, variables); + }); +} + +/* Get the specified property or nested property of an object */ +function getObjPath(path, obj) { + return path.split('.').reduce((res, key) => res[key], obj); +} /* Compute the total duration of the run. */ function compute() { |