# peek-link

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

Latest version **1.0.11** (published 2020-06-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install peek-link
pnpm add peek-link
yarn add peek-link
bun add peek-link
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.11 |
| Published | 2020-06-09 |
| First published | 2020-05-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | jesse.stateofmotion |
| Keywords | Link Preview, link preview, facebook open graph, twitter, site image, facebook link preview, twitter link preview, link preview from html |

## Links

- npm: https://www.npmjs.com/package/peek-link
- Repository: https://github.com/stateofmotion/peek-link
- Homepage: https://github.com/stateofmotion/peek-link#readme
- Issues: https://github.com/stateofmotion/peek-link/issues
- npm.io page: https://npm.io/package/peek-link

## Dependencies (3)

- [cheerio](https://npm.io/package/cheerio.md) ^1.0.0-rc.3
- [get-urls](https://npm.io/package/get-urls.md) ^9.2.0
- [html-metadata](https://npm.io/package/html-metadata.md) ^1.7.1

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 1.0.11 (latest) — 2020-06-09
- 1.0.10 — 2020-06-08
- 1.0.9 — 2020-06-08
- 1.0.8 — 2020-05-14
- 1.0.7 — 2020-05-14
- 1.0.6 — 2020-05-14
- 1.0.5 — 2020-05-14
- 1.0.4 — 2020-05-14
- 1.0.3 — 2020-05-14
- 1.0.2 — 2020-05-14
- 1.0.1 — 2020-05-14

## 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]
  }
}
```

---
_Source: https://npm.io/package/peek-link · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
