Skip to content
Parse HTML to get favicon information
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
src
.babelrc
.gitignore
.npmignore
LICENSE
README.md
package.json
webpack.config.js
yarn.lock

README.md

parse-favicon npm GitHub license

Parse HTML to get favicon information.

Support icon, msapplication-TileImage, apple-touch-icon-precomposed, apple-touch-icon.

Install

CLI

npm install -g parse-favicon

Module

npm install parse-favicon --save

Usage

parseFavicon(
  html: string
, options: Object = {
    baseURI: URI = ''
  , allowUseNetwork: boolean = false
  , allowParseImage: boolean = false
  , timeout: number = 1000 * 60
  }
, ignoreException: boolean = false
) : Promise

Example

import parseFavicon from 'parse-favicon'
import axios from 'axios'

axios.get('https://github.com')
.then(({ data: html }) => parseFavicon(html, { baseURI: 'https://github.com', allowUseNetwork: true, allowParseImage: true }))
.then(console.log)
.catch(console.error)

/* Output:
[ { url: 'https://assets-cdn.github.com/favicon.ico',
    path: '/favicon.ico',
    size: '16x16',
    type: 'image/x-icon',
    refer: 'icon' } ]
*/

CLI

> parse-favicon https://twitter.com
[
  [
    {
      "url": "https://abs.twimg.com/favicons/win8-tile-144.png",
      "path": "//abs.twimg.com/favicons/win8-tile-144.png",
      "size": "144x144",
      "type": "png",
      "refer": "msapplication-TileImage"
    },
    {
      "url": "https://abs.twimg.com/icons/apple-touch-icon-192x192.png",
      "path": "/icons/apple-touch-icon-192x192.png",
      "size": "192x192",
      "type": "image/png",
      "refer": "apple-touch-icon"
    },
    {
      "url": "https://abs.twimg.com/favicons/favicon.ico",
      "path": "//abs.twimg.com/favicons/favicon.ico",
      "size": "16x16",
      "type": "image/vnd.microsoft.icon",
      "refer": "icon"
    },
    {
      "url": "https://twitter.com/favicon.ico",
      "path": "/favicon.ico",
      "size": "16x16",
      "type": "image/x-icon",
      "refer": "/favicon.ico"
    }
  ]
]

Declaration

declare module "parse-favicon" {
  interface IconInfo{
    url: string
    path: string
    size: string
    type: string
    refer: string
  }

  interface ParseOptions {
    baseURI?: string
    allowUseNetwork?: boolean
    allowParseImage?: boolean
    timeout?: number
  }

  let parseFavicon: (html: string, options?: ParseOptions, ignoreException?: boolean) => Promise<IconInfo[]>

  export default parseFavicon
}

See also: parse-favicon.d.ts

Related projects

BlackGlory/ico-size: A Node module to get dimensions of ico & cur image file

Projects using parse-favicon

Chrome extension:

References

https://github.com/audreyr/favicon-cheat-sheet

You can’t perform that action at this time.