mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-15 21:27:50 +00:00
Add _.conformsTo.
This commit is contained in:
46
lodash.js
46
lodash.js
@@ -2413,10 +2413,22 @@
|
|||||||
* @returns {Function} Returns the new spec function.
|
* @returns {Function} Returns the new spec function.
|
||||||
*/
|
*/
|
||||||
function baseConforms(source) {
|
function baseConforms(source) {
|
||||||
var props = keys(source),
|
var props = keys(source);
|
||||||
length = props.length;
|
|
||||||
|
|
||||||
return function(object) {
|
return function(object) {
|
||||||
|
return baseConformsTo(object, source, props);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base implementation of `_.conformsTo` which accepts `props` to check.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} object The object to inspect.
|
||||||
|
* @param {Object} source The object of property predicates to conform to.
|
||||||
|
* @returns {boolean} Returns `true` if `object` conforms, else `false`.
|
||||||
|
*/
|
||||||
|
function baseConformsTo(object, source, props) {
|
||||||
|
var length = props.length;
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
return !length;
|
return !length;
|
||||||
}
|
}
|
||||||
@@ -2432,7 +2444,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10470,6 +10481,32 @@
|
|||||||
return baseClone(value, true, true, customizer);
|
return baseClone(value, true, true, customizer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if `object` conforms to `source` by invoking the predicate properties
|
||||||
|
* of `source` with the corresponding property values of `object`. This method
|
||||||
|
* is equivalent to a `_.conforms` function when `source` is partially applied.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @since 4.14.0
|
||||||
|
* @category Lang
|
||||||
|
* @param {Object} object The object to inspect.
|
||||||
|
* @param {Object} source The object of property predicates to conform to.
|
||||||
|
* @returns {boolean} Returns `true` if `object` conforms, else `false`.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* var object = { 'user': 'fred', 'age': 40 };
|
||||||
|
*
|
||||||
|
* _.conformsTo(object, { 'age': function(n) { return n > 38; } });
|
||||||
|
* // => true
|
||||||
|
*
|
||||||
|
* _.conformsTo(object, { 'age': function(n) { return n < 38; } });
|
||||||
|
* // => false
|
||||||
|
*/
|
||||||
|
function conformsTo(object, source) {
|
||||||
|
return source == null || baseConformsTo(object, source, keys(source));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a
|
* Performs a
|
||||||
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
||||||
@@ -16003,6 +16040,7 @@
|
|||||||
lodash.cloneDeep = cloneDeep;
|
lodash.cloneDeep = cloneDeep;
|
||||||
lodash.cloneDeepWith = cloneDeepWith;
|
lodash.cloneDeepWith = cloneDeepWith;
|
||||||
lodash.cloneWith = cloneWith;
|
lodash.cloneWith = cloneWith;
|
||||||
|
lodash.conformsTo = conformsTo;
|
||||||
lodash.deburr = deburr;
|
lodash.deburr = deburr;
|
||||||
lodash.defaultTo = defaultTo;
|
lodash.defaultTo = defaultTo;
|
||||||
lodash.divide = divide;
|
lodash.divide = divide;
|
||||||
|
|||||||
@@ -26597,7 +26597,7 @@
|
|||||||
var acceptFalsey = lodashStable.difference(allMethods, rejectFalsey);
|
var acceptFalsey = lodashStable.difference(allMethods, rejectFalsey);
|
||||||
|
|
||||||
QUnit.test('should accept falsey arguments', function(assert) {
|
QUnit.test('should accept falsey arguments', function(assert) {
|
||||||
assert.expect(315);
|
assert.expect(316);
|
||||||
|
|
||||||
var arrays = lodashStable.map(falsey, stubArray);
|
var arrays = lodashStable.map(falsey, stubArray);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user