favicon-thief
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

favicon-thief

Find the best favicon for a given URL.

Powers https://websktop.com.

Version License Node version Vulnerabilities Build Test Prettier

Installation

npm install favicon-thief --save

API

getFavicons

Uses findFavicons to get all favicons that represent given URL. Uses node-fetch & puppeteer to crawl webpages.

  • Results are sorted - best first.
  • Favors vector images, square images, and large images (in that order).

It's a wrapper for findFavicons that provides fetch implementations.

import { getFavicons } from 'favicon-thief';

const favicons = await getFavicons('https://websktop.com');

console.log(JSON.stringify(favicons, null, 2));
// [
//   {
//     "sizes": [
//       {
//         "width": 144,
//         "height": 144
//       }
//     ],
//     "source": "html",
//     "url": "https://www.youtube.com/s/desktop/25bf5aae/img/favicon_144x144.png"
//   },
//   {
//     "sizes": [
//       {
//         "width": 96,
//         "height": 96
//       }
//     ],
//     "source": "html",
//     "url": "https://www.youtube.com/s/desktop/25bf5aae/img/favicon_96x96.png"
//   },
//   {
//     "sizes": [
//       {
//         "width": 48,
//         "height": 48
//       }
//     ],
//     "source": "html",
//     "url": "https://www.youtube.com/s/desktop/25bf5aae/img/favicon_48x48.png"
//   },
//   {
//     "sizes": [
//       {
//         "width": 32,
//         "height": 32
//       }
//     ],
//     "source": "html",
//     "url": "https://www.youtube.com/s/desktop/25bf5aae/img/favicon_32x32.png"
//   },
//   {
//     "sizes": [],
//     "source": "html",
//     "url": "https://www.youtube.com/s/desktop/25bf5aae/img/favicon.ico"
//   },
//   {
//     "sizes": [],
//     "source": "guess",
//     "url": "https://www.youtube.com/favicon.ico"
//   },
//   {
//     "sizes": [],
//     "source": "guess",
//     "url": "https://youtube.com/favicon.ico"
//   }
// ]

findFavicons

Finds all favicons that represent given URL.

  • Pass your own fetching function.
  • Results are sorted - best first.
  • Favors vector images, square images, and large images (in that order).
  • It never throws.
import { findFavicons } from 'favicon-thief';

const myFetch = async (url: string): string => {
  // bring your own fetching implementation - turn `url` into html here
  return {
    data: '<html><head><link rel="icon" href="icon.png" sizes="160x160"></head></html>',
    url, // return different url if there was a redirect
  };
};

const favicons = await findFavicons('http://example.com', myFetch);

console.log(JSON.stringify(favicons, null, 2));
// [
//   {
//     "sizes": [
//       {
//         "width": 160,
//         "height": 160
//       }
//     ],
//     "source": "html",
//     "url": "http://example.com/icon.png"
//   },
//   {
//     "sizes": [],
//     "source": "guess",
//     "url": "http://example.com/favicon.ico"
//   }
// ]

Package Sidebar

Install

npm i favicon-thief

Weekly Downloads

3

Version

2.1.0

License

MIT

Unpacked Size

848 kB

Total Files

9

Last publish

Collaborators

  • kamilmielnik
  • yuriyyakym