Skip to content
This repository has been archived by the owner on Mar 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from tbhaxor/dev-filtering
Browse files Browse the repository at this point in the history
Filtering process added
  • Loading branch information
tbhaxor committed Sep 10, 2019
2 parents 697e396 + a8b9e51 commit 46ada9a
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 35 deletions.
105 changes: 81 additions & 24 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import proxify from "node-proxifyjs";
(async () => {
let data = await proxify(); // this will return
let data = await proxify(); // this will return all 300 proxies
console.log(data);
})();
```
Expand All @@ -34,38 +34,100 @@

## API

- **fetching `n` proxies**
### Filtering Parameters

pass an object property `count` to the function
- **Fetching `n` proxies**

pass an object property `count` to the function, only _number_

```ts
const proxify = require("node-proxifyjs");
import proxify from "node-proxifyjs";
(async () => {
let data = await proxify({ count: 20 }); // this will return first 20 proxies
console.log(data);
})();
```

- **returns**
* **Fetching `google` proxies**

pass an object property `google` to the function, only _boolean_

```ts
import proxify from "node-proxifyjs";
(async () => {
let data = await proxify({ google: true }); // pass google: false if you dont want google proxies
console.log(data);
})();
```
- **Fetching `https` proxies**
pass an object property `https` to the function, only _boolean_
```ts
interface ICountry {
code: string; // country code
name: string; // country name
}
interface IResult {
host: string; // the ip
port: number; // port numbeer
country: ICountry; // country from above interface
type: string; // type of proxy (elite, anonymous, transparent)
google: boolean; // is google
https: boolean; // is https ssl signed
lastChecked: string; // last checked for working
}
import proxify from "node-proxifyjs";
(async () => {
let data = await proxify({ https: true }); // pass https: false if you dont want https proxies
console.log(data);
})();
```
- **Fetching `country` specific proxies**
pass an object property `country` to the function, only `{code?: string, name?: Regrex String}`
**Note:** Either `code` or `name` will work, both of them at same time will not work
```ts
import proxify from "node-proxifyjs";
(async () => {
let data = await proxify({ country: { code: "US" } }); // pass the name property instead of code if you want to perform regexp search
console.log(data);
})();
```
- **Fetching proxies by `type`**
pass an object property `type` to the function, only _string_
```ts
import proxify from "node-proxifyjs";
(async () => {
let data = await proxify({ type: "elite proxy" }); // type can be either 'transparent', 'anonymous' or 'elite proxy' only
console.log(data);
})();
```
**Note:** None, one, some or all filtering predicates can be used at once
```ts
proxify({ count: 30, country: { code: "IN" }, type: "elite proxy" });
```
### Returns
```ts
interface ICountry {
code: string; // country code
name: string; // country name
}
interface IResult {
host: string; // the ip
port: number; // port numbeer
country: ICountry; // country from above interface
type: string; // type of proxy (elite, anonymous, transparent)
google: boolean; // is google
https: boolean; // is https ssl signed
lastChecked: string; // last checked for working
}
```
## Contribution
### Rules
Expand All @@ -76,11 +138,6 @@
### Scope
- Adding more filter
- filter by **country**
- filter by **https**
- filter by **google**
- filter by **type**
- Documentation
- Bugs / Suggestions / Feature Requests
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-proxifyjs",
"version": "1.1.0",
"version": "2.0.0",
"description": "Handy node.js package to find fresh and working proxies from https://free-proxy-list.net/",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
65 changes: 56 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,67 @@ export default function(filter: IFilter): Promise<IResult[]> {
// getting the output
let output: IResult[] = raw.map(format);

if (!filter) {
// check if no filter passed
if (!filter || Object.keys(filter).length == 0) {
// send all results
resolve(output);
}
// check if count is passed
else if (filter.count) {
// if requested for more than 300
if (filter.count > 300)
// reject the request
reject(new Error("Proxies limit can't exceed 300"));
console.log(1);
// check if https flag is set or not
if (filter.https !== undefined)
// filter out by the user input
output = output.filter(v => v.https == filter.https);

// check if google flag is set or not
if (filter.google !== undefined)
// filter out by the user input
output = output.filter(v => v.google == filter.google);

// check if country flag is set or not
if (filter.country !== undefined) {
// check if country sub flag is set or not
if (Object.keys(filter.country).length == 0)
// send the error
reject(new Error("Insufficient filter predicates"));
else {
// slice and send it
resolve(output.slice(0, filter.count));
// filter either by code
if (filter.country.code !== undefined) {
// filter out by the user input
output = output.filter(
v => v.country.code == filter.country.code
);
}
// or by name with regex
else if (filter.country.name !== undefined) {
// make the regexp
let r = new RegExp(filter.country.name, "i");
// filter out by the user input
output = output.filter(v => r.test(v.country.name));
}
}
}

// check if valid type passed
if (
["anonymous", "elite proxy", "transparent"].includes(filter.type)
) {
// filter out by the user input
output = output.filter(v => v.type == filter.type);
}

// check if count is passed
if (filter.count === undefined) {
// send previous
resolve(output);
}
// check if user wants more than 300
else if (filter.count > 300) {
// reject with the error
reject(new Error("Count of proxies can not exceed 300"));
} else {
// slice the proxy
output = output.slice(0, filter.count);
// send it <3
resolve(output);
}
});
Expand Down
9 changes: 9 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ export interface IResult {
lastChecked: string;
}

export interface IFilterCountry {
name?: string;
code?: string;
}

export interface IFilter {
count?: number;
https?: boolean;
google?: boolean;
country?: IFilterCountry;
type?: "anonymous" | "elite proxy" | "transparent";
}

0 comments on commit 46ada9a

Please sign in to comment.