Metrics
0
Watch 3 Star 6 Fork 2

MinJieLiu / koa-query-prettyJavaScriptMIT

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
类型化 GET 参数的 Koa 中间件 spread retract

Clone or download
MinJieLiu authored doc .
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

koa-query-pretty

Pretty query middleware for koa.

npm Build Status Coverage Status npm

中文 README

Description

Koa uses queryString to parse the GET parameter by default, but the parsed arguments are string.

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

install

yarn add koa-query-pretty

Support node.js v7.6+

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, default true, otherwise use ctx.prettyQuery to get

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

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

Comments ( 0 )

You need to Sign in for post a comment

JavaScript
1
https://gitee.com/MinJieLiu/koa-query-pretty.git
git@gitee.com:MinJieLiu/koa-query-pretty.git

Help Search