Comparing version 3.3.2 to 3.3.3
25
json.js
@@ -1,2 +0,2 @@ | ||
var stringify = require("json-stringify-safe") | ||
// var stringify = require("json-stringify-safe") | ||
@@ -18,5 +18,11 @@ var send = require("./index") | ||
var tuple = safeStringify(opts.body, | ||
opts.replacer || null, opts.space || ""); | ||
if (tuple[0]) { | ||
return callback(tuple[0]); | ||
} | ||
opts.headers = opts.headers || {} | ||
opts.body = stringify(opts.body, | ||
opts.replacer || null, opts.space || "") | ||
opts.body = tuple[1]; | ||
opts.headers["Content-Type"] = "application/json" | ||
@@ -26,1 +32,14 @@ | ||
} | ||
function safeStringify(obj, replace, space) { | ||
var json; | ||
var error = null; | ||
try { | ||
json = JSON.stringify(obj, replace, space); | ||
} catch (e) { | ||
error = e; | ||
} | ||
return [error, json]; | ||
} |
{ | ||
"name": "send-data", | ||
"version": "3.3.2", | ||
"version": "3.3.3", | ||
"description": "send data through response", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -32,2 +32,18 @@ var test = require("tape") | ||
}) | ||
} else if (req.url === "/json/shared") { | ||
var shared = { foo: "bar" } | ||
sendJson(req, res, { | ||
shared1: shared, | ||
shared2: shared | ||
}) | ||
} else if (req.url === "/json/circular") { | ||
var circular = {} | ||
circular.circular = circular | ||
sendJson(req, res, circular, function (err) { | ||
if (err) { | ||
res.end(err.message) | ||
} | ||
}) | ||
} else if (req.url === "/html") { | ||
@@ -136,3 +152,25 @@ sendHtml(req, res, { | ||
test("shared-json", function (t) { | ||
request("/json/shared", function (err, res, body) { | ||
var data = JSON.parse(body) | ||
t.equal(res.statusCode, 200) | ||
t.equal(data.shared1.foo, "bar") | ||
t.equal(data.shared2.foo, "bar") | ||
t.end() | ||
}) | ||
}) | ||
test("circular-json", function (t) { | ||
request("/json/circular", function (err, res, body) { | ||
t.equal(res.statusCode, 200) | ||
t.equal(res.body, "Converting circular structure to JSON") | ||
t.end() | ||
}) | ||
}) | ||
.on("end", done) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14812
310