import type { IconifyIcon , IconifyJSON } from '@iconify/types' ; import { fullIcon } from '@iconify/utils/lib/icon' ; import { parseIconSet } from '@iconify/utils/lib/icon-set/parse' ; import { render } from './render' ; import type { RenderResult } from './render' ; import type { IconProps } from './props' ; /**
 * Storage for icons referred by name
 */ const storage = Object . create ( null ) ; /**
 * Generate icon
 */ export function generateIcon ( props ) { const icon = typeof props . icon === 'string' ? storage [ props . icon ] : typeof props . icon === 'object' ? fullIcon ( props . icon ) : null ; if ( icon === null || typeof icon !== 'object' || typeof icon . body !== 'string' ) { return null ; } return render ( icon , props ) ; } param name param data export function addIcon ( name , data ) { storage [ name ] = fullIcon ( data ) ; } param data param prefix export function addCollection ( data , prefix ? ) { const iconPrefix = typeof prefix === 'string' ? prefix : prefix !== false && typeof data . prefix === 'string' ? data . prefix + ':' : '' ; parseIconSet ( data , ( name , icon ) => { if ( icon ) { storage [ iconPrefix + name ] = icon ; } } , { validate : { fix : true , prefix : iconPrefix , } , } ) ; }