Merge pull request #26241 from JounQin/feat/koa-static-cache

feat: add declaration file for koa-static-cache
This commit is contained in:
Armando Aguirre
2018-06-05 14:33:33 -07:00
committed by GitHub
4 changed files with 110 additions and 0 deletions

40
types/koa-static-cache/index.d.ts vendored Normal file
View File

@@ -0,0 +1,40 @@
// Type definitions for koa-static-cache 5.1
// Project: https://github.com/koajs/static-cache#readme
// Definitions by: JounQin <https://github.com/JounQin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/**
* Static server for koa.
*/
import { Middleware } from 'koa';
declare namespace staticCache {
interface Files {
[path: string]: Options;
}
interface Options {
dir?: string;
maxAge?: number;
cacheControl?: string;
buffer?: boolean;
gzip?: boolean;
usePrecompiledGzip?: boolean;
alias?: {};
prefix?: string;
dynamic?: boolean;
filter?: ((path: string) => boolean) | string[];
preload?: boolean;
files?: Files;
}
}
declare function staticCache(
dir: string | staticCache.Options,
options?: staticCache.Options | staticCache.Files,
files?: staticCache.Files
): Middleware;
export = staticCache;

View File

@@ -0,0 +1,46 @@
import Koa = require('koa');
import staticCache = require('koa-static-cache');
const app = new Koa();
app.use(staticCache('.'));
app.use(
staticCache('.', {
maxAge: 0,
filter: ['']
})
);
const files: staticCache.Files = {};
app.use(
staticCache(
'.',
{
maxAge: 0,
filter: path => !!path
},
files
)
);
files['/service-worker.js'].maxAge = 0;
app.use(
staticCache({
dir: '.',
maxAge: 0,
files
})
);
app.use(
staticCache(
{
dir: '.',
maxAge: 0
},
files
)
);

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"koa-static-cache-tests.ts"
]
}

View File

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