-
Notifications
You must be signed in to change notification settings - Fork 0
/
genAllNumbersWorker,js
30 lines (27 loc) · 1.16 KB
/
genAllNumbersWorker,js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
self.addEventListener('message', function(e) {
const formData = e.data.formData;
const NumberSegment = formData.NumberSegment.split(',');
const NumberLength = formData.NumberLength;
const EnableCountryCode = formData.EnableCountryCode;
const EnablePlus = formData.EnablePlus;
const countryCodes = formData.countryCodes;
const DisruptResults = formData.DisruptResults;
NumberSegment.forEach((item) => {
const result = [];
for (let i = 0; i < Math.pow(10, NumberLength - item.length); i++) {
let number = "";
if (EnableCountryCode && EnablePlus) {
number = `+${countryCodes}${item}${String(i).padStart(NumberLength - item.length, "0")}`;
} else if (EnableCountryCode) {
number = `${countryCodes}${item}${String(i).padStart(NumberLength - item.length, "0")}`;
} else {
number = `${item}${String(i).padStart(NumberLength - item.length, "0")}`;
}
result.push(number);
}
if (DisruptResults) {
result.sort(() => Math.random() - 0.5);
}
self.postMessage({ result, item });
});
});