build-reject-domainset-worker.js 1.6 KB

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