cached-tld-parse.ts 549 B

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