Adds express flash notification definitions.

This commit is contained in:
Mister 4 Eyes
2017-12-14 10:56:37 -05:00
parent 22f0a1d2eb
commit 084b629ffd
4 changed files with 120 additions and 0 deletions

View File

@@ -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: "/"
});
});

View File

@@ -0,0 +1,39 @@
// Type definitions for express-flash-notification 0.5
// Project: https://github.com/carlosascari/express-flash-notification
// Definitions by: Mister4Eyes <https://github.com/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;

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",
"express-flash-notification-tests.ts"
]
}

View File

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