Skip to content

Commit

Permalink
feat: drop uneeded polyfills
Browse files Browse the repository at this point in the history
  • Loading branch information
talentlessguy committed Jan 19, 2025
1 parent a6d7874 commit f288ed8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 56 deletions.
10 changes: 1 addition & 9 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import cheerio from "cheerio";
import { fetch } from "cross-fetch";
import AbortControllerPolyfill from "abort-controller";
import urlObj from "url";
import { CONSTANTS } from "./constants";

Expand Down Expand Up @@ -404,7 +402,7 @@ export async function getLinkPreview(
}

const timeout = options?.timeout ?? 3000; // 3 second timeout default
const controller = createAbortController();
const controller = new AbortController();
const timeoutCounter = setTimeout(() => controller.abort(), timeout);

const fetchOptions = {
Expand Down Expand Up @@ -489,9 +487,3 @@ export async function getPreviewFromContent(
return parseResponse(response, options);
}


function createAbortController(): AbortController | AbortControllerPolyfill {
return typeof AbortController == 'undefined'
? new AbortControllerPolyfill()
: new AbortController();
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
"license": "MIT",
"repository": "https://github.com/ospfranco/link-preview-js",
"dependencies": {
"abort-controller": "^3.0.0",
"cheerio": "1.0.0-rc.11",
"cross-fetch": "3.1.5",
"url": "0.11.0"
},
"files": [
Expand All @@ -47,5 +45,8 @@
"ts-jest": "^28.0.5",
"typescript": "^4.7.4"
},
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610",
"engines": {
"node": ">=18"
}
}
44 changes: 0 additions & 44 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -799,13 +799,6 @@
dependencies:
"@types/yargs-parser" "*"

abort-controller@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz"
integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==
dependencies:
event-target-shim "^5.0.0"

ansi-escapes@^4.2.1:
version "4.3.2"
resolved "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz"
Expand Down Expand Up @@ -1104,13 +1097,6 @@ convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
dependencies:
safe-buffer "~5.1.1"

cross-fetch@3.1.5:
version "3.1.5"
resolved "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz"
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
dependencies:
node-fetch "2.6.7"

cross-spawn@^7.0.3:
version "7.0.6"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f"
Expand Down Expand Up @@ -1240,11 +1226,6 @@ esprima@^4.0.0:
resolved "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz"
integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==

event-target-shim@^5.0.0:
version "5.0.1"
resolved "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz"
integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==

execa@^5.0.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd"
Expand Down Expand Up @@ -1986,13 +1967,6 @@ natural-compare@^1.4.0:
resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz"
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=

node-fetch@2.6.7:
version "2.6.7"
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
dependencies:
whatwg-url "^5.0.0"

node-int64@^0.4.0:
version "0.4.0"
resolved "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz"
Expand Down Expand Up @@ -2400,11 +2374,6 @@ to-regex-range@^5.0.1:
dependencies:
is-number "^7.0.0"

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz"
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=

ts-jest@^28.0.5:
version "28.0.5"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-28.0.5.tgz#31776f768fba6dfc8c061d488840ed0c8eeac8b9"
Expand Down Expand Up @@ -2471,19 +2440,6 @@ walker@^1.0.8:
dependencies:
makeerror "1.0.12"

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz"
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz"
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"

which@^2.0.1:
version "2.0.2"
resolved "https://registry.npmjs.org/which/-/which-2.0.2.tgz"
Expand Down

0 comments on commit f288ed8

Please sign in to comment.