Skip to content

Instantly share code, notes, and snippets.

@C-Rodg
Created November 1, 2017 23:03
Show Gist options
  • Save C-Rodg/84649372c43e2a5eaa320fcd51fc1953 to your computer and use it in GitHub Desktop.
Save C-Rodg/84649372c43e2a5eaa320fcd51fc1953 to your computer and use it in GitHub Desktop.
Convert a string to a byte array and then encode with Base64. Useful for putting complex data structures in XML.
const convertToBytes = (str) => {
return new TextEncoder('utf-8').encode(str);
};
const dataString = 'TT12345,1:49:52 PM,10/15/13';
// ODQsODQsNDksNTAsNTEsNTIsNTMsNDQsNDksNTgsNTIsNTcsNTgsNTMsNTAsMzIsODAsNzcsNDQsNDksNDgsNDcsNDksNTMsNDcsNDksNTE=
btoa(convertToBytes(dataString));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment