utils.js
This file
Path
lib/utils.js
94 lines · 1.8 KiB · JavaScript
Last changed by
removed old parseRange utilTj Holowaychukbefore adoptionfed7fa4
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
/*! * Express - Utils * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca> * MIT Licensed */
/** * Check if `path` looks absolute. * * @param {String} path * @return {Boolean} * @api private */
exports.isAbsolute = function(path){ if ('/' == path[0]) return true; if (':' == path[1] && '\\' == path[2]) return true;};
/** * Flatten the given `arr`. * * @param {Array} arr * @return {Array} * @api private */
exports.flatten = function(arr, ret){ var ret = ret || [] , len = arr.length; for (var i = 0; i < len; ++i) { if (Array.isArray(arr[i])) { exports.flatten(arr[i], ret); } else { ret.push(arr[i]); } } 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>');};
/** * Escape special characters in the given string of html. * * @param {String} html * @return {String} * @api private */
exports.escape = function(html) { return String(html) .replace(/&/g, '&') .replace(/"/g, '"') .replace(/</g, '<') .replace(/>/g, '>');};
/** * Fast alternative to `Array.prototype.slice.call()`. * * @param {Arguments} args * @param {Number} n * @return {Array} * @api public */
exports.toArray = function(args, i){ var arr = [] , len = args.length , i = i || 0; for (; i < len; ++i) arr.push(args[i]); return arr;};