package.json 21.2 KB
{
  "_args": [
    [
      {
        "raw": "koa-better-body",
        "scope": null,
        "escapedName": "koa-better-body",
        "name": "koa-better-body",
        "rawSpec": "",
        "spec": "latest",
        "type": "tag"
      },
      "/Users/fzy/project/koa2_Sequelize_project"
    ]
  ],
  "_from": "koa-better-body@latest",
  "_id": "koa-better-body@3.0.4",
  "_inCache": true,
  "_location": "/koa-better-body",
  "_nodeVersion": "8.1.4",
  "_npmOperationalInternal": {
    "host": "s3://npm-registry-packages",
    "tmp": "tmp/koa-better-body-3.0.4.tgz_1500215558282_0.5147535579744726"
  },
  "_npmUser": {
    "name": "tunnckocore",
    "email": "mameto_100@mail.bg"
  },
  "_npmVersion": "5.0.3",
  "_phantomChildren": {},
  "_requested": {
    "raw": "koa-better-body",
    "scope": null,
    "escapedName": "koa-better-body",
    "name": "koa-better-body",
    "rawSpec": "",
    "spec": "latest",
    "type": "tag"
  },
  "_requiredBy": [
    "#USER",
    "/"
  ],
  "_resolved": "https://registry.npmjs.org/koa-better-body/-/koa-better-body-3.0.4.tgz",
  "_shasum": "de49f544e4d6e1d9858f6c4880aedf2b8ac88759",
  "_shrinkwrap": null,
  "_spec": "koa-better-body",
  "_where": "/Users/fzy/project/koa2_Sequelize_project",
  "author": {
    "name": "Charlike Mike Reagent",
    "email": "@tunnckoCore",
    "url": "http://www.tunnckocore.tk"
  },
  "bugs": {
    "url": "https://github.com/tunnckoCore/koa-better-body/issues"
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  },
  "dependencies": {
    "extend-shallow": "^2.0.1",
    "formidable": "^1.0.17",
    "koa-body-parsers": "git+https://github.com/tunnckoCore/body-parsers.git"
  },
  "description": "Full-featured [koa][] body parser! Support parsing text, buffer, json, json patch, json api, csp-report, multipart, form and urlencoded bodies. Works for koa@1, koa@2 and will work for koa@3.",
  "devDependencies": {
    "commitizen": "^2.8.6",
    "coveralls": "^2.11.12",
    "cz-conventional-changelog": "^1.2.0",
    "eslint": "^4.2.0",
    "is-buffer": "^1.1.3",
    "koa": "^1.2.4",
    "koa-route": "^2.4.2",
    "mukla": "^0.4.1",
    "npm-run-all": "^4.0.2",
    "nyc": "^8.1.0",
    "pre-commit": "^1.1.3",
    "qs": "^6.2.1",
    "standard": "^10.0.2",
    "standard-version": "^2.4.0",
    "supertest": "^2.0.0"
  },
  "directories": {},
  "dist": {
    "integrity": "sha512-A1w/J5R1SR1RHwnX9xffJpIdAIXRpxflfBpZ/9Osw11ei428bm2mgmnJwEkoPoobiqdRfs54J7l6LjWMC8qk/Q==",
    "shasum": "de49f544e4d6e1d9858f6c4880aedf2b8ac88759",
    "tarball": "https://registry.npmjs.org/koa-better-body/-/koa-better-body-3.0.4.tgz"
  },
  "files": [
    "index.js",
    "utils.js"
  ],
  "gitHead": "fdfd3819498102342d99e420d5bfb4349954572c",
  "homepage": "https://github.com/tunnckoCore/koa-better-body#readme",
  "keywords": [
    "api",
    "awesome",
    "better",
    "body",
    "body-parser",
    "buffer",
    "csp",
    "csp-report",
    "error",
    "error-handling",
    "extendable",
    "feature",
    "features",
    "flexible",
    "form",
    "forms",
    "full",
    "full-feature",
    "handling",
    "json",
    "json-api",
    "json-patch",
    "json-strict",
    "jsonstrict",
    "koa",
    "koa-better-body",
    "multipart",
    "parse",
    "parser",
    "patch",
    "report",
    "rfc",
    "standard",
    "strict",
    "text",
    "unopinionated",
    "urlencoded"
  ],
  "license": "MIT",
  "main": "index.js",
  "maintainers": [
    {
      "name": "tunnckocore",
      "email": "mameto_100@mail.bg"
    }
  ],
  "name": "koa-better-body",
  "nyc": {
    "check-coverage": true,
    "statements": 100,
    "functions": 90,
    "branches": 88,
    "lines": 100
  },
  "optionalDependencies": {},
  "readme": "# [koa-better-body][author-www-url] [![npmjs.com][npmjs-img]][npmjs-url] [![The MIT License][license-img]][license-url] [![npm downloads][downloads-img]][downloads-url] \n\n> Full-featured [koa][] body parser! Support parsing text, buffer, json, json patch, json api, csp-report, multipart, form and urlencoded bodies. Works for koa@1, koa@2 and will work for koa@3.\n\n[![code climate][codeclimate-img]][codeclimate-url] [![standard code style][standard-img]][standard-url] [![travis build status][travis-img]][travis-url] [![coverage status][coveralls-img]][coveralls-url] [![dependency status][david-img]][david-url]\n\nYou might also be interested in our [recipes](./recipes) - working examples, answers, tips & tricks. [Contribute a recipe?](#contributing-recipes)\n\n## Install\n```\nnpm i koa-better-body --save\n```\n\n## Features\n- Work for `koa@1` and `koa@2` (with deprecation messages), will also work in `koa@3` with [koa-convert][]\n- Totally flexible through `options` and absolutely lightweight using [lazy-cache][]\n- Accept few JSON types\n- Accept [JSON Patch [RFC6902]](https://tools.ietf.org/html/rfc6902) ([koajs/bodyparser#8](https://github.com/koajs/bodyparser/pull/8))\n- Accept [JSON API v1](http://jsonapi.org/) ([koajs/bodyparser#7](https://github.com/koajs/bodyparser/pull/7))\n- Accept [JSON csp-report](https://mathiasbynens.be/notes/csp-reports) ([#3](https://github.com/tunnckoCore/koa-better-body/issues/3))\n- Accept text and buffer bodies\n- Accept urlencoded and forms bodies\n- Accept multipart form data files and fields\n- Can parse correctly array data from forms - e.g. multiple fields to have same name - [dlau/koa-body#15](https://github.com/dlau/koa-body/pull/15)\n- Can parse correctly forms that accept multiple files - see [#26](https://github.com/tunnckoCore/koa-better-body/issues/26) and [dlau/koa-body#15](https://github.com/dlau/koa-body/pull/15)\n- Strict mode by default - see why on [IETF Message Semantics: Section 6.1](https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-19#section-6.1)\n- Custom JSON request detect function - [koajs/bodyparser#f6a5ff](https://github.com/koajs/bodyparser/commit/f6a5ff7ef6162702540b101de5dde71ee5ad19cd)\n- Custom error handling function - [koajs/bodyparser#19418129](https://github.com/koajs/bodyparser/commit/194181298fe3bffce6b5fcf3cfebc35b8cda6c89)\n- Extending types of request that your app can accept - [koajs/bodyparser#ba7479b](https://github.com/koajs/bodyparser/commit/ba7479baf893fc3391fcdb88d3d8173ac4df05e7)\n- Using awesome [formidable][] package - [„battle-tested against hundreds of GB of file uploads“](https://github.com/felixge/node-formidable#current-status)\n- Passing a custom `formidable.IncomingForm` instance, allowing awesome customization\n- Passing all options to `formidable.IncomingForm`, allowing awesome control\n\n## Usage\n> For more use-cases see the [tests](./test.js)\n\n```js\nconst koaBetterBody = require('koa-better-body')\n```\n\n## Working with [koa-router][] and [koa-better-router](https://github.com/tunnckoCore/koa-better-router)\n\n```js\n'use strict'\n\nvar app = require('koa')()\nvar body = require('koa-better-body')\nvar router = require('koa-better-router')().loadMethods()\n\nrouter.post('/upload', body(), function * (next) {\n  console.log(this.request.files)\n  console.log(this.request.fields)\n\n  // there's no `.body` when `multipart`,\n  // `urlencoded` or `json` request\n  console.log(this.request.body)\n\n  // print it to the API requester\n  this.body = JSON.stringify({\n    fields: this.request.fields,\n    files: this.request.files,\n    body: this.request.body || null\n  }, null, 2)\n\n  yield next\n})\n\napp.use(router.middleware())\napp.listen(4292)\n\nvar format = require('util').format\nvar host = 'http://localhost:4292'\nvar cmd = 'curl -i %s/upload -F \"source=@%s/.editorconfig\"'\n\nconsole.log('Try it out with below CURL for `koa-better-body` repository.')\nconsole.log(format(cmd, host, __dirname))\n```\n\n### [koaBetterBody](index.js#L40)\n> Robust body parser for [koa][]@1, also works for `koa@2` (with deprecations). Will also work for future `koa@3` with [koa-convert][].\n\n**Params**\n\n* `options` **{Object}**: see more on [options section](#options)    \n* `returns` **{GeneratorFunction}**  \n\n**Example**\n\n```js\nvar koa = require('koa')\nvar body = require('koa-better-body')\nvar app = koa()\n\napp\n  .use(body())\n  .use(function * () {\n    console.log(this.request.body)    // if buffer or text\n    console.log(this.request.files)   // if multipart or urlencoded\n    console.log(this.request.fields)  // if json\n  })\n  .listen(8080, function () {\n    console.log('koa server start listening on port 8080')\n  })\n```\n\n## Options\nSane defaults. :sparkles:\n\nAccepts JSON, [JSON API v1](http://jsonapi.org/), text, buffer, [csp-report](https://mathiasbynens.be/notes/csp-reports), multipart and urlencoded/form bodies. If you want to disallow accepting and parsing multipart body you should pass `multipart: false`. Most of the defaults you can see at [utils.defaultOptions and utils.defaultTypes](./utils.js). **All `options` are also been passed to [formidable][].IncomingForm!** Even you can pass IncomingForm instance to be able to handle the different formidable events.\n\n- `fields` **{Boolean|String}**: Default `false`, which means it will set fields on `this.request.fields`. If you pass a string, for example `'foo'`, you will have fields on `this.request.foo`.\n- `files` **{Boolean|String}**: Default `false`, which means it will set files on `this.request.files`. If you pass a string, for example `'bar'`, you will have files on `this.request.bar`.\n- `multipart` **{Boolean}**: Default `true`. If you pass `false` it won't accept/parse multipart bodies.\n- `textLimit` **{String}**: Default `'100kb'`. Passed to [bytes][].parse method.\n- `formLimit` **{String}**: Default `'100kb'`. Passed to [bytes][].parse method.\n- `urlencodedLimit` **{String}**: Default `'100kb'`. Alias of `opts.formLimit`.\n- `jsonLimit` **{String}**: Default `'100kb'`. Passed to [bytes][].parse method.\n- `bufferLimit` **{String}**: Default `'1mb'`. Passed to [bytes][].parse method.\n- `jsonStrict` **{Boolean}**: Default `true`. When set to true, JSON parser will only accept arrays and objects.\n- `detectJSON` **{Function}**: Custom JSON request detect function - `detectJSON(ctx)`.\n- `strict` **{Boolean}**: Default `true`. Pass `false` if you want to allow parsing GET, DELETE and HEAD requests.\n- `onerror` **{Function}**: Custom error handle, if throw an error, you can customize the response - `onerror(err, ctx)`.\n- `extendTypes` **{Object}**: Default accepting types can find on [utils.defaultTypes function](./utils.js#L97-L119). Allowing you to extend what your app can accept. By default works for JSON, [JSON API v1](http://jsonapi.org/), multipart, text, urlencoded and [csp-report](https://mathiasbynens.be/notes/csp-reports).\n- `IncomingForm` **{IncomingForm}**: Pass an instance of `formidable.IncomingForm` to be able to handle formidable events.\n- `handler` **{GeneratorFunction}**: Works with `options.extendTypes.custom` to handle custom types of content-type - `handler(ctx, options, next)`. More info below.\n- `querystring` **{Object}**: Querystring module to be used. By default builtin [`querystring`](https://nodejs.org/api/querystring.html). More info below.\n- `qs` **{Object}**: Alias of `opts.querystring`. All `opts` are also passed to [qs][] or [querystring module](https://nodejs.org/api/querystring.html).\n- `delimiter` **{String}**: Default is `&`. Delimiter of key/value pairs, passed to querystring lib\n- `sep` **{String}**: alias of `opts.delimiter`\n- `buffer` **{Boolean}**: Default `false`, pass `true` if you want to get body as buffer.\n\n## Note about `options.extendTypes`\n\nExandTypes option gives you a flexible way to handle different content-types and modify the defaults which can be found [at utils.defaultTypes function](./utils.js#L97-L119). In addition you can pass combination of `options.extendTypes.custom` and `options.handler`. When the request has some of the \"custom\" content type, this middleware will call the `handler` **generator** function with `ctx, options, next`. You can see more at [issue #52](https://github.com/tunnckoCore/koa-better-body/issues/52).\n\nFor example manually handle such content types `foo/bar-x`, `text/quix`:\n\n```js\nconst app = require('koa')()\nconst body = require('koa-better-body')\n\napp.use(body({\n  textLimit: '300kb'\n  extendTypes: {\n    custom: [\n      'foo/bar-x',\n      'text/quix'\n    ]\n  },\n  handler: function * (ctx, opts) {\n    // `ctx` is equal to `this` and `app`\n    // `opts` is current options object\n    // passed to `koa-better-body`\n    ctx.body = yield this.request.text(opts.textLimit)\n  }\n}))\napp.use(function * showBody () {\n  // `this.body` is text\n  console.log(this.body)\n})\n```\n\n## Note about advanced `querystring` parsing\nBecause this middleware is fully based and integrated with [koa-body-parsers][], by default it uses Node's built-in module for that thing [querystring](https://nodejs.org/api/querystring.html). So if you have some issues with forms, think to add custom querystring module like [qs][] to `options.querystring` or `app.querystring`. Related to this is [issue #45](https://github.com/tunnckoCore/koa-better-body/issues/45).\n\n**Example**\n\n```js\nconst app = require('koa')()\nconst body = require('koa-better-body')\n\napp.use(body({\n  multipart: false\n  querystring: require('qs')\n}))\n```\n\nIt's intentional that it's not included in the deps by default. In `v2` it was also working by passing it to `app.querystring`, because [koa-body-parsers][] works [that way (index.js#L53)](https://github.com/koajs/body-parsers/blob/master/index.js#L53).\n\n## Note about `strict` mode\nWe are trying to follow standards. :cat2:\n\nYou can pass `strict:false`, but see [IETF HTTP/1.1 Message Semantics: Section 6.1](https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-19#section-6.1) to understand why we stay to _\"strict mode\"_ by default. GET, HEAD, and DELETE requests have no defined semantics for the request body, but this doesn't mean they may not be valid in certain use cases. Last two tests at [test/options.js](./test/options.js) are showing usage on non-strict and strict mode. \n\n## Related\nYou might also be interested in these packages:\n- [formidable](https://www.npmjs.com/package/formidable): A node.js module for parsing form data, especially file uploads. | [homepage](https://github.com/felixge/node-formidable \"A node.js module for parsing form data, especially file uploads.\")\n- [ip-filter](https://www.npmjs.com/package/ip-filter): Validates valid IPs (IPv4 and IPv6) using [micromatch][] - glob patterns, RegExp, string or… [more](https://github.com/tunnckocore/ip-filter#readme) | [homepage](https://github.com/tunnckocore/ip-filter#readme \"Validates valid IPs (IPv4 and IPv6) using [micromatch][] - glob patterns, RegExp, string or array of globs. If match returns the IP, otherwise null.\")\n- [koa-body-parsers](https://www.npmjs.com/package/koa-body-parsers): collection of koa body parsers | [homepage](https://github.com/koajs/body-parsers#readme \"collection of koa body parsers\")\n- [koa-bodyparser](https://www.npmjs.com/package/koa-bodyparser): a body parser for koa | [homepage](https://github.com/koajs/body-parser \"a body parser for koa\")\n- [koa-ip-filter](https://www.npmjs.com/package/koa-ip-filter): Middleware for [koa][] that filters IPs against glob patterns, RegExp, string or array of… [more](https://github.com/tunnckocore/koa-ip-filter#readme) | [homepage](https://github.com/tunnckocore/koa-ip-filter#readme \"Middleware for [koa][] that filters IPs against glob patterns, RegExp, string or array of globs. Support custom `403 Forbidden` message and custom ID.\")\n- [koa](https://www.npmjs.com/package/koa): Koa web app framework | [homepage](https://github.com/koajs/koa#readme \"Koa web app framework\")\n- [koala](https://www.npmjs.com/package/koala): Koa Framework Suite | [homepage](https://github.com/koajs/koala#readme \"Koa Framework Suite\")\n\n## Contributing\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/tunnckoCore/koa-better-body/issues/new).  \nBut before doing anything, please read the [CONTRIBUTING.md](./CONTRIBUTING.md) guidelines.\n\n### Contributing Recipes\nRecipes are just different use cases, written in form of README in human language. Showing some \"Pro Tips\" and tricks, answering common questions and so on. They look like [tests](./test.js), but in more readable and understandable way for humans - mostly for beginners that not reads or understand enough the README or API and tests.\n\n- They are in form of folders in the root [`recipes/`](./recipes) folder: for example `recipes/[short-meaningful-recipe-name]/`.\n- In recipe folder should exist `README.md` file: see [recipes/multipart/README.md](./recipes/multipart/README.md).\n- The examples from the recipe README.md should also exist as separate `.js` files.\n- Examples in recipe folder also should be working and actual.\n\nIt would be great if you follow these steps when you want to _fix, update or create_ a recipes. :sunglasses:\n\n- Title for recipe idea should start with `[recipe]`: for example`[recipe] my awesome recipe`\n- Title for new recipe (PR) should also start with `[recipe]`.\n- Titles of Pull Requests or Issues for fixing/updating some existing recipes should start with `[recipe-fix]`.\n\nIt will help a lot, thanks in advance! :yum:\n\n## [Charlike Make Reagent](http://j.mp/1stW47C) [![new message to charlike][new-message-img]][new-message-url] [![freenode #charlike][freenode-img]][freenode-url]\n\n[![tunnckoCore.tk][author-www-img]][author-www-url] [![keybase tunnckoCore][keybase-img]][keybase-url] [![tunnckoCore npm][author-npm-img]][author-npm-url] [![tunnckoCore twitter][author-twitter-img]][author-twitter-url] [![tunnckoCore github][author-github-img]][author-github-url]\n\n[bytes]: https://github.com/visionmedia/bytes.js\n[formidable]: https://github.com/felixge/node-formidable\n[koa-body-parsers]: https://github.com/koajs/body-parsers\n[koa-convert]: https://github.com/gyson/koa-convert\n[koa-router]: https://github.com/alexmingoia/koa-router\n[koa]: https://github.com/koajs/koa\n[lazy-cache]: https://github.com/jonschlinkert/lazy-cache\n[micromatch]: https://github.com/jonschlinkert/micromatch\n[qs]: https://github.com/ljharb/qs\n[raw-body]: https://github.com/stream-utils/raw-body\n\n[npmjs-url]: https://www.npmjs.com/package/koa-better-body\n[npmjs-img]: https://img.shields.io/npm/v/koa-better-body.svg?label=koa-better-body\n\n[license-url]: https://github.com/tunnckoCore/koa-better-body/blob/master/LICENSE\n[license-img]: https://img.shields.io/npm/l/koa-better-body.svg\n\n[downloads-url]: https://www.npmjs.com/package/koa-better-body\n[downloads-img]: https://img.shields.io/npm/dm/koa-better-body.svg\n\n[codeclimate-url]: https://codeclimate.com/github/tunnckoCore/koa-better-body\n[codeclimate-img]: https://img.shields.io/codeclimate/github/tunnckoCore/koa-better-body.svg\n\n[travis-url]: https://travis-ci.org/tunnckoCore/koa-better-body\n[travis-img]: https://img.shields.io/travis/tunnckoCore/koa-better-body/master.svg\n\n[coveralls-url]: https://coveralls.io/r/tunnckoCore/koa-better-body\n[coveralls-img]: https://img.shields.io/coveralls/tunnckoCore/koa-better-body.svg\n\n[david-url]: https://david-dm.org/tunnckoCore/koa-better-body\n[david-img]: https://img.shields.io/david/tunnckoCore/koa-better-body.svg\n\n[standard-url]: https://github.com/feross/standard\n[standard-img]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg\n\n[author-www-url]: http://www.tunnckocore.tk\n[author-www-img]: https://img.shields.io/badge/www-tunnckocore.tk-fe7d37.svg\n\n[keybase-url]: https://keybase.io/tunnckocore\n[keybase-img]: https://img.shields.io/badge/keybase-tunnckocore-8a7967.svg\n\n[author-npm-url]: https://www.npmjs.com/~tunnckocore\n[author-npm-img]: https://img.shields.io/badge/npm-~tunnckocore-cb3837.svg\n\n[author-twitter-url]: https://twitter.com/tunnckoCore\n[author-twitter-img]: https://img.shields.io/badge/twitter-@tunnckoCore-55acee.svg\n\n[author-github-url]: https://github.com/tunnckoCore\n[author-github-img]: https://img.shields.io/badge/github-@tunnckoCore-4183c4.svg\n\n[freenode-url]: http://webchat.freenode.net/?channels=charlike\n[freenode-img]: https://img.shields.io/badge/freenode-%23charlike-5654a4.svg\n\n[new-message-url]: https://github.com/tunnckoCore/ama\n[new-message-img]: https://img.shields.io/badge/ask%20me-anything-green.svg\n\n",
  "readmeFilename": "README.md",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/tunnckoCore/koa-better-body.git"
  },
  "scripts": {
    "commit": "npm-run-all -s test git",
    "git": "npm-run-all -s git:*",
    "git:add": "git add --all",
    "git:cz": "git-cz",
    "lint": "eslint ./*js ./test/*.js --fix",
    "prerelease": "npm test",
    "release": "standard-version --sign --no-verify",
    "test": "npm-run-all -s lint test:*",
    "test:api": "nyc --reporter lcov node test.js",
    "test:report": "nyc report"
  },
  "verb": {
    "run": true,
    "toc": false,
    "layout": "empty",
    "tasks": [
      "readme"
    ],
    "related": {
      "list": [
        "koa",
        "koa-ip-filter",
        "ip-filter",
        "formidable",
        "koa-body-parsers",
        "koa-bodyparser",
        "koala"
      ]
    },
    "reflinks": [
      "bytes",
      "formidable",
      "koa",
      "koa-body-parsers",
      "koa-convert",
      "lazy-cache",
      "raw-body",
      "koa-router",
      "micromatch",
      "qs"
    ],
    "lint": {
      "reflinks": true
    }
  },
  "version": "3.0.4"
}