get-gorhill-publicsuffix.ts 709 B

123456789101112131415161718
  1. import { toASCII } from 'punycode';
  2. import { traceAsync } from './trace-runner';
  3. import { createMemoizedPromise } from './memo-promise';
  4. import { getPublicSuffixListTextPromise } from '../download-publicsuffixlist';
  5. export const getGorhillPublicSuffixPromise = createMemoizedPromise(() => traceAsync('create gorhill public suffix instance', async () => {
  6. const customFetch = (url: string | URL) => Promise.resolve(Bun.file(url));
  7. const [publicSuffixListDat, { default: gorhill }] = await Promise.all([
  8. getPublicSuffixListTextPromise(),
  9. import('@gorhill/publicsuffixlist')
  10. ]);
  11. gorhill.parse(publicSuffixListDat, toASCII);
  12. await gorhill.enableWASM({ customFetch });
  13. return gorhill;
  14. }));