get-gorhill-publicsuffix.ts 776 B

1234567891011121314151617181920212223
  1. import fsp from 'fs/promises';
  2. import { toASCII } from 'punycode/punycode';
  3. import { createMemoizedPromise } from './memo-promise';
  4. import { getPublicSuffixListTextPromise } from './download-publicsuffixlist';
  5. import { fileURLToPath } from 'url';
  6. const customFetch = async (url: string | URL) => {
  7. const filePath = fileURLToPath(url);
  8. const file = await fsp.readFile(filePath);
  9. return new Blob([file]) as any;
  10. };
  11. export const getGorhillPublicSuffixPromise = createMemoizedPromise(async () => {
  12. const [publicSuffixListDat, { default: gorhill }] = await Promise.all([
  13. getPublicSuffixListTextPromise(),
  14. import('@gorhill/publicsuffixlist')
  15. ]);
  16. gorhill.parse(publicSuffixListDat, toASCII);
  17. await gorhill.enableWASM({ customFetch });
  18. return gorhill;
  19. });