Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

link-preview-js

Package Overview
Dependencies
Maintainers
0
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

link-preview-js

Javascript module to extract and fetch HTTP link information from blocks of text.

  • 3.0.12
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created

What is link-preview-js?

The link-preview-js npm package is used to generate link previews from URLs. It fetches metadata from the provided URL and returns information such as the title, description, image, and more. This is useful for creating rich link previews in applications like social media platforms, messaging apps, and content management systems.

What are link-preview-js's main functionalities?

Fetch Link Preview

This feature allows you to fetch a link preview from a given URL. The `getLinkPreview` function returns a promise that resolves with metadata such as the title, description, and images from the URL.

const { getLinkPreview } = require('link-preview-js');

getLinkPreview('https://www.example.com').then((data) => {
  console.log(data);
});

Custom Fetch Options

This feature allows you to customize the fetch options, such as setting custom headers. This can be useful for bypassing restrictions or simulating different user agents.

const { getLinkPreview } = require('link-preview-js');

getLinkPreview('https://www.example.com', {
  headers: {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
  }
}).then((data) => {
  console.log(data);
});

Handle Different Content Types

This feature allows you to handle different content types returned by the URL. The `getLinkPreview` function provides the content type in the response, enabling you to process HTML, JSON, or other types of content accordingly.

const { getLinkPreview } = require('link-preview-js');

getLinkPreview('https://www.example.com').then((data) => {
  if (data.contentType === 'text/html') {
    console.log('HTML content:', data);
  } else if (data.contentType === 'application/json') {
    console.log('JSON content:', data);
  }
});

Other packages similar to link-preview-js

Keywords

FAQs

Package last updated on 21 Oct 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc