7.0.2 • Published 6 months ago

parse-favicon v7.0.2

Weekly downloads
94
License
MIT
Repository
github
Last release
6 months ago

parse-favicon

Parse HTML to get icon information.

Install

npm install --save parse-favicon
# or
yarn add parse-favicon

Usage

import { parseFavicon } from 'parse-favicon'

const pageURL = 'https://github.com'

parseFavicon(pageURL, fetchText, fetchBuffer)
  .subscribe(icon => console.log(icon))

function fetchText(url: string): Promise<string> {
  return fetch(url)
    .then(res => res.text())
}

function fetchBuffer(url: string): Promise<ArrayBuffer> {
  return fetch(url)
    .then(res => res.arrayBuffer())
}

API

parseFavicon

type TextFetcher = (url: string) => Awaitable<string> // string | PromiseLike<string>
type BufferFetcher = (url: string) => Awaitable<ArrayBuffer> // ArrayBuffer | PromiseLike<ArrayBuffer>

interface IIcon {
  url: string
  reference: string
  type: null | string
  size: null | 'any' | ISize | ISize[]
}

interface ISize {
  width: number
  height: number
}

function parseFavicon(
  pageURL: string
, textFetcher: TextFetcher
, bufferFetcher?: BufferFetcher
): Observable<IIcon>

parseFavicon accepts textFetcher and bufferFetcher for further fetching requests when parsing icons, bufferFetcher is optional. If you need actual icon sizes and type, should provide bufferFetcher.

References related to textFetcher:

  • <meta name="msapplication-config" content="path/to/ieconfig.xml">
  • <link rel="manifest" href="path/to/manifest.webmanifest">

References related to bufferFetcher:

  • /favicon.ico
  • /apple-touch-icon-57x57-precomposed.png
  • /apple-touch-icon-57x57.png
  • /apple-touch-icon-72x72-precomposed.png
  • /apple-touch-icon-72x72.png
  • /apple-touch-icon-114x114-precomposed.png
  • /apple-touch-icon-114x114.png
  • /apple-touch-icon-120x120-precomposed.png
  • /apple-touch-icon-120x120.png
  • /apple-touch-icon-144x144-precomposed.png
  • /apple-touch-icon-144x144.png
  • /apple-touch-icon-152x152-precomposed.png
  • /apple-touch-icon-152x152.png
  • /apple-touch-icon-180x180-precomposed.png
  • /apple-touch-icon-180x180.png
  • /apple-touch-icon-precomposed.png
  • /apple-touch-icon.png

Supported references

  • <link rel="icon" href="path/to/icon.png">
  • <link rel="shortcut icon" href="path/to/icon.ico">
  • <link rel="apple-touch-icon" href="path/to/icon.png">
  • <link rel="apple-touch-icon-precomposed" href="path/to/icon.png">
  • <link rel="manifest" href="path/to/manifest.webmanifest">
  • <link rel="fluid-icon" href="path/to/icon.png">
  • <link rel="mask-icon" href="path/to/icon.svg">
  • <meta name="msapplication-TileImage" content="path/to/icon.png">
  • <meta name="msapplication-config" content="path/to/ieconfig.xml">
  • <meta name="msapplication-square70x70logo" content="path/to/icon.png">
  • <meta name="msapplication-square150x150logo" content="path/to/icon.png">
  • <meta name="msapplication-square310x310logo" content="path/to/icon.png">
  • <meta name="msapplication-wide310x150logo" content="path/to/icon.png">
  • /favicon.ico
  • /apple-touch-icon-57x57-precomposed.png
  • /apple-touch-icon-57x57.png
  • /apple-touch-icon-72x72-precomposed.png
  • /apple-touch-icon-72x72.png
  • /apple-touch-icon-114x114-precomposed.png
  • /apple-touch-icon-114x114.png
  • /apple-touch-icon-120x120-precomposed.png
  • /apple-touch-icon-120x120.png
  • /apple-touch-icon-144x144-precomposed.png
  • /apple-touch-icon-144x144.png
  • /apple-touch-icon-152x152-precomposed.png
  • /apple-touch-icon-152x152.png
  • /apple-touch-icon-180x180-precomposed.png
  • /apple-touch-icon-180x180.png
  • /apple-touch-icon-precomposed.png
  • /apple-touch-icon.png

Related projects

7.0.2

6 months ago

7.0.1

1 year ago

7.0.0

1 year ago

6.0.2

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

5.0.4

3 years ago

5.0.3

3 years ago

4.0.16

4 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.0.15

4 years ago

4.0.14

4 years ago

4.0.13

4 years ago

4.0.12

4 years ago

4.0.11

4 years ago

4.0.9

4 years ago

4.0.8

4 years ago

4.0.10

4 years ago

4.0.7

4 years ago

4.0.6

4 years ago

4.0.5

4 years ago

4.0.4

4 years ago

4.0.3

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.0.11

4 years ago

3.0.10

4 years ago

3.0.9

4 years ago

3.0.8

4 years ago

3.0.7

4 years ago

3.0.6

4 years ago

3.0.5

5 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.0.0

7 years ago

1.2.8

8 years ago

1.2.7

8 years ago

1.2.6

8 years ago

1.2.5

8 years ago

1.2.4

8 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.6

8 years ago

1.1.5

9 years ago

1.1.4

9 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago