mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-15 12:09:40 +08:00
Adds express flash notification definitions.
This commit is contained in:
@@ -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: "/"
|
||||
});
|
||||
});
|
||||
39
types/express-flash-notification/index.d.ts
vendored
Normal file
39
types/express-flash-notification/index.d.ts
vendored
Normal 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;
|
||||
23
types/express-flash-notification/tsconfig.json
Normal file
23
types/express-flash-notification/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",
|
||||
"express-flash-notification-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/express-flash-notification/tslint.json
Normal file
1
types/express-flash-notification/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user