Skip to content

Commit

Permalink
Merge pull request #3 from hyperjumptech/story/get-using-html-parser
Browse files Browse the repository at this point in the history
Feat: Add HTTP strategy
  • Loading branch information
dennypradipta authored Jun 3, 2024
2 parents dafa104 + 7a30624 commit 2e9c01a
Show file tree
Hide file tree
Showing 5 changed files with 427 additions and 56 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,34 @@

1. Install the dependencies

```
```bash
npm install @hyperjumptech/favicon-fetcher
```

2. Use it in your code

```js
const { getFavicon } = require('@hyperjumptech/favicon-fetcher') // CommonJS
import { getFavicon } from '@hyperjumptech/favicon-fetcher' // ES6
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
console.log(result1) // returns a binary or a URL

const options = {
strategies: ['duckduckgo', 'default'], // use the DuckDuckGo API and default method
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 from either DuckDuckGo API or default method
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 strategies will be run sequentially. Currently available strategies are: `default`, `duckduckgo`, `google` | `['default', 'duckduckgo', 'google']` |
| 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: `default`, `http`, `duckduckgo`, `google` | `['default', 'http', 'duckduckgo', 'google']` |
| output | `string` | Define the output format of the fetched favicon. Can be either `url` or `buffer`. | `'url'` |

## Contributing

Expand Down
208 changes: 206 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"dependencies": {
"@types/node": "^20.2.3",
"debug": "^4.3.4",
"node-fetch": "^2.6.11"
"node-fetch": "^2.6.11",
"node-html-parser": "^6.1.13"
}
}
Loading

0 comments on commit 2e9c01a

Please sign in to comment.