toString()
此函数属于 Iconify Tools 中的 IconSet 类。
函数 toString() 将图标导出为字符串。
用法
该函数包含以下参数:
- name,string。图标名称。
- customisations,IconifyIconCustomisations。可选的自定义配置列表。
函数在成功时返回渲染后的图标 string,如果图标不存在则返回 null。
自定义配置
如果未设置 customisations,则默认值为:
json
{
"width": "auto",
"height": "auto"
}这将使图标的 width 和 height 与 viewBox 匹配(见下方示例)。
如果您想使用 1em 的高度,请使用以下 customisations:
json
{
"height": "1em"
}示例
example.ts
ts
import { blankIconSet } from '@iconify/tools';
const iconSet = blankIconSet('');
iconSet.setIcon('add', {
body: '<g fill="currentColor"><path d="M14 7v1H8v6H7V8H1V7h6V1h1v6h6z"/></g>',
});
// Export icon
console.log(iconSet.toString('add'));Result:
svg
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" preserveAspectRatio="xMidYMid meet" viewBox="0 0 16 16"><g fill="currentColor"><path d="M14 7v1H8v6H7V8H1V7h6V1h1v6h6z"/></g></svg>