MCPcopy Create free account
hub / github.com/TanStack/query / signatureTypes

Function signatureTypes

scripts/generate-docs.ts:565–593  ·  view source on GitHub ↗
(signature: string)

Source from the content-addressed store, hash-verified

563
564// The type line of each parameter and of the return value in one call signature.
565function signatureTypes(signature: string) {
566 const parametersHeading = signature.match(/\n#{2,3} Parameters\n/)
567 const returnsHeading = signature.match(/\n#{2,3} Returns\n/)
568 const parameters = parametersHeading
569 ? signature.slice(
570 parametersHeading.index! + parametersHeading[0].length - 1,
571 returnsHeading?.index,
572 )
573 : ''
574 // Only the headings one level below `Parameters`, not the properties of an inline object argument.
575 const parameterHeading = '#'.repeat(
576 (parametersHeading?.[0].trim().indexOf(' ') ?? 0) + 1,
577 )
578 return {
579 parameters: new Map(
580 [
581 ...parameters.matchAll(
582 new RegExp(`\\n${parameterHeading} (\\S+)\\n\\n([^\\n]*)`, 'g'),
583 ),
584 ].map(([, name, typeLine]) => [name!, typeLine!]),
585 ),
586 returns: returnsHeading
587 ? signature
588 .slice(returnsHeading.index! + returnsHeading[0].length)
589 .trim()
590 .split('\n')[0]!
591 : undefined,
592 }
593}
594
595function typeAliasBody(source: string | undefined) {
596 const declaration = source?.match(/```ts\ntype \w+/)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected