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

@edapess/link-previewer

v2.0.0

Published

Simple node js package for getting meta data from link

Downloads

1

Readme

Link Previewer

@edapess/link-previewer is a simple tool for extracting link preview data from web pages, including titles, descriptions, images, and more. This package is especially useful for applications that need to display rich link previews, such as social media platforms or messaging apps.

Features

  • Extracts title, description, site name, images, favicons, and more from web pages.
  • Supports fetching data from TikTok links specifically.
  • Customizable request headers and timeouts.
  • Built with TypeScript for type safety.

Installation

Install the package using npm or yarn:

npm install @edapess/link-previewer

or

yarn add @edapess/link-previewer

Usage

To use the link-previewer, import the getLinkPreviewData function and call it with the URL you want to preview. You can also pass optional headers and timeout settings.

Example

import { getLinkPreviewData } from '@edapess/link-previewer';

const fetchPreviewData = async (url) => {
  try {
    const data = await getLinkPreviewData(url, {
      headers: {
        'user-agent': 'your-user-agent',
        'Accept-Language': 'en-US,en;q=0.9',
      },
      timeout: 5000,
    });

    console.log(data);
  } catch (error) {
    console.error('Error fetching link preview data:', error);
  }
};

fetchPreviewData('https://example.com');

Response Format

The getLinkPreviewData function returns a promise that resolves to an object containing the following properties:

  • url: The URL of the page.
  • title: The title of the page.
  • siteName: The name of the site.
  • description: The description of the page.
  • mediaType: The type of media (e.g., "website", "video").
  • contentType: The content type of the response.
  • images: An array of image URLs.
  • favicons: An array of favicon URLs.
  • charset: The character set of the page.
  • keywords: An array of keywords from the page.

Example Response

{
  "url": "https://example.com",
  "title": "Example Domain",
  "siteName": "Example",
  "description": "This domain is for use in illustrative examples in documents.",
  "mediaType": "website",
  "contentType": "text/html; charset=UTF-8",
  "images": ["https://example.com/image1.jpg", "https://example.com/image2.jpg"],
  "favicons": ["https://example.com/favicon.ico"],
  "charset": "UTF-8",
  "keywords": ["example", "domain", "illustrative"]
}

Options

The getLinkPreviewData function accepts an options object with the following properties:

  • headers: Custom headers to use when making the request. Default headers include user-agent, Accept-Language, Access-Control-Allow-Origin, and Accept.
  • noHeaders: If set to true, no headers will be sent with the request. Defaults to false.
  • timeout: The request timeout in milliseconds. Defaults to 3000.

Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.