Socket
Socket
Sign inDemoInstall

express-mung

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 0.2.0

17

index.js

@@ -6,2 +6,5 @@ 'use strict';

function isScalar(v) {
return typeof v !== 'object' && !Array.isArray(v);
}

@@ -24,2 +27,8 @@ mung.json = function json (fn) {

// If scalar value, then text/plain
if (isScalar(json)) {
res.set('content-type', 'text/plain');
return res.send(json);
}
return original.call(this, json);

@@ -44,3 +53,9 @@ }

return original.call(this, json);
// If scalar value, then text/plain
if (isScalar(json)) {
res.set('content-type', 'text/plain');
return res.send(json);
}
return original.call(this, json);
});

@@ -47,0 +62,0 @@

2

package.json
{
"name": "express-mung",
"version": "0.1.1",
"version": "0.2.0",
"description": "Transform an express response (or make until no good)",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -53,2 +53,4 @@ # express-mung [![Build Status](https://travis-ci.org/richardschneider/express-prefer.svg)](https://travis-ci.org/richardschneider/express-mung)

**NOTE** when `mung.json*` receives a scalar value then the `content-type` is switched `text-plain`.
# License

@@ -55,0 +57,0 @@ The MIT license

@@ -18,2 +18,6 @@ 'use strict';

function reduce (json, req, res) {
return json.a;
}
it('should return the munged JSON result', done => {

@@ -59,2 +63,16 @@ let server = express()

it('should return a munged scalar result as text/plain', done => {
let server = express()
.use(mung.json(reduce))
.get('/', (req, res) => res.status(200).json({ a: 'a' }).end());
request(server)
.get('/')
.expect(200)
.expect(res => {
res.text.should.equal('a');
res.headers.should.have.property('content-type', 'text/plain; charset=utf-8');
})
.end(done);
});
})

@@ -24,2 +24,8 @@ 'use strict';

function reduce (json, req, res) {
return Promise.resolve(json)
.then(json => json.a);
}
it('should return the munged JSON result', done => {

@@ -50,3 +56,16 @@ let server = express()

it('should return a munged scalar result as text/plain', done => {
let server = express()
.use(mung.jsonAsync(reduce))
.get('/', (req, res) => res.status(200).json({ a: 'alpha' }).end());
request(server)
.get('/')
.expect(200)
.expect(res => {
res.text.should.equal('alpha');
res.headers.should.have.property('content-type', 'text/plain; charset=utf-8');
})
.end(done);
});
})
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