grabity

Get preview data from a link. Just grab it.

Usage no npm install needed!

<script type="module">
  import grabity from 'https://cdn.skypack.dev/grabity';
</script>

README

Travis"> npm npm

grabity

Get preview data from a link. Just grab it! 🎣

Grabity looks through Open Graph and Twitter Cards markup to get Information about a link. Its functions will return as much data as they can from the markup. If no og or twitter tags are found, it will default to the content of the tag and meta description, and if either the title tag or meta description is missing, the returned property will be empty.</p> <h2><a id="getting-started" class="anchor" aria-hidden="true" href="#getting-started"></a>Getting Started:</h2> <pre><code>npm install grabity </code></pre> <h2><a id="usage" class="anchor" aria-hidden="true" href="#usage"></a>Usage:</h2> <p>It's really quite simple:</p> <pre><code class="language-javascript">let grabity = require("grabity"); (async () => { let it = await grabity.grabIt("https://github.com/e-oj/grabity"); console.log(it); })(); </code></pre> <p>Should produce:</p> <pre><code>{ title: 'e-oj/grabity', description: 'grabity - Get preview data from a link. Just grab it! 🎣', image: 'https://avatars0.githubusercontent.com/u/9700116?s=400&v=4', favicon: 'https://assets-cdn.github.com/favicon.ico' } </code></pre> <h2><a id="api" class="anchor" aria-hidden="true" href="#api"></a>API</h2> <h3><a id="grabity.grabit-url-gets-a-title-description-image-and-favicon-from-a-url" class="anchor" aria-hidden="true" href="#grabity.grabit-url-gets-a-title-description-image-and-favicon-from-a-url"></a>grabity.grabIt(url): Gets a title, description, image, and favicon from a url</h3> <blockquote> <p>url (required): url to be used</p> </blockquote> <blockquote> <p>returns: object containing title, description, image, and favicon if found</p> </blockquote> <p>Gets the <a href="http://ogp.me/">og</a> or <a href="https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/markup">twitter</a> title, description and image from a url, as well as the favicon, and returns them in an object. If <a href="http://ogp.me/">og</a> and <a href="https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/markup">twitter</a> tags exist for a property, the <a href="http://ogp.me/">og</a> tag is given preference. The <a href="https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/markup">twitter</a> tag is selected if an <a href="http://ogp.me/">og</a> tag does not exist for a property. If there is no tag (<a href="http://ogp.me/">og</a> or <a href="https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/markup">twitter</a>) for a property, that property is not included in the returned object.</p> <pre><code class="language-javascript">let grabity = require("grabity"); (async () => { let it = await grabity.grabIt("https://www.flickr.com"); console.log(it); })(); </code></pre> <p>result:</p> <pre><code>{ title: 'Flickr, a Yahoo company', description: 'Flickr is almost certainly the best online photo management and sharing application in the world. Show off your favorite photos and videos to the world, securely and privately show content to your friends and family, or blog the photos and videos you take with a cameraphone.', image: 'https://farm4.staticflickr.com/3914/15118079089_489aa62638_b.jpg', favicon: 'https://s.yimg.com/pw/favicon.ico' } </code></pre> <h3><a id="grabity.grab-url-gets-all" class="anchor" aria-hidden="true" href="#grabity.grab-url-gets-all"></a>grabity.grab(url): Gets all <a href="http://ogp.me/">og</a> + <a href="https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/markup">twitter</a> tags and their values, as well as the favicon,</h3> <blockquote> <p>url (required): url to be used</p> </blockquote> <blockquote> <p>returns: object containing all found <a href="http://ogp.me/">og</a> + <a href="https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/markup">twitter</a> tags and values, and favicon</p> </blockquote> <p>Gets all existing <a href="http://ogp.me/">og</a> and <a href="https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/markup">twitter</a> tags, as well as the favicon, from the markup and returns them in an object.</p> <pre><code class="language-javascript">let grabity = require("grabity"); (async () => { let tags = await grabity.grab("https://www.flickr.com"); console.log(tags); })(); </code></pre> <p>result:</p> <pre><code>{ 'og:site_name': 'Flickr', 'og:updated_time': '2017-11-19T21:29:36.577Z', 'og:title': 'Flickr, a Yahoo company', 'og:type': 'website', 'og:description': 'Flickr is almost certainly the best online photo management and sharing application in the world. Show off your favorite photos and videos to the world, securely and privately show content to your friends and family, or blog the photos and videos you take with a cameraphone.', 'og:image': 'https://farm4.staticflickr.com/3914/15118079089_489aa62638_b.jpg', 'twitter:card': 'summary_large_image', 'twitter:creator': '@flickr', 'twitter:title': 'Flickr, a Yahoo company', 'twitter:description': 'Flickr is almost certainly the best online photo management and sharing application in the world. Show off your favorite photos and videos to the world, securely and privately show content to your friends and family, or blog the photos and videos you take with a cameraphone.', 'twitter:image:src': 'https://farm4.staticflickr.com/3914/15118079089_489aa62638_b.jpg', favicon: 'https://s.yimg.com/pw/favicon.ico' } </code></pre> <br> <h2><a id="test" class="anchor" aria-hidden="true" href="#test"></a>Test</h2> <p>To test this module, cd to the project directory and run:</p> <pre><code>npm run-script test-server </code></pre> <p>then in a seperate terminal:</p> <pre><code>npm test </code></pre> <p><em>Note: The test server runs on port 9973 by default. You can change the port number in test_setup/config.js</em></p> </div></article> <aside><h2 class="svelte-1u3txz5">Details</h2> <dl class="details f-d1 svelte-1u3txz5"><div class="svelte-1u3txz5"><dt class="svelte-1u3txz5">Downloads (weekly)</dt> <dd class="f-mono f-h1"><div class="container svelte-a3j687"><div class="dot svelte-a3j687"></div> <div class="dot svelte-a3j687"></div> <div class="dot svelte-a3j687"></div> </div></dd> </div><div class="svelte-1u3txz5"><dt class="svelte-1u3txz5">Updated</dt> <dd><time class="" datetime="2019-01-31T19:05:05.385Z">January 31, 2019</time></dd> </div><div class="svelte-1u3txz5"><dt class="svelte-1u3txz5">Created</dt> <dd><time class="" datetime="2017-11-16T15:38:07.329Z">November 16, 2017</time></dd> </div><div class="svelte-1u3txz5"><div class="wrapper svelte-qjxoui"><dt class="header svelte-qjxoui"><span class="title svelte-qjxoui">Package score <a class="ml1 f-w400" href="https://docs.skypack.dev/package-authors/package-checks" target="_blank">learn more</a></span> <span class="f-u1"> <div class="container svelte-a3j687"><div class="dot svelte-a3j687"></div> <div class="dot svelte-a3j687"></div> <div class="dot svelte-a3j687"></div> </div></span></dt> <dd class="pt1"><ul class="checks"><li class="checks-check svelte-qjxoui"><span class="status__loading svelte-qjxoui" aria-label="loading"></span>Package Security </li><li class="checks-check svelte-qjxoui"><span class="status__warn svelte-qjxoui" aria-label="not added yet"></span> ES Module Entrypoint <a class="action svelte-qjxoui" href="https://docs.skypack.dev/package-authors/package-checks#esm" target="_blank" rel="noopener noreferrer">Info</a> </li><li class="checks-check svelte-qjxoui"><span class="status__warn svelte-qjxoui" aria-label="not added yet"></span> Export Map <a class="action svelte-qjxoui" href="https://docs.skypack.dev/package-authors/package-checks#export-map" target="_blank" rel="noopener noreferrer">Info</a> </li><li class="checks-check svelte-qjxoui"><svg class="status__check svelte-qjxoui" fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 13 9"><title>added Keywords

  • added License
  • added README
  • added Repository URL
  • TypeScript Types Info
  • License
    MIT
    Dependencies
    1
    Links
    Keywords
    Collaborators