Socket
Socket
Sign inDemoInstall

koa-json

Package Overview
Dependencies
11
Maintainers
9
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 2.0.0

5

History.md
2.0.0 / 2016-03-27
==================
* update to koa v2
1.1.0 / 2014-05-28

@@ -3,0 +8,0 @@ ==================

52

index.js

@@ -22,32 +22,32 @@

return function *filter(next){
yield *next;
return function filter(ctx, next){
return next().then(() => {
var body = ctx.body;
// unsupported body type
var stream = body
&& typeof body.pipe === 'function'
&& body._readableState
&& body._readableState.objectMode;
var json = isJSON(body);
if (!json && !stream) return;
var body = this.body;
// unsupported body type
var stream = body
&& typeof body.pipe === 'function'
&& body._readableState
&& body._readableState.objectMode;
var json = isJSON(body);
if (!json && !stream) return;
// query
var hasParam = param && ctx.query.hasOwnProperty(param);
var prettify = pretty || hasParam;
// query
var hasParam = param && this.query.hasOwnProperty(param);
var prettify = pretty || hasParam;
// always stringify object streams
if (stream) {
ctx.response.type = 'json';
var stringify = Stringify();
if (prettify) stringify.space = spaces;
ctx.body = body.pipe(stringify);
return;
}
// always stringify object streams
if (stream) {
this.response.type = 'json';
var stringify = Stringify();
if (prettify) stringify.space = spaces;
this.body = body.pipe(stringify);
return;
}
// prettify JSON responses
if (json && prettify) {
return this.body = JSON.stringify(body, null, spaces);
}
// prettify JSON responses
if (json && prettify) {
return ctx.body = JSON.stringify(body, null, spaces);
}
});
}
};
{
"name": "koa-json",
"version": "1.1.1",
"version": "2.0.0",
"repository": "koajs/json",

@@ -12,14 +12,17 @@ "description": "pretty (non-compressed) json response middleware",

"koa-is-json": "1",
"streaming-json-stringify": "1"
"streaming-json-stringify": "3"
},
"devDependencies": {
"mocha": "1",
"should": "3",
"koa": "0",
"supertest": "0"
"istanbul": "0",
"mocha": "2",
"koa": "2",
"supertest": "1"
},
"license": "MIT",
"scripts": {
"test": "make test"
}
"test": "NODE_ENV=test mocha --reporter spec",
"test-cov": "NODE_ENV=test istanbul cover ./node_modules/.bin/_mocha",
"test-travis": "NODE_ENV=test istanbul cover ./node_modules/.bin/_mocha --report lcovonly"
},
"files": ["index.js"]
}

@@ -25,8 +25,9 @@

var json = require('koa-json');
var app = koa();
var Koa = require('koa');
var app = new Koa();
app.use(json());
app.use(function *(next){
this.body = { foo: 'bar' };
app.use((ctx) => {
ctx.body = { foo: 'bar' };
});

@@ -49,8 +50,9 @@ ```

```js
var app = koa();
var Koa = require('koa');
var app = new Koa();
app.use(json({ pretty: false, param: 'pretty' }));
app.use(function *(next){
this.body = { foo: 'bar' };
app.use((ctx) => {
ctx.body = { foo: 'bar' };
});

@@ -57,0 +59,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc