JSPM

express-query-int

3.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1258
  • Score
    100M100P100Q107862F
  • License MIT

Convert query strings to numbers for express/connect applications.

Package Exports

  • express-query-int

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (express-query-int) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

express-query-int

Convert query strings to numbers for express/connect applications.

npm build status

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 = require('express-query-int');

// [...]

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

Without

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

With

// ?a=1&b[c]=2
console.log(req.query);
// => { 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.use(queryParser({
  parser: parseFloat
}));

Custom Parser

Provide a function that takes two arguments:

  • value: a string potentially representing a number
  • radix: 10
  • name : a name of query argument
app.use(queryParser({
  parser: function(value, radix, name) {
    if (true) {
      return modifiedValue;
    }
    else {
      return NaN;
    }
  }
}));

License

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