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
Provenance
- Commit
28f32b9- Tree
5db28f0- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
1d0a56b
2 files changed+0 added−106 removed
modified:lib/request.js-85 removed
22 unmodified lines23 __proto__: http.IncomingMessage.prototype24 };25 26 /**27- * Default notification formatters.28- */29-30-var defaultFormatters = exports.formatters = {31- s: String32- , d: function(val){ return val | 0; }33-};34-35-/**27 * Return request header or optional default.28 *29 * The `Referrer` header field is special-cased,30 * both `Referrer` and `Referer` will yield are226 unmodified lines257 return defaultValue;258 };259 260 /**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- */314-315-req.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 || {};319-320- 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-};344-345-/**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 linesmodified:lib/utils.js-21 removed
44 unmodified lines4546474849505152535455565758596061626364656667686949505152111 unmodified linesExpand all44 unmodified lines return ret;};
/** * Parse mini markdown implementation. * The following conversions are supported, * primarily for the "flash" middleware: * * _foo_ or *foo* become <em>foo</em> * __foo__ or **foo** become <strong>foo</strong> * [A](B) becomes <a href="B">A</a> * * @param {String} str * @return {String} * @api private */
exports.miniMarkdown = function(str){ return String(str) .replace(/(__|\*\*)(.*?)\1/g, '<strong>$2</strong>') .replace(/(_|\*)(.*?)\1/g, '<em>$2</em>') .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');};
/** * Check if `type` is acceptable based on * the given `str`. * * @param {String} type111 unmodified linesExpand all