parse-favicon
Parse HTML to get favicon information
Last updated 6 months ago by blackglory .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install parse-favicon 
SYNC missed versions from official npm registry.

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

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (7)
Dev Dependencies (5)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |