0.3.0 • Published 7 years ago

koa-query-pretty v0.3.0

Weekly downloads
10
License
MIT
Repository
github
Last release
7 years ago

koa-query-pretty

Pretty query middleware for koa.

npm Build Status Coverage Status npm

中文 README

Description

Koa usesqueryString to parse the GET parameter by default, but the parsed arguments arestring.

Koa-query-pretty can be converted to concrete types like int, float,boolean, null, undefined.

install

yarn add koa-query-pretty

use

const Koa = require('koa');
const queryPretty = require('koa-query-pretty');

const app = new Koa();
app.use(queryPretty());

effect

/home?id=1&name=jack&enable=true&money=2.5&hobby=1&hobby=2

result

ctx.query:

{
  "id": 1,
  "name": "jack",
  "enable": true,
  "money": 2.5,
  "hobby": [
    1,
    2
  ]
}

configuration

override

Overwrite the ctx.query parameter, defaulttrue, otherwise use ctx.prettyQuery to get

app.use(queryPretty({ override: false }));

app.use(async (ctx, next) => {
  console.log(ctx.prettyQuery);
  await next();
});
0.3.0

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago