Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/BlackGlory/parse-favicon

🌳 Parse HTML to get icon information
https://github.com/BlackGlory/parse-favicon

library nodejs npm-package typescript

Last synced: about 1 month ago
JSON representation

🌳 Parse HTML to get icon information

Awesome Lists containing this project

README

        

# parse-favicon
Parse HTML to get icon information.

## Install
```sh
npm install --save parse-favicon
# or
yarn add parse-favicon
```

## Usage
```js
import { parseFavicon } from 'parse-favicon'

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

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

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

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

## API
### parseFavicon
```ts
type TextFetcher = (url: string) => Awaitable // string | PromiseLike
type BufferFetcher = (url: string) => Awaitable // ArrayBuffer | PromiseLike

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
```

`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`:
- ``
- ``

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
- ``
- ``
- ``
- ``
- ``
- ``
- ``
- ``
- ``
- ``
- ``
- ``
- ``
- `/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
- [favicon-detector](https://github.com/BlackGlory/favicon-detector)