MCPcopy Create free account
hub / github.com/Effect-TS/effect / text

Function text

packages/effect/src/http/HttpBody.ts:323–333  ·  view source on GitHub ↗
(body: string, contentType?: string)

Source from the content-addressed store, hash-verified

321 * @since 4.0.0
322 */
323export 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.

Callers 3

jsonUnsafeFunction · 0.70
jsonFunction · 0.70
urlParamsFunction · 0.70

Calls 3

byteLengthMethod · 0.80
encodeMethod · 0.80
StringFunction · 0.50

Tested by

no test coverage detected