Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions lib/flash.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/**
* Module dependencies.
*/
var format = require('util').format;
var isArray = require('util').isArray;

var format = require("util").format;

/**
* Expose `flash()` function on requests.
Expand All @@ -13,14 +11,16 @@ var isArray = require('util').isArray;
*/
module.exports = function flash(options) {
options = options || {};
var safe = (options.unsafe === undefined) ? true : !options.unsafe;

return function(req, res, next) {
if (req.flash && safe) { return next(); }
var safe = options.unsafe === undefined ? true : !options.unsafe;

return function (req, res, next) {
if (req.flash && safe) {
return next();
}
req.flash = _flash;
next();
}
}
};
};

/**
* Queue flash `msg` of the given `type`.
Expand Down Expand Up @@ -57,15 +57,15 @@ module.exports = function flash(options) {
* @api public
*/
function _flash(type, msg) {
if (this.session === undefined) throw Error('req.flash() requires sessions');
var msgs = this.session.flash = this.session.flash || {};
if (this.session === undefined) throw Error("req.flash() requires sessions");
var msgs = (this.session.flash = this.session.flash || {});
if (type && msg) {
// util.format is available in Node.js 0.6+
if (arguments.length > 2 && format) {
var args = Array.prototype.slice.call(arguments, 1);
msg = format.apply(undefined, args);
} else if (isArray(msg)) {
msg.forEach(function(val){
} else if (Array.isArray(msg)) {
msg.forEach(function (val) {
(msgs[type] = msgs[type] || []).push(val);
});
return msgs[type].length;
Expand Down
24 changes: 16 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "connect-flash",
"version": "0.1.1",
"description": "Flash message middleware for Connect.",
"keywords": ["connect", "express", "flash", "messages"],
"keywords": [
"connect",
"express",
"flash",
"messages"
],
"repository": {
"type": "git",
"url": "git://github.com/jaredhanson/connect-flash.git"
Expand All @@ -15,18 +20,21 @@
"email": "[email protected]",
"url": "http://www.jaredhanson.net/"
},
"licenses": [ {
"type": "MIT",
"url": "http://www.opensource.org/licenses/MIT"
} ],
"licenses": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/MIT"
}
],
"main": "./lib",
"dependencies": {
},
"dependencies": {},
"devDependencies": {
"vows": "0.6.x"
},
"scripts": {
"test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js"
},
"engines": { "node": ">= 0.4.0" }
"engines": {
"node": ">= 0.4.0"
}
}