I'm looking for an efficient way to replace the values within an object if they match a certain pattern.
var shapes = {
square: {
attr: {
stroke: '###',
'stroke-width': '%%%'
}
},
circle: {
attr: {
fill: '###',
'stroke-width': '%%%'
}
}
}
For instance, i'd like to be able to replace all '###' patterns with a colour for a specific shape:
var square = replace(shapes.square, {
'###': '#333',
'%%%': 23
});
var circle = replace(shapes.circle, {
'###': '#111',
'%%%': 5
});
Which would allow me quickly to set the stroke and/or fill values of various objects.
Is there a way to do this cleanly? Perhaps using Lodash or regex?