Skip to content

Commit cbd5768

Browse files
authored
Merge pull request #163 from talentlessguy/remove-polyfills
feat: drop uneeded polyfills
2 parents a6d7874 + 58e7d6e commit cbd5768

File tree

4 files changed

+6
-57
lines changed

4 files changed

+6
-57
lines changed

__tests__/index.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ describe(`#getLinkPreview()`, () => {
214214
await getLinkPreview(`http://google.com/`, { followRedirects: `error` });
215215
} catch (e: any) {
216216
expect(e.message).toEqual(
217-
`uri requested responds with a redirect, redirect mode is set to error: http://google.com/`
217+
`fetch failed`
218218
);
219219
}
220220
});

index.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import cheerio from "cheerio";
2-
import { fetch } from "cross-fetch";
3-
import AbortControllerPolyfill from "abort-controller";
42
import urlObj from "url";
53
import { CONSTANTS } from "./constants";
64

@@ -404,7 +402,7 @@ export async function getLinkPreview(
404402
}
405403

406404
const timeout = options?.timeout ?? 3000; // 3 second timeout default
407-
const controller = createAbortController();
405+
const controller = new AbortController();
408406
const timeoutCounter = setTimeout(() => controller.abort(), timeout);
409407

410408
const fetchOptions = {
@@ -489,9 +487,3 @@ export async function getPreviewFromContent(
489487
return parseResponse(response, options);
490488
}
491489

492-
493-
function createAbortController(): AbortController | AbortControllerPolyfill {
494-
return typeof AbortController == 'undefined'
495-
? new AbortControllerPolyfill()
496-
: new AbortController();
497-
}

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
"license": "MIT",
3131
"repository": "https://github.com/ospfranco/link-preview-js",
3232
"dependencies": {
33-
"abort-controller": "^3.0.0",
3433
"cheerio": "1.0.0-rc.11",
35-
"cross-fetch": "3.1.5",
3634
"url": "0.11.0"
3735
},
3836
"files": [
@@ -47,5 +45,8 @@
4745
"ts-jest": "^28.0.5",
4846
"typescript": "^4.7.4"
4947
},
50-
"packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
48+
"packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610",
49+
"engines": {
50+
"node": ">=18"
51+
}
5152
}

yarn.lock

-44
Original file line numberDiff line numberDiff line change
@@ -799,13 +799,6 @@
799799
dependencies:
800800
"@types/yargs-parser" "*"
801801

802-
abort-controller@^3.0.0:
803-
version "3.0.0"
804-
resolved "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz"
805-
integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==
806-
dependencies:
807-
event-target-shim "^5.0.0"
808-
809802
ansi-escapes@^4.2.1:
810803
version "4.3.2"
811804
resolved "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz"
@@ -1104,13 +1097,6 @@ convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
11041097
dependencies:
11051098
safe-buffer "~5.1.1"
11061099

1107-
1108-
version "3.1.5"
1109-
resolved "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz"
1110-
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
1111-
dependencies:
1112-
node-fetch "2.6.7"
1113-
11141100
cross-spawn@^7.0.3:
11151101
version "7.0.6"
11161102
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f"
@@ -1240,11 +1226,6 @@ esprima@^4.0.0:
12401226
resolved "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz"
12411227
integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==
12421228

1243-
event-target-shim@^5.0.0:
1244-
version "5.0.1"
1245-
resolved "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz"
1246-
integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==
1247-
12481229
execa@^5.0.0:
12491230
version "5.1.1"
12501231
resolved "https://registry.yarnpkg.com/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd"
@@ -1986,13 +1967,6 @@ natural-compare@^1.4.0:
19861967
resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz"
19871968
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
19881969

1989-
1990-
version "2.6.7"
1991-
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz"
1992-
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
1993-
dependencies:
1994-
whatwg-url "^5.0.0"
1995-
19961970
node-int64@^0.4.0:
19971971
version "0.4.0"
19981972
resolved "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz"
@@ -2400,11 +2374,6 @@ to-regex-range@^5.0.1:
24002374
dependencies:
24012375
is-number "^7.0.0"
24022376

2403-
tr46@~0.0.3:
2404-
version "0.0.3"
2405-
resolved "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz"
2406-
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=
2407-
24082377
ts-jest@^28.0.5:
24092378
version "28.0.5"
24102379
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-28.0.5.tgz#31776f768fba6dfc8c061d488840ed0c8eeac8b9"
@@ -2471,19 +2440,6 @@ walker@^1.0.8:
24712440
dependencies:
24722441
makeerror "1.0.12"
24732442

2474-
webidl-conversions@^3.0.0:
2475-
version "3.0.1"
2476-
resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz"
2477-
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=
2478-
2479-
whatwg-url@^5.0.0:
2480-
version "5.0.0"
2481-
resolved "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz"
2482-
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
2483-
dependencies:
2484-
tr46 "~0.0.3"
2485-
webidl-conversions "^3.0.0"
2486-
24872443
which@^2.0.1:
24882444
version "2.0.2"
24892445
resolved "https://registry.npmjs.org/which/-/which-2.0.2.tgz"

0 commit comments

Comments
 (0)