95d01f392507de8002348ce5df898eac03c514f9
[yaffs-website] / node_modules / grunt-legacy-log-utils / node_modules / lodash / findKey.js
1 var baseFind = require('./_baseFind'),
2     baseForOwn = require('./_baseForOwn'),
3     baseIteratee = require('./_baseIteratee');
4
5 /**
6  * This method is like `_.find` except that it returns the key of the first
7  * element `predicate` returns truthy for instead of the element itself.
8  *
9  * @static
10  * @memberOf _
11  * @category Object
12  * @param {Object} object The object to search.
13  * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
14  * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
15  * @example
16  *
17  * var users = {
18  *   'barney':  { 'age': 36, 'active': true },
19  *   'fred':    { 'age': 40, 'active': false },
20  *   'pebbles': { 'age': 1,  'active': true }
21  * };
22  *
23  * _.findKey(users, function(o) { return o.age < 40; });
24  * // => 'barney' (iteration order is not guaranteed)
25  *
26  * // The `_.matches` iteratee shorthand.
27  * _.findKey(users, { 'age': 1, 'active': true });
28  * // => 'pebbles'
29  *
30  * // The `_.matchesProperty` iteratee shorthand.
31  * _.findKey(users, ['active', false]);
32  * // => 'fred'
33  *
34  * // The `_.property` iteratee shorthand.
35  * _.findKey(users, 'active');
36  * // => 'barney'
37  */
38 function findKey(object, predicate) {
39   return baseFind(object, baseIteratee(predicate, 3), baseForOwn, true);
40 }
41
42 module.exports = findKey;