const oldSvg = data.editor.svg;
const newSvg = svg.trim()
.replace(/(^<\?xml[^>]*>)|/g, '')
.trim()
.replace(/(^<svg[^>]*>)|(<\/svg>$)/g, '');
const position = oldSvg.length - 6;
const svgResult = [oldSvg.slice(0, position), newSvg, oldSvg.slice(position)].join('');
<button class="button open-modal">Хочу этот пакет</button>