build-reject-domainset-worker.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // @ts-check
  2. const Piscina = require('piscina');
  3. // const { isCI } = require('ci-info');
  4. const fullsetDomainStartsWithADot = Piscina.workerData
  5. const totalLen = fullsetDomainStartsWithADot.length;
  6. // const log = isCI ? () => { } : console.log.bind(console);
  7. /**
  8. * @param {{ chunk: string[] }} param0
  9. */
  10. module.exports = ({ chunk }) => {
  11. const chunkLength = chunk.length;
  12. const outputToBeRemoved = new Int8Array(chunkLength);
  13. for (let i = 0; i < chunkLength; i++) {
  14. const domainFromInputChunk = chunk[i];
  15. for (let j = 0; j < totalLen; j++) {
  16. const domainStartsWithADotAndFromFullSet = fullsetDomainStartsWithADot[j];
  17. // domainFromFullSet is always startsWith "."
  18. if (domainStartsWithADotAndFromFullSet === domainFromInputChunk) continue;
  19. const domainFromInputLen = domainFromInputChunk.length;
  20. const domainFromFullSetLen = domainStartsWithADotAndFromFullSet.length;
  21. if (domainFromInputLen < domainFromFullSetLen) {
  22. if (domainFromInputLen + 1 === domainFromFullSetLen) {
  23. // !domainFromInput.starsWith('.') && `.${domainFromInput}` === domainFromFullSet
  24. if (domainFromInputChunk.charCodeAt(0) !== 46 && domainFromInputChunk.endsWith(domainStartsWithADotAndFromFullSet)) {
  25. outputToBeRemoved[i] = 1;
  26. // log(domainFromInputChunk, domainStartsWithADotAndFromFullSet)
  27. break;
  28. }
  29. } else {
  30. break;
  31. }
  32. } else if (domainFromInputChunk.endsWith(domainStartsWithADotAndFromFullSet)) {
  33. outputToBeRemoved[i] = 1;
  34. // log(domainFromInputChunk, domainStartsWithADotAndFromFullSet)
  35. break;
  36. }
  37. }
  38. }
  39. return Piscina.move(outputToBeRemoved);
  40. };