import fonts from '../fonts/iconfont.json' ; import { IconFontMapItem , ExtendIcon } from '../types' ; const ICON_FONT_FAMILY_MAP = { } ; export const registerFontFamily = ( extendIcons ) : void => { ICON_FONT_FAMILY_MAP . graphin = fonts . glyphs as IconFontMapItem [ ] ; extendIcons . forEach ( ( item ) => { ICON_FONT_FAMILY_MAP [ item . fontFamily ] = item . map ; } ) ; } ; export default ( type , fontFamily ) => { const selectedIconFont = ICON_FONT_FAMILY_MAP [ fontFamily ] ; if ( ! selectedIconFont ) { console . warn ( `fontFamily ${ fontFamily } not found` ) ; return '' ; } const icons = selectedIconFont . map ( ( icon ) => { return { name : icon . name , unicode : String . fromCodePoint ( icon . unicode_decimal ) , } ; } ) ; const matchIcon = icons . find ( ( icon ) => { return icon . name === type ; } ) || { unicode : '' , name : '' } ; return matchIcon . unicode ; } ;