const { santize } = require('indicative')
Run sanitizations on data using pre-defined rules. Following are some key points to note.
This method will never mutate the original data set.
Sanitized data object has the same structure as the original data set.
If value to be sanitized is in wrong format, it will be returned as it is.
data |
Object |
rules |
Object |
The full build exports the santize
method from the top level object.
const { santize } = require('indicative')
When using customized build, you need to configure the sanitizor instance before you can make use of the santize
method.
import Sanitizor from 'indicative/builds/sanitizor'
import { normalizeEmail, stripTags } from 'indicative/builds/sanitizations'
const { sanitize } = Sanitizor({ normalizeEmail, stripTags })
Sanitizing data is a synchronous operation and returns a new object with sanitized values.
const rules = {
email: 'normalize_email',
bio: 'strip_tags'
}
const data = {
email: 'foo+bar@GMAIL.COM',
bio: 'Checkout my profile on <a href="">github.com</a>'
}
const sanitizedData = sanitize(data, rules)