From 084b629ffdaeee8ef947db433aebb862a9011fbe Mon Sep 17 00:00:00 2001 From: Mister 4 Eyes Date: Thu, 14 Dec 2017 10:56:37 -0500 Subject: [PATCH] Adds express flash notification definitions. --- .../express-flash-notification-tests.ts | 57 +++++++++++++++++++ types/express-flash-notification/index.d.ts | 39 +++++++++++++ .../express-flash-notification/tsconfig.json | 23 ++++++++ types/express-flash-notification/tslint.json | 1 + 4 files changed, 120 insertions(+) create mode 100644 types/express-flash-notification/express-flash-notification-tests.ts create mode 100644 types/express-flash-notification/index.d.ts create mode 100644 types/express-flash-notification/tsconfig.json create mode 100644 types/express-flash-notification/tslint.json diff --git a/types/express-flash-notification/express-flash-notification-tests.ts b/types/express-flash-notification/express-flash-notification-tests.ts new file mode 100644 index 0000000000..d5f5f3151f --- /dev/null +++ b/types/express-flash-notification/express-flash-notification-tests.ts @@ -0,0 +1,57 @@ +import * as express from "express"; +import * as flash from "express-flash-notification"; + +const app = express(); + +// Simple initialization test +app.use(flash(app)); + +// Incomplete object test +app.use(flash(app, { + sessionName: "to-flash", + utilityName: "||", + localsName: "!to-flash" +})); + +// Empty object test +app.use(flash(app, {})); + +// Functions test +app.use(flash(app, { + beforeSingleRender: (item, callback) => { callback(null, item); }, + afterAllRender: (htmlFragments, callback) => { callback(null, htmlFragments.join("\n")); } +})); + +// Full object test +app.use(flash(app, { + sessionName: "flash", + utilityName: "flash", + localsName: "flash", + viewName: "flash", + beforeSingleRender: (item, callback) => { callback(null, item); }, + afterAllRender: (htmlFragments, callback) => { callback(null, htmlFragments.join("\n")); } + })); + +app.use((req: express.Request, res: express.Response, next: express.NextFunction) => { + req.flash("info"); + req.flash("info", "I am a pretty butterfly"); + req.flash("info", "I am a pretty butterfly", "/"); + req.flash("info", "I am a pretty butterfly", true); + req.flash({ + type: "error", + message: "Lets mix things up, shall we?" + }); + + req.flash({ + type: "info", + message: "if cats rules the world", + redirect: false + }); + + req.flash({ + type: "success", + message: "Odd", + redirect: true, + url: "/" + }); +}); diff --git a/types/express-flash-notification/index.d.ts b/types/express-flash-notification/index.d.ts new file mode 100644 index 0000000000..7c9fdff97e --- /dev/null +++ b/types/express-flash-notification/index.d.ts @@ -0,0 +1,39 @@ +// Type definitions for express-flash-notification 0.5 +// Project: https://github.com/carlosascari/express-flash-notification +// Definitions by: Mister4Eyes +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.6 + +import * as express from "express"; + +interface efnOptions { + sessionName?: string; + utilityName?: string; + localsName?: string; + viewName?: string; + beforeSingleRender?: (item: any, callback: (err: any, item: any) => void) => void; + afterAllRender?: (htmlFragments: string[], callback: (err: any, html: string) => void) => void; +} + +declare function express_flash_notification(app: express.Application, options?: efnOptions, ...args: any[]): any; + +declare namespace express_flash_notification { + const prototype: {}; +} + +declare global { + namespace Express { + interface FlashOptions { + type?: string; + message?: string; + redirect?: boolean; + url?: string; + } + interface Request { + flash(type: string, message?: string, redirect?: string|boolean): void; + flash(object: FlashOptions): void; + } + } +} + +export = express_flash_notification; diff --git a/types/express-flash-notification/tsconfig.json b/types/express-flash-notification/tsconfig.json new file mode 100644 index 0000000000..842aacf264 --- /dev/null +++ b/types/express-flash-notification/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", + "express-flash-notification-tests.ts" + ] +} diff --git a/types/express-flash-notification/tslint.json b/types/express-flash-notification/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/express-flash-notification/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file