Skip to content

@ralphschuler.parser combinator.unicode.<internal>.TextEncoder

github-actions edited this page Nov 26, 2023 · 1 revision

Class: TextEncoder

unicode.<internal>.TextEncoder

An implementation of the WHATWG Encoding Standard TextEncoder API. All instances of TextEncoder only support UTF-8 encoding.

const encoder = new TextEncoder();
const uint8array = encoder.encode('this is some data');

The TextEncoder class is also available on the global object.

Since

v8.3.0

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new TextEncoder(): TextEncoder

Returns

TextEncoder

Properties

encoding

Readonly encoding: string

The encoding supported by the TextEncoder instance. Always set to 'utf-8'.

Defined in

node_modules/@types/node/util.d.ts:1252

Methods

encode

encode(input?): Uint8Array

UTF-8 encodes the input string and returns a Uint8Array containing the encoded bytes.

Parameters

Name Type Description
input? string The text to encode.

Returns

Uint8Array

Defined in

node_modules/@types/node/util.d.ts:1258


encodeInto

encodeInto(src, dest): EncodeIntoResult

UTF-8 encodes the src string to the dest Uint8Array and returns an object containing the read Unicode code units and written UTF-8 bytes.

const encoder = new TextEncoder();
const src = 'this is some data';
const dest = new Uint8Array(10);
const { read, written } = encoder.encodeInto(src, dest);

Parameters

Name Type Description
src string The text to encode.
dest Uint8Array The array to hold the encode result.

Returns

EncodeIntoResult

Defined in

node_modules/@types/node/util.d.ts:1272

Typescript Libraries

Modules

Namespaces

Clone this wiki locally