UNPKG

htmlmetaparser

Version:

A `htmlparser2` handler for parsing rich metadata from HTML. Includes HTML metadata, JSON-LD, RDFa, microdata, OEmbed, Twitter cards and AppLinks.

225 lines (224 loc) 5.66 kB
/** * Keep track of vocabulary prefixes. */ export declare const KNOWN_VOCABULARIES: { [prefix: string]: string; }; export interface HtmlValueMap { [tagName: string]: (attrs: { [key: string]: string; }, baseUrl: string) => string | undefined; } /** * Grab the correct attribute for RDFa support. */ export declare const HTML_VALUE_MAP: HtmlValueMap; export interface HandlerContext { tagName: string; text: string; flags: number; attributes: { [key: string]: string; }; rdfaTextProperty?: string[]; microdataTextProperty?: string[]; } export declare const HandlerFlags: { hasLang: number; rdfaLink: number; rdfaNode: number; rdfaVocab: number; microdataNode: number; microdataVocab: number; microdataScope: number; }; export interface ResultTwitter { card?: string; site?: string; "site:id"?: string; creator?: string; "creator:id"?: string; description?: string; title?: string; image?: string; "image:alt"?: string; player?: string; "player:width"?: string; "player:height"?: string; "player:stream"?: string; "app:name:iphone"?: string; "app:id:iphone"?: string; "app:url:iphone"?: string; "app:name:ipad"?: string; "app:id:ipad"?: string; "app:url:ipad"?: string; "app:name:googleplay"?: string; "app:id:googleplay"?: string; "app:url:googleplay"?: string; [key: string]: string | undefined; } export interface ResultDublinCore { title?: string; date?: string; "date.issued"?: string; "date.modified"?: string; [key: string]: string | undefined; } export interface ResultSailthru { title?: string; description?: string; author?: string; tags?: string; date?: string; expire_date?: string; "image.full"?: string; "image.thumb"?: string; location?: string; price?: string; [key: string]: string | undefined; } export interface ResultApplinks { "ios:url"?: string; "ios:app_store_id"?: string; "ios:app_name"?: string; "iphone:url"?: string; "iphone:app_store_id"?: string; "iphone:app_name"?: string; "ipad:url"?: string; "ipad:app_store_id"?: string; "ipad:app_name"?: string; "android:url"?: string; "android:package"?: string; "android:class"?: string; "android:app_name"?: string; "windows_phone:url"?: string; "windows_phone:app_id"?: string; "windows_phone:app_name"?: string; "windows:url"?: string; "windows:app_id"?: string; "windows:app_name"?: string; "windows_universal:url"?: string; "windows_universal:app_id"?: string; "windows_universal:app_name"?: string; "web:url"?: string; "web:should_fallback"?: string; [key: string]: string | undefined; } export interface ResultHtml { date?: string; keywords?: string; author?: string; description?: string; language?: string; generator?: string; creator?: string; publisher?: string; robots?: string; viewport?: string; "application-name"?: string; "apple-mobile-web-app-title"?: string; title?: string; canonical?: string; amphtml?: string; pingback?: string; [key: string]: string | undefined; } export interface Alternative { type: string; href: string; title?: string; media?: string; hreflang?: string; } export interface Icon { type?: string; sizes?: string; href: string; } export interface Link { href: string; text: string; download: boolean; hreflang?: string; rel?: string; type?: string; target?: string; } export interface Image { src: string; alt?: string; longdesc?: string; sizes?: string[]; srcset?: string[]; } export interface Result { alternate: Array<Alternative>; icons: Array<Icon>; links: Array<Link>; images: Array<Image>; jsonld?: RdfaNode[]; rdfa?: RdfaNode[]; microdata?: RdfaNode[]; applinks?: ResultApplinks; twitter?: ResultTwitter; dublincore?: ResultDublinCore; sailthru?: ResultSailthru; html?: ResultHtml; } export interface Options { url: string; } export interface RdfaNode { "@id"?: string; "@context"?: { [key: string]: string; }; [key: string]: unknown; } export declare class Handler { protected callback: (err: Error | null, result: Result) => void; protected options: Options; protected result: Result; protected contexts: HandlerContext[]; protected langs: string[]; private _rdfaNodes; private _rdfaVocabs; private _rdfaRels; private _microdataRefs; private _microdataScopes; private _microdataNodes; constructor(callback: (err: Error | null, result: Result) => void, options: Options); onend(): void; onerror(error: Error): void; onopentag(tagName: string, attributes: { [attribute: string]: string; }): void; ontext(value: string): void; onclosetag(): void; /** * Add a microdata property, with support for `id` references (used via `itemref`). */ private _addMicrodataProperty; /** * Set a microdata property. */ private _setMicrodataProperty; /** * Add an RDFa property to the node. */ private _addRdfaProperty; /** * Correct known prefixes in the context. */ private _normalizeRdfaProperty; /** * Create an RDFa resource. */ private _createRdfaResource; } /** * Copy properties from `a` to `b`, when "defined". */ export declare function copy<T extends { [key: string]: unknown; }>(a: T, b: T): void;