link-preview-js
Advanced tools
Comparing version 1.6.0 to 2.0.0
{ | ||
"name": "link-preview-js", | ||
"version": "1.6.0", | ||
"version": "2.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"main": "build/index.js", | ||
"scripts": { | ||
"test": "jest" | ||
"test": "jest --detectOpenHandles --colors", | ||
"build": "tsc" | ||
}, | ||
@@ -23,6 +24,6 @@ "keywords": [ | ||
"cross-fetch": "3.0.4", | ||
"es6-promise": "4.2.8", | ||
"url": "0.11.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^24.0.25", | ||
"eslint": "^6.6.0", | ||
@@ -34,5 +35,6 @@ "eslint-config-airbnb": "18.0.1", | ||
"eslint-plugin-react": "7.16.0", | ||
"expect.js": "0.3.1", | ||
"jest": "24.9.0" | ||
"jest": "24.9.0", | ||
"ts-jest": "^24.2.0", | ||
"typescript": "^3.7.4" | ||
} | ||
} |
@@ -1,2 +0,1 @@ | ||
# link-preview-js | ||
@@ -10,59 +9,60 @@ | ||
Chrome, Firefox, Safari, etc DO NOT ALLOW YOU TO DO CROSS SITE REQUESTS therefore you cannot use this library or even manually request another domain from your web application, read more about [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS). | ||
Chrome, Firefox, Safari, etc DO NOT ALLOW YOU TO DO CROSS SITE REQUESTS therefore you cannot use this library or even manually request another domain from your web application, read more about [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS). However you can use this library on React-Native or on your back-end to fetch link-information to your app. | ||
## Known issues for React-Native | ||
Apparently the fetch especification breaks on some older samsung devices, this is not patchable on this library. | ||
# 2.X.X | ||
The api for version 2.X.X changed slightly, there is no longer a default unnamed export, only a named method export `getLinkPreview`, the library has also been completely re-written on typescript so you now have types and some minor bugs have been fixed. | ||
## Usage | ||
Install the library by | ||
`$ yarn add link-preview-js` | ||
Library exposes just one method: getPreview, you have to pass a string (doesn't matter if it is just a URL or a piece of text that contains a URL), the library will take care of parsing it and returning the info of first valid URL info it finds. | ||
Library exposes just one method `getLinkPreview`, you have to pass a string, doesn't matter if it is just a URL or a piece of text that contains a URL, the library will take care of parsing it and returning the info of first valid HTTP(S) URL info it finds. | ||
URL parsing is done via: https://gist.github.com/dperini/729294 | ||
```javascript | ||
import LinkPreview from 'link-preview-js'; | ||
```typescript | ||
import {getLinkPreview} from 'link-preview-js'; | ||
... | ||
LinkPreview.getPreview('https://www.youtube.com/watch?v=MejbOFk7H6c') | ||
.then(data => console.debug(data)); | ||
getLinkPreview('https://www.youtube.com/watch?v=MejbOFk7H6c') | ||
.then((data: ILinkPreviewResponse) => console.debug(data)); | ||
LinkPreview.getPreview('This is a text supposed to be parsed and the first link displayed https://www.youtube.com/watch?v=MejbOFk7H6c') | ||
.then(data => console.debug(data)); | ||
getLinkPreview('This is a text supposed to be parsed and the first link displayed https://www.youtube.com/watch?v=MejbOFk7H6c') | ||
.then((data: ILinkPreviewResponse) => console.debug(data)); | ||
``` | ||
## Options | ||
Additionally you can pass an options object which should add more functionality to the parsing of the link | ||
| Property Name | Result | | ||
| ------------- |:-------------:| | ||
| imagesPropertyType (**optional**) (ex: 'og') | Fetches images only with the specified property, `meta[property='${imagesPropertyType}:image']` | | ||
| language (**optional**) (ex: 'de', 'en-US') | Fetch content with specific language | | ||
| headers (**optional**) (ex: { 'user-agent': 'googlebot' }) | Add request headers to fetch call | | ||
| Property Name | Result | | ||
| -------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------: | | ||
| imagesPropertyType (**optional**) (ex: 'og') | Fetches images only with the specified property, `meta[property='${imagesPropertyType}:image']` | | ||
| headers (**optional**) (ex: { 'user-agent': 'googlebot', 'Accept-Language': 'en-US' }) | Add request headers to fetch call | | ||
```javascript | ||
LinkPreview.getPreview( | ||
'https://www.youtube.com/watch?v=MejbOFk7H6c', | ||
{ | ||
imagesPropertyType: 'og', // fetches only open-graph images | ||
language: 'fr-CA', // fetches site for French language | ||
headers: { | ||
'user-agent': 'googlebot', // fetches with googlebot crawler user agent | ||
// ...other optional request headers | ||
}, | ||
}) | ||
.then(data => console.debug(data)); | ||
getLinkPreview("https://www.youtube.com/watch?v=MejbOFk7H6c", { | ||
imagesPropertyType: "og", // fetches only open-graph images | ||
headers: { | ||
"user-agent": "googlebot" // fetches with googlebot crawler user agent | ||
"Accept-Language": "fr-CA", // fetches site for French language | ||
// ...other optional HTTP request headers | ||
} | ||
}).then(data => console.debug(data)); | ||
``` | ||
## Returns | ||
## Returns | ||
Returns a Promise that resolves with an object describing the provided link. | ||
The info object returned varies depending on the content type (MIME type) returned | ||
in the HTTP response (see below for variations of response). Rejects with an error if response can not be parsed or if there was no URL in the text provided. | ||
in the HTTP response (see below for variations of response). Rejects with an error if response can not be parsed or if there was no URL in the text provided. | ||
### Text/HTML URL | ||
``` | ||
@@ -83,2 +83,3 @@ { | ||
### Image URL | ||
``` | ||
@@ -94,2 +95,3 @@ { | ||
### Audio URL | ||
``` | ||
@@ -105,2 +107,3 @@ { | ||
### Video URL | ||
``` | ||
@@ -116,2 +119,3 @@ { | ||
### Application URL | ||
``` | ||
@@ -118,0 +122,0 @@ { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
44130
3
21
900
134
10
- Removedes6-promise@4.2.8
- Removedes6-promise@4.2.8(transitive)