Skip to content
Myr

Removed `req.notify()`

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 1d0a56b · Browse files · 2 files+0 added−106 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+0 added−106 removed

  • other:+0 added−106 removed

2 files+0 added−106 removed

modified:lib/request.js-85 removed
22 unmodified lines
23 __proto__: http.IncomingMessage.prototype24};2526/**27 * Default notification formatters.28 */2930var defaultFormatters = exports.formatters = {31 s: String32 , d: function(val){ return val | 0; }33};3435/**27 * Return request header or optional default.28 *29 * The `Referrer` header field is special-cased,30 * both `Referrer` and `Referer` will yield are
226 unmodified lines
257 return defaultValue;258};259260/**270 * Queue flash `msg` of the given `type`.271 *272 * This method is aliased as `req.notify()`.273 *274 * Examples:275 *276 * req.notify('info', 'email sent');277 * req.notify('info', 'email sent');278 * req.notify('error', 'email delivery failed');279 * req.notify('info', 'email re-sent');280 * // => 2281 *282 * req.notify('info');283 * // => ['email sent', 'email re-sent']284 *285 * req.notify('info');286 * // => []287 *288 * req.notify();289 * // => { error: ['email delivery failed'], info: [] }290 *291 * Formatting:292 *293 * Flash notifications also support arbitrary formatting support.294 * For example you may pass variable arguments to `req.notify()`295 * and use the %s specifier to be replaced by the associated argument:296 *297 * req.notify('info', 'email has been sent to %s.', userName);298 *299 * You may add addition formatters by defining `app.formatters`,300 * for example in the following snippet we define `%u` to uppercase301 * a string:302 *303 * app.formatters = {304 * u: function(val){305 * return String(val).toUpperCase();306 * }307 * };308 *309 * @param {String} type310 * @param {String} msg311 * @return {Array|Object|Number}312 * @api public313 */314315req.notify = function(type, msg){316 var sess = this.session;317 if (null == sess) throw Error('req.notify() requires sessions');318 var msgs = sess.notifications = sess.notifications || {};319320 switch (arguments.length) {321 // flush all messages322 case 0:323 sess.notifications = {};324 return msgs325 // flush messages for a specific type326 case 1:327 var arr = msgs[type];328 delete msgs[type];329 return arr || [];330 // set notification message331 default:332 var i = 2333 , args = arguments334 , formatters = this.app.formatters || {};335 formatters.__proto__ = defaultFormatters;336 msg = utils.miniMarkdown(msg);337 msg = msg.replace(/%([a-zA-Z])/g, function(_, format){338 var formatter = formatters[format];339 if (formatter) return formatter(utils.escape(args[i++]));340 });341 return (msgs[type] = msgs[type] || []).push(msg);342 }343};344345/**261 * Check if the incoming request contains the "Content-Type" 262 * header field, and it contains the give mime `type`.263 *264 * Examples:
116 unmodified lines
modified:lib/utils.js-21 removed