Loosen too restrictive typings for path property, add missing ext property

This commit is contained in:
Michal Kaminski
2019-02-06 19:30:59 +01:00
parent ab0806bfb5
commit d4bda79c6c
2 changed files with 11 additions and 1 deletions

View File

@@ -9,3 +9,9 @@ var middleware: unless.RequestHandler = function(req, res, next) {
middleware.unless = unless;
app.use(middleware.unless({ method: "OPTIONS" }));
app.use(middleware.unless(req => req.path === "test"));
app.use(middleware.unless({ path: "/index", useOriginalUrl: true }));
app.use(middleware.unless({ path: /home/g, ext: ".jpg" }));
app.use(middleware.unless({ path: { url: "/index" }, ext: [ ".html", ".htm" ] }));
app.use(middleware.unless({ path: { url: "/index", methods: [ "GET", "POST" ] } }));
app.use(middleware.unless({ path: [ "/index", "/home", /home/i, { url: "/main", methods: [ "GET" ] }, { url: /home/i } ] }));

View File

@@ -2,6 +2,7 @@
// Project: https://www.npmjs.org/package/express-unless
// Definitions by: Wonshik Kim <https://github.com/wokim>
// Joao Vieira <https://github.com/joaovieira>
// Michal Kaminski <https://github.com/michal-b-kaminski>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -11,11 +12,14 @@ declare function unless(options: unless.Options): express.RequestHandler;
declare function unless(options: unless.Options["custom"]): express.RequestHandler;
declare namespace unless {
type pathFilter = string | RegExp | { url: string | RegExp, methods?: string[] };
export interface Options {
custom?: (req: express.Request) => boolean;
path?: string | string[];
path?: pathFilter | pathFilter[];
ext?: string | string[];
method?: string | string[];
useOriginalUrl?: boolean;
}
export interface RequestHandler extends express.RequestHandler {
unless?: typeof unless;