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

File diff suppressed because it is too large Load Diff