1.1.0 • Published 7 years ago

mongoose-sanitizer-plugin v1.1.0

Weekly downloads
10
License
MIT
Repository
github
Last release
7 years ago

mongoose-sanitizer-plugin

Sanitizer for mongoose models.

Uses Caja-HTML-Sanitizer.

Installation

npm i mongoose-sanitizer-plugin --save

Options

ParameterTypeDefaultDescription
modeStringescapeEnum: sanitizer, escape, normalizeRCData, unescapeEntities. See Caja-HTML-Sanitizer docs.
includeString, Array<String>[]List of properties that will be sanitized.
excludeString, Array<String>[]List of properties that won't be sanitized.

If both include and exclude are not specified then all string properties will be sanitized.

Examples

Minimal usage:

const sanitizerPlugin = require('mongoose-sanitizer-plugin');
const mongoose = require('mongoose');
const SomeSchema = new mongoose.Schema({ /* ... */ });

SomeSchema.plugin(sanitizerPlugin);

mongoose.model('Some', SomeSchema);

Specifying your own options:

SomeSchema.plugin(sanitizerPlugin, {
    mode: 'sanitize',
    include: ['firstName', 'lastName']
});

Specifying options with different mode for every group of properties:

SomeSchema.plugin(sanitizerPlugin, [
    {
        mode: 'sanitizer',
        include: ['firstName', 'lastName']
    },
    {
        mode: 'escape',
        include: 'bio'
    }
]);