MCPcopy Create free account
hub / github.com/arktypeio/arktype / defaultValueSerializer

Function defaultValueSerializer

ark/schema/shared/implement.ts:247–264  ·  view source on GitHub ↗
(v: unknown)

Source from the content-addressed store, hash-verified

245 /^(?:"|\$ark\d*\.|(?:NaN|-?Infinity|-0|-?\d+n|undefined|Invalid Date|[+-]?\d{4,6}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z)$)/
246
247export const defaultValueSerializer = (v: unknown): Json => {
248 if (typeof v === "string")
249 return ambiguousStringPattern.test(v) ? JSON.stringify(v) : v
250 if (typeof v === "boolean" || v === null) return v
251
252 if (typeof v === "number") {
253 if (Number.isNaN(v)) return "NaN"
254 if (v === Number.POSITIVE_INFINITY) return "Infinity"
255 if (v === Number.NEGATIVE_INFINITY) return "-Infinity"
256 if (Object.is(v, -0)) return "-0"
257 return v
258 }
259
260 // registering would keep the value alive, so only values compiled code reads are registered
261 return hasDomain(v, "object") || typeof v === "symbol" ?
262 namedReference(v)
263 : serializePrimitive(v as never)
264}
265
266export const metaJsonOf = (meta: ArkEnv.meta): JsonObject =>
267 flatMorph(meta, (k, v) => [

Callers 4

serializeUnitFunction · 0.90
sequence.tsFile · 0.90
toJsonSchema.tsFile · 0.90
metaJsonOfFunction · 0.85

Calls 5

hasDomainFunction · 0.90
namedReferenceFunction · 0.90
serializePrimitiveFunction · 0.90
testMethod · 0.80
isMethod · 0.80

Tested by

no test coverage detected