npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-bodyparser-base

v0.0.3

Published

koa2 解析请求内容(body-parser), 包含基本的请求实体(raw, text, json, urlencoded)

Downloads

2

Readme

koa-bodyparser-base

一个基于 raw-bodykoa 请求内容解析器;支持的解析类型有 textformjsonraw

安装

npm install koa-bodyparser-base

使用

let Koa = require('koa');
let bodyParser = require('koa-bodyparser-base');

let app = new Koa();
let.use(bodyParser());

let.use(async (ctx) => {
  // 解析后的请求内容将存放到 ctx.request.body 上
  // 如果没有解析到对应的请求,则 body 将是 undefined
  ctx.body = ctx.request.body;
});

配置选项(options)

bodyParser([options]);
  • json: 解析 json 请求时,使用 raw-body 解析时需要的参数,默认:{ limit: '1mb', encoding: true }
  • form: 解析 form 请求时,使用 raw-body 解析时需要的参数,默认 { limit: '56kb', encoding: true }
  • text: 解析 text 请求时,使用 raw-body 解析时需要的参数,默认 { limit: '1mb', encoding: true }
  • raw: 解析 raw 请求时,使用 raw-body 解析时需要的参数,默认 { limit: '100kb', encoding: true }
  • extendTypes: 解析相应格式需要匹配的后缀格式,支持扩展每一种请求所兼容的类型,例如:
    app.use(bodyparser({
      extendTypes: {
        // 转换请求类型(content-type) 为 `application/x-javascript` 的请求内容为 `json` 格式。
        json: ['application/x-javascript']
      }
    }));
  • disableBodyParse:可以动态的通过设置 ctx.disableBodyParse = true 来禁用解析。
    app.use(async (ctx, next) => {
      if (ctx.path === '/disable') {
        ctx.disableBodyParse = true;
      }
      await next();
    });
    app.use(bodyparser());

备注

  1. limit 参数为 bytes 所支持的参数格式;
  2. encoding 参数为 iconv-lite 所支持的编码格式。
  3. 如果格式为 form 返回的是 querystring.parse() 解析后的对象,该对象跟普通的 Object 是不同的,详情参考:querystring_parse

License

MIT