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

Function preparseKey

ark/type/parser/objectLiteral.ts:398–424  ·  view source on GitHub ↗
(key: Key)

Source from the content-addressed store, hash-verified

396export type IndexKey<def extends string = string> = `[${def}]`
397
398export const preparseKey = (key: Key): PreparsedKey =>
399 typeof key === "symbol" ? { kind: "required", normalized: key }
400 : key[key.length - 1] === "?" ?
401 key[key.length - 2] === Backslash ?
402 { kind: "required", normalized: `${key.slice(0, -2)}?` }
403 : key[0] === "[" && key[key.length - 2] === "]" ?
404 throwParseError(
405 writeOptionalIndexKeyMessage(key.slice(0, -1) as IndexKey)
406 )
407 : key[0] === Backslash && key[1] === "[" && key[key.length - 2] === "]" ?
408 { kind: "optional", normalized: key.slice(1, -1) }
409 : { kind: "optional", normalized: key.slice(0, -1) }
410 : key[0] === "[" && key[key.length - 1] === "]" ?
411 { kind: "index", normalized: key.slice(1, -1) }
412 : key[0] === Backslash && key[1] === "[" && key[key.length - 1] === "]" ?
413 { kind: "required", normalized: key.slice(1) }
414 : key === "..." ? { kind: "spread" }
415 : key === "+" ? { kind: "undeclared" }
416 : key === "@" ? { kind: "meta" }
417 : {
418 kind: "required",
419 normalized:
420 key === "\\..." ? "..."
421 : key === "\\+" ? "+"
422 : key === "\\@" ? "@"
423 : key
424 }
425
426export type preparseKey<k> =
427 k extends symbol ?

Callers 2

walkLiteralFunction · 0.90
parseObjectLiteralFunction · 0.85

Calls 2

throwParseErrorFunction · 0.90

Tested by

no test coverage detected