Skip to content

Commit 5d9874d

Browse files
authored
Merge pull request #243 from jshemas/aug-9
august clean up
2 parents 80b1800 + 4eda428 commit 5d9874d

File tree

19 files changed

+104
-68
lines changed

19 files changed

+104
-68
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## 6.8.0
4+
5+
- Updating how `onlyGetOpenGraphInfo` works. By default it is `false` but now it accepts an array of properties for which no fallback should be used.
6+
- Updating how you get types `import { SuccessResult } from 'open-graph-scraper/types';`. See readme for details.
7+
- Updating dependencies
8+
39
## 6.7.2
410

511
- Adding `types` to the npm export. You can now use `import { SuccessResult } from 'open-graph-scraper/types/lib/types';`
@@ -100,7 +106,7 @@
100106
- Modified the `url` property in `OpenGraphScraperOptions` to be an optional property since you don't need this when using just `html`
101107
- `Type` can optional in `ImageObject` since type is not set it it's invalid
102108
- Take all of the `customMetaTags` out of base of `ogObject` and store them into `ogObject.customMetaTags`
103-
- The interal meta properties can be string arrays
109+
- The internal meta properties can be string arrays
104110
- Updating Dependencies
105111

106112
## 6.1.0
@@ -119,7 +125,7 @@
119125
- Replace `GOT` with [fetch](https://nodejs.org/docs/latest-v18.x/api/globals.html#fetch)!
120126
- Only supporting `node18` or higher going forward
121127
- Updated how options work. `Fetch` and `OGS` options no longer being mixed together, users can now set [fetch options](https://developer.mozilla.org/en-US/docs/Web/API/fetch#options) using `options.fetchOptions`
122-
- Remove any ogImages/ogVideos/twitterImages/twitterPlayers/musicSongs resultes that have no url
128+
- Remove any ogImages/ogVideos/twitterImages/twitterPlayers/musicSongs results that have no url
123129
- The `downloadLimit` option has been removed in favor of just using timeouts.
124130
- Limit ogImages/ogVideos/twitterImages/twitterPlayers/musicSongs to 10 items
125131
- Adding html to the `SuccessResult` of `OGS`

README.md

Lines changed: 26 additions & 1 deletion
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
@@ -123,7 +148,7 @@ The request header is set to [undici](https://github.com/nodejs/undici) by defau
123148

124149
```javascript
125150
const ogs = require("open-graph-scraper");
126-
const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36';
151+
const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36';
127152
ogs({ url: 'https://www.wikipedia.org/', fetchOptions: { headers: { 'user-agent': userAgent } } })
128153
.then((data) => {
129154
const { error, html, result, response } = data;

lib/extract.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import fields from './fields';
55
import mediaSetup from './media';
66
import { unescapeScriptText } from './utils';
77

8-
import type { OgObjectInteral, OpenGraphScraperOptions } from './types';
8+
import type { OgObjectInternal, OpenGraphScraperOptions } from './types';
99

1010
/**
1111
* extract all of the meta tags needed for ogs
@@ -16,7 +16,7 @@ import type { OgObjectInteral, OpenGraphScraperOptions } from './types';
1616
*
1717
*/
1818
export default function extractMetaTags(body: string, options: OpenGraphScraperOptions) {
19-
let ogObject: OgObjectInteral = { success: true };
19+
let ogObject: OgObjectInternal = { success: true };
2020
const $ = load(body);
2121
const metaFields = fields;
2222

lib/fallback.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
isUrlValid,
99
} from './utils';
1010
import type {
11-
OpenGraphScraperOptions, ImageObject, OgObjectInteral, OnlyGetOpenGraphInfoItem,
11+
OpenGraphScraperOptions, ImageObject, OgObjectInternal, OnlyGetOpenGraphInfoItem,
1212
} from './types';
1313

1414
const doesElementExist = (selector:string, attribute:string, $: CheerioAPI) => (
@@ -24,7 +24,7 @@ const doesElementExist = (selector:string, attribute:string, $: CheerioAPI) => (
2424
* @return {object} object with ogs results with updated fallback values
2525
*
2626
*/
27-
export function fallback(ogObject: OgObjectInteral, options: OpenGraphScraperOptions, $: CheerioAPI, body: string) {
27+
export function fallback(ogObject: OgObjectInternal, options: OpenGraphScraperOptions, $: CheerioAPI, body: string) {
2828
const shouldFallback = (key: OnlyGetOpenGraphInfoItem): boolean => {
2929
if (!options.onlyGetOpenGraphInfo) {
3030
return true;

lib/fields.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { OgObjectInteral } from './types';
1+
import type { OgObjectInternal } from './types';
22

33
type Fields = {
44
multiple: boolean;
55
property: string;
6-
fieldName: keyof OgObjectInteral;
6+
fieldName: keyof OgObjectInternal;
77
}[];
88

99
/**

lib/media.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { removeNestedUndefinedValues } from './utils';
33
import type {
44
ImageObject,
55
MusicSongObject,
6-
OgObjectInteral,
6+
OgObjectInternal,
77
TwitterImageObject,
88
TwitterPlayerObject,
99
VideoObject,
@@ -84,7 +84,7 @@ const zip = (array: any, ...args: any) => {
8484
* @return {object} object with ogs results with updated media values
8585
*
8686
*/
87-
export function mediaSetup(ogObject: OgObjectInteral) {
87+
export function mediaSetup(ogObject: OgObjectInternal) {
8888
// sets ogImage property/width/height/type to empty array if one these exists
8989
if (
9090
ogObject.ogImageSecureURL

lib/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export interface MusicSongObject {
115115
url: string;
116116
}
117117

118-
export interface OgObjectInteral {
118+
export interface OgObjectInternal {
119119
alAndroidAppName?: string;
120120
alAndroidClass?: string;
121121
alAndroidPackage?: string;
@@ -319,7 +319,7 @@ export interface OgObjectInteral {
319319

320320
// Omit values from mediaMapperProperties
321321
export type OgObject = Omit<
322-
OgObjectInteral,
322+
OgObjectInternal,
323323
'musicSongDisc' |
324324
'musicSongProperty' |
325325
'musicSongTrack' |

lib/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import isUrl from './isUrl';
22
import type {
33
CustomMetaTags,
4-
OgObjectInteral,
4+
OgObjectInternal,
55
OpenGraphScraperOptions,
66
ValidatorSettings,
77
} from './types';
@@ -93,13 +93,13 @@ export function isThisANonHTMLUrl(url: string): boolean {
9393
}
9494

9595
/**
96-
* Find and delete nested undefs
96+
* Find and delete nested undefineds
9797
*
9898
* @param {object} object - object to be cleaned
99-
* @return {object} object without nested undefs
99+
* @return {object} object without nested undefineds
100100
*
101101
*/
102-
export function removeNestedUndefinedValues(object: Record<string, any>): OgObjectInteral {
102+
export function removeNestedUndefinedValues(object: Record<string, any>): OgObjectInternal {
103103
Object.entries(object).forEach(([key, value]) => {
104104
if (value && typeof value === 'object') removeNestedUndefinedValues(value);
105105
else if (value === undefined) delete object[key];

package-lock.json

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "open-graph-scraper",
33
"description": "Node.js scraper module for Open Graph and Twitter Card info",
4-
"version": "6.7.2",
4+
"version": "6.8.0",
55
"license": "MIT",
66
"main": "./dist/cjs/index.js",
77
"types": "./types/index.d.ts",
@@ -11,7 +11,7 @@
1111
"import": "./dist/esm/index.js",
1212
"require": "./dist/cjs/index.js"
1313
},
14-
"./types/lib/types": "./types/lib/types.d.ts"
14+
"./types": "./types/lib/types.d.ts"
1515
},
1616
"scripts": {
1717
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir dist/cjs/",
@@ -39,7 +39,7 @@
3939
"chardet": "^2.0.0",
4040
"cheerio": "^1.0.0-rc.12",
4141
"iconv-lite": "^0.6.3",
42-
"undici": "^6.19.5"
42+
"undici": "^6.19.7"
4343
},
4444
"files": [
4545
"/dist",
@@ -48,9 +48,9 @@
4848
"CHANGELOG.md"
4949
],
5050
"devDependencies": {
51-
"@snyk/protect": "^1.1292.2",
51+
"@snyk/protect": "^1.1292.4",
5252
"@types/mocha": "^10.0.7",
53-
"@types/node": "^18.19.42",
53+
"@types/node": "^18.19.44",
5454
"@typescript-eslint/eslint-plugin": "^7.18.0",
5555
"@typescript-eslint/parser": "^7.18.0",
5656
"chai": "^4.5.0",
@@ -59,8 +59,8 @@
5959
"eslint-config-airbnb-typescript": "^18.0.0",
6060
"eslint-plugin-import": "^2.29.1",
6161
"eslint-plugin-mocha": "^10.5.0",
62-
"eslint-plugin-promise": "^7.0.0",
63-
"mocha": "^10.6.0",
62+
"eslint-plugin-promise": "^7.1.0",
63+
"mocha": "^10.7.3",
6464
"nyc": "^17.0.0",
6565
"sinon": "^18.0.0",
6666
"ts-mocha": "^10.0.0",

0 commit comments

Comments
 (0)