@bitovi/querystring-parser
Advanced tools
Comparing version 0.2.0 to 0.3.0
{ | ||
"name": "@bitovi/querystring-parser", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
# QUERYSTRING PARSER | ||
# querystring-parser | ||
@@ -10,3 +10,3 @@ ## Purpose / Usecase | ||
- `?sort=-date,name&page[number]=1&page[size]=5` | ||
- `fields[articles]=title,body&fields[people]=name` | ||
- `?fields[articles]=title,body&fields[people]=name` | ||
- You need to parse these query parameters to fetch the requested data. This library does the query string parsing for you. | ||
@@ -17,3 +17,7 @@ | ||
```js | ||
// todo | ||
const querystringParser = require('@bitovi/querystring-parser') | ||
const { page } = querystringParser.parse('page[number]=0&page[size]=10') | ||
console.log(page.number) // --> 0 | ||
console.log(page.size) // --> 10 | ||
``` | ||
@@ -27,3 +31,3 @@ | ||
```js | ||
const { sort } = querystringParser('sort=-date,name') | ||
const { sort } = querystringParser.parse('sort=-date,name') | ||
console.log(sort[0]) // --> { field: 'date', direction: 'DESC' } | ||
@@ -38,3 +42,3 @@ console.log(sort[1]) // --> { field: 'name', direction: 'ASC' } | ||
```js | ||
const { page } = querystringParser('page[number]=0&page[size]=10') | ||
const { page } = querystringParser.parse('page[number]=0&page[size]=10') | ||
console.log(page.number) // --> 0 | ||
@@ -54,3 +58,3 @@ console.log(page.size) // --> 10 | ||
```js | ||
const { filter } = querystringParser('filter[start_date][$eq]=2020-01-01') | ||
const { filter } = querystringParser.parse('filter[start_date][$eq]=2020-01-01') | ||
console.log(filter[0].field) // --> 'start_date' | ||
@@ -66,3 +70,3 @@ console.log(filter[0].comparator) // --> '=' | ||
```js | ||
const { include } = querystringParser('include=children.movies.actors.children,children.movies.actors.pets,children.pets,pets') | ||
const { include } = querystringParser.parse('include=children.movies.actors.children,children.movies.actors.pets,children.pets,pets') | ||
console.log(include[0]) // --> 'children.movies.actors.children' | ||
@@ -79,3 +83,3 @@ console.log(include[1]) // --> 'children.movies.actors.pets' | ||
```js | ||
const { fields } = querystringParser('fields[articles]=title,body&fields[people]=name') | ||
const { fields } = querystringParser.parse('fields[articles]=title,body&fields[people]=name') | ||
console.log(fields.articles) // --> [ 'title', 'body' ] | ||
@@ -82,0 +86,0 @@ console.log(fields.people) // --> [ 'name' ] |
27887
85