function encodeSVG(data) {
  data = data.replace(/\s{2,}/g, " ");

  const symbols = /[\r\n%#()<>?[\\\]^`{|}]/g;
  const escaped = data.replace(symbols, encodeURIComponent);

  return `'data:image/svg+xml,${escaped}'`;
}
Given a string of SVG xml, encode it into a data URL
@param {string} data SVG XML string to encode
@returns {string} Data URL containing inline SVG already enclosed in quotes