@jcottam/html-metadata
is a JavaScript library for easy extraction of HTML meta and Open Graph tags from HTML content or URLs. It is useful for social media sharing and SEO.
Compatibility: Works with both Node.js (CommonJS) and modern browsers (ES6).
- Extracts HTML meta and Open Graph from HTML content or URLs.
- Parses metadata such as
og:title
,og:description
, andfavicon
. - Developed in TypeScript for better type safety.
- Simple integration and customizable error handling.
- Fast performance.
npm install @jcottam/html-metadata
ES6 and CommonJS syntax supported
const { extractFromUrl } = require("@jcottam/html-metadata")
extractFromUrl("https://www.retool.com").then((data) => console.log(data))
const { extractFromHTML } = require("@jcottam/html-metadata")
const data = extractFromHTML(
"<html><head><meta property='og:title' content='Hello World' /></head></html>"
)
extractFromHTML(html: string, options?: Options): ExtractedData
extractFromUrl(url: string, options?: Options): Promise<ExtractedData | null>
type Options = {
timeout?: number // fetch timeout in ms
metaTags?: string[] // specific meta tags to extract
}
{
"og:type": "website",
"og:url": "https://retool.com/",
"og:title": "Retool | The fastest way to build internal software.",
"og:description": "Retool is the fastest way to build internal software. Use Retool's building blocks to build apps and workflow automations that connect to your databases and APIs, instantly.",
"og:image": "https://d3399nw8s4ngfo.cloudfront.net/og-image-default.webp",
"favicon": "/favicon.png"
}
To bypass CORS in browsers, run extractFromUrl
on a server or use a proxy like AllOrigins.
The module utilizes the following third-party tools for testing and functionality:
- Vitest: Next-generation testing framework.
- Cheerio: A fast, flexible, and lean implementation of core jQuery designed for server-side Node.js.
- Shields.io: Concise, consistent, and legible badges for projects.
We welcome contributions to the @jcottam/html-metadata module! If you'd like to contribute, please follow these guidelines:
- Fork the repository and create a branch.
- Make your changes and ensure that the code style and tests pass.
- Submit a pull request with a detailed description of your changes.