only.js 705 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. var variadic = require('../helpers/variadic');
  3. module.exports = function only() {
  4. var _this = this;
  5. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  6. args[_key] = arguments[_key];
  7. }
  8. var properties = variadic(args);
  9. if (Array.isArray(this.items)) {
  10. var _collection = this.items.filter(function (item) {
  11. return properties.indexOf(item) !== -1;
  12. });
  13. return new this.constructor(_collection);
  14. }
  15. var collection = {};
  16. Object.keys(this.items).forEach(function (prop) {
  17. if (properties.indexOf(prop) !== -1) {
  18. collection[prop] = _this.items[prop];
  19. }
  20. });
  21. return new this.constructor(collection);
  22. };