README
This module is designed for the Strongloop Loopback framework.
loopback-ds-sanitizer-mixin
Sanitize user input when persisting data.
Options
To use with your Models add the mixins
attribute to the definition object of your model config.
{
"name": "Widget",
"properties": {
"name": {
"type": "string"
}
},
"mixins": {
"sanitizer" : {
"field1": INPUT_CLASS,
"field2": INPUT_CLASS
},
}
}
Where INPUT_CLASS must be one of:
- oneLineString: Removes new lines, Remove control characters, trim spaces
- multiLineString: Keeps new lines, Remove control characters, trim spaces
INSTALL
npm install --save loopback-ds-sanitizer-mixin
MIXINSOURCES
With loopback-boot@v2.8.0 mixinSources have been implemented in a way which allows for loading this mixin without changes to the server.js
file previously required.
Add the mixins
property to your server/model-config.json
like the following:
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"../node_modules/loopback-ds-sanitizer-mixin",
"../common/mixins"
]
}
}
TESTING
Run the tests in test/test.js
npm test
Run with debugging output on:
DEBUG='loopback-ds-sanitizer-mixin' npm test