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

Function splitTop

ark/type/deferred.ts:387–407  ·  view source on GitHub ↗
(def: string, separator: string)

Source from the content-addressed store, hash-verified

385}
386
387const splitTop = (def: string, separator: string): string[] => {
388 const parts: string[] = []
389 let depth = 0
390 let quoted = false
391 let start = 0
392 for (let i = 0; i < def.length; i++) {
393 const c = def[i]
394 if (c === "'") quoted = !quoted
395 else if (quoted) continue
396 else if (c === "/" || c === "\\" || c === '"') return [def]
397 else if (c === "(") depth++
398 else if (c === ")") depth--
399 else if (!depth && def.startsWith(separator, i)) {
400 parts.push(def.slice(start, i))
401 i += separator.length - 1
402 start = i + 1
403 }
404 }
405 parts.push(def.slice(start))
406 return parts
407}
408
409const wrap = (f: Facts) => (f.terms ? `(${f.key})` : f.key)
410

Callers 1

scanUnionFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected