Urara-Blog/node_modules/.pnpm-store/v3/files/b1/02f07cf3eb12413bb2cb35aa85f73507c696abb4302beb11e79d6a165772524d6c26d7c59f1d15a5f25f6f6837f48ebe22b97e5f151d6679deed5e68b88cbc
2022-08-14 01:14:53 +08:00

21 lines
682 B
Text

const regex = /\sid="(\S+)"/g;
const randomPrefix = "IconifyId" + Date.now().toString(16) + (Math.random() * 16777216 | 0).toString(16);
let counter = 0;
function replaceIDs(body, prefix = randomPrefix) {
const ids = [];
let match;
while (match = regex.exec(body)) {
ids.push(match[1]);
}
if (!ids.length) {
return body;
}
ids.forEach((id) => {
const newID = typeof prefix === "function" ? prefix(id) : prefix + (counter++).toString();
const escapedID = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
body = body.replace(new RegExp('([#;"])(' + escapedID + ')([")]|\\.[a-z])', "g"), "$1" + newID + "$3");
});
return body;
}
export { replaceIDs };