koa-json
Advanced tools
Comparing version 1.1.1 to 2.0.0
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 @@ ``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
78
3246
4
45
2
+ Addedcore-util-is@1.0.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstreaming-json-stringify@3.1.0(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedstreaming-json-stringify@1.0.1(transitive)
Updatedstreaming-json-stringify@3