@rtorcato/browser-common / encodingapis
encodingapis
Functions
isTextEncoderAvailable()
isTextEncoderAvailable():
boolean
Defined in: encodingapis/index.ts:9
Checks if the TextEncoder API is available in the current environment.
Returns
boolean
Example
import { isTextEncoderAvailable } from '@rtorcato/browser-common/encodingapis'
if (isTextEncoderAvailable()) encode()
isTextDecoderAvailable()
isTextDecoderAvailable():
boolean
Defined in: encodingapis/index.ts:21
Checks if the TextDecoder API is available in the current environment.
Returns
boolean
Example
import { isTextDecoderAvailable } from '@rtorcato/browser-common/encodingapis'
if (isTextDecoderAvailable()) decode()
encodeUTF8()
encodeUTF8(
input):Uint8Array
Defined in: encodingapis/index.ts:36
Encodes a string into a Uint8Array using UTF-8 encoding.
Parameters
input
string
The string to encode.
Returns
Uint8Array
The encoded Uint8Array.
Throws
If TextEncoder is not available.
Example
import { encodeUTF8 } from '@rtorcato/browser-common/encodingapis'
const bytes = encodeUTF8('hello')
decodeUTF8()
decodeUTF8(
bytes):string
Defined in: encodingapis/index.ts:54
Decodes a Uint8Array into a string using UTF-8 encoding.
Parameters
bytes
Uint8Array
The Uint8Array to decode.
Returns
string
The decoded string.
Throws
If TextDecoder is not available.
Example
import { decodeUTF8 } from '@rtorcato/browser-common/encodingapis'
const text = decodeUTF8(new Uint8Array([104, 105]))