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

Function fits

ark/type/deferred.ts:215–236  ·  view source on GitHub ↗
(value: unknown, facts: Facts)

Source from the content-addressed store, hash-verified

213const record = /^Record<string, (.+)>$/
214
215const fits = (value: unknown, facts: Facts): boolean => {
216 // without exactOptionalPropertyTypes a default replaces undefined, so can't be it
217 if (value === undefined) return false
218 if (facts.values) return facts.values.includes(value)
219 if (typeof value === "string") {
220 return (
221 facts.base === "string" &&
222 value.length >= (facts.min ?? 0) &&
223 value.length <= (facts.max ?? Infinity)
224 )
225 }
226 return (
227 typeof value === "number" &&
228 Number.isFinite(value) &&
229 (facts.base === "number" ||
230 (facts.base === "integer" && Number.isInteger(value))) &&
231 (facts.min === undefined ||
232 (facts.minExclusive ? value > facts.min : value >= facts.min)) &&
233 (facts.max === undefined ||
234 (facts.maxExclusive ? value < facts.max : value <= facts.max))
235 )
236}
237
238const holdsNarrow = 1
239const holdsUnit = 2

Callers 3

scanUncachedFunction · 0.85
walkLiteralFunction · 0.85
deferred.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected