Minor changes here and there

This commit is contained in:
SukkaW
2024-02-06 15:49:51 +08:00
parent b7cae1061c
commit 7b2334ee3b
11 changed files with 37 additions and 82 deletions

View File

@@ -1,11 +1,9 @@
import { createCache } from './cache-apply';
import type { PublicSuffixList } from '@gorhill/publicsuffixlist';
let gothillGetDomainCache: ReturnType<typeof createCache> | null = null;
let gorhillGetDomainCache: ReturnType<typeof createCache> | null = null;
export const createCachedGorhillGetDomain = (gorhill: PublicSuffixList) => {
gothillGetDomainCache ??= createCache('cached-gorhill-get-domain', true);
return (domain: string) => {
// we do know gothillGetDomainCache exists here
return gothillGetDomainCache!.sync(domain, () => gorhill.getDomain(domain[0] === '.' ? domain.slice(1) : domain));
};
gorhillGetDomainCache ??= createCache('cached-gorhill-get-domain', true);
return (domain: string) => gorhillGetDomainCache! // we do know gothillGetDomainCache exists here
.sync(domain, () => gorhill.getDomain(domain[0] === '.' ? domain.slice(1) : domain));
};