ce06e72b983c8300632c2f92cec7ae84c84e10d5
[yaffs-website] / node_modules / grunt-legacy-log-utils / node_modules / lodash / wrapperAt.js
1 var LazyWrapper = require('./_LazyWrapper'),
2     LodashWrapper = require('./_LodashWrapper'),
3     baseAt = require('./_baseAt'),
4     baseFlatten = require('./_baseFlatten'),
5     isIndex = require('./_isIndex'),
6     rest = require('./rest'),
7     thru = require('./thru');
8
9 /**
10  * This method is the wrapper version of `_.at`.
11  *
12  * @name at
13  * @memberOf _
14  * @category Seq
15  * @param {...(string|string[])} [paths] The property paths of elements to pick,
16  *  specified individually or in arrays.
17  * @returns {Object} Returns the new `lodash` wrapper instance.
18  * @example
19  *
20  * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
21  *
22  * _(object).at(['a[0].b.c', 'a[1]']).value();
23  * // => [3, 4]
24  *
25  * _(['a', 'b', 'c']).at(0, 2).value();
26  * // => ['a', 'c']
27  */
28 var wrapperAt = rest(function(paths) {
29   paths = baseFlatten(paths);
30   var length = paths.length,
31       start = length ? paths[0] : 0,
32       value = this.__wrapped__,
33       interceptor = function(object) { return baseAt(object, paths); };
34
35   if (length > 1 || this.__actions__.length || !(value instanceof LazyWrapper) || !isIndex(start)) {
36     return this.thru(interceptor);
37   }
38   value = value.slice(start, +start + (length ? 1 : 0));
39   value.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
40   return new LodashWrapper(value, this.__chain__).thru(function(array) {
41     if (length && !array.length) {
42       array.push(undefined);
43     }
44     return array;
45   });
46 });
47
48 module.exports = wrapperAt;