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

Method jsKeyCount

ark/schema/structure/structure.ts:1116–1129  ·  view source on GitHub ↗

writes `onCount` for a plain object whose key count is that of the declared keys it holds

(js: NodeCompiler, onCount: () => NodeCompiler)

Source from the content-addressed store, hash-verified

1114
1115 /** writes `onCount` for a plain object whose key count is that of the declared keys it holds */
1116 private jsKeyCount(js: NodeCompiler, onCount: () => NodeCompiler): void {
1117 const held = [
1118 `${this.required?.length ?? 0}`,
1119 ...(this.optional ?? []).map(
1120 prop => `+(${js.serialize(prop.key)} in data)`
1121 )
1122 ]
1123 js.if("Object.getPrototypeOf(data) === Object.prototype", () =>
1124 js
1125 .let("n", 0)
1126 .loop("for (const k in data)", () => js.line("n++"))
1127 .if(`n === ${held.join(" + ")}`, onCount)
1128 )
1129 }
1130
1131 // an Apply reporting one issue checks props as Allows does
1132 private propsOf(js: NodeCompiler): array<Prop.Node> {

Callers 1

compileMethod · 0.95

Calls 5

ifMethod · 0.80
loopMethod · 0.80
letMethod · 0.80
lineMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected