-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (42 loc) · 1.26 KB
/
index.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// filename index.js
// package name postoffice
const GENERIC_DOMAINS = "('samplemail.com','samplemail.co.uk','examplemailbox.com'";
function getDomain(email, GENERIC_DOMAINS) {
let cleanEmail = `trim(${email})`
const domain = `substr(${cleanEmail}, strpos(${cleanEmail}, '@') + 1)`;
return `case
when ${domain} in ${common.GENERIC_DOMAINS} then ${cleanEmail}
when ${domain} = "othermailbox.com" then "other.com"
when ${domain} = "mailbox.com" then "mailbox.global"
when ${domain} = "support.postman.com" then "postman.com"
else ${domain}
end`;
}
// Utility functions for data cleansing
// Function to trim whitespace from a string
function trimWhitespace(value) {
if (typeof value === 'string') {
return `trim(${value})`;
}
return value;
};
// Function to convert a string to lowercase
function toLowerCase(value) {
if (typeof value === 'string') {
return `lower(${value})`;
}
return value;
};
// Function to convert a string to uppercase
const toUpperCase = (value) => {
if (typeof value === 'string') {
return `upper(${value})`;
}
return value;
};
module.exports = {
getDomain,
trimWhitespace,
toLowerCase,
toUpperCase
}