UNPKG

microdata-tooling

Version:

Provides tooling to help using micro data from TypeScript/JavaScript.

67 lines (66 loc) 2.17 kB
import { Thing } from './schema-simple.js'; /** * Options for applying micro data. */ export interface ApplyOptions { /** * Format the text for a HyperLink. * * @remarks * * If not given or returns null, the content of the link is left alone. */ linkFormatter?: (data: string, elementData: DOMStringMap) => string | null; /** * Format the text for a time element. * * @remarks * * If not given, the content of the time element is left alone. */ timeFormatter?: (data: string, elementData: DOMStringMap) => string; /** * Format the text for a data element. * * @remarks * * If not given, the content of the data element is left alone. */ dataFormatter?: (data: string, elementData: DOMStringMap) => string; /** * Methods that allow for special handling for types. * * @remarks * * If a method returns false, then the properties of the item still go through the usual logic. */ typeHelpers?: { /** * Map from type to special handler. * * @remarks * * If the method returns false, then the properties of the item still go through the usual logic. */ [t: string]: (data: Thing, element: HTMLElement) => boolean; }; } /** * Apply micro data to an HTML element tree. * * @remarks * * Generally, if a value is a string it will be set as the text for an element * and if an object it will recurse on the properties. To support values that * are an array, * {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement | HTMLTemplateElement}s * are used. Each item in the array looks for a template with an attribute * `data-type` that matches the type. Strings look for a type of `Text`. * * @param data - The micro data to apply. * @param element - The root of the HTML element tree. * @param options - Optional options for applying data. * * @see {@link https://html.spec.whatwg.org/multipage/microdata.html} */ export declare function apply(data: Thing, element: HTMLElement, options?: ApplyOptions): void;