Skip to content

rename()

此函数属于 Iconify Tools 中的 IconSet 类。

函数 rename() 用于重命名图标。

该函数会检查引用了被重命名图标的别名和变体,并将父图标更新为新名称。

如果已存在具有新名称的图标,它将被覆盖。

用法

该函数具有以下参数:

  • oldNamestring 类型。旧图标名称。
  • newNamestring 类型。新图标名称。

函数执行成功时返回 true,失败时返回 false

示例

example.ts
tsimport { IconSet } from '@iconify/tools';

// Import icon set
const iconSet = new IconSet({
   prefix: 'carbon',
   icons: {
       'add': {
           body: '<path d="M17 15V8h-2v7H8v2h7v7h2v-7h7v-2z" fill="currentColor"/>',
       },
       'arrow-left': {
           body: '<path d="M14 26l1.41-1.41L7.83 17H28v-2H7.83l7.58-7.59L14 6L4 16l10 10z" fill="currentColor"/>',
       },
   },
   aliases: {
       'plus': {
           parent: 'add',
       },
       'arrow-right': {
           parent: 'arrow-left',
           hFlip: true,
       },
   },
   width: 32,
   height: 32,
});

// Rename 'add' to 'plus'
iconSet.rename('add', 'plus');

// Rename 'arrow-left' to 'arrow', also changes 'parent' property in 'arrow-right'
iconSet.rename('arrow-left', 'arrow');

// Export
console.log(iconSet.export());
结果:
json{
   "prefix": "carbon",
   "icons": {
       "arrow": {
           "body": "<path d=\"M14 26l1.41-1.41L7.83 17H28v-2H7.83l7.58-7.59L14 6L4 16l10 10z\" fill=\"currentColor\"/>"
       },
       "plus": {
           "body": "<path d=\"M17 15V8h-2v7H8v2h7v7h2v-7h7v-2z\" fill=\"currentColor\"/>"
       }
   },
   "aliases": {
       "arrow-right": { "parent": "arrow", "hFlip": true }
   },
   "width": 32,
   "height": 32
}