https://github.com/hyperjumptech/favicon-fetcher
A utility to fetch a website's favicon
https://github.com/hyperjumptech/favicon-fetcher
Last synced: 12 months ago
JSON representation
A utility to fetch a website's favicon
- Host: GitHub
- URL: https://github.com/hyperjumptech/favicon-fetcher
- Owner: hyperjumptech
- License: mit
- Created: 2023-05-24T06:39:05.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-05T09:20:43.000Z (almost 2 years ago)
- Last Synced: 2025-04-28T08:49:26.765Z (about 1 year ago)
- Language: TypeScript
- Size: 1010 KB
- Stars: 3
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Favicon Fetcher
`favicon-fetcher` is a utility to fetch a website's favicon by using multiple strategies. By default, it will fetch the `href` attribute of the first `` element in the target's HTML file.
## How to Use
1. Install the dependencies
```bash
npm install @hyperjumptech/favicon-fetcher
```
2. Use it in your code
```js
const { getFavicon, EStrategies } = require('@hyperjumptech/favicon-fetcher') // CommonJS
import { getFavicon, EStrategies } from '@hyperjumptech/favicon-fetcher' // ES6
const result1 = await getFavicon('https://www.google.com') // using all strategies
console.log(result1) // returns a binary or a URL
const options = {
strategies: [EStrategies.duckduckgo, EStrategies.default], // use the DuckDuckGo API and default method
output: 'url' // can be 'url' or 'buffer'
}
const result2 = await getFavicon('https://www.google.com', options) // use some strategies
console.log(result2) // returns a binary or URL from either DuckDuckGo API or default method
```
## Options
| Options | Type | Description | Default |
| ---------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- |
| strategies | `string[]` | Define the strategies that will be used to fetch the favicon. Each strategy will be run sequentially. Currently available strategies are: `http`, `duckduckgo`, `google`, and `default`. Strategies defined will be run sequentially. | `['http', 'duckduckgo', 'google', 'default']` |
| output | `string` | Define the output format of the fetched favicon. Can be either `url` or `buffer`. URL will return the favicon URL, buffer will return the image of the favicon | `'url'` |
## Contributing
`favicon-fetcher` is a Node.js application written in TypeScript.
It was developed on **node v16 (LTS)**, and **npm v8**.
To start developing, clone this repository, then install the dependencies:
```bash
git clone git@github.com:hyperjumptech/favicon-fetcher.git
npm ci
```
To keep the formatting consistent, run the following command to format the source code:
```bash
npm run format
```
Finally you can also run `npm run test` to prevent regression.
Once you have made the changes, open a Pull Request and explain the issue your change will fix or the feature your change will add.
## Discussions
If you need help, want to give feedback, or have a great idea to improve Favicon Fetcher, get involved! Let us know in the [Github discussions](https://github.com/hyperjumptech/favicon-fetcher/discussions).
Please abide by the [Contributor's Code of Conduct](CODE_OF_CONDUCTS.md)
## License
[MIT](./LICENSE.txt) License.