dotfiles/.vscode/extensions/vscodevim.vim-0.2.0/node_modules/lodash/wrapperAt.js

51 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-09-11 09:29:13 +01:00
var LazyWrapper = require('./_LazyWrapper'),
LodashWrapper = require('./_LodashWrapper'),
baseAt = require('./_baseAt'),
baseFlatten = require('./_baseFlatten'),
baseRest = require('./_baseRest'),
isIndex = require('./_isIndex'),
thru = require('./thru');
/**
* This method is the wrapper version of `_.at`.
*
* @name at
* @memberOf _
* @since 1.0.0
* @category Seq
* @param {...(string|string[])} [paths] The property paths of elements to pick.
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
*
* _(object).at(['a[0].b.c', 'a[1]']).value();
* // => [3, 4]
*/
var wrapperAt = baseRest(function(paths) {
paths = baseFlatten(paths, 1);
var length = paths.length,
start = length ? paths[0] : 0,
value = this.__wrapped__,
interceptor = function(object) { return baseAt(object, paths); };
if (length > 1 || this.__actions__.length ||
!(value instanceof LazyWrapper) || !isIndex(start)) {
return this.thru(interceptor);
}
value = value.slice(start, +start + (length ? 1 : 0));
value.__actions__.push({
'func': thru,
'args': [interceptor],
'thisArg': undefined
});
return new LodashWrapper(value, this.__chain__).thru(function(array) {
if (length && !array.length) {
array.push(undefined);
}
return array;
});
});
module.exports = wrapperAt;