Replaces all occurrences of the specified variable in the provided template
with its value.

@param {string} template The template.
@param {string} name The variable name.
@param {?(boolean|number|string|Object<string, ?(boolean|number|string)>|(boolean|number|string|Object<string, ?(boolean|number|string)>)[])} value
The variable value.
@return {string} Processed template.
function replaceVariable(template, name, value) {
  let key = `{${name}}`;
  let reg = new RegExp(helper.escapeRegExp(key), 'g');
  let encodedReg = new RegExp(helper.escapeRegExp(`{${name}|json}`), 'g');
  let encodedValue = JSON.stringify(value).replace(/<\/script/gi, '<\\/script');

  return template.replace(reg, value).replace(encodedReg, encodedValue);
}