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.

34 lines
774 B

4 years ago
  1. 'use strict';
  2. module.exports = function toArray() {
  3. var collectionInstance = this.constructor;
  4. function iterate(list, collection) {
  5. var childCollection = [];
  6. if (list instanceof collectionInstance) {
  7. list.items.forEach(function (i) {
  8. return iterate(i, childCollection);
  9. });
  10. collection.push(childCollection);
  11. } else if (Array.isArray(list)) {
  12. list.forEach(function (i) {
  13. return iterate(i, childCollection);
  14. });
  15. collection.push(childCollection);
  16. } else {
  17. collection.push(list);
  18. }
  19. }
  20. if (Array.isArray(this.items)) {
  21. var collection = [];
  22. this.items.forEach(function (items) {
  23. iterate(items, collection);
  24. });
  25. return collection;
  26. }
  27. return this.values().all();
  28. };