install
$ npm install filter-params
usage:
const attrs = {
user_id: "xxx",
email: "[email protected]",
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: "[email protected]",
isValid: false,
} */
filter.permit([ "email" ]).commit()
// or in rest style
filter.permit("email").commit()
/* {
email: "[email protected]",
} */