import { decode } from 'utf8' ; export const hexToUtf8 = function ( hex ) { let str = '' ; let code = 0 ; hex = hex . replace ( /^0x/i , '' ) ; hex = hex . replace ( /^(?:00)*/ , '' ) ; hex = hex . split ( '' ) . reverse ( ) . join ( '' ) ; hex = hex . replace ( /^(?:00)*/ , '' ) ; hex = hex . split ( '' ) . reverse ( ) . join ( '' ) ; const l = hex . length ; for ( let i = 0 ; i < l ; i += 2 ) { code = parseInt ( hex . substr ( i , 2 ) , 16 ) ; str += String . fromCharCode ( code ) ; } return decode ( str ) ; } ;