All files / roosterjs-content-model-dom/lib/domUtils retrieveDocumentMetadata.ts

100% Statements 9/9
66.67% Branches 4/6
100% Functions 3/3
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 221x             1x 42x 42x   42x 39x     42x 46x     42x    
import { toArray } from './toArray';
 
/**
 * Retrieves metadata from the given document, including HTML attributes and meta tags.
 * @param doc The document from which to retrieve metadata.
 * @returns A record containing metadata key-value pairs.
 */
export function retrieveDocumentMetadata(doc: Document): Record<string, string> {
    const result: Record<string, string> = {};
    const attributes = doc.querySelector('html')?.attributes;
 
    (attributes ? toArray(attributes) : []).forEach(attr => {
        result[attr.name] = attr.value;
    });
 
    toArray(doc.querySelectorAll('meta')).forEach(meta => {
        result[meta.name] = meta.content;
    });
 
    return result;
}