diff --git a/types/fresh/fresh-tests.ts b/types/fresh/fresh-tests.ts new file mode 100644 index 0000000000..bc62065b07 --- /dev/null +++ b/types/fresh/fresh-tests.ts @@ -0,0 +1,28 @@ +/// +import fresh = require('fresh'); +import * as http from 'http'; + +let reqHeaders = { 'if-none-match': '"foo"' }; +let resHeaders = { etag: '"bar"' }; +// $ExpectType boolean +fresh(reqHeaders, resHeaders); + +const server = http.createServer((req, res) => { + if (isFresh(req, res)) { + res.statusCode = 304; + res.end(); + return; + } + + res.statusCode = 200; + res.end('hello, world!'); +}); + +function isFresh(req: http.IncomingMessage, res: http.ServerResponse) { + return fresh(req.headers, { + etag: res.getHeader('ETag'), + 'last-modified': res.getHeader('Last-Modified') + }); +} + +server.listen(3000); diff --git a/types/fresh/index.d.ts b/types/fresh/index.d.ts new file mode 100644 index 0000000000..e50e715388 --- /dev/null +++ b/types/fresh/index.d.ts @@ -0,0 +1,14 @@ +// Type definitions for fresh 0.5 +// Project: https://github.com/jshttp/fresh#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = fresh; + +declare function fresh(reqHeaders: fresh.Headers, resHeaders: fresh.Headers): boolean; + +declare namespace fresh { + interface Headers { + [header: string]: string | string[] | number | undefined; + } +} diff --git a/types/fresh/tsconfig.json b/types/fresh/tsconfig.json new file mode 100644 index 0000000000..94d14b21a5 --- /dev/null +++ b/types/fresh/tsconfig.json @@ -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", + "fresh-tests.ts" + ] +} diff --git a/types/fresh/tslint.json b/types/fresh/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/fresh/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }