Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nise

Package Overview
Dependencies
Maintainers
4
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nise - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

12

lib/fake-server/index.js

@@ -9,2 +9,4 @@ "use strict";

var supportsArrayBuffer = typeof ArrayBuffer !== "undefined";
function responseArray(handler) {

@@ -18,4 +20,10 @@ var response = handler;

if (typeof response[2] !== "string") {
throw new TypeError("Fake server response body should be string, but was " +
typeof response[2]);
if (!supportsArrayBuffer) {
throw new TypeError("Fake server response body should be a string, but was " +
typeof response[2]);
}
else if (!(response[2] instanceof ArrayBuffer)) {
throw new TypeError("Fake server response body should be a string or ArrayBuffer, but was " +
typeof response[2]);
}
}

@@ -22,0 +30,0 @@

@@ -227,7 +227,21 @@ "use strict";

function verifyResponseBodyType(body) {
if (typeof body !== "string") {
var error = new Error("Attempted to respond to fake XMLHttpRequest with " +
body + ", which is not a string.");
function verifyResponseBodyType(body, responseType) {
var error = null;
var isString = typeof body === "string";
if (responseType === "arraybuffer") {
if (!isString && !(body instanceof ArrayBuffer)) {
error = new Error("Attempted to respond to fake XMLHttpRequest with " +
body + ", which is not a string or ArrayBuffer.");
error.name = "InvalidBodyException";
}
}
else if (!isString) {
error = new Error("Attempted to respond to fake XMLHttpRequest with " +
body + ", which is not a string.");
error.name = "InvalidBodyException";
}
if (error) {
throw error;

@@ -238,2 +252,6 @@ }

function convertToArrayBuffer(body, encoding) {
if (body instanceof ArrayBuffer) {
return body;
}
return new TextEncoder(encoding || "utf-8").encode(body).buffer;

@@ -581,3 +599,3 @@ }

verifyHeadersReceived(this);
verifyResponseBodyType(body);
verifyResponseBodyType(body, this.responseType);
var contentType = this.overriddenMimeType || this.getResponseHeader("Content-Type");

@@ -584,0 +602,0 @@

7

package.json
{
"name": "nise",
"version": "1.1.1",
"version": "1.2.0",
"description": "Fake XHR and server",

@@ -40,3 +40,4 @@ "keywords": [

"globals": {
"ArrayBuffer": false
"ArrayBuffer": false,
"Uint8Array": false
},

@@ -75,3 +76,3 @@ "env": {

"formatio": "^1.2.0",
"just-extend": "^1.1.22",
"just-extend": "^1.1.26",
"lolex": "^1.6.0",

@@ -78,0 +79,0 @@ "path-to-regexp": "^1.7.0",

@@ -47,3 +47,3 @@ # nise (偽) [![npm version](https://img.shields.io/npm/v/nise.svg?style=flat)](https://www.npmjs.com/package/nise) [![Build Status](https://travis-ci.org/sinonjs/nise.svg?branch=master)](https://travis-ci.org/sinonjs/nise)

#### var xhr = fakeXhr.useFakeXMLHttpRequest();"
#### var xhr = fakeXhr.useFakeXMLHttpRequest();

@@ -159,3 +159,3 @@ Causes fakeXhr to replace the native `XMLHttpRequest` object in browsers that support it with a custom implementation which does not send actual requests.

#### `request.setStatus(status);``
#### `request.setStatus(status);`

@@ -166,3 +166,3 @@ Sets response status (`status` and `statusText` properties).

#### `request.setResponseHeaders(object);``
#### `request.setResponseHeaders(object);`

@@ -179,3 +179,3 @@ Sets response headers (e.g. `{ "Content-Type": "text/html", /* ... */ }`, updates the `readyState` property and fires `onreadystatechange`.

#### `request.respond(status, headers, body);``
#### `request.respond(status, headers, body);`

@@ -236,3 +236,3 @@ Calls the above three methods.

#### `var server = fakeServer.create([config]);``
#### `var server = fakeServer.create([config]);`

@@ -265,3 +265,3 @@ Creates a new server.

1. A `String` representing the response body
1. A `String` or `ArrayBuffer` representing the response body
2. An `Array` with status, headers and response body, e.g. `[200, { "Content-Type": "text/html", "Content-Length": 2 }, "OK"]`

@@ -318,3 +318,3 @@ 3. A `Function`.

#### `server.autoRespond = true;`
`
If set, will automatically respond to every request after a timeout.

@@ -321,0 +321,0 @@

Sorry, the diff of this file is too big to display

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