UNPKG

htmlmetaparser

Version:

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

169 lines (168 loc) 4.68 kB
export declare const KNOWN_VOCABULARIES: { [prefix: string]: string; }; export interface HtmlValueMap { [tagName: string]: (baseUrl: string, attrs: any) => string | undefined; } export declare const HTML_VALUE_MAP: HtmlValueMap; export interface HandlerContext { tagName: string; text: string; flags: number; id?: string; scriptType?: 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 ResultJsonLd { [key: string]: any; } 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; [key: string]: string | undefined; } export interface Alternative { type: string; href: string; title?: string; media?: string; hreflang?: string; } export interface Result { alternate: Array<Alternative>; jsonld?: ResultJsonLd | ResultJsonLd[]; rdfa?: ResultJsonLd; microdata?: ResultJsonLd; applinks?: ResultApplinks; twitter?: ResultTwitter; dublincore?: ResultDublinCore; sailthru?: ResultSailthru; html?: ResultHtml; } export interface Options { url: string; } 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 _rdfa; private _rdfaNodes; private _rdfaVocabs; private _rdfaRels; private _microdata; private _microdataRefs; private _microdataScopes; private _microdataNodes; constructor(callback: (err: Error | null, result: Result) => void, options: Options); onend(): void; onerror(error: Error): void; onopentagname(tagName: string): void; onopentag(tagName: string, attributes: { [attribute: string]: string; }): void; ontext(value: string): void; onclosetag(): void; private _addMicrodataProperty(node, id, itemprop, value); private _setMicrodataProperty(node, id, key, value); private _addRdfaProperty(node, property, value); private _normalizeRdfaProperty(propertyList); private _createRdfaResource(id?); }