3.8.117 • Published 10 months ago

@taktikorg/beatae-libero-cum v3.8.117

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Query Strings Parser
=========================
License NPM Version NPM Downloads Travis Coverage Dependencies DependenciesDev Vulnerabilities Releases Contributors Issues

Middleware to transform query strings in a format that is recognized by the MongoDB, MySQL¹ and other databases.

Prerequisites

To ensure the smooth operation of the middleware, your web application must be built using the express.js or hapi.js frameworks.

Installing

Use the npm command to install this library into your project:

npm i @taktikorg/beatae-libero-cum --save  

Usage Examples

const express = require('express')  
const qs = require('@taktikorg/beatae-libero-cum')  
const app = express()  
  
app.use(qs()) // middleware @taktikorg/beatae-libero-cum  
  
app.listen(3000, (req, res) => {  
    console.log('app listening on port 3000')  
})  
  
app.get('/', (req, res) => {  
    res.send('the query is:' + JSON.stringify(req.query))  
})  
  
/**  
 * Request: http://localhost:3000?fields=name,age&skip=10&limit=10&sort=created_at  
 * Result (req.query):  
 * {  
 *    fields: { name: 1, age: 1 },  
 *    sort: { created_at: 1 }  
 *    filters: {},  
 *    pagination: {  
 *        skip: 10,  
 *        limit: 10  
 *    },  
 *    original: '?fields=name,age&skip=10&limit=10&sort=created_at'  
 * }  
 */  

Using custom configurations:

const express = require('express')  
const qs = require('@taktikorg/beatae-libero-cum')  
const app = express()  
  
app.use(qs({  
  use_page: true,  
  client_db: 'mongodb',  
  date_field: {  
      start_at: 'timestamp',  
      end_at: 'timestamp'  
  },  
  default: {  
      fields: {name: 1 , age: 1, number: 1, _id: 0},  
      sort: { created_at: -1 },  
      filters: {},  
      pagination: {  
          page: 1,  
          limit: 100  
      }  
  }  
}))  
  
/**  
 * Request: http://localhost:3000?fields=name,age&age=30  
 * Result (req.query):  
 * {  
 *    fields: { name: 1, age: 1},  
 *    sort: { created_at: -1 }  
 *    filters: {age: 30},  
 *    pagination: {  
 *        limit: 100,  
 *        page: 1  
 *    },  
 *    original: '?fields=name,age&age=30'  
 * }  
 */  

The middleware uses the following defaults:

options = {  
    use_page: false,  
    client_db: 'mongodb',  
    date_field: {  
      start_at: 'created_at',  
      end_at: 'created_at'  
    },
    default: {  
        fields: {},  
        sort: {},  
        filters: {},  
        pagination: {  
            limit: Number.MAX_SAFE_INTEGER,  
            skip: 0,  
            page: 1  
        }          
    }      
}  

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.

Parsers Functions

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()
const qs = require('@taktikorg/beatae-libero-cum')

const query = '?fields=name,age&page=1&limit=10&sort=created_at'
console.log(qs.parseFields(query, {}, { use_page: true }))

/**
* Result: 
* {
*   fields: { name: 1, age: 1 },
*   sort: { created_at: 1 },
*   filters: {},
*   pagination: { limit: 10, page: 1 },
*   original:  '?fields=name,age&page=1&limit=10&sort=created_at'
* }
*/

For more details >>

  • parseFields()
const qs = require('@taktikorg/beatae-libero-cum')

const query = '?fields=name,age'
console.log(qs.parseFields(query))

/**
* Result: 
* { 
*     name: 1,
*     age: 1
* }
*/

For more details >>

  • parseSort()
const qs = require('@taktikorg/beatae-libero-cum')

const query = '?sort=name,-age,created_at'
console.log(qs.parseSort(query))

/**
* Result: 
* { 
*     name: 1,
*     age: -1,
*     created_at: 1
* }
*/

For more details >>

  • parsePagination()
const qs = require('@taktikorg/beatae-libero-cum')

const query = '?limit=20&page=3'
console.log(qs.parsePagination(query, {}, true))

/**
* Result: 
* { 
*     limit: 20,
*     page: 3 
* }
*/

For more details >>

  • parseFilter()
 const qs = require('@taktikorg/beatae-libero-cum')
 
 const query = '?name=elvis&age=80'
 console.log(qs.parseFilter(query))
 
 /**
 * Result: 
 * { 
 *     name: 'elvis',
 *     age: 80
 * }
 */

For more details >>

  • parseDate()

    const qs = require('@taktikorg/beatae-libero-cum')
    
    const query = '?start_at=2019-02-05T00:00:00&end_at=2019-02-05T23:59:59'
    console.log(qs.parseDate(query))
    
    /**
  • Result:
  • {
  • $and: [
  •   { created_at: { lt: 2019-02-05T23:59:59 }},
  •   { created_at: { gte: 2019-02-05T00:00:00 }}
  • ]}
  • } */
    For more [details >>](https://github.com/taktikorg/beatae-libero-cum/wiki/4.-Parsers#parsedate)

Supported Query Strings

For informations and details about the supported query strings, access the wiki page.


Future Features

  • ¹Support for relational databases such as MySQL, PostgreSQL and SQLite.
ECMAScript 2023envautoprefixerpicomatcheventEmitterlimitedtesteresstatelessemitjsxbusycloudformationexecutableformattings3Array.prototype.filtermobiletapjsonpathESnextprotobufhttpconcatMapstabletc39superagentreuseinternalrecursiveECMAScript 3charactersyntaxglobalswhichpushfsavatddfullduplexworkerES2023symbolyaml0ECMAScript 2020getternodejspathcloudtrailequalitymoveweakmaplookargumentnumberwrapcoverageintrinsicdynamodbgetPrototypeOfinputcall-bindpolyfillObject.iscloudsearchoffsettestpackageArray.prototype.flattenastPromiseflatMaptyped arrayredirectfastclonereact-hookssafelrupromisesString.prototype.matchAllslotJSONutil.inspecttypedarraypyyamlschemea11ytaskECMAScript 5protocol-buffersenumerablebatchtelephonebundlercloudwatchStyleSheetclass-validatoremrsesiterationpipesharedfunction.lengthES3chromiumoptionroutingregexpimportexportPushcontainsratelimitString.prototype.trimredux-toolkitiam[[Prototype]]persistentregexObject.valuesES7loadbalancingStreamsnativedeepextendglobisConcatSpreadablemimetypesbddexpresslinkAsyncIteratoridinferenceInt16ArraySymbolcsslazypnpm9JSON-Schemahelperfunctionsdeletecall-boundwgetcodesprogressclonequeryECMAScript 7includeskoreanratefindES5jQuerytoolsfunctionefficientFunction.prototype.nameES8getjoitrimRightparentstraversebrowserstoragegatewaywritableyupcollection.es6loggerdomES2019lintES2017TypedArrayjsonbrowserlistebspostcss-pluginentrieschromepositiveObject.fromEntriesbluebirdcopyUint8ClampedArrayfindLast-0expressionenvironmentscloudfrontfilesuperstructTypeScriptcoresequencestylexhrnpmECMAScript 2022jsdomunicodematchesanimationURLSearchParamsassertionvalueswritewarning3dhashweaksetgetintrinsicfile cachehasOwnPropertyperformanceproxyxdg-openprotoschemaRFC-6455command-lineapppackage.jsonfastnopecollectionstreamcomputed-typesonceobjreduceindicatorcolorresolvetoolkitaccessoropeneragentoptimizerzerosyntaxerrorenderrgbwalkutiluuidmulti-packagecore-jsrandomcurldataviewshebangsqsassertsdependenciesmkdirmatchrfc4122validateprivateswfshellBigUint64ArrayeditortextES6identifierseslint-pluginObject.keystypescriptgdpr256commanderArrayBuffer#sliceES2022arraytrimLefttypeoffiltertimeequalRegExp.prototype.flags.envcss-in-jshas-owncircularsimple cacheflatbindeslintpluginkarmaimmutablecolumnHyBiserializationlibphonenumberhasOwnpropertysimpledbtypedarraysbundlingclireact posesymbolssetdiffguidhooksgraphqlquerystringvariablesredactmapdefine
3.6.69

12 months ago

3.6.68

12 months ago

3.6.67

12 months ago

3.6.66

12 months ago

3.6.65

12 months ago

3.6.64

1 year ago

3.6.63

1 year ago

3.6.62

1 year ago

3.6.61

1 year ago

3.6.60

1 year ago

3.2.35

1 year ago

3.2.34

1 year ago

3.6.79

12 months ago

3.2.37

1 year ago

3.6.78

12 months ago

3.2.36

1 year ago

3.6.77

12 months ago

3.6.76

12 months ago

3.2.38

1 year ago

3.6.75

12 months ago

3.6.74

12 months ago

3.4.50

1 year ago

3.4.51

1 year ago

3.6.100

11 months ago

3.6.101

11 months ago

3.2.33

1 year ago

3.6.73

12 months ago

3.6.72

12 months ago

3.6.71

12 months ago

3.6.70

12 months ago

3.1.33

1 year ago

3.3.50

1 year ago

3.1.32

1 year ago

3.1.31

1 year ago

3.6.106

11 months ago

2.1.27

1 year ago

3.6.107

11 months ago

2.1.28

1 year ago

2.1.26

1 year ago

3.6.102

11 months ago

3.6.103

11 months ago

3.6.104

11 months ago

3.6.105

11 months ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

3.6.59

1 year ago

3.6.58

1 year ago

1.1.19

1 year ago

3.6.57

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

2.1.29

1 year ago

2.1.30

1 year ago

1.1.23

1 year ago

2.1.31

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

1.1.20

1 year ago

1.1.26

1 year ago

1.1.25

1 year ago

1.1.24

1 year ago

3.5.57

1 year ago

3.5.56

1 year ago

3.5.55

1 year ago

3.3.38

1 year ago

3.5.54

1 year ago

3.3.39

1 year ago

3.5.53

1 year ago

3.5.52

1 year ago

3.5.51

1 year ago

3.8.111

11 months ago

3.8.112

11 months ago

3.8.113

10 months ago

3.8.114

10 months ago

3.8.115

10 months ago

3.8.116

10 months ago

3.8.117

10 months ago

3.3.46

1 year ago

3.3.47

1 year ago

3.3.48

1 year ago

3.3.49

1 year ago

3.3.40

1 year ago

3.3.41

1 year ago

3.3.42

1 year ago

3.3.43

1 year ago

3.3.44

1 year ago

3.3.45

1 year ago

3.7.107

11 months ago

3.7.108

11 months ago

3.6.89

11 months ago

3.6.88

11 months ago

3.6.87

11 months ago

3.6.86

11 months ago

3.6.85

11 months ago

3.7.109

11 months ago

3.7.110

11 months ago

3.6.84

12 months ago

3.7.111

11 months ago

3.6.83

12 months ago

3.6.82

12 months ago

3.6.81

12 months ago

3.6.80

12 months ago

3.6.99

11 months ago

3.6.98

11 months ago

3.6.97

11 months ago

3.6.96

11 months ago

3.6.95

11 months ago

3.6.94

11 months ago

3.6.93

11 months ago

3.6.92

11 months ago

3.6.91

11 months ago

3.6.90

11 months ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.9

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.12

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago