function percentToByte ( p ) { return String . fromCharCode ( parseInt ( p . slice ( 1 ) , 16 ) ) ; } export function encode ( str ) { return btoa ( encodeURIComponent ( str ) . replace ( /%[0-9A-F]{2}/g , percentToByte ) ) ; } function byteToPercent ( b ) { return `%${ `00${ b . charCodeAt ( 0 ) . toString ( 16 ) }` . slice ( - 2 ) }` ; } export function decode ( str ) { return decodeURIComponent ( Array . from ( atob ( str ) , byteToPercent ) . join ( "" ) ) ; }