@cyanheads/pubmed-mcp-server
Version:
Search PubMed/Europe PMC, fetch articles and full text (PMC/EPMC/Unpaywall), citations, MeSH terms via MCP. STDIO or Streamable HTTP.
44 lines • 2.51 kB
TypeScript
/**
* @fileoverview Helpers for fast-xml-parser output in `preserveOrder: true` mode.
* Each element node is `{ tagName: JatsNode[] }` with an optional `:@` carrying
* attributes; text nodes are `{ "#text": value }`. Preserving order is critical
* for JATS mixed content (e.g. `<p>text <italic>inline</italic> more text</p>`)
* — the default object shape collapses all text into a single string keyed by
* `#text`, dropping inline children's position. PMC full-text articles rely on
* this order for readable abstracts and body sections.
* @module src/services/ncbi/parsing/pmc-xml-helpers
*/
/**
* A node in the ordered XML tree.
* - Element: `{ tagName: JatsNode[] }`, optionally with `:@` carrying attributes
* - Text: `{ "#text": string | number | boolean }`
*/
export type JatsNode = Record<string, unknown>;
/**
* Ordered sibling list — every children array and the document root.
* Plain `JatsNode[]` (not readonly) so `Array.isArray` narrows inputs cleanly
* in `findOne` / `findAll`; callers should not mutate the list.
*/
export type JatsNodeList = JatsNode[];
/** Tag name of an element (the single non-attribute key); undefined for text nodes. */
export declare function tagNameOf(node: JatsNode): string | undefined;
/** Ordered children of an element node. Empty for text nodes or missing tags. */
export declare function childrenOf(node: JatsNode): JatsNodeList;
/** Attribute value (caller omits the `@_` prefix). */
export declare function attrOf(node: JatsNode, name: string): string | undefined;
/** True for `{ "#text": ... }` nodes. */
export declare function isTextNode(node: JatsNode): boolean;
/** Stringified text value of a text node. */
export declare function textOf(node: JatsNode): string;
/**
* Extract all text from a node or sibling list in document order, collapsing
* runs of whitespace to a single space and trimming the result. Use this for
* mixed-content elements (`<p>`, `<title>`, `<abstract>`, …) where inline
* children must read back in the order they appear in the source.
*/
export declare function textContent(input: JatsNode | JatsNodeList | undefined): string;
/** First direct child with the given tag name. */
export declare function findOne(input: JatsNode | JatsNodeList | undefined, tagName: string): JatsNode | undefined;
/** All direct children with the given tag name. */
export declare function findAll(input: JatsNode | JatsNodeList | undefined, tagName: string): JatsNode[];
//# sourceMappingURL=pmc-xml-helpers.d.ts.map