From a6205f38b3a5523f3002845e01018a4c3533d455 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Wed, 17 Jan 2024 09:30:02 +0100 Subject: [PATCH] perf: memoize isMediaUrl --- packages/metascraper-helpers/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/metascraper-helpers/index.js b/packages/metascraper-helpers/index.js index 7e4326401..7d20f1d2c 100644 --- a/packages/metascraper-helpers/index.js +++ b/packages/metascraper-helpers/index.js @@ -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)