proxy-rotator-js 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proxy-rotator-js",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "description": "Proxy Rotator",
6
6
  "main": "index.js",
@@ -18,10 +18,12 @@ class ProxyRotator {
18
18
  proxies.forEach( p => this._add(p) );
19
19
  }
20
20
  // handle options
21
- let { revive_timer, shuffle, protocol, assume_aliveness, check_on_next } = options;
21
+ let { returnType, revive_timer, shuffle, protocol, assume_aliveness, check_on_next } = options;
22
22
  // how long to wait before reviving a dead proxy
23
23
  // default: 30 minutes
24
24
  this.revive_timer = revive_timer ?? 1000 * 60 * 30;
25
+ // return type of proxy
26
+ this.returnType = returnType ?? 'string'; // or 'object'
25
27
  // assume a a protocol for all proxies
26
28
  this.protocol = protocol ?? null;
27
29
  // shuffle the proxies before adding them to the queue
@@ -111,7 +113,7 @@ class ProxyRotator {
111
113
  return this.setDead(proxy);
112
114
  }
113
115
 
114
- next(){
116
+ next(returnType='string'){
115
117
  // resurect a proxy from the graveyard
116
118
  if(this.check_on_next) _resurection();
117
119
  // if there are no proxies in the pool
@@ -120,8 +122,12 @@ class ProxyRotator {
120
122
  let proxy = this.pool.dequeue();
121
123
  // add to back
122
124
  this.pool.enqueue(proxy);
123
- // return
124
- return proxy
125
+ // if returnType is 'string'
126
+ if(this.returnType === 'string')
127
+ // return proxy as string
128
+ return proxy.proxy;
129
+ else if(this.returnType === 'object')
130
+ return proxy.toObject();
125
131
  }
126
132
 
127
133
  /* Randomize array in-place using Durstenfeld shuffle algorithm */