Skip to content

admatic-tool/filter-params

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FilterParams.js

install

$ npm install filter-params

usage:

  const attrs = {
    user_id: "xxx",
    email: "xxx@email.com",
    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: "xxx@email.com",
    isValid: false,
  } */

permit attributes

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

  /* {
    email: "xxx@email.com",
  } */

Releases

No releases published

Packages

No packages published