Skip to content

Commit ce5f735

Browse files
committed
updating the readme on how to get types
1 parent ba6741b commit ce5f735

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,31 @@ Check the return for a ```success``` flag. If success is set to true, then the u
6767

6868
Note: `open-graph-scraper` uses the [Fetch API](https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#fetch) for requests and most of [Fetch's options](https://developer.mozilla.org/en-US/docs/Web/API/fetch#options) should work as `open-graph-scraper`'s `fetchOptions` options.
6969

70+
## Types And Import Example
71+
72+
```javascript
73+
// example of how to get types
74+
import type { SuccessResult } from 'open-graph-scraper/types';
75+
const example: SuccessResult = {
76+
result: { ogTitle: 'this is a title' },
77+
error: false,
78+
response: {},
79+
html: '<html></html>'
80+
}
81+
82+
// import example
83+
import ogs from 'open-graph-scraper';
84+
const options = { url: 'http://ogp.me/' };
85+
ogs(options)
86+
.then((data) => {
87+
const { error, html, result, response } = data;
88+
console.log('error:', error); // This returns true or false. True if there was an error. The error itself is inside the result object.
89+
console.log('html:', html); // This contains the HTML of page
90+
console.log('result:', result); // This contains all of the Open Graph results
91+
console.log('response:', response); // This contains response from the Fetch API
92+
});
93+
```
94+
7095
## Custom Meta Tag Example
7196

7297
```javascript

0 commit comments

Comments
 (0)