safe-textify
v1.0.2
Published
"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
Downloads
6
Maintainers
Readme
safe-textify
safe-textify is a simple npm package for sanitizing strings and validating email addresses.
Installation
You can install safe-textify using npm:
npm install safe-textify
Usage
sanitize(input)
Sanitizes the input string by replacing special characters with specified replacements.
const { sanitize } = require('safe-textify');
const sanitizedString = sanitize('Hello <World>!');
console.log(sanitizedString); // Output: Hello __World!_
validateEmail(email)
Validates the given email address against a regular expression pattern.
const { validateEmail } = require('safe-textify');
const isValidEmail = validateEmail('[email protected]');
console.log(isValidEmail); // Output: true
API
sanitize(input)
input
(string): The string to sanitize.
Returns the sanitized string.
validateEmail(email)
email
(string): The email address to validate.
Returns true
if the email address is valid according to the regular expression pattern, otherwise false
.
Example
const { sanitize, validateEmail } = require('safe-textify');
// Sanitize string
const sanitizedString = sanitize('Hello <World>!');
console.log(sanitizedString); // Output: Hello __World!_
// Validate email
const isValidEmail = validateEmail('[email protected]');
console.log(isValidEmail); // Output: true