Skip to content
Open
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
12 changes: 6 additions & 6 deletions lib/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ var isArray = require('util').isArray;
* @return {Function}
* @api public
*/
module.exports = function flash(options) {
module.exports = function flash (options) {
options = options || {};
var safe = (options.unsafe === undefined) ? true : !options.unsafe;
return function(req, res, next) {

return function (req, res, next) {
if (req.flash && safe) { return next(); }
req.flash = _flash;
next();
Expand Down Expand Up @@ -56,16 +56,16 @@ module.exports = function flash(options) {
* @return {Array|Object|Number}
* @api public
*/
function _flash(type, msg) {
function _flash (type, msg) {
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