build-reject-domainset-worker.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const { workerData, move } = require('piscina');
  2. const len = workerData.length;
  3. module.exports = ({ chunk }) => {
  4. const chunkLength = chunk.length;
  5. const outputToBeRemoved = new Int32Array(chunkLength);
  6. for (let i = 0; i < chunkLength; i++) {
  7. const domainFromInput = chunk[i];
  8. for (let j = 0; j < len; j++) {
  9. const domainFromFullSet = workerData[j];
  10. if (domainFromFullSet === domainFromInput) continue;
  11. if (domainFromFullSet.charCodeAt(0) !== 46) continue;
  12. // domainFromFullSet is now startsWith a "."
  13. if (domainFromInput.charCodeAt(0) !== 46) {
  14. let shouldBeRemoved = true;
  15. for (let k = 0, l2 = domainFromInput.length; k < l2; k++) {
  16. if (domainFromFullSet.charCodeAt(k + 1) !== domainFromInput.charCodeAt(k)) {
  17. shouldBeRemoved = false;
  18. break;
  19. }
  20. }
  21. if (shouldBeRemoved) {
  22. outputToBeRemoved[i] = 1;
  23. break;
  24. }
  25. }
  26. // domainFromInput is now startsWith a "."
  27. if (domainFromInput.length >= domainFromFullSet.length) {
  28. if (domainFromInput.endsWith(domainFromFullSet)) {
  29. outputToBeRemoved[i] = 1;
  30. break;
  31. }
  32. }
  33. }
  34. }
  35. return move(outputToBeRemoved);
  36. };