Package Exports
- express-query-parser
- express-query-parser/dist/index.js
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-parser) 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-parser
A parser helps you parse request for your express server. You may usually encounter some req.query issues like parsing 'null', 'true' and any numbered string. This parser covert them to the right type.
scenarios
query with object
// GET http://localhost/?a=null&b=true&c[d]=false&c[e]=3.14
// without this parser
req.query = {a: 'null', b: 'true', c: {d: 'false', e: '3.14'}}
// with this parser
req.query = {a: null, b: true, c: {d: false, e: 3.14}}query with array
// GET http://localhost/?a[]=null&a[]=false
// without this parser
req.query = {a: ['null', 'false']}
// with this parser
req.query = {a: [null, false]}changelog
2022-05-31 (1.3.3): add empty string convert
2021-11-30 (1.3.2): add undefined convert
2021-10-12 (1.3.0): bump version, add number convert
2021-04-01 (1.2.0): bump version, only use esbuild and add type declarion
2020-10-26 (1.1.0): rewrite to typescript and rollup
2018-05-31 (1.0.2): support array
2018-05-29 (1.0.1): reduce size (177KB -> 17KB)
2018-05-17 (1.0.0): publish init version
feature
- parse your query for null / boolean / undefined
- support nested query
- support array
- support numbered string convert
install
# use yarn
yarn add express-query-parser
# use npm
npm i express-query-parserusage
const { queryParser } = require('express-query-parser')
const express = require('express')
const app = express()
app.use(
queryParser({
parseNull: true,
parseUndefined: true,
parseBoolean: true,
parseNumber: true
})
)options
| field | desc | type | default |
|---|---|---|---|
| parseNull | convert all "null" to null |
boolean |
true |
| parseUndefined | convert all "undefined" to undefined |
boolean |
true |
| parseBoolean | convert all "true" to true and "false" to false |
boolean |
true |
| parseNumber | convert all numbered string to int and float | boolean |
true |
Welcome any issues and PRs submit :D