src/common/svg.js
/**
 * Replace IDs in SVG output with unique IDs
 * Fast replacement without parsing XML, assuming commonly used patterns.
 *
 * @param body
 * @return {*}
 */
Replace IDs in SVG output with unique IDs
Fast replacement without parsing XML, assuming commonly used patterns.

@param body
@return {*}
Replace IDs in SVG output with unique IDs Fast replacement without parsing XML assuming commonly used patterns . @param body @return { * }
function replaceIDs(body) {
    var regex = /\sid="(\S+)"/g,
        ids = [],
        match, prefix;
    function strReplace(search, replace, subject) {
        var pos = 0;
        while ((pos = subject.indexOf(search, pos)) !== -1) {
            subject = subject.slice(0, pos) + replace + subject.slice(pos + search.length);
            pos += replace.length;
        }
        return subject;
    }
    while (match = regex.exec(body)) {
        ids.push(match[1]);
    }
    if (!ids.length) {
        return body;
    }
    prefix = 'IconifyId-' + Date.now().toString(16) + '-' + (Math.random() * 0x1000000 | 0).toString(16) + '-';
    ids.forEach(function(id) {
        var newID = prefix + idCounter;
        idCounter ++;
        body = strReplace('="' + id + '"', '="' + newID + '"', body);
        body = strReplace('="#' + id + '"', '="#' + newID + '"', body);
        body = strReplace('(#' + id + ')', '(#' + newID + ')', body);
    });
    return body;
}
function replaceIDs ( body ) { var regex = / \sid="(\S+)" / g , ids = [ ] , match , prefix ; function strReplace ( search , replace , subject ) { var pos = 0 ; while ( ( pos = subject . indexOf ( search , pos ) ) !== - 1 ) { subject = subject . slice ( 0 , pos ) + replace + subject . slice ( pos + search . length ) ; pos += replace . length ; } return subject ; } while ( match = regex . exec ( body ) ) { ids . push ( match [ 1 ] ) ; } if ( ! ids . length ) { return body ; } prefix = 'IconifyId-' + Date . now ( ) . toString ( 16 ) + '-' + ( Math . random ( ) * 0x1000000 | 0 ) . toString ( 16 ) + '-' ; ids . forEach ( function ( id ) { var newID = prefix + idCounter ; idCounter ++ ; body = strReplace ( '="' + id + '"' , '="' + newID + '"' , body ) ; body = strReplace ( '="#' + id + '"' , '="#' + newID + '"' , body ) ; body = strReplace ( '(#' + id + ')' , '(#' + newID + ')' , body ) ; } ) ; return body ; }
Replace IDs in SVG output with unique IDs
 Fast replacement without parsing XML, assuming commonly used patterns.
Replace IDs in SVG output with unique IDs Fast replacement without parsing XML assuming commonly used patterns .
// Find all IDs // Replace with unique ids