diff options
author | Amine El Baghdadi <75886237+NoobJsPerson@users.noreply.github.com> | 2021-05-15 18:30:55 +0000 |
---|---|---|
committer | Amine El Baghdadi <75886237+NoobJsPerson@users.noreply.github.com> | 2021-05-15 18:30:55 +0000 |
commit | b817a19326b67668ee1026d7cc52781666ec44b7 (patch) | |
tree | 32c89fa13d3b0e03fd5db1856fc0b96ac4398343 | |
parent | 12b56ae0c3980eb786fc8a9f2ca44a9a72392dac (diff) |
update 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() { |