Skip to content

Commit

Permalink
perf: memoize isMediaUrl (#688)
Browse files Browse the repository at this point in the history
* perf: memoize isMediaUrl

* build: tweaks
  • Loading branch information
Kikobeats authored Jan 17, 2024
1 parent 095c93a commit 7f577b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@
"build": "gulp build",
"clean": "pnpm --recursive --parallel exec -- rm -rf node_modules",
"contributors": "npm run contributors:add && npm run contributors:commit",
"contributors:add": "pnpm --recursive --parallel exec -- finepack --sort-ignore-object-at ava",
"contributors:commit": "(git-authors-cli && finepack --sort-ignore-object-at ava && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
"contributors:add": "pnpm --recursive --parallel exec -- finepack",
"contributors:commit": "(git-authors-cli && finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
"coverage": "c8 report --reporter=text-lcov > coverage/lcov.info",
"dev": "concurrently \"gulp\" \"npm run dev:server\"",
"dev:server": "browser-sync start --server --files \"index.html, README.md, static/**/*.(css|js)\"",
Expand Down
6 changes: 4 additions & 2 deletions packages/metascraper-helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@ const isMediaTypeUrl = (url, type, { ext, ...opts } = {}) =>
const isMediaTypeExtension = (url, type, ext) =>
eq(type, get(EXTENSIONS, ext || extension(url)))

const isMediaUrl = (url, opts) =>
isImageUrl(url, opts) || isVideoUrl(url, opts) || isAudioUrl(url, opts)
const isMediaUrl = memoizeOne(
(url, opts) =>
isImageUrl(url, opts) || isVideoUrl(url, opts) || isAudioUrl(url, opts)
)

const isVideoUrl = (url, opts) => isMediaTypeUrl(url, VIDEO, opts)

Expand Down

0 comments on commit 7f577b9

Please sign in to comment.