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

Function allowedIndexCountOf

ark/sets/structure/structure.ts:116–131  ·  view source on GitHub ↗
(
	keys: BaseRoot,
	sequence: nodeOfKind<"sequence">
)

Source from the content-addressed store, hash-verified

114// reject an index, since one keys like /^\d+$/ allow past the count would make
115// a longer array that's allowed disjoint
116const allowedIndexCountOf = (
117 keys: BaseRoot,
118 sequence: nodeOfKind<"sequence">
119): number | null => {
120 if ($ark.kw.nonNegativeIntegerString.internal.extends(keys)) return null
121 const max = Math.min(
122 sequence.maxLength ?? maxCountedIndices,
123 maxCountedIndices
124 )
125 let count = 0
126 while (count < max && keys.allowsUnused(`${count}`)) count++
127 if (count === sequence.maxLength) return null
128 return count < maxCountedIndices || !keys.allowsUnused(`${count}`) ?
129 count
130 : null
131}
132
133// the element at an index below a sequence's minLength
134const requiredElementAt = (

Callers 1

narrowToKeysOfFunction · 0.85

Calls 1

extendsMethod · 0.80

Tested by

no test coverage detected