global.TextEncoder
Turns strings into UTF-8 bytes, for hashing, uploading or writing them.
Utilisation
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'));Constructeurs
(): TextEncoderParamètres
Aucun paramètre.
Retourne
TextEncoder
Propriétés et méthodes 4
| Nom | Type | Requis | Description |
|---|---|---|---|
prototypelecture seule | TextEncoder | Oui | — |
encodinglecture seule | "utf-8" | Oui | — |
encode | (text?: string) => Uint8Array | Oui | — |
encodeInto | (text: string, into: Uint8Array) => { read: number; written: number;} | Oui | — |
encode — signatures de méthode
Signatures
(text?: string): Uint8ArrayParamètres
| Nom | Type | Requis | Description |
|---|---|---|---|
text | string | Non | — |
Retourne
Uint8Array<ArrayBufferLike>
encodeInto — signatures de méthode
Signatures
(text: string, into: Uint8Array): { read: number; written: number; }Paramètres
| Nom | Type | Requis | Description |
|---|---|---|---|
text | string | Oui | — |
into | Uint8Array<ArrayBufferLike> | Oui | — |
Retourne
{ read: number; written: number;}
Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.