proxy-rotator-js 1.0.3 → 1.0.4

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.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "description": "Proxy Rotator",
6
6
  "main": "index.js",
@@ -18,12 +18,12 @@ class ProxyRotator {
18
18
  proxies.forEach( p => this._add(p) );
19
19
  }
20
20
  // handle options
21
- let { returnType, revive_timer, shuffle, protocol, assume_aliveness, check_on_next } = options;
21
+ let { proxyType, 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
+ // return type of proxy, either 'string' or 'object'
26
+ this.proxyType = _handleProxyTypeInput(proxyType);
27
27
  // assume a a protocol for all proxies
28
28
  this.protocol = protocol ?? null;
29
29
  // shuffle the proxies before adding them to the queue
@@ -113,7 +113,7 @@ class ProxyRotator {
113
113
  return this.setDead(proxy);
114
114
  }
115
115
 
116
- next(returnType='string'){
116
+ next(proxyType=null){
117
117
  // resurect a proxy from the graveyard
118
118
  if(this.check_on_next) _resurection();
119
119
  // if there are no proxies in the pool
@@ -123,11 +123,11 @@ class ProxyRotator {
123
123
  // add to back
124
124
  this.pool.enqueue(proxy);
125
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();
126
+ if(proxyType === null) proxyType = this.proxyType;
127
+ else proxyType = this._handleProxyTypeInput(proxyType);
128
+ // return proxy
129
+ if(proxyType === 'string') return proxy.proxy;
130
+ else if(this.returnType === 'object') return proxy.toObject();
131
131
  }
132
132
 
133
133
  /* Randomize array in-place using Durstenfeld shuffle algorithm */
@@ -141,6 +141,17 @@ class ProxyRotator {
141
141
  return array;
142
142
  }
143
143
 
144
+ _handleProxyTypeInput(proxyType){
145
+ proxyType = proxyType.toLowerCase();
146
+ if(proxyType === 'str') proxyType = 'string';
147
+ if(proxyType === 'obj') proxyType = 'object';
148
+ if(proxyType !== 'string' && proxyType !== 'object'){
149
+ console.error('proxyType must be either "string" or "object"');
150
+ proxyType = 'string';
151
+ }
152
+ return proxyType;
153
+ }
154
+
144
155
  _parseFile(filename) {
145
156
  // read file
146
157
  let str = fs.readFileSync(filename, 'utf8');