backend/src/utils/sanitizer.utils.ts

57 lines
1.3 KiB
TypeScript
Raw Normal View History

//const log = require('../utils/log.utils');
function removeNonAlphanumeric(inputString: string) {
return inputString.replace(/[^a-zA-Z0-9]/g, '');
}
function removeNonAlpha(inputString: string) {
return inputString.replace(/[^a-zA-Z]/g, '');
}
function removeNonNumeric(inputString: string) {
return inputString.replace(/[^0-9]/g, '');
}
const cleanApiEndpointTxt = removeNonAlpha;
const cleanApiEndpointNum = removeNonAlphanumeric;
function cleanNrcc(input: string) { // Remove newlines and then <p> tags from input
const cleanInput = input.replace(/[\n\r]/g, '').replace(/<\/?p[^>]*>/g, '');
return cleanInput;
}
export function removeNewlineAndPTag(input: string): string {
const regex = /[\n\r]|<\/?p[^>]*>/g;
return input.replace(regex, function(match) {
if (match === "\n" || match === "\r") {
return "";
} else {
return "";
}
});
}
async function getDomainFromEmail(mail: string) { // Needs testing
let split = mail.split('@');
return split[1];
}
module.exports = {
cleanApiEndpointTxt,
cleanApiEndpointNum,
removeNonAlpha,
removeNonAlphanumeric,
removeNonNumeric,
cleanNrcc,
getDomainFromEmail,
};
export {
cleanApiEndpointTxt,
cleanApiEndpointNum,
removeNonAlpha,
removeNonAlphanumeric,
removeNonNumeric,
cleanNrcc,
getDomainFromEmail,
}