Gathering detailed insights and metrics for @npmteam2024/eius-tempore-ratione
Gathering detailed insights and metrics for @npmteam2024/eius-tempore-ratione
Gathering detailed insights and metrics for @npmteam2024/eius-tempore-ratione
Gathering detailed insights and metrics for @npmteam2024/eius-tempore-ratione
npm install @npmteam2024/eius-tempore-ratione
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
30
Middleware to transform query strings in a format that is recognized by the MongoDB, MySQL¹ and other databases.
To ensure the smooth operation of the middleware, your web application must be built using the express.js or hapi.js frameworks.
Use the npm command to install this library into your project:
1npm i @npmteam2024/eius-tempore-ratione --save
1const express = require('express') 2const qs = require('@npmteam2024/eius-tempore-ratione') 3const app = express() 4 5app.use(qs()) // middleware @npmteam2024/eius-tempore-ratione 6 7app.listen(3000, (req, res) => { 8 console.log('app listening on port 3000') 9}) 10 11app.get('/', (req, res) => { 12 res.send('the query is:' + JSON.stringify(req.query)) 13}) 14 15/** 16 * Request: http://localhost:3000?fields=name,age&skip=10&limit=10&sort=created_at 17 * Result (req.query): 18 * { 19 * fields: { name: 1, age: 1 }, 20 * sort: { created_at: 1 } 21 * filters: {}, 22 * pagination: { 23 * skip: 10, 24 * limit: 10 25 * }, 26 * original: '?fields=name,age&skip=10&limit=10&sort=created_at' 27 * } 28 */
1const express = require('express') 2const qs = require('@npmteam2024/eius-tempore-ratione') 3const app = express() 4 5app.use(qs({ 6 use_page: true, 7 client_db: 'mongodb', 8 date_field: { 9 start_at: 'timestamp', 10 end_at: 'timestamp' 11 }, 12 default: { 13 fields: {name: 1 , age: 1, number: 1, _id: 0}, 14 sort: { created_at: -1 }, 15 filters: {}, 16 pagination: { 17 page: 1, 18 limit: 100 19 } 20 } 21})) 22 23/** 24 * Request: http://localhost:3000?fields=name,age&age=30 25 * Result (req.query): 26 * { 27 * fields: { name: 1, age: 1}, 28 * sort: { created_at: -1 } 29 * filters: {age: 30}, 30 * pagination: { 31 * limit: 100, 32 * page: 1 33 * }, 34 * original: '?fields=name,age&age=30' 35 * } 36 */
The middleware uses the following defaults:
1options = { 2 use_page: false, 3 client_db: 'mongodb', 4 date_field: { 5 start_at: 'created_at', 6 end_at: 'created_at' 7 }, 8 default: { 9 fields: {}, 10 sort: {}, 11 filters: {}, 12 pagination: { 13 limit: Number.MAX_SAFE_INTEGER, 14 skip: 0, 15 page: 1 16 } 17 } 18}
If the options are not provided, the default values will be used for the treatment of queries strings.
For more details, access the wiki page.
To use these functions, simply call them through the middleware instance and pass them the query string to be converted and its default values. If you pass the default values a merge will be performed with the result of the query strings. Here are some examples of each analyzer:
parser()
1const qs = require('@npmteam2024/eius-tempore-ratione') 2 3const query = '?fields=name,age&page=1&limit=10&sort=created_at' 4console.log(qs.parseFields(query, {}, { use_page: true })) 5 6/** 7* Result: 8* { 9* fields: { name: 1, age: 1 }, 10* sort: { created_at: 1 }, 11* filters: {}, 12* pagination: { limit: 10, page: 1 }, 13* original: '?fields=name,age&page=1&limit=10&sort=created_at' 14* } 15*/
For more details >>
parseFields()
1 2const qs = require('@npmteam2024/eius-tempore-ratione') 3 4const query = '?fields=name,age' 5console.log(qs.parseFields(query)) 6 7/** 8* Result: 9* { 10* name: 1, 11* age: 1 12* } 13*/
For more details >>
parseSort()
1const qs = require('@npmteam2024/eius-tempore-ratione') 2 3const query = '?sort=name,-age,created_at' 4console.log(qs.parseSort(query)) 5 6/** 7* Result: 8* { 9* name: 1, 10* age: -1, 11* created_at: 1 12* } 13*/
For more details >>
parsePagination()
1const qs = require('@npmteam2024/eius-tempore-ratione') 2 3const query = '?limit=20&page=3' 4console.log(qs.parsePagination(query, {}, true)) 5 6/** 7* Result: 8* { 9* limit: 20, 10* page: 3 11* } 12*/
For more details >>
parseFilter()
1 const qs = require('@npmteam2024/eius-tempore-ratione') 2 3 const query = '?name=elvis&age=80' 4 console.log(qs.parseFilter(query)) 5 6 /** 7 * Result: 8 * { 9 * name: 'elvis', 10 * age: 80 11 * } 12 */
For more details >>
parseDate()
1const qs = require('@npmteam2024/eius-tempore-ratione') 2 3const query = '?start_at=2019-02-05T00:00:00&end_at=2019-02-05T23:59:59' 4console.log(qs.parseDate(query)) 5 6/** 7* Result: 8* { 9* $and: [ 10* { created_at: { lt: 2019-02-05T23:59:59 }}, 11* { created_at: { gte: 2019-02-05T00:00:00 }} 12* ]} 13* } 14*/
For more details >>
For informations and details about the supported query strings, access the wiki page.
No vulnerabilities found.
No security vulnerabilities found.