mongoose-type-html
An html field-type for Mongoose schemas. The field type can use DOMPurify and Sanitize-HTML for casting HTML values. At default only DOMPurify is enabled with default options. You can easily disable or change the options from both. To know which options you can use visit their github pages and take a look there.
usage
This will cast html, correctly:
var mongoose = require('mongoose');
require('mongoose-type-html');
var UserSchema = new mongoose.Schema({
description: mongoose.SchemaTypes.Html
});
var UserSchema = new mongoose.Schema({
description: {
type: mongoose.SchemaTypes.Html,
dompurify: true,
sanitizehtml: true
}
});
You can also use the stuff in String
type:
var UserSchema = new mongoose.Schema({
description: { type: mongoose.SchemaTypes.Html, required: true }
});
You can also use it as an array:
var UserSchema = new mongoose.Schema({
descriptions: [{type: mongoose.SchemaTypes.Html}]
});
In typescript you only have to import it instead of requiring.
import 'mongoose-type-html';