Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Use HTML as mongoose type to have sanitize-html and dompurify features

License

Notifications You must be signed in to change notification settings

CSoellinger/mongoose-type-html

Repository files navigation

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.

npm

usage

This will cast html, correctly:

var mongoose = require('mongoose');
require('mongoose-type-html');

// Using with default options: dompurify = true / sanitizehtml = false
var UserSchema = new mongoose.Schema({
    description: mongoose.SchemaTypes.Html
});

// Using with both options on true: dompurify = true / sanitizehtml = true
var UserSchema = new mongoose.Schema({
    description: {
        type: mongoose.SchemaTypes.Html,
        // You can pass an object with dompurify config too. True uses default options.
        dompurify: true,
        // You can pass an object with sanitizehtml config too. True uses default options.
        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';

About

Use HTML as mongoose type to have sanitize-html and dompurify features

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •