Skip to content

TextEncoder

[<Interface>]
type TextEncoder =
    abstract member encoding: string
    static member Create (encoding: string, encode: string option -> NonSharedUint8Array, encodeInto: Func<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,EncodeIntoResult>) : TextEncoder
    abstract member encode (?input: string) : NonSharedUint8Array
    abstract member encodeInto (src: string, dest: Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>) : EncodeIntoResult
AssemblyXantham.Fable.Node
Attributes[<Interface>]

An implementation of the WHATWG Encoding StandardTextEncoder 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

Properties

abstract member encoding: string

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

Methods

static member Create (encoding: string, encode: string option -> NonSharedUint8Array, encodeInto: Func<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,EncodeIntoResult>) : TextEncoder
abstract member encode (?input: string) : NonSharedUint8Array

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

Parameter
inputThe text to encode.
abstract member encodeInto (src: string, dest: Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>) : 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);
Parameter
srcThe text to encode.
destThe array to hold the encode result.