Add _.mockArray, _.mockFalse, _.mockObject, _.mockString, and _.mockTrue.

This commit is contained in:
John-David Dalton
2016-05-10 16:16:23 -07:00
parent 262049f737
commit 2357704540
2 changed files with 362 additions and 255 deletions

145
lodash.js
View File

@@ -1420,19 +1420,21 @@
* `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, `isBoolean`,
* `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`,
* `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMap`,
* `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`,
* `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, `isSafeInteger`,
* `isSet`, `isString`, `isUndefined`, `isTypedArray`, `isWeakMap`, `isWeakSet`,
* `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`, `lowerFirst`,
* `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`, `min`, `minBy`, `multiply`,
* `noConflict`, `noop`, `now`, `nth`, `pad`, `padEnd`, `padStart`, `parseInt`,
* `pop`, `random`, `reduce`, `reduceRight`, `repeat`, `result`, `round`,
* `runInContext`, `sample`, `shift`, `size`, `snakeCase`, `some`, `sortedIndex`,
* `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`, `startCase`,
* `startsWith`, `subtract`, `sum`, `sumBy`, `template`, `times`, `toFinite`,
* `toInteger`, `toJSON`, `toLength`, `toLower`, `toNumber`, `toSafeInteger`,
* `toString`, `toUpper`, `trim`, `trimEnd`, `trimStart`, `truncate`, `unescape`,
* `uniqueId`, `upperCase`, `upperFirst`, `value`, and `words`
* `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
* `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
* `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
* `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
* `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
* `min`, `minBy`, `mockArray`, `mockFalse`, `mockObject`, `mockString`,
* `mockTrue`, multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`, `padEnd`,
* `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, `repeat`,
* `result`, `round`, `runInContext`, `sample`, `shift`, `size`, `snakeCase`,
* `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, `sortedLastIndexBy`,
* `startCase`, `startsWith`, `subtract`, `sum`, `sumBy`, `template`, `times`,
* `toFinite`, `toInteger`, `toJSON`, `toLength`, `toLower`, `toNumber`,
* `toSafeInteger`, `toString`, `toUpper`, `trim`, `trimEnd`, `trimStart`,
* `truncate`, `unescape`, `uniqueId`, `upperCase`, `upperFirst`, `value`,
* and `words`
*
* @name _
* @constructor
@@ -5420,9 +5422,7 @@
// Fallback for IE < 11.
if (!getOwnPropertySymbols) {
getSymbols = function() {
return [];
};
getSymbols = mockArray;
}
/**
@@ -14644,10 +14644,12 @@
* @returns {Function} Returns the new constant function.
* @example
*
* var object = { 'user': 'fred' };
* var getter = _.constant(object);
* var objects = _.times(2, _.constant({ 'a': 1 }));
*
* getter() === object;
* console.log(objects);
* // => [{ 'a': 1 }, { 'a': 1 }]
*
* console.log(objects[0] === objects[1]);
* // => true
*/
function constant(value) {
@@ -14716,7 +14718,7 @@
*
* var object = { 'user': 'fred' };
*
* _.identity(object) === object;
* console.log(_.identity(object) === object);
* // => true
*/
function identity(value) {
@@ -14956,6 +14958,95 @@
return object;
}
/**
* A method that returns a new empty array.
*
* @static
* @memberOf _
* @since 4.13.0
* @category Util
* @returns {Array} Returns the new empty array.
* @example
*
* var arrays = _.times(2, _.mockArray);
*
* console.log(arrays);
* // => [[], []]
*
* console.log(arrays[0] === arrays[1]);
* // => false
*/
function mockArray() {
return [];
}
/**
* A method that returns `false`.
*
* @static
* @memberOf _
* @since 4.13.0
* @category Util
* @returns {boolean} Returns `false`.
* @example
*
* _.times(2 _.mockFalse);
* // => [false, false]
*/
var mockFalse = constant(false);
/**
* A method that returns a new empty object.
*
* @static
* @memberOf _
* @since 4.13.0
* @category Util
* @returns {Object} Returns the new empty object.
* @example
*
* var objects = _.times(2, _.mockObject);
*
* console.log(objects);
* // => [{}, {}]
*
* console.log(objects[0] === objects[1]);
* // => false
*/
function mockObject() {
return {};
}
/**
* A method that returns an empty string.
*
* @static
* @memberOf _
* @since 4.13.0
* @category Util
* @returns {string} Returns the empty string.
* @example
*
* _.times(2, _.mockString);
* // => ['', '']
*/
var mockString = constant('');
/**
* A method that returns `true`.
*
* @static
* @memberOf _
* @since 4.13.0
* @category Util
* @returns {boolean} Returns `true`.
* @example
*
* _.times(2, _.mockTrue);
* // => [true, true]
*/
var mockTrue = constant(true);
/**
* Reverts the `_` variable to its previous value and returns a reference to
* the `lodash` function.
@@ -14977,8 +15068,7 @@
}
/**
* A no-operation function that returns `undefined` regardless of the
* arguments it receives.
* A method that returns `undefined`.
*
* @static
* @memberOf _
@@ -14986,10 +15076,8 @@
* @category Util
* @example
*
* var object = { 'user': 'fred' };
*
* _.noop(object) === undefined;
* // => true
* _.times(2, _.noop);
* // => [undefined, undefined]
*/
function noop() {
// No operation performed.
@@ -15919,6 +16007,11 @@
lodash.meanBy = meanBy;
lodash.min = min;
lodash.minBy = minBy;
lodash.mockArray = mockArray;
lodash.mockFalse = mockFalse;
lodash.mockObject = mockObject;
lodash.mockTrue = mockTrue;
lodash.mockString = mockString;
lodash.multiply = multiply;
lodash.nth = nth;
lodash.noConflict = noConflict;

File diff suppressed because it is too large Load Diff