Skip to content

Commit

Permalink
updated underscore to 1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolaus Graf committed Aug 1, 2011
1 parent 47d2ce3 commit b8fe40f
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 42 deletions.
2 changes: 1 addition & 1 deletion template/base/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies:
- ConsoleDummy.js
- jquery-1.6.2.js
- underscore-1.1.6.js
- underscore-1.1.7.js
- backbone-master.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Underscore.js 1.1.6
// Underscore.js 1.1.7
// (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore is freely distributable under the MIT license.
// Portions of Underscore are inspired or borrowed from Prototype,
Expand Down Expand Up @@ -55,25 +55,26 @@
module.exports = _;
_._ = _;
} else {
root._ = _;
// Exported as a string, for Closure Compiler "advanced" mode.
root['_'] = _;
}

// Current version.
_.VERSION = '1.1.6';
_.VERSION = '1.1.7';

// Collection Functions
// --------------------

// The cornerstone, an `each` implementation, aka `forEach`.
// Handles objects implementing `forEach`, arrays, and raw objects.
// Handles objects with the built-in `forEach`, arrays, and raw objects.
// Delegates to **ECMAScript 5**'s native `forEach` if available.
var each = _.each = _.forEach = function(obj, iterator, context) {
if (obj == null) return;
if (nativeForEach && obj.forEach === nativeForEach) {
obj.forEach(iterator, context);
} else if (_.isNumber(obj.length)) {
} else if (obj.length === +obj.length) {
for (var i = 0, l = obj.length; i < l; i++) {
if (iterator.call(context, obj[i], i, obj) === breaker) return;
if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) return;
}
} else {
for (var key in obj) {
Expand Down Expand Up @@ -106,7 +107,7 @@
return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
}
each(obj, function(value, index, list) {
if (!initial && index === 0) {
if (!initial) {
memo = value;
initial = true;
} else {
Expand Down Expand Up @@ -181,14 +182,14 @@
// Delegates to **ECMAScript 5**'s native `some` if available.
// Aliased as `any`.
var any = _.some = _.any = function(obj, iterator, context) {
iterator || (iterator = _.identity);
iterator = iterator || _.identity;
var result = false;
if (obj == null) return result;
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
each(obj, function(value, index, list) {
if (result = iterator.call(context, value, index, list)) return breaker;
if (result |= iterator.call(context, value, index, list)) return breaker;
});
return result;
return !!result;
};

// Determine if a given value is included in the array or object using `===`.
Expand Down Expand Up @@ -251,6 +252,16 @@
}), 'value');
};

// Groups the object's values by a criterion produced by an iterator
_.groupBy = function(obj, iterator) {
var result = {};
each(obj, function(value, index) {
var key = iterator(value, index);
(result[key] || (result[key] = [])).push(value);
});
return result;
};

// Use a comparator function to figure out at what index an object should
// be inserted so as to maintain order. Uses binary search.
_.sortedIndex = function(array, obj, iterator) {
Expand All @@ -267,7 +278,7 @@
_.toArray = function(iterable) {
if (!iterable) return [];
if (iterable.toArray) return iterable.toArray();
if (_.isArray(iterable)) return iterable;
if (_.isArray(iterable)) return slice.call(iterable);
if (_.isArguments(iterable)) return slice.call(iterable);
return _.values(iterable);
};
Expand Down Expand Up @@ -316,8 +327,7 @@

// Return a version of the array that does not contain the specified value(s).
_.without = function(array) {
var values = slice.call(arguments, 1);
return _.filter(array, function(value){ return !_.include(values, value); });
return _.difference(array, slice.call(arguments, 1));
};

// Produce a duplicate-free version of the array. If the array has already
Expand All @@ -330,9 +340,15 @@
}, []);
};

// Produce an array that contains the union: each distinct element from all of
// the passed-in arrays.
_.union = function() {
return _.uniq(_.flatten(arguments));
};

// Produce an array that contains every item shared between all the
// passed-in arrays.
_.intersect = function(array) {
// passed-in arrays. (Aliased as "intersect" for back-compat.)
_.intersection = _.intersect = function(array) {
var rest = slice.call(arguments, 1);
return _.filter(_.uniq(array), function(item) {
return _.every(rest, function(other) {
Expand All @@ -341,6 +357,12 @@
});
};

// Take the difference between one array and another.
// Only the elements present in just the first array will remain.
_.difference = function(array, other) {
return _.filter(array, function(value){ return !_.include(other, value); });
};

// Zip together multiple lists into a single array -- elements that share
// an index go together.
_.zip = function() {
Expand Down Expand Up @@ -502,7 +524,7 @@
var funcs = slice.call(arguments);
return function() {
var args = slice.call(arguments);
for (var i=funcs.length-1; i >= 0; i--) {
for (var i = funcs.length - 1; i >= 0; i--) {
args = [funcs[i].apply(this, args)];
}
return args[0];
Expand Down Expand Up @@ -537,7 +559,11 @@
// Return a sorted list of the function names available on the object.
// Aliased as `methods`
_.functions = _.methods = function(obj) {
return _.filter(_.keys(obj), function(key){ return _.isFunction(obj[key]); }).sort();
var names = [];
for (var key in obj) {
if (_.isFunction(obj[key])) names.push(key);
}
return names.sort();
};

// Extend a given object with all the properties in passed-in object(s).
Expand Down Expand Up @@ -589,6 +615,7 @@
if (b._chain) b = b._wrapped;
// One of them implements an isEqual()?
if (a.isEqual) return a.isEqual(b);
if (b.isEqual) return b.isEqual(a);
// Check dates' integer values.
if (_.isDate(a) && _.isDate(b)) return a.getTime() === b.getTime();
// Both are NaN?
Expand Down Expand Up @@ -630,6 +657,11 @@
return toString.call(obj) === '[object Array]';
};

// Is a given variable an object?
_.isObject = function(obj) {
return obj === Object(obj);
};

// Is a given variable an arguments object?
_.isArguments = function(obj) {
return !!(obj && hasOwnProperty.call(obj, 'callee'));
Expand Down
2 changes: 1 addition & 1 deletion template/express/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies:
- ConsoleDummy.js
- jquery-1.6.2.js
- underscore-1.1.6.js
- underscore-1.1.7.js
- backbone-master.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Underscore.js 1.1.6
// Underscore.js 1.1.7
// (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore is freely distributable under the MIT license.
// Portions of Underscore are inspired or borrowed from Prototype,
Expand Down Expand Up @@ -55,25 +55,26 @@
module.exports = _;
_._ = _;
} else {
root._ = _;
// Exported as a string, for Closure Compiler "advanced" mode.
root['_'] = _;
}

// Current version.
_.VERSION = '1.1.6';
_.VERSION = '1.1.7';

// Collection Functions
// --------------------

// The cornerstone, an `each` implementation, aka `forEach`.
// Handles objects implementing `forEach`, arrays, and raw objects.
// Handles objects with the built-in `forEach`, arrays, and raw objects.
// Delegates to **ECMAScript 5**'s native `forEach` if available.
var each = _.each = _.forEach = function(obj, iterator, context) {
if (obj == null) return;
if (nativeForEach && obj.forEach === nativeForEach) {
obj.forEach(iterator, context);
} else if (_.isNumber(obj.length)) {
} else if (obj.length === +obj.length) {
for (var i = 0, l = obj.length; i < l; i++) {
if (iterator.call(context, obj[i], i, obj) === breaker) return;
if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) return;
}
} else {
for (var key in obj) {
Expand Down Expand Up @@ -106,7 +107,7 @@
return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
}
each(obj, function(value, index, list) {
if (!initial && index === 0) {
if (!initial) {
memo = value;
initial = true;
} else {
Expand Down Expand Up @@ -181,14 +182,14 @@
// Delegates to **ECMAScript 5**'s native `some` if available.
// Aliased as `any`.
var any = _.some = _.any = function(obj, iterator, context) {
iterator || (iterator = _.identity);
iterator = iterator || _.identity;
var result = false;
if (obj == null) return result;
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
each(obj, function(value, index, list) {
if (result = iterator.call(context, value, index, list)) return breaker;
if (result |= iterator.call(context, value, index, list)) return breaker;
});
return result;
return !!result;
};

// Determine if a given value is included in the array or object using `===`.
Expand Down Expand Up @@ -251,6 +252,16 @@
}), 'value');
};

// Groups the object's values by a criterion produced by an iterator
_.groupBy = function(obj, iterator) {
var result = {};
each(obj, function(value, index) {
var key = iterator(value, index);
(result[key] || (result[key] = [])).push(value);
});
return result;
};

// Use a comparator function to figure out at what index an object should
// be inserted so as to maintain order. Uses binary search.
_.sortedIndex = function(array, obj, iterator) {
Expand All @@ -267,7 +278,7 @@
_.toArray = function(iterable) {
if (!iterable) return [];
if (iterable.toArray) return iterable.toArray();
if (_.isArray(iterable)) return iterable;
if (_.isArray(iterable)) return slice.call(iterable);
if (_.isArguments(iterable)) return slice.call(iterable);
return _.values(iterable);
};
Expand Down Expand Up @@ -316,8 +327,7 @@

// Return a version of the array that does not contain the specified value(s).
_.without = function(array) {
var values = slice.call(arguments, 1);
return _.filter(array, function(value){ return !_.include(values, value); });
return _.difference(array, slice.call(arguments, 1));
};

// Produce a duplicate-free version of the array. If the array has already
Expand All @@ -330,9 +340,15 @@
}, []);
};

// Produce an array that contains the union: each distinct element from all of
// the passed-in arrays.
_.union = function() {
return _.uniq(_.flatten(arguments));
};

// Produce an array that contains every item shared between all the
// passed-in arrays.
_.intersect = function(array) {
// passed-in arrays. (Aliased as "intersect" for back-compat.)
_.intersection = _.intersect = function(array) {
var rest = slice.call(arguments, 1);
return _.filter(_.uniq(array), function(item) {
return _.every(rest, function(other) {
Expand All @@ -341,6 +357,12 @@
});
};

// Take the difference between one array and another.
// Only the elements present in just the first array will remain.
_.difference = function(array, other) {
return _.filter(array, function(value){ return !_.include(other, value); });
};

// Zip together multiple lists into a single array -- elements that share
// an index go together.
_.zip = function() {
Expand Down Expand Up @@ -502,7 +524,7 @@
var funcs = slice.call(arguments);
return function() {
var args = slice.call(arguments);
for (var i=funcs.length-1; i >= 0; i--) {
for (var i = funcs.length - 1; i >= 0; i--) {
args = [funcs[i].apply(this, args)];
}
return args[0];
Expand Down Expand Up @@ -537,7 +559,11 @@
// Return a sorted list of the function names available on the object.
// Aliased as `methods`
_.functions = _.methods = function(obj) {
return _.filter(_.keys(obj), function(key){ return _.isFunction(obj[key]); }).sort();
var names = [];
for (var key in obj) {
if (_.isFunction(obj[key])) names.push(key);
}
return names.sort();
};

// Extend a given object with all the properties in passed-in object(s).
Expand Down Expand Up @@ -589,6 +615,7 @@
if (b._chain) b = b._wrapped;
// One of them implements an isEqual()?
if (a.isEqual) return a.isEqual(b);
if (b.isEqual) return b.isEqual(a);
// Check dates' integer values.
if (_.isDate(a) && _.isDate(b)) return a.getTime() === b.getTime();
// Both are NaN?
Expand Down Expand Up @@ -630,6 +657,11 @@
return toString.call(obj) === '[object Array]';
};

// Is a given variable an object?
_.isObject = function(obj) {
return obj === Object(obj);
};

// Is a given variable an arguments object?
_.isArguments = function(obj) {
return !!(obj && hasOwnProperty.call(obj, 'callee'));
Expand Down
8 changes: 4 additions & 4 deletions test/collectDependencies.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = testCase(
options.dependencies = [
'ConsoleDummy.js',
'jquery-1.6.2.js',
'underscore-1.1.6.js',
'underscore-1.1.7.js',
'backbone-master.js'
]
options.brunchPath = 'test/fixtures/base'
Expand All @@ -22,7 +22,7 @@ module.exports = testCase(
test.deepEqual dependencyPaths, [
'test/fixtures/base/src/vendor/ConsoleDummy.js',
'test/fixtures/base/src/vendor/jquery-1.6.2.js',
'test/fixtures/base/src/vendor/underscore-1.1.6.js',
'test/fixtures/base/src/vendor/underscore-1.1.7.js',
'test/fixtures/base/src/vendor/backbone-master.js'
]
test.done()
Expand All @@ -33,7 +33,7 @@ module.exports = testCase(
options.dependencies = [
'ConsoleDummy.js',
'jquery-1.6.2.js',
'underscore-1.1.6.js',
'underscore-1.1.7.js',
'backbone-master.js',
'backbone-localstorage.js'
]
Expand All @@ -45,7 +45,7 @@ module.exports = testCase(
test.deepEqual dependencyPaths, [
'test/fixtures/alternate_vendor/ConsoleDummy.js',
'test/fixtures/alternate_vendor/jquery-1.6.2.js',
'test/fixtures/alternate_vendor/underscore-1.1.6.js',
'test/fixtures/alternate_vendor/underscore-1.1.7.js',
'test/fixtures/alternate_vendor/backbone-master.js',
'test/fixtures/alternate_vendor/backbone-localstorage.js'
]
Expand Down
Loading

0 comments on commit b8fe40f

Please sign in to comment.