Projekt

Obecné

Profil

Stáhnout (1.31 KB) Statistiky
| Větev: | Revize:
1
var LazyWrapper = require('./_LazyWrapper'),
2
    LodashWrapper = require('./_LodashWrapper'),
3
    baseAt = require('./_baseAt'),
4
    flatRest = require('./_flatRest'),
5
    isIndex = require('./_isIndex'),
6
    thru = require('./thru');
7

    
8
/**
9
 * This method is the wrapper version of `_.at`.
10
 *
11
 * @name at
12
 * @memberOf _
13
 * @since 1.0.0
14
 * @category Seq
15
 * @param {...(string|string[])} [paths] The property paths to pick.
16
 * @returns {Object} Returns the new `lodash` wrapper instance.
17
 * @example
18
 *
19
 * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
20
 *
21
 * _(object).at(['a[0].b.c', 'a[1]']).value();
22
 * // => [3, 4]
23
 */
24
var wrapperAt = flatRest(function(paths) {
25
  var length = paths.length,
26
      start = length ? paths[0] : 0,
27
      value = this.__wrapped__,
28
      interceptor = function(object) { return baseAt(object, paths); };
29

    
30
  if (length > 1 || this.__actions__.length ||
31
      !(value instanceof LazyWrapper) || !isIndex(start)) {
32
    return this.thru(interceptor);
33
  }
34
  value = value.slice(start, +start + (length ? 1 : 0));
35
  value.__actions__.push({
36
    'func': thru,
37
    'args': [interceptor],
38
    'thisArg': undefined
39
  });
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;
(579-579/590)