Skip to content
On this page

getIconData()

This function is part of Iconify Utils package.

Function getIconData() retrieves data for one icon from icon set.

Usage

Function has the following parameters:

  • data, IconifyJSON. Icon set data.
  • name, string. Icon name.

Function returns icon data with type IconifyIcon, null on error.

Example

usage.ts
tsimport { icons } from '@iconify-json/codicon';
import { getIconData, iconToSVG, iconToHTML, replaceIDs } from '@iconify/utils';

const iconName = 'debug-console';

// Get content for icon
const iconData = getIconData(icons, iconName);
if (!iconData) {
   throw new Error(`Icon "${iconName}" is missing`);
}

// Use it to render icon
const renderData = iconToSVG(iconData, {
   height: 'auto',
});

// Generate SVG string
const svg = iconToHTML(replaceIDs(renderData.body), renderData.attributes);

// Log SVG
console.log(svg);
Result:

Released under the Apache 2.0 License.