
module.exports = function replaceDomTag(source, fromTagName, toTagName, options = {}) {
    const regTagStartWithAttrs = RegExp(`<${fromTagName}\\s`, 'ig'); // <tag attr1=""></tag>
    const regTagStartNoAttrs = RegExp(`<${fromTagName}>`, 'ig'); // <tag></tag>
    const regTagEnd = RegExp(`</${fromTagName}>\\s*`, 'ig');

    const shouldWarn = regTagStartWithAttrs.test(source) || regTagStartNoAttrs.test(source);

    source = source.replace(regTagStartWithAttrs, `<${toTagName} `)
        .replace(regTagStartNoAttrs, `<${toTagName}>`)
        .replace(regTagEnd, `</${toTagName}>`);

    const {warningText, resourcePath} = options;
    
    if (warningText && shouldWarn) {
        resourcePath && console.warn(resourcePath);
        console.warn(warningText);
    }

    return source;
};