Skip to content

Commit 8adc3f9

Browse files
committed
replaced url package with URL constructor
1 parent 2bf5bbf commit 8adc3f9

File tree

3 files changed

+6
-27
lines changed

3 files changed

+6
-27
lines changed

index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import cheerio from "cheerio";
2-
import urlObj from "url";
32
import { CONSTANTS } from "./constants";
43

54
interface ILinkPreviewOptions {
@@ -93,7 +92,7 @@ function getImages(
9392
if (node.type === `tag`) {
9493
src = node.attribs.content;
9594
if (src) {
96-
src = urlObj.resolve(rootUrl, src);
95+
src = new URL(src, rootUrl).toString();
9796
images.push(src);
9897
}
9998
}
@@ -103,7 +102,7 @@ function getImages(
103102
if (images.length <= 0 && !imagesPropertyType) {
104103
src = doc(`link[rel=image_src]`).attr(`href`);
105104
if (src) {
106-
src = urlObj.resolve(rootUrl, src);
105+
src = new URL(src, rootUrl).toString();
107106
images = [src];
108107
} else {
109108
nodes = doc(`img`);
@@ -117,7 +116,7 @@ function getImages(
117116
dic[src] = true;
118117
// width = node.attribs.width;
119118
// height = node.attribs.height;
120-
images.push(urlObj.resolve(rootUrl, src));
119+
images.push(new URL(src, rootUrl).toString());
121120
}
122121
});
123122
}
@@ -192,7 +191,7 @@ function getVideos(doc: cheerio.Root) {
192191

193192
// returns default favicon (//hostname/favicon.ico) for a url
194193
function getDefaultFavicon(rootUrl: string) {
195-
return urlObj.resolve(rootUrl, `/favicon.ico`);
194+
return new URL(`/favicon.ico`, rootUrl).toString();
196195
}
197196

198197
// returns an array of URLs to favicon images
@@ -216,7 +215,7 @@ function getFavicons(doc: cheerio.Root, rootUrl: string) {
216215
nodes.each((_: number, node: cheerio.Element) => {
217216
if (node.type === `tag`) src = node.attribs.href;
218217
if (src) {
219-
src = urlObj.resolve(rootUrl, src);
218+
src = new URL(src, rootUrl).toString();
220219
images.push(src);
221220
}
222221
});
@@ -486,4 +485,3 @@ export async function getPreviewFromContent(
486485

487486
return parseResponse(response, options);
488487
}
489-

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
"license": "MIT",
3131
"repository": "https://github.com/ospfranco/link-preview-js",
3232
"dependencies": {
33-
"cheerio": "1.0.0-rc.11",
34-
"url": "0.11.0"
33+
"cheerio": "1.0.0-rc.11"
3534
},
3635
"files": [
3736
"build"

yarn.lock

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,16 +2124,6 @@ prompts@^2.0.1:
21242124
kleur "^3.0.3"
21252125
sisteransi "^1.0.5"
21262126

2127-
punycode@1.3.2:
2128-
version "1.3.2"
2129-
resolved "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz"
2130-
integrity sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0=
2131-
2132-
querystring@0.2.0:
2133-
version "0.2.0"
2134-
resolved "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz"
2135-
integrity sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=
2136-
21372127
react-is@^18.0.0:
21382128
version "18.2.0"
21392129
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
@@ -2416,14 +2406,6 @@ update-browserslist-db@^1.0.4:
24162406
escalade "^3.1.1"
24172407
picocolors "^1.0.0"
24182408

2419-
url@0.11.0:
2420-
version "0.11.0"
2421-
resolved "https://registry.npmjs.org/url/-/url-0.11.0.tgz"
2422-
integrity sha1-ODjpfPxgUh63PFJajlW/3Z4uKPE=
2423-
dependencies:
2424-
punycode "1.3.2"
2425-
querystring "0.2.0"
2426-
24272409
v8-to-istanbul@^9.0.1:
24282410
version "9.0.1"
24292411
resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-9.0.1.tgz#b6f994b0b5d4ef255e17a0d17dc444a9f5132fa4"

0 commit comments

Comments
 (0)