[proxy-addr] add typings

This commit is contained in:
Dimitri Benin 2017-08-15 08:53:43 +02:00
parent d4f42ab007
commit c3934de22b
4 changed files with 68 additions and 0 deletions

18
types/proxy-addr/index.d.ts vendored Normal file
View 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;
}

View 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);
});

View 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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }