Skip to content

setAlias()

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

函数 setAlias() 用于添加新的图标别名。

别名

图标别名是图标的另一个名称。它通常在重命名图标时使用,以便用户仍可通过旧名称访问该图标。

用法

该函数包含以下参数:

  • namestring。图标名称。
  • parentstring。父项名称。

函数在成功时返回简单的 true,失败时返回 false

示例

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

// Create icon set, add few icons
const iconSet = blankIconSet('test-prefix');
iconSet.setIcon('add', {
   body: '<path d="M17 15V8h-2v7H8v2h7v7h2v-7h7v-2z" fill="currentColor"/>',
   width: 32,
   height: 32,
});

iconSet.setIcon('caret-down', {
   body: '<path d="M24 12l-8 10l-8-10z" fill="currentColor"/>',
   width: 32,
   height: 32,
});
iconSet.setVariation('caret-up', 'caret-down', {
   vFlip: true,
});

iconSet.setAlias('plus', 'add');

// Export icon set
const data = iconSet.export();
console.log(JSON.stringify(data, null, '\t'));
Result:
json{
   "prefix": "test-prefix",
   "icons": {
       "add": {
           "body": "<path d=\"M17 15V8h-2v7H8v2h7v7h2v-7h7v-2z\" fill=\"currentColor\"/>"
       },
       "caret-down": {
           "body": "<path d=\"M24 12l-8 10l-8-10z\" fill=\"currentColor\"/>"
       }
   },
   "aliases": {
       "caret-up": {
           "parent": "caret-down",
           "vFlip": true
       },
       "plus": {
           "parent": "add"
       }
   },
   "width": 32,
   "height": 32
}