remove()
此函数属于 Iconify Tools 中的 IconSet 类。
函数 remove() 用于删除图标。
用法
该函数包含以下参数:
- name,string。图标名称。
- removeDependencies,boolean|string。可选,默认为 true。指定如何处理以被删除图标为父图标的别名和变体。
函数返回已删除项目的数量(number)。
removeDependencies 属性的可能取值:
- true 删除图标、所有别名和变体。
- false 仅删除图标,不更改别名和变体。
- string 删除图标,并将别名和变体的 parent 属性更改为提供的值。
示例
example.ts
ts
import { IconSet } from '@iconify/tools';
const iconSet = new IconSet({
prefix: 'codicon',
icons: {
'add': {
body: '<g fill="currentColor"><path d="M14 7v1H8v6H7V8H1V7h6V1h1v6h6z"/></g>',
},
'debug-pause': {
body: '<g fill="currentColor"><path d="M4.5 3H6v10H4.5V3zm7 0v10H10V3h1.5z"/></g>',
hidden: true,
},
'triangle-left': {
body: '<g fill="currentColor"><path d="M10.44 2l.56.413v11.194l-.54.393L5 8.373v-.827L10.44 2z"/></g>',
},
},
aliases: {
'plus': {
parent: 'add',
},
'triangle-right': {
parent: 'triangle-left',
hFlip: true,
},
},
});
// Removes 'add' and 'plus' icons
iconSet.remove('add');
// Removes 'triangle-left' icon.
// Variation 'triangle-right' no longer has valid parent, but still exists in icon set.
iconSet.remove('triangle-left', false);
// Export icon set. 'triangle-right' will be in result because export() does not validate icons.
console.log(iconSet.export());Result:
json
{
"prefix": "codicon",
"icons": {
"debug-pause": {
"body": "<g fill=\"currentColor\"><path d=\"M4.5 3H6v10H4.5V3zm7 0v10H10V3h1.5z\"/></g>",
"hidden": true
}
},
"aliases": {
"triangle-right": { "parent": "triangle-left", "hFlip": true }
}
}