MCPcopy Create free account
hub / github.com/langgenius/dify / isJSONSerializable

Function isJSONSerializable

cli/src/http/body.ts:6–26  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

4// plain objects, arrays, and anything with a `toJSON` method — but not typed
5// arrays/buffers, FormData, or URLSearchParams, which are sent as-is.
6export function isJSONSerializable(value: unknown): boolean {
7 if (value === undefined)
8 return false
9 if (value === null)
10 return true
11 const t = typeof value
12 if (t === 'string' || t === 'number' || t === 'boolean')
13 return true
14 if (t !== 'object')
15 return false
16 if (Array.isArray(value))
17 return true
18 const obj = value as { buffer?: unknown, constructor?: { name?: string }, toJSON?: unknown }
19 if (obj.buffer !== undefined)
20 return false
21 if (value instanceof FormData || value instanceof URLSearchParams)
22 return false
23 if (obj.constructor?.name === 'Object')
24 return true
25 return typeof obj.toJSON === 'function'
26}
27
28export type BuildBodyInput = {
29 readonly json?: unknown

Callers 2

body.test.tsFile · 0.85
buildBodyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected