Comparing version 1.3.0 to 1.3.1
15
json.js
const ErrorWithObject = require('error-with-object'); | ||
const callarest = require('./') | ||
const callarest = require('./'); | ||
let server; | ||
function callarestJson (options, callback) { | ||
@@ -10,3 +9,3 @@ const headers = { | ||
}; | ||
let data; | ||
@@ -16,3 +15,3 @@ if (options.data != null) { | ||
} | ||
callarest({ | ||
@@ -26,7 +25,7 @@ ...options, | ||
} | ||
try { | ||
rest.body = JSON.parse(rest.body); | ||
} catch (error) { | ||
callback(new ErrorWithObject({ | ||
return callback(new ErrorWithObject({ | ||
code: 'RESPONSE_NOT_VALID_JSON', | ||
@@ -37,3 +36,3 @@ message: 'The response body could not be JSON.parsed', | ||
} | ||
callback(null, rest); | ||
@@ -43,2 +42,2 @@ }); | ||
module.exports = callarestJson | ||
module.exports = callarestJson; |
{ | ||
"name": "callarest", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"keywords": [ | ||
@@ -15,3 +15,3 @@ "rest", | ||
"scripts": { | ||
"test": "tape test/*-test.js" | ||
"test": "c8 -o /tmp node test" | ||
}, | ||
@@ -33,4 +33,5 @@ "repository": { | ||
"dependencies": { | ||
"c8": "^6.0.1", | ||
"error-with-object": "^1.1.0" | ||
} | ||
} |
@@ -35,4 +35,4 @@ # Callarest | ||
```javascript | ||
const callarest = require('callarest') | ||
callarest.json({ | ||
const callarestJson = require('callarest/json) | ||
callarestJson({ | ||
method: 'post', | ||
@@ -39,0 +39,0 @@ data: { hello: 'world' }, |
@@ -27,3 +27,7 @@ const http = require('http'); | ||
function createJsonServer (callback) { | ||
function createJsonServer (data, callback) { | ||
if (arguments.length === 1) { | ||
callback = data; | ||
data = undefined; | ||
} | ||
server = http.createServer((request, response) => { | ||
@@ -38,3 +42,3 @@ if (request.url === '/echo' && request.method === 'POST') { | ||
}); | ||
response.end(JSON.stringify({ | ||
response.end(data || JSON.stringify({ | ||
a: 'you said', | ||
@@ -48,3 +52,3 @@ b: body | ||
}); | ||
response.end(JSON.stringify({success: true})); | ||
response.end(data || JSON.stringify({ success: true })); | ||
} | ||
@@ -51,0 +55,0 @@ }).listen(8000); |
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
11888
11
309
2
+ Addedc8@^6.0.1
+ Added@bcoe/v8-coverage@0.2.3(transitive)
+ Added@types/is-windows@0.2.0(transitive)
+ Added@types/istanbul-lib-coverage@2.0.6(transitive)
+ Addedansi-regex@4.1.1(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedc8@6.0.1(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedcliui@5.0.0(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconvert-source-map@1.9.0(transitive)
+ Addedcross-spawn@7.0.5(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedemoji-regex@7.0.3(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedfind-up@3.0.04.1.0(transitive)
+ Addedforeground-child@2.0.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfuri@1.3.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedhtml-escaper@2.0.2(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-fullwidth-code-point@2.0.0(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedistanbul-lib-coverage@2.0.5(transitive)
+ Addedistanbul-lib-report@2.0.8(transitive)
+ Addedistanbul-reports@2.2.7(transitive)
+ Addedjson-parse-better-errors@1.0.2(transitive)
+ Addedload-json-file@4.0.0(transitive)
+ Addedlocate-path@3.0.05.0.0(transitive)
+ Addedmake-dir@2.1.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@3.0.04.1.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedparse-json@4.0.0(transitive)
+ Addedpath-exists@3.0.04.0.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@3.0.0(transitive)
+ Addedpify@3.0.04.0.1(transitive)
+ Addedread-pkg@3.0.0(transitive)
+ Addedread-pkg-up@4.0.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@2.0.0(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedsource-map@0.7.4(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstring-width@3.1.0(transitive)
+ Addedstrip-ansi@5.2.0(transitive)
+ Addedstrip-bom@3.0.0(transitive)
+ Addedsupports-color@6.1.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtest-exclude@5.2.3(transitive)
+ Addedv8-to-istanbul@3.2.6(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwrap-ansi@5.1.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedy18n@4.0.3(transitive)
+ Addedyargs@14.2.3(transitive)
+ Addedyargs-parser@15.0.3(transitive)