-
Notifications
You must be signed in to change notification settings - Fork 0
/
emailVariationGen.ts
33 lines (25 loc) · 924 Bytes
/
emailVariationGen.ts
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
31
32
33
const getAlias = (email: string, variation: number): string => {
const mask = intToMask(variation, email.length - 1);
let numPeriods = 0;
for (let i = 0; i < mask.length; i++){
if (mask[i] == "0"){
email = insertPeriod(email, i + numPeriods + 1);
numPeriods++;
}
}
return email;
}
const insertPeriod = (string: string, index: number): string =>
`${string.slice(0, index)}.${string.slice(index)}`
const intToMask = (integer: number, targetLength: number): Array<string> => {
const mask = integer.toString(2).padStart(targetLength, '0');
return [... mask];
}
const generateAllAlias = (email: string): Array<string> => {
const numVariations = Math.pow(2, email.length - 1);
let variations = new Array<string>();
for (let v = 0; v < numVariations; v++) {
variations.push(getAlias(email, v));
}
return variations;
}