Capitalize and punctuate comments. [ci skip]

This commit is contained in:
John-David Dalton
2014-11-13 00:46:03 -08:00
parent 212eea9cf5
commit ef7db87b82

236
lodash.js
View File

@@ -621,7 +621,7 @@
} }
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
// that causes it, under certain circumstances, to provide the same value // that causes it, under certain circumstances, to provide the same value
// for `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247 // for `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247.
// //
// This also ensures a stable sort in V8 and other engines. // This also ensures a stable sort in V8 and other engines.
// See https://code.google.com/p/v8/issues/detail?id=90. // See https://code.google.com/p/v8/issues/detail?id=90.
@@ -699,8 +699,8 @@
return function() { return false; }; return function() { return false; };
} }
return function(value) { return function(value) {
// IE < 9 presents many host objects as `Object` objects that can coerce to // IE < 9 presents many host objects as `Object` objects that can coerce
// strings despite having improperly defined `toString` methods // to strings despite having improperly defined `toString` methods.
return typeof value.toString != 'function' && typeof (value + '') == 'string'; return typeof value.toString != 'function' && typeof (value + '') == 'string';
}; };
}()); }());
@@ -920,7 +920,7 @@
var Float64Array = (function() { var Float64Array = (function() {
// Safari 5 errors when using an array buffer to initialize a typed array // Safari 5 errors when using an array buffer to initialize a typed array
// where the array buffer's `byteLength` is not a multiple of the typed // where the array buffer's `byteLength` is not a multiple of the typed
// array's `BYTES_PER_ELEMENT` // array's `BYTES_PER_ELEMENT`.
try { try {
var func = isNative(func = context.Float64Array) && func, var func = isNative(func = context.Float64Array) && func,
result = new func(new ArrayBuffer(10), 0, 1) && func; result = new func(new ArrayBuffer(10), 0, 1) && func;
@@ -1706,13 +1706,13 @@
data = !reFuncName.test(source); data = !reFuncName.test(source);
} }
if (!data) { if (!data) {
// checks if `func` references the `this` keyword and stores the result // Check if `func` references the `this` keyword and store the result.
data = reThis.test(source) || isNative(func); data = reThis.test(source) || isNative(func);
baseSetData(func, data); baseSetData(func, data);
} }
} }
} }
// exit early if there are no `this` references or `func` is bound // Exit early if there are no `this` references or `func` is bound.
if (data === false || (data !== true && data[1] & BIND_FLAG)) { if (data === false || (data !== true && data[1] & BIND_FLAG)) {
return func; return func;
} }
@@ -1737,7 +1737,7 @@
if (func == null) { if (func == null) {
return identity; return identity;
} }
// handle "_.pluck" and "_.where" style callback shorthands // Handle "_.pluck" and "_.where" style callback shorthands.
return type == 'object' ? matches(func) : property(func); return type == 'object' ? matches(func) : property(func);
} }
@@ -1779,7 +1779,7 @@
if (!isDeep || result === value) { if (!isDeep || result === value) {
return result; return result;
} }
// check for circular references and return corresponding clone // Check for circular references and return corresponding clone.
stackA || (stackA = []); stackA || (stackA = []);
stackB || (stackB = []); stackB || (stackB = []);
@@ -1789,12 +1789,11 @@
return stackB[length]; return stackB[length];
} }
} }
// add the source value to the stack of traversed objects // Add the source value to the stack of traversed objects and associate it with its clone.
// and associate it with its clone
stackA.push(value); stackA.push(value);
stackB.push(result); stackB.push(result);
// recursively populate clone (susceptible to call stack limits) // Recursively populate clone (susceptible to call stack limits).
(isArr ? arrayEach : baseForOwn)(value, function(subValue, key) { (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB); result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
}); });
@@ -1812,7 +1811,7 @@
function baseCreate(prototype) { function baseCreate(prototype) {
return isObject(prototype) ? nativeCreate(prototype) : {}; return isObject(prototype) ? nativeCreate(prototype) : {};
} }
// fallback for environments without `Object.create` // Fallback for environments without `Object.create`.
if (!nativeCreate) { if (!nativeCreate) {
baseCreate = (function() { baseCreate = (function() {
function Object() {} function Object() {}
@@ -2009,7 +2008,7 @@
if (value && typeof value == 'object' && typeof value.length == 'number' if (value && typeof value == 'object' && typeof value.length == 'number'
&& (isArray(value) || isArguments(value))) { && (isArray(value) || isArguments(value))) {
// recursively flatten arrays (susceptible to call stack limits) // Recursively flatten arrays (susceptible to call stack limits).
if (isDeep) { if (isDeep) {
value = baseFlatten(value, isDeep, isStrict); value = baseFlatten(value, isDeep, isStrict);
} }
@@ -2159,15 +2158,15 @@
if (typeof result != 'undefined') { if (typeof result != 'undefined') {
return !!result; return !!result;
} }
// exit early for identical values // Exit early for identical values.
if (value === other) { if (value === other) {
// treat `+0` vs. `-0` as not equal // Treat `+0` vs. `-0` as not equal.
return value !== 0 || (1 / value == 1 / other); return value !== 0 || (1 / value == 1 / other);
} }
var valType = typeof value, var valType = typeof value,
othType = typeof other; othType = typeof other;
// exit early for unlike primitive values // Exit early for unlike primitive values.
if (!(valType == 'number' && othType == 'number') && (value == null || other == null || if (!(valType == 'number' && othType == 'number') && (value == null || other == null ||
(valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object'))) { (valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object'))) {
return false; return false;
@@ -2198,7 +2197,7 @@
} }
} }
else { else {
// unwrap any `lodash` wrapped values // Unwrap `lodash` wrapped values.
var valWrapped = valIsObj && hasOwnProperty.call(value, '__wrapped__'), var valWrapped = valIsObj && hasOwnProperty.call(value, '__wrapped__'),
othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
@@ -2213,12 +2212,12 @@
valIsArg = isArguments(value); valIsArg = isArguments(value);
othIsArg = isArguments(other); othIsArg = isArguments(other);
} }
// in older versions of Opera, `arguments` objects have `Array` constructors // In older versions of Opera, `arguments` objects have `Array` constructors.
var valCtor = valIsArg ? Object : value.constructor, var valCtor = valIsArg ? Object : value.constructor,
othCtor = othIsArg ? Object : other.constructor; othCtor = othIsArg ? Object : other.constructor;
if (valIsErr) { if (valIsErr) {
// error objects of different types are not equal // Error objects of different types are not equal.
if (valCtor.prototype.name != othCtor.prototype.name) { if (valCtor.prototype.name != othCtor.prototype.name) {
return false; return false;
} }
@@ -2231,7 +2230,7 @@
return false; return false;
} }
if (!valHasCtor) { if (!valHasCtor) {
// non `Object` object instances with different constructors are not equal // Non `Object` object instances with different constructors are not equal.
if (valCtor != othCtor && ('constructor' in value && 'constructor' in other) && if (valCtor != othCtor && ('constructor' in value && 'constructor' in other) &&
!(typeof valCtor == 'function' && valCtor instanceof valCtor && !(typeof valCtor == 'function' && valCtor instanceof valCtor &&
typeof othCtor == 'function' && othCtor instanceof othCtor)) { typeof othCtor == 'function' && othCtor instanceof othCtor)) {
@@ -2258,29 +2257,29 @@
switch (valClass) { switch (valClass) {
case boolClass: case boolClass:
case dateClass: case dateClass:
// coerce dates and booleans to numbers, dates to milliseconds and booleans // Coerce dates and booleans to numbers, dates to milliseconds and booleans
// to `1` or `0` treating invalid dates coerced to `NaN` as not equal // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
return +value == +other; return +value == +other;
case numberClass: case numberClass:
// treat `NaN` vs. `NaN` as equal // Treat `NaN` vs. `NaN` as equal.
return (value != +value) return (value != +value)
? other != +other ? other != +other
// but treat `-0` vs. `+0` as not equal // But, treat `-0` vs. `+0` as not equal.
: (value == 0 ? ((1 / value) == (1 / other)) : value == +other); : (value == 0 ? ((1 / value) == (1 / other)) : value == +other);
case regexpClass: case regexpClass:
case stringClass: case stringClass:
// coerce regexes to strings (http://es5.github.io/#x15.10.6.4) and // Coerce regexes to strings (http://es5.github.io/#x15.10.6.4) and
// treat strings primitives and string objects as equal // treat strings primitives and string objects as equal.
return value == String(other); return value == String(other);
} }
return false; return false;
} }
} }
// assume cyclic structures are equal // Assume cyclic structures are equal.
// the algorithm for detecting cyclic structures is adapted from ES 5.1 // The algorithm for detecting cyclic structures is adapted from ES 5.1
// section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3) // section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3).
stackA || (stackA = []); stackA || (stackA = []);
stackB || (stackB = []); stackB || (stackB = []);
@@ -2290,14 +2289,14 @@
return stackB[index] == other; return stackB[index] == other;
} }
} }
// add `value` and `other` to the stack of traversed objects // Add `value` and `other` to the stack of traversed objects.
stackA.push(value); stackA.push(value);
stackB.push(other); stackB.push(other);
// recursively compare objects and arrays (susceptible to call stack limits) // Recursively compare objects and arrays (susceptible to call stack limits).
result = true; result = true;
if (valIsArr) { if (valIsArr) {
// deep compare the contents, ignoring non-numeric properties // Deep compare the contents, ignoring non-numeric properties.
while (result && ++index < valLength) { while (result && ++index < valLength) {
var valValue = value[index]; var valValue = value[index];
if (isWhere) { if (isWhere) {
@@ -2413,7 +2412,7 @@
} }
return; return;
} }
// avoid merging previously merged cyclic sources // Avoid merging previously merged cyclic sources.
stackA || (stackA = []); stackA || (stackA = []);
stackB || (stackB = []); stackB || (stackB = []);
@@ -2432,12 +2431,12 @@
? (isArray(value) ? value : []) ? (isArray(value) ? value : [])
: (isPlainObject(value) ? value : {}); : (isPlainObject(value) ? value : {});
} }
// add the source value to the stack of traversed objects // Add the source value to the stack of traversed objects and associate
// and associate it with its merged value // it with its merged value.
stackA.push(srcValue); stackA.push(srcValue);
stackB.push(result); stackB.push(result);
// recursively merge objects and arrays (susceptible to call stack limits) // Recursively merge objects and arrays (susceptible to call stack limits).
if (isDeep) { if (isDeep) {
baseMerge(result, srcValue, customizer, stackA, stackB); baseMerge(result, srcValue, customizer, stackA, stackB);
} }
@@ -2667,7 +2666,7 @@
return bufferSlice.call(buffer, 0); return bufferSlice.call(buffer, 0);
} }
if (!bufferSlice) { if (!bufferSlice) {
// PhantomJS has `ArrayBuffer` and `Uint8Array` but not `Float64Array` // PhantomJS has `ArrayBuffer` and `Uint8Array` but not `Float64Array`.
bufferClone = !(ArrayBuffer && Uint8Array) ? identity : function(buffer) { bufferClone = !(ArrayBuffer && Uint8Array) ? identity : function(buffer) {
var byteLength = buffer.byteLength, var byteLength = buffer.byteLength,
floatLength = Float64Array ? floor(byteLength / FLOAT64_BYTES_PER_ELEMENT) : 0, floatLength = Float64Array ? floor(byteLength / FLOAT64_BYTES_PER_ELEMENT) : 0,
@@ -2813,7 +2812,7 @@
if (length > 3 && isIterateeCall(arguments[1], arguments[2], arguments[3])) { if (length > 3 && isIterateeCall(arguments[1], arguments[2], arguments[3])) {
length = 2; length = 2;
} }
// juggle arguments // Juggle arguments.
if (length > 3 && typeof arguments[length - 2] == 'function') { if (length > 3 && typeof arguments[length - 2] == 'function') {
var customizer = baseCallback(arguments[--length - 1], arguments[length--], 5); var customizer = baseCallback(arguments[--length - 1], arguments[length--], 5);
} else if (length > 2 && typeof arguments[length - 1] == 'function') { } else if (length > 2 && typeof arguments[length - 1] == 'function') {
@@ -2891,8 +2890,8 @@
var thisBinding = baseCreate(Ctor.prototype), var thisBinding = baseCreate(Ctor.prototype),
result = Ctor.apply(thisBinding, arguments); result = Ctor.apply(thisBinding, arguments);
// mimic the constructor's `return` behavior // Mimic the constructor's `return` behavior.
// http://es5.github.io/#x13.2.2 // See http://es5.github.io/#x13.2.2.
return isObject(result) ? result : thisBinding; return isObject(result) ? result : thisBinding;
}; };
} }
@@ -3013,8 +3012,8 @@
Ctor = createCtorWrapper(func); Ctor = createCtorWrapper(func);
function wrapper() { function wrapper() {
// avoid `arguments` object use disqualifying optimizations by // Avoid `arguments` object use disqualifying optimizations by
// converting it to an array before providing it to `composeArgs` // converting it to an array before providing it to `composeArgs`.
var argsIndex = -1, var argsIndex = -1,
argsLength = arguments.length, argsLength = arguments.length,
leftIndex = -1, leftIndex = -1,
@@ -3085,33 +3084,33 @@
funcIsBind = funcBitmask & BIND_FLAG, funcIsBind = funcBitmask & BIND_FLAG,
isBind = bitmask & BIND_FLAG; isBind = bitmask & BIND_FLAG;
// use metadata `func` and merge bitmasks // Use metadata `func` and merge bitmasks.
func = data[0]; func = data[0];
bitmask |= funcBitmask; bitmask |= funcBitmask;
// use metadata `thisArg` if available // Use metadata `thisArg` if available.
if (funcIsBind) { if (funcIsBind) {
thisArg = data[2]; thisArg = data[2];
} }
// set if currying a bound function // Set when currying a bound function.
if (!isBind && funcIsBind) { if (!isBind && funcIsBind) {
bitmask |= CURRY_BOUND_FLAG; bitmask |= CURRY_BOUND_FLAG;
} }
// compose partial arguments // Compose partial arguments.
var value = data[3]; var value = data[3];
if (value) { if (value) {
var funcHolders = data[4]; var funcHolders = data[4];
partials = isPartial ? composeArgs(partials, value, funcHolders) : baseSlice(value); partials = isPartial ? composeArgs(partials, value, funcHolders) : baseSlice(value);
holders = isPartial ? replaceHolders(partials, PLACEHOLDER) : baseSlice(funcHolders); holders = isPartial ? replaceHolders(partials, PLACEHOLDER) : baseSlice(funcHolders);
} }
// compose partial right arguments // Compose partial right arguments.
value = data[5]; value = data[5];
if (value) { if (value) {
funcHolders = data[6]; funcHolders = data[6];
partialsRight = isPartialRight ? composeArgsRight(partialsRight, value, funcHolders) : baseSlice(value); partialsRight = isPartialRight ? composeArgsRight(partialsRight, value, funcHolders) : baseSlice(value);
holdersRight = isPartialRight ? replaceHolders(partialsRight, PLACEHOLDER) : baseSlice(funcHolders); holdersRight = isPartialRight ? replaceHolders(partialsRight, PLACEHOLDER) : baseSlice(funcHolders);
} }
// append argument positions // Append argument positions.
value = data[7]; value = data[7];
if (value) { if (value) {
value = baseSlice(value); value = baseSlice(value);
@@ -3120,7 +3119,7 @@
} }
argPos = value; argPos = value;
} }
// use metadata `arity` if not provided // Use metadata `arity` if one is not provided.
if (arity == null) { if (arity == null) {
arity = data[8]; arity = data[8];
} }
@@ -3231,7 +3230,7 @@
result[index] = array[index]; result[index] = array[index];
} }
} }
// add array properties assigned by `RegExp#exec` // Add array properties assigned by `RegExp#exec`.
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) { if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
result.index = array.index; result.index = array.index;
result.input = array.input; result.input = array.input;
@@ -3277,7 +3276,7 @@
case float32Class: case float64Class: case float32Class: case float64Class:
case int8Class: case int16Class: case int32Class: case int8Class: case int16Class: case int32Class:
case uint8Class: case uint8ClampedClass: case uint16Class: case uint32Class: case uint8Class: case uint8ClampedClass: case uint16Class: case uint32Class:
// Safari 5 mobile incorrectly has `Object` as the constructor // Safari 5 mobile incorrectly has `Object` as the constructor of typed arrays.
if (Ctor instanceof Ctor) { if (Ctor instanceof Ctor) {
Ctor = ctorByClass[className]; Ctor = ctorByClass[className];
} }
@@ -3476,7 +3475,7 @@
var Ctor, var Ctor,
support = lodash.support; support = lodash.support;
// exit early for non `Object` objects // Exit early for non `Object` objects.
if (!(value && typeof value == 'object' && if (!(value && typeof value == 'object' &&
toString.call(value) == objectClass && !isHostObject(value)) || toString.call(value) == objectClass && !isHostObject(value)) ||
(!hasOwnProperty.call(value, 'constructor') && (!hasOwnProperty.call(value, 'constructor') &&
@@ -4688,7 +4687,7 @@
if (!length) { if (!length) {
return []; return [];
} }
// juggle arguments // Juggle arguments.
if (typeof isSorted != 'boolean' && isSorted != null) { if (typeof isSorted != 'boolean' && isSorted != null) {
thisArg = iteratee; thisArg = iteratee;
iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted; iteratee = isIterateeCall(array, isSorted, thisArg) ? null : isSorted;
@@ -7080,7 +7079,7 @@
* // => 0 * // => 0
*/ */
function clone(value, isDeep, customizer, thisArg) { function clone(value, isDeep, customizer, thisArg) {
// juggle arguments // Juggle arguments.
if (typeof isDeep != 'boolean' && isDeep != null) { if (typeof isDeep != 'boolean' && isDeep != null) {
thisArg = customizer; thisArg = customizer;
customizer = isIterateeCall(value, isDeep, thisArg) ? null : isDeep; customizer = isIterateeCall(value, isDeep, thisArg) ? null : isDeep;
@@ -7158,7 +7157,7 @@
var length = (value && typeof value == 'object') ? value.length : undefined; var length = (value && typeof value == 'object') ? value.length : undefined;
return (isLength(length) && toString.call(value) == argsClass) || false; return (isLength(length) && toString.call(value) == argsClass) || false;
} }
// fallback for environments without a `[[Class]]` for `arguments` objects // Fallback for environments without a `[[Class]]` for `arguments` objects.
if (!support.argsClass) { if (!support.argsClass) {
isArguments = function(value) { isArguments = function(value) {
var length = (value && typeof value == 'object') ? value.length : undefined; var length = (value && typeof value == 'object') ? value.length : undefined;
@@ -7249,7 +7248,7 @@
return (value && typeof value == 'object' && value.nodeType === 1 && return (value && typeof value == 'object' && value.nodeType === 1 &&
(lodash.support.nodeClass ? toString.call(value).indexOf('Element') > -1 : isHostObject(value))) || false; (lodash.support.nodeClass ? toString.call(value).indexOf('Element') > -1 : isHostObject(value))) || false;
} }
// fallback for environments without DOM support // Fallback for environments without DOM support.
if (!support.dom) { if (!support.dom) {
isElement = function(value) { isElement = function(value) {
return (value && typeof value == 'object' && value.nodeType === 1 && !isPlainObject(value)) || false; return (value && typeof value == 'object' && value.nodeType === 1 && !isPlainObject(value)) || false;
@@ -7412,17 +7411,17 @@
* // => false * // => false
*/ */
function isFunction(value) { function isFunction(value) {
// Use `|| false` to avoid a Chakra bug in compatibility modes of IE 11. // Avoid a Chakra JIT bug in compatibility modes of IE 11.
// See https://github.com/jashkenas/underscore/issues/1621. // See https://github.com/jashkenas/underscore/issues/1621.
return typeof value == 'function' || false; return typeof value == 'function' || false;
} }
// fallback for environments that return incorrect `typeof` operator results // Fallback for environments that return incorrect `typeof` operator results.
if (isFunction(/x/) || !Uint8Array || !isFunction(Uint8Array)) { if (isFunction(/x/) || !Uint8Array || !isFunction(Uint8Array)) {
isFunction = function(value) { isFunction = function(value) {
// the use of `Object#toString` avoids issues with the `typeof` operator // The use of `Object#toString` avoids issues with the `typeof` operator
// in older versions of Chrome and Safari which return 'function' for // in older versions of Chrome and Safari which return 'function' for
// regexes and modern Safari which returns 'object' for typed array // regexes and modern Safari which returns 'object' for typed array
// constructors // constructors.
return toString.call(value) == funcClass; return toString.call(value) == funcClass;
}; };
} }
@@ -7450,7 +7449,7 @@
* // => false * // => false
*/ */
function isObject(value) { function isObject(value) {
// Avoid a V8 bug in Chrome 19-20. // Avoid a V8 JIT bug in Chrome 19-20.
// See https://code.google.com/p/v8/issues/detail?id=2291. // See https://code.google.com/p/v8/issues/detail?id=2291.
var type = typeof value; var type = typeof value;
return type == 'function' || (value && type == 'object') || false; return type == 'function' || (value && type == 'object') || false;
@@ -7484,7 +7483,7 @@
*/ */
function isNaN(value) { function isNaN(value) {
// `NaN` as a primitive is the only value that is not equal to itself // `NaN` as a primitive is the only value that is not equal to itself
// (perform the `[[Class]]` check first to avoid errors with some host objects in IE) // (perform the `[[Class]]` check first to avoid errors with some host objects in IE).
return isNumber(value) && value != +value; return isNumber(value) && value != +value;
} }
@@ -8137,7 +8136,7 @@
// Lo-Dash skips the `constructor` property when it infers it is iterating // Lo-Dash skips the `constructor` property when it infers it is iterating
// over a `prototype` object because IE < 9 can't set the `[[Enumerable]]` // over a `prototype` object because IE < 9 can't set the `[[Enumerable]]`
// attribute of an existing property and the `constructor` property of a // attribute of an existing property and the `constructor` property of a
// prototype defaults to non-enumerable // prototype defaults to non-enumerable.
for (var key in object) { for (var key in object) {
if (!(skipProto && key == 'prototype') && if (!(skipProto && key == 'prototype') &&
!(skipErrorProps && (key == 'message' || key == 'name')) && !(skipErrorProps && (key == 'message' || key == 'name')) &&
@@ -8582,7 +8581,7 @@
* // => 'fred, barney, &amp; pebbles' * // => 'fred, barney, &amp; pebbles'
*/ */
function escape(string) { function escape(string) {
// reset `lastIndex` because in IE < 9 `String#replace` does not // Reset `lastIndex` because in IE < 9 `String#replace` does not.
string = string == null ? '' : String(string); string = string == null ? '' : String(string);
return string && (reUnescapedHtml.lastIndex = 0, reUnescapedHtml.test(string)) return string && (reUnescapedHtml.lastIndex = 0, reUnescapedHtml.test(string))
? string.replace(reUnescapedHtml, escapeHtmlChar) ? string.replace(reUnescapedHtml, escapeHtmlChar)
@@ -8759,8 +8758,8 @@
} }
string = String(string); string = String(string);
// leverage the exponentiation by squaring algorithm for a faster repeat // Leverage the exponentiation by squaring algorithm for a faster repeat.
// http://en.wikipedia.org/wiki/Exponentiation_by_squaring // See http://en.wikipedia.org/wiki/Exponentiation_by_squaring.
do { do {
if (n % 2) { if (n % 2) {
result += string; result += string;
@@ -8920,10 +8919,8 @@
* '); * ');
*/ */
function template(string, options, otherOptions) { function template(string, options, otherOptions) {
// based on John Resig's `tmpl` implementation // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
// http://ejohn.org/blog/javascript-micro-templating/ // and Laura Doktorova's doT.js (https://github.com/olado/doT).
// and Laura Doktorova's doT.js
// https://github.com/olado/doT
var settings = lodash.templateSettings; var settings = lodash.templateSettings;
if (otherOptions && isIterateeCall(string, options, otherOptions)) { if (otherOptions && isIterateeCall(string, options, otherOptions)) {
@@ -8942,7 +8939,7 @@
interpolate = options.interpolate || reNoMatch, interpolate = options.interpolate || reNoMatch,
source = "__p += '"; source = "__p += '";
// compile the regexp to match each delimiter // Compile the regexp to match each delimiter.
var reDelimiters = RegExp( var reDelimiters = RegExp(
(options.escape || reNoMatch).source + '|' + (options.escape || reNoMatch).source + '|' +
interpolate.source + '|' + interpolate.source + '|' +
@@ -8950,18 +8947,18 @@
(options.evaluate || reNoMatch).source + '|$' (options.evaluate || reNoMatch).source + '|$'
, 'g'); , 'g');
// use a sourceURL for easier debugging // Use a sourceURL for easier debugging.
// http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl // See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl.
var sourceURL = 'sourceURL' in options ? options.sourceURL : ('/lodash/template/source[' + (++templateCounter) + ']'); var sourceURL = 'sourceURL' in options ? options.sourceURL : ('/lodash/template/source[' + (++templateCounter) + ']');
sourceURL = sourceURL ? ('\n//# sourceURL=' + sourceURL) : ''; sourceURL = sourceURL ? ('\n//# sourceURL=' + sourceURL) : '';
string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) { string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
interpolateValue || (interpolateValue = esTemplateValue); interpolateValue || (interpolateValue = esTemplateValue);
// escape characters that can't be included in string literals // Escape characters that can't be included in string literals.
source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar); source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
// replace delimiters with snippets // Replace delimiters with snippets.
if (escapeValue) { if (escapeValue) {
isEscaping = true; isEscaping = true;
source += "' +\n__e(" + escapeValue + ") +\n'"; source += "' +\n__e(" + escapeValue + ") +\n'";
@@ -8975,25 +8972,25 @@
} }
index = offset + match.length; index = offset + match.length;
// the JS engine embedded in Adobe products requires returning the `match` // The JS engine embedded in Adobe products requires returning the `match`
// string in order to produce the correct `offset` value // string in order to produce the correct `offset` value.
return match; return match;
}); });
source += "';\n"; source += "';\n";
// if `variable` is not specified, wrap a with-statement around the generated // If `variable` is not specified, wrap a with-statement around the generated
// code to add the data object to the top of the scope chain // code to add the data object to the top of the scope chain.
var variable = options.variable; var variable = options.variable;
if (!variable) { if (!variable) {
source = 'with (obj) {\n' + source + '\n}\n'; source = 'with (obj) {\n' + source + '\n}\n';
} }
// cleanup code by stripping empty strings // Cleanup code by stripping empty strings.
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source) source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
.replace(reEmptyStringMiddle, '$1') .replace(reEmptyStringMiddle, '$1')
.replace(reEmptyStringTrailing, '$1;'); .replace(reEmptyStringTrailing, '$1;');
// frame code as the function body // Frame code as the function body.
source = 'function(' + (variable || 'obj') + ') {\n' + source = 'function(' + (variable || 'obj') + ') {\n' +
(variable (variable
? '' ? ''
@@ -9016,8 +9013,8 @@
return Function(importsKeys, 'return ' + source + sourceURL).apply(undefined, importsValues); return Function(importsKeys, 'return ' + source + sourceURL).apply(undefined, importsValues);
}); });
// provide the compiled function's source by its `toString` method or // Provide the compiled function's source by its `toString` method or
// the `source` property as a convenience for inlining compiled templates // the `source` property as a convenience for inlining compiled templates.
result.source = source; result.source = source;
if (isError(result)) { if (isError(result)) {
throw result; throw result;
@@ -9541,7 +9538,7 @@
* // => true * // => true
*/ */
function noop() { function noop() {
// no operation performed // No operation performed.
} }
/** /**
@@ -9583,7 +9580,7 @@
function parseInt(value, radix, guard) { function parseInt(value, radix, guard) {
return nativeParseInt(value, guard ? 0 : radix); return nativeParseInt(value, guard ? 0 : radix);
} }
// fallback for environments with pre-ES5 implementations // Fallback for environments with pre-ES5 implementations.
if (nativeParseInt(whitespace + '08') != 8) { if (nativeParseInt(whitespace + '08') != 8) {
parseInt = function(value, radix, guard) { parseInt = function(value, radix, guard) {
// Firefox < 21 and Opera < 15 follow ES3 for `parseInt` and // Firefox < 21 and Opera < 15 follow ES3 for `parseInt` and
@@ -9758,8 +9755,8 @@
} else { } else {
end = +end || 0; end = +end || 0;
} }
// use `Array(length)` so engines like Chakra and V8 avoid slower modes // Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
// http://youtu.be/XAqIpGU8ZZk#t=17m25s // See http://youtu.be/XAqIpGU8ZZk#t=17m25s.
var index = -1, var index = -1,
length = nativeMax(ceil((end - start) / (step || 1)), 0), length = nativeMax(ceil((end - start) / (step || 1)), 0),
result = Array(length); result = Array(length);
@@ -9837,6 +9834,9 @@
*/ */
function times(n, iteratee, thisArg) { function times(n, iteratee, thisArg) {
n = +n; n = +n;
// Exit early to avoid a JSC JIT bug in Safari 8
// where `Array(0)` is treated as `Array(1)`.
if (n < 1 || !nativeIsFinite(n)) { if (n < 1 || !nativeIsFinite(n)) {
return []; return [];
} }
@@ -9878,21 +9878,21 @@
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
// ensure `new LodashWrapper` is an instance of `lodash` // Ensure `new LodashWrapper` is an instance of `lodash`.
LodashWrapper.prototype = lodash.prototype; LodashWrapper.prototype = lodash.prototype;
// add functions to the `Map` cache // Add functions to the `Map` cache.
MapCache.prototype.get = mapGet; MapCache.prototype.get = mapGet;
MapCache.prototype.has = mapHas; MapCache.prototype.has = mapHas;
MapCache.prototype.set = mapSet; MapCache.prototype.set = mapSet;
// add functions to the `Set` cache // Add functions to the `Set` cache.
SetCache.prototype.push = cachePush; SetCache.prototype.push = cachePush;
// assign cache to `_.memoize` // Assign cache to `_.memoize`.
memoize.Cache = MapCache; memoize.Cache = MapCache;
// add functions that return wrapped values when chaining // Add functions that return wrapped values when chaining.
lodash.after = after; lodash.after = after;
lodash.assign = assign; lodash.assign = assign;
lodash.at = at; lodash.at = at;
@@ -9987,7 +9987,7 @@
lodash.zip = zip; lodash.zip = zip;
lodash.zipObject = zipObject; lodash.zipObject = zipObject;
// add aliases // Add aliases.
lodash.backflow = flowRight; lodash.backflow = flowRight;
lodash.collect = map; lodash.collect = map;
lodash.compose = flowRight; lodash.compose = flowRight;
@@ -10001,12 +10001,12 @@
lodash.tail = rest; lodash.tail = rest;
lodash.unique = uniq; lodash.unique = uniq;
// add functions to `lodash.prototype` // Add functions to `lodash.prototype`.
mixin(lodash, lodash); mixin(lodash, lodash);
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
// add functions that return unwrapped values when chaining // Add functions that return unwrapped values when chaining.
lodash.attempt = attempt; lodash.attempt = attempt;
lodash.camelCase = camelCase; lodash.camelCase = camelCase;
lodash.capitalize = capitalize; lodash.capitalize = capitalize;
@@ -10081,7 +10081,7 @@
lodash.uniqueId = uniqueId; lodash.uniqueId = uniqueId;
lodash.words = words; lodash.words = words;
// add aliases // Add aliases.
lodash.all = every; lodash.all = every;
lodash.any = some; lodash.any = some;
lodash.detect = find; lodash.detect = find;
@@ -10103,7 +10103,7 @@
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
// add functions capable of returning wrapped and unwrapped values when chaining // Add functions capable of returning wrapped and unwrapped values when chaining.
lodash.sample = sample; lodash.sample = sample;
lodash.prototype.sample = function(n, guard) { lodash.prototype.sample = function(n, guard) {
@@ -10127,12 +10127,12 @@
*/ */
lodash.VERSION = VERSION; lodash.VERSION = VERSION;
// assign default placeholders // Assign default placeholders.
arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) { arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
lodash[methodName].placeholder = lodash; lodash[methodName].placeholder = lodash;
}); });
// add `LazyWrapper` methods that accept an `iteratee` value // Add `LazyWrapper` methods that accept an `iteratee` value.
arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) { arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
var isFilter = !index; var isFilter = !index;
@@ -10149,7 +10149,7 @@
}; };
}); });
// add `LazyWrapper` methods for `_.drop` and `_.take` variants // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
arrayEach(['drop', 'take'], function(methodName, index) { arrayEach(['drop', 'take'], function(methodName, index) {
var countName = methodName + 'Count', var countName = methodName + 'Count',
whileName = methodName + 'While'; whileName = methodName + 'While';
@@ -10177,7 +10177,7 @@
}; };
}); });
// add `LazyWrapper` methods for `_.first` and `_.last` // Add `LazyWrapper` methods for `_.first` and `_.last`.
arrayEach(['first', 'last'], function(methodName, index) { arrayEach(['first', 'last'], function(methodName, index) {
var takeName = 'take' + (index ? 'Right': ''); var takeName = 'take' + (index ? 'Right': '');
@@ -10186,7 +10186,7 @@
}; };
}); });
// add `LazyWrapper` methods for `_.initial` and `_.rest` // Add `LazyWrapper` methods for `_.initial` and `_.rest`.
arrayEach(['initial', 'rest'], function(methodName, index) { arrayEach(['initial', 'rest'], function(methodName, index) {
var dropName = 'drop' + (index ? '' : 'Right'); var dropName = 'drop' + (index ? '' : 'Right');
@@ -10228,7 +10228,7 @@
return result; return result;
}; };
// add `LazyWrapper` methods to `lodash.prototype` // Add `LazyWrapper` methods to `lodash.prototype`.
baseForOwn(LazyWrapper.prototype, function(func, methodName) { baseForOwn(LazyWrapper.prototype, function(func, methodName) {
var retUnwrapped = /^(?:first|last)$/.test(methodName); var retUnwrapped = /^(?:first|last)$/.test(methodName);
@@ -10255,15 +10255,15 @@
}; };
}); });
// add `Array.prototype` functions to `lodash.prototype` // Add `Array.prototype` functions to `lodash.prototype`.
arrayEach(['concat', 'join', 'pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) { arrayEach(['concat', 'join', 'pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
var arrayFunc = arrayProto[methodName], var arrayFunc = arrayProto[methodName],
chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru', chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
fixObjects = !support.spliceObjects && /^(?:pop|shift|splice)$/.test(methodName), fixObjects = !support.spliceObjects && /^(?:pop|shift|splice)$/.test(methodName),
retUnwrapped = /^(?:join|pop|shift)$/.test(methodName); retUnwrapped = /^(?:join|pop|shift)$/.test(methodName);
// avoid array-like object bugs with `Array#shift` and `Array#splice` in // Avoid array-like object bugs with `Array#shift` and `Array#splice` in
// IE < 9, Firefox < 10, Narwhal, and RingoJS // IE < 9, Firefox < 10, Narwhal, and RingoJS.
var func = !fixObjects ? arrayFunc : function() { var func = !fixObjects ? arrayFunc : function() {
var result = arrayFunc.apply(this, arguments); var result = arrayFunc.apply(this, arguments);
if (this.length === 0) { if (this.length === 0) {
@@ -10283,18 +10283,18 @@
}; };
}); });
// add functions to the lazy wrapper // Add functions to the lazy wrapper.
LazyWrapper.prototype.clone = lazyClone; LazyWrapper.prototype.clone = lazyClone;
LazyWrapper.prototype.reverse = lazyReverse; LazyWrapper.prototype.reverse = lazyReverse;
LazyWrapper.prototype.value = lazyValue; LazyWrapper.prototype.value = lazyValue;
// add chaining functions to the lodash wrapper // Add chaining functions to the lodash wrapper.
lodash.prototype.chain = wrapperChain; lodash.prototype.chain = wrapperChain;
lodash.prototype.reverse = wrapperReverse; lodash.prototype.reverse = wrapperReverse;
lodash.prototype.toString = wrapperToString; lodash.prototype.toString = wrapperToString;
lodash.prototype.toJSON = lodash.prototype.value = lodash.prototype.valueOf = wrapperValueOf; lodash.prototype.toJSON = lodash.prototype.value = lodash.prototype.valueOf = wrapperValueOf;
// add function aliases to the lodash wrapper // Add function aliases to the lodash wrapper.
lodash.prototype.collect = lodash.prototype.map; lodash.prototype.collect = lodash.prototype.map;
lodash.prototype.head = lodash.prototype.first; lodash.prototype.head = lodash.prototype.first;
lodash.prototype.select = lodash.prototype.filter; lodash.prototype.select = lodash.prototype.filter;
@@ -10305,35 +10305,35 @@
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
// export Lo-Dash // Export Lo-Dash.
var _ = runInContext(); var _ = runInContext();
// some AMD build optimizers like r.js check for condition patterns like the following: // Some AMD build optimizers like r.js check for condition patterns like the following:
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) { if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
// Expose Lo-Dash to the global object when an AMD loader is present to avoid // Expose Lo-Dash to the global object when an AMD loader is present to avoid
// errors in cases where Lo-Dash is loaded by a script tag and not intended // errors in cases where Lo-Dash is loaded by a script tag and not intended
// as an AMD module. See http://requirejs.org/docs/errors.html#mismatch // as an AMD module. See http://requirejs.org/docs/errors.html#mismatch.
root._ = _; root._ = _;
// define as an anonymous module so, through path mapping, it can be // Define as an anonymous module so, through path mapping, it can be
// referenced as the "underscore" module // referenced as the "underscore" module.
define(function() { define(function() {
return _; return _;
}); });
} }
// check for `exports` after `define` in case a build optimizer adds an `exports` object // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
else if (freeExports && freeModule) { else if (freeExports && freeModule) {
// in Node.js or RingoJS // Export for Node.js or RingoJS.
if (moduleExports) { if (moduleExports) {
(freeModule.exports = _)._ = _; (freeModule.exports = _)._ = _;
} }
// in Narwhal or Rhino -require // Export for Narwhal or Rhino -require.
else { else {
freeExports._ = _; freeExports._ = _;
} }
} }
else { else {
// in a browser or Rhino // Export for a browser or Rhino.
root._ = _; root._ = _;
} }
}.call(this)); }.call(this));