Skip to main content

@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.

Example​

import { isTextEncoderAvailable } from '@rtorcato/browser-common/encodingapis'
if (isTextEncoderAvailable()) encode()

Returns​

boolean


isTextDecoderAvailable()​

isTextDecoderAvailable(): boolean

Defined in: encodingapis/index.ts:21

Checks if the TextDecoder API is available in the current environment.

Example​

import { isTextDecoderAvailable } from '@rtorcato/browser-common/encodingapis'
if (isTextDecoderAvailable()) decode()

Returns​

boolean


encodeUTF8()​

encodeUTF8(input): Uint8Array

Defined in: encodingapis/index.ts:36

Encodes a string into a Uint8Array using UTF-8 encoding.

Example​

import { encodeUTF8 } from '@rtorcato/browser-common/encodingapis'
const bytes = encodeUTF8('hello')

Parameters​

input​

string

The string to encode.

Returns​

Uint8Array

The encoded Uint8Array.

Throws​

If TextEncoder is not available.


decodeUTF8()​

decodeUTF8(bytes): string

Defined in: encodingapis/index.ts:54

Decodes a Uint8Array into a string using UTF-8 encoding.

Example​

import { decodeUTF8 } from '@rtorcato/browser-common/encodingapis'
const text = decodeUTF8(new Uint8Array([104, 105]))

Parameters​

bytes​

Uint8Array

The Uint8Array to decode.

Returns​

string

The decoded string.

Throws​

If TextDecoder is not available.