Socket
Socket
Sign inDemoInstall

loads

Package Overview
Dependencies
2
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.0 to 0.0.1

.npmignore

114

index.js
'use strict';
var response = require('xhr-response')
, one = require('one-time');
/**
* Simple nope function that assigned to XHR requests as part of a clean-up
* operation.
*
* @api private
*/
function nope() {}
/**
* Status codes that might need to be mapped to something more sane.

@@ -32,29 +43,92 @@ *

*/
module.exports = function loads(xhr, ee, streaming) {
var offset = 0;
function loads(xhr, ee, streaming) {
var onreadystatechange
, onprogress
, ontimeout
, onabort
, onerror
, onload;
function onreadystate(evt) {
var target = evt.target
, body = '';
/**
* Error listener.
*
* @param {Event} evt Triggered readyState change event.
* @api private
*/
onerror = xhr.onerror = one(function onerror(evt) {
ee.emit('error', new Error('Network request failed'));
ee.emit('end');
});
try { body = target.responseText; }
catch (e) {}
/**
* Fix for FireFox's odd abort handling behaviour. When you press ESC on an
* active request it triggers `error` instead of abort. The same is called
* when an HTTP request is canceled onunload.
*
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=768596
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=880200
* @see https://code.google.com/p/chromium/issues/detail?id=153570
*/
onabort = xhr.onabort = function onabort(evt) {
onerror(evt);
};
if (4 === target.readyState) {
if (xhr.multipart) ee.emit('streaming', body);
else if (!streaming) ee.emit('data', body);
} else if (streaming && target.re)
}
/**
* ReadyStateChange listener.
*
* @param {Event} evt Triggered readyState change event.
* @api private
*/
onreadystatechange = xhr.onreadystatechange = function change(evt) {
var target = evt.target;
function onprogress(evt) {
if (4 === target.readyState) return onload(evt);
};
}
/**
* The connection has timed out.
*
* @api private
*/
ontimeout = xhr.ontimeout = function timeout(evt) {
ee.emit('timeout', evt);
};
function onload(evt) {
/**
* IE needs have it's `onprogress` function assigned to a unique function. So,
* no touchy touchy here!
*
* @param {Event} evt Triggered progress event.
* @api private
*/
onprogress = xhr.onprogress = function progress(evt) {
var status = codes[xhr.status] || xhr.status
, data;
}
ee.emit('progress', evt, status);
xhr.onreadystatechange = onreadystate;
xhr.onprogress = onprogress;
xhr.onload = onload;
};
if (xhr.readyState >= 3 && status === 200 && (data = response(xhr))) {
ee.emit('stream', data);
}
};
/**
*
* @param {Event} evt Triggered progress event.
* @api private
*/
onload = xhr.onload = one(function load(evt) {
var status = codes[xhr.status] || xhr.status
, data = response(xhr);
if (status < 100 || status > 599) return onerror(evt);
if (data) ee.emit('stream', data);
ee.emit('end');
});
}
//
// Expose all the things.
//
module.exports = loads;

8

package.json
{
"name": "loads",
"version": "0.0.0",
"version": "0.0.1",
"description": "Dedicated listening for xhr requests.",

@@ -25,3 +25,7 @@ "main": "index.js",

},
"homepage": "https://github.com/unshiftio/loads"
"homepage": "https://github.com/unshiftio/loads",
"dependencies": {
"one-time": "0.0.x",
"xhr-response": "1.0.x"
}
}
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