Socket
Socket
Sign inDemoInstall

limited-request-queue

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

limited-request-queue - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

lib/defaultOptions.js

60

lib/getHostKey.js
"use strict";
var isBrowser = require("is-browser");
var parseDomain,parseUrl;
var isString = require("is-string");
var parseDomain,URL;

@@ -10,3 +11,3 @@

parseDomain = function(){ return null };
parseUrl = require("url-parse");
URL = window.URL;
}

@@ -16,3 +17,3 @@ else

parseDomain = require("parse-domain");
parseUrl = require("url").parse;
URL = require("whatwg-url").URL;
}

@@ -24,18 +25,19 @@

{
var domainObj,port,protocol,urlObj;
var key = "";
var key,port,protocol,urlDomain;
if (typeof url==="string" || url instanceof String===true)
if (isString(url) === true)
{
urlObj = parseUrl(url);
try
{
url = new URL(url);
}
catch (error)
{
return false;
}
}
else
{
urlObj = url;
}
protocol = urlObj.protocol;
protocol = url.protocol;
// Not using strict equals because `urlObj` might be a foreign object type
if (!protocol || !urlObj.hostname)
if (isEmptyString(protocol)===true || isEmptyString(url.hostname)===true)
{

@@ -51,6 +53,6 @@ return false;

port = urlObj.port;
port = url.port;
// Get default port
if (port==null && options.defaultPorts[protocol]!==undefined)
if (isEmptyStringOrNumber(port)===true && options.defaultPorts[protocol]!==undefined)
{

@@ -60,2 +62,4 @@ port = options.defaultPorts[protocol];

key = "";
if (options.ignoreSchemes === false)

@@ -68,17 +72,17 @@ {

{
key += urlObj.hostname;
key += url.hostname;
}
else
{
domainObj = parseDomain(urlObj.hostname);
urlDomain = parseDomain(url.hostname);
// If unknown top-level-domain (.com, etc)
// Or, if running in a browser
if (domainObj === null)
if (urlDomain === null)
{
key += urlObj.hostname;
key += url.hostname;
}
else
{
key += domainObj.domain + "." + domainObj.tld;
key += urlDomain.domain + "." + urlDomain.tld;
}

@@ -99,2 +103,16 @@ }

function isEmptyString(value)
{
return value==="" || value==null || isString(value)===false;
}
function isEmptyStringOrNumber(value)
{
return value==="" || value==null || isNaN(value)===true;
}
module.exports = getHostKey;
"use strict";
var defaultOptions = require("./defaultOptions");
var getHostKey = require("./getHostKey");
var defaultOptions =
{
defaultPorts: {ftp:21, http:80, https:443},
ignorePorts: true,
ignoreSchemes: true,
ignoreSubdomains: true,
maxSockets: Infinity,
maxSocketsPerHost: 1,
rateLimit: 0
};
var isString = require("is-string");

@@ -55,3 +47,3 @@

// enqueue("url")
if (typeof input==="string" || input instanceof String===true)
if (isString(input) === true)
{

@@ -164,3 +156,3 @@ input = { url:input };

{
return new Error("Invalid URI");
return new TypeError("Invalid URL");
}

@@ -167,0 +159,0 @@

{
"name": "limited-request-queue",
"description": "Interactively manage concurrency for outgoing requests.",
"version": "2.0.0",
"description": "Interactively manage concurrency for outbound requests.",
"version": "3.0.0",
"license": "MIT",

@@ -22,22 +22,28 @@ "homepage": "https://github.com/stevenvachon/limited-request-queue",

"is-browser": "^2.0.1",
"parse-domain": "~0.2.0"
"is-string": "^1.0.4",
"parse-domain": "~0.2.1",
"whatwg-url": "^3.0.0"
},
"devDependencies": {
"browserify": "^12.0.1",
"chai": "^3.4.1",
"mocha": "^2.3.4",
"mocha-phantomjs": "4.0.1",
"object.assign": "^4.0.3",
"phantomjs": "1.9.19",
"uglify-js": "^2.6.1",
"url-parse": "^1.0.5"
"browserify": "^13.1.0",
"chai": "^3.5.0",
"mocha": "^3.0.1",
"mocha-phantomjs": "4.1.0",
"napa": "^2.3.0",
"object.assign": "^4.0.4",
"phantomjs-prebuilt": "^2.1.10",
"uglify-js": "^2.7.0"
},
"napa": {
"url-polyfill": "git+https://github.com/annevk/url.git"
},
"engines": {
"node": ">= 0.10"
"node": ">= 4"
},
"scripts": {
"browserify": "browserify lib/ --exclude parse-domain --exclude url --standalone RequestQueue | uglifyjs --compress --mangle -o browser/requestqueue.js",
"browserify": "browserify lib/ --exclude parse-domain --exclude whatwg-url --standalone RequestQueue | uglifyjs --compress --mangle -o browser/requestqueue.js",
"install": "napa",
"test": "npm run test_server && npm run test_browser",
"test_browser": "npm run browserify && mocha-phantomjs test/browser.html",
"test_server": "mocha test/server/ --reporter spec --check-leaks --bail",
"test": "npm run test_server && npm run test_browser"
"test_server": "mocha test/server/ --reporter spec --check-leaks --bail"
},

@@ -44,0 +50,0 @@ "files": [

@@ -7,5 +7,5 @@ # limited-request-queue [![NPM Version][npm-image]][npm-url] [![Bower Version][bower-image]][bower-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][david-image]][david-url]

* Concurrency & rate limiting prevents overload on your server
* Per-Host concurrency limiting prevents overload on everyone else's server
* Per-Host concurrency limiting prevents overload on everyone else's servers
* Pause/Resume at any time
* Works in the browser (~6.5KB)
* Works in the browser (~4.2KB not gzipped)

@@ -38,8 +38,10 @@ ```js

[Node.js](http://nodejs.org/) `>= 0.10` is required; `< 4.0` will need an `Object.assign` polyfill. To install, type this at the command line:
[Node.js](http://nodejs.org/) `>= 4` is required. To install, type this at the command line:
```shell
npm install limited-request-queue --save-dev
npm install limited-request-queue
```
Note: for use in a web browser, you will likely need [`Object.assign`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) and [`URL`](https://developer.mozilla.org/en/docs/Web/API/URL/URL) polyfills for maximum coverage.
## Constructor

@@ -53,6 +55,6 @@ ```js

### .dequeue(id)
### `.dequeue(id)`
Removes a queue item from the queue. Use of this function is likely not needed as items are auto-dequeued when their turn is reached. Returns `true` on success or an `Error` on failure.
### .enqueue(input)
### `.enqueue(input)`
Adds a URL to the queue. `input` can either be a URL `String` or an `Object`. Returns a queue ID on success or an `Error` on failure.

@@ -62,19 +64,19 @@

* `url`: a URL `String` or [`url.parse()`](https://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost)-compatible `Object`.
* `url`: a URL `String` or [`URL`](https://developer.mozilla.org/en/docs/Web/API/URL/)-compatible `Object`.
* `data`: additional data to be stored in the queue item.
* `id`: a unique ID (`String` or `Number`). If not defined, one will be generated.
### .length()
Returns the total number of items in the queue, active and non-active.
### `.length()`
Returns the total number of items in the queue, active and inactive.
### .numActive()
### `.numActive()`
Returns the number of items whose requests are currently in progress.
### .numQueued()
### `.numQueued()`
Returns the number of items that have not yet made requests.
### .pause()
### `.pause()`
Pauses the queue, but will not pause any active requests.
### .resume()
### `.resume()`
Resumes the queue.

@@ -85,3 +87,3 @@

### options.ignorePorts
### `options.ignorePorts`
Type: `Boolean`

@@ -91,3 +93,3 @@ Default value: `true`

### options.ignoreSchemes
### `options.ignoreSchemes`
Type: `Boolean`

@@ -97,3 +99,3 @@ Default value: `true`

### options.ignoreSubdomains
### `options.ignoreSubdomains`
Type: `Boolean`

@@ -105,3 +107,3 @@ Default value: `true`

### options.maxSockets
### `options.maxSockets`
Type: `Number`

@@ -111,3 +113,3 @@ Default value: `Infinity`

### options.maxSocketsPerHost
### `options.maxSocketsPerHost`
Type: `Number`

@@ -117,3 +119,3 @@ Default value: `1`

### options.rateLimit
### `options.rateLimit`
Type: `Number`

@@ -126,6 +128,6 @@ Default value: `0`

### handlers.end
### `handlers.end`
Called when the last item in the queue has been completed.
### handlers.item
### `handlers.item`
Called when a queue item's turn has been reached. Arguments are: `input`, `done`.

@@ -132,0 +134,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