{"ScriptPreparationCode":"String.prototype.replaceAll = function(search, replacement) {\r\n var target = this;\r\n return target.replace(new RegExp(search, \u0027g\u0027), replacement);\r\n};\r\n\r\nfunction parse(str) {\r\n const result = [];\r\n\r\n let buf = \u0027\u0027;\r\n\r\n for (let i = 0; i \u003C str.length; i\u002B\u002B) {\r\n const c = str.charAt(i);\r\n switch (c) {\r\n case \u0027{\u0027:\r\n if (buf.length === 0 || buf === \u0027{\u0027) {\r\n buf \u002B= c;\r\n } else {\r\n throw new Error(\u0060invalid \u0027{\u0027 at ${i}\u0060);\r\n }\r\n break;\r\n case \u0027}\u0027:\r\n if (buf.length \u003E 3) {\r\n buf \u002B= c;\r\n if (buf[buf.length - 2] === \u0027}\u0027) {\r\n result.push([buf.substr(2, buf.length - 4), i - buf.length \u002B 1, i \u002B 1]);\r\n buf = \u0027\u0027;\r\n }\r\n } else {\r\n throw new Error(\u0060invalid \u0027}\u0027 at ${i}\u0060);\r\n }\r\n break;\r\n case \u0027 \u0027:\r\n if (buf.length \u003E 0) {\r\n throw new Error(\u0060invalid \u0027 \u0027 at ${i}\u0060);\r\n }\r\n break;\r\n default:\r\n if (buf.length \u003E 1) {\r\n buf \u002B= c;\r\n }\r\n }\r\n }\r\n\r\n if (buf.length \u0026\u0026 buf[0] === \u0027{\u0027) {\r\n throw new Error(\u0027unmatched brace\u0027);\r\n }\r\n\r\n return result;\r\n}\r\n\r\nfunction printf(str, varMap, vars) {\r\n let result = \u0027\u0027 \u002B str;\r\n let i = varMap.length;\r\n while (i--) {\r\n const [key, start, end] = varMap[i];\r\n // eslint-disable-next-line no-prototype-builtins\r\n if (vars.hasOwnProperty(key)) {\r\n result = result.slice(0, start) \u002B vars[key] \u002B result.slice(end);\r\n }\r\n }\r\n\r\n return result;\r\n}","TestCases":[{"Name":"replace regex","Code":"const template = \u0027/nns/V1/event/offeringid/{{offeringid}}?division={{division}}\u0026vodId={{vodId}}\u0026lineup={{lineupId}}\u0026profile={{nnsProfile}}\u0026cacheID={{cacheID}}\u0027;\r\n\r\ntemplate.replace(/{{offeringid}}/g, \u00221\u0022);\r\ntemplate.replace(/{{division}}/g, \u00222\u0022);\r\ntemplate.replace(/{{vodId}}/g, \u00223\u0022);\r\ntemplate.replace(/{{lineupId}}/g, \u00224\u0022);\r\ntemplate.replace(/{{nnsProfile}}/g, \u00225\u0022);\r\ntemplate.replace(/{{cacheID}}/g, \u00226\u0022);","IsDeferred":false},{"Name":"replace All","Code":"const template = \u0027/nns/V1/event/offeringid/{{offeringid}}?division={{division}}\u0026vodId={{vodId}}\u0026lineup={{lineupId}}\u0026profile={{nnsProfile}}\u0026cacheID={{cacheID}}\u0027;\r\ntemplate.replaceAll(\u0022{{offeringid}}\u0022, \u00221\u0022);\r\ntemplate.replaceAll(\u0022{{division}}\u0022, \u00222\u0022);\r\ntemplate.replaceAll(\u0022{{vodId}}\u0022, \u00223\u0022);\r\ntemplate.replaceAll(\u0022{{lineupId}}\u0022, \u00224\u0022);\r\ntemplate.replaceAll(\u0022{{nnsProfile}}\u0022, \u00225\u0022);\r\ntemplate.replaceAll(\u0022{{cacheID}}\u0022, \u00226\u0022);","IsDeferred":false},{"Name":"Neu parser","Code":" const template = \u0027/nns/V1/event/offeringid/{{offeringid}}?division={{division}}\u0026vodId={{vodId}}\u0026lineup={{lineupId}}\u0026profile={{nnsProfile}}\u0026cacheID={{cacheID}}\u0027;\r\n const varmap = parse(template);\r\n const result = printf(template, varmap, {\r\n offeringid: \u00271\u0027,\r\n division: \u00272\u0027,\r\n vodId: \u00273\u0027,\r\n lineupId: \u00274\u0027,\r\n nnsProfile: \u00275\u0027,\r\n cacheID: \u00276\u0027,\r\n });","IsDeferred":false}]}