/** * Utility types and functions for processing XML. * * @module util/xml */ /** * Hello contributor 👋! If you are working on this file, please * endeavor to remove the need for the following `eslint-disable` line 🙏. * Remove the line and run `npx eslint path/to/this/file.ts` to * see which code needs some linting ❤️. * See https://github.com/stencila/encoda/issues/199 for suggestions * on how to refactor code to avoid non-strict boolean expressions. */ import xmljs from 'xml-js'; export type Element = xmljs.Element; export type Attributes = xmljs.Attributes; /** * Load (i.e. parse) a XML document from a string * * @param xml The XML string to load */ export declare function load(xml: string): Element; /** * Dump (i.e. serialize) a XML document to a string */ export declare const dump: typeof xmljs.js2xml; /** * Create an `Element` */ export declare function elem(name: string, attrs?: Attributes | Element | string | null, ...children: (Element | string | null)[]): Element; /** * Get an element's text content. Will always coerce the result to a string, so * null elements or those of the wrong type will return '' */ export declare function text(elem: Element | null): string; /** * Get an element's text content if possible, if the element is null, has the * wrong type or is not text, return undefined */ export declare function textOrUndefined(elem: Element | null): string | undefined; /** * Split the text of `elem` on `separator`. If `elem` is null or text can't be * extracted from it, return undefined */ export declare function splitTextOrUndefined(elem: Element | null, separator: string | RegExp): string[] | undefined; /** * Get an elements text content and convert it to an integer. If the element * content is undefined/empty/null/invalid or not a number, then return * undefined */ export declare function intOrUndefined(elem: Element | null): number | undefined; /** * Get an element attribute */ export declare function attr(elem: Element | null, name: string): string | null; /** * Get an element attribute or `undefined` if it does not exist */ export declare function attrOrUndefined(elem: Element | null, name: string): string | undefined; /** * Does an element match name/s and attributes */ export declare function matches(elem: Element, name: string | string[], attributes?: Attributes): boolean; /** * Get the first child element that matches name/s and attributes */ export declare function child(elem: Element | null, name: string | string[], attributes?: Attributes): Element | null; /** * Get all child elements that match name/s and attributes */ export declare function children(elem: Element | null, name: string | string[], attributes?: Attributes): Element[]; /** * Get the first descendent element that matches name/s and attributes */ export declare function first(elem: Element | null, name: string | string[], attributes?: Attributes): Element | null; /** * Get the first descendent element of a specific type */ export declare function firstByType(elem: Element | null, type: string | null): Element | null; /** * Get all descendent elements that match name/s and attributes */ export declare function all(elem: Element | null, name: string | string[], attributes?: Attributes): Element[];