mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-02 06:29:40 +08:00
Merge pull request #26241 from JounQin/feat/koa-static-cache
feat: add declaration file for koa-static-cache
This commit is contained in:
40
types/koa-static-cache/index.d.ts
vendored
Normal file
40
types/koa-static-cache/index.d.ts
vendored
Normal 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;
|
||||
46
types/koa-static-cache/koa-static-cache-tests.ts
Normal file
46
types/koa-static-cache/koa-static-cache-tests.ts
Normal 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
|
||||
)
|
||||
);
|
||||
23
types/koa-static-cache/tsconfig.json
Normal file
23
types/koa-static-cache/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/koa-static-cache/tslint.json
Normal file
1
types/koa-static-cache/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user