global.TextEncoder
Turns strings into UTF-8 bytes, for hashing, uploading or writing them.
Utilização
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'));Construtores
(): TextEncoderParâmetros
Sem parâmetros.
Devolve
TextEncoder
Propriedades e métodos 4
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
prototypesó de leitura | TextEncoder | Sim | — |
encodingsó de leitura | "utf-8" | Sim | — |
encode | (text?: string) => Uint8Array | Sim | — |
encodeInto | (text: string, into: Uint8Array) => { read: number; written: number;} | Sim | — |
encode — assinaturas de método
Assinaturas
(text?: string): Uint8ArrayParâmetros
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
text | string | Não | — |
Devolve
Uint8Array<ArrayBufferLike>
encodeInto — assinaturas de método
Assinaturas
(text: string, into: Uint8Array): { read: number; written: number; }Parâmetros
| Nome | Tipo | Obrigatório | Descrição |
|---|---|---|---|
text | string | Sim | — |
into | Uint8Array<ArrayBufferLike> | Sim | — |
Devolve
{ read: number; written: number;}
Gerado a partir das declarações TypeScript públicas: assinaturas, props e predefinições vêm da fonte verificada, as descrições da sua JSDoc. Nenhuma predefinição é inventada.