TextEncoder takes a stream of code points as input and emits a stream of bytes. For a more scalable, non-native library, see StringView – a C-like representation of strings based on typed arrays.
class TextEncoder | globals module | Bun BuildDocsReferenceGuidesBlogDiscord/Globals/TextEncoderMencodeMencodeIntoPencoding BuildDocsReferenceGuidesBlogDiscord /Globals/TextEncoderMencodeMencodeIntoPencoding readonly encoding: string encode(input?: string): Uint8Array; encodeInto(source: string,destination: Uint8Array): TextEncoderEncodeIntoResult; encodeInto(src?: string,dest?: BufferSource): TextEncoderEncodeIntoResult; @param src @param dest
Search the reference...
/
class
TextEncoderclass TextEncoderReturns "utf-8".
Returns the result of running UTF-8's encoder.
Runs the UTF-8 encoder on source, stores the result of that operation into destination, and returns the progress made as an object wherein read is the number of converted code units of source and written is the number of bytes modified in destination.
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);
The text to encode.
The array to hold the encode result.
Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlogToolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →class TextEncoder | globals module | Bun,AI智能索引,全网链接索引,智能导航,网页索引
- TextEncoder takes a stream of code points as input and emits a stream of bytes. For a more scalable, non-native library, see StringView – a C-like representation of strings based on typed arrays.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/TextEncoder)