mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-13 08:57:26 +08:00
[proxy-lists] Add types for proxy-lists (#25267)
* [proxy-lists] Add types for proxy-lists * Change minimum TS version These definitions depends on request, which has a minimum TS version of 2.3. * Refactor static class and namespace to plain ES6 exports
This commit is contained in:
committed by
Wesley Wigham
parent
e178d12a21
commit
39d211b878
70
types/proxy-lists/index.d.ts
vendored
Normal file
70
types/proxy-lists/index.d.ts
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
// Type definitions for proxy-lists 1.14
|
||||
// Project: https://github.com/chill117/proxy-lists#readme
|
||||
// Definitions by: BehindTheMath <https://github.com/BehindTheMath>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
import { CoreOptions as RequestOptions } from "request";
|
||||
import { EventEmitter } from "events";
|
||||
|
||||
export function getProxies(options?: Partial<Options>): GetProxiesEventEmitter;
|
||||
|
||||
export function getProxiesFromSource(name: string, options?: Options): GetProxiesEventEmitter;
|
||||
|
||||
export function addSource(name: string, source: AddSource): void;
|
||||
|
||||
export function listSources(options?: ListSourcesOptions): Source[];
|
||||
|
||||
export class GetProxiesEventEmitter extends EventEmitter {
|
||||
on(event: "data", listener: (proxies: Proxy[]) => void): this;
|
||||
on(event: "error", listener: (error: any) => void): this;
|
||||
on(event: "end", listener: () => void): this;
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
filterMode?: "strict" | "loose";
|
||||
countries?: string[];
|
||||
countriesBlackList?: string[];
|
||||
protocols?: Protocol[];
|
||||
anonymityLevels?: AnonymityLevel[];
|
||||
sourcesWhiteList?: string[];
|
||||
sourcesBlackList?: string[];
|
||||
series?: boolean;
|
||||
ipTypes?: IPType[];
|
||||
defaultRequestOptions?: RequestOptions;
|
||||
}
|
||||
|
||||
export type Protocol = "http" | "https" | "socks5" | "socks4";
|
||||
|
||||
export type AnonymityLevel = "transparent" | "anonymous" | "elite";
|
||||
|
||||
export type IPType = "ipv4" | "ipv6";
|
||||
|
||||
export interface Proxy {
|
||||
ipAddress: string;
|
||||
port: number;
|
||||
country: string;
|
||||
anonymityLevel?: AnonymityLevel;
|
||||
protocols?: Protocol[];
|
||||
source: string;
|
||||
tunnel?: boolean;
|
||||
}
|
||||
|
||||
export interface InternalOptions extends Options {
|
||||
sample?: boolean;
|
||||
}
|
||||
|
||||
export interface AddSource {
|
||||
homeUrl: string;
|
||||
getProxies(options: InternalOptions): GetProxiesEventEmitter;
|
||||
}
|
||||
|
||||
export interface ListSourcesOptions {
|
||||
sourcesWhiteList?: string[];
|
||||
sourcesBlackList?: string[];
|
||||
}
|
||||
|
||||
export interface Source {
|
||||
name: string;
|
||||
homeUrl: string;
|
||||
}
|
||||
55
types/proxy-lists/proxy-lists-tests.ts
Normal file
55
types/proxy-lists/proxy-lists-tests.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import * as ProxyLists from "proxy-lists";
|
||||
import { EventEmitter } from "events";
|
||||
|
||||
const options: ProxyLists.Options = {
|
||||
filterMode: 'strict',
|
||||
countries: ['us', 'ca'],
|
||||
countriesBlackList: ['de', 'gb'],
|
||||
protocols: ['http', 'https'],
|
||||
anonymityLevels: ['anonymous', 'elite'],
|
||||
sourcesWhiteList: ['freeproxylists'],
|
||||
sourcesBlackList: ['freeproxylists'],
|
||||
series: false,
|
||||
ipTypes: ['ipv4'],
|
||||
defaultRequestOptions: {
|
||||
method: "GET"
|
||||
}
|
||||
};
|
||||
|
||||
// `gettingProxies` is an event emitter object.
|
||||
let gettingProxies: ProxyLists.GetProxiesEventEmitter = ProxyLists.getProxies(options);
|
||||
|
||||
gettingProxies.on('data', proxies => {
|
||||
// Received some proxies.
|
||||
});
|
||||
|
||||
gettingProxies.on('error', error => {
|
||||
// Some error has occurred.
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
gettingProxies.once('end', () => {
|
||||
// Done getting proxies.
|
||||
});
|
||||
|
||||
gettingProxies = ProxyLists.getProxiesFromSource('freeproxylists', options);
|
||||
|
||||
gettingProxies.on('data', proxies => {
|
||||
// Received some proxies.
|
||||
});
|
||||
|
||||
const source: ProxyLists.AddSource = {
|
||||
homeUrl: 'www.example.com',
|
||||
getProxies: (options: ProxyLists.InternalOptions) => {
|
||||
return new EventEmitter();
|
||||
}
|
||||
};
|
||||
|
||||
ProxyLists.addSource('testSource', source);
|
||||
|
||||
const listSourcesOptions: ProxyLists.ListSourcesOptions = {
|
||||
sourcesWhiteList: ['freeproxylists'],
|
||||
sourcesBlackList: ['freeproxylists']
|
||||
};
|
||||
|
||||
ProxyLists.listSources(listSourcesOptions).forEach(source => console.log(source.name, source.homeUrl));
|
||||
23
types/proxy-lists/tsconfig.json
Normal file
23
types/proxy-lists/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strictFunctionTypes": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"proxy-lists-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/proxy-lists/tslint.json
Normal file
1
types/proxy-lists/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user