concat.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  3. var clone = require('../helpers/clone');
  4. module.exports = function concat(collectionOrArrayOrObject) {
  5. var list = collectionOrArrayOrObject;
  6. if (collectionOrArrayOrObject instanceof this.constructor) {
  7. list = collectionOrArrayOrObject.all();
  8. } else if (_typeof(collectionOrArrayOrObject) === 'object') {
  9. list = [];
  10. Object.keys(collectionOrArrayOrObject).forEach(function (property) {
  11. list.push(collectionOrArrayOrObject[property]);
  12. });
  13. }
  14. var collection = clone(this.items);
  15. list.forEach(function (item) {
  16. if (_typeof(item) === 'object') {
  17. Object.keys(item).forEach(function (key) {
  18. return collection.push(item[key]);
  19. });
  20. } else {
  21. collection.push(item);
  22. }
  23. });
  24. return new this.constructor(collection);
  25. };