Skip to content

checkTheme()

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

函数 checkTheme() 用于查找属于特定主题的所有图标。它可用于验证主题,以确保不存在空主题或缺失的主题。

用法

该函数包含以下参数:

  • prefixboolean 类型。指定要检查的内容。如果为 true,函数将检查 prefixes。如果为 false,函数将检查 suffixes

该函数返回一个包含以下属性的对象:

  • validRecord<string,string[]> 类型。匹配主题的图标。键为主题名称(而非标题!),值为图标名称数组。
  • invalidstring[] 类型。不匹配任何主题的图标。

示例

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-down-regular': {
           body: '<path d="M24.59 16.59L17 24.17V4h-2v20.17l-7.59-7.58L6 18l10 10l10-10l-1.41-1.41z" fill="currentColor"/>',
       },
       'arrow-left-regular': {
           body: '<path d="M14 26l1.41-1.41L7.83 17H28v-2H7.83l7.58-7.59L14 6L4 16l10 10z" fill="currentColor"/>',
       },
       'back-to-top-regular': {
           body: '<path d="M16 14L6 24l1.4 1.4l8.6-8.6l8.6 8.6L26 24z" fill="currentColor"/><path d="M4 8h24v2H4z" fill="currentColor"/>',
       },
       'bookmark-filled': {
           body: '<path d="M24 2H8a2 2 0 0 0-2 2v26l10-5.054L26 30V4a2 2 0 0 0-2-2z" fill="currentColor"/>',
       },
       'caret-down-regular': {
           body: '<path d="M24 12l-8 10l-8-10z" fill="currentColor"/>',
       },
       'caret-left-regular': {
           body: '<path d="M20 24l-10-8l10-8z" fill="currentColor"/>',
       },
   },
   aliases: {
       'add-regular': {
           parent: 'add',
       },
       'arrow-up-regular': {
           parent: 'arrow-down-regular',
           vFlip: true,
       },
       'arrow-right-regular': {
           parent: 'arrow-left-regular',
           hFlip: true,
       },
       'caret-up-regular': {
           parent: 'caret-down-regular',
           vFlip: true,
       },
       'caret-right-regular': {
           parent: 'caret-left-regular',
           hFlip: true,
       },
   },
   width: 32,
   height: 32,
   prefixes: {
       arrow: 'Arrows',
       caret: 'Carets',
   },
   suffixes: {
       'filled': 'Filled',
       'regular': 'Regular',
       '': 'Other',
   },
});

// Check all prefixes
console.log(iconSet.checkTheme(true));

// Check all suffixes
console.log(iconSet.checkTheme(false));
Results:
json{
   "valid": {
       "arrow": [
           "arrow-down-regular",
           "arrow-left-regular",
           "arrow-up-regular",
           "arrow-right-regular"
       ],
       "caret": [
           "caret-down-regular",
           "caret-left-regular",
           "caret-up-regular",
           "caret-right-regular"
       ]
   },
   "invalid": ["add", "back-to-top-regular", "bookmark-filled"]
}
json{
   "valid": {
       "regular": [
           "arrow-down-regular",
           "arrow-left-regular",
           "back-to-top-regular",
           "caret-down-regular",
           "caret-left-regular",
           "arrow-up-regular",
           "arrow-right-regular",
           "caret-up-regular",
           "caret-right-regular"
       ],
       "filled": ["bookmark-filled"],
       "": ["add"]
   },
   "invalid": []
}