npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jcottam/html-metadata

v2.1.1

Published

This JavaScript library simplifies the extraction of HTML Meta and OpenGraph tags from HTML content or URLs.

Downloads

503

Readme

HTML Metadata

npm license developed by

@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).

Features

  • Extracts HTML meta and Open Graph from HTML content or URLs.
  • Parses metadata such as og:title, og:description, and favicon.
  • Developed in TypeScript for better type safety.
  • Simple integration and customizable error handling.
  • Fast performance.

Installation

npm install @jcottam/html-metadata

Usage

ES6 and CommonJS syntax supported

Extract tags from a URL

const { extractFromUrl } = require("@jcottam/html-metadata")

extractFromUrl("https://www.retool.com").then((data) => console.log(data))

Extract tags from an HTML string

const { extractFromHTML } = require("@jcottam/html-metadata")

const data = extractFromHTML(
  "<html><head><meta property='og:title' content='Hello World' /></head></html>"
)

Documentation

Methods

  • extractFromHTML(html: string, options?: Options): ExtractedData
  • extractFromUrl(url: string, options?: Options): Promise<ExtractedData | null>

Options

type Options = {
  timeout?: number // fetch timeout in ms
  metaTags?: string[] // specific meta tags to extract
}

Example Response

{
  "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"
}

CORS

To bypass CORS in browsers, run extractFromUrl on a server or use a proxy like AllOrigins.

Third Party Tools

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.

Contributing

We welcome contributions to the @jcottam/html-metadata module! If you'd like to contribute, please follow these guidelines:

  1. Fork the repository and create a branch.
  2. Make your changes and ensure that the code style and tests pass.
  3. Submit a pull request with a detailed description of your changes.