hashlink
Version:
Javascript Cryptographic Hyperlinks Library (hashlink)
15 lines (13 loc) • 396 B
JavaScript
// Node.js TextDecoder/TextEncoder
import {TextDecoder, TextEncoder} from 'util';
export {TextDecoder, TextEncoder};
export function stringToUint8Array(data) {
if(typeof data === 'string') {
// convert data to Uint8Array
return new TextEncoder().encode(data);
}
if(!(data instanceof Uint8Array)) {
throw new TypeError('"data" be a string or Uint8Array.');
}
return data;
}