New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

send-data

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

send-data - npm Package Compare versions

Comparing version 1.1.2 to 2.0.1

25

error.js

@@ -5,9 +5,26 @@ var sendJson = require("./json")

function sendError(req, res, error, statusCode) {
var message = typeof error === "string" ? error : error.message
function sendError(req, res, opts) {
if (!opts.statusCode || !opts.error) {
opts = { error: opts, statusCode: 500 }
}
var error = opts.error
var statusCode = opts.statusCode
var headers = opts.headers
var body
if (Array.isArray(error)) {
body = { errors: error }
} else if (typeof error === "string") {
body = { errors: [{ message: error, attribute: "general" }] }
} else if (error && typeof error.message === "string") {
body = { errors: [
{ message: error.message, attribute: "general" }
] }
}
sendJson(req, res, {
statusCode: statusCode || 500,
body: { message: message }
statusCode: statusCode,
body: body,
headers: headers
})
}

2

index.js

@@ -22,3 +22,3 @@ var Buffer = require("buffer").Buffer

body = Buffer.isBuffer(body) ? body : new Buffer(body)
body = Buffer.isBuffer(body) ? body : new Buffer(body || "")
headers = headers || {}

@@ -25,0 +25,0 @@

@@ -12,3 +12,3 @@ var send = require("./index")

function sendJson(req, res, value) {
if (!value.statusCode && !value.headers) {
if (!value || (!value.statusCode && !value.headers)) {
value = { body: value }

@@ -15,0 +15,0 @@ }

{
"name": "send-data",
"version": "1.1.2",
"version": "2.0.1",
"description": "send data through response",

@@ -5,0 +5,0 @@ "keywords": [],

@@ -7,3 +7,3 @@ # send-data [![build status][1]][2]

```
```js
var send = require("send-data")

@@ -18,5 +18,5 @@ var sendJson = require("send-data/json")

send(req, res, {
body: "foo"
, statusCode: 202
, headers: {
body: "foo",
statusCode: 202,
headers: {
bar: "baz"

@@ -31,4 +31,4 @@ }

foo: "bar"
}
, statusCode: 201
},
statusCode: 201
})

@@ -41,5 +41,5 @@ } else if (req.url === "/json/optional") {

sendHtml(req, res, {
body: "<div>foo</div>"
, statusCode: 200
, headers: {}
body: "<div>foo</div>",
statusCode: 200,
headers: {}
})

@@ -54,2 +54,33 @@ } else if (req.url === "/html/optional") {

## Docs
```ocaml
send-data := (HttpRequest, HttpResponse, Buffer | String | {
headers?: Object<String, String>,
body?: Buffer | String,
statusCode?: Number
})
send-data/json := (HttpRequest, HttpResponse, Value | {
body: Value,
headers?: Object<String, String>,
statusCode?: Number
})
send-data/html := (HttpRequest, HttpResponse, String | {
body: String,
headers?: Object<String, String>,
statusCode?: Number
})
type ErrorObject := { attribute: String, message: String }
type MaybeErrorObject := Array<ErrorObject> | String | Error
send-data/error := (HttpRequest, HttpResponse, MaybeErrorObject | {
error: MaybeErrorObject,
statusCode?: Number,
headers?: Object<String, String>
})
```
## Installation

@@ -56,0 +87,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc