
Security News
npm Introduces minimumReleaseAge and Bulk OIDC Configuration
npm rolls out a package release cooldown and scalable trusted publishing updates as ecosystem adoption of install safeguards grows.
head-metadata
Advanced tools
Status: Experimental
head-metadata is a utility for extracting structured metadata (like <meta>, <title>, and <link>) from the <head> of an HTML document.
<head>import { extractHeadMetadata } from 'head-metadata';
import { metaExtractor, titleExtractor, linkExtractor } from 'head-metadata/extractors';
const html = `
<html>
<head>
<title>Example</title>
<meta name="description" content="An example page" />
<link rel="canonical" href="https://example.com" />
</head>
</html>
`;
const metadata = extractHeadMetadata(html, {
meta: metaExtractor,
title: titleExtractor,
link: linkExtractor
});
console.log(metadata);
/*
{
title: 'Example',
meta: {
description: 'An example page'
},
link: {
canonical: 'https://example.com'
}
}
*/
You can write your own extractors to handle any <head> child element:
export const customLinkExtractor = {
type: 'collection' as const,
parent: 'link' as const,
callback: (node) => {
const rel = node.attributes.find((a) => a.local === 'rel');
const href = node.attributes.find((a) => a.local === 'href');
if (rel != null && href != null) {
return { key: rel.value, value: href.value };
}
return null;
}
} satisfies TCollectionExtractor;
FAQs
Typesafe and straightforward utility for extracting structured metadata (like `<meta>`, `<title>`, and `<link>`) from the `<head>` of an HTML document
The npm package head-metadata receives a total of 5 weekly downloads. As such, head-metadata popularity was classified as not popular.
We found that head-metadata demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
npm rolls out a package release cooldown and scalable trusted publishing updates as ecosystem adoption of install safeguards grows.

Security News
AI agents are writing more code than ever, and that's creating new supply chain risks. Feross joins the Risky Business Podcast to break down what that means for open source security.

Research
/Security News
Socket uncovered four malicious NuGet packages targeting ASP.NET apps, using a typosquatted dropper and localhost proxy to steal Identity data and backdoor apps.