global.TextEncoder
Turns strings into UTF-8 bytes, for hashing, uploading or writing them.
Verwendung
Send text, form fields or bytes with fetch.
// Send text, form fields or bytes with fetch.
async function post(url: string, body: BodyInit) {
const response = await fetch(url, { method: 'POST', body });
if (!response.ok) throw new Error(`${url} answered ${response.status}`);
}
await post('https://api.example.com/login', new URLSearchParams({ user: 'ana', remember: '1' }));
await post('https://api.example.com/notes', 'Plain text, sent as UTF-8');
await post('https://api.example.com/upload', new TextEncoder().encode('bytes'));Konstruktoren
(): TextEncoderParameter
Keine Parameter.
Rückgabe
TextEncoder
Eigenschaften und Methoden 4
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
prototypeschreibgeschützt | TextEncoder | Ja | — |
encodingschreibgeschützt | "utf-8" | Ja | — |
encode | (text?: string) => Uint8Array | Ja | — |
encodeInto | (text: string, into: Uint8Array) => { read: number; written: number;} | Ja | — |
encode — Methodensignaturen
Signaturen
(text?: string): Uint8ArrayParameter
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
text | string | Nein | — |
Rückgabe
Uint8Array<ArrayBufferLike>
encodeInto — Methodensignaturen
Signaturen
(text: string, into: Uint8Array): { read: number; written: number; }Parameter
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
text | string | Ja | — |
into | Uint8Array<ArrayBufferLike> | Ja | — |
Rückgabe
{ read: number; written: number;}
Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.