/**
 * Sets a default color to the svg if it does not contain any
 * @param {string} svgStr
 * @return {string}
 */
export const initDefaultColor = svgStr => {
    if (!/#[0-9a-f]{3,6}/i.test(svgStr)) {
        const styleFix = 'fill: #000000;';
        return svgStr.replace(/<svg((?!style)[^>])*(style="([^"]+)")?[^>]*>/, function insertDefaultColor() {
            // appends it to the current style if exists, otherwise in a style attribute
            const svgTag = arguments[0];
            const currentStyle = arguments[3];
            return currentStyle
                ? svgTag.replace(currentStyle, currentStyle + ' ' + styleFix)
                : svgTag.replace('>', ` style="${styleFix}">`);
        });
    }
    return svgStr;
};
