d9f5f618a634df140c33caea04f87ce5984961df
[yaffs-website] / baseConforms.js
1 var keys = require('../keys');
2
3 /**
4  * The base implementation of `_.conforms` which doesn't clone `source`.
5  *
6  * @private
7  * @param {Object} source The object of property predicates to conform to.
8  * @returns {Function} Returns the new function.
9  */
10 function baseConforms(source) {
11   var props = keys(source),
12       length = props.length;
13
14   return function(object) {
15     if (object == null) {
16       return !length;
17     }
18     var index = length;
19     while (index--) {
20       var key = props[index],
21           predicate = source[key],
22           value = object[key];
23
24       if ((value === undefined && !(key in Object(object))) || !predicate(value)) {
25         return false;
26       }
27     }
28     return true;
29   };
30 }
31
32 module.exports = baseConforms;