Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / baseMatchesProperty.js
1 var baseGet = require('./baseGet'),
2     baseIsEqual = require('./baseIsEqual'),
3     baseSlice = require('./baseSlice'),
4     isArray = require('../lang/isArray'),
5     isKey = require('./isKey'),
6     isStrictComparable = require('./isStrictComparable'),
7     last = require('../array/last'),
8     toObject = require('./toObject'),
9     toPath = require('./toPath');
10
11 /**
12  * The base implementation of `_.matchesProperty` which does not clone `srcValue`.
13  *
14  * @private
15  * @param {string} path The path of the property to get.
16  * @param {*} srcValue The value to compare.
17  * @returns {Function} Returns the new function.
18  */
19 function baseMatchesProperty(path, srcValue) {
20   var isArr = isArray(path),
21       isCommon = isKey(path) && isStrictComparable(srcValue),
22       pathKey = (path + '');
23
24   path = toPath(path);
25   return function(object) {
26     if (object == null) {
27       return false;
28     }
29     var key = pathKey;
30     object = toObject(object);
31     if ((isArr || !isCommon) && !(key in object)) {
32       object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
33       if (object == null) {
34         return false;
35       }
36       key = last(path);
37       object = toObject(object);
38     }
39     return object[key] === srcValue
40       ? (srcValue !== undefined || (key in object))
41       : baseIsEqual(srcValue, object[key], undefined, true);
42   };
43 }
44
45 module.exports = baseMatchesProperty;