I have this code that lays 3 different svgs over each other to form one svg, but I keep getting an error. Please help, thank you :)
function getLayer(name, skip=0.0) {
const svg = readFileSync(`./layers/${name}.svg`, 'utf-8');
const re = /(?<=\<svg\s*[^>]*>)([\s\S]*?)(?=\<\/svg\>)/g
const layer = svg.match(re)[0];
return Math.random() > skip ? layer : '';
}
the problem is yhe file you are trying to read is not matched with the regex you provided. you can gaurd your code like the followig:
function getLayer(name, skip=0.0) {
const svg = readFileSync(`./layers/${name}.svg`, 'utf-8');
const re = /(?<=\<svg\s*[^>]*>)([\s\S]*?)(?=\<\/svg\>)/g
const res = svg.match(re);
return res?.length && Math.random() > skip ? res[0] : ''
}
otherwise you should check your input file for invalid svg matches