Spaces:
Running
Running
| function generateRandomId(length) { | |
| const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
| let result = ''; | |
| for (let i = 0; i < length; i++) { | |
| result += characters.charAt(Math.floor(Math.random() * characters.length)); | |
| } | |
| return result; | |
| } | |
| // From https://blog.jim-nielsen.com/2022/multiple-inline-svgs/ | |
| function uniqueSvg(svg) { | |
| const id = generateRandomId(10); | |
| return svg | |
| .replace(/id="clip/g, `id="${id}__clip`) | |
| .replace(/clip-path="url\(#clip/g, `clip-path="url(#${id}__clip`); | |
| } | |
| module.exports = { | |
| uniqueSvg, | |
| }; | |