Skip to content

count()

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

函数 count() 用于统计图标集中的图标数量。

用法

该函数无参数。

函数返回图标的 number(数量)。

统计哪些图标?

计入统计的:

  • 图标。
  • 变体(见下文)。

不计入统计的:

  • 隐藏的图标及其别名/变体。
  • 别名。

图标类型

IconSet 中包含 3 种类型的图标项:"icon"、"variation"、"alias"。

"icon" 表示一个完整的唯一图标。

"variation" 表示另一个图标的变体。它具有以下属性:

  • parentstring。父图标的名称。

以及至少以下变换之一:

  • rotate 旋转 90180270 度。
  • hFlip 水平翻转。
  • vFlip 垂直翻转。

变体使得创建图标克隆变得很容易,例如在创建 arrow-right 之后创建 arrow-left

"alias" 是图标的别名。它具有以下属性:

  • parentstring。父图标的名称。

可以创建别名来为图标提供不同的名称。如果您重命名了某个图标,可以使用别名来允许用户继续使用旧名称。

示例

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

const iconSet = new IconSet({
   prefix: 'codicon',
   icons: {
       // Counted
       'add': {
           body: '<g fill="currentColor"><path d="M14 7v1H8v6H7V8H1V7h6V1h1v6h6z"/></g>',
       },
       // Ignored: hidden
       'debug-pause': {
           body: '<g fill="currentColor"><path d="M4.5 3H6v10H4.5V3zm7 0v10H10V3h1.5z"/></g>',
           hidden: true,
       },
       // Counted
       'triangle-left': {
           body: '<g fill="currentColor"><path d="M10.44 2l.56.413v11.194l-.54.393L5 8.373v-.827L10.44 2z"/></g>',
       },
   },
   aliases: {
       // Ignored: alias
       'plus': {
           parent: 'add',
       },
       // Counted: variation
       'triangle-right': {
           parent: 'triangle-left',
           hFlip: true,
       },
   },
});

// Count icons: returns 3
console.log(iconSet.count());