npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

restful-filter2

v1.2.0

Published

Simple library to parse restful filter based on http querystring

Downloads

6

Readme

Restful filter

This library aim to convert querystring parameters into parsed json with related operators, so you would able to use the parsed values into another query action like filtering by using your model on SQL library (knex, sequelize, etc).

Features

  • Filter querystring parameters
  • Parse pagination by using page and count parameter
  • Parse ordering by using order parameter

Installation

# via npm
npm i restful-filter --save

# via yarn
yarn add rest

Usage

const restfulFilter = require('restful-filter')

const filter = restfulFilter({ 
    case_sensitive: false // false by default, this is just example
})

# FILTER
# /api/users?name__ilike=aditya&age__eq=25&password__ilike=%a%
.get('/users', (req, res, next) => {
  const queryParams = req.query
  const allowedColumn = ['name', 'age']
  const searchParams = filter.parse(queryParams, allowedColumn).filter

  # now searchParams contains
  # {
  #   name: {operator: '$iLike', operatorSQL: 'ILIKE', column: 'name', value: 'aditya'},
  #   age: {operator: '$eq', operatorSQL: '=', column: 'age', value: '25'}
  # }
  #
  # password filter will not processed because not listed in the allowedColumn
})

# PAGINATION
# /api/users?page=2
.get('/users', (req, res, next) => {
    const queryParams = req.query
    const paginationParams = filter.parse(queryParams).paginate

    # paginationParams contains
    # {
    #   offset: 20,
    #   limit: 20   
    # }
})

# ORDER
# api/users?order_by=-id,name
.get('/users', (req, res, next) => {
    const queryParams = req.query
    const orderParams = filter.parse(queryParams).order

    # orderParams contains
    # [
    #   ['id', 'DESC']
    #   ['name', 'ASC']
    # ]

    # You even can limit the order column value by using second parameter as allowedColumn to process
    # Like 
    
    const orderParams = filter.parse(queryParams, ['id']).order

    # Would return
    # [
    #   ['id', 'DESC']
    # ]
})

Configuration

Key | Default Value | Description --- | --- | --- case_sensitive | false | Use case sensitive on query string parameter and parameter value page_param_name | page | Page parameter name to be used on querystring limit_param_name | count | Limit parameter name to be used on querystring per_page | 20 | Default number count per request if not set max_count_per_page | 100 | Maximum count for per_page parameter, so for example if count parameter value is higher than 100, the return value would stick to 100 order_param_name | order_by | Order parameter name to be used on querystring

Operators

Operator | Description | Example --- | --- | --- __eq | Find column equal with value | ?name__eq=smith __not | Not same with given value | ?active__not=true __ne | Negation, the opposite of equal | ?name__ne=smith __lt | Lower than | ?age__lt=10 __gt | Greater than | ?age__gt=15 __lte | Lower than and equal | ?age__lte=25 __gte | Greater than and equal | ?age__gte=20 __like | Like with case sensitive | ?name__like=smith __ilike | Like with case insensitive (Postgres) | ?name__ilike=smith __notLike | Opposite of like with case sensitive | ?name__notLike=smith __notILike | Opposite of like with case insensitive (Postgres) | ?name__notILike=smith __in | Find value which listed on given list | ?city__in=jakarta,bandung,bekasi __notIn | Find value which not listed in given list | ?city__notIn=bogor,depok,tangerang __contains | Find value that contains in given list (Postgres) | ?name__contains=smith __between | Find value which between 2 given values | ?date__between=2015-06-18,2017-05-31 __notBetween | Find value which is not between 2 given values | ?date__notBetween=2015-06-18,2017-05-31

Test

npm run test

Note

Please open a pull request for further abilities and another issues

License

MIT