Skip to content

Latest commit

 

History

History
57 lines (44 loc) · 813 Bytes

README.md

File metadata and controls

57 lines (44 loc) · 813 Bytes

FilterParams.js

install

$ npm install filter-params

usage:

  const attrs = {
    user_id: "xxx",
    email: "[email protected]",
    name: null,
    isValid: false,
  }

  const filter = new FilterParams(attrs)

Require an attribute

  filter.req([ "name" ])
  // or in rest style
  filter.req("name")

  // raise Error `name is required`

Filtering attributes

exclude attrbutes

  filter.exclude([ "name" ]).commit()
  // or in rest style
  filter.exclude("name").commit()

  /* {
    user_id: "xxx",
    email: "[email protected]",
    isValid: false,
  } */

permit attributes

  filter.permit([ "email" ]).commit()
  // or in rest style
  filter.permit("email").commit()

  /* {
    email: "[email protected]",
  } */