import React from 'react' ; import * as allIcons from '@ant-design/icons' ; import { IRoute } from '@vitjs/core' ; React . version ; function toHump ( name ) { return name . replace ( /\-(\w)/g , function ( all , letter ) { return letter . toUpperCase ( ) ; } ) ; } type IconMap = { [ icon ] : string ; } ; export function resolveIcons ( data , parentIcons ? ) { if ( ! Array . isArray ( data ) ) { return { } ; } let icons = parentIcons || { } ; ( data || [ ] ) . forEach ( ( item = { path : '/' } ) => { if ( item . icon ) { const { icon } = item ; const v4IconName = toHump ( icon . replace ( icon [ 0 ] , icon [ 0 ] . toUpperCase ( ) ) ) ; if ( ( allIcons as any ) [ icon ] && ! icons [ icon ] ) { icons [ icon ] = icon ; } if ( ( allIcons as any ) [ `${ v4IconName }Outlined` ] && ! icons [ icon ] ) { icons [ icon ] = `${ v4IconName }Outlined` ; } } if ( item . routes ) { icons = resolveIcons ( item . routes , icons ) ; } } ) ; return icons ; }