import { getAllIconsObject , TIconObject } from "./assets/icons_object" ; import { getClassName } from "./icons" ; import { TQuery } from "./query" ; export type TEncodedQuery = string ; const decodeQuery = ( encodedQuery ) : TQuery => { const queryJsonString = Buffer . from ( encodedQuery , "base64" ) . toString ( ) ; return JSON . parse ( queryJsonString ) as TQuery ; } ; const getIconObject = ( query ) : TIconObject | undefined => { const allIconsObject = getAllIconsObject ( ) ; return allIconsObject . find ( ( icon ) => icon . name === query . name && icon . style === query . style ) ; } ; export const putName = ( encodedQuery ) : string | null => { const query = decodeQuery ( encodedQuery ) ; const iconObject = getIconObject ( query ) ; if ( ! iconObject ) return null ; return getClassName ( iconObject ) ; } ; export const putCode = ( encodedQuery ) : string | null => { const query = decodeQuery ( encodedQuery ) ; const iconObject = getIconObject ( query ) ; if ( ! iconObject ) return null ; return iconObject . unicode ; } ; export const putRef = ( encodedQuery ) : string | null => { const query = decodeQuery ( encodedQuery ) ; const iconObject = getIconObject ( query ) ; if ( ! iconObject ) return null ; const ref = String . fromCodePoint ( parseInt ( iconObject . unicode , 16 ) ) ; return ref ; } ; export const putUrl = ( encodedQuery ) : string | null => { const query = decodeQuery ( encodedQuery ) ; const iconObject = getIconObject ( query ) ; if ( ! iconObject ) return null ; return `https://fontawesome.com/icons/${ iconObject . name }` ; } ;