Repository URL to install this package:
|
Version:
3.12.2 ▾
|
var provideSvgStrWithCurrColor = function provideSvgStrWithCurrColor(svgString) {
var preparedSvgString = svgString.replaceAll(/(<\?xml.*?>|<!--.*-->)[\r\n]?/gi, '');
var startOfSvgTagIndex = preparedSvgString.indexOf('<svg');
// we are checking start of the tag first for making sure we would catch the first end after the svg opening to avoid issues.
var endOfSvgTagIndex = startOfSvgTagIndex + preparedSvgString.substr(startOfSvgTagIndex).indexOf('>');
var svgTagWithPreparedColor = "".concat(preparedSvgString.substr(0, endOfSvgTagIndex).replace(/\s*(?:fill|stroke|color)[:=]\s*['"]?.*['"; }]/i, '').trim(), " color=\"currentColor\" fill=\"currentColor\"");
var restOfSvgElementPreparedColor = preparedSvgString.substr(endOfSvgTagIndex, preparedSvgString.length).replaceAll(/(\s*(?:fill|stroke|color)[:=]\s*['"]?)#?\b(?!\s*?none).+?([\r\n'";})])/gi, '$1currentColor$2').replaceAll(/(\n\t|\n|\t)/g, ' ');
return svgTagWithPreparedColor + restOfSvgElementPreparedColor;
};
export default provideSvgStrWithCurrColor;