mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
10 lines
532 B
TypeScript
10 lines
532 B
TypeScript
import { createCache } from './cache-apply';
|
|
import type { PublicSuffixList } from '@gorhill/publicsuffixlist';
|
|
|
|
let gorhillGetDomainCache: ReturnType<typeof createCache> | null = null;
|
|
export const createCachedGorhillGetDomain = (gorhill: PublicSuffixList) => {
|
|
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));
|
|
};
|