From e5ae20b1b6533ee751adbfc13d5dbd7aa075bbce Mon Sep 17 00:00:00 2001 From: Anthony Dionise Date: Tue, 29 Jan 2019 16:53:12 -0500 Subject: [PATCH] include esclusions typings --- .../connect-history-api-fallback-tests.ts | 63 +++++++++++++++++++ .../index.d.ts | 36 +++++++++++ .../tsconfig.json | 23 +++++++ .../tslint.json | 1 + 4 files changed, 123 insertions(+) create mode 100644 types/connect-history-api-fallback-exclusions/connect-history-api-fallback-tests.ts create mode 100644 types/connect-history-api-fallback-exclusions/index.d.ts create mode 100644 types/connect-history-api-fallback-exclusions/tsconfig.json create mode 100644 types/connect-history-api-fallback-exclusions/tslint.json diff --git a/types/connect-history-api-fallback-exclusions/connect-history-api-fallback-tests.ts b/types/connect-history-api-fallback-exclusions/connect-history-api-fallback-tests.ts new file mode 100644 index 0000000000..33fae5bde4 --- /dev/null +++ b/types/connect-history-api-fallback-exclusions/connect-history-api-fallback-tests.ts @@ -0,0 +1,63 @@ +import historyApiFallback = require('connect-history-api-fallback-exclusions'); +import express = require('express'); + +const app = express(); +app.use(historyApiFallback()); + +historyApiFallback({ + verbose: true +}); + +historyApiFallback({ + logger: console.log.bind(console) +}); + +historyApiFallback({ + rewrites: [ + { from: /\/soccer/, to: '/soccer.html' } + ] +}); + +historyApiFallback({ + index: 'default.html' +}); + +historyApiFallback({ + htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'] +}); + +historyApiFallback({ + rewrites: [ + { + from: /^\/libs\/(.*)$/, + to(context) { + return './bower_components' + context.parsedUrl.pathname; + } + } + ] +}); + +historyApiFallback({ + rewrites: [ + { + from: /\/app\/login/, + to: function onMatch(ctx) { + if (ctx.parsedUrl.path && ctx.parsedUrl.path.indexOf('.js')) { + return ctx.parsedUrl.href || ''; + } + return '/app/login/index.html'; + } + } + ] +}); + +historyApiFallback({ + rewrites: [ + { + from: /^\/libs\/(.*)$/, + to(context) { + return `/${context.match[2]}/${context.match[3]}`; + } + } + ] +}); diff --git a/types/connect-history-api-fallback-exclusions/index.d.ts b/types/connect-history-api-fallback-exclusions/index.d.ts new file mode 100644 index 0000000000..19a48e0bab --- /dev/null +++ b/types/connect-history-api-fallback-exclusions/index.d.ts @@ -0,0 +1,36 @@ +// Type definitions for connect-history-api-fallback-exclusions 1.5.1 +// Project: https://github.com/Wirewheel/connect-history-api-fallback#readme +// Definitions by: Tony Stone +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +/// + +import { Url } from 'url'; + +import * as core from "express-serve-static-core"; + +declare function historyApiFallback(options?: Options): core.RequestHandler; +declare namespace historyApiFallback {} +export = historyApiFallback; + +interface Options { + exclusions?: string[]; + disableDotRule?: true; + htmlAcceptHeaders?: string[]; + index?: string; + logger?: typeof console.log; + rewrites?: Rewrite[]; + verbose?: boolean; +} + +interface Context { + match: RegExpMatchArray; + parsedUrl: Url; +} +type RewriteTo = (context: Context) => string; + +interface Rewrite { + from: RegExp; + to: string | RegExp | RewriteTo; +} diff --git a/types/connect-history-api-fallback-exclusions/tsconfig.json b/types/connect-history-api-fallback-exclusions/tsconfig.json new file mode 100644 index 0000000000..ad8919e94e --- /dev/null +++ b/types/connect-history-api-fallback-exclusions/tsconfig.json @@ -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", + "connect-history-api-fallback-tests.ts" + ] +} \ No newline at end of file diff --git a/types/connect-history-api-fallback-exclusions/tslint.json b/types/connect-history-api-fallback-exclusions/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/connect-history-api-fallback-exclusions/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }