@fruitsjs/util
Version:
Useful utilities and tools for building Fruits Eco-Blockchain applications
17 lines (15 loc) • 502 B
text/typescript
/**
* Converts a string into byte array
* Inverse function [[convertByteArrayToString]]
* @param str The string to be converted
* @return {number[]} A byte array representing the string input
* @module util
*/
export const convertStringToByteArray = (str: string): Uint8Array => {
const s = unescape(encodeURIComponent(str));
const bytes = new Uint8Array(s.length);
for (let i = 0; i < s.length; ++i) {
bytes[i] = s.charCodeAt(i);
}
return bytes;
};