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-short-body

v1.1.0

Published

More short API for koa-better-body.

Downloads

8

Readme

npm mit license build status coverage status deps status

More short API for koa-better-body.

A koa body parser middleware with support for multipart, json, csp-report and urlencoded request bodies. Via formidable and co-better-body. It's fork of koa-better-body

Install

npm i --save koa-short-body
npm test

Usage

For more use-cases see the tests or examples folder.

Extending default types

Every new defined type, will be appended to defaults, see defaults

app.use(koaBody({
  extendTypes: {
    // will parse application/x-javascript type body as a JSON string
    json: ['application/x-javascript'],
    multipart: ['multipart/mixed']
  }
}));

will expects request bodies

application/json
application/json-patch+json
application/vnd.api+json
application/csp-report
application/x-javascript

application/x-www-form-urlencoded

multipart/form-data
multipart/mixed

get field or file via this

app.use(function * (next) {
    // Get specify fields
    console.log(this.field("field_name"));

    // Get received all fields.
    console.log(this.field());

    // Get specify fields file (it's must be returns Array<File>)
    console.log(this.file("file"));

    // Get all received files
    console.log(this.file());
})

.koaBetterBody

However, koa-short-body have few custom options, see also co-better-body, raw-body and formidable

  • [options] {Object}
    • jsonLimit {String|Number} The byte limit of the JSON body, default 1mb
    • formLimit {String|Number} The byte limit of the form body, default 56kb
    • encoding {String} Sets encoding for incoming form fields, default utf-8
    • encode {String} alias of opts.encoding
    • multipart {Boolean} Support multipart/form-data request bodies, default false
    • extendTypes {Object} extending request types, see defaults
      • multipart {Array} array with multipart types, default ['multipart/form-data']
      • json {Array} array with json types, default ['application/x-www-form-urlencoded']
      • form {Array} array with form types
    • qs {Object} Options that are passing to qs
    • formidable {Object} Options that are passing to formidable
  • return {GeneratorFunction} That you can use with koa or co

formidable options

See node-formidable for a full list of options

  • bytesExpected {Integer} The expected number of bytes in this form, default null
  • maxFields {Integer} Limits the number of fields that the querystring parser will decode, default 1000
  • maxFieldsSize {Integer} Limits the amount of memory a field can allocate in bytes, default 2mb
  • uploadDir {String} Sets the directory for placing file uploads in, default os.tmpDir()
  • hash {String} If you want checksums calculated for incoming files - 'sha1' or 'md5', default false
  • multiples {Boolean} Multiple file uploads or no, default false

qs options

See qs for a full list of options

  • depth {Integer} The parsed object maximum hierarchy depth, default 5
  • delimiter {String|Regex} The query string delimeter, default &
  • arrayLimit {Integer} Maximum array size or -1 to disable arrays, default 20

Author

Charlike Mike Reagent

License MIT license

Copyright (c) 2014-2015 Charlike Mike Reagent, contributors.
Released under the MIT license.


Powered and automated by kdf, February 6, 2015