express-query-auto-parse

Convert query strings to numbers and booleans for express/connect applications.

Usage no npm install needed!

<script type="module">
  import expressQueryAutoParse from 'https://cdn.skypack.dev/express-query-auto-parse';
</script>

README

express-query-auto-parse

Convert query strings to boolean, numbers and dates for express/connect applications.

npm Build Status

Installation

npm install --save express-query-boolean

Getting Started

The module will recursively attempt to parse every property in req.query.

Load it right after bodyParser:

var autoParser = require('express-query-auto-parse');

// [...]

app.use(bodyParser.json());
app.use(autoParser());

Without

// ?a=true&b[c]=false
console.log(req.query);
// => { a: 'true', b: { c: 'false' } }

With

// ?a=true&b[c]=false
console.log(req.query);
// => { a: true, b: { c: false } }

Numbers

Convert string to numbers if they can be converted.

// ?a=2a&b=2
console.log(req.query);
// => { a: '2a', b: 2 }

Dates ( New in v2.2.0 )

Convert string to dates if they are valid dates.

// ?a=2a&b=2020-03-17T23:05:53.733Z
console.log(req.query);
// => { a: '2a', b: 2020-03-17T23:05:53.733Z }

Change logs

v3.0.1

  • FIX - Documentation

v3.0.0

  • Added support for date conversion.
  • FIX - Vulns and outdatet packages.
  • FIX - Travis integration shows wrong build.
  • FIX - NPM tag show wrong info.
  • README updated

Forked from

Copyright (c) 2015 Marius Craciunoiu. Licensed under the MIT license.