diff --git a/types/proxy-lists/index.d.ts b/types/proxy-lists/index.d.ts new file mode 100644 index 0000000000..c0b223bb60 --- /dev/null +++ b/types/proxy-lists/index.d.ts @@ -0,0 +1,70 @@ +// Type definitions for proxy-lists 1.14 +// Project: https://github.com/chill117/proxy-lists#readme +// Definitions by: 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): 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; +} diff --git a/types/proxy-lists/proxy-lists-tests.ts b/types/proxy-lists/proxy-lists-tests.ts new file mode 100644 index 0000000000..132aa431e4 --- /dev/null +++ b/types/proxy-lists/proxy-lists-tests.ts @@ -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)); diff --git a/types/proxy-lists/tsconfig.json b/types/proxy-lists/tsconfig.json new file mode 100644 index 0000000000..b632be67c9 --- /dev/null +++ b/types/proxy-lists/tsconfig.json @@ -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" + ] +} diff --git a/types/proxy-lists/tslint.json b/types/proxy-lists/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/proxy-lists/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }