UNPKG

@blockcerts/hashlink-verifier

Version:
17 lines (15 loc) 488 B
// browser TextDecoder/TextEncoder /* eslint-env browser */ const TextDecoder = self.TextDecoder; const TextEncoder = self.TextEncoder; export { TextDecoder, TextEncoder }; export function stringToUint8Array (data: string | Uint8Array): Uint8Array { 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; }