logo

Text

This is a collection of functions for working with TextDecoder and TextEncoder.

Encode

The encodeText function encodes a string into a Uint8Array.

import { encodeText } from '@aracna/core';

// will log Uint8Array(5) [104, 101, 108, 108, 111]
console.log(encodeText('hello'));

Decode

The decodeText function decodes a buffer into a string.

import { decodeText } from '@aracna/core';

// will log "hello"
console.log(decodeText(new Uint8Array([104, 101, 108, 108, 111])));

Get a TextDecoder

The getTextDecoder function returns a new TextDecoder or a stub if the environment does not support it.

import { getTextDecoder } from '@aracna/core';

// will log TextDecoder
console.log(getTextDecoder());

Get a TextEncoder

The getTextEncoder function returns a new TextEncoder or a stub if the environment does not support it.

import { getTextEncoder } from '@aracna/core';

// will log TextEncoder
console.log(getTextEncoder());