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

peek-link

v1.0.11

Published

Package for getting open graph settings, and twitter link preview data from a url, or from the first link in a block of html content.

Downloads

5

Readme

peek-link

Get open grah settings, and twitter link preview data from a provided url. PeekLink also allows you to pass in a block of html text containing an anchor tag, and will fetch the link preview data from the url extracted from the anchor tag. PeekLink was created to help with building social media feed features such as the way link previews are displayed in most social networks.

Features

  • Fetch open graph, and twitter data such as a page image, description, and title from the meta tags in the html of a provided url
  • Extract the first url from an html anchor tag from a block of html, and fetch the link previews associated with it

Installing

npm install peek-link

Usage

// ES6
import PeekLink from 'peek-link'
const PeekLink = require('peek-link)

Get Link Previews from a URL

Example 1

Create a new instance of PeekLink passing in an object literal with a url key and value

const pl = new PeekLink({
  url: [PROVIDE_YOUR_URL_HERE]
})

// ES6
const links = await pl.fromUrl()

// Can also use then/catch
pl.fromUrl()
.then(function(links) {
  console.log(links)
}).catch(function(error) {
  console.log(error)
})

Example 2

const pl = new PeekLink()

// ES6
const links = await pl.fromUrl([YOUR_URL_HERE])

// Can also use then/catch
pl.fromUrl([YOUR_URL_HERE])
.then(function(links) {
  console.log(links)
}).catch(function(error) {
  console.log(error)
})

Get Link Previews from HTML

Example 1

const pl = new PeekLink({
  html: [HTML_AS_STRING]
})

// ES6
const links = await pl.fromHtml()

// Can also use then/catch
pl.fromHtml()
.then(function(links) {
  console.log(links)
}).catch(function(error) {
  console.log(error)
})

Example 2

const pl = new PeekLink()

// ES6
const links = await pl.fromHtml([HTML_AS_STRING])

// Can also use then/catch
pl.fromHtml([HTML_AS_STRING])
.then(function(links) {
  console.log(links)
}).catch(function(error) {
  console.log(error)
})

Link Preview Response

{
  twitter: {
    image: [TWITTER_IMAGE_URL],
    description: [TWITTER_DESCRIPTION],
    title: [TITLE]
  },
  openGraph: {
    image: [OPEN_GRAPH_IMAGE_URL],
    description: [OPEN_GRAPH_DESCRIPTION],
    title: [OPEN_GRAPH_TITLE]
  },
  general: {
    image: [GENERAL_IMAGE_URL],
    description: [GENERAL_DESCRIPTION],
    title: [GENERAL_TITLE]
  }
}