express-query-int
Convert query strings to numbers for express/connect applications.
Installation
npm install --save express-query-int
Getting Started
The module will recursively attempt to parse every property in req.query
.
Load it right after the bodyParser
:
var queryParser = ; // [...] app;app;
Without
// ?a=1&b[c]=2console;// => { a: '4', b: { c: '2' } }
With
// ?a=1&b[c]=2console;// => { a: 4, b: { c: 2 } }
Default Parser
By default the parser will use Number
to convert numbers. You can use parseInt
, parseFloat
, or your own function.
app;
Custom Parser
Provide a function that takes two arguments:
value
: a string potentially representing a numberradix
: 10name
: a name of query argument
app;
License
Copyright (c) 2015 Marius Craciunoiu. Licensed under the MIT license.