Nuclear Planning Manual

    mongoose-type-html
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.4 • Public • Published

    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,
            dompurify: true, // You can pass an object with dompurify config too. True uses default options.
            sanitizehtml: true // You can pass an object with sanitizehtml config too. True uses default options.
        }
    });

    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';

    Install

    npm i mongoose-type-html

    DownloadsWeekly Downloads

    5

    Version

    0.0.4

    License

    MIT

    Last publish

    Collaborators

    • csoellinger