mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
[proxy-addr] add typings
This commit is contained in:
parent
d4f42ab007
commit
c3934de22b
18
types/proxy-addr/index.d.ts
vendored
Normal file
18
types/proxy-addr/index.d.ts
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
// Type definitions for proxy-addr 2.0
|
||||
// Project: https://github.com/jshttp/proxy-addr#readme
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
import { IncomingMessage } from 'http';
|
||||
|
||||
export = proxyAddr;
|
||||
|
||||
declare function proxyAddr(req: IncomingMessage, trust: proxyAddr.Address | proxyAddr.Address[] | ((addr: string, i: number) => boolean)): string;
|
||||
|
||||
declare namespace proxyAddr {
|
||||
function all(req: IncomingMessage, trust?: Address | Address[] | ((addr: string, i: number) => boolean)): string[];
|
||||
function compile(val: Address | Address[]): (addr: string, i: number) => boolean;
|
||||
|
||||
type Address = 'loopback' | 'linklocal' | 'uniquelocal' | string;
|
||||
}
|
||||
27
types/proxy-addr/proxy-addr-tests.ts
Normal file
27
types/proxy-addr/proxy-addr-tests.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import proxyaddr = require('proxy-addr');
|
||||
import { createServer } from 'http';
|
||||
|
||||
createServer(req => {
|
||||
// $ExpectType string
|
||||
proxyaddr(req, addr => addr === '127.0.0.1');
|
||||
proxyaddr(req, (addr, i) => i < 1);
|
||||
|
||||
proxyaddr(req, '127.0.0.1');
|
||||
proxyaddr(req, ['127.0.0.0/8', '10.0.0.0/8']);
|
||||
proxyaddr(req, ['127.0.0.0/255.0.0.0', '192.168.0.0/255.255.0.0']);
|
||||
|
||||
proxyaddr(req, '::1');
|
||||
proxyaddr(req, ['::1/128', 'fe80::/10']);
|
||||
|
||||
proxyaddr(req, 'loopback');
|
||||
proxyaddr(req, ['loopback', 'fc00:ac:1ab5:fff::1/64']);
|
||||
|
||||
// $ExpectType string[]
|
||||
proxyaddr.all(req);
|
||||
proxyaddr.all(req, 'loopback');
|
||||
|
||||
const trust = proxyaddr.compile('localhost');
|
||||
proxyaddr.compile(['localhost']);
|
||||
trust; // $ExpectType (addr: string, i: number) => boolean
|
||||
proxyaddr(req, trust);
|
||||
});
|
||||
22
types/proxy-addr/tsconfig.json
Normal file
22
types/proxy-addr/tsconfig.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"proxy-addr-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/proxy-addr/tslint.json
Normal file
1
types/proxy-addr/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user