thug-filters

A filter add-on for thug functional model

thug-filters

Thug is a functional model system for nodejs, this module is an add-on module of common filters that any model may use.

https://github.com/sintaxi/thug

Thug was created to minimize the complexity of validating and altering an object before writing it to a data store or performing an operation. Thug is not an ORM but is ment to be a replacment for one. Thug is very small and works on both the server or in a browser.

npm install thug-filters --save

Thug Model

var Thug = require('thug');
var filters = require('thug-filters');
 
module.exports = function(config) {
  var post = new Thug({
    filters: {
      "in": [
        filters.whitelist(['title', 'body', 'author'])
      ]
    }
  });
  return post;
}

Removes all nodes from the document that are specified in the fields array.

Keeps all nodes from the document that are specified in the fields array and discards the rest.

Includes this field and a defaultValue for your document. This is great to set the docType attribute for a couchDb document.

filters: {
  beforeWrite: [filters.include('docType', 'Post')]
}

Removes any xss injections in text fields using the validator module.

filters: {
  beforeWrite: [filters.sanitize('body')]
}
 

Generates a unique identifer using the node-uuid module.

MIT

pull requests are welcome!