Docly Developers
Function Updated 17 Oct 2026

textEncode(text, [encoding])

Converts a string into bytes using the specified encoding.

Parameters

textstringrequired

The string to encode into bytes.

encodingstringoptional

utf8 (default, also utf-8), utf32, unicode (UTF-16 little-endian, also utf), bigendianunicode, ascii, utf7 or default (UTF-8). Case-insensitive. An unknown name returns null.

Returns

A byte array (not a Node.js Buffer). null if text is null or the encoding is unknown.

Example

Normal JavaScript, running in the browser or on the Docly™ server.
// Encoding a string into bytes
let bytes = docly.textEncode("Hello, docly!", "utf8");

// Decoding bytes back into a string
let str = docly.textDecode(bytes, "utf8");
write(str); // Outputs: Hello, docly!