Skip to content
Myr

utils.js

This file

Path

lib/utils.js

94 lines · 1.8 KiB · JavaScript

Last changed by

new ViewTj Holowaychukbefore adoptione1da383

History of this file

Take it

The walk stopped after 200 commits: lines older than 7eec21a point at it.

examplesTj Holowaychukbefore adoption7eec21a

lines 1–2why, one step back
1
2/*!

new ViewTj Holowaychukbefore adoptione1da383

line 3why, one step back
3 * Express - utils

examplesTj Holowaychukbefore adoption7eec21a

lines 4–8why, one step back
4 * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
5 * MIT Licensed6 */78/**

Fixed absolute path checking on windows. Closes #829 [reported by andrewpmckenzie]Tj Holowaychukbefore adoptionc21e3fe

lines 9–21why, one step back
9 * Check if `path` looks absolute.
10 *11 * @param {String} path12 * @return {Boolean}13 * @api private14 */1516exports.isAbsolute = function(path){17 if ('/' == path[0]) return true;18 if (':' == path[1] && '\\' == path[2]) return true;19};2021/**

examplesTj Holowaychukbefore adoption7eec21a

lines 22–94why, one step back
22 * Flatten the given `arr`.
23 *24 * @param {Array} arr25 * @return {Array}26 * @api private27 */2829exports.flatten = function(arr, ret){30 var ret = ret || []31 , len = arr.length;32 for (var i = 0; i < len; ++i) {33 if (Array.isArray(arr[i])) {34 exports.flatten(arr[i], ret);35 } else {36 ret.push(arr[i]);37 }38 }39 return ret;40};4142/**43 * Parse mini markdown implementation.44 * The following conversions are supported,45 * primarily for the "flash" middleware:46 *47 * _foo_ or *foo* become <em>foo</em>48 * __foo__ or **foo** become <strong>foo</strong>49 * [A](B) becomes <a href="B">A</a>50 *51 * @param {String} str52 * @return {String}53 * @api private54 */5556exports.miniMarkdown = function(str){57 return String(str)58 .replace(/(__|\*\*)(.*?)\1/g, '<strong>$2</strong>')59 .replace(/(_|\*)(.*?)\1/g, '<em>$2</em>')60 .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');61};6263/**64 * Escape special characters in the given string of html.65 *66 * @param {String} html67 * @return {String}68 * @api private69 */7071exports.escape = function(html) {72 return String(html)73 .replace(/&/g, '&amp;')74 .replace(/"/g, '&quot;')75 .replace(/</g, '&lt;')76 .replace(/>/g, '&gt;');77};7879/**80 * Fast alternative to `Array.prototype.slice.call()`.81 *82 * @param {Arguments} args83 * @param {Number} n84 * @return {Array}85 * @api public86 */8788exports.toArray = function(args, i){89 var arr = []90 , len = args.length91 , i = i || 0;92 for (; i < len; ++i) arr.push(args[i]);93 return arr;94};