Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function iconHelper(name, attributes = {}, options = {}) {
const icon = CarbonIcons[name];
if (!icon) {
throw new Error(`Unable to find the icon: \`${name}\``);
}
const content = icon.content.map(toString);
const attrs = {
...icon.attrs,
...Object.assign({}, attributes.hash || attributes, options.hash),
};
return new SafeString(
`<svg>${content.join('')}</svg>`
);
}
const toString = descriptor => {
if (typeof descriptor === 'string') {
return descriptor;
}
const { elem = 'svg', attrs = {}, content = [] } = descriptor;
const children = content.map(toString).join('');
if (elem !== 'svg') {
return `<${elem} ${formatAttributes(attrs)}>${children}`;
}
return `<${elem} ${formatAttributes(getAttributes(attrs))}>${children}`;
};
const toString = descriptor => {
if (typeof descriptor === 'string') {
return descriptor;
}
const { elem = 'svg', attrs = {}, content = [] } = descriptor;
const children = content.map(toString).join('');
if (elem !== 'svg') {
return `<${elem} ${formatAttributes(attrs)}>${children}`;
}
return `<${elem} ${formatAttributes(getAttributes(attrs))}>${children}`;
};
const toString = descriptor => {
if (typeof descriptor === 'string') {
return descriptor;
}
const { elem = 'svg', attrs = {}, content = [] } = descriptor;
const children = content.map(toString).join('');
if (elem !== 'svg') {
return `<${elem} ${formatAttributes(attrs)}>${children}`;
}
return `<${elem} ${formatAttributes(getAttributes(attrs))}>${children}`;
};
const toString = descriptor => {
if (typeof descriptor === 'string') {
return descriptor;
}
const { elem = 'svg', attrs = {}, content = [] } = descriptor;
const children = content.map(toString).join('');
if (elem !== 'svg') {
return `<${elem} ${formatAttributes(attrs)}>${children}`;
}
return `<${elem} ${formatAttributes(getAttributes(attrs))}>${children}`;
};