|
1 |
| -[![License][license-image]][license-url] [![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![Travis][travis-image]][travis-url] [![Coverage][coverage-image]][coverage-url] [![Vulnerabilities][known-vulnerabilities-image]][known-vulnerabilities-url] |
2 | 1 |
|
3 |
| -# Query Strings Parser |
4 |
| -Middleware to transform query strings in a format that is recognized by the MongoDB, MySQL[¹](#future-features) and other databases. |
5 |
| - |
6 |
| -## Prerequisites |
7 |
| -To ensure the smooth operation of the middleware, your web application must be built using the [express.js][express] or [hapi.js][hapi] frameworks. |
8 |
| - |
9 |
| -## Installing |
10 |
| -Use the npm command to install this library into your project: |
11 |
| -``` |
12 |
| -npm i --save query-strings-parser |
13 |
| -``` |
14 |
| - |
15 |
| -### Usage Examples |
16 |
| -#### 1. Using default configurations |
17 |
| -```js |
18 |
| -const express = require('express') |
19 |
| -const qs = require('query-strings-parser') |
20 |
| -const app = express() |
21 |
| - |
22 |
| -app.use(qs()) // middleware query-strings-parser |
23 |
| - |
24 |
| -app.listen(3000, (req, res) => { |
25 |
| - console.log('app listening on port 3000') |
26 |
| -}) |
27 |
| - |
28 |
| -app.get('/', (req, res) => { |
29 |
| - res.send('the query is:' + JSON.stringify(req.query)) |
30 |
| -}) |
31 |
| - |
32 |
| -/** |
33 |
| - * Request: http://localhost:3000?fields=name,age&skip=10&limit=10&sort=created_at |
34 |
| - * Result (req.query): |
35 |
| - * { |
36 |
| - * fields: { name: 1, age: 1 }, |
37 |
| - * sort: { created_at: 'asc' } |
38 |
| - * filters: {}, |
39 |
| - * pagination: { |
40 |
| - * skip: 10, |
41 |
| - * limit: 10 |
42 |
| - * }, |
43 |
| - * original: '?fields=name,age&skip=10&limit=10&sort=created_at' |
44 |
| - * } |
45 |
| - */ |
46 |
| -``` |
47 |
| -#### The middleware uses the following defaults: |
48 |
| -```js |
49 |
| -options = { |
50 |
| - use_page: false, |
51 |
| - client_db: 'mongodb', |
52 |
| - date_field: { |
53 |
| - start_at: 'created_at', |
54 |
| - end_at: 'created_at' |
55 |
| - }, |
56 |
| - default: { |
57 |
| - fields: {}, |
58 |
| - sort: {}, |
59 |
| - filters: {}, |
60 |
| - pagination: { |
61 |
| - limit: Number.MAX_SAFE_INTEGER, |
62 |
| - skip: 0, |
63 |
| - page: 1 |
64 |
| - } |
65 |
| - } |
66 |
| -} |
67 |
| -``` |
68 |
| -If the options are not provided, the default values will be used for the treatment of queries strings. |
69 |
| - |
70 |
| -### 2. Using custom configurations: |
71 |
| -```js |
72 |
| -const express = require('express') |
73 |
| -const qs = require('query-strings-parser') |
74 |
| -const app = express() |
75 |
| - |
76 |
| -app.use(qs({ |
77 |
| - use_page: true, |
78 |
| - client_db: 'mongodb', |
79 |
| - date_field: { |
80 |
| - start_at: 'timestamp', |
81 |
| - end_at: 'timestamp' |
82 |
| - }, |
83 |
| - default: { |
84 |
| - fields: {name: 1 , age: 1, number: 1, _id: 0}, |
85 |
| - sort: { created_at: 'desc' }, |
86 |
| - filters: {}, |
87 |
| - pagination: { |
88 |
| - page: 1, |
89 |
| - limit: 100 |
90 |
| - } |
91 |
| - } |
92 |
| -})) |
93 |
| - |
94 |
| -/** |
95 |
| - * Request: http://localhost:3000?fields=name,age&age=30 |
96 |
| - * Result (req.query): |
97 |
| - * { |
98 |
| - * fields: { name: 1, age: 1}, |
99 |
| - * sort: { created_at: 'desc' } |
100 |
| - * filters: {age: 30}, |
101 |
| - * pagination: { |
102 |
| - * limit: 100, |
103 |
| - * page: 1 |
104 |
| - * }, |
105 |
| - * original: '?fields=name,age&age=30' |
106 |
| - * } |
107 |
| - */ |
108 |
| -``` |
109 |
| - |
110 |
| -For more details, access the [wiki](https://github.com/nutes-uepb/query-strings-parser/wiki/2.-Usage-Examples) page. |
111 |
| - |
112 |
| -## Supported Query Strings |
113 |
| - |
114 |
| -For informations and details about the supported query strings, access the [wiki](https://github.com/nutes-uepb/query-strings-parser/wiki/3.-Supported-Query-Strings) page. |
115 |
| - |
116 |
| -## New Features |
117 |
| - |
118 |
| -- Support for parser functions. For informations and details about parser functions, access the [wiki](https://github.com/nutes-uepb/query-strings-parser/wiki/4.-Parsers) page. |
119 |
| -## Future Features |
120 |
| -- ¹Support for relational databases such as MySQL, PostgreSQL and SQLite. |
| 2 | +Query Strings Parser |
| 3 | +========================= |
| 4 | +[![License][license-image]][license-url] [![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][npm-url] [![Travis][travis-image]][travis-url] [![Coverage][coverage-image]][coverage-url] [![Dependencies][dependencies-image]][dependencies-url] [![DependenciesDev][dependencies-dev-image]][dependencies-dev-url] [![Vulnerabilities][known-vulnerabilities-image]][known-vulnerabilities-url] [![Releases][releases-image]][releases-url] [![Contributors][contributors-image]][contributors-url] [![Issues][issues-image]][issues-url] |
| 5 | + |
| 6 | +Middleware to transform query strings in a format that is recognized by the MongoDB, MySQL[¹](#future-features) and other databases. |
| 7 | + |
| 8 | +## Prerequisites |
| 9 | +To ensure the smooth operation of the middleware, your web application must be built using the [express.js][express] or [hapi.js][hapi] frameworks. |
| 10 | + |
| 11 | +## Installing |
| 12 | +Use the npm command to install this library into your project: |
| 13 | +``` |
| 14 | +npm i --save query-strings-parser |
| 15 | +``` |
| 16 | + |
| 17 | +### Usage Examples |
| 18 | +#### 1. Using default configurations |
| 19 | +```js |
| 20 | +const express = require('express') |
| 21 | +const qs = require('query-strings-parser') |
| 22 | +const app = express() |
| 23 | + |
| 24 | +app.use(qs()) // middleware query-strings-parser |
| 25 | + |
| 26 | +app.listen(3000, (req, res) => { |
| 27 | + console.log('app listening on port 3000') |
| 28 | +}) |
| 29 | + |
| 30 | +app.get('/', (req, res) => { |
| 31 | + res.send('the query is:' + JSON.stringify(req.query)) |
| 32 | +}) |
| 33 | + |
| 34 | +/** |
| 35 | + * Request: http://localhost:3000?fields=name,age&skip=10&limit=10&sort=created_at |
| 36 | + * Result (req.query): |
| 37 | + * { |
| 38 | + * fields: { name: 1, age: 1 }, |
| 39 | + * sort: { created_at: 'asc' } |
| 40 | + * filters: {}, |
| 41 | + * pagination: { |
| 42 | + * skip: 10, |
| 43 | + * limit: 10 |
| 44 | + * }, |
| 45 | + * original: '?fields=name,age&skip=10&limit=10&sort=created_at' |
| 46 | + * } |
| 47 | + */ |
| 48 | +``` |
| 49 | +#### The middleware uses the following defaults: |
| 50 | +```js |
| 51 | +options = { |
| 52 | + use_page: false, |
| 53 | + client_db: 'mongodb', |
| 54 | + date_field: { |
| 55 | + start_at: 'created_at', |
| 56 | + end_at: 'created_at' |
| 57 | + }, |
| 58 | + default: { |
| 59 | + fields: {}, |
| 60 | + sort: {}, |
| 61 | + filters: {}, |
| 62 | + pagination: { |
| 63 | + limit: Number.MAX_SAFE_INTEGER, |
| 64 | + skip: 0, |
| 65 | + page: 1 |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | +If the options are not provided, the default values will be used for the treatment of queries strings. |
| 71 | + |
| 72 | + |
| 73 | +### 2. Using custom configurations: |
| 74 | +```js |
| 75 | +const express = require('express') |
| 76 | +const qs = require('query-strings-parser') |
| 77 | +const app = express() |
| 78 | + |
| 79 | +app.use(qs({ |
| 80 | + use_page: true, |
| 81 | + client_db: 'mongodb', |
| 82 | + date_field: { |
| 83 | + start_at: 'timestamp', |
| 84 | + end_at: 'timestamp' |
| 85 | + }, |
| 86 | + default: { |
| 87 | + fields: {name: 1 , age: 1, number: 1, _id: 0}, |
| 88 | + sort: { created_at: 'desc' }, |
| 89 | + filters: {}, |
| 90 | + pagination: { |
| 91 | + page: 1, |
| 92 | + limit: 100 |
| 93 | + } |
| 94 | + } |
| 95 | +})) |
| 96 | + |
| 97 | +/** |
| 98 | + * Request: http://localhost:3000?fields=name,age&age=30 |
| 99 | + * Result (req.query): |
| 100 | + * { |
| 101 | + * fields: { name: 1, age: 1}, |
| 102 | + * sort: { created_at: 'desc' } |
| 103 | + * filters: {age: 30}, |
| 104 | + * pagination: { |
| 105 | + * limit: 100, |
| 106 | + * page: 1 |
| 107 | + * }, |
| 108 | + * original: '?fields=name,age&age=30' |
| 109 | + * } |
| 110 | + */ |
| 111 | +``` |
| 112 | + |
| 113 | +For more details, access the [wiki](https://github.com/nutes-uepb/query-strings-parser/wiki/2.-Usage-Examples) page. |
| 114 | + |
| 115 | +## Supported Query Strings |
| 116 | +For informations and details about the supported query strings, access the [wiki](https://github.com/nutes-uepb/query-strings-parser/wiki/3.-Supported-Query-Strings) page. |
| 117 | + |
| 118 | +## New Features |
| 119 | +- Support for parser functions. For informations and details about parser functions, access the [wiki](https://github.com/nutes-uepb/query-strings-parser/wiki/4.-Parsers) page. |
| 120 | + |
| 121 | +## Future Features |
| 122 | +- ¹Support for relational databases such as MySQL, PostgreSQL and SQLite. |
121 | 123 |
|
122 | 124 | [//]: # (These are reference links used in the body of this note.)
|
123 |
| -[build-test]: <https://travis-ci.org/nutes-uepb/query-strings-parser> |
124 |
| -[test-coverage]: <https://coveralls.io/github/nutes-uepb/query-strings-parser?branch=master> |
125 |
| -[node.js]: <https://nodejs.org> |
126 |
| -[npm.js]: <https://www.npmjs.com/> |
127 |
| -[express]: <https://expressjs.com> |
128 |
| -[hapi]: <https://hapijs.com/> |
129 |
| - |
130 |
| -[license-image]: https://img.shields.io/github/license/mashape/apistatus.svg |
| 125 | +[node.js]: <https://nodejs.org> |
| 126 | +[npm.js]: <https://www.npmjs.com/> |
| 127 | +[express]: <https://expressjs.com> |
| 128 | +[hapi]: <https://hapijs.com/> |
| 129 | +[license-image]: https://img.shields.io/badge/license-Apache%202-blue.svg |
131 | 130 | [license-url]: https://github.com/nutes-uepb/query-strings-parser/blob/master/LICENSE
|
132 |
| -[npm-image]: https://img.shields.io/npm/v/query-strings-parser.svg |
| 131 | +[npm-image]: https://img.shields.io/npm/v/query-strings-parser.svg?color=red&logo=npm |
133 | 132 | [npm-url]: https://npmjs.org/package/query-strings-parser
|
134 |
| -[downloads-image]: https://img.shields.io/npm/dt/query-strings-parser.svg |
135 |
| -[downloads-url]: https://npmjs.org/package/query-strings-parser |
136 |
| -[travis-image]: https://travis-ci.org/nutes-uepb/query-strings-parser.svg?branch=master |
| 133 | +[downloads-image]: https://img.shields.io/npm/dt/query-strings-parser.svg?logo=npm |
| 134 | +[travis-image]: https://img.shields.io/travis/nutes-uepb/query-strings-parser.svg?logo=travis |
137 | 135 | [travis-url]: https://travis-ci.org/nutes-uepb/query-strings-parser
|
138 | 136 | [coverage-image]: https://coveralls.io/repos/github/nutes-uepb/query-strings-parser/badge.svg
|
139 | 137 | [coverage-url]: https://coveralls.io/github/nutes-uepb/query-strings-parser?branch=master
|
140 | 138 | [known-vulnerabilities-image]: https://snyk.io/test/github/nutes-uepb/query-strings-parser/badge.svg?targetFile=package.json
|
141 | 139 | [known-vulnerabilities-url]: https://snyk.io/test/github/nutes-uepb/query-strings-parser?targetFile=package.json
|
| 140 | +[dependencies-image]: https://david-dm.org/nutes-uepb/query-strings-parser.svg |
| 141 | +[dependencies-url]: https://david-dm.org/nutes-uepb/query-strings-parser |
| 142 | +[dependencies-dev-image]: https://david-dm.org/nutes-uepb/query-strings-parser/dev-status.svg |
| 143 | +[dependencies-dev-url]: https://david-dm.org/nutes-uepb/query-strings-parser?type=dev |
| 144 | +[releases-image]: https://img.shields.io/github/release-date/nutes-uepb/query-strings-parser.svg |
| 145 | +[releases-url]: https://github.com/nutes-uepb/ip-allowed/releases |
| 146 | +[contributors-image]: https://img.shields.io/github/contributors/nutes-uepb/query-strings-parser.svg?color=green |
| 147 | +[contributors-url]: https://github.com/nutes-uepb/query-strings-parser/graphs/contributors |
| 148 | +[issues-image]: https://img.shields.io/github/issues/nutes-uepb/query-strings-parser.svg |
| 149 | +[issues-url]: https://github.com/nutes-uepb/query-strings-parser/issues |
0 commit comments