install
$ npm install filter-params
usage:
const attrs = {
user_id: "xxx",
email: "xxx@email.com",
name: null,
isValid: false,
}
const filter = new FilterParams(attrs)
filter.req([ "name" ])
// or in rest style
filter.req("name")
// raise Error `name is required`
filter.exclude([ "name" ]).commit()
// or in rest style
filter.exclude("name").commit()
/* {
user_id: "xxx",
email: "xxx@email.com",
isValid: false,
} */
filter.permit([ "email" ]).commit()
// or in rest style
filter.permit("email").commit()
/* {
email: "xxx@email.com",
} */