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

Function parse

ark/sets/formats.ts:45–64  ·  view source on GitHub ↗
(schema: Schema, options?: ParseOptions)

Source from the content-addressed store, hash-verified

43
44/** the Root a schema's values make up */
45export const parse = (schema: Schema, options?: ParseOptions): Root => {
46 const io = options?.io ?? "in"
47 if (schema instanceof BaseRoot) return io === "in" ? schema._in : schema._out
48 if (typeof schema === "boolean") return readJsonSchema(schema, options?.root)
49 if (!hasDomain(schema, "object"))
50 return throwParseError(writeUnparsableSchemaMessage(printable(schema)))
51 if (!("~standard" in schema)) {
52 return isJsonSchemaObject(schema) ?
53 readJsonSchema(schema, options?.root)
54 : throwParseError(writeUnparsableSchemaMessage(printable(schema)))
55 }
56 let root = standardRootsByIo[io].get(schema)
57 if (!root) {
58 standardRootsByIo[io].set(
59 schema,
60 (root = readStandardSchema(schema as StandardJSONSchemaV1, io))
61 )
62 }
63 return root
64}
65
66/** the JSON Schema of a schema's values */
67export const toJsonSchema = (

Callers 14

isSubsetFunction · 0.90
isDisjointFunction · 0.90
intersectFunction · 0.90
unionFunction · 0.90
discriminateFunction · 0.90
toJsonSchemaFunction · 0.70
gc.test.tsFile · 0.50
algebra.test.tsFile · 0.50
parse.test.tsFile · 0.50
readFunction · 0.50
disagreementsOfFunction · 0.50

Calls 9

readJsonSchemaFunction · 0.90
hasDomainFunction · 0.90
throwParseErrorFunction · 0.90
printableFunction · 0.90
isJsonSchemaObjectFunction · 0.90
readStandardSchemaFunction · 0.85
getMethod · 0.65
setMethod · 0.45

Tested by 3

readFunction · 0.40
disagreementsOfFunction · 0.40
checkEquivalentFunction · 0.40