Surge_by_SukkaW/Build/lib/cached-tld-parse.ts
2024-01-15 16:24:41 +08:00

12 lines
549 B
TypeScript

import { createCache } from './cache-apply';
import type { PublicSuffixList } from '@gorhill/publicsuffixlist';
let gothillGetDomainCache: 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));
};
};