2023-02-09 20:34:53 +00:00
|
|
|
const clean = require('string-sanitizer-fix');
|
|
|
|
const log = require('../utils/log.utils');
|
|
|
|
|
|
|
|
/*
|
|
|
|
string.sanitize("a.bc@d efg#h"); // abcdefgh
|
|
|
|
string.sanitize.keepSpace("a.bc@d efg#h"); // abcd efgh
|
|
|
|
string.sanitize.keepUnicode("a.bc@d efg#hক"); // abcd efghক
|
|
|
|
string.sanitize.addFullstop("a.bc@d efg#h"); // abcd.efgh
|
|
|
|
string.sanitize.addUnderscore("a.bc@d efg#h"); // abcd_efgh
|
|
|
|
string.sanitize.addDash("a.bc@d efg#h"); // abcd-efgh
|
|
|
|
string.sanitize.removeNumber("@abcd efgh123"); // abcdefgh
|
|
|
|
string.sanitize.keepNumber("@abcd efgh123"); // abcdefgh123
|
|
|
|
string.addFullstop("abcd efgh"); // abcd.efgh
|
|
|
|
string.addUnderscore("@abcd efgh"); // @abcd_efgh
|
|
|
|
string.addDash("@abcd efgh"); // @abcd-efgh
|
|
|
|
string.removeSpace("@abcd efgh"); // @abcdefgh
|
|
|
|
*/
|
|
|
|
|
|
|
|
function cleanApiEndpointTxt(input) {
|
|
|
|
var output = clean.sanitize.keepSpace(input)
|
|
|
|
if (output != input){
|
2023-03-30 21:08:16 +01:00
|
|
|
log.out(`sanitizerUtils.cleanApiEndpoint: WARN: Sanitizing changed string. Input = ${input}`, "warn");
|
2023-02-09 20:34:53 +00:00
|
|
|
}
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanApiEndpointNum(input) {
|
|
|
|
var output = clean.sanitize.keepNumber(input)
|
|
|
|
if (output != input){
|
2023-03-30 21:08:16 +01:00
|
|
|
log.out(`sanitizerUtils.cleanApiEndpointNum: WARN: Sanitizing changed string. Input = ${input}`, "warn");
|
2023-02-09 20:34:53 +00:00
|
|
|
}
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanNrcc(input) {
|
|
|
|
var rmNewline = input.replace(/[\n\r]/g, ""); // Remove newlines
|
|
|
|
var rmPara = rmNewline.replace(/<\/?p[^>]*>/g, ""); // Remove <p> & </p>
|
|
|
|
return rmPara;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
cleanApiEndpointTxt,
|
|
|
|
cleanApiEndpointNum,
|
|
|
|
cleanNrcc
|
|
|
|
}
|