This function is part of Iconify Utils package.

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


Function has the following parameters:

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

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


import { icons } from '@iconify-json/codicon';
import { getIconData, iconToSVG, 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 attributes for SVG element
const svgAttributes: Record<string, string> = {
   'xmlns': '',
   'xmlns:xlink': '',
const svgAttributesStr = Object.keys(svgAttributes)
       (attr) =>
           // No need to check attributes for special characters, such as quotes,
           // they cannot contain anything that needs escaping.
           `${attr}="${svgAttributes[attr as keyof typeof svgAttributes]}"`
   .join(' ');

// Generate SVG
const svg = `<svg ${svgAttributesStr}>${replaceIDs(renderData.body)}</svg>`;

// Log SVG