UNPKG

@trpc/client

Version:

The tRPC client library

20 lines (17 loc) • 512 B
import type { Encoder } from '@trpc/server/unstable-core-do-not-import'; export type { Encoder }; /** * The default WebSocket encoder. Sends messages as JSON text frames. */ export const jsonEncoder: Encoder = { encode: (data) => JSON.stringify(data), decode: (data) => { if (typeof data !== 'string') { throw new Error( 'jsonEncoder received binary data. JSON uses text frames. ' + 'Use a binary encoder for binary data.', ); } return JSON.parse(data); }, };