source: imaps-frontend/node_modules/lodash-es/wrapperAt.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[d565449]1import LazyWrapper from './_LazyWrapper.js';
2import LodashWrapper from './_LodashWrapper.js';
3import baseAt from './_baseAt.js';
4import flatRest from './_flatRest.js';
5import isIndex from './_isIndex.js';
6import thru from './thru.js';
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 */
24var 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
48export default wrapperAt;
Note: See TracBrowser for help on using the repository browser.