From 936581ce934cb189cb1062dc5235e8d056652e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=A0=E6=89=8B=E6=8D=A7=E9=B2=9C=E8=8A=B1?= <157215725@qq.com> Date: Sun, 10 Sep 2023 21:30:07 +0800 Subject: [PATCH] feat: supports `fetch.bypassingCache` option value is `RegExp` (closes #38) --- src/fetch.ts | 4 +++- src/options.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fetch.ts b/src/fetch.ts index 827670e..72c6fe8 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -62,7 +62,9 @@ export function contextFetch(context: Context, options: ContextFetchOptions) { // cache bypass so we dont have CORS issues with cached images // ref: https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache if (bypassingCache) { - url += (/\?/.test(url) ? '&' : '?') + new Date().getTime() + if (bypassingCache instanceof RegExp && bypassingCache.test(url)) { + url += (/\?/.test(url) ? '&' : '?') + new Date().getTime() + } } const baseFetchOptions: BaseFetchOptions = { diff --git a/src/options.ts b/src/options.ts index b11bdc6..8df9e27 100644 --- a/src/options.ts +++ b/src/options.ts @@ -88,7 +88,7 @@ export interface Options { * * default: false */ - bypassingCache?: boolean + bypassingCache?: boolean | RegExp /** * A data URL for a placeholder image that will be used when fetching