Skip to content

getTree()

This function is part of IconSet class in Iconify Tools.

Function getTree() returns list of parent icons for each icon in icon set, null for icons that cannot be resolved.

It is useful when you need to figure out which icons need to be exported when exporting a subset of icons, it can be used to figure out which icons have invalid parent icons.

Usage

Function has the following optional parameter:

  • names, string[]. List of icons to check. If not set, all icons will be checked.

Function will return object, where key is icon name, value is:

  • null if icon cannot be resolved.
  • string[] array of parent icon names, excluding icon. First entry is direct parent.

Example

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

const iconSet = new IconSet({
   prefix: 'foo',
   icons: {
       bar: {
           body: '<g />',
       },
   },
   aliases: {
       baz: {
           parent: 'bar',
       },
       baz2: {
           parent: 'baz',
       },
       bad: {
           parent: 'whatever',
       },
   },
});

console.log(iconSet.getTree());
Result:
json{
   "bar": [],
   "baz": ["bar"],
   "baz2": ["baz", "bar"],
   "bad": null,
   "whatever": null
}

Released under the Apache 2.0 License.