MCPcopy
hub / github.com/code-hike/codehike / parseProps

Function parseProps

packages/codehike/src/blocks.ts:55–90  ·  view source on GitHub ↗
(
  content: unknown,
  Schema: z.ZodType<Output, Def, Input>,
)

Source from the content-addressed store, hash-verified

53})
54
55export function parseProps<Output, Def extends ZodTypeDef, Input>(
56 content: unknown,
57 Schema: z.ZodType<Output, Def, Input>,
58): Output {
59 if ((content as any)?.__hike) {
60 throw new Error(
61 "Code Hike Error: can't parse component content. Looks like you are missing CodeHike's recma plugin or the framework you are using doesn't support it.",
62 )
63 }
64
65 const result = Schema.safeParse(content)
66 if (result.success) {
67 return result.data
68 }
69
70 const error = result.error.errors[0]
71
72 let p = error.path.slice()
73 let block = content as any
74 let location = ""
75 while (p.length) {
76 const key = p.shift()!
77 block = block[key]
78 if (block?._data?.header) {
79 location += `\n${block._data.header}`
80 }
81 }
82
83 const { path, code, message, ...rest } = error
84 const name = path[path.length - 1]
85
86 throw new Error(`at ${location || "root"}
87Error for \`${name}\`: ${message}
88${JSON.stringify(rest, null, 2)}
89 `)
90}

Callers 15

BlocksDemoFunction · 0.90
CodeWithNotesFunction · 0.90
ExampleTabsFunction · 0.90
ChainFunction · 0.90
CodeblocksFunction · 0.90
FineGrainedFunction · 0.90
LayoutFunction · 0.90
ScrollyFunction · 0.90
ColumnsFunction · 0.90
ScrollycodingFunction · 0.90
APIReferenceFunction · 0.90
ExamplesFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…