mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[fresh] add typings (#18990)
This commit is contained in:
parent
62cadd0386
commit
8db0c98591
28
types/fresh/fresh-tests.ts
Normal file
28
types/fresh/fresh-tests.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/// <reference types="node" />
|
||||
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);
|
||||
14
types/fresh/index.d.ts
vendored
Normal file
14
types/fresh/index.d.ts
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
// Type definitions for fresh 0.5
|
||||
// Project: https://github.com/jshttp/fresh#readme
|
||||
// Definitions by: BendingBender <https://github.com/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;
|
||||
}
|
||||
}
|
||||
22
types/fresh/tsconfig.json
Normal file
22
types/fresh/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",
|
||||
"fresh-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/fresh/tslint.json
Normal file
1
types/fresh/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user