103cefe01d8e7f0a5ad11cefaab7f4d49ab0663b
[yaffs-website] / node_modules / uncss / node_modules / lodash / takeWhile.js
1 var baseIteratee = require('./internal/baseIteratee'),
2     baseWhile = require('./internal/baseWhile');
3
4 /**
5  * Creates a slice of `array` with elements taken from the beginning. Elements
6  * are taken until `predicate` returns falsey. The predicate is invoked with
7  * three arguments: (value, index, array).
8  *
9  * @static
10  * @memberOf _
11  * @category Array
12  * @param {Array} array The array to query.
13  * @param {Function|Object|string} [predicate=_.identity] The function invoked per iteration.
14  * @returns {Array} Returns the slice of `array`.
15  * @example
16  *
17  * var users = [
18  *   { 'user': 'barney',  'active': false },
19  *   { 'user': 'fred',    'active': false},
20  *   { 'user': 'pebbles', 'active': true }
21  * ];
22  *
23  * _.takeWhile(users, function(o) { return !o.active; });
24  * // => objects for ['barney', 'fred']
25  *
26  * // using the `_.matches` iteratee shorthand
27  * _.takeWhile(users, { 'user': 'barney', 'active': false });
28  * // => objects for ['barney']
29  *
30  * // using the `_.matchesProperty` iteratee shorthand
31  * _.takeWhile(users, ['active', false]);
32  * // => objects for ['barney', 'fred']
33  *
34  * // using the `_.property` iteratee shorthand
35  * _.takeWhile(users, 'active');
36  * // => []
37  */
38 function takeWhile(array, predicate) {
39   return (array && array.length)
40     ? baseWhile(array, baseIteratee(predicate, 3))
41     : [];
42 }
43
44 module.exports = takeWhile;