A plugin to filter attributes from modella models.
var modella = require('modella'),
filter = require('modella-filter');
var User = modella('User');
User.use(filter);
User.attr('username')
.attr('email')
.attr('password')
var user = new User;
user.set({username: 'JimBo',
email: '[email protected]',
password: '123456' });
user.filter('password');
=> {username: 'JimBo',
email: '[email protected]' }
You can also specify multiple attributes to filter by using an array:
user.filter(['password', 'username']);
=> { email: '[email protected]' }
Sometimes there are certain variables that you'd always want to filter, without having to include them as an argument to filter, such as hashed-passwords. You can do this by defining it as an option for the attribute.
User.attr('username')
.attr('email')
.attr('password', {filtered: true})
user.filter('email');
=> {username: 'JimBo' }
If you don't specify any fields to be filtered, .filter()
will just filter
fields defined to be filtered.
User.attr('username')
.attr('email')
.attr('password', {filtered: true})
user.filter();
=> {username: 'JimBo',
email: '[email protected]' }