get-gorhill-publicsuffix.ts 714 B

12345678910111213141516171819
  1. import { toASCII } from 'punycode';
  2. import { createMemoizedPromise } from './memo-promise';
  3. import { getPublicSuffixListTextPromise } from './download-publicsuffixlist';
  4. const customFetch = typeof Bun !== 'undefined'
  5. ? (url: string | URL) => Promise.resolve(Bun.file(url))
  6. : (url: string | URL) => fetch(url).then(resp => resp.blob() as Promise<Blob>);
  7. export const getGorhillPublicSuffixPromise = createMemoizedPromise(async () => {
  8. const [publicSuffixListDat, { default: gorhill }] = await Promise.all([
  9. getPublicSuffixListTextPromise(),
  10. import('@gorhill/publicsuffixlist')
  11. ]);
  12. gorhill.parse(publicSuffixListDat, toASCII);
  13. await gorhill.enableWASM({ customFetch });
  14. return gorhill;
  15. });