diff options
author | Matthew Miller <matthew@millerti.me> | 2022-11-11 16:47:39 -0800 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2022-11-11 16:47:39 -0800 |
commit | 79bec97bc5ad6a8d574c588e26630c9b7333637c (patch) | |
tree | 081916fcc2ba5fea11fd965a6a129df14973bdd4 /packages/server/src/helpers/uint8array.ts | |
parent | 0e7a60ae6008ac0af4b1a180c62a1b80aceb98d5 (diff) |
Clean up uint8array text en/decoder
Diffstat (limited to 'packages/server/src/helpers/uint8array.ts')
-rw-r--r-- | packages/server/src/helpers/uint8array.ts | 24 |
1 files changed, 2 insertions, 22 deletions
diff --git a/packages/server/src/helpers/uint8array.ts b/packages/server/src/helpers/uint8array.ts index f33e913..92a53ca 100644 --- a/packages/server/src/helpers/uint8array.ts +++ b/packages/server/src/helpers/uint8array.ts @@ -63,17 +63,7 @@ export function concat(arrays: Uint8Array[]): Uint8Array { * Convert bytes into a UTF-8 string */ export function toUTF8String(array: Uint8Array): string { - type _TextDecoder = { - decode(value: Uint8Array): string; - } - /** - * The typing gets ugly here because I can't reference TS' DOM types, and I don't want to - * reference Node/Deno/Bun/... types in my quest to make this isomorphic. The fact is, the - * runtime that is "Web API"-compatible should expose `TextDecoder` globally. If not, then, - * well...I'll deal with that case if it happens. - */ - // @ts-ignore 2304 - const decoder: _TextDecoder = new globalThis.TextDecoder("utf-8"); + const decoder = new globalThis.TextDecoder("utf-8"); return decoder.decode(array); } @@ -81,17 +71,7 @@ export function toUTF8String(array: Uint8Array): string { * Convert a UTF-8 string back into bytes */ export function fromUTF8String(utf8String: string): Uint8Array { - type _TextEncoder = { - encode(value: string): Uint8Array; - } - /** - * The typing gets ugly here because I can't reference TS' DOM types, and I don't want to - * reference Node/Deno/Bun/... types in my quest to make this isomorphic. The fact is, the - * runtime that is "Web API"-compatible should expose `TextEncoder` globally. If not, then, - * well...I'll deal with that case if it happens. - */ - // @ts-ignore 2304 - const encoder: _TextEncoder = new globalThis.TextEncoder(); + const encoder = new globalThis.TextEncoder(); return encoder.encode(utf8String); } |