Merge branch 'master' of git://github.com/visionmedia/express into async_plugins
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Conflicts: lib/express/plugins/cookie.js lib/express/plugins/hooks.js lib/express/request.js
authored by ciaranj · committed by ciaranj · parents 3e80915, ce94168 · Browse files · 32 files·+160 added−1499 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
32 files+160 added−1499 removed
- tests:+9 added−512 removed
- other:+151 added−987 removed
Provenance
- Commit
27ff134- Tree
29e9cc2- Author
ciaranj <ciaranj@gmail.com>- Committer
ciaranj <ciaranj@gmail.com>- Parent 1
3e80915- Parent 2
ce94168
32 files changed+160 added−1499 removed
deleted:benchmarks/benchmark.js-83 removed
1-2-;(function(){3- var currentSuite4- 5- /**6- * Contents of _fn_. Strips function literal and signature.7- *8- * @param {function} fn9- * @return {string}10- * @api private11- */12- 13- function contentsOf(fn) {14- return fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1]15- }16- 17- /**18- * Pad _str_ to _len_.19- *20- * @param {string} str21- * @param {integer} len22- * @return {string}23- * @api private24- */25- 26- function pad(str, len) {27- return str + (new Array(len - str.length)).join(' ')28- }29- 30- /**31- * Time the execution of _fn_32- *33- * @param {function} fn34- * @return {float}35- * @api private36- */37- 38- function time(fn) {39- var start = Number(new Date)40- fn()41- return (Number(new Date) - start) / 100042- }43- 44- /**45- * Benchmark _fn_ with the given _label_.46- *47- * @param {string} label48- * @param {function} fn49- * @api public50- */51- 52- function benchmark(label, fn) {53- var duration = time(function(){54- for (var i = 0; i < currentSuite.times; ++i)55- fn()56- }).toFixed(3)57- print(pad(' ' + label, 50 - duration.toString().length) + duration + ' |')58- }59- 60- /**61- * Create a benchmark suite with the given _label_, which62- * will run each benchmark n _times_. If _times_ is omitted63- * then it defaults to 1.64- *65- * @param {string} label66- * @param {integer, function} times67- * @param {function} fn68- * @api public69- */70- 71- suite = function(label, times, fn) {72- currentSuite = this73- if (typeof times == 'function')74- this.times = 1, fn = times75- else76- this.times = times77- print('\n ' + pad(label, 42 - this.times.toString().length) + this.times + ' time(s)')78- print(' -------------------------------------------------')79- eval(contentsOf(fn))80- print('')81- }82- 83-})()deleted:benchmarks/collection.js-111 removed
1-2-require.paths.unshift('lib')3-require.paths.unshift('benchmarks')4-process.mixin(GLOBAL, require('sys'))5-process.mixin(GLOBAL, require('benchmark'))6-require('express')7-8-print = puts9-10-range = function(a, b) {11- var array = []12- while (a++ < b)13- array.push(a-1)14- return array15-}16-17-suite('Collection with [0..10,000]', 100, function(){18- array = range(0, 10000)19- 20- benchmark('for', function(){21- for (var i = 0, len = array.length; i < len; ++i) ;22- })23- 24- benchmark('for uncached', function(){25- for (var i = 0; i < array.length; ++i) ;26- })27- 28- benchmark('forEach()', function(){29- array.forEach(function(){})30- })31- 32- benchmark('#each()', function(){33- $(array).each(function(){})34- })35- 36- benchmark('#map()', function(){37- $(array).map(function(n){ return n += 1 })38- })39- 40- benchmark('#map() with shorthand', function(){41- $(array).map('a += 1')42- })43- 44- benchmark('#find()', function(){45- $(array).find(function(n){ return n > 5000 })46- })47- 48- benchmark('#select()', function(){49- $(array).select(function(n){ return n % 2 })50- })51- 52- benchmark('#first()', function(){53- $(array).first(5000)54- })55- 56- benchmark('#slice()', function(){57- $(array).slice(100, 5000)58- })59- 60- benchmark('#drop()', function(){61- $(array).drop(5000)62- })63- 64- benchmark('#length()', function(){65- $(array).length()66- })67- 68- benchmark('#keys()', function(){69- $(array).keys()70- })71- 72- benchmark('#toArray()', function(){73- $(array).toArray()74- })75- 76- benchmark('#min()', function(){77- $(array).min()78- })79- 80- benchmark('#max()', function(){81- $(array).max()82- })83- 84- benchmark('#sum()', function(){85- $(array).sum()86- })87- 88- benchmark('#avg()', function(){89- $(array).avg()90- })91- 92- benchmark('#clone()', function(){93- $(array).clone()94- })95- 96- benchmark('#merge()', function(){97- $(array).merge({ foo: 'bar' })98- })99- 100- benchmark('#sample()', function(){101- $(array).sample()102- })103- 104- benchmark('#chunk()', function(){105- $(array).chunk(5)106- })107- 108- benchmark('#at()', function(){109- $(array).at(5000)110- })111-})deleted:benchmarks/views.js-56 removed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
require.paths.unshift('lib')require.paths.unshift('benchmarks')process.mixin(GLOBAL, require('sys'))process.mixin(GLOBAL, require('benchmark'))require('express')
print = puts
engine = { ejs: require('ejs'), haml: require('haml'), sass: require('sass')}
options = { locals: { article: { title: 'Foo', body: 'bar' }}}
ejs = ' \n\<div id="primary"> \n\ <div class="block first"> \n\ <h1><%= article.title %></h1> \n\ <p><%= article.body %></p> \n\ </div> \n\</div> \n\'
haml = ' \n\#primary \n\ .block.first \n\ %h1= article.title \n\ %p= article.body \n\'
sass = ' \n\red: #ff0000 \n\body \n\ ul \n\ li \n\ a \n\ :color !red \n\ :list-style none \n\'
suite('Template Engines', 1000, function(){ benchmark('ejs', function(){ engine.ejs.render(ejs, options) }) benchmark('haml', function(){ engine.haml.render(haml, options) }) benchmark('sass', function(){ engine.sass.render(sass) })})No newline at end of filemodified:examples/upload/app.js+3 added-4 removed
24 unmodified lines252627282930293032333132333435368 unmodified lines24 unmodified lines })})
post('/upload', function(){ var self = this; $(this.param('images')).each(function(image){ this.param('images').each(function(image){ puts(image.filename + ' -> ' + image.tempfile) self.flash('info', 'Uploaded ' + image.filename) }) this.flash('info', 'Uploaded ' + image.filename) }, this) this.redirect('/upload')})
get('/public/*', function(file){8 unmodified linesmodified:lib/express/pages/show-exceptions.js+3 added-3 removed
11 unmodified lines1213141516161718192010 unmodified lines31323334353635363738394038 unmodified lines11 unmodified lines */
function stack(e) { if (e.stack) return $(e.stack.split('\n').slice(1)).map(function(val, i){ return e.stack.split('\n').slice(1).map(function(val, i){ if (!i) return '<li>' + val.replace(/^(.*?):/, '<span class="path">$1</span>:') + '</li>' return '<li>' + val .replace(/\(([^:]+)/, '(<span class="path">$1</span>')10 unmodified lines * @api private */
function hash(hash) { if (!$(hash).length()) return '<tr><td class="empty" colspan="2">Empty</td></tr>' return $(hash).map(function(val, key){ if (!hash || !hash.values.length) return '<tr><td class="empty" colspan="2">Empty</td></tr>' return hash.map(function(val, key){ return '<tr><td>' + key + ':</td><td>' + JSON.encode(val) + '</td></tr>' }).join('\n')}
38 unmodified linesmodified:lib/express/plugins/body-decoder.js+7 added-1 removed
1234567891011121314154 unmodified lines202122231824252627282 unmodified lines
// Express - BodyDecoder - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
/** * Module dependencies. */
var queryString = require('querystring')
// --- BodyDecoder
exports.BodyDecoder = Plugin.extend({ on: { /**4 unmodified lines request: function(event, callback) { var request = event.request if (request.header('content-type') && request.header('content-type').indexOf('application/x-www-form-urlencoded') > -1) request.header('content-type').includes('application/x-www-form-urlencoded')) request.params.post = queryString.parseQuery(request.body) callback(); }2 unmodified linesmodified:lib/express/plugins/cache.js+8 added-6 removed
28 unmodified lines29 * @api public30 */31 32 set: function(key, val) {33- if (typeof key !== 'string') throw new Error(this.name + ' store #set() key must be a string')33+ if (typeof key !== 'string')34+ throw new Error(this.name + ' store #set() key must be a string')35 },36 37 /**38 * Ensure that the given _key_ is a string.3 unmodified lines42 * @api public43 */44 45 get: function(key) {45- if (typeof key !== 'string') throw new Error(this.name + 'store #get() key must be a string')46+ if (typeof key !== 'string')47+ throw new Error(this.name + 'store #get() key must be a string')48 },49 50 /**51 * Convert to '[NAME Store]'.63 unmodified lines115 return this.data[key] instanceof Cache ?116 this.data[key].val :117 null118 var regexp = this.normalize(key) 117- return $(this.data).reduce({}, function(vals, cache){119+ return this.data.reduce(function(vals, cache){120 if (regexp.test(cache.key))121 vals[cache.key] = cache.val122 return vals121- })123+ }, {})124 },125 126 /**127 * Clear data matching the given _key_.26 unmodified lines154 155 reap: function(ms) {156 var self = this,157 threshold = Number(new Date(Number(new Date) - ms))156- $(this.data).each(function(cache){158+ this.data.each(function(cache){159 if (cache.created < threshold)160 self.clear(cache.key)161 })162 },32 unmodified lines195 * @api private196 */197 198 init: function(options) {197- process.mixin(this, options)199+ this.merge(options || {})200 this.store = new (this.dataStore || exports.Store.Memory)(options)201 Request.include({ cache: this.store })202 this.startReaper()203 },17 unmodified linesmodified:lib/express/plugins/cookie.js+8 added-8 removed
8 unmodified lines9 * @api public10 */11 12 exports.parseCookie = function(cookie) {13- return $(cookie.replace(/^ *| *$/g, '').split(/ *; */)).reduce({}, function(hash, pair){13+ return cookie.replace(/^ *| *$/g, '').split(/ *; */).reduce(function(hash, pair){14 var parts = pair.split(/ *= */)15 hash[parts[0]] = parts[1]16 return hash17- })17+ }, {})18 }19 20 /**21 * Compile cookie _name_, _val_ and _options_ to a string.6 unmodified lines28 */29 30 exports.compileCookie = function(name, val, options) {31 if (!options) return name + '=' + val32- return name + '=' + val + '; ' + $(options).map(function(val, key){32+ return name + '=' + val + '; ' + options.map(function(val, key){33 if (val instanceof Date)34 val = val.toString()35 .replace(/^(\w+)/, '$1,')36 .replace(/(\w+) (\d+) (\d+)/, '$2-$1-$3')37 .replace(/GMT.*$/, 'GMT')38 return val === true ? key : key + '=' + val39- }).toArray().join('; ')39+ }).join('; ')40 }41 42 // --- Cookie43 48 unmodified lines92 */93 94 request: function(event, callback) {95 event.request.response.cookies = []96- event.request.cookies = event.request.headers.cookie ? 97- exports.parseCookie(event.request.headers.cookie) : 98- {}99- callback();96+ event.request.cookies = event.request.headers.cookie97+ ? exports.parseCookie(event.request.headers.cookie)98+ : {}99+ callback()100 },101 102 /**103 * Set the Set-Cookie header when response cookies are available.9 unmodified linesmodified:lib/express/plugins/hooks.js+11 added-5 removed
1 2 // Express - Hooks - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4+/**5+ * Callbacks.6+ */7+8 exports.callbacks = { before: [], after: [] }9 10 /**11 * Add a _fn_ to be excuted before a request.26 unmodified lines38 * Initialize extensions.39 */40 41 init: function() {42+ global.merge({38- process.mixin(GLOBAL, { before: exports.before,39- after: exports.after })43+ before: exports.before,44+ after: exports.after45+ })46 }47 },48 49 // --- Events4 unmodified lines54 * Invoke all before handlers.55 */56 57 request: function(event, callback) {52- $(exports.callbacks.before).each(function(fn){58+ exports.callbacks.before.each(function(fn){59 fn.call(event.request, event.request)60 })61 callback();62 },1 unmodified line64 /**65 * Invoke all after handlers.66 */67 62- response: function(event, callback) {63- $(exports.callbacks.after).each(function(fn){68+ response: function(event) {69+ exports.callbacks.after.each(function(fn){70 fn.call(event.request, event.request)71 })72 callback();73 }2 unmodified linesmodified:lib/express/plugins/profiler.js+1 added-1 removed
16 unmodified lines17 * @api private18 */19 20 init: function(options) {21- process.mixin(this, options)21+ this.merge(options || {})22 }23 },24 25 // --- Events28 unmodified linesmodified:lib/express/plugins/redirect.js+1 added-1 removed
30 unmodified lines31 * @api public32 */33 34 redirect: function(url, code) {35- if (url == 'back' || url == 'home') url = this[url]35+ if (url === 'back' || url === 'home') url = this[url]36 this.header('location', url)37 this.halt(code || 303)38 } 39 })19 unmodified linesmodified:lib/express/plugins/session.js+6 added-7 removed
116 unmodified lines117 * @api public118 */119 120 length: function() {121- return $(this.store).length()121+ return this.store.values.length122 },123 124 /**125 * Reap sessions older than _ms_.2 unmodified lines128 * @api private129 */130 131 reap: function(ms) {132- var self = this,133- threshold = Number(new Date(Number(new Date) - ms))134- $(this.store).each(function(session, sid){132+ var threshold = Number(new Date(Number(new Date) - ms))133+ this.store.each(function(session, sid){134 if (session.lastAccess < threshold)136- self.destroy(sid)137- })135+ this.destroy(sid)136+ }, this)137 }138 })139 140 // --- Session14 unmodified lines155 * @api private156 */157 158 init: function(options) {160- process.mixin(this, options)159+ this.merge(options || {})160 this.store = new (this.dataStore || exports.Store.Memory)(options)161 this.startReaper()162 },163 43 unmodified linesmodified:lib/express/plugins/view.js+6 added-5 removed
4 unmodified lines5 * Module dependencies.6 */7 8 var utils = require('express/utils'),9+ extname = require('path').extname,10 fs = require('fs')11 12 /**13 * Supported template engines.53 unmodified lines67 var self = this,68 options = options || {},69 path = set('views') + '/' + view,70 type = path.split('.').slice(-2)[0],70- ext = utils.extname(path),71+ ext = extname(path),72 layout = options.layout === undefined ? 'layout' : options.layout73 options.context = options.context || this74 self.contentType(ext)75 function render(content) {76 content = engine[type].render(content, options)77 if (layout)77- self.render(layout + '.' + type + '.' + ext, utils.mixin(true, options, {78+ self.render(layout + '.' + type + ext, utils.mixin(true, options, {79 layout: false,80 locals: {81 body: content82 }5 unmodified lines88 render(self.cache.get(path))89 else90 fs.readFile(path, function(e, content){91 if (e) throw e91- set('cache view contents') ?92- render(self.cache.set(path, content)) :93- render(content)92+ set('cache view contents')93+ ? render(self.cache.set(path, content))94+ : render(content)95 })96 }97 })98 }3 unmodified linesmodified:lib/express/spec/mocks.js+7 added-1 removed
1 2 // Express - MockRequest - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4+/**5+ * Module dependencies.6+ */7+ 8+var utils = require('express/utils')9+10 // --- MockRequest11 12 var MockRequest = Class({13 24 unmodified lines38 'accept': 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',39 'accept-language': 'en-us',40 'connection': 'keep-alive'41 }36- process.mixin(true, this, options)42+ utils.mixin(true, this, options)43 }44 })45 46 // --- MockResponse89 unmodified linesdeleted:lib/express/collection.js-549 removed
1-2-// Express - Collection - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3-4-/**5- * Module dependencies.6- */7- 8-var utils = require('express/utils')9-10-/**11- * Throw $break in order to stop iteration.12- */13-14-$break = '__break__'15-16-var property = /^\w+$/,17- method = /^\w+\(/18-19-/**20- * Normalize callback _fn_. When a string is21- * passed convert the shorthand expr to a function.22- *23- * - Functions are passed through un-touched24- * - Strings with length of < 4 are considered operators between a and b25- * - Single words are considered properties on a26- * - Single functions are considered method calls on a27- * - Larger strings are considered return expressions28- *29- * @param {string, function} fn30- * @return {function}31- * @api private32- */33-34-function callback(fn) {35- if (fn === undefined) return36- if (fn instanceof Function) return fn37- if (fn.length < 4) return Function('a, b, c', 'return a ' + fn + ' b')38- if (property.test(fn) || method.test(fn)) fn = 'a.' + fn39- return Function('a, b, c', 'return ' + fn)40-}41-42-// --- Collection43-44-Collection = Class({45- 46- /**47- * Initialize collection with an array-like object.48- *49- * @param {object} arr50- * @api private51- */52- 53- init: function(arr) {54- this.arr = arr || []55- },56- 57- /**58- * Return the value of _index_ or null.59- *60- * @param {int} index61- * @return {mixed}62- * @api public63- */64- 65- at: function(index) {66- if ('length' in this.arr)67- return this.arr[index]68- var result, i = 069- this.each(function(val){70- if (i++ == index) {71- result = val72- throw $break73- }74- })75- return result76- },77- 78- /**79- * Iterate collection using callback _fn_,80- * passing both the value and index.81- *82- * @param {function} fn83- * @return {Collection}84- * @api public85- */86- 87- each: function(fn) {88- try {89- if (this.arr.forEach)90- this.arr.forEach(fn)91- else92- for (var key in this.arr)93- if (this.arr.hasOwnProperty(key))94- fn(this.arr[key], key)95- }96- catch (e) {97- if (e != $break) throw e98- }99- return this100- },101- 102- /**103- * Reverse a collection.104- *105- * @return {Collection}106- * @api public107- */108- 109- reverse: function() {110- if (this.arr.reverse)111- return $(this.arr.reverse())112- return this113- },114- 115- /**116- * Join a collection with the given _str_ or ''.117- *118- * @param {string} str119- * @return {string}120- * @api public121- */122- 123- join: function(str) {124- return this.toArray().join(str || '')125- },126- 127- /**128- * Sort collection with optional _fn_.129- *130- * @param {function} fn131- * @return {Collection}132- * @warn converts to array133- * @api public134- */135- 136- sort: function(fn) {137- fn = callback(fn)138- return $(this.toArray().sort(fn))139- },140- 141- /**142- * Iterate with _memo_ using callback _fn_.143- * The _memo_ object is passed as the first 144- * argument, and the return value of _fn_ becomes145- * the value of _memo_ providing a functional 146- * approach to reducing a collection.147- *148- * @param {mixed} memo149- * @param {function} fn150- * @return {mixed}151- * @api public152- */153- 154- reduce: function(memo, fn) {155- fn = callback(fn)156- if (this.arr.reduce)157- return this.arr.reduce(fn, memo)158- this.each(function(val, key){159- memo = fn(memo, val, key)160- })161- return memo162- },163- 164- /**165- * Map using callback _fn_, returning a 166- * new collection of return values.167- *168- * @param {function} fn169- * @return {Collection}170- * @api public171- */172- 173- map: function(fn) {174- fn = callback(fn)175- if (this.arr.map)176- return $(this.arr.map(fn))177- return $(this.reduce([], function(array, val, key){178- array.push(fn(val, key))179- return array180- }))181- },182- 183- /**184- * Return collection of values when _fn_ evaluates185- * to true.186- *187- * @param {function} fn188- * @return {Collection}189- * @api public190- */191- 192- select: function(fn) {193- fn = callback(fn)194- return $(this.reduce([], function(array, val, key){195- if (fn(val, key))196- array.push(val)197- return array198- }))199- },200- 201- /**202- * Return collection of values when _fn_ evaluates203- * to false.204- *205- * @param {function} fn206- * @return {Collection}207- * @api public208- */209- 210- reject: function(fn) {211- fn = callback(fn)212- return $(this.reduce([], function(array, val, key){213- if (!fn(val, key))214- array.push(val)215- return array216- }))217- },218- 219- /**220- * Check if all arguments passed are found within 221- * the collection using the === operator.222- *223- * @return {bool}224- * @api public225- */226- 227- includes: function() {228- var self = this229- return $(arguments).all(function(arg){230- return self.any(function(val){231- return val === arg232- })233- })234- },235- 236- /**237- * Return the first _n_ value(s), defaults to 1.238- *239- * @param {int} n240- * @return {mixed}241- * @api public242- */243- 244- first: function(n) {245- return n ? 246- this.slice(0, n) :247- this.at(0)248- },249- 250- /**251- * Return the last _n_ value(s), defaults to -1.252- *253- * @param {int} n254- * @return {mixed}255- * @api public256- */257- 258- last: function(n) {259- var len = this.length()260- return n ? 261- this.slice(len - n, len) :262- this.at(--len)263- },264- 265- /**266- * Drop the first _n_ values, returning the others.267- *268- * @param {int} n269- * @return {Collection}270- * @api public271- */272- 273- drop: function(n) {274- return this.slice(n, this.length())275- },276- 277- /**278- * Return a slice of values from _start_ to _end_.279- *280- * @param {int} start281- * @param {int} end282- * @return {Collection}283- * @api public284- */285- 286- slice: function(start, end) {287- if (this.arr.slice)288- return $(this.arr.slice(start, end))289- var i = 0290- return $(this.reduce([], function(array, val){291- if (i++ >= start)292- if (i <= end)293- array.push(val)294- else295- throw $break296- return array297- }))298- },299- 300- /**301- * Iterate until _fn_ evaluates to true, then302- * return the matching value.303- *304- * @param {function} fn305- * @return {mixed}306- * @api public307- */308- 309- find: function(fn) {310- var result, fn = callback(fn)311- this.each(function(val, key){312- if (fn(val, key)) {313- result = val314- throw $break315- }316- })317- return result318- },319- 320- /**321- * Return true if _fn_ ever evaluates to true, otherwise322- * returns false.323- *324- * @param {function} fn325- * @return {bool}326- * @api public327- */328- 329- any: function(fn) {330- fn = callback(fn)331- if (this.arr.some)332- return this.arr.some(fn)333- return !! this.find(fn)334- },335- 336- /**337- * Returns true if _fn_ always evaluates to true, otherwise338- * returns false.339- *340- * @param {function} fn341- * @return {bool}342- * @api public343- */344- 345- all: function(fn) {346- fn = callback(fn)347- if (this.arr.every)348- return this.arr.every(fn)349- return this.reduce(true, function(state, val, key){350- if (!state) throw $break351- return !! fn(val, key)352- })353- },354- 355- /**356- * Select values matching _pattern_357- *358- * @param {regexp} pattern359- * @return {Collection}360- * @api public361- */362- 363- grep: function(pattern) {364- return this.select(function(val){365- return pattern.exec(val)366- })367- },368- 369- /**370- * Return keys as a collection.371- *372- * @return {Collection}373- * @api public374- */375- 376- keys: function() {377- return $(Object.keys(this.arr))378- },379- 380- /**381- * Convert a collection to a true array.382- * Works recursively383- *384- * @return {array}385- * @api public386- */387- 388- toArray: function() {389- return this.reduce([], function(array, val){390- val instanceof Collection ?391- array.push(val.toArray()) :392- array.push(val)393- return array394- })395- },396- 397- /**398- * Return the lowest number in the collection.399- *400- * @return {number}401- * @api public402- */403- 404- min: function() {405- return this.reduce(null, function(min, val){406- return min === null ? val :407- val < min ? val :408- min409- })410- },411- 412- /**413- * Return the largest number in the collection.414- *415- * @return {number}416- * @api public417- */418- 419- max: function() {420- return this.reduce(null, function(max, val){421- return max === null ? val :422- val > max ? val :423- max424- })425- },426- 427- /**428- * Group collection into several collections grouped by _size_.429- *430- * @param {int} size431- * @return {Collection}432- * @api public433- */434- 435- chunk: function(size) {436- var len = this.arr.length, 437- chunks = [], chunk = [], i = 0 438- this.each(function(val, key){439- chunk.push(val)440- if (i++ > 0 && (i % size == 0 || i == len))441- chunks.push($(chunk)),442- chunk = []443- })444- return $(chunks)445- },446- 447- /**448- * Return the length of this collection.449- *450- * @return {int}451- * @api public452- */453- 454- length: function() {455- if ('length' in this.arr)456- return this.arr.length457- return this.reduce(0, function(len){458- return ++len459- })460- },461- 462- /**463- * Return the sum of numeric values in this collection.464- *465- * @return {number}466- * @api public467- */468- 469- sum: function() {470- return this.reduce(0, function(sum, n){471- return sum + n472- })473- },474- 475- /**476- * Return the average of numeric values in this collection.477- *478- * @return {number}479- * @api public480- */481- 482- avg: function() {483- return this.sum() / this.length()484- },485- 486- /**487- * Merge _other_ with this collection.488- *489- * @param {mixed} other490- * @return {Collection}491- * @api public492- */493- 494- merge: function(other) {495- if (this.arr instanceof Array)496- return $($(other).reduce(this.arr, function(array, val){497- array.push(val)498- return array499- }))500- else501- return $(utils.mixin(this.arr, $(other).arr))502- },503- 504- /**505- * Clone the collection.506- *507- * @return {Collection}508- * @api public509- */510- 511- clone: function() {512- return $(utils.clone(this.arr))513- },514- 515- /**516- * Return the value of a random index.517- *518- * @return {mixed}519- * @api public520- */521- 522- sample: function() {523- return this.at(Math.floor(Math.random() * this.length()))524- },525- 526- /**527- * Convert collection to a string.528- *529- * @return {string}530- * @api public531- */532- 533- toString: function() {534- return '[Collection ' + this.arr + ']'535- }536-})537-538-/**539- * Create a new collection from an array-like object.540- *541- * @param {object} arr542- * @return {Collection}543- * @api public544- */545-546-var $ = exports.$ = function(arr) {547- if (arr instanceof Collection) return arr548- return new Collection(arr)549-}modified:lib/express/core.js+16 added-19 removed
8 unmodified lines9 utils = require('express/utils'),10 events = require('events'),11 fs = require('fs')12 13-utils.mixin(require('sys'))14-utils.mixin(require('express/exceptions'))15-utils.mixin(require('express/collection'))16-utils.mixin(require('express/event'))17-utils.mixin(require('express/request'))18-utils.mixin(require('express/plugin'))19-utils.mixin(require('express/dsl'))13+global.merge(require('sys'))14+global.merge(require('express/exceptions'))15+global.merge(require('express/event'))16+global.merge(require('express/request'))17+global.merge(require('express/plugin'))18+global.merge(require('express/dsl'))19 20 // --- Route21 22 Route = Class({46 unmodified lines69 normalize: function(path) {70 var self = this71 this.keys = []72 if (path instanceof RegExp) return path74- return new RegExp('^' + utils.escapeRegexp(normalizePath(path), '.')73+ return new RegExp('^' + RegExp.escape(normalizePath(path), '.')74 .replace(/\*/g, '(.+)')75 .replace(/(\/|\\\.):(\w+)\?/g, function(_, c, key){76 self.keys.push(key)77 return '(?:' + c + '([^\/]+))?'44 unmodified lines122 * @api private123 */124 125 matchingRoute: function(){127- var self = this128- return $(Express.routes).find(function(route){129- return self.match(route)130- })126+ return Express.routes.find(function(route){127+ return this.match(route)128+ }, this)129 },130 131 /**132 * Check if _route_ matches the current request.13 unmodified lines146 },147 148 /**149 * Map #request.captures to #request.params.path based on the152- * given _route_ keys.150+ * given _route_ params.151 *152 * @param {Route} route153 * @api private154 */155 156 mapParams: function(route) {159- var self = this160- $(route.keys).each(function(key, i){161- self.request.params.path[key] = self.request.captures[++i]162- })157+ route.keys.each(function(key, i){158+ this.request.params.path[key] = this.request.captures[++i]159+ }, this)160 }161 })162 163 // --- Server48 unmodified lines212 else if (!pendingFiles)213 self.route(request, response)214 }215 if (request.headers['content-type'] &&219- request.headers['content-type'].indexOf('multipart/form-data') !== -1) {216+ request.headers['content-type'].includes('multipart/form-data')) {217 var stream = multipart.parse(request),218 pendingFiles = 0219 request.params = { post: {}}220 stream83 unmodified lines304 305 // --- Express306 307 Express = { 311- version: '0.4.0',308+ version: '0.5.0',309 config: [],310 routes: [],311 plugins: [],312 settings: {},25 unmodified linesmodified:lib/express/dsl.js+21 added-20 removed
17 unmodified lines18 function route(method) {19 return function(path, options, fn){20 if (options instanceof Function)21 fn = options, options = {}22- if (path.indexOf('http://') === 0)22+ if (path.startsWith('http://'))23 return http[method].apply(this, arguments)24 else if (!Express.server.running)25 Express.routes.push(new Route(method, path, fn, options))26 else11 unmodified lines38 * @api public39 */40 41 exports.set = function(option, val) {42- return val === undefined ?43- Express.settings[option] instanceof Function ?44- Express.settings[option]() :45- Express.settings[option] :46- Express.settings[option] = val42+ return val === undefined43+ ? Express.settings[option] instanceof Function44+ ? Express.settings[option]()45+ : Express.settings[option]46+ : Express.settings[option] = val47 }48 49 /**50 * Enable _options_.27 unmodified lines78 * @api public79 */80 81 exports.run = function() {82- configure(Express.environment = process.ENV.EXPRESS_ENV || 'development')83- $(Express.plugins).each(function(plugin){82+ configure(Express.environment = process.env.EXPRESS_ENV || 'development')83+ Express.plugins.each(function(plugin){84 if ('init' in plugin.klass)85 plugin.klass.init(plugin.options)86 })87 Express.server.run.apply(Express.server, arguments)88 }89 90 /**91- * Configure _environment_ with _fn_.91+ * Configure _env_ with _fn_.92 *93 * Global configuration, disregards which94 * environment is active:95 *10 unmodified lines106 * Running configurations:107 * 108 * configure('development')109 *110- * @param {string, function} environment110+ * @param {string, function} env111 * @param {function} fn112 * @api public113 */114 115-exports.configure = function(environment, fn) {116- if (environment instanceof Function)117- fn = environment, environment = 'all'115+exports.configure = function(env, fn) {116+ if (env instanceof Function)117+ fn = env, env = 'all'118 if (fn instanceof Function)119- return Express.config.push([environment, fn])120- if (typeof environment != 'string')119+ return Express.config.push([env, fn])120+ if (typeof env !== 'string')121 throw new Error('environment required')122- for (var i = 0, len = Express.config.length; i < len; ++i)123- if (Express.config[i][0] == environment ||124- Express.config[i][0] == 'all')125- Express.config[i][1].call(Express)122+ Express.config.each(function(conf){123+ if (conf[0] === env ||124+ conf[0] === 'all')125+ conf[1].call(Express)126+ })127 }128 129 // --- Routing API130 131 exports.get = exports.view = route('get')132 exports.post = exports.create = route('post')133 exports.del = exports.destroy = route('delete')133-exports.put = exports.update = route('put')134+exports.put = exports.update = route('put')modified:lib/express/event.js+2 added-1 removed
1 2 // Express - Event - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3+4 exports.Event = Class({5 6 /**7 * Initialize with event _name_ and optional _data_.4 unmodified lines12 */13 14 init: function(name, data) {15 this.name = name15- process.mixin(this, data)16+ this.merge(data || {})17 },18 19 /**20 * Return event string.9 unmodified linesmodified:lib/express/mime.js+2 added-2 removed
3 unmodified lines4 /**5 * Module dependencies.6 */7 8-var utils = require('express/utils')8+var extname = require('path').extname9 10 /**11 * Mime type lookup table.12 */350 unmodified lines363 */364 365 exports.type = function(path) {366 return exports.types[path] || 367- exports.types[utils.extname(path)] || 367+ exports.types[extname(path).substr(1)] || 368 set('default mime type') || 369 'application/octet-stream' 370 }modified:lib/express/plugin.js+8 added-2 removed
1-var utils = require('express/utils');1+2 // Express - Plugin - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4 /**5+ * Module dependencies.6+ */7+8+var utils = require('express/utils');9+10+/**11 * Push _plugin_ with _options_ to the plugin stack.12 * If _plugin_ has already been pushed, then it's options13 * will override any previously set.14 *4 unmodified lines19 20 exports.use = function(plugin, options) {21 if (Express.environment === 'test' && 'init' in plugin)22 plugin.init(options)17- $(Express.plugins).each(function(other, i){23+ Express.plugins.each(function(other, i){24 if (other.klass === plugin)25 delete Express.plugins[i]26 })27 Express.plugins.push({36 unmodified linesmodified:lib/express/plugins.js+2 added-1 removed
1 2 // Express - Plugins - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3+3-var utils = require('express/utils');4+var utils = require('express/utils')5 utils.mixin(require('express/plugins/hooks'))6 utils.mixin(require('express/plugins/flash'))7 utils.mixin(require('express/plugins/cache'))8 utils.mixin(require('express/plugins/cookie'))5 unmodified linesmodified:lib/express/request.js+14 added-16 removed
71 unmodified lines72 this.params = this.params || {}73 this.params.path = {}74 this.params.get = this.url.query ? queryString.parseQuery(this.url.query) : {}75 this.params.post = this.params.post || {}76- this.plugins = $(Express.plugins).map(function(plugin){76+ this.plugins = Express.plugins.map(function(plugin){77 return new plugin.klass(plugin.options) 78 })79 },80 51 unmodified lines132 */133 134 accepts: function() {135 var accept = this.header('accept')136- return accept ? 137- $(arguments).any(function(path){138- var type = mime.type(path)139- return accept.indexOf(type) !== -1 ||140- accept.indexOf(type.split('/')[0]+'/*') !== -1141- }) :142- true136+ return accept 137+ ? arguments.any(function(path){138+ var type = mime.type(path)139+ return accept.indexOf(type) !== -1 ||140+ accept.indexOf(type.split('/')[0]+'/*') !== -1141+ })142+ : true143 },144 145 /**146 * Set response status to _code_.75 unmodified lines222 * @api public223 */224 225 trigger: function(name, data, callback) {226- data = process.mixin(data || {}, {227- request: this,228- response: this.response229- })226+ data = data || {}227+ data.merge({ request: this, response: this.response })228 //TODO: we'd want to use the nice collection stuff that was here instead of this crappy approach...229 var pluginsExecuted= 0,230 plugin= undefined,233- totalPlugins= this.plugins.length(),231+ totalPlugins= this.plugins.length,232 self= this;233 var callNextPlugin= function(error) {234 if( error || pluginsExecuted >= totalPlugins ) callback(error); // All the plugins have called back or there was an error ..235 else {32 unmodified lines268 * @api public269 */270 271 attachment: function(path) {274- this.header('content-disposition', path ? 275- 'attachment; filename="' + path + '"' :276- 'attachment')272+ this.header('content-disposition', path273+ ? 'attachment; filename="' + path + '"'274+ : 'attachment')275 return this276 },277 278 /**12 unmodified linesmodified:lib/express/utils.js+6 added-64 removed
27 unmodified lines28 return uid29 }30 31 /**32- * Return the extension name of the given _path_,33- * or null when not present.34- *35- * @param {string} path36- * @return {string}37- * @api public38- */39-40-exports.extname = function(path) {41- if (path.lastIndexOf('.') < 0) return42- return path.slice(path.lastIndexOf('.') + 1)43-}44-45-/**46- * Return the basename of the given _path_.47- *48- * @param {string} path49- * @return {string}50- * @api public51- */52-53-exports.basename = function(path) {54- return path.split('/').slice(-1)[0]55-}56-57-/**32 * Escape special characters in _html_.33 *34 * @param {string} html35 * @return {string}36 * @api public37 */38 39 exports.escape = function(html) {66- return html.toString()40+ return String(html)41 .replace(/&/g, '&')42 .replace(/"/g, '"')43 .replace(/</g, '<')44 .replace(/>/g, '>')45 }46 47 /**74- * Convert native array-like objects into an75- * array with optional _offset_.76- *77- * @param {object} arr78- * @param {int} offset79- * @return {array}80- * @api public81- */82-83-exports.toArray = function(arr, offset) {84- return Array.prototype.slice.call(arr, offset)85-}86-87-/**88- * Escape RegExp _chars_ in _string_. Where _chars_ 89- * defaults to regular expression special characters.90- *91- * _chars_ should be a space delimited list of characters,92- * for example '[ ] ( )'.93- *94- * @param {string} string95- * @param {string} chars96- * @return {Type}97- * @api public98- */99-100-exports.escapeRegexp = function(string, chars) {101- var specials = (chars || '/ . * + ? | ( ) [ ] { } \\').split(' ').join('|\\')102- return string.replace(new RegExp('(\\' + specials + ')', 'g'), '\\$1')103-}104-105-/**48 * Merge param _key_ and _val_ into _params_. Key49 * should be a query string key such as 'user[name]',50 * and _val_ is it's associated object. The root _params_51 * object is returned.7 unmodified lines59 exports.mergeParam = function(key, val, params) {60 var orig = params,61 keys = key.trim().match(/\w+/g),62 array = /\[\]$/.test(key)121- $(keys).reduce(queryString.parseQuery(key), function(parts, key, i){63+ keys.reduce(function(parts, key, i){64 if (i === keys.length - 1)65 if (key in params)124- params[key] instanceof Array ?125- params[key].push(val) :126- params[key] = [params[key], val]66+ params[key] instanceof Array67+ ? params[key].push(val)68+ : params[key] = [params[key], val]69 else70 params[key] = array ? [val] : val71 if (!(key in params)) params[key] = {}72 params = params[key]73 return parts[key]132- })74+ }, queryString.parseQuery(key))75 return orig76 }77 78 /**73 unmodified linesadded:lib/support/extnot shown
Its text is not shown, added.
modified:lib/express.js+2 added
1 unmodified line2 require.paths.unshift(__dirname + '/support/js-oo/lib')3 require.paths.unshift(__dirname + '/support/ejs/lib')4 require.paths.unshift(__dirname + '/support/haml/lib')5 require.paths.unshift(__dirname + '/support/sass/lib')6+require.paths.unshift(__dirname + '/support/ext/lib')7 require('oo')8+require('ext')9 require('express/core')modified:spec/node.js-1 removed
20 unmodified lines21 'utils',22 'request',23 'mime',24 'static',25- 'collection',25 'plugins',26 'plugins.cache',27 'plugins.view',28 'plugins.common-logger',21 unmodified linesdeleted:spec/spec.collection.js-474 removed
1-2-process.mixin(require('express/collection'))3-4-describe 'Express'5- describe 'Collection'6- describe '$(array)'7- it 'should return a Collection'8- $(['foo', 'bar']).should.be_an_instance_of Collection9- end10- end11- 12- describe '$(object)'13- it 'should return a Collection'14- $({ foo: 'bar' }).should.be_an_instance_of Collection15- end16- end17- 18- describe '$(Collection)'19- it 'should return the collection passed'20- var collection = $(['foo'])21- $(collection).should.equal collection22- end23- end24- 25- describe 'shorthand expressions'26- describe 'with 3 or less chars'27- it 'should be considered binary operator between a / b'28- $(5..1).sort('-').toArray().should.eql 1..529- $(5..1).reduce(0, '+').should.eql 1530- end31- end32- 33- describe 'with over 3 chars'34- it 'should be considered a return expression'35- $(5..1).sort('a - b').toArray().should.eql 1..536- $(5..1).reduce(0, 'a + b').should.eql 1537- end38- 39- it 'should consider a single word a property on a'40- $(['foo', 'foobar']).map('length').toArray().should.eql [3, 6]41- end42- 43- it 'should consider a single function a method on a'44- $(['foo', 'foobar']).map('charAt(0)').toArray().should.eql ['f', 'f']45- end46- end47- end48- 49- describe '#at()'50- it 'should return the value at the given index'51- $(['foo', 'bar']).at(0).should.eql 'foo'52- $(['foo', 'bar']).at(1).should.eql 'bar'53- $(['foo', 'bar']).at(2).should.be_null54- end55- 56- it 'should work with objects'57- $({ foo: 'bar', baz: 'raz' }).at(0).should.eql 'bar'58- $({ foo: 'bar', baz: 'raz' }).at(1).should.eql 'raz'59- $({ foo: 'bar', baz: 'raz' }).at(2).should.be_null60- end61- end62- 63- describe '#each()'64- it 'should iterate passing index and value'65- var result = []66- $(['foo', 'bar']).each(function(val, i){67- result.push(i, val)68- })69- result.should.eql [0, 'foo', 1, 'bar']70- end71- 72- it 'should work with objects'73- var result = []74- $({ foo: 'bar', baz: 'raz' }).each(function(val, key){75- result.push(key, val)76- })77- result.should.eql ['foo', 'bar', 'baz', 'raz']78- end79- 80- it 'should return the collection'81- $([]).each(function(){}).should.be_an_instance_of Collection82- end83- end84- 85- describe '#reduce()'86- it 'should iterate with memo object'87- var sum = $([1,2,3]).reduce(0, function(sum, n){ return sum + n })88- sum.should.eql 689- end90- 91- it 'should allow shorthand expressions'92- $([1,2,3]).reduce(0, '+').should.eql 693- $([1,2,3]).reduce(0, 'a + b').should.eql 694- end95- end96- 97- describe '#map()'98- it 'should iterate collecting results into a new collection'99- var collection = $(['foo', 'bar']).map(function(val){ return val.toUpperCase() })100- collection.at(0).should.eql 'FOO'101- collection.at(1).should.eql 'BAR'102- end103- 104- it 'should work with objects'105- var collection = $({ foo: 'bar', baz: 'raz' }).map(function(val){ return val.toUpperCase() })106- collection.at(0).should.eql 'BAR'107- collection.at(1).should.eql 'RAZ'108- end109- 110- it 'should allow shorthand expressions'111- $(['foo', 'bar']).map('a.toUpperCase()').toArray().should.eql ['FOO', 'BAR']112- end113- end114- 115- describe '#first()'116- it 'should return the first value'117- $(['foo']).first().should.eql 'foo'118- end119- 120- it 'should return the first n values'121- $([5,4,3,2,1]).first(2).at(0).should.eql 5122- $([5,4,3,2,1]).first(2).at(1).should.eql 4123- end124- 125- it 'should work with objects'126- $({ foo: 'bar' }).first().should.eql 'bar'127- end 128- end129- 130- describe '#last()'131- it 'should return the last value'132- $(['foo', 'bar']).last().should.eql 'bar'133- end134- 135- it 'should return the last n values'136- $([5,4,3,2,1]).last(2).at(0).should.eql 2137- $([5,4,3,2,1]).last(2).at(1).should.eql 1138- end139- 140- it 'should work with objects'141- $({ a: 'foo', b: 'bar' }).last(2).at(0).should.eql 'foo'142- $({ a: 'foo', b: 'bar' }).last(2).at(1).should.eql 'bar'143- $({ a: 'foo', b: 'bar' }).last().should.eql 'bar'144- end 145- end146- 147- describe '#drop()'148- it 'should drop the first n values'149- $(1..5).drop(2).arr.should.eql 3..5150- end151- end152- 153- describe '#find()'154- it 'should return the value of the first match'155- var result = $(['foo', 'bar']).find(function(val){ return val.charAt(0) == 'b' })156- result.should.eql 'bar'157- end158- 159- it 'should return null when nothing matches'160- var result = $(['foo', 'bar']).find(function(val){ return val.charAt(0) == 'a' })161- result.should.be_null162- end163- 164- it 'should work with objects'165- var result = $({ foo: 'bar', baz: 'raz' }).find(function(val, key){166- return val.charAt(0) == 'r'167- })168- result.should.eql 'raz'169- end170- 171- it 'should allow shorthand expressions'172- $(['foo', 'bar']).find("a.charAt(0) == 'b'").should.eql 'bar'173- end174- end175- 176- describe '#all()'177- it 'should return true when all evaluate to true'178- $(['foo', 'foobar']).all(function(val){ return val.charAt(0) == 'f' }).should.be_true179- end180- 181- it 'should return false when any evaluate to false'182- $(['foo', 'bar', 'foobar']).all(function(val){ return val.charAt(0) == 'f' }).should.be_false183- end184- 185- it 'should work with objects'186- $({ a: 'foo', b: 'foobar' }).all(function(val){ return val.charAt(0) == 'f' }).should.be_true187- end188- 189- it 'should allow shorthand expressions'190- $(['foo', 'bar']).all('a.length > 2').should.be_true191- end192- end193- 194- describe '#any()'195- it 'should return true when found'196- $(['foo', 'bar']).any(function(val){ return val.charAt(0) == 'b' }).should.be_true197- end198- 199- it 'should return false when not found'200- $(['foo', 'bar']).any(function(val){ return val.charAt(0) == 'r' }).should.be_false201- end202- 203- it 'should work with objects'204- $({ foo: 'bar' }).any(function(val){ return val.charAt(0) == 'b' }).should.be_true205- $({ foo: 'bar' }).any(function(val){ return val.charAt(0) == 'c' }).should.be_false206- end207- 208- it 'should allow shorthand expressions'209- $(['foo', 'bar']).any('a.length > 2').should.be_true210- end211- end212- 213- describe '#select()'214- it 'should return values which evaluate to true'215- var result = $([1,2,3,4,5]).select(function(n){ return n % 2 })216- result.at(0).should.eql 1217- result.at(1).should.eql 3218- result.at(2).should.eql 5219- end220- 221- it 'should return a Collection'222- var result = $([1,2,3,4,5]).select(function(n){ return n % 2 })223- result.should.be_an_instance_of Collection224- end225- 226- it 'should allow shorthand expressions'227- $([1,2,3,4,5]).select('a % 2').toArray().should.eql [1,3,5]228- end229- end230- 231- describe '#reject()'232- it 'should return values which evaluate to false'233- var result = $([1,2,3,4,5,6]).reject(function(n){ return n % 2 })234- result.at(0).should.eql 2235- result.at(1).should.eql 4236- result.at(2).should.eql 6237- end238- 239- it 'should return a Collection'240- var result = $([1,2,3,4,5]).reject(function(n){ return n % 2 })241- result.should.be_an_instance_of Collection242- end243- 244- it 'should allow shorthand expressions'245- $(['foo', 'bar']).reject('a.charAt(0) == "b"').toArray().should.eql ['foo']246- end247- end248- 249- describe '#slice()'250- it 'should return a slice of values'251- var collection = $(['foo', 'bar', 'baz']).slice(1, 3)252- collection.at(0).should.eql 'bar'253- collection.at(1).should.eql 'baz'254- end255- 256- it 'should work with objects'257- var collection = $({ foo: 1, bar: 2, baz: 3, raz: 4 }).slice(1, 3)258- collection.at(0).should.eql 2259- collection.at(1).should.eql 3 260- end261- end262- 263- describe '#grep()'264- it 'should select values matching the regular expression passed'265- var result = $(['foo', 'bar', 'foobar', 'baz']).grep(/foo(bar)?/)266- result.at(0).should.eql 'foo'267- result.at(1).should.eql 'foobar'268- result.at(2).should.be_null269- end270- end271- 272- describe '#keys()'273- it 'should return indices when array-like'274- $(['foo', 'bar']).keys().at(0).should.eql '0'275- $(['foo', 'bar']).keys().at(1).should.eql '1'276- end277- 278- it 'should return keys when an object'279- $({ foo: 'bar', baz: 'raz' }).keys().at(0).should.eql 'foo'280- $({ foo: 'bar', baz: 'raz' }).keys().at(1).should.eql 'baz'281- end282- end283- 284- describe '#toArray()'285- it 'should return an array'286- $(['foo', 'bar']).keys().toArray().should.eql ['0', '1']287- end288- 289- it 'should work on nested collections'290- $([$(['foo']), $(['bar'])]).toArray().should.eql [['foo'], ['bar']]291- end292- 293- it 'should work with objects'294- $({ foo: 'bar', baz: { name: 'wahoo' }}).toArray().should.eql ['bar', { name: 'wahoo' }]295- end296- end297- 298- describe '#min()'299- it 'should return the min value'300- $([4,5,2,3,62]).min().should.eql 2301- end302- end303- 304- describe '#max()'305- it 'should return the max value'306- $([3,5,2,3,43,2]).max().should.eql 43307- end308- end309- 310- describe '#length()'311- it 'should work with arrays'312- $([1,2,3]).length().should.eql 3313- end314- 315- it 'should work with objects'316- $({ a: 'b', c: 'd', e: 'f' }).length().should.eql 3317- end318- end319- 320- describe '#chunk()'321- it 'should group into chunks of the given size'322- $([1,1,2,2,3,3]).chunk(2).toArray().should.eql [[1,1],[2,2],[3,3]]323- $([1,1,2,2,3,3]).chunk(4).toArray().should.eql [[1,1,2,2],[3,3]]324- end325- end326- 327- describe '#sum()'328- it 'should return the sum of the numeric values'329- $([1,2,3]).sum().should.eql 6330- end331- end332- 333- describe '#avg()'334- it 'should return the average of numeric values'335- $([3,1]).avg().should.eql 2336- end337- end338- 339- describe '#merge()'340- it 'should merge two array collections'341- var a = $([1,2,3])342- var b = $([4,5,6])343- a.merge(b).toArray().should.eql [1,2,3,4,5,6]344- 345- var a = $([1,2,3])346- var b = [4,5,6]347- a.merge(b).toArray().should.eql [1,2,3,4,5,6]348- end349- 350- it 'should merge two object collections'351- var a = $({ a: 'b' })352- var b = $({ c: 'd' })353- a.merge(b).arr.should.eql { a: 'b', c: 'd' }354- 355- var a = $({ a: 'b' })356- var b = { c: 'd' }357- a.merge(b).arr.should.eql { a: 'b', c: 'd' }358- end359- 360- it 'should merge an array and object collection'361- var a = $([1,2])362- var b = $({ a: 'b', c: 'd' })363- a.merge(b).arr.should.eql [1, 2, 'b', 'd']364- 365- var a = $([1,2])366- var b = { a: 'b', c: 'd' }367- a.merge(b).arr.should.eql [1, 2, 'b', 'd']368- end369- 370- it 'should merge an object and array collection'371- var a = $({ a: 'b', c: 'd' })372- var b = $([1,2])373- a.merge(b).arr.should.eql { a: 'b', c: 'd', 0: 1, 1: 2 }374- 375- var a = $({ a: 'b', c: 'd' })376- var b = [1,2]377- a.merge(b).arr.should.eql { a: 'b', c: 'd', 0: 1, 1: 2 }378- end379- end380- 381- describe '#clone()'382- it 'should clone an array collection'383- var a = $([1,2,3])384- var b = a.clone()385- a.should.not.equal b386- b.arr.should.eql [1,2,3]387- b.arr.should.not.equal a.arr388- end389- 390- it 'should clone an object collection'391- var a = $({ foo: 'bar' })392- var b = a.clone()393- a.should.not.equal b394- b.arr.should.eql { foo: 'bar' }395- b.arr.should.not.equal a.arr396- end397- end398- 399- describe '#sample()'400- it 'should return a random value'401- Math.stub('random').and_return(0.1)402- $([1,2,3,4]).sample().should.eql 1403- end404- end405- 406- describe '#reverse()'407- it 'should reverse a collection'408- $([1,2,3]).reverse().toArray().should.eql [3,2,1]409- end410- end411- 412- describe '#sort()'413- it 'should sort a collection'414- $([3,1,2]).sort().toArray().should.eql [1,2,3]415- end416- 417- it 'should sort with a function'418- $([3,1,2]).sort(function(a, b){ return b - a }).toArray().should.eql [3,2,1]419- end420- 421- it 'should allow shorthand expressions'422- $([3,1,2]).sort('-').toArray().should.eql [1,2,3]423- end424- end425- 426- describe '#join()'427- it 'should join a collection with "" by default'428- $([1,2,3]).join().should.eql '123'429- end430- 431- it 'should join with an arbitrary string'432- $([1,2,3]).join(' ').should.eql '1 2 3'433- end434- 435- it 'should work with objects'436- $({ foo: 'bar', baz: 'raz' }).join(' ').should.eql 'bar raz'437- end438- end439- 440- describe '#includes()'441- it 'should return true when the value is present'442- $([1,2,3]).includes(2).should.be_true443- end444- 445- it 'should return true when all values are present'446- $([1,2,3]).includes(2, 3).should.be_true447- end448- 449- it 'should return false when the value is not present'450- $([1,2,3]).includes(4).should.be_false451- end452- 453- it 'should return false when the any value is not present'454- $([1,2,3]).includes(1,2,4).should.be_false455- $([1,2,3]).includes(1,4,2).should.be_false456- end457- end458- 459- describe '#toString()'460- it 'should output [Collection ...] for array'461- $([1,2,3]).toString().should.eql '[Collection 1,2,3]'462- end463- 464- it 'should output [Collection [object Object]] for object'465- $({ foo: "bar" }).toString().should.eql '[Collection [object Object]]'466- end467- 468- it 'should output [Collection [[Collection ...]]] for nested collections'469- $([$([1,2,3])]).toString().should.eql '[Collection [Collection 1,2,3]]'470- end471- end472- 473- end474-endmodified:spec/spec.utils.js+2 added-36 removed
2 unmodified lines3 before4 utils = require('express/utils')5 end6 7- describe 'toArray()'8- describe 'when given an array'9- it 'should return the array'10- utils.toArray([1,2,3]).should.eql [1,2,3]11- end12- end13- 14- describe 'when given an object with indexed values and length'15- it 'should return an array'16- var args = -{ return arguments }('foo', 'bar')17- utils.toArray(args).should.eql ['foo', 'bar']18- end19- end20- end21- 7 describe 'escape()'8 it 'should escape html'9 utils.escape('<p>this & that').should.eql '<p>this & that'10 end5 unmodified lines16 utils.uid().length.should.be_greater_than 2017 end18 end19 35- describe 'extname()'36- it 'should return the a files extension'37- utils.extname('image.png').should.eql 'png'38- utils.extname('image.large.png').should.eql 'png'39- utils.extname('/path/to/image.large.png').should.eql 'png'40- end41- 42- it 'should return null when not found'43- utils.extname('path').should.be_null44- utils.extname('/just/a/path').should.be_null45- end46- end47- 48- describe 'basename()'49- it 'should return a files basename'50- utils.basename('foo/bar/baz.image.png').should.eql 'baz.image.png'51- end52- end53- 20 describe 'mergeParam()'21 describe 'with empty params'22 it 'should merge the given key and value'23 params = {}58- utils.mergeParam('user[names][first]', 'tj', params)59- params.user.names.first.should.eql 'tj'24+ utils.mergeParam('user[names][firstName]', 'tj', params)25+ params.user.names.firstName.should.eql 'tj'26 end27 end28 29 describe 'with populated params'75 unmodified linesmodified:.gitmodules+3 added
5 unmodified lines6 url = git://github.com/visionmedia/js-oo.git7 [submodule "lib/support/sass"]8 path = lib/support/sass9 url = git://github.com/visionmedia/sass.js.git10+[submodule "lib/support/ext"]11+ path = lib/support/ext12+ url = git://github.com/visionmedia/ext.js.gitmodified:History.md+12 added
1 2+0.5.0 / 2010-03-103+==================4+5+ * Added ext dependency (library of js extensions)6+ * Removed extname() / basename() utils. Use path module7+ * Removed toArray() util. Use arguments.values8+ * Removed escapeRegexp() util. Use RegExp.escape()9+ * Removed process.mixin() dependency. Use utils.mixin()10+ * Removed Collection11+ * Removed ElementCollection12+ * Shameless self promotion of ebook "Advanced JavaScript" (http://dev-mag.com) ;)13+14 0.4.0 / 2010-02-1115 ==================16 17 * Added flash() example to sample upload app78 unmodified linesmodified:Makefile+2 added-6 removed
4 unmodified lines5 6 init:7 @git submodule init && git submodule update8 9-test: init9+test:10 @$(NODE) spec/node.js all11 12 app: app-chat13 2 unmodified lines16 17 app-upload:18 @$(NODE) examples/upload/app.js19 20-benchmark:21- @$(NODE) benchmarks/collection.js22- @$(NODE) benchmarks/views.js23- 24-.PHONY: init test benchmark app20+.PHONY: init test appmodified:Readme.md+7 added-16 removed
12 unmodified lines13 * High performance14 * Session support15 * Mime helpers16 * Redirection helpers17- * Nested parameter parsing18- * Full test coverage19- * Extremely readable specs17+ * Multipart file upload support18 * Test helpers (mock requests etc)19 * Environment based configuration20 * Light-weight JavaScript class implementation via js-oo23- * Collections and chainable iterators21 * View support (ejs, haml, sass, etc)22+ * Full test coverage23+ * Extremely readable specs24 25 ## Installation26 27 Currently Express must be cloned (or downloaded), you can use the following command to41 unmodified lines69 run()70 71 ## Running Tests72 73+First we need to ensure all submodules are updated:74+ 75+ $ make init76+77 Express uses the [JSpec](http://jspec.info) BDD JavaScript testing78 framework to write and run elegant spec suites. JSpec is frozen 79 to spec/lib and does not require separate installation.80 78-To run all specifications run the following command. This will ensure79-git submodules are initialized and updated, as well as building test80-related dependencies such as libxmljs.81-81 $ make test82 84-To run independent specs (which do not require building of external apis etc) use:85-86- $ make test-independant87- 88-To run dependent specs (which require building of external apis etc) use:89-90- $ make test-dependant91- 83 Run individual suites:84 85 $ node spec/node.js core86 $ node spec/node.js mime44 unmodified lines