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

link-preview-extractor

v1.0.2

Published

link-preview-extractor is a lightweight package that extracts metadata (title, description, images) from URLs, supporting Open Graph and Twitter Cards for generating rich link previews.

Downloads

158

Readme

Here’s the modified README file based on your request:


link-preview-extractor

link-preview-extractor is a lightweight Node.js package that extracts metadata from URLs, including title, description, images, and Open Graph/Twitter Card tags. It's ideal for generating rich previews for links, commonly used in social media, chat apps, and content-sharing platforms.

Features

  • Extracts metadata including title, description, and images from URLs.
  • Supports Open Graph (OG) and Twitter Card metadata.
  • Optionally returns images as base64 strings.
  • Simple to use with a clean API.
  • Option to return additional metadata details if needed.

Installation

Install the package using npm:

npm install link-preview-extractor

Usage

Basic Usage

const extractLinkPreview = require('link-preview-extractor');

const url = 'https://example.com';

extractLinkPreview(url)
  .then((metadata) => {
    console.log(metadata);
    // Output: { url, domain, title, description, image }
  })
  .catch((err) => console.error(err));

Example Output

{
  "url": "https://example.com",
  "domain": "example.com",
  "title": "Example Site",
  "description": "This is an example description.",
  "image": "https://example.com/image.jpg"
}

Advanced Usage

1. imageAsBase64 (Set to true)

You can request the image as a base64 string by setting the imageAsBase64 parameter to true. This is useful if you want to embed images directly into your app without making additional requests.

extractLinkPreview(url, true)
  .then((metadata) => {
    console.log(metadata);
    // Output includes image as a base64 string
  })
  .catch((err) => console.error(err));

Example Output (with imageAsBase64: true):

{
  "url": "https://example.com",
  "domain": "example.com",
  "title": "Example Site",
  "description": "This is an example description.",
  "image": "https://example.com/image.jpg",
  "imgBase64String": "<BASE64 IMAGE STRING>"
}

2. extraDetails (Set to true)

When you set the extraDetails parameter to true, additional metadata including metaTags, ogTags, and twitterTags is returned in the response.

extractLinkPreview(url, false, true)
  .then((metadata) => {
    console.log(metadata);
    // Output includes extra metadata details like metaTags, ogTags, and twitterTags
  })
  .catch((err) => console.error(err));

Example Output (with extraDetails: true):

{
  "url": "https://example.com",
  "domain": "example.com",
  "title": "Example Site",
  "description": "This is an example description.",
  "image": "https://example.com/image.jpg",
  "imgBase64String": "",
  "metaTags": {
    "title": "Example Meta Title",
    "description": "This is an example meta description.",
    "url": "https://example.com"
  },
  "ogTags": {
    "title": "Example OG Title",
    "description": "This is an example OG description.",
    "site_name": "Example Site",
    "url": "https://example.com",
    "image": "https://example.com/og-image.jpg"
  },
  "twitterTags": {
    "title": "Example Twitter Title",
    "description": "This is an example Twitter description.",
    "card": "summary_large_image",
    "image": "https://example.com/twitter-image.jpg"
  }
}

License

This project is licensed under the MIT License.