num-parser
Parse numbers in ExpressJS requests.
Last updated 3 years ago by passabilities .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install num-parser 
SYNC missed versions from official npm registry.

num-parser npm

Parse numbers in ExpressJS requests.

Installation

npm i num-parser --save

Usage

The module will parse all numbers in req.query, req.params, and req.body.

Also works with floating points.

To work with req.body you need to add after body-parser:

const bodyParser = require('body-parser')
const numParser = require('num-parser')

app.use(bodyParser.json())
app.use(numParser)

// ?a=1&b[c]=tw0&b[d]=3.5
app.use('/', (req, res) => {
  console.log(req.query)
  // => { a: 1, b: { c: 'tw0', d: 3.5 } }
})

NOTE: I've had problems having it as a global middleware to work with req.params. If it's not working for you, try putting the middleware in for each route:

// ?a=1&b[c]=tw0&b[d]=3.5
app.use('/', numParser, (req, res) => {
  console.log(req.query)
  // => { a: 1, b: { c: 'tw0', d: 3.5 } }
})

Current Tags

  • 1.1.0                                ...           latest (3 years ago)

6 Versions

  • 1.1.0                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 2
Last Month 2
Dependencies (1)
Dev Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2016 © taobao.org |