UNPKG

safe-textify

Version:

"safe-textify: Secure your inputs effortlessly. This npm package offers robust input validation and sanitization tools, safeguarding your application against common security threats like XSS attacks. With customizable rules and clear error handling, ensur

27 lines (21 loc) 718 B
function sanitize(input) { const sanitizationRules = [ { regex: /&/g, replacement: '_' }, { regex: /</g, replacement: '__' }, { regex: />/g, replacement: '.' }, { regex: /"/g, replacement: '_' }, { regex: /'/g, replacement: '.' }, { regex: /\//g, replacement: '.' } ]; let sanitizedString = input; sanitizationRules.forEach(rule => { sanitizedString = sanitizedString.replace(rule.regex, rule.replacement); }); return sanitizedString; } function validateEmail(email) { const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; return emailPattern.test(email); } export { sanitize}; export {validateEmail};