You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
978 B

4 years ago
  1. 'use strict';
  2. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  3. module.exports = function take(length) {
  4. var _this = this;
  5. if (!Array.isArray(this.items) && _typeof(this.items) === 'object') {
  6. var keys = Object.keys(this.items);
  7. var slicedKeys = void 0;
  8. if (length < 0) {
  9. slicedKeys = keys.slice(length);
  10. } else {
  11. slicedKeys = keys.slice(0, length);
  12. }
  13. var collection = {};
  14. keys.forEach(function (prop) {
  15. if (slicedKeys.indexOf(prop) !== -1) {
  16. collection[prop] = _this.items[prop];
  17. }
  18. });
  19. return new this.constructor(collection);
  20. }
  21. if (length < 0) {
  22. return new this.constructor(this.items.slice(length));
  23. }
  24. return new this.constructor(this.items.slice(0, length));
  25. };