Merge pull request #5047 from chrootsu/lodash-isEqual

lodash: changed _.isEqual() method
This commit is contained in:
Masahiro Wakame
2015-07-28 23:25:36 +09:00
2 changed files with 97 additions and 29 deletions
+22 -13
View File
@@ -1028,21 +1028,30 @@ result = <boolean>_.isEmpty([1, 2, 3]);
result = <boolean>_.isEmpty({});
result = <boolean>_.isEmpty('');
var moe = { 'name': 'moe', 'age': 40 };
var copy = { 'name': 'moe', 'age': 40 };
// _.isEqual (alias: _.eq)
result = <boolean>_.isEqual(1, 1);
result = <boolean>_(1).isEqual(1);
result = <boolean>_.eq(1, 1);
result = <boolean>_(1).eq(1);
result = <boolean>_.isEqual(moe, copy);
var testEqObject = { 'user': 'fred' };
var testEqOtherObject = { 'user': 'fred' };
result = <boolean>_.isEqual(testEqObject, testEqOtherObject);
result = <boolean>_(testEqObject).isEqual(testEqOtherObject);
result = <boolean>_.eq(testEqObject, testEqOtherObject);
result = <boolean>_(testEqObject).eq(testEqOtherObject);
var words = ['hello', 'goodbye'];
var otherWords = ['hi', 'goodbye'];
result = <boolean>_.isEqual(words, otherWords, function (a, b) {
var reGreet = /^(?:hello|hi)$/i,
aGreet = _.isString(a) && reGreet.test(a),
bGreet = _.isString(b) && reGreet.test(b);
return (aGreet || bGreet) ? (aGreet == bGreet) : undefined;
});
var testEqArray = ['hello', 'goodbye'];
var testEqOtherArray = ['hi', 'goodbye'];
var testEqCustomizerFn = (value: any, other: any): boolean => {
if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
return true;
}
};
result = <boolean>_.isEqual(testEqArray, testEqOtherArray, testEqCustomizerFn);
result = <boolean>_(testEqArray).isEqual(testEqOtherArray, testEqCustomizerFn);
result = <boolean>_.eq(testEqArray, testEqOtherArray, testEqCustomizerFn);
result = <boolean>_(testEqArray).eq(testEqOtherArray, testEqCustomizerFn);
result = <boolean>_.isFinite(-101);
result = <boolean>_.isFinite('10');
+75 -16
View File
@@ -6071,25 +6071,84 @@ declare module _ {
isError(value: any): boolean;
}
//_.isEqual
interface EqCustomizer {
(value: any, other: any, indexOrKey?: number|string): boolean;
}
interface LoDashStatic {
/**
* Performs a deep comparison between two values to determine if they are equivalent to each
* other. If a callback is provided it will be executed to compare values. If the callback
* returns undefined comparisons will be handled by the method instead. The callback is bound to
* thisArg and invoked with two arguments; (a, b).
* @param a The value to compare.
* @param b The other value to compare.
* @param callback The function to customize comparing values.
* @param thisArg The this binding of callback.
* @return True if the values are equivalent, else false.
**/
isEqual(
a?: any,
b?: any,
callback?: (a: any, b: any) => boolean,
thisArg?: any): boolean;
* Performs a deep comparison between two values to determine if they are equivalent. If customizer is
* provided it is invoked to compare values. If customizer returns undefined comparisons are handled
* by the method instead. The customizer is bound to thisArg and invoked with three
* arguments: (value, other [, index|key]).
* @param value The value to compare.
* @param other The other value to compare.
* @param callback The function to customize value comparisons.
* @param thisArg The this binding of customizer.
* @return True if the values are equivalent, else false.
*/
isEqual(value?: any,
other?: any,
callback?: EqCustomizer,
thisArg?: any): boolean;
/**
* @see _.isEqual
*/
eq(value?: any,
other?: any,
callback?: EqCustomizer,
thisArg?: any): boolean;
}
interface LoDashWrapper<T> {
/**
* @see _.isEqual
*/
isEqual(other?: any,
callback?: EqCustomizer,
thisArg?: any): boolean;
/**
* @see _.isEqual
*/
eq(other?: any,
callback?: EqCustomizer,
thisArg?: any): boolean;
}
interface LoDashArrayWrapper<T> {
/**
* @see _.isEqual
*/
isEqual(other?: any,
callback?: EqCustomizer,
thisArg?: any): boolean;
/**
* @see _.isEqual
*/
eq(other?: any,
callback?: EqCustomizer,
thisArg?: any): boolean;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.isEqual
*/
isEqual(other?: any,
callback?: EqCustomizer,
thisArg?: any): boolean;
/**
* @see _.isEqual
*/
eq(other?: any,
callback?: EqCustomizer,
thisArg?: any): boolean;
}
//_.isFinite