(body: string, contentType?: string)
| 321 | * @since 4.0.0 |
| 322 | */ |
| 323 | export const text = (body: string, contentType?: string): Uint8Array => { |
| 324 | if (typeof body !== "string") { |
| 325 | // Preserve untyped callers that relied on TextEncoder coercion. |
| 326 | body = body === undefined ? "" : String(body) |
| 327 | } |
| 328 | if (buffer !== undefined) { |
| 329 | return new Uint8Array(undefined, contentType ?? "text/plain", buffer.byteLength(body, "utf8"), body) |
| 330 | } |
| 331 | const bytes = encoder.encode(body) |
| 332 | return new Uint8Array(bytes, contentType ?? "text/plain", bytes.length, body) |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Creates a JSON HTTP body using `JSON.stringify`, throwing if serialization fails. |
no test coverage detected